[llvm] 44b1643 - [NewPM] Support -disable-simplify-libcall/-disable-builtin in NPM opt

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 16:38:46 PDT 2020


Author: Arthur Eubanks
Date: 2020-09-21T16:38:37-07:00
New Revision: 44b1643d17753fb2f35ef1d42420a4578bb8d55d

URL: https://github.com/llvm/llvm-project/commit/44b1643d17753fb2f35ef1d42420a4578bb8d55d
DIFF: https://github.com/llvm/llvm-project/commit/44b1643d17753fb2f35ef1d42420a4578bb8d55d.diff

LOG: [NewPM] Support -disable-simplify-libcall/-disable-builtin in NPM opt

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D87932

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/disable-simplify-libcalls.ll
    llvm/tools/opt/NewPMDriver.cpp
    llvm/tools/opt/NewPMDriver.h
    llvm/tools/opt/opt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/disable-simplify-libcalls.ll b/llvm/test/Transforms/InstCombine/disable-simplify-libcalls.ll
index e25ce31cbfbf..04b80ac54186 100644
--- a/llvm/test/Transforms/InstCombine/disable-simplify-libcalls.ll
+++ b/llvm/test/Transforms/InstCombine/disable-simplify-libcalls.ll
@@ -1,6 +1,7 @@
 ; Test that -disable-simplify-libcalls is wired up correctly.
 ;
 ; RUN: opt < %s -instcombine -disable-simplify-libcalls -S | FileCheck %s
+; RUN: opt < %s -passes=instcombine -disable-simplify-libcalls -S | FileCheck %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 

diff  --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index b38f67ac4519..c6c4191c1459 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -18,6 +18,7 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/CGSCCPassManager.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/Bitcode/BitcodeWriterPass.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/IR/Dominators.h"
@@ -213,7 +214,8 @@ static void registerEPCallbacks(PassBuilder &PB, bool VerifyEachPass,
 #include "llvm/Support/Extension.def"
 
 bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
-                           ToolOutputFile *Out, ToolOutputFile *ThinLTOLinkOut,
+                           TargetLibraryInfoImpl *TLII, ToolOutputFile *Out,
+                           ToolOutputFile *ThinLTOLinkOut,
                            ToolOutputFile *OptRemarkFile,
                            StringRef PassPipeline, ArrayRef<StringRef> Passes,
                            OutputKind OK, VerifierKind VK,
@@ -363,6 +365,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
 
   // Register the AA manager first so that our version is the one used.
   FAM.registerPass([&] { return std::move(AA); });
+  // Register our TargetLibraryInfoImpl.
+  FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
 
   // Register all the basic analyses with the managers.
   PB.registerModuleAnalyses(MAM);

diff  --git a/llvm/tools/opt/NewPMDriver.h b/llvm/tools/opt/NewPMDriver.h
index 7ae273a2c1f4..3cb47235660e 100644
--- a/llvm/tools/opt/NewPMDriver.h
+++ b/llvm/tools/opt/NewPMDriver.h
@@ -27,6 +27,7 @@ class StringRef;
 class Module;
 class TargetMachine;
 class ToolOutputFile;
+class TargetLibraryInfoImpl;
 
 namespace opt_tool {
 enum OutputKind {
@@ -59,10 +60,10 @@ enum CSPGOKind { NoCSPGO, CSInstrGen, CSInstrUse };
 /// ThinLTOLinkOut is only used when OK is OK_OutputThinLTOBitcode, and can be
 /// nullptr.
 bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
-                     ToolOutputFile *Out, ToolOutputFile *ThinLinkOut,
-                     ToolOutputFile *OptRemarkFile, StringRef PassPipeline,
-                     ArrayRef<StringRef> PassInfos, opt_tool::OutputKind OK,
-                     opt_tool::VerifierKind VK,
+                     TargetLibraryInfoImpl *TLII, ToolOutputFile *Out,
+                     ToolOutputFile *ThinLinkOut, ToolOutputFile *OptRemarkFile,
+                     StringRef PassPipeline, ArrayRef<StringRef> PassInfos,
+                     opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
                      bool ShouldPreserveAssemblyUseListOrder,
                      bool ShouldPreserveBitcodeUseListOrder,
                      bool EmitSummaryIndex, bool EmitModuleHash,

diff  --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index 3b20d12bafcf..f269437c5f9d 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -727,6 +727,25 @@ int main(int argc, char **argv) {
   if (OutputThinLTOBC)
     M->addModuleFlag(Module::Error, "EnableSplitLTOUnit", SplitLTOUnit);
 
+  // Add an appropriate TargetLibraryInfo pass for the module's triple.
+  TargetLibraryInfoImpl TLII(ModuleTriple);
+
+  // The -disable-simplify-libcalls flag actually disables all builtin optzns.
+  if (DisableSimplifyLibCalls)
+    TLII.disableAllFunctions();
+  else {
+    // Disable individual builtin functions in TargetLibraryInfo.
+    LibFunc F;
+    for (auto &FuncName : DisableBuiltins)
+      if (TLII.getLibFunc(FuncName, F))
+        TLII.setUnavailable(F);
+      else {
+        errs() << argv[0] << ": cannot disable nonexistent builtin function "
+               << FuncName << '\n';
+        return 1;
+      }
+  }
+
   // If `-passes=` is specified, use NPM.
   // If `-enable-new-pm` is specified and there are no codegen passes, use NPM.
   // e.g. `-enable-new-pm -sroa` will use NPM.
@@ -769,9 +788,9 @@ int main(int argc, char **argv) {
     // The user has asked to use the new pass manager and provided a pipeline
     // string. Hand off the rest of the functionality to the new code for that
     // layer.
-    return runPassPipeline(argv[0], *M, TM.get(), Out.get(), ThinLinkOut.get(),
-                           RemarksFile.get(), PassPipeline, Passes, OK, VK,
-                           PreserveAssemblyUseListOrder,
+    return runPassPipeline(argv[0], *M, TM.get(), &TLII, Out.get(),
+                           ThinLinkOut.get(), RemarksFile.get(), PassPipeline,
+                           Passes, OK, VK, PreserveAssemblyUseListOrder,
                            PreserveBitcodeUseListOrder, EmitSummaryIndex,
                            EmitModuleHash, EnableDebugify, Coroutines)
                ? 0
@@ -787,25 +806,6 @@ int main(int argc, char **argv) {
 
   bool AddOneTimeDebugifyPasses = EnableDebugify && !DebugifyEach;
 
-  // Add an appropriate TargetLibraryInfo pass for the module's triple.
-  TargetLibraryInfoImpl TLII(ModuleTriple);
-
-  // The -disable-simplify-libcalls flag actually disables all builtin optzns.
-  if (DisableSimplifyLibCalls)
-    TLII.disableAllFunctions();
-  else {
-    // Disable individual builtin functions in TargetLibraryInfo.
-    LibFunc F;
-    for (auto &FuncName : DisableBuiltins)
-      if (TLII.getLibFunc(FuncName, F))
-        TLII.setUnavailable(F);
-      else {
-        errs() << argv[0] << ": cannot disable nonexistent builtin function "
-               << FuncName << '\n';
-        return 1;
-      }
-  }
-
   Passes.add(new TargetLibraryInfoWrapperPass(TLII));
 
   // Add internal analysis passes from the target machine.


        


More information about the llvm-commits mailing list