[llvm] [BOLT] Add a printing function for MCInst (PR #67225)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 23 07:50:27 PDT 2023
https://github.com/llongint updated https://github.com/llvm/llvm-project/pull/67225
>From 7bacce76506515d19901d2f41a2dcf66c2a3cff8 Mon Sep 17 00:00:00 2001
From: hezuoqiang <hezuoqiang2 at huawei.com>
Date: Sat, 23 Sep 2023 13:23:16 +0800
Subject: [PATCH] [BOLT] Extract a function for dump MCInst.
Extract a function for printing MCInst, so we can call it in GDB to get
a more intuitive assembly representation.
---
bolt/include/bolt/Core/BinaryContext.h | 3 +++
bolt/lib/Core/BinaryContext.cpp | 9 +++++++++
bolt/lib/Passes/ValidateInternalCalls.cpp | 10 ++++------
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h
index ef57ff3541dc8c9..da402d3ae857c24 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -1272,6 +1272,9 @@ class BinaryContext {
/// Return true if the function should be emitted to the output file.
bool shouldEmit(const BinaryFunction &Function) const;
+ /// Dump the assembly representation of MCInst to debug output.
+ void dumpInst(const MCInst &Inst) const;
+
/// Print the string name for a CFI operation.
static void printCFI(raw_ostream &OS, const MCCFIInstruction &Inst);
diff --git a/bolt/lib/Core/BinaryContext.cpp b/bolt/lib/Core/BinaryContext.cpp
index 8132e5c213af449..cb59cff0fc0a67c 100644
--- a/bolt/lib/Core/BinaryContext.cpp
+++ b/bolt/lib/Core/BinaryContext.cpp
@@ -1704,6 +1704,15 @@ bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
return HasRelocations || Function.isSimple();
}
+void BinaryContext::dumpInst(const MCInst &Inst) const {
+ if (LLVM_UNLIKELY(!InstPrinter)) {
+ dbgs() << "Cannot dump for InstPrinter is not initialized.\n";
+ return;
+ }
+ InstPrinter->printInst(&Inst, 0, "", *STI, dbgs());
+ dbgs() << "\n";
+}
+
void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
uint32_t Operation = Inst.getOperation();
switch (Operation) {
diff --git a/bolt/lib/Passes/ValidateInternalCalls.cpp b/bolt/lib/Passes/ValidateInternalCalls.cpp
index 22dadf4f6403be3..5fda81f035fe8fd 100644
--- a/bolt/lib/Passes/ValidateInternalCalls.cpp
+++ b/bolt/lib/Passes/ValidateInternalCalls.cpp
@@ -281,18 +281,16 @@ bool ValidateInternalCalls::analyzeFunction(BinaryFunction &Function) const {
LLVM_DEBUG({
dbgs() << "Detected out-of-range PIC reference in " << Function
<< "\nReturn address load: ";
- BC.InstPrinter->printInst(TargetInst, 0, "", *BC.STI, dbgs());
- dbgs() << "\nUse: ";
- BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
- dbgs() << "\n";
+ BC.dumpInst(*TargetInst);
+ dbgs() << "Use: ";
+ BC.dumpInst(Use);
Function.dump();
});
return false;
}
LLVM_DEBUG({
dbgs() << "Validated access: ";
- BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
- dbgs() << "\n";
+ BC.dumpInst(Use);
});
}
if (!UseDetected) {
More information about the llvm-commits
mailing list