From 219066bab87870160be2563298794b8cbe2e29f7 Mon Sep 17 00:00:00 2001 From: Konstantin Zhuravlyov Date: Sat, 14 Oct 2017 16:15:28 +0000 Subject: [PATCH] AMDGPU: Improve note directive verification in assembler - Do not allow amd_amdgpu_isa directives on non-amdgcn architectures - Do not allow amd_amdgpu_hsa_metadata on non-amdhsa OSes - Do not allow amd_amdgpu_pal_metadata on non-amdpal OSes Differential Revision: https://reviews.llvm.org/D38750 llvm-svn: 315812 --- .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp | 20 ++++++++++++++++++- llvm/test/MC/AMDGPU/elf-notes-verify-amdgcn.s | 7 +++++++ llvm/test/MC/AMDGPU/elf-notes-verify-r600.s | 10 ++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 llvm/test/MC/AMDGPU/elf-notes-verify-amdgcn.s create mode 100644 llvm/test/MC/AMDGPU/elf-notes-verify-r600.s diff --git a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp index 7f8c28e9c243..806aa420c50f 100644 --- a/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp +++ b/llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp @@ -2454,6 +2454,12 @@ bool AMDGPUAsmParser::ParseDirectiveAMDGPUHsaKernel() { } bool AMDGPUAsmParser::ParseDirectiveISAVersion() { + if (getSTI().getTargetTriple().getArch() != Triple::amdgcn) { + return Error(getParser().getTok().getLoc(), + ".amd_amdgpu_isa directive is not available on non-amdgcn " + "architectures"); + } + auto ISAVersionStringFromASM = getLexer().getTok().getStringContents(); std::string ISAVersionStringFromSTI; @@ -2473,6 +2479,12 @@ bool AMDGPUAsmParser::ParseDirectiveISAVersion() { } bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() { + if (getSTI().getTargetTriple().getOS() != Triple::AMDHSA) { + return Error(getParser().getTok().getLoc(), + (Twine(HSAMD::AssemblerDirectiveBegin) + Twine(" directive is " + "not available on non-amdhsa OSes")).str()); + } + std::string HSAMetadataString; raw_string_ostream YamlStream(HSAMetadataString); @@ -2504,7 +2516,7 @@ bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() { if (getLexer().is(AsmToken::Eof) && !FoundEnd) { return TokError(Twine("expected directive ") + - Twine(HSAMD::AssemblerDirectiveEnd) + Twine("not found")); + Twine(HSAMD::AssemblerDirectiveEnd) + Twine(" not found")); } YamlStream.flush(); @@ -2516,6 +2528,12 @@ bool AMDGPUAsmParser::ParseDirectiveHSAMetadata() { } bool AMDGPUAsmParser::ParseDirectivePALMetadata() { + if (getSTI().getTargetTriple().getOS() != Triple::AMDPAL) { + return Error(getParser().getTok().getLoc(), + (Twine(PALMD::AssemblerDirective) + Twine(" directive is " + "not available on non-amdpal OSes")).str()); + } + PALMD::Metadata PALMetadata; for (;;) { uint32_t Value; diff --git a/llvm/test/MC/AMDGPU/elf-notes-verify-amdgcn.s b/llvm/test/MC/AMDGPU/elf-notes-verify-amdgcn.s new file mode 100644 index 000000000000..73157ef953dc --- /dev/null +++ b/llvm/test/MC/AMDGPU/elf-notes-verify-amdgcn.s @@ -0,0 +1,7 @@ +// RUN: not llvm-mc -arch amdgcn %s 2>&1 | FileCheck --check-prefix=GCN %s + +// GCN: error: .amd_amdgpu_hsa_metadata directive is not available on non-amdhsa OSes +.amd_amdgpu_hsa_metadata + +// GCN: error: .amd_amdgpu_pal_metadata directive is not available on non-amdpal OSes +.amd_amdgpu_pal_metadata diff --git a/llvm/test/MC/AMDGPU/elf-notes-verify-r600.s b/llvm/test/MC/AMDGPU/elf-notes-verify-r600.s new file mode 100644 index 000000000000..d6144096bb92 --- /dev/null +++ b/llvm/test/MC/AMDGPU/elf-notes-verify-r600.s @@ -0,0 +1,10 @@ +// RUN: not llvm-mc -arch r600 %s 2>&1 | FileCheck --check-prefix=R600 %s + +// R600: error: .amd_amdgpu_isa directive is not available on non-amdgcn architectures +.amd_amdgpu_isa "r600" + +// R600: error: .amd_amdgpu_hsa_metadata directive is not available on non-amdhsa OSes +.amd_amdgpu_hsa_metadata + +// R600: error: .amd_amdgpu_pal_metadata directive is not available on non-amdpal OSes +.amd_amdgpu_pal_metadata -- 2.34.1