[llvm] 8d09927 - MCInt: Change dump functions to accept MCContext instead of MCRegiserInfo
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 29 10:31:34 PDT 2025
Author: Fangrui Song
Date: 2025-06-29T10:31:29-07:00
New Revision: 8d099271c6ce9b9073104f5e2aaf3e06a750b84a
URL: https://github.com/llvm/llvm-project/commit/8d099271c6ce9b9073104f5e2aaf3e06a750b84a
DIFF: https://github.com/llvm/llvm-project/commit/8d099271c6ce9b9073104f5e2aaf3e06a750b84a.diff
LOG: MCInt: Change dump functions to accept MCContext instead of MCRegiserInfo
* MCContext is more accessible to callers.
* With MCContext available, printExpr can be used to print an MCExpr (MCOperand::print) seamlessly.
Added:
Modified:
llvm/include/llvm/MC/MCInst.h
llvm/lib/MC/MCInst.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/MCInst.h b/llvm/include/llvm/MC/MCInst.h
index 581dc609b913f..f26af88d92140 100644
--- a/llvm/include/llvm/MC/MCInst.h
+++ b/llvm/include/llvm/MC/MCInst.h
@@ -27,6 +27,7 @@
namespace llvm {
+class MCContext;
class MCExpr;
class MCInst;
class MCInstPrinter;
@@ -175,8 +176,7 @@ class MCOperand {
return Op;
}
- LLVM_ABI void print(raw_ostream &OS,
- const MCRegisterInfo *RegInfo = nullptr) const;
+ LLVM_ABI void print(raw_ostream &OS, const MCContext *Ctx = nullptr) const;
LLVM_ABI void dump() const;
LLVM_ABI bool isBareSymbolRef() const;
LLVM_ABI bool evaluateAsConstantImm(int64_t &Imm) const;
@@ -228,8 +228,7 @@ class MCInst {
return Operands.insert(I, Op);
}
- LLVM_ABI void print(raw_ostream &OS,
- const MCRegisterInfo *RegInfo = nullptr) const;
+ LLVM_ABI void print(raw_ostream &OS, const MCContext *Ctx = nullptr) const;
LLVM_ABI void dump() const;
/// Dump the MCInst as prettily as possible using the additional MC
@@ -238,10 +237,10 @@ class MCInst {
LLVM_ABI void dump_pretty(raw_ostream &OS,
const MCInstPrinter *Printer = nullptr,
StringRef Separator = " ",
- const MCRegisterInfo *RegInfo = nullptr) const;
+ const MCContext *Ctx = nullptr) const;
LLVM_ABI void dump_pretty(raw_ostream &OS, StringRef Name,
StringRef Separator = " ",
- const MCRegisterInfo *RegInfo = nullptr) const;
+ const MCContext *Ctx = nullptr) const;
};
inline raw_ostream& operator<<(raw_ostream &OS, const MCOperand &MO) {
diff --git a/llvm/lib/MC/MCInst.cpp b/llvm/lib/MC/MCInst.cpp
index 8ee174c751fb0..46a6a18e15963 100644
--- a/llvm/lib/MC/MCInst.cpp
+++ b/llvm/lib/MC/MCInst.cpp
@@ -8,6 +8,8 @@
#include "llvm/MC/MCInst.h"
#include "llvm/Config/llvm-config.h"
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/MC/MCRegisterInfo.h"
@@ -18,14 +20,14 @@
using namespace llvm;
-void MCOperand::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
+void MCOperand::print(raw_ostream &OS, const MCContext *Ctx) const {
OS << "<MCOperand ";
if (!isValid())
OS << "INVALID";
else if (isReg()) {
OS << "Reg:";
- if (RegInfo)
- OS << RegInfo->getName(getReg());
+ if (Ctx && Ctx->getRegisterInfo())
+ OS << Ctx->getRegisterInfo()->getName(getReg());
else
OS << getReg();
} else if (isImm())
@@ -36,11 +38,14 @@ void MCOperand::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
OS << "DFPImm:" << bit_cast<double>(getDFPImm());
else if (isExpr()) {
OS << "Expr:";
- getExpr()->print(OS, nullptr);
+ if (Ctx)
+ Ctx->getAsmInfo()->printExpr(OS, *getExpr());
+ else
+ getExpr()->print(OS, nullptr);
} else if (isInst()) {
OS << "Inst:(";
if (const auto *Inst = getInst())
- Inst->print(OS, RegInfo);
+ Inst->print(OS, Ctx);
else
OS << "NULL";
OS << ")";
@@ -73,24 +78,23 @@ LLVM_DUMP_METHOD void MCOperand::dump() const {
}
#endif
-void MCInst::print(raw_ostream &OS, const MCRegisterInfo *RegInfo) const {
+void MCInst::print(raw_ostream &OS, const MCContext *Ctx) const {
OS << "<MCInst " << getOpcode();
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
OS << " ";
- getOperand(i).print(OS, RegInfo);
+ getOperand(i).print(OS, Ctx);
}
OS << ">";
}
void MCInst::dump_pretty(raw_ostream &OS, const MCInstPrinter *Printer,
- StringRef Separator,
- const MCRegisterInfo *RegInfo) const {
+ StringRef Separator, const MCContext *Ctx) const {
StringRef InstName = Printer ? Printer->getOpcodeName(getOpcode()) : "";
- dump_pretty(OS, InstName, Separator, RegInfo);
+ dump_pretty(OS, InstName, Separator, Ctx);
}
void MCInst::dump_pretty(raw_ostream &OS, StringRef Name, StringRef Separator,
- const MCRegisterInfo *RegInfo) const {
+ const MCContext *Ctx) const {
OS << "<MCInst #" << getOpcode();
// Show the instruction opcode name if we have it.
@@ -99,7 +103,7 @@ void MCInst::dump_pretty(raw_ostream &OS, StringRef Name, StringRef Separator,
for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
OS << Separator;
- getOperand(i).print(OS, RegInfo);
+ getOperand(i).print(OS, Ctx);
}
OS << ">";
}
More information about the llvm-commits
mailing list