void RegisterAliasingTracker::FillOriginAndAliasedBits( const llvm::MCRegisterInfo &RegInfo, const llvm::BitVector &SourceBits) { using RegAliasItr = llvm::MCRegAliasIterator; for (const size_t PhysReg : SourceBits.set_bits()) { for (auto Itr = RegAliasItr(PhysReg, &RegInfo, true); Itr.isValid(); ++Itr) { AliasedBits.set(*Itr); Origins[*Itr] = PhysReg; } } }
llvm::BitVector getAliasedBits(const llvm::MCRegisterInfo &RegInfo, const llvm::BitVector &SourceBits) { llvm::BitVector AliasedBits(RegInfo.getNumRegs()); for (const size_t PhysReg : SourceBits.set_bits()) { using RegAliasItr = llvm::MCRegAliasIterator; for (auto Itr = RegAliasItr(PhysReg, &RegInfo, true); Itr.isValid(); ++Itr) { AliasedBits.set(*Itr); } } return AliasedBits; }
static void randomize(const Instruction &Instr, const Variable &Var, llvm::MCOperand &AssignedValue, const llvm::BitVector &ForbiddenRegs) { const Operand &Op = Instr.getPrimaryOperand(Var); switch (Op.getExplicitOperandInfo().OperandType) { case llvm::MCOI::OperandType::OPERAND_IMMEDIATE: // FIXME: explore immediate values too. AssignedValue = llvm::MCOperand::createImm(1); break; case llvm::MCOI::OperandType::OPERAND_REGISTER: { assert(Op.isReg()); auto AllowedRegs = Op.getRegisterAliasing().sourceBits(); assert(AllowedRegs.size() == ForbiddenRegs.size()); for (auto I : ForbiddenRegs.set_bits()) AllowedRegs.reset(I); AssignedValue = llvm::MCOperand::createReg(randomBit(AllowedRegs)); break; } default: break; } }
static void remove(llvm::BitVector &a, const llvm::BitVector &b) { assert(a.size() == b.size()); for (auto I : b.set_bits()) a.reset(I); }