MCPcopy Create free account
hub / github.com/Rust-GPU/rust-gpu / fuse_bool

Function fuse_bool

crates/rustc_codegen_spirv/src/linker/peephole_opts.rs:509–551  ·  view source on GitHub ↗
(
    header: &mut ModuleHeader,
    defs: &FxHashMap<Word, (usize, Instruction)>,
    phis_to_insert: &mut Vec<(usize, Instruction)>,
    already_mapped: &mut FxHashMap<Word, Word>,
    bool_ty: Word

Source from the content-addressed store, hash-verified

507}
508
509fn fuse_bool(
510 header: &mut ModuleHeader,
511 defs: &FxHashMap<Word, (usize, Instruction)>,
512 phis_to_insert: &mut Vec<(usize, Instruction)>,
513 already_mapped: &mut FxHashMap<Word, Word>,
514 bool_ty: Word,
515 int_value: Word,
516) -> Word {
517 if let Some(&result) = already_mapped.get(&int_value) {
518 return result;
519 }
520 let (block_of_inst, inst) = defs.get(&int_value).unwrap();
521 match inst.class.opcode {
522 Op::Select => inst.operands[0].unwrap_id_ref(),
523 Op::Phi => {
524 let result_id = id(header);
525 already_mapped.insert(int_value, result_id);
526 let new_phi_args = inst
527 .operands
528 .chunks(2)
529 .flat_map(|arr| {
530 let phi_value = &arr[0];
531 let block = &arr[1];
532 [
533 Operand::IdRef(fuse_bool(
534 header,
535 defs,
536 phis_to_insert,
537 already_mapped,
538 bool_ty,
539 phi_value.unwrap_id_ref(),
540 )),
541 block.clone(),
542 ]
543 })
544 .collect::<Vec<_>>();
545 let inst = Instruction::new(Op::Phi, Some(bool_ty), Some(result_id), new_phi_args);
546 phis_to_insert.push((*block_of_inst, inst));
547 result_id
548 }
549 _ => bug!("can_fuse_bool should have prevented this case"),
550 }
551}
552
553// The compiler generates a lot of code that looks like this:
554// %v_int = OpSelect %int %v %const_1 %const_0

Callers 1

bool_fusionFunction · 0.85

Calls 3

idFunction · 0.85
insertMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected