OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef V8_COMPILER_CODE_GENERATOR_IMPL_H_ | 5 #ifndef V8_COMPILER_CODE_GENERATOR_IMPL_H_ |
6 #define V8_COMPILER_CODE_GENERATOR_IMPL_H_ | 6 #define V8_COMPILER_CODE_GENERATOR_IMPL_H_ |
7 | 7 |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 #include "src/compiler/code-generator.h" | 9 #include "src/compiler/code-generator.h" |
10 #include "src/compiler/instruction.h" | 10 #include "src/compiler/instruction.h" |
11 #include "src/compiler/linkage.h" | 11 #include "src/compiler/linkage.h" |
12 #include "src/compiler/opcodes.h" | 12 #include "src/compiler/opcodes.h" |
13 #include "src/macro-assembler.h" | 13 #include "src/macro-assembler.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace compiler { | 17 namespace compiler { |
18 | 18 |
19 // Converts InstructionOperands from a given instruction to | 19 // Converts InstructionOperands from a given instruction to |
20 // architecture-specific | 20 // architecture-specific |
21 // registers and operands after they have been assigned by the register | 21 // registers and operands after they have been assigned by the register |
22 // allocator. | 22 // allocator. |
23 class InstructionOperandConverter { | 23 class InstructionOperandConverter { |
24 public: | 24 public: |
25 InstructionOperandConverter(CodeGenerator* gen, Instruction* instr) | 25 InstructionOperandConverter(CodeGenerator* gen, Instruction* instr) |
26 : gen_(gen), instr_(instr) {} | 26 : gen_(gen), instr_(instr) {} |
27 | 27 |
| 28 // -- Instruction operand accesses with conversions -------------------------- |
| 29 |
28 Register InputRegister(int index) { | 30 Register InputRegister(int index) { |
29 return ToRegister(instr_->InputAt(index)); | 31 return ToRegister(instr_->InputAt(index)); |
30 } | 32 } |
31 | 33 |
32 DoubleRegister InputDoubleRegister(int index) { | 34 DoubleRegister InputDoubleRegister(int index) { |
33 return ToDoubleRegister(instr_->InputAt(index)); | 35 return ToDoubleRegister(instr_->InputAt(index)); |
34 } | 36 } |
35 | 37 |
36 double InputDouble(int index) { return ToDouble(instr_->InputAt(index)); } | 38 double InputDouble(int index) { return ToDouble(instr_->InputAt(index)); } |
37 | 39 |
(...skipping 12 matching lines...) Expand all Loading... |
50 } | 52 } |
51 | 53 |
52 uint8_t InputInt6(int index) { | 54 uint8_t InputInt6(int index) { |
53 return static_cast<uint8_t>(InputInt32(index) & 0x3F); | 55 return static_cast<uint8_t>(InputInt32(index) & 0x3F); |
54 } | 56 } |
55 | 57 |
56 Handle<HeapObject> InputHeapObject(int index) { | 58 Handle<HeapObject> InputHeapObject(int index) { |
57 return ToHeapObject(instr_->InputAt(index)); | 59 return ToHeapObject(instr_->InputAt(index)); |
58 } | 60 } |
59 | 61 |
60 Label* InputLabel(int index) { return gen_->GetLabel(InputRpo(index)); } | 62 Label* InputLabel(int index) { return ToLabel(instr_->InputAt(index)); } |
61 | 63 |
62 BasicBlock::RpoNumber InputRpo(int index) { | 64 BasicBlock::RpoNumber InputRpo(int index) { |
63 int rpo_number = InputInt32(index); | 65 return ToRpoNumber(instr_->InputAt(index)); |
64 return BasicBlock::RpoNumber::FromInt(rpo_number); | |
65 } | 66 } |
66 | 67 |
67 Register OutputRegister(int index = 0) { | 68 Register OutputRegister(int index = 0) { |
68 return ToRegister(instr_->OutputAt(index)); | 69 return ToRegister(instr_->OutputAt(index)); |
69 } | 70 } |
70 | 71 |
| 72 Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); } |
| 73 |
71 DoubleRegister OutputDoubleRegister() { | 74 DoubleRegister OutputDoubleRegister() { |
72 return ToDoubleRegister(instr_->Output()); | 75 return ToDoubleRegister(instr_->Output()); |
73 } | 76 } |
74 | 77 |
75 Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); } | 78 // -- Conversions for operands ----------------------------------------------- |
| 79 |
| 80 Label* ToLabel(InstructionOperand* op) { |
| 81 return gen_->GetLabel(ToRpoNumber(op)); |
| 82 } |
| 83 |
| 84 BasicBlock::RpoNumber ToRpoNumber(InstructionOperand* op) { |
| 85 return ToConstant(op).ToRpoNumber(); |
| 86 } |
76 | 87 |
77 Register ToRegister(InstructionOperand* op) { | 88 Register ToRegister(InstructionOperand* op) { |
78 DCHECK(op->IsRegister()); | 89 DCHECK(op->IsRegister()); |
79 return Register::FromAllocationIndex(op->index()); | 90 return Register::FromAllocationIndex(op->index()); |
80 } | 91 } |
81 | 92 |
82 DoubleRegister ToDoubleRegister(InstructionOperand* op) { | 93 DoubleRegister ToDoubleRegister(InstructionOperand* op) { |
83 DCHECK(op->IsDoubleRegister()); | 94 DCHECK(op->IsDoubleRegister()); |
84 return DoubleRegister::FromAllocationIndex(op->index()); | 95 return DoubleRegister::FromAllocationIndex(op->index()); |
85 } | 96 } |
86 | 97 |
87 Constant ToConstant(InstructionOperand* operand) { | 98 Constant ToConstant(InstructionOperand* op) { |
88 if (operand->IsImmediate()) { | 99 if (op->IsImmediate()) { |
89 return gen_->code()->GetImmediate(operand->index()); | 100 return gen_->code()->GetImmediate(op->index()); |
90 } | 101 } |
91 return gen_->code()->GetConstant(operand->index()); | 102 return gen_->code()->GetConstant(op->index()); |
92 } | 103 } |
93 | 104 |
94 double ToDouble(InstructionOperand* operand) { | 105 double ToDouble(InstructionOperand* op) { return ToConstant(op).ToFloat64(); } |
95 return ToConstant(operand).ToFloat64(); | |
96 } | |
97 | 106 |
98 Handle<HeapObject> ToHeapObject(InstructionOperand* operand) { | 107 Handle<HeapObject> ToHeapObject(InstructionOperand* op) { |
99 return ToConstant(operand).ToHeapObject(); | 108 return ToConstant(op).ToHeapObject(); |
100 } | 109 } |
101 | 110 |
102 Frame* frame() const { return gen_->frame(); } | 111 Frame* frame() const { return gen_->frame(); } |
103 Isolate* isolate() const { return gen_->isolate(); } | 112 Isolate* isolate() const { return gen_->isolate(); } |
104 Linkage* linkage() const { return gen_->linkage(); } | 113 Linkage* linkage() const { return gen_->linkage(); } |
105 | 114 |
106 protected: | 115 protected: |
107 CodeGenerator* gen_; | 116 CodeGenerator* gen_; |
108 Instruction* instr_; | 117 Instruction* instr_; |
109 }; | 118 }; |
110 | 119 |
111 | 120 |
112 // TODO(dcarney): generify this on bleeding_edge and replace this call | 121 // TODO(dcarney): generify this on bleeding_edge and replace this call |
113 // when merged. | 122 // when merged. |
114 static inline void FinishCode(MacroAssembler* masm) { | 123 static inline void FinishCode(MacroAssembler* masm) { |
115 #if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM | 124 #if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM |
116 masm->CheckConstPool(true, false); | 125 masm->CheckConstPool(true, false); |
117 #endif | 126 #endif |
118 } | 127 } |
119 | 128 |
120 } // namespace compiler | 129 } // namespace compiler |
121 } // namespace internal | 130 } // namespace internal |
122 } // namespace v8 | 131 } // namespace v8 |
123 | 132 |
124 #endif // V8_COMPILER_CODE_GENERATOR_IMPL_H | 133 #endif // V8_COMPILER_CODE_GENERATOR_IMPL_H |
OLD | NEW |