[llvm] [BOLT] Refactor MCInst target symbol lookup. NFCI (PR #129131)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 27 14:04:07 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-bolt
Author: Maksim Panchenko (maksfb)
<details>
<summary>Changes</summary>
In analyzeInstructionForFuncReference(), use MCPlusBuilder interface while scanning symbolic operands of MCInst. Should be NFC on x86, but will make the function work on other architectures. Note that it's currently unused on non-x86 as its functionality is exclusive to safe ICF that runs on x86 only.
---
Full diff: https://github.com/llvm/llvm-project/pull/129131.diff
1 Files Affected:
- (modified) bolt/lib/Core/BinaryFunction.cpp (+4-8)
``````````diff
diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index ff5eb5cf6e1eb..5a1ff58b72f75 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -1544,15 +1544,11 @@ MCSymbol *BinaryFunction::registerBranch(uint64_t Src, uint64_t Dst) {
}
void BinaryFunction::analyzeInstructionForFuncReference(const MCInst &Inst) {
- for (const MCOperand &Op : MCPlus::primeOperands(Inst)) {
- if (!Op.isExpr())
+ for (unsigned OpNum = 0; OpNum < MCPlus::getNumPrimeOperands(Inst); ++OpNum) {
+ const MCSymbol *Symbol = BC.MIB->getTargetSymbol(Inst, OpNum);
+ if (!Symbol)
continue;
- const MCExpr &Expr = *Op.getExpr();
- if (Expr.getKind() != MCExpr::SymbolRef)
- continue;
- const MCSymbol &Symbol = cast<MCSymbolRefExpr>(Expr).getSymbol();
- // Set HasAddressTaken for a function regardless of the ICF level.
- if (BinaryFunction *BF = BC.getFunctionForSymbol(&Symbol))
+ if (BinaryFunction *BF = BC.getFunctionForSymbol(Symbol))
BF->setHasAddressTaken(true);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/129131
More information about the llvm-commits
mailing list