OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
7 | 7 |
8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
9 | 9 |
10 #include "lib/error.h" | 10 #include "lib/error.h" |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 __ movq(RBX, Immediate(reinterpret_cast<uword>(native_c_function()))); | 873 __ movq(RBX, Immediate(reinterpret_cast<uword>(native_c_function()))); |
874 __ movq(R10, Immediate(arg_count)); | 874 __ movq(R10, Immediate(arg_count)); |
875 compiler->GenerateCall(token_pos(), | 875 compiler->GenerateCall(token_pos(), |
876 &StubCode::CallNativeCFunctionLabel(), | 876 &StubCode::CallNativeCFunctionLabel(), |
877 PcDescriptors::kOther, | 877 PcDescriptors::kOther, |
878 locs()); | 878 locs()); |
879 __ popq(result); | 879 __ popq(result); |
880 } | 880 } |
881 | 881 |
882 | 882 |
883 static bool CanBeIndexImmediate(Value* index) { | |
884 if (!index->definition()->IsConstant()) return false; | |
885 const Object& constant = index->definition()->AsConstant()->value(); | |
886 const Smi& smi_const = Smi::Cast(constant); | |
srdjan
2012/09/12 12:56:16
The reason why this works is because this code mus
Florian Schneider
2012/09/12 13:28:35
Yes, and when optimizing we generate a smi-check f
| |
887 int64_t disp = smi_const.AsInt64Value() * kWordSize + sizeof(RawArray); | |
888 return Utils::IsInt(32, disp); | |
889 } | |
890 | |
891 | |
883 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { | 892 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { |
884 const intptr_t kNumInputs = 2; | 893 const intptr_t kNumInputs = 2; |
885 return LocationSummary::Make(kNumInputs, | 894 const intptr_t kNumTemps = 0; |
886 Location::RequiresRegister(), | 895 LocationSummary* locs = |
887 LocationSummary::kNoCall); | 896 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
897 locs->set_in(0, Location::RequiresRegister()); | |
898 locs->set_in(1, CanBeIndexImmediate(index()) | |
899 ? Location::RegisterOrConstant(index()) | |
900 : Location::RequiresRegister()); | |
901 locs->set_out(Location::RequiresRegister()); | |
902 return locs; | |
903 } | |
904 | |
905 | |
906 static int64_t RawSmi(const Object& constant) { | |
907 ASSERT(constant.IsSmi()); | |
908 return reinterpret_cast<int64_t>(constant.raw()); | |
888 } | 909 } |
889 | 910 |
890 | 911 |
891 void LoadIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 912 void LoadIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
892 Register array = locs()->in(0).reg(); | 913 Register array = locs()->in(0).reg(); |
893 Register index = locs()->in(1).reg(); | |
894 Register result = locs()->out().reg(); | 914 Register result = locs()->out().reg(); |
895 | 915 |
896 // Note that index is Smi, i.e, times 4. | 916 // Note that index is Smi, i.e, times 4. |
897 ASSERT(kSmiTagShift == 1); | 917 ASSERT(kSmiTagShift == 1); |
898 __ movq(result, FieldAddress(array, index, TIMES_4, sizeof(RawArray))); | 918 if (locs()->in(1).IsRegister()) { |
919 Register index = locs()->in(1).reg(); | |
920 __ movq(result, FieldAddress(array, index, TIMES_4, sizeof(RawArray))); | |
921 } else { | |
922 int64_t disp = RawSmi(locs()->in(1).constant()) * 4 + sizeof(RawArray); | |
923 ASSERT(Utils::IsInt(32, disp)); | |
924 __ movq(result, FieldAddress(array, static_cast<int32_t>(disp))); | |
925 } | |
899 } | 926 } |
900 | 927 |
901 | 928 |
902 LocationSummary* StoreIndexedInstr::MakeLocationSummary() const { | 929 LocationSummary* StoreIndexedInstr::MakeLocationSummary() const { |
903 const intptr_t kNumInputs = 3; | 930 const intptr_t kNumInputs = 3; |
904 const intptr_t kNumTemps = 0; | 931 const intptr_t kNumTemps = 0; |
905 LocationSummary* locs = | 932 LocationSummary* locs = |
906 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 933 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
907 locs->set_in(0, Location::RequiresRegister()); | 934 locs->set_in(0, Location::RequiresRegister()); |
908 locs->set_in(1, Location::RequiresRegister()); | 935 locs->set_in(1, CanBeIndexImmediate(index()) |
909 locs->set_in(2, value()->NeedsStoreBuffer() ? Location::WritableRegister() | 936 ? Location::RegisterOrConstant(index()) |
910 : Location::RequiresRegister()); | 937 : Location::RequiresRegister()); |
938 locs->set_in(2, value()->NeedsStoreBuffer() | |
939 ? Location::WritableRegister() | |
940 : Location::RegisterOrConstant(value())); | |
911 return locs; | 941 return locs; |
912 } | 942 } |
913 | 943 |
914 | 944 |
915 void StoreIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 945 void StoreIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
916 Register array = locs()->in(0).reg(); | 946 Register array = locs()->in(0).reg(); |
917 Register index = locs()->in(1).reg(); | |
918 Register value = locs()->in(2).reg(); | |
919 | 947 |
920 // Note that index is Smi, i.e, times 4. | 948 // Note that index is Smi, i.e, times 4. |
921 ASSERT(kSmiTagShift == 1); | 949 ASSERT(kSmiTagShift == 1); |
950 FieldAddress field_address = locs()->in(1).IsConstant() | |
951 ? FieldAddress( | |
952 array, | |
953 static_cast<int32_t>( | |
954 RawSmi(locs()->in(1).constant()) * 4 + sizeof(RawArray))) | |
955 : FieldAddress(array, locs()->in(1).reg(), TIMES_4, sizeof(RawArray)); | |
956 | |
922 if (this->value()->NeedsStoreBuffer()) { | 957 if (this->value()->NeedsStoreBuffer()) { |
923 __ StoreIntoObject(array, | 958 Register value = locs()->in(2).reg(); |
924 FieldAddress(array, index, TIMES_4, sizeof(RawArray)), | 959 __ StoreIntoObject(array, field_address, value); |
925 value); | |
926 } else { | 960 } else { |
927 __ StoreIntoObjectNoBarrier(array, | 961 if (locs()->in(2).IsConstant()) { |
928 FieldAddress(array, index, TIMES_4, sizeof(RawArray)), | 962 const Object& constant = locs()->in(2).constant(); |
929 value); | 963 __ StoreObject(field_address, constant); |
964 } else { | |
965 Register value = locs()->in(2).reg(); | |
966 __ StoreIntoObjectNoBarrier(array, field_address, value); | |
967 } | |
930 } | 968 } |
931 } | 969 } |
932 | 970 |
933 | 971 |
934 LocationSummary* LoadInstanceFieldInstr::MakeLocationSummary() const { | 972 LocationSummary* LoadInstanceFieldInstr::MakeLocationSummary() const { |
935 // TODO(fschneider): For this instruction the input register may be | 973 // TODO(fschneider): For this instruction the input register may be |
936 // reused for the result (but is not required to) because the input | 974 // reused for the result (but is not required to) because the input |
937 // is not used after the result is defined. We should consider adding | 975 // is not used after the result is defined. We should consider adding |
938 // this information to the input policy. | 976 // this information to the input policy. |
939 return LocationSummary::Make(1, | 977 return LocationSummary::Make(1, |
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2302 __ j(ABOVE_EQUAL, deopt); | 2340 __ j(ABOVE_EQUAL, deopt); |
2303 } | 2341 } |
2304 } | 2342 } |
2305 | 2343 |
2306 | 2344 |
2307 } // namespace dart | 2345 } // namespace dart |
2308 | 2346 |
2309 #undef __ | 2347 #undef __ |
2310 | 2348 |
2311 #endif // defined TARGET_ARCH_X64 | 2349 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |