]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/Analysis/OptimizationDiagnosticInfo.h
Merge ^/head r304537 through r304699.
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / Analysis / OptimizationDiagnosticInfo.h
1 //===- OptimizationDiagnosticInfo.h - Optimization Diagnostic ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Optimization diagnostic interfaces.  It's packaged as an analysis pass so
11 // that by using this service passes become dependent on BFI as well.  BFI is
12 // used to compute the "hotness" of the diagnostic message.
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
16 #define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
17
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Pass.h"
21
22 namespace llvm {
23 class BlockFrequencyInfo;
24 class DebugLoc;
25 class Function;
26 class LLVMContext;
27 class Loop;
28 class Pass;
29 class Twine;
30 class Value;
31
32 class OptimizationRemarkEmitter {
33 public:
34   OptimizationRemarkEmitter(Function *F, BlockFrequencyInfo *BFI)
35       : F(F), BFI(BFI) {}
36
37   OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
38       : F(Arg.F), BFI(Arg.BFI) {}
39
40   OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
41     F = RHS.F;
42     BFI = RHS.BFI;
43     return *this;
44   }
45
46   /// Emit an optimization-missed message.
47   ///
48   /// \p PassName is the name of the pass emitting the message. If
49   /// -Rpass-missed= is given and the name matches the regular expression in
50   /// -Rpass, then the remark will be emitted. \p Fn is the function triggering
51   /// the remark, \p DLoc is the debug location where the diagnostic is
52   /// generated. \p V is the IR Value that identifies the code region. \p Msg is
53   /// the message string to use.
54   void emitOptimizationRemarkMissed(const char *PassName, const DebugLoc &DLoc,
55                                     Value *V, const Twine &Msg);
56
57   /// \brief Same as above but derives the IR Value for the code region and the
58   /// debug location from the Loop parameter \p L.
59   void emitOptimizationRemarkMissed(const char *PassName, Loop *L,
60                                     const Twine &Msg);
61
62 private:
63   Function *F;
64
65   BlockFrequencyInfo *BFI;
66
67   Optional<uint64_t> computeHotness(Value *V);
68
69   OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
70   void operator=(const OptimizationRemarkEmitter &) = delete;
71 };
72
73 class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
74   std::unique_ptr<OptimizationRemarkEmitter> ORE;
75
76 public:
77   OptimizationRemarkEmitterWrapperPass();
78
79   bool runOnFunction(Function &F) override;
80
81   void getAnalysisUsage(AnalysisUsage &AU) const override;
82
83   OptimizationRemarkEmitter &getORE() {
84     assert(ORE && "pass not run yet");
85     return *ORE;
86   }
87
88   static char ID;
89 };
90
91 class OptimizationRemarkEmitterAnalysis
92     : public AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis> {
93   friend AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis>;
94   static char PassID;
95
96 public:
97   /// \brief Provide the result typedef for this analysis pass.
98   typedef OptimizationRemarkEmitter Result;
99
100   /// \brief Run the analysis pass over a function and produce BFI.
101   Result run(Function &F, AnalysisManager<Function> &AM);
102 };
103 }
104 #endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H