diff --git a/include/llvm/Analysis/OptimizationDiagnosticInfo.h b/include/llvm/Analysis/OptimizationDiagnosticInfo.h index 426fbb548e6..2fd4819064c 100644 --- a/include/llvm/Analysis/OptimizationDiagnosticInfo.h +++ b/include/llvm/Analysis/OptimizationDiagnosticInfo.h @@ -38,7 +38,7 @@ class Value; /// enabled in the LLVM context. class OptimizationRemarkEmitter { public: - OptimizationRemarkEmitter(Function *F, BlockFrequencyInfo *BFI) + OptimizationRemarkEmitter(const Function *F, BlockFrequencyInfo *BFI) : F(F), BFI(BFI) {} /// \brief This variant can be used to generate ORE on demand (without the @@ -52,7 +52,7 @@ public: /// operation since BFI and all its required analyses are computed. This is /// for example useful for CGSCC passes that can't use function analyses /// passes in the old PM. - OptimizationRemarkEmitter(Function *F); + OptimizationRemarkEmitter(const Function *F); OptimizationRemarkEmitter(OptimizationRemarkEmitter &&Arg) : F(Arg.F), BFI(Arg.BFI) {} @@ -216,7 +216,7 @@ public: } private: - Function *F; + const Function *F; BlockFrequencyInfo *BFI; diff --git a/include/llvm/IR/DiagnosticInfo.h b/include/llvm/IR/DiagnosticInfo.h index e06fb4bdaef..1d4eddc0959 100644 --- a/include/llvm/IR/DiagnosticInfo.h +++ b/include/llvm/IR/DiagnosticInfo.h @@ -526,7 +526,7 @@ public: const char *PassName, StringRef RemarkName, const Function &Fn, const DiagnosticLocation &Loc, - Value *CodeRegion = nullptr) + const Value *CodeRegion = nullptr) : DiagnosticInfoOptimizationBase(Kind, Severity, PassName, RemarkName, Fn, Loc), CodeRegion(CodeRegion) {} @@ -566,7 +566,7 @@ public: *this << Msg.str(); } - Value *getCodeRegion() const { return CodeRegion; } + const Value *getCodeRegion() const { return CodeRegion; } static bool classof(const DiagnosticInfo *DI) { return DI->getKind() >= DK_FirstRemark && DI->getKind() <= DK_LastRemark; @@ -575,7 +575,7 @@ public: private: /// The IR value (currently basic block) that the optimization operates on. /// This is currently used to provide run-time hotness information with PGO. - Value *CodeRegion; + const Value *CodeRegion; }; /// Diagnostic information for applied optimization remarks. @@ -601,7 +601,7 @@ public: /// Loc is the debug location and \p CodeRegion is the region that the /// optimization operates on (currently on block is supported). OptimizationRemark(const char *PassName, StringRef RemarkName, - const DiagnosticLocation &Loc, Value *CodeRegion); + const DiagnosticLocation &Loc, const Value *CodeRegion); /// Same as above but the debug location and code region is derived from \p /// Instr. diff --git a/lib/Analysis/OptimizationDiagnosticInfo.cpp b/lib/Analysis/OptimizationDiagnosticInfo.cpp index 7198e474d4b..23199746c40 100644 --- a/lib/Analysis/OptimizationDiagnosticInfo.cpp +++ b/lib/Analysis/OptimizationDiagnosticInfo.cpp @@ -23,14 +23,14 @@ using namespace llvm; -OptimizationRemarkEmitter::OptimizationRemarkEmitter(Function *F) +OptimizationRemarkEmitter::OptimizationRemarkEmitter(const Function *F) : F(F), BFI(nullptr) { if (!F->getContext().getDiagnosticHotnessRequested()) return; // First create a dominator tree. DominatorTree DT; - DT.recalculate(*F); + DT.recalculate(*const_cast(F)); // Generate LoopInfo from it. LoopInfo LI; @@ -146,7 +146,7 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(DiagnosticInfoOptimizationBase::Argument) void OptimizationRemarkEmitter::computeHotness( DiagnosticInfoIROptimization &OptDiag) { - Value *V = OptDiag.getCodeRegion(); + const Value *V = OptDiag.getCodeRegion(); if (V) OptDiag.setHotness(computeHotness(V)); } diff --git a/lib/IR/DiagnosticInfo.cpp b/lib/IR/DiagnosticInfo.cpp index 2af2ab9d7a9..fccf34a6ccb 100644 --- a/lib/IR/DiagnosticInfo.cpp +++ b/lib/IR/DiagnosticInfo.cpp @@ -222,7 +222,7 @@ void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const { OptimizationRemark::OptimizationRemark(const char *PassName, StringRef RemarkName, const DiagnosticLocation &Loc, - Value *CodeRegion) + const Value *CodeRegion) : DiagnosticInfoIROptimization( DK_OptimizationRemark, DS_Remark, PassName, RemarkName, *cast(CodeRegion)->getParent(), Loc, CodeRegion) {}