summaryrefslogtreecommitdiff
path: root/chromium/v8/src/compiler/code-generator-impl.h
blob: 0be26269a318f917adc0a693398730ff7ea73142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2013 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_CODE_GENERATOR_IMPL_H_
#define V8_COMPILER_CODE_GENERATOR_IMPL_H_

#include "src/code-stubs.h"
#include "src/compiler/code-generator.h"
#include "src/compiler/instruction.h"
#include "src/compiler/linkage.h"
#include "src/compiler/opcodes.h"
#include "src/macro-assembler.h"

namespace v8 {
namespace internal {
namespace compiler {

// Converts InstructionOperands from a given instruction to
// architecture-specific
// registers and operands after they have been assigned by the register
// allocator.
class InstructionOperandConverter {
 public:
  InstructionOperandConverter(CodeGenerator* gen, Instruction* instr)
      : gen_(gen), instr_(instr) {}

  Register InputRegister(int index) {
    return ToRegister(instr_->InputAt(index));
  }

  DoubleRegister InputDoubleRegister(int index) {
    return ToDoubleRegister(instr_->InputAt(index));
  }

  double InputDouble(int index) { return ToDouble(instr_->InputAt(index)); }

  int32_t InputInt32(int index) {
    return ToConstant(instr_->InputAt(index)).ToInt32();
  }

  int8_t InputInt8(int index) { return static_cast<int8_t>(InputInt32(index)); }

  int16_t InputInt16(int index) {
    return static_cast<int16_t>(InputInt32(index));
  }

  uint8_t InputInt5(int index) {
    return static_cast<uint8_t>(InputInt32(index) & 0x1F);
  }

  uint8_t InputInt6(int index) {
    return static_cast<uint8_t>(InputInt32(index) & 0x3F);
  }

  Handle<HeapObject> InputHeapObject(int index) {
    return ToHeapObject(instr_->InputAt(index));
  }

  Label* InputLabel(int index) {
    return gen_->code()->GetLabel(InputRpo(index));
  }

  BasicBlock::RpoNumber InputRpo(int index) {
    int rpo_number = InputInt32(index);
    return BasicBlock::RpoNumber::FromInt(rpo_number);
  }

  Register OutputRegister(int index = 0) {
    return ToRegister(instr_->OutputAt(index));
  }

  DoubleRegister OutputDoubleRegister() {
    return ToDoubleRegister(instr_->Output());
  }

  Register TempRegister(int index) { return ToRegister(instr_->TempAt(index)); }

  Register ToRegister(InstructionOperand* op) {
    DCHECK(op->IsRegister());
    return Register::FromAllocationIndex(op->index());
  }

  DoubleRegister ToDoubleRegister(InstructionOperand* op) {
    DCHECK(op->IsDoubleRegister());
    return DoubleRegister::FromAllocationIndex(op->index());
  }

  Constant ToConstant(InstructionOperand* operand) {
    if (operand->IsImmediate()) {
      return gen_->code()->GetImmediate(operand->index());
    }
    return gen_->code()->GetConstant(operand->index());
  }

  double ToDouble(InstructionOperand* operand) {
    return ToConstant(operand).ToFloat64();
  }

  Handle<HeapObject> ToHeapObject(InstructionOperand* operand) {
    return ToConstant(operand).ToHeapObject();
  }

  Frame* frame() const { return gen_->frame(); }
  Isolate* isolate() const { return gen_->isolate(); }
  Linkage* linkage() const { return gen_->linkage(); }

 protected:
  CodeGenerator* gen_;
  Instruction* instr_;
};


// TODO(dcarney): generify this on bleeding_edge and replace this call
// when merged.
static inline void FinishCode(MacroAssembler* masm) {
#if V8_TARGET_ARCH_ARM64 || V8_TARGET_ARCH_ARM
  masm->CheckConstPool(true, false);
#endif
}

}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_CODE_GENERATOR_IMPL_H