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 CanBeImmediateIndex(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); |
| 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, CanBeImmediateIndex(index()) |
| 899 ? Location::RegisterOrConstant(index()) |
| 900 : Location::RequiresRegister()); |
| 901 locs->set_out(Location::RequiresRegister()); |
| 902 return locs; |
888 } | 903 } |
889 | 904 |
890 | 905 |
891 void LoadIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 906 void LoadIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
892 Register array = locs()->in(0).reg(); | 907 Register array = locs()->in(0).reg(); |
893 Register index = locs()->in(1).reg(); | |
894 Register result = locs()->out().reg(); | 908 Register result = locs()->out().reg(); |
895 | 909 |
896 // Note that index is Smi, i.e, times 4. | 910 Location index = locs()->in(1); |
897 ASSERT(kSmiTagShift == 1); | 911 if (index.IsRegister()) { |
898 __ movq(result, FieldAddress(array, index, TIMES_4, sizeof(RawArray))); | 912 // Note that index is Smi, i.e, times 4. |
| 913 ASSERT(kSmiTagShift == 1); |
| 914 __ movq(result, |
| 915 FieldAddress(array, index.reg(), TIMES_4, sizeof(RawArray))); |
| 916 } else { |
| 917 const int64_t disp = |
| 918 Smi::Cast(index.constant()).Value() * kWordSize + sizeof(RawArray); |
| 919 ASSERT(Utils::IsInt(32, disp)); |
| 920 __ movq(result, FieldAddress(array, static_cast<int32_t>(disp))); |
| 921 } |
899 } | 922 } |
900 | 923 |
901 | 924 |
902 LocationSummary* StoreIndexedInstr::MakeLocationSummary() const { | 925 LocationSummary* StoreIndexedInstr::MakeLocationSummary() const { |
903 const intptr_t kNumInputs = 3; | 926 const intptr_t kNumInputs = 3; |
904 const intptr_t kNumTemps = 0; | 927 const intptr_t kNumTemps = 0; |
905 LocationSummary* locs = | 928 LocationSummary* locs = |
906 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 929 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
907 locs->set_in(0, Location::RequiresRegister()); | 930 locs->set_in(0, Location::RequiresRegister()); |
908 locs->set_in(1, Location::RequiresRegister()); | 931 locs->set_in(1, CanBeImmediateIndex(index()) |
909 locs->set_in(2, value()->NeedsStoreBuffer() ? Location::WritableRegister() | 932 ? Location::RegisterOrConstant(index()) |
910 : Location::RequiresRegister()); | 933 : Location::RequiresRegister()); |
| 934 locs->set_in(2, value()->NeedsStoreBuffer() |
| 935 ? Location::WritableRegister() |
| 936 : Location::RegisterOrConstant(value())); |
911 return locs; | 937 return locs; |
912 } | 938 } |
913 | 939 |
914 | 940 |
915 void StoreIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 941 void StoreIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
916 Register array = locs()->in(0).reg(); | 942 Register array = locs()->in(0).reg(); |
917 Register index = locs()->in(1).reg(); | |
918 Register value = locs()->in(2).reg(); | |
919 | 943 |
920 // Note that index is Smi, i.e, times 4. | 944 // Note that index is Smi, i.e, times 4. |
921 ASSERT(kSmiTagShift == 1); | 945 ASSERT(kSmiTagShift == 1); |
| 946 Location index = locs()->in(1); |
| 947 FieldAddress field_address = index.IsConstant() |
| 948 ? FieldAddress( |
| 949 array, |
| 950 static_cast<int32_t>( |
| 951 Smi::Cast(index.constant()).Value() * kWordSize + sizeof(RawArray))) |
| 952 : FieldAddress(array, index.reg(), TIMES_4, sizeof(RawArray)); |
| 953 |
922 if (this->value()->NeedsStoreBuffer()) { | 954 if (this->value()->NeedsStoreBuffer()) { |
923 __ StoreIntoObject(array, | 955 Register value = locs()->in(2).reg(); |
924 FieldAddress(array, index, TIMES_4, sizeof(RawArray)), | 956 __ StoreIntoObject(array, field_address, value); |
925 value); | |
926 } else { | 957 } else { |
927 __ StoreIntoObjectNoBarrier(array, | 958 if (locs()->in(2).IsConstant()) { |
928 FieldAddress(array, index, TIMES_4, sizeof(RawArray)), | 959 const Object& constant = locs()->in(2).constant(); |
929 value); | 960 __ StoreObject(field_address, constant); |
| 961 } else { |
| 962 Register value = locs()->in(2).reg(); |
| 963 __ StoreIntoObjectNoBarrier(array, field_address, value); |
| 964 } |
930 } | 965 } |
931 } | 966 } |
932 | 967 |
933 | 968 |
934 LocationSummary* LoadInstanceFieldInstr::MakeLocationSummary() const { | 969 LocationSummary* LoadInstanceFieldInstr::MakeLocationSummary() const { |
935 // TODO(fschneider): For this instruction the input register may be | 970 // TODO(fschneider): For this instruction the input register may be |
936 // reused for the result (but is not required to) because the input | 971 // 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 | 972 // is not used after the result is defined. We should consider adding |
938 // this information to the input policy. | 973 // this information to the input policy. |
939 return LocationSummary::Make(1, | 974 return LocationSummary::Make(1, |
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2302 __ j(ABOVE_EQUAL, deopt); | 2337 __ j(ABOVE_EQUAL, deopt); |
2303 } | 2338 } |
2304 } | 2339 } |
2305 | 2340 |
2306 | 2341 |
2307 } // namespace dart | 2342 } // namespace dart |
2308 | 2343 |
2309 #undef __ | 2344 #undef __ |
2310 | 2345 |
2311 #endif // defined TARGET_ARCH_X64 | 2346 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |