Add global value numbering pass.

This commit is contained in:
Camille GILLOT
2023-03-20 18:05:07 +00:00
parent 551c7183f8
commit 8b848af325
33 changed files with 6476 additions and 26 deletions

View File

@@ -13,7 +13,6 @@ use rustc_middle::middle::resolve_bound_vars::Set1;
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
#[derive(Debug)]
pub struct SsaLocals {
/// Assignments to each local. This defines whether the local is SSA.
assignments: IndexVec<Local, Set1<LocationExtended>>,
@@ -129,6 +128,25 @@ impl SsaLocals {
self.direct_uses[local]
}
pub fn assignment_dominates(
&self,
dominators: &Dominators<BasicBlock>,
local: Local,
location: Location,
) -> bool {
match self.assignments[local] {
Set1::One(LocationExtended::Arg) => true,
Set1::One(LocationExtended::Plain(ass)) => {
if ass.block == location.block {
ass.statement_index < location.statement_index
} else {
dominators.dominates(ass.block, location.block)
}
}
_ => false,
}
}
pub fn assignments<'a, 'tcx>(
&'a self,
body: &'a Body<'tcx>,