[PATCH] D97776: [CSSPGO][llvm-profgen] Continue disassembling after illegal instruction is seen.
Hongtao Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 2 08:57:04 PST 2021
hoy created this revision.
Herald added a subscriber: wenlei.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Previously we errored out when disassembling illegal instructions and there would be no profile generated. In fact illegal instructions are not uncommon and we'd better skip them and print "unknown" instead of erroring out. This matches the behavior of llvm-objdump (see disassembleObject in llvm-objdump.cpp).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97776
Files:
llvm/tools/llvm-profgen/ProfiledBinary.cpp
Index: llvm/tools/llvm-profgen/ProfiledBinary.cpp
===================================================================
--- llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -222,9 +222,11 @@
MCInst Inst;
uint64_t Size;
// Disassemble an instruction.
- if (!DisAsm->getInstruction(Inst, Size, Bytes.slice(Offset - SectionOffset),
- Offset + PreferredBaseAddress, nulls()))
- return false;
+ bool Disassembled =
+ DisAsm->getInstruction(Inst, Size, Bytes.slice(Offset - SectionOffset),
+ Offset + PreferredBaseAddress, nulls());
+ if (Size == 0)
+ Size = 1;
if (ShowDisassemblyOnly) {
if (ShowPseudoProbe) {
@@ -233,34 +235,38 @@
}
outs() << format("%8" PRIx64 ":", Offset);
size_t Start = outs().tell();
- IPrinter->printInst(&Inst, Offset + Size, "", *STI.get(), outs());
+ if (Disassembled)
+ IPrinter->printInst(&Inst, Offset + Size, "", *STI.get(), outs());
+ else
+ outs() << "\t<unknown>";
if (ShowSourceLocations) {
unsigned Cur = outs().tell() - Start;
if (Cur < 40)
outs().indent(40 - Cur);
- InstructionPointer Inst(this, Offset);
- outs() << getReversedLocWithContext(symbolize(Inst));
+ InstructionPointer IP(this, Offset);
+ outs() << getReversedLocWithContext(symbolize(IP));
}
outs() << "\n";
}
- const MCInstrDesc &MCDesc = MII->get(Inst.getOpcode());
-
- // Populate a vector of the symbolized callsite at this location
- // We don't need symbolized info for probe-based profile, just use an empty
- // stack as an entry to indicate a valid binary offset
- FrameLocationStack SymbolizedCallStack;
- if (!UsePseudoProbes) {
- InstructionPointer IP(this, Offset);
- SymbolizedCallStack = symbolize(IP, true);
+ if (Disassembled) {
+ const MCInstrDesc &MCDesc = MII->get(Inst.getOpcode());
+ // Populate a vector of the symbolized callsite at this location
+ // We don't need symbolized info for probe-based profile, just use an
+ // empty stack as an entry to indicate a valid binary offset
+ FrameLocationStack SymbolizedCallStack;
+ if (!UsePseudoProbes) {
+ InstructionPointer IP(this, Offset);
+ SymbolizedCallStack = symbolize(IP, true);
+ }
+ Offset2LocStackMap[Offset] = SymbolizedCallStack;
+ // Populate address maps.
+ CodeAddrs.push_back(Offset);
+ if (MCDesc.isCall())
+ CallAddrs.insert(Offset);
+ else if (MCDesc.isReturn())
+ RetAddrs.insert(Offset);
}
- Offset2LocStackMap[Offset] = SymbolizedCallStack;
- // Populate address maps.
- CodeAddrs.push_back(Offset);
- if (MCDesc.isCall())
- CallAddrs.insert(Offset);
- else if (MCDesc.isReturn())
- RetAddrs.insert(Offset);
Offset += Size;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97776.327475.patch
Type: text/x-patch
Size: 2971 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210302/d3fd7016/attachment.bin>
More information about the llvm-commits
mailing list