Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(509)

Side by Side Diff: src/compiler/interpreter-assembler.cc

Issue 1239793002: [interpreter] Add basic framework for bytecode handler code generation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add comment to count macro. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 #include "src/compiler/interpreter-assembler.h"
6
7 #include <ostream>
8
9 #include "src/compiler/graph.h"
10 #include "src/compiler/instruction-selector.h"
11 #include "src/compiler/linkage.h"
12 #include "src/compiler/machine-type.h"
13 #include "src/compiler/pipeline.h"
14 #include "src/compiler/raw-machine-assembler.h"
15 #include "src/compiler/schedule.h"
16 #include "src/frames.h"
17 #include "src/interpreter/bytecodes.h"
18 #include "src/macro-assembler.h"
19 #include "src/zone.h"
20
21 namespace v8 {
22 namespace internal {
23 namespace compiler {
24
25
26 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone,
27 interpreter::Bytecode bytecode)
28 : zone_(zone),
29 bytecode_(bytecode),
30 raw_assembler_(new RawMachineAssembler(
31 isolate, new (zone) Graph(zone),
32 Linkage::GetInterpreterDispatchDescriptor(
33 zone, interpreter::Bytecodes::IsReturn(bytecode)),
34 kMachPtr, InstructionSelector::SupportedMachineOperatorFlags())),
35 code_generated_(false) {}
36
37
38 InterpreterAssembler::~InterpreterAssembler() {}
39
40
41 Handle<Code> InterpreterAssembler::GenerateCode() {
42 DCHECK(!code_generated_);
43
44 Schedule* schedule = raw_assembler_->Export();
45 // TODO(rmcilroy): use a non-testing code generator.
46 Handle<Code> code = Pipeline::GenerateCodeForTesting(
47 isolate(), raw_assembler_->call_descriptor(), graph(), schedule);
48
49 #ifdef ENABLE_DISASSEMBLER
50 if (FLAG_trace_ignition_codegen) {
51 OFStream os(stdout);
52 code->Disassemble(interpreter::Bytecodes::ToString(bytecode_), os);
53 os << std::flush;
54 }
55 #endif
56
57 code_generated_ = true;
58 return code;
59 }
60
61
62 Node* InterpreterAssembler::BytecodePointer() {
63 return raw_assembler_->Parameter(kBytecodePointerParameter);
64 }
65
66
67 Node* InterpreterAssembler::DispatchTablePointer() {
68 return raw_assembler_->Parameter(kDispatchTablePointerParameter);
69 }
70
71
72 Node* InterpreterAssembler::FramePointer() {
73 return raw_assembler_->LoadFramePointer();
74 }
75
76
77 Node* InterpreterAssembler::RegisterFrameOffset(int index) {
78 return Int32Constant(-StandardFrameConstants::kFixedFrameSizeFromFp -
79 (index << kPointerSizeLog2));
80 }
81
82
83 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) {
84 return raw_assembler_->Int32Sub(
85 Int32Constant(-StandardFrameConstants::kFixedFrameSizeFromFp),
86 raw_assembler_->WordShl(index, Int32Constant(kPointerSizeLog2)));
87 }
88
89
90 Node* InterpreterAssembler::BytecodeArg(int delta) {
91 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfArguments(bytecode_));
92 return raw_assembler_->Load(kMachUint8, BytecodePointer(),
93 Int32Constant(1 + delta));
94 }
95
96
97 Node* InterpreterAssembler::LoadRegister(int index) {
98 return raw_assembler_->Load(kMachPtr, FramePointer(),
99 RegisterFrameOffset(index));
100 }
101
102
103 Node* InterpreterAssembler::LoadRegister(Node* index) {
104 return raw_assembler_->Load(kMachPtr, FramePointer(),
105 RegisterFrameOffset(index));
106 }
107
108
109 void InterpreterAssembler::StoreRegister(Node* value, int index) {
110 raw_assembler_->Store(kMachPtr, FramePointer(), RegisterFrameOffset(index),
111 value);
112 }
113
114
115 void InterpreterAssembler::StoreRegister(Node* value, Node* index) {
116 raw_assembler_->Store(kMachPtr, FramePointer(), RegisterFrameOffset(index),
117 value);
118 }
119
120
121 void InterpreterAssembler::Return(Node* value) {
122 return raw_assembler_->Return(value);
123 }
124
125
126 Node* InterpreterAssembler::Advance(int delta) {
127 return raw_assembler_->IntPtrAdd(BytecodePointer(), Int32Constant(delta));
128 }
129
130
131 void InterpreterAssembler::Dispatch() {
132 Node* new_bytecode_pointer = Advance(interpreter::Bytecodes::Size(bytecode_));
133 Node* target_bytecode =
134 raw_assembler_->Load(kMachUint8, new_bytecode_pointer);
135
136 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion
137 // from code object on every dispatch.
138 Node* target_code_object = raw_assembler_->Load(
139 kMachPtr, DispatchTablePointer(),
140 raw_assembler_->WordShl(target_bytecode,
141 Int32Constant(kPointerSizeLog2)));
142
143 // If the order of the parameters you need to change the call signature below.
144 DCHECK_EQ(0, kBytecodePointerParameter);
145 DCHECK_EQ(1, kDispatchTablePointerParameter);
146 Node* tail_call = graph()->NewNode(
147 common()->TailCall(
148 Linkage::GetInterpreterDispatchDescriptor(zone_, false)),
149 target_code_object, new_bytecode_pointer, DispatchTablePointer());
150 schedule()->AddTailCall(raw_assembler_->CurrentBlock(), tail_call);
151 }
152
153
154 // RawMachineAssembler delegate helpers:
155 Isolate* InterpreterAssembler::isolate() { return raw_assembler_->isolate(); }
156
157
158 Graph* InterpreterAssembler::graph() { return raw_assembler_->graph(); }
159
160
161 Schedule* InterpreterAssembler::schedule() {
162 return raw_assembler_->schedule();
163 }
164
165
166 MachineOperatorBuilder* InterpreterAssembler::machine() {
167 return raw_assembler_->machine();
168 }
169
170
171 CommonOperatorBuilder* InterpreterAssembler::common() {
172 return raw_assembler_->common();
173 }
174
175
176 Node* InterpreterAssembler::Int32Constant(int value) {
177 return raw_assembler_->Int32Constant(value);
178 }
179
180
181 Node* InterpreterAssembler::NumberConstant(double value) {
182 return raw_assembler_->NumberConstant(value);
183 }
184
185
186 } // namespace interpreter
187 } // namespace internal
188 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698