yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: jansvoboda11, dang.
yaxunl requested review of this revision.

Add option --gpu-inline-threshold for inline threshold for device compilation 
only.


https://reviews.llvm.org/D99233

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-options.hip


Index: clang/test/Driver/hip-options.hip
===================================================================
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -51,3 +51,8 @@
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=CTA %s
 // CTA: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-mconstructor-aliases"
 // CTA-NOT: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} 
"-mconstructor-aliases"
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --offload-arch=gfx906 --gpu-inline-threshold=1000 %s 2>&1 | 
FileCheck -check-prefix=THRESH %s
+// THRESH: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-mllvm" 
"-inline-threshold=1000"
+// THRESH-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} 
"-inline-threshold=1000"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -291,6 +291,13 @@
     CC1Args.push_back("-mlink-builtin-bitcode");
     CC1Args.push_back(DriverArgs.MakeArgString(BCFile));
   });
+
+  StringRef InlineThresh =
+      DriverArgs.getLastArgValue(options::OPT_gpu_inline_threshold_EQ);
+  if (!InlineThresh.empty()) {
+    std::string ArgStr = std::string("-inline-threshold=") + 
InlineThresh.str();
+    CC1Args.append({"-mllvm", DriverArgs.MakeArgStringRef(ArgStr)});
+  }
 }
 
 llvm::opt::DerivedArgList *
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -950,6 +950,9 @@
   HelpText<"Default max threads per block for kernel launch bounds for HIP">,
   MarshallingInfoInt<LangOpts<"GPUMaxThreadsPerBlock">, "1024">,
   ShouldParseIf<hip.KeyPath>;
+def gpu_inline_threshold_EQ : Joined<["--"], "gpu-inline-threshold=">,
+  Flags<[CC1Option]>,
+  HelpText<"Inline threshold for device compilation for HIP">;
 def gpu_instrument_lib_EQ : Joined<["--"], "gpu-instrument-lib=">,
   HelpText<"Instrument device library for HIP, which is a LLVM bitcode 
containing "
   "__cyg_profile_func_enter and __cyg_profile_func_exit">;


Index: clang/test/Driver/hip-options.hip
===================================================================
--- clang/test/Driver/hip-options.hip
+++ clang/test/Driver/hip-options.hip
@@ -51,3 +51,8 @@
 // RUN:   --cuda-gpu-arch=gfx906  %s 2>&1 | FileCheck -check-prefix=CTA %s
 // CTA: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-mconstructor-aliases"
 // CTA-NOT: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-mconstructor-aliases"
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
+// RUN:   --offload-arch=gfx906 --gpu-inline-threshold=1000 %s 2>&1 | FileCheck -check-prefix=THRESH %s
+// THRESH: clang{{.*}} "-triple" "amdgcn-amd-amdhsa" {{.*}} "-mllvm" "-inline-threshold=1000"
+// THRESH-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-inline-threshold=1000"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===================================================================
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -291,6 +291,13 @@
     CC1Args.push_back("-mlink-builtin-bitcode");
     CC1Args.push_back(DriverArgs.MakeArgString(BCFile));
   });
+
+  StringRef InlineThresh =
+      DriverArgs.getLastArgValue(options::OPT_gpu_inline_threshold_EQ);
+  if (!InlineThresh.empty()) {
+    std::string ArgStr = std::string("-inline-threshold=") + InlineThresh.str();
+    CC1Args.append({"-mllvm", DriverArgs.MakeArgStringRef(ArgStr)});
+  }
 }
 
 llvm::opt::DerivedArgList *
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -950,6 +950,9 @@
   HelpText<"Default max threads per block for kernel launch bounds for HIP">,
   MarshallingInfoInt<LangOpts<"GPUMaxThreadsPerBlock">, "1024">,
   ShouldParseIf<hip.KeyPath>;
+def gpu_inline_threshold_EQ : Joined<["--"], "gpu-inline-threshold=">,
+  Flags<[CC1Option]>,
+  HelpText<"Inline threshold for device compilation for HIP">;
 def gpu_instrument_lib_EQ : Joined<["--"], "gpu-instrument-lib=">,
   HelpText<"Instrument device library for HIP, which is a LLVM bitcode containing "
   "__cyg_profile_func_enter and __cyg_profile_func_exit">;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D99233: [HIP] Add o... Yaxun Liu via Phabricator via cfe-commits

Reply via email to