Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #ifndef V8_CODE_STUBS_H_ | 5 #ifndef V8_CODE_STUBS_H_ |
| 6 #define V8_CODE_STUBS_H_ | 6 #define V8_CODE_STUBS_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| 11 #include "src/compiler/code-stub-assembler.h" | |
| 11 #include "src/globals.h" | 12 #include "src/globals.h" |
| 12 #include "src/ic/ic-state.h" | 13 #include "src/ic/ic-state.h" |
| 13 #include "src/interface-descriptors.h" | 14 #include "src/interface-descriptors.h" |
| 14 #include "src/macro-assembler.h" | 15 #include "src/macro-assembler.h" |
| 15 #include "src/ostreams.h" | 16 #include "src/ostreams.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| 19 | 20 |
| 20 // List of code stubs used on all platforms. | 21 // List of code stubs used on all platforms. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 V(RegExpConstructResult) \ | 90 V(RegExpConstructResult) \ |
| 90 V(StoreFastElement) \ | 91 V(StoreFastElement) \ |
| 91 V(StoreGlobalViaContext) \ | 92 V(StoreGlobalViaContext) \ |
| 92 V(StoreScriptContextField) \ | 93 V(StoreScriptContextField) \ |
| 93 V(StringAdd) \ | 94 V(StringAdd) \ |
| 94 V(ToBoolean) \ | 95 V(ToBoolean) \ |
| 95 V(TransitionElementsKind) \ | 96 V(TransitionElementsKind) \ |
| 96 V(KeyedLoadIC) \ | 97 V(KeyedLoadIC) \ |
| 97 V(LoadIC) \ | 98 V(LoadIC) \ |
| 98 /* TurboFanCodeStubs */ \ | 99 /* TurboFanCodeStubs */ \ |
| 99 V(StringLengthTF) \ | 100 V(StringLength) \ |
| 100 V(StringAddTF) \ | |
| 101 /* TurboFanICs */ \ | |
| 102 V(MathFloor) \ | |
| 103 /* IC Handler stubs */ \ | 101 /* IC Handler stubs */ \ |
| 104 V(ArrayBufferViewLoadField) \ | 102 V(ArrayBufferViewLoadField) \ |
| 105 V(LoadConstant) \ | 103 V(LoadConstant) \ |
| 106 V(LoadFastElement) \ | 104 V(LoadFastElement) \ |
| 107 V(LoadField) \ | 105 V(LoadField) \ |
| 108 V(KeyedLoadSloppyArguments) \ | 106 V(KeyedLoadSloppyArguments) \ |
| 109 V(KeyedStoreSloppyArguments) \ | 107 V(KeyedStoreSloppyArguments) \ |
| 110 V(StoreField) \ | 108 V(StoreField) \ |
| 111 V(StoreGlobal) \ | 109 V(StoreGlobal) \ |
| 112 V(StoreTransition) \ | 110 V(StoreTransition) |
| 113 V(StringLength) | |
| 114 | 111 |
| 115 // List of code stubs only used on ARM 32 bits platforms. | 112 // List of code stubs only used on ARM 32 bits platforms. |
| 116 #if V8_TARGET_ARCH_ARM | 113 #if V8_TARGET_ARCH_ARM |
| 117 #define CODE_STUB_LIST_ARM(V) V(DirectCEntry) | 114 #define CODE_STUB_LIST_ARM(V) V(DirectCEntry) |
| 118 | 115 |
| 119 #else | 116 #else |
| 120 #define CODE_STUB_LIST_ARM(V) | 117 #define CODE_STUB_LIST_ARM(V) |
| 121 #endif | 118 #endif |
| 122 | 119 |
| 123 // List of code stubs only used on ARM 64 bits platforms. | 120 // List of code stubs only used on ARM 64 bits platforms. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 Handle<Code> GenerateCode() override; \ | 339 Handle<Code> GenerateCode() override; \ |
| 343 DEFINE_CODE_STUB(NAME, SUPER) | 340 DEFINE_CODE_STUB(NAME, SUPER) |
| 344 | 341 |
| 345 #define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \ | 342 #define DEFINE_TURBOFAN_CODE_STUB(NAME, SUPER) \ |
| 346 public: \ | 343 public: \ |
| 347 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \ | 344 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \ |
| 348 return DESC##Descriptor(isolate()); \ | 345 return DESC##Descriptor(isolate()); \ |
| 349 }; \ | 346 }; \ |
| 350 DEFINE_CODE_STUB(NAME, SUPER) | 347 DEFINE_CODE_STUB(NAME, SUPER) |
| 351 | 348 |
| 352 #define DEFINE_TURBOFAN_IC(NAME, SUPER, DESC) \ | |
| 353 public: \ | |
| 354 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \ | |
| 355 if (GetCallMode() == CALL_FROM_OPTIMIZED_CODE) { \ | |
| 356 return DESC##CallFromOptimizedCodeDescriptor(isolate()); \ | |
| 357 } else { \ | |
| 358 return DESC##CallFromUnoptimizedCodeDescriptor(isolate()); \ | |
| 359 } \ | |
| 360 }; \ | |
| 361 \ | |
| 362 protected: \ | |
| 363 DEFINE_CODE_STUB(NAME, SUPER) | |
| 364 | |
| 365 #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \ | 349 #define DEFINE_HANDLER_CODE_STUB(NAME, SUPER) \ |
| 366 public: \ | 350 public: \ |
| 367 Handle<Code> GenerateCode() override; \ | 351 Handle<Code> GenerateCode() override; \ |
| 368 DEFINE_CODE_STUB(NAME, SUPER) | 352 DEFINE_CODE_STUB(NAME, SUPER) |
| 369 | 353 |
| 370 #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \ | 354 #define DEFINE_CALL_INTERFACE_DESCRIPTOR(NAME) \ |
| 371 public: \ | 355 public: \ |
| 372 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \ | 356 CallInterfaceDescriptor GetCallInterfaceDescriptor() const override { \ |
| 373 return NAME##Descriptor(isolate()); \ | 357 return NAME##Descriptor(isolate()); \ |
| 374 } | 358 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 | 527 |
| 544 int GetStackParameterCount() const override { | 528 int GetStackParameterCount() const override { |
| 545 return GetCallInterfaceDescriptor().GetStackParameterCount(); | 529 return GetCallInterfaceDescriptor().GetStackParameterCount(); |
| 546 } | 530 } |
| 547 | 531 |
| 548 Code::StubType GetStubType() const override { return Code::FAST; } | 532 Code::StubType GetStubType() const override { return Code::FAST; } |
| 549 | 533 |
| 550 protected: | 534 protected: |
| 551 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {} | 535 explicit TurboFanCodeStub(Isolate* isolate) : CodeStub(isolate) {} |
| 552 | 536 |
| 537 virtual void GenerateAssembly( | |
| 538 compiler::CodeStubAssembler* assmebler) const = 0; | |
|
Michael Starzinger
2015/12/01 18:06:53
nit: s/assmebler/assembler/
danno
2015/12/02 07:00:19
Done.
| |
| 539 | |
| 553 private: | 540 private: |
| 554 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub); | 541 DEFINE_CODE_STUB_BASE(TurboFanCodeStub, CodeStub); |
| 542 | |
| 543 base::SmartPointer<compiler::CodeStubAssembler> asm_; | |
|
Michael Starzinger
2015/12/01 18:06:53
nit: It looks like this field is unused, can we dr
danno
2015/12/02 07:00:18
Done.
| |
| 555 }; | 544 }; |
| 556 | 545 |
| 557 | 546 |
| 558 class TurboFanIC : public TurboFanCodeStub { | |
| 559 public: | |
| 560 enum CallMode { CALL_FROM_UNOPTIMIZED_CODE, CALL_FROM_OPTIMIZED_CODE }; | |
| 561 | |
| 562 protected: | |
| 563 explicit TurboFanIC(Isolate* isolate, CallMode mode) | |
| 564 : TurboFanCodeStub(isolate) { | |
| 565 minor_key_ = CallModeBits::encode(mode); | |
| 566 } | |
| 567 | |
| 568 CallMode GetCallMode() const { return CallModeBits::decode(minor_key_); } | |
| 569 | |
| 570 void set_sub_minor_key(uint32_t key) { | |
| 571 minor_key_ = SubMinorKeyBits::update(minor_key_, key); | |
| 572 } | |
| 573 | |
| 574 uint32_t sub_minor_key() const { return SubMinorKeyBits::decode(minor_key_); } | |
| 575 | |
| 576 static const int kSubMinorKeyBits = kStubMinorKeyBits - 1; | |
| 577 | |
| 578 private: | |
| 579 class CallModeBits : public BitField<CallMode, 0, 1> {}; | |
| 580 class SubMinorKeyBits : public BitField<int, 1, kSubMinorKeyBits> {}; | |
| 581 DEFINE_CODE_STUB_BASE(TurboFanIC, TurboFanCodeStub); | |
| 582 }; | |
| 583 | |
| 584 | |
| 585 // Helper interface to prepare to/restore after making runtime calls. | 547 // Helper interface to prepare to/restore after making runtime calls. |
| 586 class RuntimeCallHelper { | 548 class RuntimeCallHelper { |
| 587 public: | 549 public: |
| 588 virtual ~RuntimeCallHelper() {} | 550 virtual ~RuntimeCallHelper() {} |
| 589 | 551 |
| 590 virtual void BeforeCall(MacroAssembler* masm) const = 0; | 552 virtual void BeforeCall(MacroAssembler* masm) const = 0; |
| 591 | 553 |
| 592 virtual void AfterCall(MacroAssembler* masm) const = 0; | 554 virtual void AfterCall(MacroAssembler* masm) const = 0; |
| 593 | 555 |
| 594 protected: | 556 protected: |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 class NopRuntimeCallHelper : public RuntimeCallHelper { | 604 class NopRuntimeCallHelper : public RuntimeCallHelper { |
| 643 public: | 605 public: |
| 644 NopRuntimeCallHelper() {} | 606 NopRuntimeCallHelper() {} |
| 645 | 607 |
| 646 void BeforeCall(MacroAssembler* masm) const override {} | 608 void BeforeCall(MacroAssembler* masm) const override {} |
| 647 | 609 |
| 648 void AfterCall(MacroAssembler* masm) const override {} | 610 void AfterCall(MacroAssembler* masm) const override {} |
| 649 }; | 611 }; |
| 650 | 612 |
| 651 | 613 |
| 652 class MathFloorStub : public TurboFanIC { | 614 class StringLengthStub : public TurboFanCodeStub { |
| 653 public: | 615 public: |
| 654 explicit MathFloorStub(Isolate* isolate, TurboFanIC::CallMode mode) | 616 explicit StringLengthStub(Isolate* isolate) : TurboFanCodeStub(isolate) {} |
| 655 : TurboFanIC(isolate, mode) {} | |
| 656 Code::Kind GetCodeKind() const override { return Code::CALL_IC; } | |
| 657 DEFINE_TURBOFAN_IC(MathFloor, TurboFanIC, MathRoundVariant); | |
| 658 }; | |
| 659 | |
| 660 | |
| 661 class StringLengthTFStub : public TurboFanCodeStub { | |
| 662 public: | |
| 663 explicit StringLengthTFStub(Isolate* isolate) : TurboFanCodeStub(isolate) {} | |
| 664 | 617 |
| 665 Code::Kind GetCodeKind() const override { return Code::HANDLER; } | 618 Code::Kind GetCodeKind() const override { return Code::HANDLER; } |
| 666 InlineCacheState GetICState() const override { return MONOMORPHIC; } | 619 InlineCacheState GetICState() const override { return MONOMORPHIC; } |
| 667 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; } | 620 ExtraICState GetExtraICState() const override { return Code::LOAD_IC; } |
| 668 | 621 |
| 622 void GenerateAssembly(compiler::CodeStubAssembler* assembler) const override; | |
| 623 | |
| 669 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector); | 624 DEFINE_CALL_INTERFACE_DESCRIPTOR(LoadWithVector); |
| 670 DEFINE_CODE_STUB(StringLengthTF, TurboFanCodeStub); | 625 DEFINE_CODE_STUB(StringLength, TurboFanCodeStub); |
| 671 }; | 626 }; |
| 672 | 627 |
| 673 | 628 |
| 674 enum StringAddFlags { | 629 enum StringAddFlags { |
| 675 // Omit both parameter checks. | 630 // Omit both parameter checks. |
| 676 STRING_ADD_CHECK_NONE = 0, | 631 STRING_ADD_CHECK_NONE = 0, |
| 677 // Check left parameter. | 632 // Check left parameter. |
| 678 STRING_ADD_CHECK_LEFT = 1 << 0, | 633 STRING_ADD_CHECK_LEFT = 1 << 0, |
| 679 // Check right parameter. | 634 // Check right parameter. |
| 680 STRING_ADD_CHECK_RIGHT = 1 << 1, | 635 STRING_ADD_CHECK_RIGHT = 1 << 1, |
| 681 // Check both parameters. | 636 // Check both parameters. |
| 682 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT, | 637 STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT, |
| 683 // Convert parameters when check fails (instead of throwing an exception). | 638 // Convert parameters when check fails (instead of throwing an exception). |
| 684 STRING_ADD_CONVERT = 1 << 2, | 639 STRING_ADD_CONVERT = 1 << 2, |
| 685 STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT, | 640 STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT, |
| 686 STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT | 641 STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT |
| 687 }; | 642 }; |
| 688 | 643 |
| 689 | 644 |
| 690 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags); | 645 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags); |
| 691 | 646 |
| 692 | 647 |
| 693 class StringAddTFStub : public TurboFanCodeStub { | |
| 694 public: | |
| 695 StringAddTFStub(Isolate* isolate, StringAddFlags flags, | |
| 696 PretenureFlag pretenure_flag) | |
| 697 : TurboFanCodeStub(isolate) { | |
| 698 minor_key_ = StringAddFlagsBits::encode(flags) | | |
| 699 PretenureFlagBits::encode(pretenure_flag); | |
| 700 } | |
| 701 | |
| 702 StringAddFlags flags() const { | |
| 703 return StringAddFlagsBits::decode(MinorKey()); | |
| 704 } | |
| 705 | |
| 706 PretenureFlag pretenure_flag() const { | |
| 707 return PretenureFlagBits::decode(MinorKey()); | |
| 708 } | |
| 709 | |
| 710 private: | |
| 711 class StringAddFlagsBits : public BitField<StringAddFlags, 0, 3> {}; | |
| 712 class PretenureFlagBits : public BitField<PretenureFlag, 3, 1> {}; | |
| 713 | |
| 714 void PrintBaseName(std::ostream& os) const override; // NOLINT | |
| 715 | |
| 716 DEFINE_CALL_INTERFACE_DESCRIPTOR(StringAdd); | |
| 717 DEFINE_CODE_STUB(StringAddTF, TurboFanCodeStub); | |
| 718 }; | |
| 719 | |
| 720 | |
| 721 class NumberToStringStub final : public HydrogenCodeStub { | 648 class NumberToStringStub final : public HydrogenCodeStub { |
| 722 public: | 649 public: |
| 723 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {} | 650 explicit NumberToStringStub(Isolate* isolate) : HydrogenCodeStub(isolate) {} |
| 724 | 651 |
| 725 // Parameters accessed via CodeStubGraphBuilder::GetParameter() | 652 // Parameters accessed via CodeStubGraphBuilder::GetParameter() |
| 726 static const int kNumber = 0; | 653 static const int kNumber = 0; |
| 727 | 654 |
| 728 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString); | 655 DEFINE_CALL_INTERFACE_DESCRIPTOR(NumberToString); |
| 729 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub); | 656 DEFINE_HYDROGEN_CODE_STUB(NumberToString, HydrogenCodeStub); |
| 730 }; | 657 }; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1173 Code::Kind kind() const override { return Code::LOAD_IC; } | 1100 Code::Kind kind() const override { return Code::LOAD_IC; } |
| 1174 Code::StubType GetStubType() const override { return Code::FAST; } | 1101 Code::StubType GetStubType() const override { return Code::FAST; } |
| 1175 | 1102 |
| 1176 private: | 1103 private: |
| 1177 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {}; | 1104 class ConstantIndexBits : public BitField<int, 0, kSubMinorKeyBits> {}; |
| 1178 | 1105 |
| 1179 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub); | 1106 DEFINE_HANDLER_CODE_STUB(LoadConstant, HandlerStub); |
| 1180 }; | 1107 }; |
| 1181 | 1108 |
| 1182 | 1109 |
| 1183 class StringLengthStub: public HandlerStub { | |
| 1184 public: | |
| 1185 explicit StringLengthStub(Isolate* isolate) : HandlerStub(isolate) {} | |
| 1186 | |
| 1187 protected: | |
| 1188 Code::Kind kind() const override { return Code::LOAD_IC; } | |
| 1189 Code::StubType GetStubType() const override { return Code::FAST; } | |
| 1190 | |
| 1191 DEFINE_HANDLER_CODE_STUB(StringLength, HandlerStub); | |
| 1192 }; | |
| 1193 | |
| 1194 | |
| 1195 class StoreFieldStub : public HandlerStub { | 1110 class StoreFieldStub : public HandlerStub { |
| 1196 public: | 1111 public: |
| 1197 StoreFieldStub(Isolate* isolate, FieldIndex index, | 1112 StoreFieldStub(Isolate* isolate, FieldIndex index, |
| 1198 Representation representation) | 1113 Representation representation) |
| 1199 : HandlerStub(isolate) { | 1114 : HandlerStub(isolate) { |
| 1200 int property_index_key = index.GetFieldAccessStubKey(); | 1115 int property_index_key = index.GetFieldAccessStubKey(); |
| 1201 uint8_t repr = PropertyDetails::EncodeRepresentation(representation); | 1116 uint8_t repr = PropertyDetails::EncodeRepresentation(representation); |
| 1202 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) | | 1117 set_sub_minor_key(StoreFieldByIndexBits::encode(property_index_key) | |
| 1203 RepresentationBits::encode(repr)); | 1118 RepresentationBits::encode(repr)); |
| 1204 } | 1119 } |
| (...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3061 #undef DEFINE_HYDROGEN_CODE_STUB | 2976 #undef DEFINE_HYDROGEN_CODE_STUB |
| 3062 #undef DEFINE_CODE_STUB | 2977 #undef DEFINE_CODE_STUB |
| 3063 #undef DEFINE_CODE_STUB_BASE | 2978 #undef DEFINE_CODE_STUB_BASE |
| 3064 | 2979 |
| 3065 extern Representation RepresentationFromType(Type* type); | 2980 extern Representation RepresentationFromType(Type* type); |
| 3066 | 2981 |
| 3067 } // namespace internal | 2982 } // namespace internal |
| 3068 } // namespace v8 | 2983 } // namespace v8 |
| 3069 | 2984 |
| 3070 #endif // V8_CODE_STUBS_H_ | 2985 #endif // V8_CODE_STUBS_H_ |
| OLD | NEW |