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

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

Issue 9595017: Refactor constant part. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More comment addressing. 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 | « frog/leg/ssa/nodes.dart ('k') | frog/leg/ssa/tracer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/ssa/optimize.dart
diff --git a/frog/leg/ssa/optimize.dart b/frog/leg/ssa/optimize.dart
index aff636e30b201ea4f5440b7037bfe6379fa16b41..8159db969465dfd28254c9448e69f812c3a2cee9 100644
--- a/frog/leg/ssa/optimize.dart
+++ b/frog/leg/ssa/optimize.dart
@@ -92,7 +92,9 @@ 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.addNewLiteralFalse();
+ if (input.type.isKnown()) {
+ return graph.addConstantBool(false);
+ }
return node;
}
@@ -100,9 +102,10 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
List<HInstruction> inputs = node.inputs;
assert(inputs.length == 1);
HInstruction input = inputs[0];
- if (input is HLiteral) {
- HLiteral literal = input;
- return graph.addNewLiteralBool(literal.value !== true);
+ if (input is HConstant) {
+ HConstant constant = input;
+ bool isTrue = constant.constant.isTrue();
+ return graph.addConstantBool(!isTrue);
}
return node;
}
@@ -113,39 +116,45 @@ 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
- // literal type the right-hand side is.
+ // type the right-hand side is.
if (node.left.isString()) {
// First try to eliminate adding the empty string to a string.
- if (node.right.isLiteralString()) {
- HLiteral right = node.right;
- DartString rightString = right.value;
+ if (node.right.isConstantString()) {
+ HConstant right = node.right;
+ Constant rightStringConstant = right.constant;
+ DartString rightString = rightStringConstant.value;
if (rightString.isEmpty()) {
// String has no content, i.e., it's the empty string.
return node.left;
}
}
- // Then, if both are literals, try to do the concatenation statically.
- if (node.left.isLiteralString()) {
- HLiteral left = node.left;
- DartString leftString = left.value;
+ // 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;
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 HLiteral) {
- HLiteral right = node.right;
- // Right is a literal, so we can statically convert it to String
+ if (node.right is HConstant) {
+ HConstant right = node.right;
+ // Right is a constant, so we can statically convert it to String
// and return that.
// Remaining literal types are represented by their Dart value.
- assert(right.isLiteralBoolean() ||
- right.isLiteralNumber() ||
- right.isLiteralNull());
- String str = right.value.toString();
- return graph.addNewLiteralString(new DartString.literal(str));
+ if (right.isConstantBoolean() ||
+ right.isConstantNumber() ||
+ right.isConstantNull()) {
+ PrimitiveConstant rightConstant = right.constant;
+ String str = rightConstant.value.toString();
+ return graph.addConstantString(new DartString.literal(str));
+ }
}
}
// TODO(lrn): Perform concatenation in Dart.
@@ -154,26 +163,6 @@ 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 | « frog/leg/ssa/nodes.dart ('k') | frog/leg/ssa/tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698