Lib/Liveness/Liveness.cpp
/**
 * Replace the variables with the assigned registers for the given instruction
 *
 * This functions assigns real registers to the 'variable registers' of the instruction.
 *
 * The incoming instructions all have REG_A as registers but signify variables.
 * The reg id's indicate the variable at this stage.
 *
 * Allocation is first done with reg types TMP_A/TMP_B,
 * to avoid accidental replacements of registers with same id.
 * This has happened IRL.
 */
Replace the variables with the assigned registers for the given instruction
This functions assigns real registers to the 'variable registers' of the instruction.

The incoming instructions all have REG_A as registers but signify variables.
The reg id's indicate the variable at this stage.

Allocation is first done with reg types TMP_A/TMP_B,
to avoid accidental replacements of registers with same id.
This has happened IRL.
Replace the variables with the assigned registers for the given instruction This functions assigns real registers to the ' variable registers ' of the instruction . The incoming instructions all have REG_A as registers but signify variables . The reg id ' s indicate the variable at this stage . Allocation is first done with reg types TMP_A / TMP_B to avoid accidental replacements of registers with same id . This has happened IRL .
void allocate_registers(Instr &instr, RegUsage const &alloc) {
  auto check_regfile_register = [&instr] (Reg const &replace_with, RegId r) -> bool {
    if (replace_with.tag == REG_A) return true;
    if (Platform::compiling_for_vc4() && replace_with.tag == REG_B) return true;
    UseDefReg out(instr);
    std::string msg = "regAlloc(): allocated register must be in register file.";
    msg << "\n"
        << "Instruction: " << instr.dump() << ", "
        << "Registers: " << out.dump() << ", "
        << "Reg id : " << r << ", alloc value: " << replace_with.dump();
    error(msg, true);  
    return false;
  };
  UseDef useDefSet(instr);  
  if (useDefSet.def.tag != NONE) {
    RegId r = useDefSet.def.regId; 
    assert(!alloc[r].unused());
    Reg replace_with = alloc[r].reg;
    if (check_regfile_register(replace_with, r)) {
      replace_with.tag = (replace_with.tag == REG_A)?TMP_A:TMP_B;
      instr.rename_dest(Reg(REG_A, r), replace_with);
    }
  }
  for (auto r: useDefSet.use) {
    assert(!alloc[r].unused());
    Reg replace_with = alloc[r].reg;
    if (!check_regfile_register(replace_with, r)) continue;
    replace_with.tag = (replace_with.tag == REG_A)?TMP_A:TMP_B;
    renameUses(instr, Reg(REG_A, r), replace_with);
  }
  substRegTag(&instr, TMP_A, REG_A);
  substRegTag(&instr, TMP_B, REG_B);
}
void allocate_registers ( Instr & instr , RegUsage const & alloc ) { auto check_regfile_register = [ & instr ] ( Reg const & replace_with , RegId r ) -> bool { if ( replace_with . tag == REG_A ) return true ; if ( Platform :: compiling_for_vc4 ( ) && replace_with . tag == REG_B ) return true ; UseDefReg out ( instr ) ; std :: string msg = " " ; msg << " \n " << " " << instr . dump ( ) << " " << " " << out . dump ( ) << " " << " " << r << " " << replace_with . dump ( ) ; error ( msg , true ) ; return false ; } ; UseDef useDefSet ( instr ) ; if ( useDefSet . def . tag != NONE ) { RegId r = useDefSet . def . regId ; assert ( ! alloc [ r ] . unused ( ) ) ; Reg replace_with = alloc [ r ] . reg ; if ( check_regfile_register ( replace_with , r ) ) { replace_with . tag = ( replace_with . tag == REG_A ) ? TMP_A : TMP_B ; instr . rename_dest ( Reg ( REG_A , r ) , replace_with ) ; } } for ( auto r : useDefSet . use ) { assert ( ! alloc [ r ] . unused ( ) ) ; Reg replace_with = alloc [ r ] . reg ; if ( ! check_regfile_register ( replace_with , r ) ) continue ; replace_with . tag = ( replace_with . tag == REG_A ) ? TMP_A : TMP_B ; renameUses ( instr , Reg ( REG_A , r ) , replace_with ) ; } substRegTag ( & instr , TMP_A , REG_A ) ; substRegTag ( & instr , TMP_B , REG_B ) ; }
Replace the variables with the assigned registers for the given instruction
 This functions assigns real registers to the 'variable registers' of the instruction.
Replace the variables with the assigned registers for the given instruction This functions assigns real registers to the ' variable registers ' of the instruction .
// true: throw if there is an error // Registers only usage REG_A