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

Side by Side Diff: src/compiler/code-stub-assembler.cc

Issue 1673333004: [Interpreter] Make InterpreterAssembler a subclass of CodeStubAssembler. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Address review comments. Created 4 years, 10 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
« no previous file with comments | « src/compiler/code-stub-assembler.h ('k') | src/compiler/interpreter-assembler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/code-stub-assembler.h" 5 #include "src/compiler/code-stub-assembler.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
11 #include "src/compiler/instruction-selector.h" 11 #include "src/compiler/instruction-selector.h"
12 #include "src/compiler/linkage.h" 12 #include "src/compiler/linkage.h"
13 #include "src/compiler/pipeline.h" 13 #include "src/compiler/pipeline.h"
14 #include "src/compiler/raw-machine-assembler.h" 14 #include "src/compiler/raw-machine-assembler.h"
15 #include "src/compiler/schedule.h" 15 #include "src/compiler/schedule.h"
16 #include "src/frames.h" 16 #include "src/frames.h"
17 #include "src/interface-descriptors.h" 17 #include "src/interface-descriptors.h"
18 #include "src/interpreter/bytecodes.h" 18 #include "src/interpreter/bytecodes.h"
19 #include "src/machine-type.h" 19 #include "src/machine-type.h"
20 #include "src/macro-assembler.h" 20 #include "src/macro-assembler.h"
21 #include "src/zone.h" 21 #include "src/zone.h"
22 22
23 namespace v8 { 23 namespace v8 {
24 namespace internal { 24 namespace internal {
25 namespace compiler { 25 namespace compiler {
26 26
27 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone, 27 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
28 const CallInterfaceDescriptor& descriptor, 28 const CallInterfaceDescriptor& descriptor,
29 Code::Flags flags, const char* name) 29 Code::Flags flags, const char* name,
30 size_t result_size)
30 : raw_assembler_(new RawMachineAssembler( 31 : raw_assembler_(new RawMachineAssembler(
31 isolate, new (zone) Graph(zone), 32 isolate, new (zone) Graph(zone),
32 Linkage::GetStubCallDescriptor(isolate, zone, descriptor, 0, 33 Linkage::GetStubCallDescriptor(
33 CallDescriptor::kNoFlags))), 34 isolate, zone, descriptor, descriptor.GetStackParameterCount(),
35 CallDescriptor::kNoFlags, Operator::kNoProperties,
36 MachineType::AnyTagged(), result_size))),
34 flags_(flags), 37 flags_(flags),
35 name_(name), 38 name_(name),
36 code_generated_(false), 39 code_generated_(false),
37 variables_(zone) {} 40 variables_(zone) {}
38 41
39 CodeStubAssembler::~CodeStubAssembler() {} 42 CodeStubAssembler::~CodeStubAssembler() {}
40 43
44 void CodeStubAssembler::CallPrologue() {}
45
46 void CodeStubAssembler::CallEpilogue() {}
41 47
42 Handle<Code> CodeStubAssembler::GenerateCode() { 48 Handle<Code> CodeStubAssembler::GenerateCode() {
43 DCHECK(!code_generated_); 49 DCHECK(!code_generated_);
44 50
45 Schedule* schedule = raw_assembler_->Export(); 51 Schedule* schedule = raw_assembler_->Export();
46 Handle<Code> code = Pipeline::GenerateCodeForCodeStub( 52 Handle<Code> code = Pipeline::GenerateCodeForCodeStub(
47 isolate(), raw_assembler_->call_descriptor(), graph(), schedule, flags_, 53 isolate(), raw_assembler_->call_descriptor(), graph(), schedule, flags_,
48 name_); 54 name_);
49 55
50 code_generated_ = true; 56 code_generated_ = true;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 96 }
91 97
92 void CodeStubAssembler::Bind(CodeStubAssembler::Label* label) { 98 void CodeStubAssembler::Bind(CodeStubAssembler::Label* label) {
93 return label->Bind(); 99 return label->Bind();
94 } 100 }
95 101
96 Node* CodeStubAssembler::LoadFramePointer() { 102 Node* CodeStubAssembler::LoadFramePointer() {
97 return raw_assembler_->LoadFramePointer(); 103 return raw_assembler_->LoadFramePointer();
98 } 104 }
99 105
106 Node* CodeStubAssembler::LoadStackPointer() {
107 return raw_assembler_->LoadStackPointer();
108 }
109
100 Node* CodeStubAssembler::SmiShiftBitsConstant() { 110 Node* CodeStubAssembler::SmiShiftBitsConstant() {
101 return Int32Constant(kSmiShiftSize + kSmiTagSize); 111 return Int32Constant(kSmiShiftSize + kSmiTagSize);
102 } 112 }
103 113
104 114
105 Node* CodeStubAssembler::SmiTag(Node* value) { 115 Node* CodeStubAssembler::SmiTag(Node* value) {
106 return raw_assembler_->WordShl(value, SmiShiftBitsConstant()); 116 return raw_assembler_->WordShl(value, SmiShiftBitsConstant());
107 } 117 }
108 118
109 119
110 Node* CodeStubAssembler::SmiUntag(Node* value) { 120 Node* CodeStubAssembler::SmiUntag(Node* value) {
111 return raw_assembler_->WordSar(value, SmiShiftBitsConstant()); 121 return raw_assembler_->WordSar(value, SmiShiftBitsConstant());
112 } 122 }
113 123
114 #define DEFINE_CODE_STUB_ASSEMBER_BINARY_OP(name) \ 124 #define DEFINE_CODE_STUB_ASSEMBER_BINARY_OP(name) \
115 Node* CodeStubAssembler::name(Node* a, Node* b) { \ 125 Node* CodeStubAssembler::name(Node* a, Node* b) { \
116 return raw_assembler_->name(a, b); \ 126 return raw_assembler_->name(a, b); \
117 } 127 }
118 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_BINARY_OP) 128 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_BINARY_OP)
119 #undef DEFINE_CODE_STUB_ASSEMBER_BINARY_OP 129 #undef DEFINE_CODE_STUB_ASSEMBER_BINARY_OP
120 130
131 Node* CodeStubAssembler::ChangeInt32ToInt64(Node* value) {
132 return raw_assembler_->ChangeInt32ToInt64(value);
133 }
134
121 Node* CodeStubAssembler::WordShl(Node* value, int shift) { 135 Node* CodeStubAssembler::WordShl(Node* value, int shift) {
122 return raw_assembler_->WordShl(value, Int32Constant(shift)); 136 return raw_assembler_->WordShl(value, Int32Constant(shift));
123 } 137 }
124 138
125 Node* CodeStubAssembler::WordIsSmi(Node* a) { 139 Node* CodeStubAssembler::WordIsSmi(Node* a) {
126 return WordEqual(raw_assembler_->WordAnd(a, Int32Constant(kSmiTagMask)), 140 return WordEqual(raw_assembler_->WordAnd(a, Int32Constant(kSmiTagMask)),
127 Int32Constant(0)); 141 Int32Constant(0));
128 } 142 }
129 143
130 Node* CodeStubAssembler::LoadBufferObject(Node* buffer, int offset) { 144 Node* CodeStubAssembler::LoadBufferObject(Node* buffer, int offset) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 compiler::Node* roots_array_start = 186 compiler::Node* roots_array_start =
173 ExternalConstant(ExternalReference::roots_array_start(isolate())); 187 ExternalConstant(ExternalReference::roots_array_start(isolate()));
174 USE(roots_array_start); 188 USE(roots_array_start);
175 189
176 // TODO(danno): Implement thee root-access case where the root is not constant 190 // TODO(danno): Implement thee root-access case where the root is not constant
177 // and must be loaded from the root array. 191 // and must be loaded from the root array.
178 UNIMPLEMENTED(); 192 UNIMPLEMENTED();
179 return nullptr; 193 return nullptr;
180 } 194 }
181 195
196 Node* CodeStubAssembler::Load(MachineType rep, Node* base) {
197 return raw_assembler_->Load(rep, base);
198 }
199
200 Node* CodeStubAssembler::Load(MachineType rep, Node* base, Node* index) {
201 return raw_assembler_->Load(rep, base, index);
202 }
203
204 Node* CodeStubAssembler::Store(MachineRepresentation rep, Node* base,
205 Node* value) {
206 return raw_assembler_->Store(rep, base, value, kFullWriteBarrier);
207 }
208
209 Node* CodeStubAssembler::Store(MachineRepresentation rep, Node* base,
210 Node* index, Node* value) {
211 return raw_assembler_->Store(rep, base, index, value, kFullWriteBarrier);
212 }
213
214 Node* CodeStubAssembler::StoreNoWriteBarrier(MachineRepresentation rep,
215 Node* base, Node* value) {
216 return raw_assembler_->Store(rep, base, value, kNoWriteBarrier);
217 }
218
219 Node* CodeStubAssembler::StoreNoWriteBarrier(MachineRepresentation rep,
220 Node* base, Node* index,
221 Node* value) {
222 return raw_assembler_->Store(rep, base, index, value, kNoWriteBarrier);
223 }
224
225 Node* CodeStubAssembler::Projection(int index, Node* value) {
226 return raw_assembler_->Projection(index, value);
227 }
228
182 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target, 229 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target,
183 Node** args) { 230 Node** args) {
184 return raw_assembler_->CallN(descriptor, code_target, args); 231 CallPrologue();
232 Node* return_value = raw_assembler_->CallN(descriptor, code_target, args);
233 CallEpilogue();
234 return return_value;
185 } 235 }
186 236
187 237
188 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor, 238 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor,
189 Node* code_target, Node** args) { 239 Node* code_target, Node** args) {
190 return raw_assembler_->TailCallN(descriptor, code_target, args); 240 return raw_assembler_->TailCallN(descriptor, code_target, args);
191 } 241 }
192 242
243 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
244 Node* context) {
245 CallPrologue();
246 Node* return_value = raw_assembler_->CallRuntime0(function_id, context);
247 CallEpilogue();
248 return return_value;
249 }
193 250
194 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id, 251 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
195 Node* context, Node* arg1) { 252 Node* context, Node* arg1) {
196 return raw_assembler_->CallRuntime1(function_id, arg1, context); 253 CallPrologue();
254 Node* return_value = raw_assembler_->CallRuntime1(function_id, arg1, context);
255 CallEpilogue();
256 return return_value;
197 } 257 }
198 258
199
200 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id, 259 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
201 Node* context, Node* arg1, Node* arg2) { 260 Node* context, Node* arg1, Node* arg2) {
202 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, context); 261 CallPrologue();
262 Node* return_value =
263 raw_assembler_->CallRuntime2(function_id, arg1, arg2, context);
264 CallEpilogue();
265 return return_value;
266 }
267
268 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
269 Node* context, Node* arg1, Node* arg2,
270 Node* arg3) {
271 CallPrologue();
272 Node* return_value =
273 raw_assembler_->CallRuntime3(function_id, arg1, arg2, arg3, context);
274 CallEpilogue();
275 return return_value;
276 }
277
278 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
279 Node* context, Node* arg1, Node* arg2,
280 Node* arg3, Node* arg4) {
281 CallPrologue();
282 Node* return_value = raw_assembler_->CallRuntime4(function_id, arg1, arg2,
283 arg3, arg4, context);
284 CallEpilogue();
285 return return_value;
203 } 286 }
204 287
205 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 288 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
206 Node* context, Node* arg1) { 289 Node* context, Node* arg1) {
207 return raw_assembler_->TailCallRuntime1(function_id, arg1, context); 290 return raw_assembler_->TailCallRuntime1(function_id, arg1, context);
208 } 291 }
209 292
210 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 293 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
211 Node* context, Node* arg1, 294 Node* context, Node* arg1,
212 Node* arg2) { 295 Node* arg2) {
213 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context); 296 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context);
214 } 297 }
215 298
216 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 299 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
217 Node* context, Node* arg1, Node* arg2, 300 Node* context, Node* arg1, Node* arg2,
218 Node* arg3) { 301 Node* arg3) {
219 return raw_assembler_->TailCallRuntime3(function_id, arg1, arg2, arg3, 302 return raw_assembler_->TailCallRuntime3(function_id, arg1, arg2, arg3,
220 context); 303 context);
221 } 304 }
222 305
223 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, 306 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
224 Node* context, Node* arg1, Node* arg2, 307 Node* context, Node* arg1, Node* arg2,
225 Node* arg3, Node* arg4) { 308 Node* arg3, Node* arg4) {
226 return raw_assembler_->TailCallRuntime4(function_id, arg1, arg2, arg3, arg4, 309 return raw_assembler_->TailCallRuntime4(function_id, arg1, arg2, arg3, arg4,
227 context); 310 context);
228 } 311 }
229 312
313 Node* CodeStubAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
314 Node* target, Node* context, Node* arg1,
315 size_t result_size) {
316 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
317 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
318 CallDescriptor::kNoFlags, Operator::kNoProperties,
319 MachineType::AnyTagged(), result_size);
320
321 Node** args = zone()->NewArray<Node*>(2);
322 args[0] = arg1;
323 args[1] = context;
324
325 return CallN(call_descriptor, target, args);
326 }
327
328 Node* CodeStubAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
329 Node* target, Node* context, Node* arg1,
330 Node* arg2, size_t result_size) {
331 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
332 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
333 CallDescriptor::kNoFlags, Operator::kNoProperties,
334 MachineType::AnyTagged(), result_size);
335
336 Node** args = zone()->NewArray<Node*>(3);
337 args[0] = arg1;
338 args[1] = arg2;
339 args[2] = context;
340
341 return CallN(call_descriptor, target, args);
342 }
343
344 Node* CodeStubAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
345 Node* target, Node* context, Node* arg1,
346 Node* arg2, Node* arg3, size_t result_size) {
347 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
348 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
349 CallDescriptor::kNoFlags, Operator::kNoProperties,
350 MachineType::AnyTagged(), result_size);
351
352 Node** args = zone()->NewArray<Node*>(4);
353 args[0] = arg1;
354 args[1] = arg2;
355 args[2] = arg3;
356 args[3] = context;
357
358 return CallN(call_descriptor, target, args);
359 }
360
361 Node* CodeStubAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
362 Node* target, Node* context, Node* arg1,
363 Node* arg2, Node* arg3, Node* arg4,
364 size_t result_size) {
365 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
366 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
367 CallDescriptor::kNoFlags, Operator::kNoProperties,
368 MachineType::AnyTagged(), result_size);
369
370 Node** args = zone()->NewArray<Node*>(5);
371 args[0] = arg1;
372 args[1] = arg2;
373 args[2] = arg3;
374 args[3] = arg4;
375 args[4] = context;
376
377 return CallN(call_descriptor, target, args);
378 }
379
380 Node* CodeStubAssembler::CallStub(const CallInterfaceDescriptor& descriptor,
381 Node* target, Node* context, Node* arg1,
382 Node* arg2, Node* arg3, Node* arg4,
383 Node* arg5, size_t result_size) {
384 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor(
385 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(),
386 CallDescriptor::kNoFlags, Operator::kNoProperties,
387 MachineType::AnyTagged(), result_size);
388
389 Node** args = zone()->NewArray<Node*>(6);
390 args[0] = arg1;
391 args[1] = arg2;
392 args[2] = arg3;
393 args[3] = arg4;
394 args[4] = arg5;
395 args[5] = context;
396
397 return CallN(call_descriptor, target, args);
398 }
399
230 Node* CodeStubAssembler::TailCallStub(CodeStub& stub, Node** args) { 400 Node* CodeStubAssembler::TailCallStub(CodeStub& stub, Node** args) {
231 Node* code_target = HeapConstant(stub.GetCode()); 401 Node* code_target = HeapConstant(stub.GetCode());
232 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( 402 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
233 isolate(), zone(), stub.GetCallInterfaceDescriptor(), 403 isolate(), zone(), stub.GetCallInterfaceDescriptor(),
234 stub.GetStackParameterCount(), CallDescriptor::kSupportsTailCalls); 404 stub.GetStackParameterCount(), CallDescriptor::kSupportsTailCalls);
235 return raw_assembler_->TailCallN(descriptor, code_target, args); 405 return raw_assembler_->TailCallN(descriptor, code_target, args);
236 } 406 }
237 407
238 Node* CodeStubAssembler::TailCall( 408 Node* CodeStubAssembler::TailCall(
239 const CallInterfaceDescriptor& interface_descriptor, Node* code_target, 409 const CallInterfaceDescriptor& interface_descriptor, Node* code_target,
240 Node** args) { 410 Node** args, size_t result_size) {
241 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( 411 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor(
242 isolate(), zone(), interface_descriptor, 412 isolate(), zone(), interface_descriptor,
243 interface_descriptor.GetStackParameterCount(), 413 interface_descriptor.GetStackParameterCount(),
244 CallDescriptor::kSupportsTailCalls); 414 CallDescriptor::kSupportsTailCalls, Operator::kNoProperties,
415 MachineType::AnyTagged(), result_size);
245 return raw_assembler_->TailCallN(descriptor, code_target, args); 416 return raw_assembler_->TailCallN(descriptor, code_target, args);
246 } 417 }
247 418
248 void CodeStubAssembler::Goto(CodeStubAssembler::Label* label) { 419 void CodeStubAssembler::Goto(CodeStubAssembler::Label* label) {
249 label->MergeVariables(); 420 label->MergeVariables();
250 raw_assembler_->Goto(label->label_); 421 raw_assembler_->Goto(label->label_);
251 } 422 }
252 423
253 void CodeStubAssembler::Branch(Node* condition, 424 void CodeStubAssembler::Branch(Node* condition,
254 CodeStubAssembler::Label* true_label, 425 CodeStubAssembler::Label* true_label,
(...skipping 15 matching lines...) Expand all
270 case_labels[i]->MergeVariables(); 441 case_labels[i]->MergeVariables();
271 default_label->MergeVariables(); 442 default_label->MergeVariables();
272 } 443 }
273 return raw_assembler_->Switch(index, default_label->label_, case_values, 444 return raw_assembler_->Switch(index, default_label->label_, case_values,
274 labels, case_count); 445 labels, case_count);
275 } 446 }
276 447
277 // RawMachineAssembler delegate helpers: 448 // RawMachineAssembler delegate helpers:
278 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); } 449 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); }
279 450
280
281 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); } 451 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); }
282 452
283
284 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); } 453 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); }
285 454
286 // The core implementation of Variable is stored through an indirection so 455 // The core implementation of Variable is stored through an indirection so
287 // that it can outlive the often block-scoped Variable declarations. This is 456 // that it can outlive the often block-scoped Variable declarations. This is
288 // needed to ensure that variable binding and merging through phis can 457 // needed to ensure that variable binding and merging through phis can
289 // properly be verified. 458 // properly be verified.
290 class CodeStubAssembler::Variable::Impl : public ZoneObject { 459 class CodeStubAssembler::Variable::Impl : public ZoneObject {
291 public: 460 public:
292 explicit Impl(MachineRepresentation rep) : value_(nullptr), rep_(rep) {} 461 explicit Impl(MachineRepresentation rep) : value_(nullptr), rep_(rep) {}
293 Node* value_; 462 Node* value_;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 602 }
434 } 603 }
435 } 604 }
436 605
437 bound_ = true; 606 bound_ = true;
438 } 607 }
439 608
440 } // namespace compiler 609 } // namespace compiler
441 } // namespace internal 610 } // namespace internal
442 } // namespace v8 611 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/code-stub-assembler.h ('k') | src/compiler/interpreter-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698