Skip to content

Commit

Permalink
AMDGPU: Don't use TargetStreamer if it has not been initialized
Browse files Browse the repository at this point in the history
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.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315830 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
kzhuravl committed Oct 14, 2017
1 parent 2bed3de commit 38ae50b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ const MCSubtargetInfo* AMDGPUAsmPrinter::getSTI() const {
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) {
Expand All @@ -131,28 +133,32 @@ void AMDGPUAsmPrinter::EmitStartOfAsmFile(Module &M) {

// 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");
}

void AMDGPUAsmPrinter::EmitEndOfAsmFile(Module &M) {
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).
Expand All @@ -164,7 +170,7 @@ void AMDGPUAsmPrinter::EmitEndOfAsmFile(Module &M) {
PALMetadataVector.push_back(i.first);
PALMetadataVector.push_back(i.second);
}
getTargetStreamer().EmitPALMetadata(PALMetadataVector);
getTargetStreamer()->EmitPALMetadata(PALMetadataVector);
}
}

Expand Down Expand Up @@ -193,7 +199,7 @@ void AMDGPUAsmPrinter::EmitFunctionBodyStart() {
getAmdKernelCode(KernelCode, CurrentProgramInfo, *MF);

OutStreamer->SwitchSection(getObjFileLowering().getTextSection());
getTargetStreamer().EmitAMDKernelCodeT(KernelCode);
getTargetStreamer()->EmitAMDKernelCodeT(KernelCode);
}

if (TM.getTargetTriple().getOS() != Triple::AMDHSA)
Expand All @@ -210,7 +216,7 @@ void AMDGPUAsmPrinter::EmitFunctionEntryLabel() {
if (MFI->isEntryFunction() && STM.isAmdCodeObjectV2(*MF)) {
SmallString<128> SymbolName;
getNameWithPrefix(SymbolName, MF->getFunction()),
getTargetStreamer().EmitAMDGPUSymbolType(
getTargetStreamer()->EmitAMDGPUSymbolType(
SymbolName, ELF::STT_AMDGPU_HSA_KERNEL);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Target/AMDGPU/AMDGPUAsmPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class AMDGPUAsmPrinter final : public AsmPrinter {

const MCSubtargetInfo* getSTI() const;

AMDGPUTargetStreamer& getTargetStreamer() const;
AMDGPUTargetStreamer* getTargetStreamer() const;

bool doFinalization(Module &M) override;
bool runOnMachineFunction(MachineFunction &MF) override;
Expand Down

0 comments on commit 38ae50b

Please sign in to comment.