[PATCH] D40169: [AMDGPU] add labels to +DumpCode output
Tim Renouf via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 17 01:13:22 PST 2017
tpr created this revision.
Herald added a subscriber: nhaehnle.
+DumpCode is a hack to embed disassembly in the ELF file. This commit
fixes it to include labels, to make it slightly more useful.
https://reviews.llvm.org/D40169
Files:
lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
lib/Target/AMDGPU/AMDGPUAsmPrinter.h
Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.h
===================================================================
--- lib/Target/AMDGPU/AMDGPUAsmPrinter.h
+++ lib/Target/AMDGPU/AMDGPUAsmPrinter.h
@@ -181,6 +181,8 @@
void EmitFunctionEntryLabel() override;
+ void EmitBasicBlockStart(const MachineBasicBlock &MBB) const override;
+
void EmitGlobalVariable(const GlobalVariable *GV) override;
void EmitStartOfAsmFile(Module &M) override;
@@ -195,8 +197,8 @@
raw_ostream &O) override;
protected:
- std::vector<std::string> DisasmLines, HexLines;
- size_t DisasmLineMaxLen;
+ mutable std::vector<std::string> DisasmLines, HexLines;
+ mutable size_t DisasmLineMaxLen;
AMDGPUAS AMDGPUASI;
};
Index: lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
===================================================================
--- lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
@@ -219,10 +219,30 @@
getTargetStreamer()->EmitAMDGPUSymbolType(
SymbolName, ELF::STT_AMDGPU_HSA_KERNEL);
}
+ const AMDGPUSubtarget &STI = MF->getSubtarget<AMDGPUSubtarget>();
+ if (STI.dumpCode()) {
+ // Disassemble function name label to text.
+ DisasmLines.push_back(MF->getFunction()->getName().str() + ":");
+ DisasmLineMaxLen = std::max(DisasmLineMaxLen, DisasmLines.back().size());
+ HexLines.push_back("");
+ }
AsmPrinter::EmitFunctionEntryLabel();
}
+void AMDGPUAsmPrinter::EmitBasicBlockStart(const MachineBasicBlock &MBB) const {
+ const AMDGPUSubtarget &STI = MBB.getParent()->getSubtarget<AMDGPUSubtarget>();
+ if (STI.dumpCode() && !isBlockOnlyReachableByFallthrough(&MBB)) {
+ // Write a line for the basic block label if it is not only fallthrough.
+ DisasmLines.push_back(
+ (Twine("BB") + Twine(getFunctionNumber())
+ + "_" + Twine(MBB.getNumber()) + ":").str());
+ DisasmLineMaxLen = std::max(DisasmLineMaxLen, DisasmLines.back().size());
+ HexLines.push_back("");
+ }
+ AsmPrinter::EmitBasicBlockStart(MBB);
+}
+
void AMDGPUAsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
// Group segment variables aren't emitted in HSA.
@@ -406,8 +426,11 @@
Context.getELFSection(".AMDGPU.disasm", ELF::SHT_NOTE, 0));
for (size_t i = 0; i < DisasmLines.size(); ++i) {
- std::string Comment(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
- Comment += " ; " + HexLines[i] + "\n";
+ std::string Comment = "\n";
+ if (!HexLines[i].empty()) {
+ Comment = std::string(DisasmLineMaxLen - DisasmLines[i].size(), ' ');
+ Comment += " ; " + HexLines[i] + "\n";
+ }
OutStreamer->EmitBytes(StringRef(DisasmLines[i]));
OutStreamer->EmitBytes(StringRef(Comment));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40169.123304.patch
Type: text/x-patch
Size: 2752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171117/00333547/attachment.bin>
More information about the llvm-commits
mailing list