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

Unified Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 2585223002: Access ConstantSystem through ClosedWorld. (Closed)
Patch Set: Created 4 years 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
Index: pkg/compiler/lib/src/ssa/optimize.dart
diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart
index c8a2648756c2817930761ec2c3f8f9f9113bc48f..2c6cdb82e8bd4d90801d3a7cb707629166d96462 100644
--- a/pkg/compiler/lib/src/ssa/optimize.dart
+++ b/pkg/compiler/lib/src/ssa/optimize.dart
@@ -8,7 +8,7 @@ import '../common/tasks.dart' show CompilerTask;
import '../compiler.dart' show Compiler;
import '../constants/constant_system.dart';
import '../constants/values.dart';
-import '../core_types.dart' show CommonElements, CoreClasses;
+import '../core_types.dart' show CommonElements;
import '../dart_types.dart';
import '../elements/elements.dart';
import '../js/js.dart' as js;
@@ -53,7 +53,6 @@ class SsaOptimizerTask extends CompilerTask {
assert(graph.isValid());
}
- ConstantSystem constantSystem = compiler.backend.constantSystem;
bool trustPrimitives = compiler.options.trustPrimitives;
CodegenRegistry registry = work.registry;
Set<HInstruction> boundsChecked = new Set<HInstruction>();
@@ -62,27 +61,24 @@ class SsaOptimizerTask extends CompilerTask {
List<OptimizationPhase> phases = <OptimizationPhase>[
// Run trivial instruction simplification first to optimize
// some patterns useful for type conversion.
- new SsaInstructionSimplifier(
- constantSystem, backend, closedWorld, this, registry),
+ new SsaInstructionSimplifier(backend, closedWorld, this, registry),
new SsaTypeConversionInserter(closedWorld),
new SsaRedundantPhiEliminator(),
new SsaDeadPhiEliminator(),
new SsaTypePropagator(compiler, closedWorld),
// After type propagation, more instructions can be
// simplified.
- new SsaInstructionSimplifier(
- constantSystem, backend, closedWorld, this, registry),
+ new SsaInstructionSimplifier(backend, closedWorld, this, registry),
new SsaCheckInserter(
trustPrimitives, backend, closedWorld, boundsChecked),
- new SsaInstructionSimplifier(
- constantSystem, backend, closedWorld, this, registry),
+ new SsaInstructionSimplifier(backend, closedWorld, this, registry),
new SsaCheckInserter(
trustPrimitives, backend, closedWorld, boundsChecked),
new SsaTypePropagator(compiler, closedWorld),
// Run a dead code eliminator before LICM because dead
// interceptors are often in the way of LICM'able instructions.
- new SsaDeadCodeEliminator(compiler, closedWorld, this),
- new SsaGlobalValueNumberer(compiler),
+ new SsaDeadCodeEliminator(closedWorld, this),
+ new SsaGlobalValueNumberer(),
// After GVN, some instructions might need their type to be
// updated because they now have different inputs.
new SsaTypePropagator(compiler, closedWorld),
@@ -91,11 +87,10 @@ class SsaOptimizerTask extends CompilerTask {
new SsaRedundantPhiEliminator(),
new SsaDeadPhiEliminator(),
new SsaTypePropagator(compiler, closedWorld),
- new SsaValueRangeAnalyzer(compiler, closedWorld, constantSystem, this),
+ new SsaValueRangeAnalyzer(backend.helpers, closedWorld, this),
// Previous optimizations may have generated new
// opportunities for instruction simplification.
- new SsaInstructionSimplifier(
- constantSystem, backend, closedWorld, this, registry),
+ new SsaInstructionSimplifier(backend, closedWorld, this, registry),
new SsaCheckInserter(
trustPrimitives, backend, closedWorld, boundsChecked),
];
@@ -104,34 +99,29 @@ class SsaOptimizerTask extends CompilerTask {
// Simplifying interceptors is not strictly just an optimization, it is
// required for implementation correctness because the code generator
// assumes it is always performed.
- runPhase(new SsaSimplifyInterceptors(
- compiler, closedWorld, constantSystem, work.element));
+ runPhase(
+ new SsaSimplifyInterceptors(compiler, closedWorld, work.element));
- SsaDeadCodeEliminator dce =
- new SsaDeadCodeEliminator(compiler, closedWorld, this);
+ SsaDeadCodeEliminator dce = new SsaDeadCodeEliminator(closedWorld, this);
runPhase(dce);
if (codeMotion.movedCode || dce.eliminatedSideEffects) {
phases = <OptimizationPhase>[
new SsaTypePropagator(compiler, closedWorld),
- new SsaGlobalValueNumberer(compiler),
+ new SsaGlobalValueNumberer(),
new SsaCodeMotion(),
- new SsaValueRangeAnalyzer(
- compiler, closedWorld, constantSystem, this),
- new SsaInstructionSimplifier(
- constantSystem, backend, closedWorld, this, registry),
+ new SsaValueRangeAnalyzer(backend.helpers, closedWorld, this),
+ new SsaInstructionSimplifier(backend, closedWorld, this, registry),
new SsaCheckInserter(
trustPrimitives, backend, closedWorld, boundsChecked),
- new SsaSimplifyInterceptors(
- compiler, closedWorld, constantSystem, work.element),
- new SsaDeadCodeEliminator(compiler, closedWorld, this),
+ new SsaSimplifyInterceptors(compiler, closedWorld, work.element),
+ new SsaDeadCodeEliminator(closedWorld, this),
];
} else {
phases = <OptimizationPhase>[
new SsaTypePropagator(compiler, closedWorld),
// Run the simplifier to remove unneeded type checks inserted by
// type propagation.
- new SsaInstructionSimplifier(
- constantSystem, backend, closedWorld, this, registry),
+ new SsaInstructionSimplifier(backend, closedWorld, this, registry),
];
}
phases.forEach(runPhase);
@@ -172,19 +162,20 @@ class SsaInstructionSimplifier extends HBaseVisitor
final String name = "SsaInstructionSimplifier";
final JavaScriptBackend backend;
final ClosedWorld closedWorld;
- final ConstantSystem constantSystem;
final CodegenRegistry registry;
HGraph graph;
Compiler get compiler => backend.compiler;
final SsaOptimizerTask optimizer;
- SsaInstructionSimplifier(this.constantSystem, this.backend, this.closedWorld,
- this.optimizer, this.registry);
+ SsaInstructionSimplifier(
+ this.backend, this.closedWorld, this.optimizer, this.registry);
CommonElements get commonElements => closedWorld.commonElements;
BackendHelpers get helpers => backend.helpers;
+ ConstantSystem get constantSystem => closedWorld.constantSystem;
+
GlobalTypeInferenceResults get globalInferenceResults =>
compiler.globalInference.results;
@@ -258,7 +249,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (node.usedBy.isEmpty) return;
ConstantValue value = getConstantFromType(node);
if (value != null) {
- HConstant constant = graph.addConstant(value, compiler);
+ HConstant constant = graph.addConstant(value, closedWorld);
for (HInstruction user in node.usedBy.toList()) {
user.changeUse(node, constant);
}
@@ -305,7 +296,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
// All values that cannot be 'true' are boolified to false.
TypeMask mask = input.instructionType;
if (!mask.contains(helpers.jsBoolClass, closedWorld)) {
- return graph.addConstantBool(false, compiler);
+ return graph.addConstantBool(false, closedWorld);
}
return node;
}
@@ -317,7 +308,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (input is HConstant) {
HConstant constant = input;
bool isTrue = constant.constant.isTrue;
- return graph.addConstantBool(!isTrue, compiler);
+ return graph.addConstantBool(!isTrue, closedWorld);
} else if (input is HNot) {
return input.inputs[0];
}
@@ -334,7 +325,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (operand is HConstant) {
HConstant receiver = operand;
ConstantValue folded = operation.fold(receiver.constant);
- if (folded != null) return graph.addConstant(folded, compiler);
+ if (folded != null) return graph.addConstant(folded, closedWorld);
}
return null;
}
@@ -345,11 +336,11 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (actualReceiver.isConstantString()) {
HConstant constantInput = actualReceiver;
StringConstantValue constant = constantInput.constant;
- return graph.addConstantInt(constant.length, compiler);
+ return graph.addConstantInt(constant.length, closedWorld);
} else if (actualReceiver.isConstantList()) {
HConstant constantInput = actualReceiver;
ListConstantValue constant = constantInput.constant;
- return graph.addConstantInt(constant.length, compiler);
+ return graph.addConstantInt(constant.length, closedWorld);
}
MemberElement element = helpers.jsIndexableLength;
bool isFixed = isFixedLength(actualReceiver.instructionType, closedWorld);
@@ -369,7 +360,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
} else if (actualReceiver.isConstantMap()) {
HConstant constantInput = actualReceiver;
MapConstantValue constant = constantInput.constant;
- return graph.addConstantInt(constant.length, compiler);
+ return graph.addConstantInt(constant.length, closedWorld);
}
return null;
}
@@ -594,7 +585,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
HConstant op1 = left;
HConstant op2 = right;
ConstantValue folded = operation.fold(op1.constant, op2.constant);
- if (folded != null) return graph.addConstant(folded, compiler);
+ if (folded != null) return graph.addConstant(folded, closedWorld);
}
return null;
}
@@ -655,8 +646,8 @@ class SsaInstructionSimplifier extends HBaseVisitor
TypeMask leftType = left.instructionType;
TypeMask rightType = right.instructionType;
- HInstruction makeTrue() => graph.addConstantBool(true, compiler);
- HInstruction makeFalse() => graph.addConstantBool(false, compiler);
+ HInstruction makeTrue() => graph.addConstantBool(true, closedWorld);
+ HInstruction makeFalse() => graph.addConstantBool(false, closedWorld);
// Intersection of int and double return conflicting, so
// we don't optimize on numbers to preserve the runtime semantics.
@@ -707,7 +698,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
void simplifyCondition(
HBasicBlock block, HInstruction condition, bool value) {
condition.dominatedUsers(block.first).forEach((user) {
- HInstruction newCondition = graph.addConstantBool(value, compiler);
+ HInstruction newCondition = graph.addConstantBool(value, closedWorld);
user.changeUse(condition, newCondition);
});
}
@@ -750,7 +741,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
}
if (type.isObject || type.treatAsDynamic) {
- return graph.addConstantBool(true, compiler);
+ return graph.addConstantBool(true, closedWorld);
}
HInstruction expression = node.expression;
@@ -758,30 +749,30 @@ class SsaInstructionSimplifier extends HBaseVisitor
if (element == commonElements.intClass ||
element == commonElements.numClass ||
Elements.isNumberOrStringSupertype(element, commonElements)) {
- return graph.addConstantBool(true, compiler);
+ return graph.addConstantBool(true, closedWorld);
} else if (element == commonElements.doubleClass) {
// We let the JS semantics decide for that check. Currently
// the code we emit will always return true.
return node;
} else {
- return graph.addConstantBool(false, compiler);
+ return graph.addConstantBool(false, closedWorld);
}
} else if (expression.isDouble(closedWorld)) {
if (element == commonElements.doubleClass ||
element == commonElements.numClass ||
Elements.isNumberOrStringSupertype(element, commonElements)) {
- return graph.addConstantBool(true, compiler);
+ return graph.addConstantBool(true, closedWorld);
} else if (element == commonElements.intClass) {
// We let the JS semantics decide for that check. Currently
// the code we emit will return true for a double that can be
// represented as a 31-bit integer and for -0.0.
return node;
} else {
- return graph.addConstantBool(false, compiler);
+ return graph.addConstantBool(false, closedWorld);
}
} else if (expression.isNumber(closedWorld)) {
if (element == commonElements.numClass) {
- return graph.addConstantBool(true, compiler);
+ return graph.addConstantBool(true, closedWorld);
} else {
// We cannot just return false, because the expression may be of
// type int or double.
@@ -801,9 +792,9 @@ class SsaInstructionSimplifier extends HBaseVisitor
? new TypeMask.subtype(element, closedWorld)
: new TypeMask.nonNullSubtype(element, closedWorld);
if (expressionMask.union(typeMask, closedWorld) == typeMask) {
- return graph.addConstantBool(true, compiler);
+ return graph.addConstantBool(true, closedWorld);
} else if (expressionMask.isDisjoint(typeMask, closedWorld)) {
- return graph.addConstantBool(false, compiler);
+ return graph.addConstantBool(false, closedWorld);
}
}
return node;
@@ -874,11 +865,12 @@ class SsaInstructionSimplifier extends HBaseVisitor
return receiver.inputs[0];
}
} else if (receiver.isConstantList() || receiver.isConstantString()) {
- return graph.addConstantInt(receiver.constant.length, compiler);
+ return graph.addConstantInt(receiver.constant.length, closedWorld);
} else {
var type = receiver.instructionType;
if (type.isContainer && type.length != null) {
- HInstruction constant = graph.addConstantInt(type.length, compiler);
+ HInstruction constant =
+ graph.addConstantInt(type.length, closedWorld);
if (type.isNullable) {
// If the container can be null, we update all uses of the
// length access to use the constant instead, but keep the
@@ -902,7 +894,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
Map<Element, ConstantValue> fields = constructedConstant.fields;
ConstantValue value = fields[node.element];
if (value != null) {
- return graph.addConstant(value, compiler);
+ return graph.addConstant(value, closedWorld);
}
}
}
@@ -917,7 +909,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
instruction = node.index;
int index = instruction.constant.primitiveValue;
if (index >= 0 && index < entries.length) {
- return graph.addConstant(entries[index], compiler);
+ return graph.addConstant(entries[index], closedWorld);
}
}
return node;
@@ -1072,7 +1064,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
HInstruction folded = graph.addConstant(
constantSystem.createString(new ast.DartString.concat(
leftString.primitiveValue, rightString.primitiveValue)),
- compiler);
+ closedWorld);
if (prefix == null) return folded;
return new HStringConcat(
prefix, folded, closedWorld.commonMasks.stringType);
@@ -1096,7 +1088,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
}
PrimitiveConstantValue primitive = constant.constant;
return graph.addConstant(
- constantSystem.createString(primitive.toDartString()), compiler);
+ constantSystem.createString(primitive.toDartString()), closedWorld);
}
HInstruction tryToString() {
@@ -1289,7 +1281,7 @@ class SsaInstructionSimplifier extends HBaseVisitor
return finishSubstituted(
object.element,
// If there are type arguments, all type arguments are 'dynamic'.
- (int i) => graph.addConstantNull(compiler));
+ (int i) => graph.addConstantNull(closedWorld));
}
}
@@ -1336,7 +1328,6 @@ class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
HBoundsCheck insertBoundsCheck(
HInstruction indexNode, HInstruction array, HInstruction indexArgument) {
- Compiler compiler = backend.compiler;
HFieldGet length = new HFieldGet(helpers.jsIndexableLength, array,
closedWorld.commonMasks.positiveIntType,
isAssignable: !isFixedLength(array.instructionType, closedWorld));
@@ -1381,8 +1372,8 @@ class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
// `0` is the index we want to check, but we want to report `-1`, as if we
// executed `a[a.length-1]`
HBoundsCheck check = insertBoundsCheck(
- node, node.receiver, graph.addConstantInt(0, backend.compiler));
- HInstruction minusOne = graph.addConstantInt(-1, backend.compiler);
+ node, node.receiver, graph.addConstantInt(0, closedWorld));
+ HInstruction minusOne = graph.addConstantInt(-1, closedWorld);
check.inputs.add(minusOne);
minusOne.usedBy.add(check);
}
@@ -1391,7 +1382,6 @@ class SsaCheckInserter extends HBaseVisitor implements OptimizationPhase {
class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
final String name = "SsaDeadCodeEliminator";
- final Compiler compiler;
final ClosedWorld closedWorld;
final SsaOptimizerTask optimizer;
SsaLiveBlockAnalyzer analyzer;
@@ -1399,7 +1389,7 @@ class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
new Maplet<HInstruction, bool>();
bool eliminatedSideEffects = false;
- SsaDeadCodeEliminator(this.compiler, this.closedWorld, this.optimizer);
+ SsaDeadCodeEliminator(this.closedWorld, this.optimizer);
HInstruction zapInstructionCache;
HInstruction get zapInstruction {
@@ -1407,7 +1397,7 @@ class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
// A constant with no type does not pollute types at phi nodes.
ConstantValue constant = new SyntheticConstantValue(
SyntheticConstantKind.EMPTY_VALUE, const TypeMask.nonNullEmpty());
- zapInstructionCache = analyzer.graph.addConstant(constant, compiler);
+ zapInstructionCache = analyzer.graph.addConstant(constant, closedWorld);
}
return zapInstructionCache;
}
@@ -1802,13 +1792,12 @@ class GvnWorkItem {
class SsaGlobalValueNumberer implements OptimizationPhase {
final String name = "SsaGlobalValueNumberer";
- final Compiler compiler;
final Set<int> visited;
List<int> blockChangesFlags;
List<int> loopChangesFlags;
- SsaGlobalValueNumberer(this.compiler) : visited = new Set<int>();
+ SsaGlobalValueNumberer() : visited = new Set<int>();
void visitGraph(HGraph graph) {
computeChangesFlags(graph);

Powered by Google App Engine
This is Rietveld 408576698