sameerds created this revision. Herald added subscribers: llvm-commits, cfe-commits, kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, wdng, jvesely, kzhuravl, arsenm. Herald added projects: clang, LLVM. sameerds added reviewers: yaxunl, scchan, arsenm, rampitec, dstuttard.
The StrucurizeCFG pass has two known limitations that are addressed by the FixIrreducible pass and the UnifyLoopExits pass. These passes are invoked by the AMDGPU backend, but currently hidden behind a command-line option which is disabled by default. This change enables the workaround when compiling a HIP program. The option can now be specified multiple times. The user can thus override the HIP default using: clang -mllvm --amdgpu-enable-structurizer-workarounds=false The HIP toolchain passes all "-mllvm" options to both opt and llc. But this particular option has no effect on the opt invocation since it is only used by the AMDGPU target during code generation. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D78900 Files: clang/lib/Driver/ToolChains/HIP.cpp clang/test/Driver/hip-structurizer-workarounds.hip llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -195,7 +195,7 @@ static cl::opt<bool> EnableStructurizerWorkarounds( "amdgpu-enable-structurizer-workarounds", cl::desc("Enable workarounds for the StructurizeCFG pass"), cl::init(false), - cl::Hidden); + cl::Hidden, cl::ZeroOrMore); extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() { // Register the target Index: clang/test/Driver/hip-structurizer-workarounds.hip =================================================================== --- /dev/null +++ clang/test/Driver/hip-structurizer-workarounds.hip @@ -0,0 +1,11 @@ +// REQUIRES: clang-driver +// REQUIRES: x86-registered-target +// REQUIRES: amdgpu-registered-target + +// RUN: %clang -### -x hip %s 2>&1 | FileCheck %s -check-prefix=CHECK +// RUN: %clang -### -x hip -mllvm --amdgpu-enable-structurizer-workarounds=false %s 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=MLLVM + +// CHECK: "{{.*llc}}" +// CHECK-SAME: "-mtriple=amdgcn-amd-amdhsa" +// CHECK-SAME: "--amdgpu-enable-structurizer-workarounds" +// MLLVM-SAME: "--amdgpu-enable-structurizer-workarounds=false" Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -155,6 +155,7 @@ LlcArgs.push_back(Args.MakeArgString("-mcpu=" + SubArchName)); LlcArgs.push_back( Args.MakeArgString(Twine("-filetype=") + (OutputIsAsm ? "asm" : "obj"))); + LlcArgs.push_back("--amdgpu-enable-structurizer-workarounds"); // Extract all the -m options std::vector<llvm::StringRef> Features;
Index: llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -195,7 +195,7 @@ static cl::opt<bool> EnableStructurizerWorkarounds( "amdgpu-enable-structurizer-workarounds", cl::desc("Enable workarounds for the StructurizeCFG pass"), cl::init(false), - cl::Hidden); + cl::Hidden, cl::ZeroOrMore); extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAMDGPUTarget() { // Register the target Index: clang/test/Driver/hip-structurizer-workarounds.hip =================================================================== --- /dev/null +++ clang/test/Driver/hip-structurizer-workarounds.hip @@ -0,0 +1,11 @@ +// REQUIRES: clang-driver +// REQUIRES: x86-registered-target +// REQUIRES: amdgpu-registered-target + +// RUN: %clang -### -x hip %s 2>&1 | FileCheck %s -check-prefix=CHECK +// RUN: %clang -### -x hip -mllvm --amdgpu-enable-structurizer-workarounds=false %s 2>&1 | FileCheck %s -check-prefix=CHECK -check-prefix=MLLVM + +// CHECK: "{{.*llc}}" +// CHECK-SAME: "-mtriple=amdgcn-amd-amdhsa" +// CHECK-SAME: "--amdgpu-enable-structurizer-workarounds" +// MLLVM-SAME: "--amdgpu-enable-structurizer-workarounds=false" Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -155,6 +155,7 @@ LlcArgs.push_back(Args.MakeArgString("-mcpu=" + SubArchName)); LlcArgs.push_back( Args.MakeArgString(Twine("-filetype=") + (OutputIsAsm ? "asm" : "obj"))); + LlcArgs.push_back("--amdgpu-enable-structurizer-workarounds"); // Extract all the -m options std::vector<llvm::StringRef> Features;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits