Skip to content

Commit 23a4d69

Browse files
committed
[move compiler] common subexpression elimination
1 parent 88ac450 commit 23a4d69

File tree

79 files changed

+7424
-450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+7424
-450
lines changed

third_party/move/move-compiler-v2/src/experiments.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ pub static EXPERIMENTS: Lazy<BTreeMap<String, Experiment>> = Lazy::new(|| {
162162
description: "Turns on optimizations waiting for comparison testing".to_string(),
163163
default: Given(false),
164164
},
165+
Experiment {
166+
name: Experiment::COMMON_SUBEXP_ELIMINATION.to_string(),
167+
description: "Whether to run common subexpression elimination".to_string(),
168+
default: Inherited(Experiment::OPTIMIZE_WAITING_FOR_COMPARE_TESTS.to_string()),
169+
},
165170
Experiment {
166171
name: Experiment::CFG_SIMPLIFICATION.to_string(),
167172
description: "Whether to do the control flow graph simplification".to_string(),
@@ -322,6 +327,7 @@ impl Experiment {
322327
pub const CFG_SIMPLIFICATION: &'static str = "cfg-simplification";
323328
pub const CHECKS: &'static str = "checks";
324329
pub const CMP_REWRITE: &'static str = "cmp-rewrite";
330+
pub const COMMON_SUBEXP_ELIMINATION: &'static str = "common-subexp-elimination";
325331
pub const COMPILE_FOR_TESTING: &'static str = "compile-for-testing";
326332
pub const DEAD_CODE_ELIMINATION: &'static str = "dead-code-elimination";
327333
pub const DUPLICATE_STRUCT_PARAMS_CHECK: &'static str = "duplicate-struct-params-check";

third_party/move/move-compiler-v2/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ use crate::{
2525
},
2626
pipeline::{
2727
ability_processor::AbilityProcessor,
28+
common_subexp_elimination::CommonSubexpElimination,
2829
control_flow_graph_simplifier::ControlFlowGraphSimplifier,
2930
dead_store_elimination::DeadStoreElimination,
3031
exit_state_analysis::ExitStateAnalysisProcessor,
3132
flush_writes_processor::FlushWritesProcessor,
3233
lint_processor::LintProcessor,
3334
livevar_analysis_processor::LiveVarAnalysisProcessor,
35+
reaching_def_analysis_processor::ReachingDefProcessor,
3436
reference_safety::{reference_safety_processor_v2, reference_safety_processor_v3},
3537
split_critical_edges_processor::SplitCriticalEdgesProcessor,
3638
uninitialized_use_checker::UninitializedUseChecker,
@@ -556,6 +558,26 @@ pub fn stackless_bytecode_optimization_pipeline(options: &Options) -> FunctionTa
556558
pipeline.add_processor(Box::new(SplitCriticalEdgesProcessor {}));
557559
}
558560

561+
// Common subexpression elimination
562+
// Need to run before `ABILITY_CHECK`
563+
// Further, all annotations are clearned after this pass
564+
if options.experiment_on(Experiment::COMMON_SUBEXP_ELIMINATION) {
565+
// analysis dependecy: live_var -> reference_safety -> reaching_def -> common_subexp_elimination
566+
pipeline.add_processor(Box::new(LiveVarAnalysisProcessor::new(true)));
567+
pipeline.add_processor(Box::new(FlushWritesProcessor {}));
568+
if options.experiment_on(Experiment::REFERENCE_SAFETY_V3) {
569+
pipeline.add_processor(Box::new(
570+
reference_safety_processor_v3::ReferenceSafetyProcessor {},
571+
));
572+
} else {
573+
pipeline.add_processor(Box::new(
574+
reference_safety_processor_v2::ReferenceSafetyProcessor {},
575+
));
576+
}
577+
pipeline.add_processor(Box::new(ReachingDefProcessor {}));
578+
pipeline.add_processor(Box::new(CommonSubexpElimination::new(true)));
579+
}
580+
559581
// Reference safety checkers need live variable annotation.
560582
pipeline.add_processor(Box::new(LiveVarAnalysisProcessor::new(false)));
561583
if options.experiment_on(Experiment::REFERENCE_SAFETY_V3) {

0 commit comments

Comments
 (0)