Skip to content

Commit

Permalink
add decoration-id rewrite to inliner
Browse files Browse the repository at this point in the history
  • Loading branch information
SiebenCorgie committed May 5, 2023
1 parent a64857a commit cd4d786
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/rustc_codegen_spirv/src/linker/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
let mut inliner = Inliner {
header: module.header.as_mut().unwrap(),
types_global_values: &mut module.types_global_values,
annotations: &mut module.annotations,
void,
functions: &functions,
legal_globals: &legal_globals,
Expand Down Expand Up @@ -337,6 +338,7 @@ fn should_inline(
struct Inliner<'m, 'map> {
header: &'m mut ModuleHeader,
types_global_values: &'m mut Vec<Instruction>,
annotations: &'m mut Vec<Instruction>,
void: Word,
functions: &'map FunctionMap,
legal_globals: &'map FxHashMap<Word, LegalGlobal>,
Expand All @@ -350,6 +352,22 @@ impl Inliner<'_, '_> {
result
}

///Applies all rewrite rules to the decorations in the header.
fn apply_rewrite_for_decorations(&mut self, rewrite_rules: &FxHashMap<Word, Word>) {
// NOTE(siebencorgie): We don't care *what* decoration we rewrite atm. AFAIK there is no case where rewriting
// the decoration on inline wouldn't be valid.
for annotation in self.annotations.iter_mut() {
if annotation.class.opcode == Op::Decorate {
//There must be a second operand containing a id, check if that's one we need to rewrite
if let Some(id) = annotation.operands[0].id_ref_any_mut() {
if let Some(&rewrite) = rewrite_rules.get(id) {
*id = rewrite;
}
}
}
}
}

fn ptr_ty(&mut self, pointee: Word) -> Word {
// TODO: This is horribly slow, fix this
let existing = self.types_global_values.iter().find(|inst| {
Expand Down Expand Up @@ -448,6 +466,7 @@ impl Inliner<'_, '_> {
// fn is inlined multiple times.
self.add_clone_id_rules(&mut rewrite_rules, &inlined_callee_blocks);
apply_rewrite_rules(&rewrite_rules, &mut inlined_callee_blocks);
self.apply_rewrite_for_decorations(&rewrite_rules);

// Split the block containing the `OpFunctionCall` into pre-call vs post-call.
let pre_call_block_idx = block_idx;
Expand Down

0 comments on commit cd4d786

Please sign in to comment.