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

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

Issue 1289863003: [interpreter]: Changes to interpreter builtins for accumulator and register file registers. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@fix_interpreter_initialization
Patch Set: Created 5 years, 4 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
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/interpreter-assembler.h" 5 #include "src/compiler/interpreter-assembler.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "src/compiler/graph.h" 9 #include "src/compiler/graph.h"
10 #include "src/compiler/instruction-selector.h" 10 #include "src/compiler/instruction-selector.h"
(...skipping 13 matching lines...) Expand all
24 24
25 25
26 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone, 26 InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone,
27 interpreter::Bytecode bytecode) 27 interpreter::Bytecode bytecode)
28 : bytecode_(bytecode), 28 : bytecode_(bytecode),
29 raw_assembler_(new RawMachineAssembler( 29 raw_assembler_(new RawMachineAssembler(
30 isolate, new (zone) Graph(zone), 30 isolate, new (zone) Graph(zone),
31 Linkage::GetInterpreterDispatchDescriptor(zone), kMachPtr, 31 Linkage::GetInterpreterDispatchDescriptor(zone), kMachPtr,
32 InstructionSelector::SupportedMachineOperatorFlags())), 32 InstructionSelector::SupportedMachineOperatorFlags())),
33 end_node_(nullptr), 33 end_node_(nullptr),
34 outgoing_accumulator_(nullptr),
34 code_generated_(false) {} 35 code_generated_(false) {}
35 36
36 37
37 InterpreterAssembler::~InterpreterAssembler() {} 38 InterpreterAssembler::~InterpreterAssembler() {}
38 39
39 40
40 Handle<Code> InterpreterAssembler::GenerateCode() { 41 Handle<Code> InterpreterAssembler::GenerateCode() {
41 DCHECK(!code_generated_); 42 DCHECK(!code_generated_);
42 43
43 End(); 44 End();
44 45
45 Schedule* schedule = raw_assembler_->Export(); 46 Schedule* schedule = raw_assembler_->Export();
46 // TODO(rmcilroy): use a non-testing code generator. 47 // TODO(rmcilroy): use a non-testing code generator.
47 Handle<Code> code = Pipeline::GenerateCodeForTesting( 48 Handle<Code> code = Pipeline::GenerateCodeForTesting(
48 isolate(), raw_assembler_->call_descriptor(), graph(), schedule); 49 isolate(), raw_assembler_->call_descriptor(), graph(), schedule);
49 50
50 #ifdef ENABLE_DISASSEMBLER 51 #ifdef ENABLE_DISASSEMBLER
51 if (FLAG_trace_ignition_codegen) { 52 if (FLAG_trace_ignition_codegen) {
52 OFStream os(stdout); 53 OFStream os(stdout);
53 code->Disassemble(interpreter::Bytecodes::ToString(bytecode_), os); 54 code->Disassemble(interpreter::Bytecodes::ToString(bytecode_), os);
54 os << std::flush; 55 os << std::flush;
55 } 56 }
56 #endif 57 #endif
57 58
58 code_generated_ = true; 59 code_generated_ = true;
59 return code; 60 return code;
60 } 61 }
61 62
62 63
64 Node* InterpreterAssembler::IncomingAccumulator() {
65 return raw_assembler_->Parameter(Linkage::kInterpreterAccumulatorParameter);
66 }
67
68
69 void InterpreterAssembler::StoreAccumulator(Node* value) {
70 DCHECK(!outgoing_accumulator_);
71 outgoing_accumulator_ = value;
72 }
73
74
75 Node* InterpreterAssembler::OutgoingAccumulator() {
76 if (outgoing_accumulator_) {
77 return outgoing_accumulator_;
78 } else {
79 return IncomingAccumulator();
80 }
81 }
82
83
84 Node* InterpreterAssembler::RegisterFilePointer() {
85 return raw_assembler_->Parameter(Linkage::kInterpreterRegisterFileParameter);
86 }
87
88
63 Node* InterpreterAssembler::BytecodeArrayPointer() { 89 Node* InterpreterAssembler::BytecodeArrayPointer() {
64 return raw_assembler_->Parameter(Linkage::kInterpreterBytecodeArrayParameter); 90 return raw_assembler_->Parameter(Linkage::kInterpreterBytecodeArrayParameter);
65 } 91 }
66 92
67 93
68 Node* InterpreterAssembler::BytecodeOffset() { 94 Node* InterpreterAssembler::BytecodeOffset() {
69 return raw_assembler_->Parameter( 95 return raw_assembler_->Parameter(
70 Linkage::kInterpreterBytecodeOffsetParameter); 96 Linkage::kInterpreterBytecodeOffsetParameter);
71 } 97 }
72 98
73 99
74 Node* InterpreterAssembler::DispatchTablePointer() { 100 Node* InterpreterAssembler::DispatchTablePointer() {
75 return raw_assembler_->Parameter(Linkage::kInterpreterDispatchTableParameter); 101 return raw_assembler_->Parameter(Linkage::kInterpreterDispatchTableParameter);
76 } 102 }
77 103
78 104
79 Node* InterpreterAssembler::FramePointer() {
80 return raw_assembler_->LoadFramePointer();
81 }
82
83
84 Node* InterpreterAssembler::RegisterFrameOffset(int index) {
85 DCHECK_LE(index, kMaxRegisterIndex);
86 return Int32Constant(kFirstRegisterOffsetFromFp -
87 (index << kPointerSizeLog2));
88 }
89
90
91 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) { 105 Node* InterpreterAssembler::RegisterFrameOffset(Node* index) {
92 return raw_assembler_->IntPtrSub( 106 return raw_assembler_->WordShl(index, Int32Constant(kPointerSizeLog2));
93 Int32Constant(kFirstRegisterOffsetFromFp),
94 raw_assembler_->WordShl(index, Int32Constant(kPointerSizeLog2)));
95 } 107 }
96 108
97 109
110 Node* InterpreterAssembler::LoadRegister(Node* reg_index) {
111 return raw_assembler_->Load(kMachPtr, RegisterFilePointer(),
112 RegisterFrameOffset(reg_index));
113 }
114
115
116 Node* InterpreterAssembler::StoreRegister(Node* value, Node* reg_index) {
117 return raw_assembler_->Store(kMachPtr, RegisterFilePointer(),
118 RegisterFrameOffset(reg_index), value);
119 }
120
121
98 Node* InterpreterAssembler::BytecodeOperand(int delta) { 122 Node* InterpreterAssembler::BytecodeOperand(int delta) {
99 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfOperands(bytecode_)); 123 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfOperands(bytecode_));
100 return raw_assembler_->Load( 124 return raw_assembler_->Load(
101 kMachUint8, BytecodeArrayPointer(), 125 kMachUint8, BytecodeArrayPointer(),
102 raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(1 + delta))); 126 raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(1 + delta)));
103 } 127 }
104 128
105 129
106 Node* InterpreterAssembler::LoadRegister(int index) { 130 Node* InterpreterAssembler::BytecodeOperandSignExtended(int delta) {
107 return raw_assembler_->Load(kMachPtr, FramePointer(), 131 DCHECK_LT(delta, interpreter::Bytecodes::NumberOfOperands(bytecode_));
108 RegisterFrameOffset(index)); 132 Node* load = raw_assembler_->Load(
133 kMachInt8, BytecodeArrayPointer(),
134 raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(1 + delta)));
135 // Ensure that we sign extend to full pointer size
136 if (kPointerSize == 8) {
137 load = raw_assembler_->ChangeInt32ToInt64(load);
138 }
139 return load;
109 } 140 }
110 141
111 142
112 Node* InterpreterAssembler::LoadRegister(Node* index) {
113 return raw_assembler_->Load(kMachPtr, FramePointer(),
114 RegisterFrameOffset(index));
115 }
116
117
118 Node* InterpreterAssembler::StoreRegister(Node* value, int index) {
119 return raw_assembler_->Store(kMachPtr, FramePointer(),
120 RegisterFrameOffset(index), value);
121 }
122
123
124 Node* InterpreterAssembler::StoreRegister(Node* value, Node* index) {
125 return raw_assembler_->Store(kMachPtr, FramePointer(),
126 RegisterFrameOffset(index), value);
127 }
128
129
130 void InterpreterAssembler::Return() { 143 void InterpreterAssembler::Return() {
131 Node* exit_trampoline_code_object = 144 Node* exit_trampoline_code_object =
132 HeapConstant(Unique<HeapObject>::CreateImmovable( 145 HeapConstant(Unique<HeapObject>::CreateImmovable(
133 isolate()->builtins()->InterpreterExitTrampoline())); 146 isolate()->builtins()->InterpreterExitTrampoline()));
134 // If the order of the parameters you need to change the call signature below. 147 // If the order of the parameters you need to change the call signature below.
135 STATIC_ASSERT(0 == Linkage::kInterpreterBytecodeOffsetParameter); 148 STATIC_ASSERT(0 == Linkage::kInterpreterAccumulatorParameter);
136 STATIC_ASSERT(1 == Linkage::kInterpreterBytecodeArrayParameter); 149 STATIC_ASSERT(1 == Linkage::kInterpreterRegisterFileParameter);
137 STATIC_ASSERT(2 == Linkage::kInterpreterDispatchTableParameter); 150 STATIC_ASSERT(2 == Linkage::kInterpreterBytecodeOffsetParameter);
138 Node* tail_call = graph()->NewNode( 151 STATIC_ASSERT(3 == Linkage::kInterpreterBytecodeArrayParameter);
139 common()->TailCall(call_descriptor()), exit_trampoline_code_object, 152 STATIC_ASSERT(4 == Linkage::kInterpreterDispatchTableParameter);
140 BytecodeOffset(), BytecodeArrayPointer(), DispatchTablePointer(), 153 Node* tail_call = raw_assembler_->TailCallInterpreterDispatch(
141 graph()->start(), graph()->start()); 154 call_descriptor(), exit_trampoline_code_object, OutgoingAccumulator(),
142 schedule()->AddTailCall(raw_assembler_->CurrentBlock(), tail_call); 155 RegisterFilePointer(), BytecodeOffset(), BytecodeArrayPointer(),
156 DispatchTablePointer());
143 // This should always be the end node. 157 // This should always be the end node.
144 SetEndInput(tail_call); 158 SetEndInput(tail_call);
145 } 159 }
146 160
147 161
148 Node* InterpreterAssembler::Advance(int delta) { 162 Node* InterpreterAssembler::Advance(int delta) {
149 return raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(delta)); 163 return raw_assembler_->IntPtrAdd(BytecodeOffset(), Int32Constant(delta));
150 } 164 }
151 165
152 166
153 void InterpreterAssembler::Dispatch() { 167 void InterpreterAssembler::Dispatch() {
154 Node* new_bytecode_offset = Advance(interpreter::Bytecodes::Size(bytecode_)); 168 Node* new_bytecode_offset = Advance(interpreter::Bytecodes::Size(bytecode_));
155 Node* target_bytecode = raw_assembler_->Load( 169 Node* target_bytecode = raw_assembler_->Load(
156 kMachUint8, BytecodeArrayPointer(), new_bytecode_offset); 170 kMachUint8, BytecodeArrayPointer(), new_bytecode_offset);
157 171
158 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion 172 // TODO(rmcilroy): Create a code target dispatch table to avoid conversion
159 // from code object on every dispatch. 173 // from code object on every dispatch.
160 Node* target_code_object = raw_assembler_->Load( 174 Node* target_code_object = raw_assembler_->Load(
161 kMachPtr, DispatchTablePointer(), 175 kMachPtr, DispatchTablePointer(),
162 raw_assembler_->Word32Shl(target_bytecode, 176 raw_assembler_->Word32Shl(target_bytecode,
163 Int32Constant(kPointerSizeLog2))); 177 Int32Constant(kPointerSizeLog2)));
164 178
165 // If the order of the parameters you need to change the call signature below. 179 // If the order of the parameters you need to change the call signature below.
166 STATIC_ASSERT(0 == Linkage::kInterpreterBytecodeOffsetParameter); 180 STATIC_ASSERT(0 == Linkage::kInterpreterAccumulatorParameter);
167 STATIC_ASSERT(1 == Linkage::kInterpreterBytecodeArrayParameter); 181 STATIC_ASSERT(1 == Linkage::kInterpreterRegisterFileParameter);
168 STATIC_ASSERT(2 == Linkage::kInterpreterDispatchTableParameter); 182 STATIC_ASSERT(2 == Linkage::kInterpreterBytecodeOffsetParameter);
169 Node* tail_call = graph()->NewNode( 183 STATIC_ASSERT(3 == Linkage::kInterpreterBytecodeArrayParameter);
170 common()->TailCall(call_descriptor()), target_code_object, 184 STATIC_ASSERT(4 == Linkage::kInterpreterDispatchTableParameter);
171 new_bytecode_offset, BytecodeArrayPointer(), DispatchTablePointer(), 185 Node* tail_call = raw_assembler_->TailCallInterpreterDispatch(
172 graph()->start(), graph()->start()); 186 call_descriptor(), target_code_object, OutgoingAccumulator(),
173 schedule()->AddTailCall(raw_assembler_->CurrentBlock(), tail_call); 187 RegisterFilePointer(), new_bytecode_offset, BytecodeArrayPointer(),
188 DispatchTablePointer());
174 // This should always be the end node. 189 // This should always be the end node.
175 SetEndInput(tail_call); 190 SetEndInput(tail_call);
176 } 191 }
177 192
178 193
179 void InterpreterAssembler::SetEndInput(Node* input) { 194 void InterpreterAssembler::SetEndInput(Node* input) {
180 DCHECK(!end_node_); 195 DCHECK(!end_node_);
181 end_node_ = input; 196 end_node_ = input;
182 } 197 }
183 198
184 199
185 void InterpreterAssembler::End() { 200 void InterpreterAssembler::End() {
186 DCHECK(end_node_); 201 DCHECK(end_node_);
187 // TODO(rmcilroy): Support more than 1 end input. 202 // TODO(rmcilroy): Support more than 1 end input.
188 Node* end = graph()->NewNode(common()->End(1), end_node_); 203 Node* end = graph()->NewNode(raw_assembler_->common()->End(1), end_node_);
189 graph()->SetEnd(end); 204 graph()->SetEnd(end);
190 } 205 }
191 206
192 207
193 // RawMachineAssembler delegate helpers: 208 // RawMachineAssembler delegate helpers:
194 Isolate* InterpreterAssembler::isolate() { return raw_assembler_->isolate(); } 209 Isolate* InterpreterAssembler::isolate() { return raw_assembler_->isolate(); }
195 210
196 211
197 Graph* InterpreterAssembler::graph() { return raw_assembler_->graph(); } 212 Graph* InterpreterAssembler::graph() { return raw_assembler_->graph(); }
198 213
199 214
200 CallDescriptor* InterpreterAssembler::call_descriptor() const { 215 CallDescriptor* InterpreterAssembler::call_descriptor() const {
201 return raw_assembler_->call_descriptor(); 216 return raw_assembler_->call_descriptor();
202 } 217 }
203 218
204 219
205 Schedule* InterpreterAssembler::schedule() { 220 Schedule* InterpreterAssembler::schedule() {
206 return raw_assembler_->schedule(); 221 return raw_assembler_->schedule();
207 } 222 }
208 223
209 224
210 MachineOperatorBuilder* InterpreterAssembler::machine() {
211 return raw_assembler_->machine();
212 }
213
214
215 CommonOperatorBuilder* InterpreterAssembler::common() {
216 return raw_assembler_->common();
217 }
218
219
220 Node* InterpreterAssembler::Int32Constant(int value) { 225 Node* InterpreterAssembler::Int32Constant(int value) {
221 return raw_assembler_->Int32Constant(value); 226 return raw_assembler_->Int32Constant(value);
222 } 227 }
223 228
224 229
225 Node* InterpreterAssembler::NumberConstant(double value) { 230 Node* InterpreterAssembler::NumberConstant(double value) {
226 return raw_assembler_->NumberConstant(value); 231 return raw_assembler_->NumberConstant(value);
227 } 232 }
228 233
229 234
230 Node* InterpreterAssembler::HeapConstant(Unique<HeapObject> object) { 235 Node* InterpreterAssembler::HeapConstant(Unique<HeapObject> object) {
231 return raw_assembler_->HeapConstant(object); 236 return raw_assembler_->HeapConstant(object);
232 } 237 }
233 238
234
235 } // namespace interpreter 239 } // namespace interpreter
236 } // namespace internal 240 } // namespace internal
237 } // namespace v8 241 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698