[PATCH] D40169: [AMDGPU] add labels to +DumpCode output

Tim Renouf via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 06:10:15 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL320146: [AMDGPU] add labels to +DumpCode output (authored by tpr).

Repository:
  rL LLVM

https://reviews.llvm.org/D40169

Files:
  llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
  llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h


Index: llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
===================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
+++ llvm/trunk/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));
Index: llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
===================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
+++ llvm/trunk/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;
 };
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40169.126131.patch
Type: text/x-patch
Size: 2818 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171208/54ea3695/attachment.bin>


More information about the llvm-commits mailing list