MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / type_suffix

Function type_suffix

cranelift/codegen/src/write.rs:287–315  ·  view source on GitHub ↗

Should `inst` be printed with a type suffix? Polymorphic instructions may need a suffix indicating the value of the controlling type variable if it can't be trivially inferred.

(func: &Function, inst: Inst)

Source from the content-addressed store, hash-verified

285// if it can't be trivially inferred.
286//
287fn type_suffix(func: &Function, inst: Inst) -> Option<Type> {
288 let inst_data = &func.dfg.insts[inst];
289 let constraints = inst_data.opcode().constraints();
290
291 if !constraints.is_polymorphic() {
292 return None;
293 }
294
295 // If the controlling type variable can be inferred from the type of the designated value input
296 // operand, we don't need the type suffix.
297 if constraints.use_typevar_operand() {
298 let ctrl_var = inst_data.typevar_operand(&func.dfg.value_lists).unwrap();
299 let def_block = match func.dfg.value_def(ctrl_var) {
300 ValueDef::Result(instr, _) => func.layout.inst_block(instr),
301 ValueDef::Param(block, _) => Some(block),
302 ValueDef::Union(..) => None,
303 };
304 if def_block.is_some() && def_block == func.layout.inst_block(inst) {
305 return None;
306 }
307 }
308
309 let rtype = func.dfg.ctrl_typevar(inst);
310 assert!(
311 !rtype.is_invalid(),
312 "Polymorphic instruction must produce a result"
313 );
314 Some(rtype)
315}
316
317/// Write out any aliases to the given target, including indirect aliases
318fn write_value_aliases(

Callers 1

write_instructionFunction · 0.85

Calls 10

constraintsMethod · 0.80
is_polymorphicMethod · 0.80
use_typevar_operandMethod · 0.80
typevar_operandMethod · 0.80
value_defMethod · 0.80
inst_blockMethod · 0.80
ctrl_typevarMethod · 0.80
opcodeMethod · 0.45
unwrapMethod · 0.45
is_someMethod · 0.45

Tested by

no test coverage detected