deps: update v8 to 4.3.61.21
[platform/upstream/nodejs.git] / deps / v8 / src / compiler / code-generator-impl.h
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.
4
5 #ifndef V8_COMPILER_CODE_GENERATOR_IMPL_H_
6 #define V8_COMPILER_CODE_GENERATOR_IMPL_H_
7
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"
14
15 namespace v8 {
16 namespace internal {
17 namespace compiler {
18
19 // Converts InstructionOperands from a given instruction to
20 // architecture-specific
21 // registers and operands after they have been assigned by the register
22 // allocator.
23 class InstructionOperandConverter {
24  public:
25   InstructionOperandConverter(CodeGenerator* gen, Instruction* instr)
26       : gen_(gen), instr_(instr) {}
27
28   // -- Instruction operand accesses with conversions --------------------------
29
30   Register InputRegister(size_t index) {
31     return ToRegister(instr_->InputAt(index));
32   }
33
34   DoubleRegister InputDoubleRegister(size_t index) {
35     return ToDoubleRegister(instr_->InputAt(index));
36   }
37
38   double InputDouble(size_t index) { return ToDouble(instr_->InputAt(index)); }
39
40   int32_t InputInt32(size_t index) {
41     return ToConstant(instr_->InputAt(index)).ToInt32();
42   }
43
44   int8_t InputInt8(size_t index) {
45     return static_cast<int8_t>(InputInt32(index));
46   }
47
48   int16_t InputInt16(size_t index) {
49     return static_cast<int16_t>(InputInt32(index));
50   }
51
52   uint8_t InputInt5(size_t index) {
53     return static_cast<uint8_t>(InputInt32(index) & 0x1F);
54   }
55
56   uint8_t InputInt6(size_t index) {
57     return static_cast<uint8_t>(InputInt32(index) & 0x3F);
58   }
59
60   Handle<HeapObject> InputHeapObject(size_t index) {
61     return ToHeapObject(instr_->InputAt(index));
62   }
63
64   Label* InputLabel(size_t index) { return ToLabel(instr_->InputAt(index)); }
65
66   RpoNumber InputRpo(size_t index) {
67     return ToRpoNumber(instr_->InputAt(index));
68   }
69
70   Register OutputRegister(size_t index = 0) {
71     return ToRegister(instr_->OutputAt(index));
72   }
73
74   Register TempRegister(size_t index) {
75     return ToRegister(instr_->TempAt(index));
76   }
77
78   DoubleRegister OutputDoubleRegister() {
79     return ToDoubleRegister(instr_->Output());
80   }
81
82   // -- Conversions for operands -----------------------------------------------
83
84   Label* ToLabel(InstructionOperand* op) {
85     return gen_->GetLabel(ToRpoNumber(op));
86   }
87
88   RpoNumber ToRpoNumber(InstructionOperand* op) {
89     return ToConstant(op).ToRpoNumber();
90   }
91
92   Register ToRegister(InstructionOperand* op) {
93     DCHECK(op->IsRegister());
94     return Register::FromAllocationIndex(op->index());
95   }
96
97   DoubleRegister ToDoubleRegister(InstructionOperand* op) {
98     DCHECK(op->IsDoubleRegister());
99     return DoubleRegister::FromAllocationIndex(op->index());
100   }
101
102   Constant ToConstant(InstructionOperand* op) {
103     if (op->IsImmediate()) {
104       return gen_->code()->GetImmediate(op->index());
105     }
106     return gen_->code()->GetConstant(op->index());
107   }
108
109   double ToDouble(InstructionOperand* op) { return ToConstant(op).ToFloat64(); }
110
111   Handle<HeapObject> ToHeapObject(InstructionOperand* op) {
112     return ToConstant(op).ToHeapObject();
113   }
114
115   Frame* frame() const { return gen_->frame(); }
116   Isolate* isolate() const { return gen_->isolate(); }
117   Linkage* linkage() const { return gen_->linkage(); }
118
119  protected:
120   CodeGenerator* gen_;
121   Instruction* instr_;
122 };
123
124
125 // Generator for out-of-line code that is emitted after the main code is done.
126 class OutOfLineCode : public ZoneObject {
127  public:
128   explicit OutOfLineCode(CodeGenerator* gen);
129   virtual ~OutOfLineCode();
130
131   virtual void Generate() = 0;
132
133   Label* entry() { return &entry_; }
134   Label* exit() { return &exit_; }
135   MacroAssembler* masm() const { return masm_; }
136   OutOfLineCode* next() const { return next_; }
137
138  private:
139   Label entry_;
140   Label exit_;
141   MacroAssembler* const masm_;
142   OutOfLineCode* const next_;
143 };
144
145
146 // TODO(dcarney): generify this on bleeding_edge and replace this call
147 // when merged.
148 static inline void FinishCode(MacroAssembler* masm) {
149 #if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM
150   masm->CheckConstPool(true, false);
151 #elif V8_TARGET_ARCH_IA32 || V8_TARGET_ARCH_X64
152   masm->ud2();
153 #endif
154 }
155
156 }  // namespace compiler
157 }  // namespace internal
158 }  // namespace v8
159
160 #endif  // V8_COMPILER_CODE_GENERATOR_IMPL_H