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

Side by Side Diff: runtime/vm/intermediate_language.cc

Issue 266633007: Merge ConstantInstr -> UnboxDouble to UnboxedConstant. Reduces register usage and allows for variou… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 7 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
OLDNEW
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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bigint_operations.h" 7 #include "vm/bigint_operations.h"
8 #include "vm/bit_vector.h" 8 #include "vm/bit_vector.h"
9 #include "vm/cpu.h" 9 #include "vm/cpu.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 318 }
319 319
320 320
321 bool ConstantInstr::AttributesEqual(Instruction* other) const { 321 bool ConstantInstr::AttributesEqual(Instruction* other) const {
322 ConstantInstr* other_constant = other->AsConstant(); 322 ConstantInstr* other_constant = other->AsConstant();
323 ASSERT(other_constant != NULL); 323 ASSERT(other_constant != NULL);
324 return (value().raw() == other_constant->value().raw()); 324 return (value().raw() == other_constant->value().raw());
325 } 325 }
326 326
327 327
328 UnboxedConstantInstr::UnboxedConstantInstr(const Object& value)
329 : ConstantInstr(value), constant_address_(NULL) {
330 // Only doubles supported for now.
331 ASSERT(value.IsDouble());
332 constant_address_ =
333 FlowGraphBuilder::FindDoubleConstant(Double::Cast(value).value());
334 }
335
328 // Returns true if the value represents a constant. 336 // Returns true if the value represents a constant.
329 bool Value::BindsToConstant() const { 337 bool Value::BindsToConstant() const {
330 return definition()->IsConstant(); 338 return definition()->IsConstant();
331 } 339 }
332 340
333 341
334 // Returns true if the value represents constant null. 342 // Returns true if the value represents constant null.
335 bool Value::BindsToConstantNull() const { 343 bool Value::BindsToConstantNull() const {
336 ConstantInstr* constant = definition()->AsConstant(); 344 ConstantInstr* constant = definition()->AsConstant();
337 return (constant != NULL) && constant->value().IsNull(); 345 return (constant != NULL) && constant->value().IsNull();
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 return Utils::IsPowerOfTwo(Utils::Abs(int_value)); 1225 return Utils::IsPowerOfTwo(Utils::Abs(int_value));
1218 } 1226 }
1219 1227
1220 1228
1221 static bool ToIntegerConstant(Value* value, intptr_t* result) { 1229 static bool ToIntegerConstant(Value* value, intptr_t* result) {
1222 if (!value->BindsToConstant()) { 1230 if (!value->BindsToConstant()) {
1223 if (value->definition()->IsUnboxDouble()) { 1231 if (value->definition()->IsUnboxDouble()) {
1224 return ToIntegerConstant(value->definition()->AsUnboxDouble()->value(), 1232 return ToIntegerConstant(value->definition()->AsUnboxDouble()->value(),
1225 result); 1233 result);
1226 } 1234 }
1227
1228 return false; 1235 return false;
1229 } 1236 }
1230 1237
1231 const Object& constant = value->BoundConstant(); 1238 const Object& constant = value->BoundConstant();
1232 if (constant.IsDouble()) { 1239 if (constant.IsDouble()) {
1233 const Double& double_constant = Double::Cast(constant); 1240 const Double& double_constant = Double::Cast(constant);
1234 *result = static_cast<intptr_t>(double_constant.value()); 1241 *result = static_cast<intptr_t>(double_constant.value());
1235 return (static_cast<double>(*result) == double_constant.value()); 1242 return (static_cast<double>(*result) == double_constant.value());
1236 } else if (constant.IsSmi()) { 1243 } else if (constant.IsSmi()) {
1237 *result = Smi::Cast(constant).Value(); 1244 *result = Smi::Cast(constant).Value();
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
1593 // Fold away BoxDouble(UnboxDouble(v)) if value is known to be double. 1600 // Fold away BoxDouble(UnboxDouble(v)) if value is known to be double.
1594 UnboxDoubleInstr* defn = value()->definition()->AsUnboxDouble(); 1601 UnboxDoubleInstr* defn = value()->definition()->AsUnboxDouble();
1595 if ((defn != NULL) && (defn->value()->Type()->ToCid() == kDoubleCid)) { 1602 if ((defn != NULL) && (defn->value()->Type()->ToCid() == kDoubleCid)) {
1596 return defn->value()->definition(); 1603 return defn->value()->definition();
1597 } 1604 }
1598 1605
1599 return this; 1606 return this;
1600 } 1607 }
1601 1608
1602 1609
1603 Definition* UnboxDoubleInstr::Canonicalize(FlowGraph* flow_graph) { 1610 Definition* UnboxDoubleInstr::Canonicalize(FlowGraph* flow_graph) {
Florian Schneider 2014/05/01 18:34:16 Maybe add if (!HasUses()) return NULL; so that U
srdjan 2014/05/01 20:33:04 Done.
1604 // Fold away UnboxDouble(BoxDouble(v)). 1611 // Fold away UnboxDouble(BoxDouble(v)).
1605 BoxDoubleInstr* defn = value()->definition()->AsBoxDouble(); 1612 BoxDoubleInstr* box_defn = value()->definition()->AsBoxDouble();
1606 return (defn != NULL) ? defn->value()->definition() : this; 1613 if (box_defn != NULL) {
1614 return box_defn->value()->definition();
1615 }
1616
1617 ConstantInstr* c = value()->definition()->AsConstant();
1618 if ((c != NULL) && c->value().IsDouble()) {
1619 UnboxedConstantInstr* uc = new UnboxedConstantInstr(c->value());
1620 flow_graph->InsertBefore(this, uc, this->env(), Definition::kValue);
Florian Schneider 2014/05/01 18:34:16 UnboxedConstant should not need an environment, si
srdjan 2014/05/01 20:33:04 Done.
1621 return uc;
Florian Schneider 2014/05/01 18:34:16 Make sure that the UnboxDoubleInstr get removed by
srdjan 2014/05/01 20:33:04 I checked it visually in disassembled output/flow
1622 }
1623
1624 return this;
1607 } 1625 }
1608 1626
1609 1627
1610 Definition* BoxFloat32x4Instr::Canonicalize(FlowGraph* flow_graph) { 1628 Definition* BoxFloat32x4Instr::Canonicalize(FlowGraph* flow_graph) {
1611 if (input_use_list() == NULL) { 1629 if (input_use_list() == NULL) {
1612 // Environments can accomodate any representation. No need to box. 1630 // Environments can accomodate any representation. No need to box.
1613 return value()->definition(); 1631 return value()->definition();
1614 } 1632 }
1615 1633
1616 // Fold away BoxFloat32x4(UnboxFloat32x4(v)). 1634 // Fold away BoxFloat32x4(UnboxFloat32x4(v)).
(...skipping 1721 matching lines...) Expand 10 before | Expand all | Expand 10 after
3338 case Token::kTRUNCDIV: return 0; 3356 case Token::kTRUNCDIV: return 0;
3339 case Token::kMOD: return 1; 3357 case Token::kMOD: return 1;
3340 default: UNIMPLEMENTED(); return -1; 3358 default: UNIMPLEMENTED(); return -1;
3341 } 3359 }
3342 } 3360 }
3343 3361
3344 3362
3345 #undef __ 3363 #undef __
3346 3364
3347 } // namespace dart 3365 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698