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 Register InputRegister(int index) {
29 return ToRegister(instr_->InputAt(index));
32 DoubleRegister InputDoubleRegister(int index) {
33 return ToDoubleRegister(instr_->InputAt(index));
36 double InputDouble(int index) { return ToDouble(instr_->InputAt(index)); }
38 int32_t InputInt32(int index) {
39 return ToConstant(instr_->InputAt(index)).ToInt32();
42 int8_t InputInt8(int index) { return static_cast<int8_t>(InputInt32(index)); }
44 int16_t InputInt16(int index) {
45 return static_cast<int16_t>(InputInt32(index));
48 uint8_t InputInt5(int index) {
49 return static_cast<uint8_t>(InputInt32(index) & 0x1F);
52 uint8_t InputInt6(int index) {
53 return static_cast<uint8_t>(InputInt32(index) & 0x3F);
56 Handle<HeapObject> InputHeapObject(int index) {
57 return ToHeapObject(instr_->InputAt(index));
60 Label* InputLabel(int index) {
61 return gen_->code()->GetLabel(InputRpo(index));
64 BasicBlock::RpoNumber InputRpo(int index) {
65 int rpo_number = InputInt32(index);
66 return BasicBlock::RpoNumber::FromInt(rpo_number);
69 Register OutputRegister(int index = 0) {
70 return ToRegister(instr_->OutputAt(index));
73 DoubleRegister OutputDoubleRegister() {
74 return ToDoubleRegister(instr_->Output());
77 Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); }
79 Register ToRegister(InstructionOperand* op) {
80 DCHECK(op->IsRegister());
81 return Register::FromAllocationIndex(op->index());
84 DoubleRegister ToDoubleRegister(InstructionOperand* op) {
85 DCHECK(op->IsDoubleRegister());
86 return DoubleRegister::FromAllocationIndex(op->index());
89 Constant ToConstant(InstructionOperand* operand) {
90 if (operand->IsImmediate()) {
91 return gen_->code()->GetImmediate(operand->index());
93 return gen_->code()->GetConstant(operand->index());
96 double ToDouble(InstructionOperand* operand) {
97 return ToConstant(operand).ToFloat64();
100 Handle<HeapObject> ToHeapObject(InstructionOperand* operand) {
101 return ToConstant(operand).ToHeapObject();
104 Frame* frame() const { return gen_->frame(); }
105 Isolate* isolate() const { return gen_->isolate(); }
106 Linkage* linkage() const { return gen_->linkage(); }
114 // TODO(dcarney): generify this on bleeding_edge and replace this call
116 static inline void FinishCode(MacroAssembler* masm) {
117 #if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM
118 masm->CheckConstPool(true, false);
122 } // namespace compiler
123 } // namespace internal
126 #endif // V8_COMPILER_CODE_GENERATOR_IMPL_H