jdoerfert created this revision. jdoerfert added reviewers: JonChesterfield, jhuber6, ye-luo. Herald added subscribers: kerbowa, guansong, bollu, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl. jdoerfert requested review of this revision. Herald added subscribers: cfe-commits, sstefan1, wdng. Herald added a project: clang.
Once we linked in math files, potentially even if we link in only other "system libraries", we want to optimize the code again. This is not only reasonable but also helps to hide various problems with the missing attribute annotations in the math libraries. Repository: rG LLVM Github Monorepo 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