This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG6f2ee1ca5e39: [OpenMP][AMDGPU] Optimize the linked in math 
libraries (authored by jdoerfert).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116906/new/

https://reviews.llvm.org/D116906

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp


Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -16,6 +16,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/Tool.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -95,9 +96,9 @@
     if (II.isFilename())
       CmdArgs.push_back(II.getFilename());
 
+  bool HasLibm = false;
   if (Args.hasArg(options::OPT_l)) {
     auto Lm = Args.getAllArgValues(options::OPT_l);
-    bool HasLibm = false;
     for (auto &Lib : Lm) {
       if (Lib == "m") {
         HasLibm = true;
@@ -143,6 +144,26 @@
   C.addCommand(std::make_unique<Command>(
       JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs,
       InputInfo(&JA, Args.MakeArgString(OutputFileName))));
+
+  // If we linked in libm definitions late we run another round of 
optimizations
+  // to inline the definitions and fold what is foldable.
+  if (HasLibm) {
+    ArgStringList OptCmdArgs;
+    const char *OptOutputFileName =
+        getOutputFileName(C, OutputFilePrefix, "-linked-opt", "bc");
+    addLLCOptArg(Args, OptCmdArgs);
+    OptCmdArgs.push_back(OutputFileName);
+    OptCmdArgs.push_back("-o");
+    OptCmdArgs.push_back(OptOutputFileName);
+    const char *OptExec =
+        Args.MakeArgString(getToolChain().GetProgramPath("opt"));
+    C.addCommand(std::make_unique<Command>(
+        JA, *this, ResponseFileSupport::AtFileCurCP(), OptExec, OptCmdArgs,
+        InputInfo(&JA, Args.MakeArgString(OutputFileName)),
+        InputInfo(&JA, Args.MakeArgString(OptOutputFileName))));
+    OutputFileName = OptOutputFileName;
+  }
+
   return OutputFileName;
 }
 


Index: clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -16,6 +16,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/InputInfo.h"
 #include "clang/Driver/Options.h"
+#include "clang/Driver/Tool.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/FormatAdapters.h"
@@ -95,9 +96,9 @@
     if (II.isFilename())
       CmdArgs.push_back(II.getFilename());
 
+  bool HasLibm = false;
   if (Args.hasArg(options::OPT_l)) {
     auto Lm = Args.getAllArgValues(options::OPT_l);
-    bool HasLibm = false;
     for (auto &Lib : Lm) {
       if (Lib == "m") {
         HasLibm = true;
@@ -143,6 +144,26 @@
   C.addCommand(std::make_unique<Command>(
       JA, *this, ResponseFileSupport::AtFileCurCP(), Exec, CmdArgs, Inputs,
       InputInfo(&JA, Args.MakeArgString(OutputFileName))));
+
+  // If we linked in libm definitions late we run another round of optimizations
+  // to inline the definitions and fold what is foldable.
+  if (HasLibm) {
+    ArgStringList OptCmdArgs;
+    const char *OptOutputFileName =
+        getOutputFileName(C, OutputFilePrefix, "-linked-opt", "bc");
+    addLLCOptArg(Args, OptCmdArgs);
+    OptCmdArgs.push_back(OutputFileName);
+    OptCmdArgs.push_back("-o");
+    OptCmdArgs.push_back(OptOutputFileName);
+    const char *OptExec =
+        Args.MakeArgString(getToolChain().GetProgramPath("opt"));
+    C.addCommand(std::make_unique<Command>(
+        JA, *this, ResponseFileSupport::AtFileCurCP(), OptExec, OptCmdArgs,
+        InputInfo(&JA, Args.MakeArgString(OutputFileName)),
+        InputInfo(&JA, Args.MakeArgString(OptOutputFileName))));
+    OutputFileName = OptOutputFileName;
+  }
+
   return OutputFileName;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to