Skip to content

Commit cead41d

Browse files
author
Tim Renouf
committedDec 8, 2017
[AMDGPU] add labels to +DumpCode output
Summary: +DumpCode is a hack to embed disassembly in the ELF file. This commit fixes it to include labels, to make it slightly more useful. Reviewers: arsenm, kzhuravl Subscribers: nhaehnle, timcorringham, dstuttard, llvm-commits, t-tye, yaxunl, wdng, kzhuravl Differential Revision: https://reviews.llvm.org/D40169 llvm-svn: 320146
1 parent 63a3de0 commit cead41d

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed
 

‎llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp

+25-2
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,30 @@ void AMDGPUAsmPrinter::EmitFunctionEntryLabel() {
219219
getTargetStreamer()->EmitAMDGPUSymbolType(
220220
SymbolName, ELF::STT_AMDGPU_HSA_KERNEL);
221221
}
222+
const AMDGPUSubtarget &STI = MF->getSubtarget<AMDGPUSubtarget>();
223+
if (STI.dumpCode()) {
224+
// Disassemble function name label to text.
225+
DisasmLines.push_back(MF->getFunction()->getName().str() + ":");
226+
DisasmLineMaxLen = std::max(DisasmLineMaxLen, DisasmLines.back().size());
227+
HexLines.push_back("");
228+
}
222229

223230
AsmPrinter::EmitFunctionEntryLabel();
224231
}
225232

233+
void AMDGPUAsmPrinter::EmitBasicBlockStart(const MachineBasicBlock &MBB) const {
234+
const AMDGPUSubtarget &STI = MBB.getParent()->getSubtarget<AMDGPUSubtarget>();
235+
if (STI.dumpCode() && !isBlockOnlyReachableByFallthrough(&MBB)) {
236+
// Write a line for the basic block label if it is not only fallthrough.
237+
DisasmLines.push_back(
238+
(Twine("BB") + Twine(getFunctionNumber())
239+
+ "_" + Twine(MBB.getNumber()) + ":").str());
240+
DisasmLineMaxLen = std::max(DisasmLineMaxLen, DisasmLines.back().size());
241+
HexLines.push_back("");
242+
}
243+
AsmPrinter::EmitBasicBlockStart(MBB);
244+
}
245+
226246
void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
227247

228248
// Group segment variables aren't emitted in HSA.
@@ -406,8 +426,11 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
406426
Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0));
407427

408428
for (size_t i = 0; i < DisasmLines.size(); ++i) {
409-
std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
410-
Comment += " ; " + HexLines[i] + "\n";
429+
std::string Comment = "\n";
430+
if (!HexLines[i].empty()) {
431+
Comment = std::string(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
432+
Comment += " ; " + HexLines[i] + "\n";
433+
}
411434

412435
OutStreamer->EmitBytes(StringRef(DisasmLines[i]));
413436
OutStreamer->EmitBytes(StringRef(Comment));

‎llvm/lib/Target/AMDGPU/AMDGPUAsmPrinter.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ class AMDGPUAsmPrinter final : public AsmPrinter {
181181

182182
void EmitFunctionEntryLabel() override;
183183

184+
void EmitBasicBlockStart(const MachineBasicBlock &MBB) const override;
185+
184186
void EmitGlobalVariable(const GlobalVariable *GV) override;
185187

186188
void EmitStartOfAsmFile(Module &M) override;
@@ -195,8 +197,8 @@ class AMDGPUAsmPrinter final : public AsmPrinter {
195197
raw_ostream &O) override;
196198

197199
protected:
198-
std::vector<std::string> DisasmLines, HexLines;
199-
size_t DisasmLineMaxLen;
200+
mutable std::vector<std::string> DisasmLines, HexLines;
201+
mutable size_t DisasmLineMaxLen;
200202
AMDGPUAS AMDGPUASI;
201203
};
202204

0 commit comments

Comments
 (0)