[llvm] [BOLT] Correctly print preferred disassembly for annotated instructions (PR #120564)
Kristof Beyls via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 20 00:53:45 PST 2024
================
@@ -1961,7 +1961,15 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
OS << "\tjit\t" << MIB->getTargetSymbol(Instruction)->getName()
<< " # ID: " << DynamicID;
} else {
- InstPrinter->printInst(&Instruction, 0, "", *STI, OS);
+ // If there are annotations on the instruction, the MCInstPrinter will fail
+ // to print the preferred alias as it only does so when the number of
+ // operands is as expected. See
+ // https://github.com/llvm/llvm-project/blob/782f1a0d895646c364a53f9dcdd6d4ec1f3e5ea0/llvm/lib/MC/MCInstPrinter.cpp#L142
+ // Therefore, create a temporary copy of the Inst from which the annotations
+ // are removed, and print that Inst.
+ MCInst InstNoAnnot = Instruction;
+ MIB->stripAnnotations(InstNoAnnot);
+ InstPrinter->printInst(&InstNoAnnot, 0, "", *STI, OS);
----------------
kbeyls wrote:
Yes, I am also expecting the bottleneck to be I/O here, so thought it would be good to keep the code simple and not make it more complicated to avoid the copy.
https://github.com/llvm/llvm-project/pull/120564
More information about the llvm-commits
mailing list