Declare constants in the function preamble

This allows us to give names to constants in the constant pool and then use these names in the function body. The original behavior, specifiying the constant value as an instruction immediate, is still supported as a shortcut but some filetests had to change since the canonical way of printing the CLIF constants is now in the preamble.
This commit is contained in:
Andrew Brown
2020-03-20 14:08:03 -07:00
parent 7d88384c0f
commit 0672d1dc0f
14 changed files with 255 additions and 74 deletions

View File

@@ -102,6 +102,11 @@ pub trait FuncWriter {
self.write_entity_definition(w, func, jt.into(), jt_data)?;
}
for (&cref, cval) in func.dfg.constants.iter() {
any = true;
self.write_entity_definition(w, func, cref.into(), cval)?;
}
Ok(any)
}
@@ -494,6 +499,9 @@ pub fn write_operands(
UnaryIeee64 { imm, .. } => write!(w, " {}", imm),
UnaryBool { imm, .. } => write!(w, " {}", imm),
UnaryGlobalValue { global_value, .. } => write!(w, " {}", global_value),
UnaryConst {
constant_handle, ..
} => write!(w, " {}", constant_handle),
Binary { args, .. } => write!(w, " {}, {}", args[0], args[1]),
BinaryImm { arg, imm, .. } => write!(w, " {}, {}", arg, imm),
Ternary { args, .. } => write!(w, " {}, {}, {}", args[0], args[1], args[2]),
@@ -507,12 +515,6 @@ pub fn write_operands(
NullAry { .. } => write!(w, " "),
InsertLane { lane, args, .. } => write!(w, " {}, {}, {}", args[0], lane, args[1]),
ExtractLane { lane, arg, .. } => write!(w, " {}, {}", arg, lane),
UnaryConst {
constant_handle, ..
} => {
let constant_data = dfg.constants.get(constant_handle);
write!(w, " {}", constant_data)
}
Shuffle { mask, args, .. } => {
let data = dfg.immediates.get(mask).expect(
"Expected the shuffle mask to already be inserted into the immediates table",