From: Jay Foad Date: Thu, 27 Jun 2019 08:19:28 +0000 (+0000) Subject: [AMDGPU] Fix +DumpCode to print an entry label for the first function X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=135f7bd0843bac2b78a70a41b1f5326375fa9c9c;p=llvm [AMDGPU] Fix +DumpCode to print an entry label for the first function Summary: The +DumpCode attribute is a horrible hack in AMDGPU to embed the disassembly of the generated code into the elf file. It is used by LLPC to implement an extension that allows the application to read back the disassembly of the code. It tries to print an entry label at the start of every function, but that didn't work for the first function in the module because DumpCodeInstEmitter wasn't initialised until EmitFunctionBodyStart which is too late. Change-Id: I790d73ddf4f51fd02ab32529380c7cb7c607c4ee Reviewers: arsenm, tpr, kzhuravl Reviewed By: arsenm Subscribers: arsenm, kzhuravl, jvesely, wdng, nhaehnle, yaxunl, dstuttard, tpr, t-tye, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63712 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364508 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp b/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp index cf1ed349302..b74a9e631a7 100644 --- a/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp +++ b/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp @@ -206,18 +206,6 @@ void AMDGPUAsmPrinter::EmitFunctionBodyStart() { if (STM.isAmdHsaOS()) HSAMetadataStream->emitKernel(*MF, CurrentProgramInfo); - - DumpCodeInstEmitter = nullptr; - if (STM.dumpCode()) { - // For -dumpcode, get the assembler out of the streamer, even if it does - // not really want to let us have it. This only works with -filetype=obj. - bool SaveFlag = OutStreamer->getUseAssemblerInfoForParsing(); - OutStreamer->setUseAssemblerInfoForParsing(true); - MCAssembler *Assembler = OutStreamer->getAssemblerPtr(); - OutStreamer->setUseAssemblerInfoForParsing(SaveFlag); - if (Assembler) - DumpCodeInstEmitter = Assembler->getEmitterPtr(); - } } void AMDGPUAsmPrinter::EmitFunctionBodyEnd() { @@ -458,6 +446,18 @@ bool AMDGPUAsmPrinter::runOnMachineFunction(MachineFunction &MF) { EmitProgramInfoSI(MF, CurrentProgramInfo); } + DumpCodeInstEmitter = nullptr; + if (STM.dumpCode()) { + // For -dumpcode, get the assembler out of the streamer, even if it does + // not really want to let us have it. This only works with -filetype=obj. + bool SaveFlag = OutStreamer->getUseAssemblerInfoForParsing(); + OutStreamer->setUseAssemblerInfoForParsing(true); + MCAssembler *Assembler = OutStreamer->getAssemblerPtr(); + OutStreamer->setUseAssemblerInfoForParsing(SaveFlag); + if (Assembler) + DumpCodeInstEmitter = Assembler->getEmitterPtr(); + } + DisasmLines.clear(); HexLines.clear(); DisasmLineMaxLen = 0; diff --git a/test/CodeGen/AMDGPU/debug.ll b/test/CodeGen/AMDGPU/debug.ll index f149aaddb8e..87f1de05540 100644 --- a/test/CodeGen/AMDGPU/debug.ll +++ b/test/CodeGen/AMDGPU/debug.ll @@ -3,6 +3,8 @@ ; Test for a crash in the custom assembly dump code. +; SI: test: +; SI: BB0_0: ; SI: s_endpgm define amdgpu_kernel void @test(i32 addrspace(1)* %out) { store i32 0, i32 addrspace(1)* %out