| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 #include "arm/lithium-codegen-arm.h" | 28 #include "arm/lithium-codegen-arm.h" |
| 29 #include "arm/lithium-gap-resolver-arm.h" | 29 #include "arm/lithium-gap-resolver-arm.h" |
| 30 #include "code-stubs.h" | 30 #include "code-stubs.h" |
| 31 #include "stub-cache.h" | 31 #include "stub-cache.h" |
| 32 | 32 |
| 33 namespace v8 { | 33 namespace v8 { |
| 34 namespace internal { | 34 namespace internal { |
| 35 | 35 |
| 36 | 36 |
| 37 class SafepointGenerator : public PostCallGenerator { | 37 class SafepointGenerator : public CallWrapper { |
| 38 public: | 38 public: |
| 39 SafepointGenerator(LCodeGen* codegen, | 39 SafepointGenerator(LCodeGen* codegen, |
| 40 LPointerMap* pointers, | 40 LPointerMap* pointers, |
| 41 int deoptimization_index) | 41 int deoptimization_index) |
| 42 : codegen_(codegen), | 42 : codegen_(codegen), |
| 43 pointers_(pointers), | 43 pointers_(pointers), |
| 44 deoptimization_index_(deoptimization_index) { } | 44 deoptimization_index_(deoptimization_index) { } |
| 45 virtual ~SafepointGenerator() { } | 45 virtual ~SafepointGenerator() { } |
| 46 | 46 |
| 47 virtual void Generate() { | 47 virtual void BeforeCall(int call_size) { |
| 48 ASSERT(call_size >= 0); |
| 49 // Ensure that we have enough space after the previous safepoint position |
| 50 // for the generated code there. |
| 51 int call_end = codegen_->masm()->pc_offset() + call_size; |
| 52 int prev_jump_end = |
| 53 codegen_->LastSafepointEnd() + Deoptimizer::patch_size(); |
| 54 if (call_end < prev_jump_end) { |
| 55 int padding_size = prev_jump_end - call_end; |
| 56 ASSERT_EQ(0, padding_size % Assembler::kInstrSize); |
| 57 while (padding_size > 0) { |
| 58 codegen_->masm()->nop(); |
| 59 padding_size -= Assembler::kInstrSize; |
| 60 } |
| 61 } |
| 62 } |
| 63 |
| 64 virtual void AfterCall() { |
| 48 codegen_->RecordSafepoint(pointers_, deoptimization_index_); | 65 codegen_->RecordSafepoint(pointers_, deoptimization_index_); |
| 49 } | 66 } |
| 50 | 67 |
| 51 private: | 68 private: |
| 52 LCodeGen* codegen_; | 69 LCodeGen* codegen_; |
| 53 LPointerMap* pointers_; | 70 LPointerMap* pointers_; |
| 54 int deoptimization_index_; | 71 int deoptimization_index_; |
| 55 }; | 72 }; |
| 56 | 73 |
| 57 | 74 |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 } | 789 } |
| 773 } | 790 } |
| 774 | 791 |
| 775 | 792 |
| 776 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { | 793 void LCodeGen::DoUnknownOSRValue(LUnknownOSRValue* instr) { |
| 777 // Nothing to do. | 794 // Nothing to do. |
| 778 } | 795 } |
| 779 | 796 |
| 780 | 797 |
| 781 void LCodeGen::DoModI(LModI* instr) { | 798 void LCodeGen::DoModI(LModI* instr) { |
| 799 if (instr->hydrogen()->HasPowerOf2Divisor()) { |
| 800 Register dividend = ToRegister(instr->InputAt(0)); |
| 801 |
| 802 int32_t divisor = |
| 803 HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
| 804 |
| 805 if (divisor < 0) divisor = -divisor; |
| 806 |
| 807 Label positive_dividend, done; |
| 808 __ tst(dividend, Operand(dividend)); |
| 809 __ b(pl, &positive_dividend); |
| 810 __ rsb(dividend, dividend, Operand(0)); |
| 811 __ and_(dividend, dividend, Operand(divisor - 1)); |
| 812 __ rsb(dividend, dividend, Operand(0), SetCC); |
| 813 if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 814 __ b(ne, &done); |
| 815 DeoptimizeIf(al, instr->environment()); |
| 816 } |
| 817 __ bind(&positive_dividend); |
| 818 __ and_(dividend, dividend, Operand(divisor - 1)); |
| 819 __ bind(&done); |
| 820 return; |
| 821 } |
| 822 |
| 782 class DeferredModI: public LDeferredCode { | 823 class DeferredModI: public LDeferredCode { |
| 783 public: | 824 public: |
| 784 DeferredModI(LCodeGen* codegen, LModI* instr) | 825 DeferredModI(LCodeGen* codegen, LModI* instr) |
| 785 : LDeferredCode(codegen), instr_(instr) { } | 826 : LDeferredCode(codegen), instr_(instr) { } |
| 786 virtual void Generate() { | 827 virtual void Generate() { |
| 787 codegen()->DoDeferredBinaryOpStub(instr_, Token::MOD); | 828 codegen()->DoDeferredBinaryOpStub(instr_, Token::MOD); |
| 788 } | 829 } |
| 789 private: | 830 private: |
| 790 LModI* instr_; | 831 LModI* instr_; |
| 791 }; | 832 }; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 __ b(lt, &done); | 873 __ b(lt, &done); |
| 833 // If not, reduce the left hand side by the right hand | 874 // If not, reduce the left hand side by the right hand |
| 834 // side and check again. | 875 // side and check again. |
| 835 if (i < kUnfolds - 1) __ sub(scratch, scratch, right); | 876 if (i < kUnfolds - 1) __ sub(scratch, scratch, right); |
| 836 } | 877 } |
| 837 | 878 |
| 838 // Check for power of two on the right hand side. | 879 // Check for power of two on the right hand side. |
| 839 __ JumpIfNotPowerOfTwoOrZero(right, scratch, &call_stub); | 880 __ JumpIfNotPowerOfTwoOrZero(right, scratch, &call_stub); |
| 840 // Perform modulo operation (scratch contains right - 1). | 881 // Perform modulo operation (scratch contains right - 1). |
| 841 __ and_(result, scratch, Operand(left)); | 882 __ and_(result, scratch, Operand(left)); |
| 883 __ b(&done); |
| 842 | 884 |
| 843 __ bind(&call_stub); | 885 __ bind(&call_stub); |
| 844 // Call the stub. The numbers in r0 and r1 have | 886 // Call the stub. The numbers in r0 and r1 have |
| 845 // to be tagged to Smis. If that is not possible, deoptimize. | 887 // to be tagged to Smis. If that is not possible, deoptimize. |
| 846 DeferredModI* deferred = new DeferredModI(this, instr); | 888 DeferredModI* deferred = new DeferredModI(this, instr); |
| 847 __ TrySmiTag(left, &deoptimize, scratch); | 889 __ TrySmiTag(left, &deoptimize, scratch); |
| 848 __ TrySmiTag(right, &deoptimize, scratch); | 890 __ TrySmiTag(right, &deoptimize, scratch); |
| 849 | 891 |
| 850 __ b(al, deferred->entry()); | 892 __ b(al, deferred->entry()); |
| 851 __ bind(deferred->exit()); | 893 __ bind(deferred->exit()); |
| (...skipping 2222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3074 instr->pointer_map(), 2, Safepoint::kNoDeoptimizationIndex); | 3116 instr->pointer_map(), 2, Safepoint::kNoDeoptimizationIndex); |
| 3075 if (FLAG_debug_code) { | 3117 if (FLAG_debug_code) { |
| 3076 __ AbortIfNotSmi(r0); | 3118 __ AbortIfNotSmi(r0); |
| 3077 } | 3119 } |
| 3078 __ SmiUntag(r0); | 3120 __ SmiUntag(r0); |
| 3079 __ StoreToSafepointRegisterSlot(r0, result); | 3121 __ StoreToSafepointRegisterSlot(r0, result); |
| 3080 __ PopSafepointRegisters(); | 3122 __ PopSafepointRegisters(); |
| 3081 } | 3123 } |
| 3082 | 3124 |
| 3083 | 3125 |
| 3126 void LCodeGen::DoStringCharFromCode(LStringCharFromCode* instr) { |
| 3127 class DeferredStringCharFromCode: public LDeferredCode { |
| 3128 public: |
| 3129 DeferredStringCharFromCode(LCodeGen* codegen, LStringCharFromCode* instr) |
| 3130 : LDeferredCode(codegen), instr_(instr) { } |
| 3131 virtual void Generate() { codegen()->DoDeferredStringCharFromCode(instr_); } |
| 3132 private: |
| 3133 LStringCharFromCode* instr_; |
| 3134 }; |
| 3135 |
| 3136 DeferredStringCharFromCode* deferred = |
| 3137 new DeferredStringCharFromCode(this, instr); |
| 3138 |
| 3139 ASSERT(instr->hydrogen()->value()->representation().IsInteger32()); |
| 3140 Register char_code = ToRegister(instr->char_code()); |
| 3141 Register result = ToRegister(instr->result()); |
| 3142 ASSERT(!char_code.is(result)); |
| 3143 |
| 3144 __ cmp(char_code, Operand(String::kMaxAsciiCharCode)); |
| 3145 __ b(hi, deferred->entry()); |
| 3146 __ LoadRoot(result, Heap::kSingleCharacterStringCacheRootIndex); |
| 3147 __ add(result, result, Operand(char_code, LSL, kPointerSizeLog2)); |
| 3148 __ ldr(result, FieldMemOperand(result, FixedArray::kHeaderSize)); |
| 3149 __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 3150 __ cmp(result, ip); |
| 3151 __ b(eq, deferred->entry()); |
| 3152 __ bind(deferred->exit()); |
| 3153 } |
| 3154 |
| 3155 |
| 3156 void LCodeGen::DoDeferredStringCharFromCode(LStringCharFromCode* instr) { |
| 3157 Register char_code = ToRegister(instr->char_code()); |
| 3158 Register result = ToRegister(instr->result()); |
| 3159 |
| 3160 // TODO(3095996): Get rid of this. For now, we need to make the |
| 3161 // result register contain a valid pointer because it is already |
| 3162 // contained in the register pointer map. |
| 3163 __ mov(result, Operand(0)); |
| 3164 |
| 3165 __ PushSafepointRegisters(); |
| 3166 __ SmiTag(char_code); |
| 3167 __ push(char_code); |
| 3168 __ CallRuntimeSaveDoubles(Runtime::kCharFromCode); |
| 3169 RecordSafepointWithRegisters( |
| 3170 instr->pointer_map(), 1, Safepoint::kNoDeoptimizationIndex); |
| 3171 __ StoreToSafepointRegisterSlot(r0, result); |
| 3172 __ PopSafepointRegisters(); |
| 3173 } |
| 3174 |
| 3175 |
| 3084 void LCodeGen::DoStringLength(LStringLength* instr) { | 3176 void LCodeGen::DoStringLength(LStringLength* instr) { |
| 3085 Register string = ToRegister(instr->InputAt(0)); | 3177 Register string = ToRegister(instr->InputAt(0)); |
| 3086 Register result = ToRegister(instr->result()); | 3178 Register result = ToRegister(instr->result()); |
| 3087 __ ldr(result, FieldMemOperand(string, String::kLengthOffset)); | 3179 __ ldr(result, FieldMemOperand(string, String::kLengthOffset)); |
| 3088 } | 3180 } |
| 3089 | 3181 |
| 3090 | 3182 |
| 3091 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { | 3183 void LCodeGen::DoInteger32ToDouble(LInteger32ToDouble* instr) { |
| 3092 LOperand* input = instr->InputAt(0); | 3184 LOperand* input = instr->InputAt(0); |
| 3093 ASSERT(input->IsRegister() || input->IsStackSlot()); | 3185 ASSERT(input->IsRegister() || input->IsStackSlot()); |
| (...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3860 ASSERT(!environment->HasBeenRegistered()); | 3952 ASSERT(!environment->HasBeenRegistered()); |
| 3861 RegisterEnvironmentForDeoptimization(environment); | 3953 RegisterEnvironmentForDeoptimization(environment); |
| 3862 ASSERT(osr_pc_offset_ == -1); | 3954 ASSERT(osr_pc_offset_ == -1); |
| 3863 osr_pc_offset_ = masm()->pc_offset(); | 3955 osr_pc_offset_ = masm()->pc_offset(); |
| 3864 } | 3956 } |
| 3865 | 3957 |
| 3866 | 3958 |
| 3867 #undef __ | 3959 #undef __ |
| 3868 | 3960 |
| 3869 } } // namespace v8::internal | 3961 } } // namespace v8::internal |
| OLD | NEW |