| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return LocationSummary::Make(kNumInputs, | 143 return LocationSummary::Make(kNumInputs, |
| 144 Location::RequiresRegister(), | 144 Location::RequiresRegister(), |
| 145 LocationSummary::kNoCall); | 145 LocationSummary::kNoCall); |
| 146 } | 146 } |
| 147 | 147 |
| 148 | 148 |
| 149 void ConstantInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 149 void ConstantInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 150 // The register allocator drops constant definitions that have no uses. | 150 // The register allocator drops constant definitions that have no uses. |
| 151 if (!locs()->out().IsInvalid()) { | 151 if (!locs()->out().IsInvalid()) { |
| 152 Register result = locs()->out().reg(); | 152 Register result = locs()->out().reg(); |
| 153 __ LoadObject(result, value()); | 153 __ LoadObjectSafely(result, value()); |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 | 157 |
| 158 LocationSummary* AssertAssignableInstr::MakeLocationSummary() const { | 158 LocationSummary* AssertAssignableInstr::MakeLocationSummary() const { |
| 159 const intptr_t kNumInputs = 3; | 159 const intptr_t kNumInputs = 3; |
| 160 const intptr_t kNumTemps = 0; | 160 const intptr_t kNumTemps = 0; |
| 161 LocationSummary* summary = | 161 LocationSummary* summary = |
| 162 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); | 162 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); |
| 163 summary->set_in(0, Location::RegisterLocation(EAX)); // Value. | 163 summary->set_in(0, Location::RegisterLocation(EAX)); // Value. |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 (is_bootstrap_native()) ? &StubCode::CallBootstrapCFunctionLabel() : | 934 (is_bootstrap_native()) ? &StubCode::CallBootstrapCFunctionLabel() : |
| 935 &StubCode::CallNativeCFunctionLabel(); | 935 &StubCode::CallNativeCFunctionLabel(); |
| 936 compiler->GenerateCall(token_pos(), | 936 compiler->GenerateCall(token_pos(), |
| 937 stub_entry, | 937 stub_entry, |
| 938 PcDescriptors::kOther, | 938 PcDescriptors::kOther, |
| 939 locs()); | 939 locs()); |
| 940 __ popl(result); | 940 __ popl(result); |
| 941 } | 941 } |
| 942 | 942 |
| 943 | 943 |
| 944 static bool CanBeImmediateIndex(Value* index, intptr_t cid) { | 944 static bool CanBeImmediateIndex(Value* value, intptr_t cid) { |
| 945 if (!index->definition()->IsConstant()) return false; | 945 ConstantInstr* constant = value->definition()->AsConstant(); |
| 946 const Object& constant = index->definition()->AsConstant()->value(); | 946 if ((constant == NULL) || !Assembler::IsSafeSmi(constant->value())) { |
| 947 if (!constant.IsSmi()) return false; | 947 return false; |
| 948 const Smi& smi_const = Smi::Cast(constant); | 948 } |
| 949 const int64_t index = Smi::Cast(constant->value()).AsInt64Value(); |
| 949 const intptr_t scale = FlowGraphCompiler::ElementSizeFor(cid); | 950 const intptr_t scale = FlowGraphCompiler::ElementSizeFor(cid); |
| 950 const intptr_t data_offset = FlowGraphCompiler::DataOffsetFor(cid); | 951 const intptr_t offset = FlowGraphCompiler::DataOffsetFor(cid); |
| 951 const int64_t disp = smi_const.AsInt64Value() * scale + data_offset; | 952 const int64_t displacement = index * scale + offset; |
| 952 return Utils::IsInt(32, disp); | 953 return Utils::IsInt(32, displacement); |
| 953 } | 954 } |
| 954 | 955 |
| 955 | 956 |
| 956 LocationSummary* StringFromCharCodeInstr::MakeLocationSummary() const { | 957 LocationSummary* StringFromCharCodeInstr::MakeLocationSummary() const { |
| 957 const intptr_t kNumInputs = 1; | 958 const intptr_t kNumInputs = 1; |
| 958 // TODO(fschneider): Allow immediate operands for the char code. | 959 // TODO(fschneider): Allow immediate operands for the char code. |
| 959 return LocationSummary::Make(kNumInputs, | 960 return LocationSummary::Make(kNumInputs, |
| 960 Location::RequiresRegister(), | 961 Location::RequiresRegister(), |
| 961 LocationSummary::kNoCall); | 962 LocationSummary::kNoCall); |
| 962 } | 963 } |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 } | 1107 } |
| 1107 } | 1108 } |
| 1108 | 1109 |
| 1109 | 1110 |
| 1110 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { | 1111 LocationSummary* LoadIndexedInstr::MakeLocationSummary() const { |
| 1111 const intptr_t kNumInputs = 2; | 1112 const intptr_t kNumInputs = 2; |
| 1112 const intptr_t kNumTemps = 0; | 1113 const intptr_t kNumTemps = 0; |
| 1113 LocationSummary* locs = | 1114 LocationSummary* locs = |
| 1114 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 1115 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 1115 locs->set_in(0, Location::RequiresRegister()); | 1116 locs->set_in(0, Location::RequiresRegister()); |
| 1116 // The smi index is either untagged (element size == 1), or it is left smi | 1117 if (CanBeImmediateIndex(index(), class_id())) { |
| 1117 // tagged (for all element sizes > 1). | 1118 // CanBeImmediateIndex must return false for unsafe smis. |
| 1118 if (index_scale() == 1) { | 1119 locs->set_in(1, Location::Constant(index()->BoundConstant())); |
| 1119 locs->set_in(1, CanBeImmediateIndex(index(), class_id()) | |
| 1120 ? Location::Constant( | |
| 1121 index()->definition()->AsConstant()->value()) | |
| 1122 : Location::WritableRegister()); | |
| 1123 } else { | 1120 } else { |
| 1124 locs->set_in(1, CanBeImmediateIndex(index(), class_id()) | 1121 // The index is either untagged (element size == 1) or a smi (for all |
| 1125 ? Location::Constant( | 1122 // element sizes > 1). |
| 1126 index()->definition()->AsConstant()->value()) | 1123 locs->set_in(1, (index_scale() == 1) |
| 1127 : Location::RequiresRegister()); | 1124 ? Location::WritableRegister() |
| 1125 : Location::RequiresRegister()); |
| 1128 } | 1126 } |
| 1129 if (representation() == kUnboxedDouble) { | 1127 if (representation() == kUnboxedDouble) { |
| 1130 locs->set_out(Location::RequiresFpuRegister()); | 1128 locs->set_out(Location::RequiresFpuRegister()); |
| 1131 } else { | 1129 } else { |
| 1132 locs->set_out(Location::RequiresRegister()); | 1130 locs->set_out(Location::RequiresRegister()); |
| 1133 } | 1131 } |
| 1134 return locs; | 1132 return locs; |
| 1135 } | 1133 } |
| 1136 | 1134 |
| 1137 | 1135 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1272 } | 1270 } |
| 1273 } | 1271 } |
| 1274 | 1272 |
| 1275 | 1273 |
| 1276 LocationSummary* StoreIndexedInstr::MakeLocationSummary() const { | 1274 LocationSummary* StoreIndexedInstr::MakeLocationSummary() const { |
| 1277 const intptr_t kNumInputs = 3; | 1275 const intptr_t kNumInputs = 3; |
| 1278 const intptr_t kNumTemps = 0; | 1276 const intptr_t kNumTemps = 0; |
| 1279 LocationSummary* locs = | 1277 LocationSummary* locs = |
| 1280 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 1278 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 1281 locs->set_in(0, Location::RequiresRegister()); | 1279 locs->set_in(0, Location::RequiresRegister()); |
| 1282 // The smi index is either untagged (element size == 1), or it is left smi | 1280 if (CanBeImmediateIndex(index(), class_id())) { |
| 1283 // tagged (for all element sizes > 1). | 1281 // CanBeImmediateIndex must return false for unsafe smis. |
| 1284 if (index_scale() == 1) { | 1282 locs->set_in(1, Location::Constant(index()->BoundConstant())); |
| 1285 locs->set_in(1, CanBeImmediateIndex(index(), class_id()) | |
| 1286 ? Location::Constant( | |
| 1287 index()->definition()->AsConstant()->value()) | |
| 1288 : Location::WritableRegister()); | |
| 1289 } else { | 1283 } else { |
| 1290 locs->set_in(1, CanBeImmediateIndex(index(), class_id()) | 1284 // The index is either untagged (element size == 1) or a smi (for all |
| 1291 ? Location::Constant( | 1285 // element sizes > 1). |
| 1292 index()->definition()->AsConstant()->value()) | 1286 locs->set_in(1, (index_scale() == 1) |
| 1293 : Location::RequiresRegister()); | 1287 ? Location::WritableRegister() |
| 1288 : Location::RequiresRegister()); |
| 1294 } | 1289 } |
| 1295 switch (class_id()) { | 1290 switch (class_id()) { |
| 1296 case kArrayCid: | 1291 case kArrayCid: |
| 1297 locs->set_in(2, ShouldEmitStoreBarrier() | 1292 locs->set_in(2, ShouldEmitStoreBarrier() |
| 1298 ? Location::WritableRegister() | 1293 ? Location::WritableRegister() |
| 1299 : Location::RegisterOrConstant(value())); | 1294 : Location::RegisterOrConstant(value())); |
| 1300 break; | 1295 break; |
| 1301 case kExternalTypedDataUint8ArrayCid: | 1296 case kExternalTypedDataUint8ArrayCid: |
| 1302 case kExternalTypedDataUint8ClampedArrayCid: | 1297 case kExternalTypedDataUint8ClampedArrayCid: |
| 1303 case kTypedDataInt8ArrayCid: | 1298 case kTypedDataInt8ArrayCid: |
| (...skipping 1123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2427 | 2422 |
| 2428 LocationSummary* BinarySmiOpInstr::MakeLocationSummary() const { | 2423 LocationSummary* BinarySmiOpInstr::MakeLocationSummary() const { |
| 2429 const intptr_t kNumInputs = 2; | 2424 const intptr_t kNumInputs = 2; |
| 2430 if (op_kind() == Token::kTRUNCDIV) { | 2425 if (op_kind() == Token::kTRUNCDIV) { |
| 2431 const intptr_t kNumTemps = 1; | 2426 const intptr_t kNumTemps = 1; |
| 2432 LocationSummary* summary = | 2427 LocationSummary* summary = |
| 2433 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 2428 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| 2434 if (RightIsPowerOfTwoConstant()) { | 2429 if (RightIsPowerOfTwoConstant()) { |
| 2435 summary->set_in(0, Location::RequiresRegister()); | 2430 summary->set_in(0, Location::RequiresRegister()); |
| 2436 ConstantInstr* right_constant = right()->definition()->AsConstant(); | 2431 ConstantInstr* right_constant = right()->definition()->AsConstant(); |
| 2432 // The programmer only controls one bit, so the constant is safe. |
| 2437 summary->set_in(1, Location::Constant(right_constant->value())); | 2433 summary->set_in(1, Location::Constant(right_constant->value())); |
| 2438 summary->set_temp(0, Location::RequiresRegister()); | 2434 summary->set_temp(0, Location::RequiresRegister()); |
| 2439 summary->set_out(Location::SameAsFirstInput()); | 2435 summary->set_out(Location::SameAsFirstInput()); |
| 2440 } else { | 2436 } else { |
| 2441 // Both inputs must be writable because they will be untagged. | 2437 // Both inputs must be writable because they will be untagged. |
| 2442 summary->set_in(0, Location::RegisterLocation(EAX)); | 2438 summary->set_in(0, Location::RegisterLocation(EAX)); |
| 2443 summary->set_in(1, Location::WritableRegister()); | 2439 summary->set_in(1, Location::WritableRegister()); |
| 2444 summary->set_out(Location::SameAsFirstInput()); | 2440 summary->set_out(Location::SameAsFirstInput()); |
| 2445 // Will be used for sign extension and division. | 2441 // Will be used for sign extension and division. |
| 2446 summary->set_temp(0, Location::RegisterLocation(EDX)); | 2442 summary->set_temp(0, Location::RegisterLocation(EDX)); |
| (...skipping 2730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5177 PcDescriptors::kOther, | 5173 PcDescriptors::kOther, |
| 5178 locs()); | 5174 locs()); |
| 5179 __ Drop(2); // Discard type arguments and receiver. | 5175 __ Drop(2); // Discard type arguments and receiver. |
| 5180 } | 5176 } |
| 5181 | 5177 |
| 5182 } // namespace dart | 5178 } // namespace dart |
| 5183 | 5179 |
| 5184 #undef __ | 5180 #undef __ |
| 5185 | 5181 |
| 5186 #endif // defined TARGET_ARCH_IA32 | 5182 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |