[PATCH] D78900: [HIP][AMDGPU] Enable structurizer workarounds

Sameer Sahasrabuddhe via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 27 00:29:29 PDT 2020


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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78900.260226.patch
Type: text/x-patch
Size: 1828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200427/a82eb3c3/attachment.bin>


More information about the llvm-commits mailing list