[llvm] Allow MCInstrAnalysis to change MCInst (PR #85906)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 20 01:49:06 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-binary-utilities
Author: Stanislav Mekhanoshin (rampitec)
<details>
<summary>Changes</summary>
I have a compelling case downstream to let is modify an instruction from a recorded state. Currently NFC. Just an interface.
---
Full diff: https://github.com/llvm/llvm-project/pull/85906.diff
2 Files Affected:
- (modified) llvm/include/llvm/MC/MCInstrAnalysis.h (+5)
- (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+3)
``````````diff
diff --git a/llvm/include/llvm/MC/MCInstrAnalysis.h b/llvm/include/llvm/MC/MCInstrAnalysis.h
index 87db57f74f520e..7b73b03f1a7d4b 100644
--- a/llvm/include/llvm/MC/MCInstrAnalysis.h
+++ b/llvm/include/llvm/MC/MCInstrAnalysis.h
@@ -24,6 +24,7 @@
namespace llvm {
+class MCContext;
class MCRegisterInfo;
class Triple;
@@ -52,6 +53,10 @@ class MCInstrAnalysis {
/// new function), clients should call resetState to clear it.
virtual void updateState(const MCInst &Inst, uint64_t Addr) {}
+ /// Let the analysis update disassembled instruction from a recorded internal
+ /// state.
+ virtual void updateInst(MCInst &Inst, const MCContext &Ctx) const {}
+
virtual bool isBranch(const MCInst &Inst) const {
return Info->get(Inst.getOpcode()).isBranch();
}
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 78cf67b1e630bb..ec6883d28e35ef 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -2252,6 +2252,9 @@ disassembleObject(ObjectFile &Obj, const ObjectFile &DbgObj,
LVP.update({Index, Section.getIndex()},
{Index + Size, Section.getIndex()}, Index + Size != End);
+ if (Disassembled && DT->InstrAnalysis)
+ DT->InstrAnalysis->updateInst(Inst, *DT->Context);
+
DT->InstPrinter->setCommentStream(CommentStream);
DT->Printer->printInst(
``````````
</details>
https://github.com/llvm/llvm-project/pull/85906
More information about the llvm-commits
mailing list