[llvm] r315830 - AMDGPU: Don't use TargetStreamer if it has not been initialized
Konstantin Zhuravlyov via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 14 15:16:26 PDT 2017
Author: kzhuravl
Date: Sat Oct 14 15:16:26 2017
New Revision: 315830
URL: http://llvm.org/viewvc/llvm-project?rev=315830&view=rev
Log:
AMDGPU: Don't use TargetStreamer if it has not been initialized
Fixes cfe/trunk/test/Misc/backend-resource-limit-diagnostics.cl
test after r315808
We may hit few other similar issues, but I want to discuss good
solution offline.
Modified:
llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp?rev=315830&r1=315829&r2=315830&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp Sat Oct 14 15:16:26 2017
@@ -107,8 +107,10 @@ const MCSubtargetInfo* AMDGPUAsmPrinter:
return TM.getMCSubtargetInfo();
}
-AMDGPUTargetStreamer& AMDGPUAsmPrinter::getTargetStreamer() const {
- return static_cast<AMDGPUTargetStreamer&>(*OutStreamer->getTargetStreamer());
+AMDGPUTargetStreamer* AMDGPUAsmPrinter::getTargetStreamer() const {
+ if (!OutStreamer)
+ return nullptr;
+ return static_cast<AMDGPUTargetStreamer*>(OutStreamer->getTargetStreamer());
}
void AMDGPUAsmPrinter::EmitStartOfAsmFile(Module &M) {
@@ -131,11 +133,11 @@ void AMDGPUAsmPrinter::EmitStartOfAsmFil
// HSA emits NT_AMDGPU_HSA_CODE_OBJECT_VERSION for code objects v2.
if (TM.getTargetTriple().getOS() == Triple::AMDHSA)
- getTargetStreamer().EmitDirectiveHSACodeObjectVersion(2, 1);
+ getTargetStreamer()->EmitDirectiveHSACodeObjectVersion(2, 1);
// HSA and PAL emit NT_AMDGPU_HSA_ISA for code objects v2.
IsaInfo::IsaVersion ISA = IsaInfo::getIsaVersion(getSTI()->getFeatureBits());
- getTargetStreamer().EmitDirectiveHSACodeObjectISA(
+ getTargetStreamer()->EmitDirectiveHSACodeObjectISA(
ISA.Major, ISA.Minor, ISA.Stepping, "AMD", "AMDGPU");
}
@@ -143,16 +145,20 @@ void AMDGPUAsmPrinter::EmitEndOfAsmFile(
if (TM.getTargetTriple().getArch() != Triple::amdgcn)
return;
+ // Following code requires TargetStreamer to be present.
+ if (!getTargetStreamer())
+ return;
+
// Emit ISA Version (NT_AMD_AMDGPU_ISA).
std::string ISAVersionString;
raw_string_ostream ISAVersionStream(ISAVersionString);
IsaInfo::streamIsaVersion(getSTI(), ISAVersionStream);
- getTargetStreamer().EmitISAVersion(ISAVersionStream.str());
+ getTargetStreamer()->EmitISAVersion(ISAVersionStream.str());
// Emit HSA Metadata (NT_AMD_AMDGPU_HSA_METADATA).
if (TM.getTargetTriple().getOS() == Triple::AMDHSA) {
HSAMetadataStream.end();
- getTargetStreamer().EmitHSAMetadata(HSAMetadataStream.getHSAMetadata());
+ getTargetStreamer()->EmitHSAMetadata(HSAMetadataStream.getHSAMetadata());
}
// Emit PAL Metadata (NT_AMD_AMDGPU_PAL_METADATA).
@@ -164,7 +170,7 @@ void AMDGPUAsmPrinter::EmitEndOfAsmFile(
PALMetadataVector.push_back(i.first);
PALMetadataVector.push_back(i.second);
}
- getTargetStreamer().EmitPALMetadata(PALMetadataVector);
+ getTargetStreamer()->EmitPALMetadata(PALMetadataVector);
}
}
@@ -193,7 +199,7 @@ void AMDGPUAsmPrinter::EmitFunctionBodyS
getAmdKernelCode(KernelCode, CurrentProgramInfo, *MF);
OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
- getTargetStreamer().EmitAMDKernelCodeT(KernelCode);
+ getTargetStreamer()->EmitAMDKernelCodeT(KernelCode);
}
if (TM.getTargetTriple().getOS() != Triple::AMDHSA)
@@ -210,7 +216,7 @@ void AMDGPUAsmPrinter::EmitFunctionEntry
if (MFI->isEntryFunction() && STM.isAmdCodeObjectV2(*MF)) {
SmallString<128> SymbolName;
getNameWithPrefix(SymbolName, MF->getFunction()),
- getTargetStreamer().EmitAMDGPUSymbolType(
+ getTargetStreamer()->EmitAMDGPUSymbolType(
SymbolName, ELF::STT_AMDGPU_HSA_KERNEL);
}
Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h?rev=315830&r1=315829&r2=315830&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h (original)
+++ llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h Sat Oct 14 15:16:26 2017
@@ -155,7 +155,7 @@ public:
const MCSubtargetInfo* getSTI() const;
- AMDGPUTargetStreamer& getTargetStreamer() const;
+ AMDGPUTargetStreamer* getTargetStreamer() const;
bool doFinalization(Module &M) override;
bool runOnMachineFunction(MachineFunction &MF) override;
More information about the llvm-commits
mailing list