[llvm-branch-commits] [llvm] [BOLT] Factor out MCInstReference from gadget scanner (NFC) (PR #138655)

Maksim Panchenko via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed May 28 11:38:05 PDT 2025


================
@@ -1682,48 +1648,66 @@ void Analysis::runOnFunction(BinaryFunction &BF,
   }
 }
 
+// Compute the instruction address for printing (may be slow).
+static uint64_t getAddress(const MCInstReference &Inst) {
+  const BinaryFunction *BF = Inst.getFunction();
+
+  if (Inst.hasCFG()) {
+    const BinaryBasicBlock *BB = Inst.getBasicBlock();
+
+    auto It = static_cast<BinaryBasicBlock::const_iterator>(&Inst.getMCInst());
+    unsigned IndexInBB = std::distance(BB->begin(), It);
+
+    // FIXME: this assumes all instructions are 4 bytes in size. This is true
----------------
maksfb wrote:

We have `BinaryContext::computeCodeSize()`.

https://github.com/llvm/llvm-project/pull/138655


More information about the llvm-branch-commits mailing list