#define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
#include "llvm/ADT/Optional.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
namespace llvm {
class Twine;
class Value;
-class OptimizationRemarkEmitter : public FunctionPass {
+class OptimizationRemarkEmitter {
public:
- OptimizationRemarkEmitter();
+ OptimizationRemarkEmitter(Function *F, BlockFrequencyInfo *BFI)
+ : F(F), BFI(BFI) {}
+
+ OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg)
+ : F(Arg.F), BFI(Arg.BFI) {}
+
+ OptimizationRemarkEmitter &operator=(OptimizationRemarkEmitter &&RHS) {
+ F = RHS.F;
+ BFI = RHS.BFI;
+ return *this;
+ }
/// Emit an optimization-missed message.
///
void emitOptimizationRemarkMissed(const char *PassName, Loop *L,
const Twine &Msg);
+private:
+ Function *F;
+
+ BlockFrequencyInfo *BFI;
+
+ Optional<uint64_t> computeHotness(Value *V);
+
+ OptimizationRemarkEmitter(const OptimizationRemarkEmitter &) = delete;
+ void operator=(const OptimizationRemarkEmitter &) = delete;
+};
+
+class OptimizationRemarkEmitterWrapperPass : public FunctionPass {
+ std::unique_ptr<OptimizationRemarkEmitter> ORE;
+
+public:
+ OptimizationRemarkEmitterWrapperPass();
+
bool runOnFunction(Function &F) override;
void getAnalysisUsage(AnalysisUsage &AU) const override;
+ OptimizationRemarkEmitter &getORE() {
+ assert(ORE && "pass not run yet");
+ return *ORE;
+ }
+
static char ID;
+};
-private:
- Function *F;
+class OptimizationRemarkEmitterAnalysis
+ : public AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis> {
+ friend AnalysisInfoMixin<OptimizationRemarkEmitterAnalysis>;
+ static char PassID;
- BlockFrequencyInfo *BFI;
+public:
+ /// \brief Provide the result typedef for this analysis pass.
+ typedef OptimizationRemarkEmitter Result;
- Optional<uint64_t> computeHotness(Value *V);
+ /// \brief Run the analysis pass over a function and produce BFI.
+ Result run(Function &F, AnalysisManager<Function> &AM);
};
}
-
#endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H
void initializeObjCARCContractPass(PassRegistry&);
void initializeObjCARCExpandPass(PassRegistry&);
void initializeObjCARCOptPass(PassRegistry&);
-void initializeOptimizationRemarkEmitterPass(PassRegistry&);
+void initializeOptimizationRemarkEmitterWrapperPassPass(PassRegistry&);
void initializeOptimizePHIsPass(PassRegistry&);
void initializePAEvalPass(PassRegistry &);
void initializePEIPass(PassRegistry&);
initializeModuleDebugInfoPrinterPass(Registry);
initializeModuleSummaryIndexWrapperPassPass(Registry);
initializeObjCARCAAWrapperPassPass(Registry);
- initializeOptimizationRemarkEmitterPass(Registry);
+ initializeOptimizationRemarkEmitterWrapperPassPass(Registry);
initializePostDominatorTreeWrapperPassPass(Registry);
initializeRegionInfoPassPass(Registry);
initializeRegionViewerPass(Registry);
using namespace llvm;
-OptimizationRemarkEmitter::OptimizationRemarkEmitter() : FunctionPass(ID) {
- initializeOptimizationRemarkEmitterPass(*PassRegistry::getPassRegistry());
-}
-
Optional<uint64_t> OptimizationRemarkEmitter::computeHotness(Value *V) {
if (!BFI)
return None;
emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg);
}
-bool OptimizationRemarkEmitter::runOnFunction(Function &Fn) {
- F = &Fn;
+OptimizationRemarkEmitterWrapperPass::OptimizationRemarkEmitterWrapperPass()
+ : FunctionPass(ID) {
+ initializeOptimizationRemarkEmitterWrapperPassPass(
+ *PassRegistry::getPassRegistry());
+}
+
+bool OptimizationRemarkEmitterWrapperPass::runOnFunction(Function &Fn) {
+ BlockFrequencyInfo *BFI;
if (Fn.getContext().getDiagnosticHotnessRequested())
BFI = &getAnalysis<LazyBlockFrequencyInfoPass>().getBFI();
else
BFI = nullptr;
+ ORE = llvm::make_unique<OptimizationRemarkEmitter>(&Fn, BFI);
return false;
}
-void OptimizationRemarkEmitter::getAnalysisUsage(AnalysisUsage &AU) const {
+void OptimizationRemarkEmitterWrapperPass::getAnalysisUsage(
+ AnalysisUsage &AU) const {
LazyBlockFrequencyInfoPass::getLazyBFIAnalysisUsage(AU);
AU.setPreservesAll();
}
-char OptimizationRemarkEmitter::ID = 0;
+char OptimizationRemarkEmitterAnalysis::PassID;
+
+OptimizationRemarkEmitter
+OptimizationRemarkEmitterAnalysis::run(Function &F, AnalysisManager<Function> &AM) {
+ BlockFrequencyInfo *BFI;
+
+ if (F.getContext().getDiagnosticHotnessRequested())
+ BFI = &AM.getResult<BlockFrequencyAnalysis>(F);
+ else
+ BFI = nullptr;
+
+ return OptimizationRemarkEmitter(&F, BFI);
+}
+
+char OptimizationRemarkEmitterWrapperPass::ID = 0;
static const char ore_name[] = "Optimization Remark Emitter";
#define ORE_NAME "opt-remark-emitter"
-INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitter, ORE_NAME, ore_name, false,
- true)
+INITIALIZE_PASS_BEGIN(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
+ false, true)
INITIALIZE_PASS_DEPENDENCY(LazyBFIPass)
-INITIALIZE_PASS_END(OptimizationRemarkEmitter, ORE_NAME, ore_name, false, true)
+INITIALIZE_PASS_END(OptimizationRemarkEmitterWrapperPass, ORE_NAME, ore_name,
+ false, true)
#include "llvm/Analysis/LoopAccessAnalysis.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
+#include "llvm/Analysis/OptimizationDiagnosticInfo.h"
#include "llvm/Analysis/PostDominators.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/RegionInfo.h"
FUNCTION_ANALYSIS("memoryssa", MemorySSAAnalysis())
FUNCTION_ANALYSIS("regions", RegionInfoAnalysis())
FUNCTION_ANALYSIS("no-op-function", NoOpFunctionAnalysis())
+FUNCTION_ANALYSIS("opt-remark-emit", OptimizationRemarkEmitterAnalysis())
FUNCTION_ANALYSIS("scalar-evolution", ScalarEvolutionAnalysis())
FUNCTION_ANALYSIS("targetlibinfo", TargetLibraryAnalysis())
FUNCTION_ANALYSIS("targetir",
auto *LAA = &getAnalysis<LoopAccessLegacyAnalysis>();
auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
- auto *ORE = &getAnalysis<OptimizationRemarkEmitter>();
+ auto *ORE = &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE();
// Build up a worklist of inner-loops to vectorize. This is necessary as the
// act of distributing a loop creates new loops and can invalidate iterators
AU.addRequired<LoopAccessLegacyAnalysis>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.addPreserved<DominatorTreeWrapperPass>();
- AU.addRequired<OptimizationRemarkEmitter>();
+ AU.addRequired<OptimizationRemarkEmitterWrapperPass>();
}
static char ID;
INITIALIZE_PASS_DEPENDENCY(LoopAccessLegacyAnalysis)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitter)
+INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitterWrapperPass)
INITIALIZE_PASS_END(LoopDistribute, LDIST_NAME, ldist_name, false, false)
namespace llvm {