1 //===- OptimizationDiagnosticInfo.h - Optimization Diagnostic ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
16 #define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/IR/PassManager.h"
20 #include "llvm/Pass.h"
23 class BlockFrequencyInfo;
32 class OptimizationRemarkEmitter {
34 OptimizationRemarkEmitter(Function *F, BlockFrequencyInfo *BFI)
37 OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
38 : F(Arg.F), BFI(Arg.BFI) {}
40 OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
46 /// Emit an optimization-missed message.
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);
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,
65 BlockFrequencyInfo *BFI;
67 Optional<uint64_t> computeHotness(Value *V);
69 OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
70 void operator=(const OptimizationRemarkEmitter &) = delete;
73 class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
74 std::unique_ptr<OptimizationRemarkEmitter> ORE;
77 OptimizationRemarkEmitterWrapperPass();
79 bool runOnFunction(Function &F) override;
81 void getAnalysisUsage(AnalysisUsage &AU) const override;
83 OptimizationRemarkEmitter &getORE() {
84 assert(ORE && "pass not run yet");
91 class OptimizationRemarkEmitterAnalysis
92 : public AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis> {
93 friend AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis>;
97 /// \brief Provide the result typedef for this analysis pass.
98 typedef OptimizationRemarkEmitter Result;
100 /// \brief Run the analysis pass over a function and produce BFI.
101 Result run(Function &F, AnalysisManager<Function> &AM);
104 #endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H