Allow creating constants in legalization AST
This adds a `DummyConstant` structure that is converted to something like `let const0 = pos.func.dfg.constants.insert(...)` in `gen_legalizer.rs`. This allows us to create constants during legalization with something like `let ones = constant(vec![0xff; 16])` and then use `ones` within a `def!` block, e.g.: `def!(a = vconst(ones))`. One unfortunate side-effect of this change is that, because the names of the constants in `ConstPool` are dynamic, the `VarPool` and `SymbolTable` structures that previously operated on `&'static str` types now must operate on `String` types; however, since this is a change to the meta code-generation, it should result in no runtime performance impact.
This commit is contained in:
@@ -43,7 +43,7 @@ fn unwrap_inst(
|
||||
.args
|
||||
.iter()
|
||||
.map(|arg| match arg.maybe_var() {
|
||||
Some(var_index) => var_pool.get(var_index).name,
|
||||
Some(var_index) => var_pool.get(var_index).name.as_ref(),
|
||||
None => "_",
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
@@ -114,7 +114,7 @@ fn unwrap_inst(
|
||||
assert_eq!(inst.operands_in.len(), apply.args.len());
|
||||
for (i, op) in inst.operands_in.iter().enumerate() {
|
||||
if op.is_varargs() {
|
||||
let name = var_pool
|
||||
let name = &var_pool
|
||||
.get(apply.args[i].maybe_var().expect("vararg without name"))
|
||||
.name;
|
||||
|
||||
@@ -283,8 +283,8 @@ fn emit_dst_inst(def: &Def, def_pool: &DefPool, var_pool: &VarPool, fmt: &mut Fo
|
||||
let vars = def
|
||||
.defined_vars
|
||||
.iter()
|
||||
.map(|&var_index| var_pool.get(var_index).name)
|
||||
.collect::<Vec<_>>();
|
||||
.map(|&var_index| var_pool.get(var_index).name.as_ref())
|
||||
.collect::<Vec<&str>>();
|
||||
if vars.len() == 1 {
|
||||
vars[0].to_string()
|
||||
} else {
|
||||
@@ -401,6 +401,16 @@ fn gen_transform<'a>(
|
||||
// Guard the actual expansion by `predicate`.
|
||||
fmt.line("if predicate {");
|
||||
fmt.indent(|fmt| {
|
||||
// Emit any constants that must be created before use.
|
||||
for (name, value) in transform.const_pool.iter() {
|
||||
fmtln!(
|
||||
fmt,
|
||||
"let {} = pos.func.dfg.constants.insert(vec!{:?});",
|
||||
name,
|
||||
value
|
||||
);
|
||||
}
|
||||
|
||||
// If we are adding some blocks, we need to recall the original block, such that we can
|
||||
// recompute it.
|
||||
if !transform.block_pool.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user