Skip to content

Commit 8b88a87

Browse files
committed
[move compiler] common subexpression elimination
1 parent d9b6d27 commit 8b88a87

File tree

91 files changed

+7668
-457
lines changed

Some content is hidden

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

91 files changed

+7668
-457
lines changed

execution/executor-benchmark/src/db_generator.rs

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

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: 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)