[llvm] r226160 - [PM] Port TargetLibraryInfo to the new pass manager, provided by the

Chandler Carruth chandlerc at gmail.com
Thu Jan 15 03:39:47 PST 2015


Author: chandlerc
Date: Thu Jan 15 05:39:46 2015
New Revision: 226160

URL: http://llvm.org/viewvc/llvm-project?rev=226160&view=rev
Log:
[PM] Port TargetLibraryInfo to the new pass manager, provided by the
TargetLibraryAnalysis pass.

There are actually no direct tests of this already in the tree. I've
added the most basic test that the pass manager bits themselves work,
and the TLI object produced will be tested by an upcoming patches as
they port passes which rely on TLI.

This is starting to point out the awkwardness of the invalidate API --
it seems poorly fitting on the *result* object. I suspect I will change
it to live on the analysis instead, but that's not for this change, and
I'd rather have a few more passes ported in order to have more
experience with how this plays out.

I believe there is only one more analysis required in order to start
porting instcombine. =]

Modified:
    llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h
    llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
    llvm/trunk/test/Other/new-pass-manager.ll
    llvm/trunk/tools/opt/PassRegistry.def
    llvm/trunk/tools/opt/Passes.cpp

Modified: llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h?rev=226160&r1=226159&r2=226160&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/TargetLibraryInfo.h Thu Jan 15 05:39:46 2015
@@ -11,10 +11,14 @@
 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
 
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 
 namespace llvm {
-  class Triple;
+class PreservedAnalyses;
 
   namespace LibFunc {
     enum Func {
@@ -718,7 +722,12 @@ class TargetLibraryInfo {
 public:
   TargetLibraryInfo();
   explicit TargetLibraryInfo(const Triple &T);
-  explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
+
+  // Provide value semantics.
+  TargetLibraryInfo(const TargetLibraryInfo &TLI);
+  TargetLibraryInfo(TargetLibraryInfo &&TLI);
+  TargetLibraryInfo &operator=(const TargetLibraryInfo &TLI);
+  TargetLibraryInfo &operator=(TargetLibraryInfo &&TLI);
 
   /// \brief Searches for a particular function name.
   ///
@@ -799,6 +808,66 @@ public:
   ///
   /// This can be used for options like -fno-builtin.
   void disableAllFunctions();
+
+  /// \brief Handle invalidation from the pass manager.
+  ///
+  /// If we try to invalidate this info, just return false. It cannot become
+  /// invalid even if the module changes.
+  bool invalidate(Module &, const PreservedAnalyses &) { return false; }
+};
+
+/// \brief Analysis pass providing the \c TargetLibraryInfo.
+///
+/// Note that this pass's result cannot be invalidated, it is immutable for the
+/// life of the module.
+class TargetLibraryAnalysis {
+public:
+  typedef TargetLibraryInfo Result;
+
+  /// \brief Opaque, unique identifier for this analysis pass.
+  static void *ID() { return (void *)&PassID; }
+
+  /// \brief Default construct the library analysis.
+  ///
+  /// This will use the module's triple to construct the library info for that
+  /// module.
+  TargetLibraryAnalysis() {}
+
+  /// \brief Construct a library analysis with preset info.
+  ///
+  /// This will directly copy the preset info into the result without
+  /// consulting the module's triple.
+  TargetLibraryAnalysis(TargetLibraryInfo PresetInfo)
+      : PresetInfo(std::move(PresetInfo)) {}
+
+  // Value semantics. We spell out the constructors for MSVC.
+  TargetLibraryAnalysis(const TargetLibraryAnalysis &Arg)
+      : PresetInfo(Arg.PresetInfo) {}
+  TargetLibraryAnalysis(TargetLibraryAnalysis &&Arg)
+      : PresetInfo(std::move(Arg.PresetInfo)) {}
+  TargetLibraryAnalysis &operator=(const TargetLibraryAnalysis &RHS) {
+    PresetInfo = RHS.PresetInfo;
+    return *this;
+  }
+  TargetLibraryAnalysis &operator=(TargetLibraryAnalysis &&RHS) {
+    PresetInfo = std::move(RHS.PresetInfo);
+    return *this;
+  }
+
+  TargetLibraryInfo run(Module &M) {
+    if (PresetInfo)
+      return *PresetInfo;
+
+    return TargetLibraryInfo(Triple(M.getTargetTriple()));
+  }
+
+  /// \brief Provide access to a name for this pass for debugging purposes.
+  static StringRef name() { return "TargetLibraryAnalysis"; }
+
+private:
+  static char PassID;
+
+  Optional<TargetLibraryInfo> PresetInfo;
 };
 
 class TargetLibraryInfoWrapperPass : public ImmutablePass {

Modified: llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp?rev=226160&r1=226159&r2=226160&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/TargetLibraryInfo.cpp Thu Jan 15 05:39:46 2015
@@ -690,9 +690,28 @@ TargetLibraryInfo::TargetLibraryInfo(con
   initialize(*this, T, StandardNames);
 }
 
-TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI) {
+TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
+    : CustomNames(TLI.CustomNames) {
   memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
+}
+
+TargetLibraryInfo::TargetLibraryInfo(TargetLibraryInfo &&TLI)
+    : CustomNames(std::move(TLI.CustomNames)) {
+  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
+            AvailableArray);
+}
+
+TargetLibraryInfo &TargetLibraryInfo::operator=(const TargetLibraryInfo &TLI) {
   CustomNames = TLI.CustomNames;
+  memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
+  return *this;
+}
+
+TargetLibraryInfo &TargetLibraryInfo::operator=(TargetLibraryInfo &&TLI) {
+  CustomNames = std::move(TLI.CustomNames);
+  std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
+            AvailableArray);
+  return *this;
 }
 
 namespace {
@@ -756,6 +775,8 @@ TargetLibraryInfoWrapperPass::TargetLibr
   initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
 }
 
+char TargetLibraryAnalysis::PassID;
+
 // Register the basic pass.
 INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
                 "Target Library Information", false, true)

Modified: llvm/trunk/test/Other/new-pass-manager.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/new-pass-manager.ll?rev=226160&r1=226159&r2=226160&view=diff
==============================================================================
--- llvm/trunk/test/Other/new-pass-manager.ll (original)
+++ llvm/trunk/test/Other/new-pass-manager.ll Thu Jan 15 05:39:46 2015
@@ -266,6 +266,18 @@
 ; CHECK-INVALIDATE-ALL-CG-NOT: Running analysis: NoOpModuleAnalysis
 ; CHECK-INVALIDATE-ALL-CG: Finished pass manager
 
+; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
+; RUN:     -passes='require<targetlibinfo>,invalidate<all>,require<targetlibinfo>' \
+; RUN:     | FileCheck %s --check-prefix=CHECK-TLI
+; CHECK-TLI: Starting pass manager
+; CHECK-TLI: Running pass: RequireAnalysisPass
+; CHECK-TLI: Running analysis: TargetLibraryAnalysis
+; CHECK-TLI: Running pass: InvalidateAllAnalysesPass
+; CHECK-TLI-NOT: Invalidating analysis: TargetLibraryAnalysis
+; CHECK-TLI: Running pass: RequireAnalysisPass
+; CHECK-TLI-NOT: Running analysis: TargetLibraryAnalysis
+; CHECK-TLI: Finished pass manager
+
 define void @foo() {
   ret void
 }

Modified: llvm/trunk/tools/opt/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/PassRegistry.def?rev=226160&r1=226159&r2=226160&view=diff
==============================================================================
--- llvm/trunk/tools/opt/PassRegistry.def (original)
+++ llvm/trunk/tools/opt/PassRegistry.def Thu Jan 15 05:39:46 2015
@@ -21,6 +21,7 @@
 #endif
 MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
 MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis())
+MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
 #undef MODULE_ANALYSIS
 
 #ifndef MODULE_PASS

Modified: llvm/trunk/tools/opt/Passes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/Passes.cpp?rev=226160&r1=226159&r2=226160&view=diff
==============================================================================
--- llvm/trunk/tools/opt/Passes.cpp (original)
+++ llvm/trunk/tools/opt/Passes.cpp Thu Jan 15 05:39:46 2015
@@ -17,6 +17,7 @@
 #include "Passes.h"
 #include "llvm/Analysis/CGSCCPassManager.h"
 #include "llvm/Analysis/LazyCallGraph.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/IR/Dominators.h"
 #include "llvm/IR/IRPrintingPasses.h"
 #include "llvm/IR/PassManager.h"





More information about the llvm-commits mailing list