blob: fc7aca15e8b84d428c45ae20e38ad6c01c16b230 [file] [log] [blame]
library tree_ir.optimization;
import '../tree_ir_nodes.dart';
import '../../elements/elements.dart';
import '../../constants/values.dart' as values;
part 'copy_propagator.dart';
part 'logical_rewriter.dart';
part 'loop_rewriter.dart';
part 'statement_rewriter.dart';
/// An optimization pass over the Tree IR.
abstract class Pass {
/// Applies optimizations to root, rewriting it in the process.
void rewrite(ExecutableDefinition root) => root.applyPass(this);
void rewriteFieldDefinition(FieldDefinition root);
void rewriteFunctionDefinition(FunctionDefinition root);
void rewriteConstructorDefinition(ConstructorDefinition root);
String get passName;
}
abstract class PassMixin implements Pass {
void rewrite(ExecutableDefinition root) => root.applyPass(this);
void rewriteExecutableDefinition(ExecutableDefinition root);
void rewriteFieldDefinition(FieldDefinition root) {
if (!root.hasInitializer) return;
rewriteExecutableDefinition(root);
}
void rewriteFunctionDefinition(FunctionDefinition root) {
if (root.isAbstract) return;
rewriteExecutableDefinition(root);
}
void rewriteConstructorDefinition(ConstructorDefinition root) {
if (root.isAbstract) return;
rewriteExecutableDefinition(root);
}
}