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

Side by Side Diff: src/ia32/codegen-ia32.h

Issue 844006: Merge changes up to V8 version 2.1.3 into the partial snapshots (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/partial_snapshots/
Patch Set: Created 10 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/ia32/builtins-ia32.cc ('k') | src/ia32/codegen-ia32.cc » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 10 matching lines...) Expand all
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef V8_IA32_CODEGEN_IA32_H_ 28 #ifndef V8_IA32_CODEGEN_IA32_H_
29 #define V8_IA32_CODEGEN_IA32_H_ 29 #define V8_IA32_CODEGEN_IA32_H_
30 30
31 #include "ic-inl.h"
32
31 namespace v8 { 33 namespace v8 {
32 namespace internal { 34 namespace internal {
33 35
34 // Forward declarations 36 // Forward declarations
35 class CompilationInfo; 37 class CompilationInfo;
36 class DeferredCode; 38 class DeferredCode;
37 class RegisterAllocator; 39 class RegisterAllocator;
38 class RegisterFile; 40 class RegisterFile;
39 41
40 enum InitState { CONST_INIT, NOT_CONST_INIT }; 42 enum InitState { CONST_INIT, NOT_CONST_INIT };
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 338
337 bool in_spilled_code() const { return in_spilled_code_; } 339 bool in_spilled_code() const { return in_spilled_code_; }
338 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } 340 void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; }
339 341
340 private: 342 private:
341 // Construction/Destruction 343 // Construction/Destruction
342 explicit CodeGenerator(MacroAssembler* masm); 344 explicit CodeGenerator(MacroAssembler* masm);
343 345
344 // Accessors 346 // Accessors
345 inline bool is_eval(); 347 inline bool is_eval();
346 Scope* scope(); 348 inline Scope* scope();
347 349
348 // Generating deferred code. 350 // Generating deferred code.
349 void ProcessDeferred(); 351 void ProcessDeferred();
350 352
351 // State 353 // State
352 ControlDestination* destination() const { return state_->destination(); } 354 ControlDestination* destination() const { return state_->destination(); }
353 355
354 // Track loop nesting level. 356 // Track loop nesting level.
355 int loop_nesting() const { return loop_nesting_; } 357 int loop_nesting() const { return loop_nesting_; }
356 void IncrementLoopNesting() { loop_nesting_++; } 358 void IncrementLoopNesting() { loop_nesting_++; }
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 Result* right, 489 Result* right,
488 OverwriteMode overwrite_mode); 490 OverwriteMode overwrite_mode);
489 491
490 void Comparison(AstNode* node, 492 void Comparison(AstNode* node,
491 Condition cc, 493 Condition cc,
492 bool strict, 494 bool strict,
493 ControlDestination* destination); 495 ControlDestination* destination);
494 496
495 // To prevent long attacker-controlled byte sequences, integer constants 497 // To prevent long attacker-controlled byte sequences, integer constants
496 // from the JavaScript source are loaded in two parts if they are larger 498 // from the JavaScript source are loaded in two parts if they are larger
497 // than 16 bits. 499 // than 17 bits.
498 static const int kMaxSmiInlinedBits = 16; 500 static const int kMaxSmiInlinedBits = 17;
499 bool IsUnsafeSmi(Handle<Object> value); 501 bool IsUnsafeSmi(Handle<Object> value);
500 // Load an integer constant x into a register target or into the stack using 502 // Load an integer constant x into a register target or into the stack using
501 // at most 16 bits of user-controlled data per assembly operation. 503 // at most 16 bits of user-controlled data per assembly operation.
502 void MoveUnsafeSmi(Register target, Handle<Object> value); 504 void MoveUnsafeSmi(Register target, Handle<Object> value);
503 void StoreUnsafeSmiToLocal(int offset, Handle<Object> value); 505 void StoreUnsafeSmiToLocal(int offset, Handle<Object> value);
504 void PushUnsafeSmi(Handle<Object> value); 506 void PushUnsafeSmi(Handle<Object> value);
505 507
506 void CallWithArguments(ZoneList<Expression*>* arguments, 508 void CallWithArguments(ZoneList<Expression*>* arguments,
507 CallFunctionFlags flags, 509 CallFunctionFlags flags,
508 int position); 510 int position);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 void GenerateArgumentsAccess(ZoneList<Expression*>* args); 558 void GenerateArgumentsAccess(ZoneList<Expression*>* args);
557 559
558 // Support for accessing the class and value fields of an object. 560 // Support for accessing the class and value fields of an object.
559 void GenerateClassOf(ZoneList<Expression*>* args); 561 void GenerateClassOf(ZoneList<Expression*>* args);
560 void GenerateValueOf(ZoneList<Expression*>* args); 562 void GenerateValueOf(ZoneList<Expression*>* args);
561 void GenerateSetValueOf(ZoneList<Expression*>* args); 563 void GenerateSetValueOf(ZoneList<Expression*>* args);
562 564
563 // Fast support for charCodeAt(n). 565 // Fast support for charCodeAt(n).
564 void GenerateFastCharCodeAt(ZoneList<Expression*>* args); 566 void GenerateFastCharCodeAt(ZoneList<Expression*>* args);
565 567
568 // Fast support for string.charAt(n) and string[n].
569 void GenerateCharFromCode(ZoneList<Expression*>* args);
570
566 // Fast support for object equality testing. 571 // Fast support for object equality testing.
567 void GenerateObjectEquals(ZoneList<Expression*>* args); 572 void GenerateObjectEquals(ZoneList<Expression*>* args);
568 573
569 void GenerateLog(ZoneList<Expression*>* args); 574 void GenerateLog(ZoneList<Expression*>* args);
570 575
571 void GenerateGetFramePointer(ZoneList<Expression*>* args); 576 void GenerateGetFramePointer(ZoneList<Expression*>* args);
572 577
573 // Fast support for Math.random(). 578 // Fast support for Math.random().
574 void GenerateRandomPositiveSmi(ZoneList<Expression*>* args); 579 void GenerateRandomPositiveSmi(ZoneList<Expression*>* args);
575 580
576 // Fast support for StringAdd. 581 // Fast support for StringAdd.
577 void GenerateStringAdd(ZoneList<Expression*>* args); 582 void GenerateStringAdd(ZoneList<Expression*>* args);
578 583
579 // Fast support for SubString. 584 // Fast support for SubString.
580 void GenerateSubString(ZoneList<Expression*>* args); 585 void GenerateSubString(ZoneList<Expression*>* args);
581 586
582 // Fast support for StringCompare. 587 // Fast support for StringCompare.
583 void GenerateStringCompare(ZoneList<Expression*>* args); 588 void GenerateStringCompare(ZoneList<Expression*>* args);
584 589
585 // Support for direct calls from JavaScript to native RegExp code. 590 // Support for direct calls from JavaScript to native RegExp code.
586 void GenerateRegExpExec(ZoneList<Expression*>* args); 591 void GenerateRegExpExec(ZoneList<Expression*>* args);
587 592
588 // Fast support for number to string. 593 // Fast support for number to string.
589 void GenerateNumberToString(ZoneList<Expression*>* args); 594 void GenerateNumberToString(ZoneList<Expression*>* args);
590 595
596 // Fast support for Math.pow().
597 void GenerateMathPow(ZoneList<Expression*>* args);
598
591 // Fast call to transcendental functions. 599 // Fast call to transcendental functions.
592 void GenerateMathSin(ZoneList<Expression*>* args); 600 void GenerateMathSin(ZoneList<Expression*>* args);
593 void GenerateMathCos(ZoneList<Expression*>* args); 601 void GenerateMathCos(ZoneList<Expression*>* args);
594 602
603 // Fast case for sqrt
604 void GenerateMathSqrt(ZoneList<Expression*>* args);
605
595 // Simple condition analysis. 606 // Simple condition analysis.
596 enum ConditionAnalysis { 607 enum ConditionAnalysis {
597 ALWAYS_TRUE, 608 ALWAYS_TRUE,
598 ALWAYS_FALSE, 609 ALWAYS_FALSE,
599 DONT_KNOW 610 DONT_KNOW
600 }; 611 };
601 ConditionAnalysis AnalyzeCondition(Expression* cond); 612 ConditionAnalysis AnalyzeCondition(Expression* cond);
602 613
603 // Methods used to indicate which source code is generated for. Source 614 // Methods used to indicate which source code is generated for. Source
604 // positions are collected by the assembler and emitted with the relocation 615 // positions are collected by the assembler and emitted with the relocation
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 NO_GENERIC_BINARY_FLAGS = 0, 691 NO_GENERIC_BINARY_FLAGS = 0,
681 NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub. 692 NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub.
682 }; 693 };
683 694
684 695
685 class GenericBinaryOpStub: public CodeStub { 696 class GenericBinaryOpStub: public CodeStub {
686 public: 697 public:
687 GenericBinaryOpStub(Token::Value op, 698 GenericBinaryOpStub(Token::Value op,
688 OverwriteMode mode, 699 OverwriteMode mode,
689 GenericBinaryFlags flags, 700 GenericBinaryFlags flags,
690 NumberInfo::Type operands_type = NumberInfo::kUnknown) 701 NumberInfo operands_type)
691 : op_(op), 702 : op_(op),
692 mode_(mode), 703 mode_(mode),
693 flags_(flags), 704 flags_(flags),
694 args_in_registers_(false), 705 args_in_registers_(false),
695 args_reversed_(false), 706 args_reversed_(false),
696 name_(NULL), 707 static_operands_type_(operands_type),
697 operands_type_(operands_type) { 708 runtime_operands_type_(BinaryOpIC::DEFAULT),
709 name_(NULL) {
710 if (static_operands_type_.IsSmi()) {
711 mode_ = NO_OVERWRITE;
712 }
698 use_sse3_ = CpuFeatures::IsSupported(SSE3); 713 use_sse3_ = CpuFeatures::IsSupported(SSE3);
699 ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); 714 ASSERT(OpBits::is_valid(Token::NUM_TOKENS));
700 } 715 }
701 716
717 GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo runtime_operands_type)
718 : op_(OpBits::decode(key)),
719 mode_(ModeBits::decode(key)),
720 flags_(FlagBits::decode(key)),
721 args_in_registers_(ArgsInRegistersBits::decode(key)),
722 args_reversed_(ArgsReversedBits::decode(key)),
723 use_sse3_(SSE3Bits::decode(key)),
724 static_operands_type_(NumberInfo::ExpandedRepresentation(
725 StaticTypeInfoBits::decode(key))),
726 runtime_operands_type_(runtime_operands_type),
727 name_(NULL) {
728 }
729
702 // Generate code to call the stub with the supplied arguments. This will add 730 // Generate code to call the stub with the supplied arguments. This will add
703 // code at the call site to prepare arguments either in registers or on the 731 // code at the call site to prepare arguments either in registers or on the
704 // stack together with the actual call. 732 // stack together with the actual call.
705 void GenerateCall(MacroAssembler* masm, Register left, Register right); 733 void GenerateCall(MacroAssembler* masm, Register left, Register right);
706 void GenerateCall(MacroAssembler* masm, Register left, Smi* right); 734 void GenerateCall(MacroAssembler* masm, Register left, Smi* right);
707 void GenerateCall(MacroAssembler* masm, Smi* left, Register right); 735 void GenerateCall(MacroAssembler* masm, Smi* left, Register right);
708 736
709 Result GenerateCall(MacroAssembler* masm, 737 Result GenerateCall(MacroAssembler* masm,
710 VirtualFrame* frame, 738 VirtualFrame* frame,
711 Result* left, 739 Result* left,
712 Result* right); 740 Result* right);
713 741
714 private: 742 private:
715 Token::Value op_; 743 Token::Value op_;
716 OverwriteMode mode_; 744 OverwriteMode mode_;
717 GenericBinaryFlags flags_; 745 GenericBinaryFlags flags_;
718 bool args_in_registers_; // Arguments passed in registers not on the stack. 746 bool args_in_registers_; // Arguments passed in registers not on the stack.
719 bool args_reversed_; // Left and right argument are swapped. 747 bool args_reversed_; // Left and right argument are swapped.
720 bool use_sse3_; 748 bool use_sse3_;
749
750 // Number type information of operands, determined by code generator.
751 NumberInfo static_operands_type_;
752
753 // Operand type information determined at runtime.
754 BinaryOpIC::TypeInfo runtime_operands_type_;
755
721 char* name_; 756 char* name_;
722 NumberInfo::Type operands_type_; // Number type information of operands.
723 757
724 const char* GetName(); 758 const char* GetName();
725 759
726 #ifdef DEBUG 760 #ifdef DEBUG
727 void Print() { 761 void Print() {
728 PrintF("GenericBinaryOpStub %d (op %s), " 762 PrintF("GenericBinaryOpStub %d (op %s), "
729 "(mode %d, flags %d, registers %d, reversed %d, number_info %s)\n", 763 "(mode %d, flags %d, registers %d, reversed %d, number_info %s)\n",
730 MinorKey(), 764 MinorKey(),
731 Token::String(op_), 765 Token::String(op_),
732 static_cast<int>(mode_), 766 static_cast<int>(mode_),
733 static_cast<int>(flags_), 767 static_cast<int>(flags_),
734 static_cast<int>(args_in_registers_), 768 static_cast<int>(args_in_registers_),
735 static_cast<int>(args_reversed_), 769 static_cast<int>(args_reversed_),
736 NumberInfo::ToString(operands_type_)); 770 static_operands_type_.ToString());
737 } 771 }
738 #endif 772 #endif
739 773
740 // Minor key encoding in 16 bits NNNFRASOOOOOOOMM. 774 // Minor key encoding in 18 bits RRNNNFRASOOOOOOOMM.
741 class ModeBits: public BitField<OverwriteMode, 0, 2> {}; 775 class ModeBits: public BitField<OverwriteMode, 0, 2> {};
742 class OpBits: public BitField<Token::Value, 2, 7> {}; 776 class OpBits: public BitField<Token::Value, 2, 7> {};
743 class SSE3Bits: public BitField<bool, 9, 1> {}; 777 class SSE3Bits: public BitField<bool, 9, 1> {};
744 class ArgsInRegistersBits: public BitField<bool, 10, 1> {}; 778 class ArgsInRegistersBits: public BitField<bool, 10, 1> {};
745 class ArgsReversedBits: public BitField<bool, 11, 1> {}; 779 class ArgsReversedBits: public BitField<bool, 11, 1> {};
746 class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {}; 780 class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {};
747 class NumberInfoBits: public BitField<NumberInfo::Type, 13, 3> {}; 781 class StaticTypeInfoBits: public BitField<int, 13, 3> {};
782 class RuntimeTypeInfoBits: public BitField<BinaryOpIC::TypeInfo, 16, 2> {};
748 783
749 Major MajorKey() { return GenericBinaryOp; } 784 Major MajorKey() { return GenericBinaryOp; }
750 int MinorKey() { 785 int MinorKey() {
751 // Encode the parameters in a unique 16 bit value. 786 // Encode the parameters in a unique 18 bit value.
752 return OpBits::encode(op_) 787 return OpBits::encode(op_)
753 | ModeBits::encode(mode_) 788 | ModeBits::encode(mode_)
754 | FlagBits::encode(flags_) 789 | FlagBits::encode(flags_)
755 | SSE3Bits::encode(use_sse3_) 790 | SSE3Bits::encode(use_sse3_)
756 | ArgsInRegistersBits::encode(args_in_registers_) 791 | ArgsInRegistersBits::encode(args_in_registers_)
757 | ArgsReversedBits::encode(args_reversed_) 792 | ArgsReversedBits::encode(args_reversed_)
758 | NumberInfoBits::encode(operands_type_); 793 | StaticTypeInfoBits::encode(
794 static_operands_type_.ThreeBitRepresentation())
795 | RuntimeTypeInfoBits::encode(runtime_operands_type_);
759 } 796 }
760 797
761 void Generate(MacroAssembler* masm); 798 void Generate(MacroAssembler* masm);
762 void GenerateSmiCode(MacroAssembler* masm, Label* slow); 799 void GenerateSmiCode(MacroAssembler* masm, Label* slow);
763 void GenerateLoadArguments(MacroAssembler* masm); 800 void GenerateLoadArguments(MacroAssembler* masm);
764 void GenerateReturn(MacroAssembler* masm); 801 void GenerateReturn(MacroAssembler* masm);
765 void GenerateHeapResultAllocation(MacroAssembler* masm, Label* alloc_failure); 802 void GenerateHeapResultAllocation(MacroAssembler* masm, Label* alloc_failure);
803 void GenerateRegisterArgsPush(MacroAssembler* masm);
804 void GenerateTypeTransition(MacroAssembler* masm);
766 805
767 bool ArgsInRegistersSupported() { 806 bool ArgsInRegistersSupported() {
768 return op_ == Token::ADD || op_ == Token::SUB 807 return op_ == Token::ADD || op_ == Token::SUB
769 || op_ == Token::MUL || op_ == Token::DIV; 808 || op_ == Token::MUL || op_ == Token::DIV;
770 } 809 }
771 bool IsOperationCommutative() { 810 bool IsOperationCommutative() {
772 return (op_ == Token::ADD) || (op_ == Token::MUL); 811 return (op_ == Token::ADD) || (op_ == Token::MUL);
773 } 812 }
774 813
775 void SetArgsInRegisters() { args_in_registers_ = true; } 814 void SetArgsInRegisters() { args_in_registers_ = true; }
776 void SetArgsReversed() { args_reversed_ = true; } 815 void SetArgsReversed() { args_reversed_ = true; }
777 bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; } 816 bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; }
778 bool HasArgsInRegisters() { return args_in_registers_; } 817 bool HasArgsInRegisters() { return args_in_registers_; }
779 bool HasArgsReversed() { return args_reversed_; } 818 bool HasArgsReversed() { return args_reversed_; }
819
820 bool ShouldGenerateSmiCode() {
821 return HasSmiCodeInStub() &&
822 runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS &&
823 runtime_operands_type_ != BinaryOpIC::STRINGS;
824 }
825
826 bool ShouldGenerateFPCode() {
827 return runtime_operands_type_ != BinaryOpIC::STRINGS;
828 }
829
830 virtual int GetCodeKind() { return Code::BINARY_OP_IC; }
831
832 virtual InlineCacheState GetICState() {
833 return BinaryOpIC::ToState(runtime_operands_type_);
834 }
780 }; 835 };
781 836
782 837
783 class StringStubBase: public CodeStub { 838 class StringStubBase: public CodeStub {
784 public: 839 public:
785 // Generate code for copying characters using a simple loop. This should only 840 // Generate code for copying characters using a simple loop. This should only
786 // be used in places where the number of characters is small and the 841 // be used in places where the number of characters is small and the
787 // additional setup and checking in GenerateCopyCharactersREP adds too much 842 // additional setup and checking in GenerateCopyCharactersREP adds too much
788 // overhead. Copying of overlapping regions is not supported. 843 // overhead. Copying of overlapping regions is not supported.
789 void GenerateCopyCharacters(MacroAssembler* masm, 844 void GenerateCopyCharacters(MacroAssembler* masm,
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 void Print() { 972 void Print() {
918 PrintF("NumberToStringStub\n"); 973 PrintF("NumberToStringStub\n");
919 } 974 }
920 #endif 975 #endif
921 }; 976 };
922 977
923 978
924 } } // namespace v8::internal 979 } } // namespace v8::internal
925 980
926 #endif // V8_IA32_CODEGEN_IA32_H_ 981 #endif // V8_IA32_CODEGEN_IA32_H_
OLDNEW
« no previous file with comments | « src/ia32/builtins-ia32.cc ('k') | src/ia32/codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698