forked from aptos-labs/aptos-core
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[compiler-v2] Use livevar analysis to optimize file format generation (…
…aptos-labs#9361) * [compiler-v2] Use livevar analysis to optimize file format generation This connects the live-variable analysis which is already present in the Move prover to the v2 bytecode pipeline. This information is then used in the file-format generator to make better decisions when to move or copy values. Livevar is a standard compiler construction data flow analysis. It computes the set of variables which are alive (being used in subsequent reachable code) before and after each program point. The implementation from the prover uses our dataflow analysis framework and is [here](https://github.com/aptos-labs/aptos-core/blob/206f529c0c9d8488e27d2e50297178f0caf429a5/third_party/move/move-prover/bytecode/src/livevar_analysis.rs#L381). In this PR we create the first processing step in the bytecode pipeline with the new module `pipeline/livevar_analysis_step.rs` which forwards logical work to the existing analysis. * Addressing reviewer comments.
- Loading branch information
Showing
19 changed files
with
1,631 additions
and
185 deletions.
There are no files selected for viewing
184 changes: 132 additions & 52 deletions
184
third_party/move/move-compiler-v2/src/file_format_generator/function_generator.rs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
third_party/move/move-compiler-v2/src/pipeline/livevar_analysis_processor.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright © Aptos Foundation | ||
// Parts of the project are originally copyright © Meta Platforms, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! Implements a live-variable analysis processor, annotating lifetime information about locals. | ||
//! See also https://en.wikipedia.org/wiki/Live-variable_analysis | ||
use move_model::model::FunctionEnv; | ||
use move_stackless_bytecode::{ | ||
function_target::{FunctionData, FunctionTarget}, | ||
function_target_pipeline::{FunctionTargetProcessor, FunctionTargetsHolder}, | ||
livevar_analysis, | ||
}; | ||
|
||
pub struct LiveVarAnalysisProcessor(); | ||
|
||
impl FunctionTargetProcessor for LiveVarAnalysisProcessor { | ||
fn process( | ||
&self, | ||
_targets: &mut FunctionTargetsHolder, | ||
fun_env: &FunctionEnv, | ||
mut data: FunctionData, | ||
_scc_opt: Option<&[FunctionEnv]>, | ||
) -> FunctionData { | ||
// Call the existing live-var analysis from the move-prover. | ||
let target = FunctionTarget::new(fun_env, &data); | ||
let offset_to_live_refs = livevar_analysis::LiveVarAnnotation::from_map( | ||
livevar_analysis::run_livevar_analysis(&target, &data.code), | ||
); | ||
// Annotate the result on the function data. | ||
data.annotations.set(offset_to_live_refs, true); | ||
data | ||
} | ||
|
||
fn name(&self) -> String { | ||
"LiveVarAnalysisProcessor".to_owned() | ||
} | ||
} | ||
|
||
impl LiveVarAnalysisProcessor { | ||
/// Registers annotation formatter at the given function target. This is for debugging and | ||
/// testing. | ||
pub fn register_formatters(target: &FunctionTarget) { | ||
target.register_annotation_formatter(Box::new(livevar_analysis::format_livevar_annotation)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Copyright © Aptos Foundation | ||
// Parts of the project are originally copyright © Meta Platforms, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pub mod livevar_analysis_processor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.