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

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

Issue 9592009: Reapply "Refactor constant part." (r4958) with fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update tests and fix code after renaming. Created 8 years, 9 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 1aa1891731ed58e196e7071e3c61d8f38c8fb694..caaef1b42b6a82d63cec9f3403d4b3344d3c6022 100644
--- a/frog/leg/ssa/optimize.dart
+++ b/frog/leg/ssa/optimize.dart
@@ -90,7 +90,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;
}
@@ -98,9 +100,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;
}
@@ -111,39 +114,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.
@@ -153,23 +162,16 @@ class SsaConstantFolder extends HBaseVisitor implements OptimizationPhase {
}
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()) {
+ HInstruction left = node.left;
+ HInstruction right = node.right;
+ if (!left.isConstant() && right.isConstantNull()) {
HStatic target = new HStatic(
compiler.builder.interceptors.getEqualsNullInterceptor());
kasperl 2012/03/06 13:50:13 It seems pretty common that you want to get hold o
floitsch 2012/03/06 14:01:52 I will look into it. Added TODO.
- node.block.addBefore(node, target);
+ node.block.addBefore(node,target);
return new HEquals(target, node.left, node.right);
}
- return node;
+ // All other cases are dealt with by the [visitInvokeBinary].
+ return visitInvokeBinary(node);
}
HInstruction visitTypeGuard(HTypeGuard 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