llvm.org GIT mirror llvm / e2ffd02
[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. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226160 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 4 years ago
5 changed file(s) with 107 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1010 #define LLVM_ANALYSIS_TARGETLIBRARYINFO_H
1111
1212 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/IR/Module.h"
16 #include "llvm/IR/Module.h"
1317 #include "llvm/Pass.h"
1418
1519 namespace llvm {
16 class Triple;
20 class PreservedAnalyses;
1721
1822 namespace LibFunc {
1923 enum Func {
717721 public:
718722 TargetLibraryInfo();
719723 explicit TargetLibraryInfo(const Triple &T);
720 explicit TargetLibraryInfo(const TargetLibraryInfo &TLI);
724
725 // Provide value semantics.
726 TargetLibraryInfo(const TargetLibraryInfo &TLI);
727 TargetLibraryInfo(TargetLibraryInfo &&TLI);
728 TargetLibraryInfo &operator=(const TargetLibraryInfo &TLI);
729 TargetLibraryInfo &operator=(TargetLibraryInfo &&TLI);
721730
722731 /// \brief Searches for a particular function name.
723732 ///
798807 ///
799808 /// This can be used for options like -fno-builtin.
800809 void disableAllFunctions();
810
811 /// \brief Handle invalidation from the pass manager.
812 ///
813 /// If we try to invalidate this info, just return false. It cannot become
814 /// invalid even if the module changes.
815 bool invalidate(Module &, const PreservedAnalyses &) { return false; }
816 };
817
818 /// \brief Analysis pass providing the \c TargetLibraryInfo.
819 ///
820 /// Note that this pass's result cannot be invalidated, it is immutable for the
821 /// life of the module.
822 class TargetLibraryAnalysis {
823 public:
824 typedef TargetLibraryInfo Result;
825
826 /// \brief Opaque, unique identifier for this analysis pass.
827 static void *ID() { return (void *)&PassID; }
828
829 /// \brief Default construct the library analysis.
830 ///
831 /// This will use the module's triple to construct the library info for that
832 /// module.
833 TargetLibraryAnalysis() {}
834
835 /// \brief Construct a library analysis with preset info.
836 ///
837 /// This will directly copy the preset info into the result without
838 /// consulting the module's triple.
839 TargetLibraryAnalysis(TargetLibraryInfo PresetInfo)
840 : PresetInfo(std::move(PresetInfo)) {}
841
842 // Value semantics. We spell out the constructors for MSVC.
843 TargetLibraryAnalysis(const TargetLibraryAnalysis &Arg)
844 : PresetInfo(Arg.PresetInfo) {}
845 TargetLibraryAnalysis(TargetLibraryAnalysis &&Arg)
846 : PresetInfo(std::move(Arg.PresetInfo)) {}
847 TargetLibraryAnalysis &operator=(const TargetLibraryAnalysis &RHS) {
848 PresetInfo = RHS.PresetInfo;
849 return *this;
850 }
851 TargetLibraryAnalysis &operator=(TargetLibraryAnalysis &&RHS) {
852 PresetInfo = std::move(RHS.PresetInfo);
853 return *this;
854 }
855
856 TargetLibraryInfo run(Module &M) {
857 if (PresetInfo)
858 return *PresetInfo;
859
860 return TargetLibraryInfo(Triple(M.getTargetTriple()));
861 }
862
863 /// \brief Provide access to a name for this pass for debugging purposes.
864 static StringRef name() { return "TargetLibraryAnalysis"; }
865
866 private:
867 static char PassID;
868
869 Optional PresetInfo;
801870 };
802871
803872 class TargetLibraryInfoWrapperPass : public ImmutablePass {
689689 initialize(*this, T, StandardNames);
690690 }
691691
692 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI) {
692 TargetLibraryInfo::TargetLibraryInfo(const TargetLibraryInfo &TLI)
693 : CustomNames(TLI.CustomNames) {
693694 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
695 }
696
697 TargetLibraryInfo::TargetLibraryInfo(TargetLibraryInfo &&TLI)
698 : CustomNames(std::move(TLI.CustomNames)) {
699 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
700 AvailableArray);
701 }
702
703 TargetLibraryInfo &TargetLibraryInfo::operator=(const TargetLibraryInfo &TLI) {
694704 CustomNames = TLI.CustomNames;
705 memcpy(AvailableArray, TLI.AvailableArray, sizeof(AvailableArray));
706 return *this;
707 }
708
709 TargetLibraryInfo &TargetLibraryInfo::operator=(TargetLibraryInfo &&TLI) {
710 CustomNames = std::move(TLI.CustomNames);
711 std::move(std::begin(TLI.AvailableArray), std::end(TLI.AvailableArray),
712 AvailableArray);
713 return *this;
695714 }
696715
697716 namespace {
755774 initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry());
756775 }
757776
777 char TargetLibraryAnalysis::PassID;
778
758779 // Register the basic pass.
759780 INITIALIZE_PASS(TargetLibraryInfoWrapperPass, "targetlibinfo",
760781 "Target Library Information", false, true)
265265 ; CHECK-INVALIDATE-ALL-CG-NOT: Running analysis: NoOpModuleAnalysis
266266 ; CHECK-INVALIDATE-ALL-CG: Finished pass manager
267267
268 ; RUN: opt -disable-output -disable-verify -debug-pass-manager %s 2>&1 \
269 ; RUN: -passes='require,invalidate,require' \
270 ; RUN: | FileCheck %s --check-prefix=CHECK-TLI
271 ; CHECK-TLI: Starting pass manager
272 ; CHECK-TLI: Running pass: RequireAnalysisPass
273 ; CHECK-TLI: Running analysis: TargetLibraryAnalysis
274 ; CHECK-TLI: Running pass: InvalidateAllAnalysesPass
275 ; CHECK-TLI-NOT: Invalidating analysis: TargetLibraryAnalysis
276 ; CHECK-TLI: Running pass: RequireAnalysisPass
277 ; CHECK-TLI-NOT: Running analysis: TargetLibraryAnalysis
278 ; CHECK-TLI: Finished pass manager
279
268280 define void @foo() {
269281 ret void
270282 }
2020 #endif
2121 MODULE_ANALYSIS("lcg", LazyCallGraphAnalysis())
2222 MODULE_ANALYSIS("no-op-module", NoOpModuleAnalysis())
23 MODULE_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
2324 #undef MODULE_ANALYSIS
2425
2526 #ifndef MODULE_PASS
1616 #include "Passes.h"
1717 #include "llvm/Analysis/CGSCCPassManager.h"
1818 #include "llvm/Analysis/LazyCallGraph.h"
19 #include "llvm/Analysis/TargetLibraryInfo.h"
1920 #include "llvm/IR/Dominators.h"
2021 #include "llvm/IR/IRPrintingPasses.h"
2122 #include "llvm/IR/PassManager.h"