[llvm] Allow MCInstrAnalysis to change MCInst (PR #85906)
Stanislav Mekhanoshin via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 20 01:48:37 PDT 2024
https://github.com/rampitec created https://github.com/llvm/llvm-project/pull/85906
I have a compelling case downstream to let is modify an instruction from a recorded state. Currently NFC. Just an interface.
>From 543369b4ac34d414a7ffc626281d49cd1a7e5d3a Mon Sep 17 00:00:00 2001
From: Stanislav Mekhanoshin <Stanislav.Mekhanoshin at amd.com>
Date: Wed, 20 Mar 2024 01:38:24 -0700
Subject: [PATCH] Allow MCInstrAnalysis to change MCInst
I have a compelling case downstream to let is modify an instruction
from a recorded state. Currently NFC. Just an interface.
---
llvm/include/llvm/MC/MCInstrAnalysis.h | 5 +++++
llvm/tools/llvm-objdump/llvm-objdump.cpp | 3 +++
2 files changed, 8 insertions(+)
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(
More information about the llvm-commits
mailing list