From 9acb533c38be833ec1d8daa06e127a9de8f0a5ef Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Tue, 25 Jun 2024 12:19:28 +0100 Subject: [clang][Driver] Add HIPAMD Driver support for AMDGCN flavoured SPIR-V (#95061) This patch augments the HIPAMD driver to allow it to target AMDGCN flavoured SPIR-V compilation. It's mostly straightforward, as we re-use some of the existing SPIRV infra, however there are a few notable additions: - we introduce an `amdgcnspirv` offload arch, rather than relying on using `generic` (this is already fairly overloaded) or simply using `spirv` or `spirv64` (we'll want to use these to denote unflavoured SPIRV, once we bring up that capability) - initially it is won't be possible to mix-in SPIR-V and concrete AMDGPU targets, as it would require some relatively intrusive surgery in the HIPAMD Toolchain and the Driver to deal with two triples (`spirv64-amd-amdhsa` and `amdgcn-amd-amdhsa`, respectively) - in order to retain user provided compiler flags and have them available at JIT time, we rely on embedding the command line via `-fembed-bitcode=marker`, which the bitcode writer had previously not implemented for SPIRV; we only allow it conditionally for AMDGCN flavoured SPIRV, and it is handled correctly by the Translator (it ends up as a string literal) Once the SPIRV BE is no longer experimental we'll switch to using that rather than the translator. There's some additional work that'll come via a separate PR around correctly piping through AMDGCN's implementation of `printf`, for now we merely handle its flags correctly. --- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'llvm/lib/Bitcode/Writer/BitcodeWriter.cpp') diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index ba16c08..7a228fb 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -5309,6 +5309,8 @@ static const char *getSectionNameForBitcode(const Triple &T) { llvm_unreachable("GOFF is not yet implemented"); break; case Triple::SPIRV: + if (T.getVendor() == Triple::AMD) + return ".llvmbc"; llvm_unreachable("SPIRV is not yet implemented"); break; case Triple::XCOFF: @@ -5334,6 +5336,8 @@ static const char *getSectionNameForCommandline(const Triple &T) { llvm_unreachable("GOFF is not yet implemented"); break; case Triple::SPIRV: + if (T.getVendor() == Triple::AMD) + return ".llvmcmd"; llvm_unreachable("SPIRV is not yet implemented"); break; case Triple::XCOFF: -- cgit v1.1