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
3 // found in the LICENSE file.
5 #ifndef V8_COMPILER_CODE_GENERATOR_IMPL_H_
6 #define V8_COMPILER_CODE_GENERATOR_IMPL_H_
8 #include "src/code-stubs.h"
9 #include "src/compiler/code-generator.h"
10 #include "src/compiler/instruction.h"
11 #include "src/compiler/linkage.h"
12 #include "src/compiler/opcodes.h"
13 #include "src/macro-assembler.h"
19 // Converts InstructionOperands from a given instruction to
20 // architecture-specific
21 // registers and operands after they have been assigned by the register
23 class InstructionOperandConverter {
25 InstructionOperandConverter(CodeGenerator* gen, Instruction* instr)
26 : gen_(gen), instr_(instr) {}
28 // -- Instruction operand accesses with conversions --------------------------
30 Register InputRegister(int index) {
31 return ToRegister(instr_->InputAt(index));
34 DoubleRegister InputDoubleRegister(int index) {
35 return ToDoubleRegister(instr_->InputAt(index));
38 double InputDouble(int index) { return ToDouble(instr_->InputAt(index)); }
40 int32_t InputInt32(int index) {
41 return ToConstant(instr_->InputAt(index)).ToInt32();
44 int8_t InputInt8(int index) { return static_cast<int8_t>(InputInt32(index)); }
46 int16_t InputInt16(int index) {
47 return static_cast<int16_t>(InputInt32(index));
50 uint8_t InputInt5(int index) {
51 return static_cast<uint8_t>(InputInt32(index) & 0x1F);
54 uint8_t InputInt6(int index) {
55 return static_cast<uint8_t>(InputInt32(index) & 0x3F);
58 Handle<HeapObject> InputHeapObject(int index) {
59 return ToHeapObject(instr_->InputAt(index));
62 Label* InputLabel(int index) { return ToLabel(instr_->InputAt(index)); }
64 BasicBlock::RpoNumber InputRpo(int index) {
65 return ToRpoNumber(instr_->InputAt(index));
68 Register OutputRegister(int index = 0) {
69 return ToRegister(instr_->OutputAt(index));
72 Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); }
74 DoubleRegister OutputDoubleRegister() {
75 return ToDoubleRegister(instr_->Output());
78 // -- Conversions for operands -----------------------------------------------
80 Label* ToLabel(InstructionOperand* op) {
81 return gen_->GetLabel(ToRpoNumber(op));
84 BasicBlock::RpoNumber ToRpoNumber(InstructionOperand* op) {
85 return ToConstant(op).ToRpoNumber();
88 Register ToRegister(InstructionOperand* op) {
89 DCHECK(op->IsRegister());
90 return Register::FromAllocationIndex(op->index());
93 DoubleRegister ToDoubleRegister(InstructionOperand* op) {
94 DCHECK(op->IsDoubleRegister());
95 return DoubleRegister::FromAllocationIndex(op->index());
98 Constant ToConstant(InstructionOperand* op) {
99 if (op->IsImmediate()) {
100 return gen_->code()->GetImmediate(op->index());
102 return gen_->code()->GetConstant(op->index());
105 double ToDouble(InstructionOperand* op) { return ToConstant(op).ToFloat64(); }
107 Handle<HeapObject> ToHeapObject(InstructionOperand* op) {
108 return ToConstant(op).ToHeapObject();
111 Frame* frame() const { return gen_->frame(); }
112 Isolate* isolate() const { return gen_->isolate(); }
113 Linkage* linkage() const { return gen_->linkage(); }
121 // Generator for out-of-line code that is emitted after the main code is done.
122 class OutOfLineCode : public ZoneObject {
124 explicit OutOfLineCode(CodeGenerator* gen);
125 virtual ~OutOfLineCode();
127 virtual void Generate() = 0;
129 Label* entry() { return &entry_; }
130 Label* exit() { return &exit_; }
131 MacroAssembler* masm() const { return masm_; }
132 OutOfLineCode* next() const { return next_; }
137 MacroAssembler* const masm_;
138 OutOfLineCode* const next_;
142 // TODO(dcarney): generify this on bleeding_edge and replace this call
144 static inline void FinishCode(MacroAssembler* masm) {
145 #if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM
146 masm->CheckConstPool(true, false);
147 #elif V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
152 } // namespace compiler
153 } // namespace internal
156 #endif // V8_COMPILER_CODE_GENERATOR_IMPL_H