Skip to content

Commit b6f8d5d

Browse files
committed
[move compiler] common subexpression elimination
1 parent 72949fe commit b6f8d5d

Some content is hidden

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

41 files changed

+5340
-502
lines changed

Cargo.lock

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

execution/executor-benchmark/src/db_generator.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub fn create_db_with_accounts<V>(
4848
if db_dir.as_ref().exists() {
4949
panic!("data-dir exists already.");
5050
}
51+
52+
println!("Creating directory at: {:?}", db_dir.as_ref());
53+
println!("Canonical path: {:?}", std::fs::canonicalize(&db_dir).ok());
5154
// create if not exists
5255
fs::create_dir_all(db_dir.as_ref()).unwrap();
5356

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(),
@@ -317,6 +322,7 @@ impl Experiment {
317322
pub const CFG_SIMPLIFICATION: &'static str = "cfg-simplification";
318323
pub const CHECKS: &'static str = "checks";
319324
pub const CMP_REWRITE: &'static str = "cmp-rewrite";
325+
pub const COMMON_SUBEXP_ELIMINATION: &'static str = "common-subexp-elimination";
320326
pub const COMPILE_FOR_TESTING: &'static str = "compile-for-testing";
321327
pub const DEAD_CODE_ELIMINATION: &'static str = "dead-code-elimination";
322328
pub const DUPLICATE_STRUCT_PARAMS_CHECK: &'static str = "duplicate-struct-params-check";

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

Lines changed: 21 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,
@@ -557,6 +559,25 @@ pub fn stackless_bytecode_optimization_pipeline(options: &Options) -> FunctionTa
557559
pipeline.add_processor(Box::new(SplitCriticalEdgesProcessor {}));
558560
}
559561

562+
// Common subexpression elimination
563+
// Need to run before `ABILITY_CHECK`
564+
// Further, all annotations are clearned after this pass
565+
if options.experiment_on(Experiment::COMMON_SUBEXP_ELIMINATION) {
566+
// analysis dependecy: live_var -> reference_safety -> reaching_def -> common_subexp_elimination
567+
pipeline.add_processor(Box::new(LiveVarAnalysisProcessor::new(true)));
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+
560581
// Reference safety checkers need live variable annotation.
561582
pipeline.add_processor(Box::new(LiveVarAnalysisProcessor::new(false)));
562583
if options.experiment_on(Experiment::REFERENCE_SAFETY_V3) {

0 commit comments

Comments
 (0)