Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / 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   Register InputRegister(int index) {
29     return ToRegister(instr_->InputAt(index));
30   }
31
32   DoubleRegister InputDoubleRegister(int index) {
33     return ToDoubleRegister(instr_->InputAt(index));
34   }
35
36   double InputDouble(int index) { return ToDouble(instr_->InputAt(index)); }
37
38   int32_t InputInt32(int index) {
39     return ToConstant(instr_->InputAt(index)).ToInt32();
40   }
41
42   int8_t InputInt8(int index) { return static_cast<int8_t>(InputInt32(index)); }
43
44   int16_t InputInt16(int index) {
45     return static_cast<int16_t>(InputInt32(index));
46   }
47
48   uint8_t InputInt5(int index) {
49     return static_cast<uint8_t>(InputInt32(index) & 0x1F);
50   }
51
52   uint8_t InputInt6(int index) {
53     return static_cast<uint8_t>(InputInt32(index) & 0x3F);
54   }
55
56   Handle<HeapObject> InputHeapObject(int index) {
57     return ToHeapObject(instr_->InputAt(index));
58   }
59
60   Label* InputLabel(int index) {
61     return gen_->code()->GetLabel(InputRpo(index));
62   }
63
64   BasicBlock::RpoNumber InputRpo(int index) {
65     int rpo_number = InputInt32(index);
66     return BasicBlock::RpoNumber::FromInt(rpo_number);
67   }
68
69   Register OutputRegister(int index = 0) {
70     return ToRegister(instr_->OutputAt(index));
71   }
72
73   DoubleRegister OutputDoubleRegister() {
74     return ToDoubleRegister(instr_->Output());
75   }
76
77   Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); }
78
79   Register ToRegister(InstructionOperand* op) {
80     DCHECK(op->IsRegister());
81     return Register::FromAllocationIndex(op->index());
82   }
83
84   DoubleRegister ToDoubleRegister(InstructionOperand* op) {
85     DCHECK(op->IsDoubleRegister());
86     return DoubleRegister::FromAllocationIndex(op->index());
87   }
88
89   Constant ToConstant(InstructionOperand* operand) {
90     if (operand->IsImmediate()) {
91       return gen_->code()->GetImmediate(operand->index());
92     }
93     return gen_->code()->GetConstant(operand->index());
94   }
95
96   double ToDouble(InstructionOperand* operand) {
97     return ToConstant(operand).ToFloat64();
98   }
99
100   Handle<HeapObject> ToHeapObject(InstructionOperand* operand) {
101     return ToConstant(operand).ToHeapObject();
102   }
103
104   Frame* frame() const { return gen_->frame(); }
105   Isolate* isolate() const { return gen_->isolate(); }
106   Linkage* linkage() const { return gen_->linkage(); }
107
108  protected:
109   CodeGenerator* gen_;
110   Instruction* instr_;
111 };
112
113
114 // TODO(dcarney): generify this on bleeding_edge and replace this call
115 // when merged.
116 static inline void FinishCode(MacroAssembler* masm) {
117 #if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM
118   masm->CheckConstPool(true, false);
119 #endif
120 }
121
122 }  // namespace compiler
123 }  // namespace internal
124 }  // namespace v8
125
126 #endif  // V8_COMPILER_CODE_GENERATOR_IMPL_H