[BOLT][NFC] Add MCPlus::primeOperands iterator_range

Reviewed By: yota9

Differential Revision: https://reviews.llvm.org/D125397
This commit is contained in:
Amir Ayupov 2022-05-11 09:34:10 -07:00
parent f933c896d1
commit 8cb7a873ab
7 changed files with 22 additions and 16 deletions

View file

@ -113,6 +113,19 @@ inline unsigned getNumPrimeOperands(const MCInst &Inst) {
return Inst.getNumOperands();
}
/// Return iterator range of operands excluding operands representing
/// annotations.
inline iterator_range<MCInst::iterator> primeOperands(MCInst &Inst) {
return iterator_range<MCInst::iterator>(
Inst.begin(), Inst.begin() + getNumPrimeOperands(Inst));
}
inline iterator_range<MCInst::const_iterator>
primeOperands(const MCInst &Inst) {
return iterator_range<MCInst::const_iterator>(
Inst.begin(), Inst.begin() + getNumPrimeOperands(Inst));
}
} // namespace MCPlus
} // namespace bolt

View file

@ -3610,8 +3610,8 @@ size_t BinaryFunction::computeHash(bool UseDFS,
Opcode = Opcode >> 8;
}
for (unsigned I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I)
HashString.append(OperandHashFunc(Inst.getOperand(I)));
for (const MCOperand &Op : MCPlus::primeOperands(Inst))
HashString.append(OperandHashFunc(Op));
}
}

View file

@ -44,11 +44,9 @@ bool isIndifferentToSP(const MCInst &Inst, const BinaryContext &BC) {
II.hasImplicitUseOfPhysReg(BC.MIB->getStackPointer()))
return false;
for (int I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I) {
const MCOperand &Operand = Inst.getOperand(I);
for (const MCOperand &Operand : MCPlus::primeOperands(Inst))
if (Operand.isReg() && Operand.getReg() == BC.MIB->getStackPointer())
return false;
}
return true;
}

View file

@ -212,9 +212,7 @@ void dumpFunction(const BinaryFunction &BF) {
// Analyze symbol references (data, functions) from the instruction.
bool IsCall = BC.MIB->isCall(Instr);
for (unsigned I = 0, E = MCPlus::getNumPrimeOperands(Instr); I != E;
++I) {
MCOperand Operand = Instr.getOperand(I);
for (const MCOperand &Operand : MCPlus::primeOperands(Instr)) {
if (Operand.isExpr() &&
Operand.getExpr()->getKind() == MCExpr::SymbolRef) {
std::pair<const MCSymbol *, uint64_t> TSI =

View file

@ -47,8 +47,7 @@ void RegReAssign::swap(BinaryFunction &Function, MCPhysReg A, MCPhysReg B) {
// Regular instructions
for (BinaryBasicBlock &BB : Function) {
for (MCInst &Inst : BB) {
for (int I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I) {
MCOperand &Operand = Inst.getOperand(I);
for (MCOperand &Operand : MCPlus::primeOperands(Inst)) {
if (!Operand.isReg())
continue;

View file

@ -619,11 +619,10 @@ public:
auto addInstrOperands = [&](const MCInst &Instr) {
// Update Uses table
for (unsigned OpNum = 0, OpEnd = MCPlus::getNumPrimeOperands(Instr);
OpNum != OpEnd; ++OpNum) {
if (!Instr.getOperand(OpNum).isReg())
for (const MCOperand &Operand : MCPlus::primeOperands(Instr)) {
if (!Operand.isReg())
continue;
unsigned Reg = Instr.getOperand(OpNum).getReg();
unsigned Reg = Operand.getReg();
MCInst *AliasInst = RegAliasTable[Reg];
Uses[&Instr].push_back(AliasInst);
LLVM_DEBUG({

View file

@ -985,8 +985,7 @@ public:
case X86::MOVZX32rm8:
case X86::MOVZX32rr8:
case X86::TEST8ri:
for (int I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I) {
const MCOperand &Operand = Inst.getOperand(I);
for (const MCOperand &Operand : MCPlus::primeOperands(Inst)) {
if (!Operand.isReg())
continue;
if (isUpper8BitReg(Operand.getReg()))