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

Unified Diff: dart/frog/leg/ssa/optimize.dart

Issue 9578021: Revert "Refactor constant part." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « dart/frog/leg/ssa/nodes.dart ('k') | dart/frog/leg/ssa/tracer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dart/frog/leg/ssa/optimize.dart
diff --git a/dart/frog/leg/ssa/optimize.dart b/dart/frog/leg/ssa/optimize.dart
index 1abe1d47dc107899eab82f3e357845164253c5c2..7fdf1b0dcabaaea1b11b0a6aa0b9d002301519ec 100644
--- a/dart/frog/leg/ssa/optimize.dart
+++ b/dart/frog/leg/ssa/optimize.dart
@@ -90,9 +90,7 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
HInstruction input = inputs[0];
if (input.isBoolean()) return input;
// All values !== true are boolified to false.
- if (input.type.isKnown()) {
- return graph.addConstantBool(false);
- }
+ if (input.type.isKnown()) return graph.addNewLiteralFalse();
return node;
}
@@ -100,10 +98,9 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
List<HInstruction> inputs = node.inputs;
assert(inputs.length == 1);
HInstruction input = inputs[0];
- if (input is HConstant) {
- HConstant constant = input;
- bool isTrue = constant.constant.isTrue();
- return graph.addConstantBool(!isTrue);
+ if (input is HLiteral) {
+ HLiteral literal = input;
+ return graph.addNewLiteralBool(literal.value !== true);
}
return node;
}
@@ -114,45 +111,39 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
=> node.fold(graph);
HInstruction visitAdd(HAdd node) {
- // TODO(floitsch): move this code into the compile-time constant handler.
-
// String + is defined for all literals. We don't need to know which
- // type the right-hand side is.
+ // literal type the right-hand side is.
if (node.left.isString()) {
// First try to eliminate adding the empty string to a string.
- if (node.right.isConstantString()) {
- HConstant right = node.right;
- Constant rightStringConstant = right.constant;
- DartString rightString = rightStringConstant.value;
+ if (node.right.isLiteralString()) {
+ HLiteral right = node.right;
+ DartString rightString = right.value;
if (rightString.isEmpty()) {
// String has no content, i.e., it's the empty string.
return node.left;
}
}
- // Then, if both are constants, try to do the concatenation statically.
- if (node.left.isConstantString()) {
- HConstant left = node.left;
- Constant leftStringConstant = left.constant;
- DartString leftString = leftStringConstant.value;
+ // Then, if both are literals, try to do the concatenation statically.
+ if (node.left.isLiteralString()) {
+ HLiteral left = node.left;
+ DartString leftString = left.value;
if (leftString.isEmpty()) {
// Left is empty String.
if (node.right.isString()) {
// Right is already a String, just return that.
return node.right;
}
- if (node.right is HConstant) {
- HConstant right = node.right;
- // Right is a constant, so we can statically convert it to String
+ if (node.right is HLiteral) {
+ HLiteral right = node.right;
+ // Right is a literal, so we can statically convert it to String
// and return that.
// Remaining literal types are represented by their Dart value.
- if (right.isConstantBoolean() ||
- right.isConstantNumber() ||
- right.isConstantNull()) {
- PrimitiveConstant rightConstant = right.constant;
- String str = rightConstant.value.toString();
- return graph.addConstantString(new DartString.literal(str));
- }
+ assert(right.isLiteralBoolean() ||
+ right.isLiteralNumber() ||
+ right.isLiteralNull());
+ String str = right.value.toString();
+ return graph.addNewLiteralString(new DartString.literal(str));
}
}
// TODO(lrn): Perform concatenation in Dart.
@@ -161,6 +152,26 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
return visitInvokeBinary(node);
}
+ HInstruction visitEquals(HEquals node) {
+ if (node.left is HLiteral && node.right is HLiteral) {
+ HLiteral op1 = node.left;
+ HLiteral op2 = node.right;
+ if (op1.isLiteralString()) {
+ if (op2.isLiteralString() && op1.value.definitelyEquals(op2.value)) {
+ return graph.addNewLiteralTrue();
+ }
+ } else {
+ return graph.addNewLiteralBool(op1.value == op2.value);
+ }
+ } else if (node.right.isLiteralNull()) {
+ HStatic target = new HStatic(
+ compiler.builder.interceptors.getEqualsNullInterceptor());
+ node.block.addBefore(node, target);
+ return new HEquals(target, node.left, node.right);
+ }
+ return node;
+ }
+
HInstruction visitTypeGuard(HTypeGuard node) {
HInstruction value = node.guarded;
return (value.type.combine(node.type) == value.type) ? value : node;
« no previous file with comments | « dart/frog/leg/ssa/nodes.dart ('k') | dart/frog/leg/ssa/tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698