Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BOLT][NFC] Extract a function for dump MCInst #67225

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,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 dump(const MCInst &Inst) const;

/// Print the string name for a CFI operation.
static void printCFI(raw_ostream &OS, const MCCFIInstruction &Inst);

Expand Down
9 changes: 9 additions & 0 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,15 @@ bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
return HasRelocations || Function.isSimple();
}

void BinaryContext::dump(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) {
Expand Down
10 changes: 4 additions & 6 deletions bolt/lib/Passes/ValidateInternalCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.dump(*TargetInst);
dbgs() << "Use: ";
BC.dump(Use);
Function.dump();
});
return false;
}
LLVM_DEBUG({
dbgs() << "Validated access: ";
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
dbgs() << "\n";
BC.dump(Use);
});
}
if (!UseDetected) {
Expand Down