Make value aliases during references rewriting
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
8e38c7907d
commit
d93c37a826
@@ -234,6 +234,19 @@ impl DataFlowGraph {
|
||||
panic!("Cannot change direct value {} into an alias", dest);
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a new value alias.
|
||||
///
|
||||
/// Note that this function should only be called by the parser.
|
||||
pub fn make_value_alias(&mut self, src: Value) -> Value {
|
||||
let ty = self.value_type(src);
|
||||
|
||||
let data = ValueData::Alias {
|
||||
ty: ty,
|
||||
original: src,
|
||||
};
|
||||
self.make_value(data)
|
||||
}
|
||||
}
|
||||
|
||||
/// Where did a value come from?
|
||||
|
||||
@@ -188,6 +188,24 @@ impl<'a> Context<'a> {
|
||||
// numbering. These references need to be rewritten after parsing is complete since forward
|
||||
// references are allowed.
|
||||
fn rewrite_references(&mut self) -> Result<()> {
|
||||
for (&source_from, &(source_to, source_loc)) in &self.aliases {
|
||||
let ir_to = match self.map.get_value(source_to) {
|
||||
Some(v) => v,
|
||||
None => {
|
||||
return err!(source_loc,
|
||||
"IR destination value alias not found for {}",
|
||||
source_to);
|
||||
}
|
||||
};
|
||||
let dest_loc = self.map
|
||||
.location(AnyEntity::from(ir_to))
|
||||
.expect(&*format!("Error in looking up location of IR destination value alias \
|
||||
for {}",
|
||||
ir_to));
|
||||
let ir_from = self.function.dfg.make_value_alias(ir_to);
|
||||
self.map.def_value(source_from, ir_from, &dest_loc)?;
|
||||
}
|
||||
|
||||
for ebb in self.function.layout.ebbs() {
|
||||
for inst in self.function.layout.ebb_insts(ebb) {
|
||||
let loc = inst.into();
|
||||
|
||||
Reference in New Issue
Block a user