[PATCH] D109014: [OpenMP] Add an option to always inline OpenMP device functions.

Joseph Huber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 31 12:04:47 PDT 2021


jhuber6 created this revision.
jhuber6 added a reviewer: jdoerfert.
Herald added subscribers: ormris, guansong, hiraditya, yaxunl.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

Performance on GPU targets can be highly variable, sometimes inlining
everything hurts performance and sometimes it greatly improves it. Add
an option to toggle this behaviour to better investigate it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109014

Files:
  llvm/lib/Transforms/IPO/OpenMPOpt.cpp


Index: llvm/lib/Transforms/IPO/OpenMPOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -97,6 +97,11 @@
     cl::desc("Print the current module after OpenMP optimizations."),
     cl::Hidden, cl::init(false));
 
+static cl::opt<bool> AlwaysInlineDeviceFunctions(
+    "openmp-opt-inline-device", cl::ZeroOrMore,
+    cl::desc("Inline all applicible functions on the device."),
+    cl::Hidden, cl::init(false));
+
 STATISTIC(NumOpenMPRuntimeCallsDeduplicated,
           "Number of OpenMP runtime calls deduplicated");
 STATISTIC(NumOpenMPParallelRegionsDeleted,
@@ -4481,6 +4486,13 @@
   OpenMPOpt OMPOpt(SCC, CGUpdater, OREGetter, InfoCache, A);
   bool Changed = OMPOpt.run(true);
 
+  // Optionally inline device functions for potentially better performance.
+  if (AlwaysInlineDeviceFunctions)
+    if (isOpenMPDevice(M))
+      for (Function &F : M)
+        if (!F.isDeclaration() && !F.hasFnAttribute(Attribute::NoInline))
+          F.addFnAttr(Attribute::AlwaysInline);
+
   if (PrintModuleAfterOptimizations)
     LLVM_DEBUG(dbgs() << TAG << "Module after OpenMPOpt Module Pass:\n" << M);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109014.369760.patch
Type: text/x-patch
Size: 1214 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210831/5ab1c7b0/attachment.bin>


More information about the llvm-commits mailing list