| OLD | NEW |
| 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" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 98 } |
| 99 | 99 |
| 100 Node* CodeStubAssembler::ExternalConstant(ExternalReference address) { | 100 Node* CodeStubAssembler::ExternalConstant(ExternalReference address) { |
| 101 return raw_assembler_->ExternalConstant(address); | 101 return raw_assembler_->ExternalConstant(address); |
| 102 } | 102 } |
| 103 | 103 |
| 104 Node* CodeStubAssembler::Float64Constant(double value) { | 104 Node* CodeStubAssembler::Float64Constant(double value) { |
| 105 return raw_assembler_->Float64Constant(value); | 105 return raw_assembler_->Float64Constant(value); |
| 106 } | 106 } |
| 107 | 107 |
| 108 Node* CodeStubAssembler::HeapNumberMapConstant() { |
| 109 return HeapConstant(isolate()->factory()->heap_number_map()); |
| 110 } |
| 111 |
| 108 Node* CodeStubAssembler::Parameter(int value) { | 112 Node* CodeStubAssembler::Parameter(int value) { |
| 109 return raw_assembler_->Parameter(value); | 113 return raw_assembler_->Parameter(value); |
| 110 } | 114 } |
| 111 | 115 |
| 112 | 116 |
| 113 void CodeStubAssembler::Return(Node* value) { | 117 void CodeStubAssembler::Return(Node* value) { |
| 114 return raw_assembler_->Return(value); | 118 return raw_assembler_->Return(value); |
| 115 } | 119 } |
| 116 | 120 |
| 117 void CodeStubAssembler::Bind(CodeStubAssembler::Label* label) { | 121 void CodeStubAssembler::Bind(CodeStubAssembler::Label* label) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 132 | 136 |
| 133 Node* CodeStubAssembler::SmiShiftBitsConstant() { | 137 Node* CodeStubAssembler::SmiShiftBitsConstant() { |
| 134 return IntPtrConstant(kSmiShiftSize + kSmiTagSize); | 138 return IntPtrConstant(kSmiShiftSize + kSmiTagSize); |
| 135 } | 139 } |
| 136 | 140 |
| 137 | 141 |
| 138 Node* CodeStubAssembler::SmiTag(Node* value) { | 142 Node* CodeStubAssembler::SmiTag(Node* value) { |
| 139 return raw_assembler_->WordShl(value, SmiShiftBitsConstant()); | 143 return raw_assembler_->WordShl(value, SmiShiftBitsConstant()); |
| 140 } | 144 } |
| 141 | 145 |
| 142 | |
| 143 Node* CodeStubAssembler::SmiUntag(Node* value) { | 146 Node* CodeStubAssembler::SmiUntag(Node* value) { |
| 144 return raw_assembler_->WordSar(value, SmiShiftBitsConstant()); | 147 return raw_assembler_->WordSar(value, SmiShiftBitsConstant()); |
| 145 } | 148 } |
| 146 | 149 |
| 147 Node* CodeStubAssembler::SmiToInt32(Node* value) { | 150 Node* CodeStubAssembler::SmiToInt32(Node* value) { |
| 148 Node* result = raw_assembler_->WordSar(value, SmiShiftBitsConstant()); | 151 Node* result = raw_assembler_->WordSar(value, SmiShiftBitsConstant()); |
| 149 if (raw_assembler_->machine()->Is64()) { | 152 if (raw_assembler_->machine()->Is64()) { |
| 150 result = raw_assembler_->TruncateInt64ToInt32(result); | 153 result = raw_assembler_->TruncateInt64ToInt32(result); |
| 151 } | 154 } |
| 152 return result; | 155 return result; |
| 153 } | 156 } |
| 154 | 157 |
| 158 Node* CodeStubAssembler::SmiToFloat64(Node* value) { |
| 159 return ChangeInt32ToFloat64(SmiUntag(value)); |
| 160 } |
| 161 |
| 155 Node* CodeStubAssembler::SmiAdd(Node* a, Node* b) { return IntPtrAdd(a, b); } | 162 Node* CodeStubAssembler::SmiAdd(Node* a, Node* b) { return IntPtrAdd(a, b); } |
| 156 | 163 |
| 157 Node* CodeStubAssembler::SmiEqual(Node* a, Node* b) { return WordEqual(a, b); } | 164 Node* CodeStubAssembler::SmiEqual(Node* a, Node* b) { return WordEqual(a, b); } |
| 158 | 165 |
| 159 #define DEFINE_CODE_STUB_ASSEMBER_BINARY_OP(name) \ | 166 #define DEFINE_CODE_STUB_ASSEMBER_BINARY_OP(name) \ |
| 160 Node* CodeStubAssembler::name(Node* a, Node* b) { \ | 167 Node* CodeStubAssembler::name(Node* a, Node* b) { \ |
| 161 return raw_assembler_->name(a, b); \ | 168 return raw_assembler_->name(a, b); \ |
| 162 } | 169 } |
| 163 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_BINARY_OP) | 170 CODE_STUB_ASSEMBLER_BINARY_OP_LIST(DEFINE_CODE_STUB_ASSEMBER_BINARY_OP) |
| 164 #undef DEFINE_CODE_STUB_ASSEMBER_BINARY_OP | 171 #undef DEFINE_CODE_STUB_ASSEMBER_BINARY_OP |
| (...skipping 16 matching lines...) Expand all Loading... |
| 181 return raw_assembler_->Load(MachineType::AnyTagged(), buffer, | 188 return raw_assembler_->Load(MachineType::AnyTagged(), buffer, |
| 182 IntPtrConstant(offset)); | 189 IntPtrConstant(offset)); |
| 183 } | 190 } |
| 184 | 191 |
| 185 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) { | 192 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) { |
| 186 return raw_assembler_->Load(MachineType::AnyTagged(), object, | 193 return raw_assembler_->Load(MachineType::AnyTagged(), object, |
| 187 IntPtrConstant(offset - kHeapObjectTag)); | 194 IntPtrConstant(offset - kHeapObjectTag)); |
| 188 } | 195 } |
| 189 | 196 |
| 190 Node* CodeStubAssembler::LoadHeapNumberValue(Node* object) { | 197 Node* CodeStubAssembler::LoadHeapNumberValue(Node* object) { |
| 191 return raw_assembler_->Load( | 198 return Load(MachineType::Float64(), object, |
| 192 MachineType::Float64(), object, | 199 IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag)); |
| 193 IntPtrConstant(HeapNumber::kValueOffset - kHeapObjectTag)); | 200 } |
| 201 |
| 202 Node* CodeStubAssembler::LoadMapInstanceType(Node* map) { |
| 203 return Load(MachineType::Uint8(), map, |
| 204 IntPtrConstant(Map::kInstanceTypeOffset - kHeapObjectTag)); |
| 194 } | 205 } |
| 195 | 206 |
| 196 Node* CodeStubAssembler::LoadFixedArrayElementSmiIndex(Node* object, | 207 Node* CodeStubAssembler::LoadFixedArrayElementSmiIndex(Node* object, |
| 197 Node* smi_index, | 208 Node* smi_index, |
| 198 int additional_offset) { | 209 int additional_offset) { |
| 199 int const kSmiShiftBits = kSmiShiftSize + kSmiTagSize; | 210 int const kSmiShiftBits = kSmiShiftSize + kSmiTagSize; |
| 200 Node* header_size = IntPtrConstant(additional_offset + | 211 Node* header_size = IntPtrConstant(additional_offset + |
| 201 FixedArray::kHeaderSize - kHeapObjectTag); | 212 FixedArray::kHeaderSize - kHeapObjectTag); |
| 202 Node* scaled_index = | 213 Node* scaled_index = |
| 203 (kSmiShiftBits > kPointerSizeLog2) | 214 (kSmiShiftBits > kPointerSizeLog2) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 Node* base, Node* index, | 283 Node* base, Node* index, |
| 273 Node* value) { | 284 Node* value) { |
| 274 return raw_assembler_->Store(rep, base, index, value, kNoWriteBarrier); | 285 return raw_assembler_->Store(rep, base, index, value, kNoWriteBarrier); |
| 275 } | 286 } |
| 276 | 287 |
| 277 Node* CodeStubAssembler::Projection(int index, Node* value) { | 288 Node* CodeStubAssembler::Projection(int index, Node* value) { |
| 278 return raw_assembler_->Projection(index, value); | 289 return raw_assembler_->Projection(index, value); |
| 279 } | 290 } |
| 280 | 291 |
| 281 Node* CodeStubAssembler::LoadInstanceType(Node* object) { | 292 Node* CodeStubAssembler::LoadInstanceType(Node* object) { |
| 282 return raw_assembler_->Word32And( | 293 return LoadMapInstanceType(LoadObjectField(object, HeapObject::kMapOffset)); |
| 283 LoadObjectField(LoadObjectField(object, HeapObject::kMapOffset), | |
| 284 Map::kInstanceTypeOffset), | |
| 285 raw_assembler_->Int32Constant(255)); | |
| 286 } | 294 } |
| 287 | 295 |
| 288 Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift, | 296 Node* CodeStubAssembler::BitFieldDecode(Node* word32, uint32_t shift, |
| 289 uint32_t mask) { | 297 uint32_t mask) { |
| 290 return raw_assembler_->Word32Shr( | 298 return raw_assembler_->Word32Shr( |
| 291 raw_assembler_->Word32And(word32, raw_assembler_->Int32Constant(mask)), | 299 raw_assembler_->Word32And(word32, raw_assembler_->Int32Constant(mask)), |
| 292 raw_assembler_->Int32Constant(shift)); | 300 raw_assembler_->Int32Constant(shift)); |
| 293 } | 301 } |
| 294 | 302 |
| 303 void CodeStubAssembler::BranchIfFloat64Equal(Node* a, Node* b, Label* if_true, |
| 304 Label* if_false) { |
| 305 Label if_equal(this), if_notequal(this); |
| 306 Branch(Float64Equal(a, b), &if_equal, &if_notequal); |
| 307 Bind(&if_equal); |
| 308 Goto(if_true); |
| 309 Bind(&if_notequal); |
| 310 Goto(if_false); |
| 311 } |
| 312 |
| 295 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target, | 313 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target, |
| 296 Node** args) { | 314 Node** args) { |
| 297 CallPrologue(); | 315 CallPrologue(); |
| 298 Node* return_value = raw_assembler_->CallN(descriptor, code_target, args); | 316 Node* return_value = raw_assembler_->CallN(descriptor, code_target, args); |
| 299 CallEpilogue(); | 317 CallEpilogue(); |
| 300 return return_value; | 318 return return_value; |
| 301 } | 319 } |
| 302 | 320 |
| 303 | 321 |
| 304 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor, | 322 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 args[0] = arg1; | 479 args[0] = arg1; |
| 462 args[1] = arg2; | 480 args[1] = arg2; |
| 463 args[2] = arg3; | 481 args[2] = arg3; |
| 464 args[3] = arg4; | 482 args[3] = arg4; |
| 465 args[4] = arg5; | 483 args[4] = arg5; |
| 466 args[5] = context; | 484 args[5] = context; |
| 467 | 485 |
| 468 return CallN(call_descriptor, target, args); | 486 return CallN(call_descriptor, target, args); |
| 469 } | 487 } |
| 470 | 488 |
| 471 Node* CodeStubAssembler::TailCallStub(CodeStub& stub, Node** args) { | 489 Node* CodeStubAssembler::TailCallStub(const CallInterfaceDescriptor& descriptor, |
| 472 Node* code_target = HeapConstant(stub.GetCode()); | 490 Node* target, Node* context, Node* arg1, |
| 473 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( | 491 Node* arg2, size_t result_size) { |
| 474 isolate(), zone(), stub.GetCallInterfaceDescriptor(), | 492 CallDescriptor* call_descriptor = Linkage::GetStubCallDescriptor( |
| 475 stub.GetStackParameterCount(), CallDescriptor::kSupportsTailCalls); | 493 isolate(), zone(), descriptor, descriptor.GetStackParameterCount(), |
| 476 return raw_assembler_->TailCallN(descriptor, code_target, args); | 494 CallDescriptor::kSupportsTailCalls, Operator::kNoProperties, |
| 495 MachineType::AnyTagged(), result_size); |
| 496 |
| 497 Node** args = zone()->NewArray<Node*>(3); |
| 498 args[0] = arg1; |
| 499 args[1] = arg2; |
| 500 args[2] = context; |
| 501 |
| 502 return raw_assembler_->TailCallN(call_descriptor, target, args); |
| 477 } | 503 } |
| 478 | 504 |
| 479 Node* CodeStubAssembler::TailCall( | 505 Node* CodeStubAssembler::TailCall( |
| 480 const CallInterfaceDescriptor& interface_descriptor, Node* code_target, | 506 const CallInterfaceDescriptor& interface_descriptor, Node* code_target, |
| 481 Node** args, size_t result_size) { | 507 Node** args, size_t result_size) { |
| 482 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( | 508 CallDescriptor* descriptor = Linkage::GetStubCallDescriptor( |
| 483 isolate(), zone(), interface_descriptor, | 509 isolate(), zone(), interface_descriptor, |
| 484 interface_descriptor.GetStackParameterCount(), | 510 interface_descriptor.GetStackParameterCount(), |
| 485 CallDescriptor::kSupportsTailCalls, Operator::kNoProperties, | 511 CallDescriptor::kSupportsTailCalls, Operator::kNoProperties, |
| 486 MachineType::AnyTagged(), result_size); | 512 MachineType::AnyTagged(), result_size); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 510 for (size_t i = 0; i < case_count; ++i) { | 536 for (size_t i = 0; i < case_count; ++i) { |
| 511 labels[i] = case_labels[i]->label_; | 537 labels[i] = case_labels[i]->label_; |
| 512 case_labels[i]->MergeVariables(); | 538 case_labels[i]->MergeVariables(); |
| 513 default_label->MergeVariables(); | 539 default_label->MergeVariables(); |
| 514 } | 540 } |
| 515 return raw_assembler_->Switch(index, default_label->label_, case_values, | 541 return raw_assembler_->Switch(index, default_label->label_, case_values, |
| 516 labels, case_count); | 542 labels, case_count); |
| 517 } | 543 } |
| 518 | 544 |
| 519 // RawMachineAssembler delegate helpers: | 545 // RawMachineAssembler delegate helpers: |
| 520 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); } | 546 Isolate* CodeStubAssembler::isolate() const { |
| 547 return raw_assembler_->isolate(); |
| 548 } |
| 521 | 549 |
| 522 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); } | 550 Factory* CodeStubAssembler::factory() const { return isolate()->factory(); } |
| 523 | 551 |
| 524 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); } | 552 Graph* CodeStubAssembler::graph() const { return raw_assembler_->graph(); } |
| 553 |
| 554 Zone* CodeStubAssembler::zone() const { return raw_assembler_->zone(); } |
| 525 | 555 |
| 526 // The core implementation of Variable is stored through an indirection so | 556 // The core implementation of Variable is stored through an indirection so |
| 527 // that it can outlive the often block-scoped Variable declarations. This is | 557 // that it can outlive the often block-scoped Variable declarations. This is |
| 528 // needed to ensure that variable binding and merging through phis can | 558 // needed to ensure that variable binding and merging through phis can |
| 529 // properly be verified. | 559 // properly be verified. |
| 530 class CodeStubAssembler::Variable::Impl : public ZoneObject { | 560 class CodeStubAssembler::Variable::Impl : public ZoneObject { |
| 531 public: | 561 public: |
| 532 explicit Impl(MachineRepresentation rep) : value_(nullptr), rep_(rep) {} | 562 explicit Impl(MachineRepresentation rep) : value_(nullptr), rep_(rep) {} |
| 533 Node* value_; | 563 Node* value_; |
| 534 MachineRepresentation rep_; | 564 MachineRepresentation rep_; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 } | 703 } |
| 674 } | 704 } |
| 675 } | 705 } |
| 676 | 706 |
| 677 bound_ = true; | 707 bound_ = true; |
| 678 } | 708 } |
| 679 | 709 |
| 680 } // namespace compiler | 710 } // namespace compiler |
| 681 } // namespace internal | 711 } // namespace internal |
| 682 } // namespace v8 | 712 } // namespace v8 |
| OLD | NEW |