llvm.org GIT mirror llvm / c7b8b5e
[OptRemarkEmitter] Port to new PM Summary: The main goal is to able to start using the new OptRemarkEmitter analysis from the LoopVectorizer. Since the vectorizer was recently converted to the new PM, it makes sense to convert this analysis as well. This pass is currently tested through the LoopDistribution pass, so I am also porting LoopDistribution to get coverage for this analysis with the new PM. Reviewers: davidxl, silvas Subscribers: llvm-commits, mzolotukhin Differential Revision: https://reviews.llvm.org/D22436 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275810 91177308-0d34-0410-b5e6-96231b3b80d8 Adam Nemet 4 years ago
7 changed file(s) with 84 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
1515 #define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
1616
1717 #include "llvm/ADT/Optional.h"
18 #include "llvm/IR/PassManager.h"
1819 #include "llvm/Pass.h"
1920
2021 namespace llvm {
2728 class Twine;
2829 class Value;
2930
30 class OptimizationRemarkEmitter : public FunctionPass {
31 class OptimizationRemarkEmitter {
3132 public:
32 OptimizationRemarkEmitter();
33 OptimizationRemarkEmitter(Function *F, BlockFrequencyInfo *BFI)
34 : F(F), BFI(BFI) {}
35
36 OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
37 : F(Arg.F), BFI(Arg.BFI) {}
38
39 OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
40 F = RHS.F;
41 BFI = RHS.BFI;
42 return *this;
43 }
3344
3445 /// Emit an optimization-missed message.
3546 ///
4758 void emitOptimizationRemarkMissed(const char *PassName, Loop *L,
4859 const Twine &Msg);
4960
50 bool runOnFunction(Function &F) override;
51
52 void getAnalysisUsage(AnalysisUsage &AU) const override;
53
54 static char ID;
55
5661 private:
5762 Function *F;
5863
5964 BlockFrequencyInfo *BFI;
6065
6166 Optional computeHotness(Value *V);
67
68 OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
69 void operator=(const OptimizationRemarkEmitter &) = delete;
70 };
71
72 class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
73 std::unique_ptr ORE;
74
75 public:
76 OptimizationRemarkEmitterWrapperPass();
77
78 bool runOnFunction(Function &F) override;
79
80 void getAnalysisUsage(AnalysisUsage &AU) const override;
81
82 OptimizationRemarkEmitter &getORE() {
83 assert(ORE && "pass not run yet");
84 return *ORE;
85 }
86
87 static char ID;
88 };
89
90 class OptimizationRemarkEmitterAnalysis
91 : public AnalysisInfoMixin {
92 friend AnalysisInfoMixin;
93 static char PassID;
94
95 public:
96 /// \brief Provide the result typedef for this analysis pass.
97 typedef OptimizationRemarkEmitter Result;
98
99 /// \brief Run the analysis pass over a function and produce BFI.
100 Result run(Function &F, AnalysisManager &AM);
62101 };
63102 }
64
65103 #endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
242242 void initializeObjCARCContractPass(PassRegistry&);
243243 void initializeObjCARCExpandPass(PassRegistry&);
244244 void initializeObjCARCOptPass(PassRegistry&);
245 void initializeOptimizationRemarkEmitterPass(PassRegistry&);
245 void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry&);
246246 void initializeOptimizePHIsPass(PassRegistry&);
247247 void initializePAEvalPass(PassRegistry &);
248248 void initializePEIPass(PassRegistry&);
6363 initializeModuleDebugInfoPrinterPass(Registry);
6464 initializeModuleSummaryIndexWrapperPassPass(Registry);
6565 initializeObjCARCAAWrapperPassPass(Registry);
66 initializeOptimizationRemarkEmitterPass(Registry);
66 initializeOptimizationRemarkEmitterWrapperPassPass(Registry);
6767 initializePostDominatorTreeWrapperPassPass(Registry);
6868 initializeRegionInfoPassPass(Registry);
6969 initializeRegionViewerPass(Registry);
1919
2020 using namespace llvm;
2121
22 OptimizationRemarkEmitter::OptimizationRemarkEmitter() : FunctionPass(ID) {
23 initializeOptimizationRemarkEmitterPass(*PassRegistry::getPassRegistry());
24 }
25
2622 Optional OptimizationRemarkEmitter::computeHotness(Value *V) {
2723 if (!BFI)
2824 return None;
4238 emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg);
4339 }
4440
45 bool OptimizationRemarkEmitter::runOnFunction(Function &Fn) {
46 F = &Fn;
41 OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
42 : FunctionPass(ID) {
43 initializeOptimizationRemarkEmitterWrapperPassPass(
44 *PassRegistry::getPassRegistry());
45 }
46
47 bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
48 BlockFrequencyInfo *BFI;
4749
4850 if (Fn.getContext().getDiagnosticHotnessRequested())
4951 BFI = &getAnalysis().getBFI();
5052 else
5153 BFI = nullptr;
5254
55 ORE = llvm::make_unique(&Fn, BFI);
5356 return false;
5457 }
5558
56 void OptimizationRemarkEmitter::getAnalysisUsage(AnalysisUsage &AU) const {
59 void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
60 AnalysisUsage &AU) const {
5761 LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
5862 AU.setPreservesAll();
5963 }
6064
61 char OptimizationRemarkEmitter::ID = 0;
65 char OptimizationRemarkEmitterAnalysis::PassID;
66
67 OptimizationRemarkEmitter
68 OptimizationRemarkEmitterAnalysis::run(Function &F, AnalysisManager &AM) {
69 BlockFrequencyInfo *BFI;
70
71 if (F.getContext().getDiagnosticHotnessRequested())
72 BFI = &AM.getResult(F);
73 else
74 BFI = nullptr;
75
76 return OptimizationRemarkEmitter(&F, BFI);
77 }
78
79 char OptimizationRemarkEmitterWrapperPass::ID = 0;
6280 static const char ore_name[] = "Optimization Remark Emitter";
6381 #define ORE_NAME "opt-remark-emitter"
6482
65 INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitter, ORE_NAME, ore_name, false,
66 true)
83 INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
84 false, true)
6785 INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
68 INITIALIZE_PASS_END(OptimizationRemarkEmitter, ORE_NAME, ore_name, false, true)
86 INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
87 false, true)
3737 #include "llvm/Analysis/LoopAccessAnalysis.h"
3838 #include "llvm/Analysis/LoopInfo.h"
3939 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
40 #include "llvm/Analysis/OptimizationDiagnosticInfo.h"
4041 #include "llvm/Analysis/PostDominators.h"
4142 #include "llvm/Analysis/ProfileSummaryInfo.h"
4243 #include "llvm/Analysis/RegionInfo.h"
100100 FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis())
101101 FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
102102 FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
103 FUNCTION_ANALYSIS("opt-remark-emit", OptimizationRemarkEmitterAnalysis())
103104 FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
104105 FUNCTION_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
105106 FUNCTION_ANALYSIS("targetir",
882882 auto *LAA = &getAnalysis();
883883 auto *DT = &getAnalysis().getDomTree();
884884 auto *SE = &getAnalysis().getSE();
885 auto *ORE = &getAnalysis>();
885 auto *ORE = &getAnalysisWrapperPass>().getORE();
886886
887887 // Build up a worklist of inner-loops to vectorize. This is necessary as the
888888 // act of distributing a loop creates new loops and can invalidate iterators
917917 AU.addRequired();
918918 AU.addRequired();
919919 AU.addPreserved();
920 AU.addRequired>();
920 AU.addRequiredWrapperPass>();
921921 }
922922
923923 static char ID;
937937 INITIALIZE_PASS_DEPENDENCY(LoopAccessLegacyAnalysis)
938938 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
939939 INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
940 INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitter)
940 INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
941941 INITIALIZE_PASS_END(LoopDistribute, LDIST_NAME, ldist_name, false, false)
942942
943943 namespace llvm {