llvm.org GIT mirror llvm / a9da9cb
Introduce RegionInfoAnalysis, which compute Region Tree in the new PassManager. NFC Differential Revision: http://reviews.llvm.org/D17571 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261884 91177308-0d34-0410-b5e6-96231b3b80d8 Hongbin Zheng 4 years ago
22 changed file(s) with 149 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
4646
4747 namespace llvm {
4848
49 // FIXME: Replace this brittle forward declaration with the include of the new
50 // PassManager.h when doing so doesn't break the PassManagerBuilder.
51 template class AnalysisManager;
52 class PreservedAnalyses;
53
4954 // Class to be specialized for different users of RegionInfo
5055 // (i.e. BasicBlocks or MachineBasicBlocks). This is only to avoid needing to
5156 // pass around an unreasonable number of template parameters.
675680 RegionInfoBase(const RegionInfoBase &) = delete;
676681 const RegionInfoBase &operator=(const RegionInfoBase &) = delete;
677682
683 RegionInfoBase(RegionInfoBase &&Arg)
684 : DT(std::move(Arg.DT)), PDT(std::move(Arg.PDT)), DF(std::move(Arg.DF)),
685 TopLevelRegion(std::move(Arg.TopLevelRegion)),
686 BBtoRegion(std::move(Arg.BBtoRegion)) {
687 Arg.wipe();
688 }
689 RegionInfoBase &operator=(RegionInfoBase &&RHS) {
690 DT = std::move(RHS.DT);
691 PDT = std::move(RHS.PDT);
692 DF = std::move(RHS.DF);
693 TopLevelRegion = std::move(RHS.TopLevelRegion);
694 BBtoRegion = std::move(RHS.BBtoRegion);
695 RHS.wipe();
696 return *this;
697 }
698
678699 DomTreeT *DT;
679700 PostDomTreeT *PDT;
680701 DomFrontierT *DF;
685706 private:
686707 /// Map every BB to the smallest region, that contains BB.
687708 BBtoRegionMap BBtoRegion;
709
710 /// \brief Wipe this region tree's state without releasing any resources.
711 ///
712 /// This is essentially a post-move helper only. It leaves the object in an
713 /// assignable and destroyable state, but otherwise invalid.
714 void wipe() {
715 DT = nullptr;
716 PDT = nullptr;
717 DF = nullptr;
718 TopLevelRegion = nullptr;
719 BBtoRegion.clear();
720 }
688721
689722 // Check whether the entries of BBtoRegion for the BBs of region
690723 // SR are correct. Triggers an assertion if not. Calls itself recursively for
835868
836869 class RegionInfo : public RegionInfoBase> {
837870 public:
871 typedef RegionInfoBase> Base;
872
838873 explicit RegionInfo();
839874
840875 ~RegionInfo() override;
876
877 RegionInfo(RegionInfo &&Arg)
878 : Base(std::move(static_cast(Arg))) {}
879 RegionInfo &operator=(RegionInfo &&RHS) {
880 Base::operator=(std::move(static_cast(RHS)));
881 return *this;
882 }
841883
842884 // updateStatistics - Update statistic about created regions.
843885 void updateStatistics(Region *R) final;
883925 //@}
884926 };
885927
928 /// \brief Analysis pass that exposes the \c RegionInfo for a function.
929 class RegionInfoAnalysis {
930 static char PassID;
931
932 public:
933 typedef RegionInfo Result;
934
935 /// \brief Opaque, unique identifier for this analysis pass.
936 static void *ID() { return (void *)&PassID; }
937
938 /// \brief Provide a name for the analysis for debugging and logging.
939 static StringRef name() { return "RegionInfoAnalysis"; }
940
941 RegionInfo run(Function &F, AnalysisManager *AM);
942 };
943
944 /// \brief Printer pass for the \c RegionInfo.
945 class RegionInfoPrinterPass {
946 raw_ostream &OS;
947
948 public:
949 explicit RegionInfoPrinterPass(raw_ostream &OS);
950 PreservedAnalyses run(Function &F, AnalysisManager *AM);
951
952 static StringRef name() { return "RegionInfoPrinterPass"; }
953 };
954
955 /// \brief Verifier pass for the \c RegionInfo.
956 struct RegionInfoVerifierPass {
957 PreservedAnalyses run(Function &F, AnalysisManager *AM);
958
959 static StringRef name() { return "RegionInfoVerifierPass"; }
960 };
961
886962 template <>
887963 template <>
888964 inline BasicBlock *
1414 #include "llvm/Analysis/LoopInfo.h"
1515 #include "llvm/Analysis/RegionInfoImpl.h"
1616 #include "llvm/Analysis/RegionIterator.h"
17 #include "llvm/IR/PassManager.h"
1718 #include "llvm/Support/CommandLine.h"
1819 #include "llvm/Support/Debug.h"
1920 #include "llvm/Support/ErrorHandling.h"
179180 }
180181 }
181182
183 //===----------------------------------------------------------------------===//
184 // RegionInfoAnalysis implementation
185 //
186
187 char RegionInfoAnalysis::PassID;
188
189 RegionInfo RegionInfoAnalysis::run(Function &F, AnalysisManager *AM) {
190 RegionInfo RI;
191 auto *DT = &AM->getResult(F);
192 auto *PDT = &AM->getResult(F);
193 auto *DF = &AM->getResult(F);
194
195 RI.recalculate(F, DT, PDT, DF);
196 return RI;
197 }
198
199 RegionInfoPrinterPass::RegionInfoPrinterPass(raw_ostream &OS)
200 : OS(OS) {}
201
202 PreservedAnalyses
203 RegionInfoPrinterPass::run(Function &F, FunctionAnalysisManager *AM) {
204 OS << "Region Tree for function: " << F.getName() << "\n";
205 AM->getResult(F).print(OS);
206
207 return PreservedAnalyses::all();
208 }
209
210 PreservedAnalyses RegionInfoVerifierPass::run(Function &F,
211 AnalysisManager *AM) {
212 AM->getResult(F).verifyAnalysis();
213
214 return PreservedAnalyses::all();
215 }
2525 #include "llvm/Analysis/LazyCallGraph.h"
2626 #include "llvm/Analysis/LoopInfo.h"
2727 #include "llvm/Analysis/PostDominators.h"
28 #include "llvm/Analysis/RegionInfo.h"
2829 #include "llvm/Analysis/ScalarEvolution.h"
2930 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
3031 #include "llvm/Analysis/ScopedNoAliasAA.h"
5959 FUNCTION_ANALYSIS("postdomtree", PostDominatorTreeAnalysis())
6060 FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis())
6161 FUNCTION_ANALYSIS("loops", LoopAnalysis())
62 FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
6263 FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
6364 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
6465 FUNCTION_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
9394 FUNCTION_PASS("print", PostDominatorTreePrinterPass(dbgs()))
9495 FUNCTION_PASS("print", DominanceFrontierPrinterPass(dbgs()))
9596 FUNCTION_PASS("print", LoopPrinterPass(dbgs()))
97 FUNCTION_PASS("print", RegionInfoPrinterPass(dbgs()))
9698 FUNCTION_PASS("print", ScalarEvolutionPrinterPass(dbgs()))
9799 FUNCTION_PASS("simplify-cfg", SimplifyCFGPass())
98100 FUNCTION_PASS("sroa", SROA())
99101 FUNCTION_PASS("verify", VerifierPass())
100102 FUNCTION_PASS("verify", DominatorTreeVerifierPass())
103 FUNCTION_PASS("verify", RegionInfoVerifierPass())
101104 #undef FUNCTION_PASS
102105
103106 #ifndef LOOP_ANALYSIS
0 ; RUN: opt -regions < %s
1 ; RUN: opt < %s -passes='print'
2
13 define i32 @main() nounwind {
24 entry:
35 br label %for.cond
22 ; RUN: opt -regions -stats -analyze < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @BZ2_blockSort() nounwind {
79 start:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @normal_condition() nounwind {
79 5:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define internal fastcc zeroext i8 @handle_compress() nounwind {
79 end165:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define internal fastcc void @compress() nounwind {
79 end33:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @normal_condition() nounwind {
79 0:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @normal_condition() nounwind {
79 0:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @normal_condition() nounwind {
79 0:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define internal fastcc zeroext i8 @handle_compress() nounwind {
79 entry:
33
44 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
55 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
6
7 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
68
79 define void @normal_condition() nounwind {
810 0:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define internal fastcc zeroext i8 @loops_1() nounwind {
79 entry:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @meread_() nounwind {
79 entry:
33
44 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
55 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
6
7 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
68
79 define void @a_linear_impl_fig_1() nounwind {
810 0:
33
44 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
55 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
6
7 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
68
79 define internal fastcc zeroext i8 @handle_compress() nounwind {
810 entry:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @MAIN__() nounwind {
79 entry:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define void @a_linear_impl_fig_1() nounwind {
79 0:
22 ; RUN: opt -regions -stats < %s 2>&1 | FileCheck -check-prefix=STAT %s
33 ; RUN: opt -regions -print-region-style=bb -analyze < %s 2>&1 | FileCheck -check-prefix=BBIT %s
44 ; RUN: opt -regions -print-region-style=rn -analyze < %s 2>&1 | FileCheck -check-prefix=RNIT %s
5
6 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
57
68 define internal fastcc zeroext i8 @handle_compress() nounwind {
79 entry:
0 ; RUN: opt -regions -analyze < %s | FileCheck %s
1 ; RUN: opt < %s -passes='print' 2>&1 | FileCheck %s
12
23 ; We should not crash if there are some bbs that are not reachable.
34 define void @f() {