v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
code-generator-impl.h
Go to the documentation of this file.
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_BACKEND_CODE_GENERATOR_IMPL_H_
6#define V8_COMPILER_BACKEND_CODE_GENERATOR_IMPL_H_
7
13
14namespace v8 {
15namespace internal {
16namespace compiler {
17
18// Converts InstructionOperands from a given instruction to
19// architecture-specific
20// registers and operands after they have been assigned by the register
21// allocator.
23 public:
26
27 // -- Instruction operand accesses with conversions --------------------------
28
29 Register InputRegister(size_t index) const {
30 return ToRegister(instr_->InputAt(index));
31 }
32
34 return ToFloatRegister(instr_->InputAt(index));
35 }
36
38 return ToDoubleRegister(instr_->InputAt(index));
39 }
40
42 return ToSimd128Register(instr_->InputAt(index));
43 }
44
45 double InputDouble(size_t index) { return ToDouble(instr_->InputAt(index)); }
46
47 float InputFloat32(size_t index) { return ToFloat32(instr_->InputAt(index)); }
48
49 int32_t InputInt32(size_t index) {
50 return ToConstant(instr_->InputAt(index)).ToInt32();
51 }
52
53 uint32_t InputUint32(size_t index) {
55 }
56
57 int64_t InputInt64(size_t index) {
58 return ToConstant(instr_->InputAt(index)).ToInt64();
59 }
60
61 int8_t InputInt8(size_t index) {
62 return static_cast<int8_t>(InputInt32(index));
63 }
64
65 uint8_t InputUint8(size_t index) {
67 }
68
69 int16_t InputInt16(size_t index) {
70 return static_cast<int16_t>(InputInt32(index));
71 }
72
73 uint8_t InputInt3(size_t index) {
74 return static_cast<uint8_t>(InputInt32(index) & 0x7);
75 }
76
77 uint8_t InputInt4(size_t index) {
78 return static_cast<uint8_t>(InputInt32(index) & 0xF);
79 }
80
81 uint8_t InputInt5(size_t index) {
82 return static_cast<uint8_t>(InputInt32(index) & 0x1F);
83 }
84
85 uint8_t InputInt6(size_t index) {
86 return static_cast<uint8_t>(InputInt32(index) & 0x3F);
87 }
88
90 // Tags are stored shifted to the right so they fit into 32-bits.
91 uint64_t shifted_tag = InputUint32(index);
92 return static_cast<CodeEntrypointTag>(shifted_tag
94 }
95
99
100 Handle<Code> InputCode(size_t index) {
101 return ToCode(instr_->InputAt(index));
102 }
103
104 Label* InputLabel(size_t index) { return ToLabel(instr_->InputAt(index)); }
105
106 RpoNumber InputRpo(size_t index) {
107 return ToRpoNumber(instr_->InputAt(index));
108 }
109
110 Register OutputRegister(size_t index = 0) const {
111 return ToRegister(instr_->OutputAt(index));
112 }
113
114 Register TempRegister(size_t index) {
115 return ToRegister(instr_->TempAt(index));
116 }
117
119 return ToFloatRegister(instr_->OutputAt(index));
120 }
121
123 return ToDoubleRegister(instr_->OutputAt(index));
124 }
125
127 return ToDoubleRegister(instr_->TempAt(index));
128 }
129
133
135 return ToSimd128Register(instr_->TempAt(index));
136 }
137
138#if defined(V8_TARGET_ARCH_X64)
139 Simd256Register InputSimd256Register(size_t index) {
140 return ToSimd256Register(instr_->InputAt(index));
141 }
142
143 Simd256Register OutputSimd256Register() {
144 return ToSimd256Register(instr_->Output());
145 }
146
147 Simd256Register TempSimd256Register(size_t index) {
148 return ToSimd256Register(instr_->TempAt(index));
149 }
150#endif
151
152 // -- Conversions for operands -----------------------------------------------
153
155 return gen_->GetLabel(ToRpoNumber(op));
156 }
157
161
165
169
173
176#ifdef V8_TARGET_ARCH_X64
177 if (loc_op->IsSimd256Register()) {
178 return loc_op->GetSimd256RegisterAsSimd128();
179 }
180#endif
181 return loc_op->GetSimd128Register();
182 }
183
184#if defined(V8_TARGET_ARCH_X64)
185 Simd256Register ToSimd256Register(InstructionOperand* op) {
186 return LocationOperand::cast(op)->GetSimd256Register();
187 }
188#endif
189
191 if (op->IsImmediate()) {
192 return gen_->instructions()->GetImmediate(ImmediateOperand::cast(op));
193 }
194 return gen_->instructions()->GetConstant(
195 ConstantOperand::cast(op)->virtual_register());
196 }
197
199 return ToConstant(op).ToFloat64().value();
200 }
201
203
207
211
212 const Frame* frame() const { return gen_->frame(); }
216 Isolate* isolate() const { return gen_->isolate(); }
217 Linkage* linkage() const { return gen_->linkage(); }
218
219 protected:
222};
223
224// Deoptimization exit.
226 public:
241
244 }
245 int deoptimization_id() const {
247 return deoptimization_id_;
248 }
252 SourcePosition pos() const { return pos_; }
253 // The label for the deoptimization call.
254 Label* label() { return &label_; }
255 // The label after the deoptimization check, which will resume execution.
258 int translation_id() const { return translation_id_; }
259 int pc_offset() const { return pc_offset_; }
260 DeoptimizeKind kind() const { return kind_; }
261 DeoptimizeReason reason() const { return reason_; }
262 NodeId node_id() const { return node_id_; }
269 // Returns whether the deopt exit has already been emitted. Most deopt exits
270 // are emitted contiguously at the end of the code, but unconditional deopt
271 // exits (kArchDeoptimize) may be inlined where they are encountered.
272 bool emitted() const { return emitted_; }
273 void set_emitted() { emitted_ = true; }
274
275 private:
276 static const int kNoDeoptIndex = kMaxInt16 + 1;
283 const int pc_offset_;
289};
290
291// Generator for out-of-line code that is emitted after the main code is done.
292class OutOfLineCode : public ZoneObject {
293 public:
295 virtual ~OutOfLineCode();
296
297 virtual void Generate() = 0;
298
299 Label* entry() { return &entry_; }
300 Label* exit() { return &exit_; }
301 const Frame* frame() const { return frame_; }
302 MacroAssembler* masm() { return masm_; }
303 OutOfLineCode* next() const { return next_; }
304
305 private:
308 const Frame* const frame_;
311};
312
313} // namespace compiler
314} // namespace internal
315} // namespace v8
316
317#endif // V8_COMPILER_BACKEND_CODE_GENERATOR_IMPL_H_
constexpr double value() const
Definition double.h:158
FrameAccessState * frame_access_state() const
InstructionSequence * instructions() const
base::Double ToFloat64() const
ExternalReference ToExternalReference() const
IndirectHandle< Code > ToCode() const
void set_immediate_args(ZoneVector< ImmediateOperand * > *immediate_args)
void set_deoptimization_id(int deoptimization_id)
const ZoneVector< ImmediateOperand * > * immediate_args() const
DeoptimizationExit(SourcePosition pos, BytecodeOffset bailout_id, int translation_id, int pc_offset, DeoptimizeKind kind, DeoptimizeReason reason, NodeId node_id)
ZoneVector< ImmediateOperand * > * immediate_args_
DoubleRegister ToDoubleRegister(InstructionOperand *op)
FloatRegister ToFloatRegister(InstructionOperand *op)
Constant ToConstant(InstructionOperand *op) const
Simd128Register ToSimd128Register(InstructionOperand *op)
InstructionOperandConverter(CodeGenerator *gen, Instruction *instr)
Handle< Code > ToCode(InstructionOperand *op)
ExternalReference ToExternalReference(InstructionOperand *op)
Register ToRegister(InstructionOperand *op) const
Constant GetImmediate(const ImmediateOperand *op) const
Constant GetConstant(int virtual_register) const
const InstructionOperand * OutputAt(size_t i) const
const InstructionOperand * Output() const
const InstructionOperand * InputAt(size_t i) const
const InstructionOperand * TempAt(size_t i) const
Simd128Register GetSimd128Register() const
static LocationOperand * cast(InstructionOperand *op)
DoubleRegister GetDoubleRegister() const
Instruction * instr
V8_INLINE Dest bit_cast(Source const &source)
Definition macros.h:95
YMMRegister Simd256Register
constexpr int kMaxInt16
Definition globals.h:380
constexpr int kCodeEntrypointTagShift
BodyGen * gen
#define DCHECK(condition)
Definition logging.h:482