Index: include/llvm/Analysis/OptimizationDiagnosticInfo.h =================================================================== --- /dev/null +++ include/llvm/Analysis/OptimizationDiagnosticInfo.h @@ -0,0 +1,66 @@ +//===- OptimizationDiagnosticInfo.h - Optimization Diagnostic ---*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Optimization diagnostic interfaces. It's packaged as an analysis pass so +// that by using this service passes become dependent on BFI as well. BFI is +// used to compute the "hotness" of the diagnostic message. +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H +#define LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H + +#include "llvm/ADT/Optional.h" +#include "llvm/Pass.h" + +namespace llvm { +class BlockFrequencyInfo; +class DebugLoc; +class Function; +class LLVMContext; +class Loop; +class Pass; +class Twine; +class Value; + +class OptimizationRemarkEmitter : public FunctionPass { +public: + OptimizationRemarkEmitter(); + + /// Emit an optimization-missed message. + /// + /// \p PassName is the name of the pass emitting the message. If + /// -Rpass-missed= is given and the name matches the regular expression in + /// -Rpass, then the remark will be emitted. \p Fn is the function triggering + /// the remark, \p DLoc is the debug location where the diagnostic is + /// generated. \p V is the IR Value that identifies the code region. \p Msg is + /// the message string to use. + void emitOptimizationRemarkMissed(const char *PassName, const DebugLoc &DLoc, + Value *V, const Twine &Msg); + + /// \brief Same as above but derives the IR Value for the code region and the + /// debug location from the Loop parameter \p L. + void emitOptimizationRemarkMissed(const char *PassName, Loop *L, + const Twine &Msg); + + bool runOnFunction(Function &F) override; + + void getAnalysisUsage(AnalysisUsage &AU) const override; + + static char ID; + +private: + Function *F; + + BlockFrequencyInfo *BFI; + + Optional computeHotness(Value *V); +}; +} + +#endif // LLVM_IR_OPTIMIZATIONDIAGNOSTICINFO_H Index: include/llvm/IR/DiagnosticInfo.h =================================================================== --- include/llvm/IR/DiagnosticInfo.h +++ include/llvm/IR/DiagnosticInfo.h @@ -15,6 +15,7 @@ #ifndef LLVM_IR_DIAGNOSTICINFO_H #define LLVM_IR_DIAGNOSTICINFO_H +#include "llvm/ADT/Optional.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" #include "llvm/IR/DebugLoc.h" @@ -31,6 +32,7 @@ class Instruction; class LLVMContext; class Module; +class Pass; class SMDiagnostic; /// \brief Defines the different supported severity of a diagnostic. @@ -383,9 +385,10 @@ DiagnosticInfoOptimizationBase(enum DiagnosticKind Kind, enum DiagnosticSeverity Severity, const char *PassName, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg) + const DebugLoc &DLoc, const Twine &Msg, + Optional Hotness = None) : DiagnosticInfoWithDebugLocBase(Kind, Severity, Fn, DLoc), - PassName(PassName), Msg(Msg) {} + PassName(PassName), Msg(Msg), Hotness(Hotness) {} /// \see DiagnosticInfo::print. void print(DiagnosticPrinter &DP) const override; @@ -413,6 +416,10 @@ /// Message to report. const Twine &Msg; + + /// If profile information is available, this is the number of times the + /// corresponding code was executed in a profile instrumentation run. + Optional Hotness; }; /// Diagnostic information for applied optimization remarks. @@ -453,9 +460,10 @@ /// must be valid for the whole life time of the diagnostic. DiagnosticInfoOptimizationRemarkMissed(const char *PassName, const Function &Fn, - const DebugLoc &DLoc, const Twine &Msg) + const DebugLoc &DLoc, const Twine &Msg, + Optional Hotness = None) : DiagnosticInfoOptimizationBase(DK_OptimizationRemarkMissed, DS_Remark, - PassName, Fn, DLoc, Msg) {} + PassName, Fn, DLoc, Msg, Hotness) {} static bool classof(const DiagnosticInfo *DI) { return DI->getKind() == DK_OptimizationRemarkMissed; Index: include/llvm/IR/LLVMContext.h =================================================================== --- include/llvm/IR/LLVMContext.h +++ include/llvm/IR/LLVMContext.h @@ -174,6 +174,13 @@ /// setDiagnosticContext. void *getDiagnosticContext() const; + /// \brief Return if a code hotness metric should be included in optimization + /// diagnostic. + bool getDiagnosticHotnessRequested() const; + /// \brief Set if a code hotness metric should be included in optimization + /// diagnostic. + void setDiagnosticHotnessRequested(bool Requested); + /// \brief Get the prefix that should be printed in front of a diagnostic of /// the given \p Severity static const char *getDiagnosticMessagePrefix(DiagnosticSeverity Severity); Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -239,6 +239,7 @@ void initializeObjCARCContractPass(PassRegistry&); void initializeObjCARCExpandPass(PassRegistry&); void initializeObjCARCOptPass(PassRegistry&); +void initializeOptimizationRemarkEmitterPass(PassRegistry&); void initializeOptimizePHIsPass(PassRegistry&); void initializePAEvalPass(PassRegistry &); void initializePEIPass(PassRegistry&); Index: lib/Analysis/CMakeLists.txt =================================================================== --- lib/Analysis/CMakeLists.txt +++ lib/Analysis/CMakeLists.txt @@ -53,6 +53,7 @@ ObjCARCAliasAnalysis.cpp ObjCARCAnalysisUtils.cpp ObjCARCInstKind.cpp + OptimizationDiagnosticInfo.cpp OrderedBasicBlock.cpp PHITransAddr.cpp PostDominators.cpp Index: lib/Analysis/OptimizationDiagnosticInfo.cpp =================================================================== --- /dev/null +++ lib/Analysis/OptimizationDiagnosticInfo.cpp @@ -0,0 +1,69 @@ +//===- OptimizationDiagnosticInfo.cpp - Optimization Diagnostic -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// Optimization diagnostic interfaces. It's packaged as an analysis pass so +// that by using this service passes become dependent on BFI as well. BFI is +// used to compute the "hotness" of the diagnostic message. +//===----------------------------------------------------------------------===// + +#include "llvm/Analysis/OptimizationDiagnosticInfo.h" +#include "llvm/Analysis/BlockFrequencyInfo.h" +#include "llvm/Analysis/LoopInfo.h" +#include "llvm/IR/DiagnosticInfo.h" +#include "llvm/IR/LLVMContext.h" + +using namespace llvm; + +OptimizationRemarkEmitter::OptimizationRemarkEmitter() : FunctionPass(ID) { + initializeOptimizationRemarkEmitterPass(*PassRegistry::getPassRegistry()); +} + +Optional OptimizationRemarkEmitter::computeHotness(Value *V) { + if (!BFI) + return None; + + return BFI->getBlockProfileCount(cast(V)); +} + +void OptimizationRemarkEmitter::emitOptimizationRemarkMissed( + const char *PassName, const DebugLoc &DLoc, Value *V, const Twine &Msg) { + LLVMContext &Ctx = F->getContext(); + Ctx.diagnose(DiagnosticInfoOptimizationRemarkMissed(PassName, *F, DLoc, Msg, + computeHotness(V))); +} + +void OptimizationRemarkEmitter::emitOptimizationRemarkMissed( + const char *PassName, Loop *L, const Twine &Msg) { + emitOptimizationRemarkMissed(PassName, L->getStartLoc(), L->getHeader(), Msg); +} + +bool OptimizationRemarkEmitter::runOnFunction(Function &Fn) { + F = &Fn; + + if (Fn.getContext().getDiagnosticHotnessRequested()) + BFI = &getAnalysis().getBFI(); + else + BFI = nullptr; + + return false; +} + +void OptimizationRemarkEmitter::getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequired(); + AU.setPreservesAll(); +} + +char OptimizationRemarkEmitter::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_DEPENDENCY(BlockFrequencyInfoWrapperPass) +INITIALIZE_PASS_END(OptimizationRemarkEmitter, ORE_NAME, ore_name, false, true) Index: lib/IR/DiagnosticInfo.cpp =================================================================== --- lib/IR/DiagnosticInfo.cpp +++ lib/IR/DiagnosticInfo.cpp @@ -172,6 +172,8 @@ void DiagnosticInfoOptimizationBase::print(DiagnosticPrinter &DP) const { DP << getLocationStr() << ": " << getMsg(); + if (Hotness) + DP << " (hotness: " << *Hotness << ")"; } bool DiagnosticInfoOptimizationRemark::isEnabled() const { Index: lib/IR/LLVMContext.cpp =================================================================== --- lib/IR/LLVMContext.cpp +++ lib/IR/LLVMContext.cpp @@ -196,6 +196,13 @@ pImpl->RespectDiagnosticFilters = RespectFilters; } +void LLVMContext::setDiagnosticHotnessRequested(bool Requested) { + pImpl->DiagnosticHotnessRequested = Requested; +} +bool LLVMContext::getDiagnosticHotnessRequested() const { + return pImpl->DiagnosticHotnessRequested; +} + LLVMContext::DiagnosticHandlerTy LLVMContext::getDiagnosticHandler() const { return pImpl->DiagnosticHandler; } Index: lib/IR/LLVMContextImpl.h =================================================================== --- lib/IR/LLVMContextImpl.h +++ lib/IR/LLVMContextImpl.h @@ -1038,6 +1038,7 @@ LLVMContext::DiagnosticHandlerTy DiagnosticHandler; void *DiagnosticContext; bool RespectDiagnosticFilters; + bool DiagnosticHotnessRequested; LLVMContext::YieldCallbackTy YieldCallback; void *YieldOpaqueHandle; Index: lib/IR/LLVMContextImpl.cpp =================================================================== --- lib/IR/LLVMContextImpl.cpp +++ lib/IR/LLVMContextImpl.cpp @@ -45,6 +45,7 @@ DiagnosticHandler = nullptr; DiagnosticContext = nullptr; RespectDiagnosticFilters = false; + DiagnosticHotnessRequested = false; YieldCallback = nullptr; YieldOpaqueHandle = nullptr; NamedStructTypesUniqueID = 0; Index: lib/Transforms/Vectorize/LoopVectorize.cpp =================================================================== --- lib/Transforms/Vectorize/LoopVectorize.cpp +++ lib/Transforms/Vectorize/LoopVectorize.cpp @@ -66,6 +66,7 @@ #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/LoopIterator.h" #include "llvm/Analysis/LoopPass.h" +#include "llvm/Analysis/OptimizationDiagnosticInfo.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" @@ -1290,9 +1291,9 @@ } static void emitMissedWarning(Function *F, Loop *L, - const LoopVectorizeHints &LH) { - emitOptimizationRemarkMissed(F->getContext(), LV_NAME, *F, L->getStartLoc(), - LH.emitRemark()); + const LoopVectorizeHints &LH, + OptimizationRemarkEmitter *ORE) { + ORE->emitOptimizationRemarkMissed(LV_NAME, L, LH.emitRemark()); if (LH.getForce() == LoopVectorizeHints::FK_Enabled) { if (LH.getWidth() != 1) @@ -1789,6 +1790,8 @@ AliasAnalysis *AA; AssumptionCache *AC; LoopAccessAnalysis *LAA; + OptimizationRemarkEmitter *ORE; + bool DisableUnrolling; bool AlwaysVectorize; @@ -1809,6 +1812,7 @@ AC = &getAnalysis().getAssumptionCache(F); LAA = &getAnalysis(); DB = &getAnalysis().getDemandedBits(); + ORE = &getAnalysis(); // Compute some weights outside of the loop over the loops. Compute this // using a BranchProbability to re-use its scaling math. @@ -1942,7 +1946,7 @@ &Requirements, &Hints); if (!LVL.canVectorize()) { DEBUG(dbgs() << "LV: Not vectorizing: Cannot prove legality.\n"); - emitMissedWarning(F, L, Hints); + emitMissedWarning(F, L, Hints, ORE); return false; } @@ -1979,7 +1983,7 @@ F, L, Hints, VectorizationReport() << "loop not vectorized due to NoImplicitFloat attribute"); - emitMissedWarning(F, L, Hints); + emitMissedWarning(F, L, Hints, ORE); return false; } @@ -1993,7 +1997,7 @@ emitAnalysisDiag(F, L, Hints, VectorizationReport() << "loop not vectorized due to unsafe FP support."); - emitMissedWarning(F, L, Hints); + emitMissedWarning(F, L, Hints, ORE); return false; } @@ -2014,7 +2018,7 @@ if (Requirements.doesNotMeet(F, L, Hints)) { DEBUG(dbgs() << "LV: Not vectorizing: loop did not meet vectorization " "requirements.\n"); - emitMissedWarning(F, L, Hints); + emitMissedWarning(F, L, Hints, ORE); return false; } @@ -2118,6 +2122,7 @@ AU.addRequired(); AU.addRequired(); AU.addRequired(); + AU.addRequired(); AU.addPreserved(); AU.addPreserved(); AU.addPreserved(); @@ -6396,6 +6401,7 @@ INITIALIZE_PASS_DEPENDENCY(LoopSimplify) INITIALIZE_PASS_DEPENDENCY(LoopAccessAnalysis) INITIALIZE_PASS_DEPENDENCY(DemandedBitsWrapperPass) +INITIALIZE_PASS_DEPENDENCY(OptimizationRemarkEmitter) INITIALIZE_PASS_END(LoopVectorize, LV_NAME, lv_name, false, false) namespace llvm { Index: test/Transforms/LoopVectorize/diag-with-hotness-info.ll =================================================================== --- /dev/null +++ test/Transforms/LoopVectorize/diag-with-hotness-info.ll @@ -0,0 +1,199 @@ +; RUN: opt -S -loop-vectorize -pass-remarks-missed=loop-vectorize \ +; RUN: -pass-remarks-with-hotness < %s 2>&1 | \ +; RUN: FileCheck -check-prefix=HOTNESS -check-prefix=BOTH %s + +; RUN: opt -S -loop-vectorize -pass-remarks-missed=loop-vectorize < %s 2>&1 | \ +; RUN: FileCheck -check-prefix=NO_HOTNESS -check-prefix=BOTH %s + + +; 1 void cold(char *A, char *B, char *C, char *D, char *E, int N) { +; 2 for(int i = 0; i < N; i++) { +; 3 A[i + 1] = A[i] + B[i]; +; 4 C[i] = D[i] * E[i]; +; 5 } +; 6 } +; 7 +; 8 void hot(char *A, char *B, char *C, char *D, char *E, int N) { +; 9 for(int i = 0; i < N; i++) { +; 10 A[i + 1] = A[i] + B[i]; +; 11 C[i] = D[i] * E[i]; +; 12 } +; 13 } +; 14 +; 15 void unknown(char *A, char *B, char *C, char *D, char *E, int N) { +; 16 for(int i = 0; i < N; i++) { +; 17 A[i + 1] = A[i] + B[i]; +; 18 C[i] = D[i] * E[i]; +; 19 } +; 20 } + +; HOTNESS: remark: /tmp/s.c:2:3: loop not vectorized: use -Rpass-analysis=loop-vectorize for more info (hotness: 300) +; NO_HOTNESS: remark: /tmp/s.c:2:3: loop not vectorized: use -Rpass-analysis=loop-vectorize for more info{{$}} +; HOTNESS: remark: /tmp/s.c:9:3: loop not vectorized: use -Rpass-analysis=loop-vectorize for more info (hotness: 5000) +; NO_HOTNESS: remark: /tmp/s.c:9:3: loop not vectorized: use -Rpass-analysis=loop-vectorize for more info{{$}} +; BOTH: remark: /tmp/s.c:16:3: loop not vectorized: use -Rpass-analysis=loop-vectorize for more info{{$}} + +; ModuleID = '/tmp/s.c' +source_filename = "/tmp/s.c" +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-apple-macosx10.11.0" + +; Function Attrs: norecurse nounwind ssp uwtable +define void @cold(i8* nocapture %A, i8* nocapture readonly %B, i8* nocapture %C, i8* nocapture readonly %D, i8* nocapture readonly %E, i32 %N) local_unnamed_addr #0 !dbg !7 !prof !56 { +entry: + %cmp28 = icmp sgt i32 %N, 0, !dbg !9 + br i1 %cmp28, label %for.body, label %for.cond.cleanup, !dbg !10, !prof !58 + +for.cond.cleanup: ; preds = %for.body, %entry + ret void, !dbg !11 + +for.body: ; preds = %entry, %for.body + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] + %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !12 + %0 = load i8, i8* %arrayidx, align 1, !dbg !12, !tbaa !13 + %arrayidx2 = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !16 + %1 = load i8, i8* %arrayidx2, align 1, !dbg !16, !tbaa !13 + %add = add i8 %1, %0, !dbg !17 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !10 + %arrayidx7 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv.next, !dbg !18 + store i8 %add, i8* %arrayidx7, align 1, !dbg !19, !tbaa !13 + %arrayidx9 = getelementptr inbounds i8, i8* %D, i64 %indvars.iv, !dbg !20 + %2 = load i8, i8* %arrayidx9, align 1, !dbg !20, !tbaa !13 + %arrayidx12 = getelementptr inbounds i8, i8* %E, i64 %indvars.iv, !dbg !21 + %3 = load i8, i8* %arrayidx12, align 1, !dbg !21, !tbaa !13 + %mul = mul i8 %3, %2, !dbg !22 + %arrayidx16 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !23 + store i8 %mul, i8* %arrayidx16, align 1, !dbg !24, !tbaa !13 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !10 + %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !10 + br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !10, !llvm.loop !25, !prof !59 +} + +; Function Attrs: norecurse nounwind ssp uwtable +define void @hot(i8* nocapture %A, i8* nocapture readonly %B, i8* nocapture %C, i8* nocapture readonly %D, i8* nocapture readonly %E, i32 %N) local_unnamed_addr #0 !dbg !26 !prof !57 { +entry: + %cmp28 = icmp sgt i32 %N, 0, !dbg !27 + br i1 %cmp28, label %for.body, label %for.cond.cleanup, !dbg !28, !prof !58 + +for.cond.cleanup: ; preds = %for.body, %entry + ret void, !dbg !29 + +for.body: ; preds = %entry, %for.body + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] + %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !30 + %0 = load i8, i8* %arrayidx, align 1, !dbg !30, !tbaa !13 + %arrayidx2 = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !31 + %1 = load i8, i8* %arrayidx2, align 1, !dbg !31, !tbaa !13 + %add = add i8 %1, %0, !dbg !32 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !28 + %arrayidx7 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv.next, !dbg !33 + store i8 %add, i8* %arrayidx7, align 1, !dbg !34, !tbaa !13 + %arrayidx9 = getelementptr inbounds i8, i8* %D, i64 %indvars.iv, !dbg !35 + %2 = load i8, i8* %arrayidx9, align 1, !dbg !35, !tbaa !13 + %arrayidx12 = getelementptr inbounds i8, i8* %E, i64 %indvars.iv, !dbg !36 + %3 = load i8, i8* %arrayidx12, align 1, !dbg !36, !tbaa !13 + %mul = mul i8 %3, %2, !dbg !37 + %arrayidx16 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !38 + store i8 %mul, i8* %arrayidx16, align 1, !dbg !39, !tbaa !13 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !28 + %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !28 + br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !28, !llvm.loop !40, !prof !59 +} + +; Function Attrs: norecurse nounwind ssp uwtable +define void @unknown(i8* nocapture %A, i8* nocapture readonly %B, i8* nocapture %C, i8* nocapture readonly %D, i8* nocapture readonly %E, i32 %N) local_unnamed_addr #0 !dbg !41 { +entry: + %cmp28 = icmp sgt i32 %N, 0, !dbg !42 + br i1 %cmp28, label %for.body, label %for.cond.cleanup, !dbg !43 + +for.cond.cleanup: ; preds = %for.body, %entry + ret void, !dbg !44 + +for.body: ; preds = %entry, %for.body + %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ] + %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !45 + %0 = load i8, i8* %arrayidx, align 1, !dbg !45, !tbaa !13 + %arrayidx2 = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !46 + %1 = load i8, i8* %arrayidx2, align 1, !dbg !46, !tbaa !13 + %add = add i8 %1, %0, !dbg !47 + %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !43 + %arrayidx7 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv.next, !dbg !48 + store i8 %add, i8* %arrayidx7, align 1, !dbg !49, !tbaa !13 + %arrayidx9 = getelementptr inbounds i8, i8* %D, i64 %indvars.iv, !dbg !50 + %2 = load i8, i8* %arrayidx9, align 1, !dbg !50, !tbaa !13 + %arrayidx12 = getelementptr inbounds i8, i8* %E, i64 %indvars.iv, !dbg !51 + %3 = load i8, i8* %arrayidx12, align 1, !dbg !51, !tbaa !13 + %mul = mul i8 %3, %2, !dbg !52 + %arrayidx16 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !53 + store i8 %mul, i8* %arrayidx16, align 1, !dbg !54, !tbaa !13 + %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !43 + %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !43 + br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !43, !llvm.loop !55 +} + +attributes #0 = { norecurse nounwind ssp uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="core2" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273572) (llvm/trunk 273585)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2) +!1 = !DIFile(filename: "/tmp/s.c", directory: "/tmp") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 2} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"PIC Level", i32 2} +!6 = !{!"clang version 3.9.0 (trunk 273572) (llvm/trunk 273585)"} +!7 = distinct !DISubprogram(name: "cold", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) +!8 = !DISubroutineType(types: !2) +!9 = !DILocation(line: 2, column: 20, scope: !7) +!10 = !DILocation(line: 2, column: 3, scope: !7) +!11 = !DILocation(line: 6, column: 1, scope: !7) +!12 = !DILocation(line: 3, column: 16, scope: !7) +!13 = !{!14, !14, i64 0} +!14 = !{!"omnipotent char", !15, i64 0} +!15 = !{!"Simple C/C++ TBAA"} +!16 = !DILocation(line: 3, column: 23, scope: !7) +!17 = !DILocation(line: 3, column: 21, scope: !7) +!18 = !DILocation(line: 3, column: 5, scope: !7) +!19 = !DILocation(line: 3, column: 14, scope: !7) +!20 = !DILocation(line: 4, column: 12, scope: !7) +!21 = !DILocation(line: 4, column: 19, scope: !7) +!22 = !DILocation(line: 4, column: 17, scope: !7) +!23 = !DILocation(line: 4, column: 5, scope: !7) +!24 = !DILocation(line: 4, column: 10, scope: !7) +!25 = distinct !{!25, !10} +!26 = distinct !DISubprogram(name: "hot", scope: !1, file: !1, line: 8, type: !8, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) +!27 = !DILocation(line: 9, column: 20, scope: !26) +!28 = !DILocation(line: 9, column: 3, scope: !26) +!29 = !DILocation(line: 13, column: 1, scope: !26) +!30 = !DILocation(line: 10, column: 16, scope: !26) +!31 = !DILocation(line: 10, column: 23, scope: !26) +!32 = !DILocation(line: 10, column: 21, scope: !26) +!33 = !DILocation(line: 10, column: 5, scope: !26) +!34 = !DILocation(line: 10, column: 14, scope: !26) +!35 = !DILocation(line: 11, column: 12, scope: !26) +!36 = !DILocation(line: 11, column: 19, scope: !26) +!37 = !DILocation(line: 11, column: 17, scope: !26) +!38 = !DILocation(line: 11, column: 5, scope: !26) +!39 = !DILocation(line: 11, column: 10, scope: !26) +!40 = distinct !{!40, !28} +!41 = distinct !DISubprogram(name: "unknown", scope: !1, file: !1, line: 15, type: !8, isLocal: false, isDefinition: true, scopeLine: 15, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2) +!42 = !DILocation(line: 16, column: 20, scope: !41) +!43 = !DILocation(line: 16, column: 3, scope: !41) +!44 = !DILocation(line: 20, column: 1, scope: !41) +!45 = !DILocation(line: 17, column: 16, scope: !41) +!46 = !DILocation(line: 17, column: 23, scope: !41) +!47 = !DILocation(line: 17, column: 21, scope: !41) +!48 = !DILocation(line: 17, column: 5, scope: !41) +!49 = !DILocation(line: 17, column: 14, scope: !41) +!50 = !DILocation(line: 18, column: 12, scope: !41) +!51 = !DILocation(line: 18, column: 19, scope: !41) +!52 = !DILocation(line: 18, column: 17, scope: !41) +!53 = !DILocation(line: 18, column: 5, scope: !41) +!54 = !DILocation(line: 18, column: 10, scope: !41) +!55 = distinct !{!55, !43} +!56 = !{!"function_entry_count", i64 3} +!57 = !{!"function_entry_count", i64 50} +!58 = !{!"branch_weights", i32 99, i32 1} +!59 = !{!"branch_weights", i32 1, i32 99} Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -215,6 +215,11 @@ cl::desc("Discard names from Value (other than GlobalValue)."), cl::init(false), cl::Hidden); +static cl::opt PassRemarksWithHotness( + "pass-remarks-with-hotness", + cl::desc("With PGO, include profile count in optimization remarks"), + cl::Hidden); + static inline void addPass(legacy::PassManagerBase &PM, Pass *P) { // Add the pass to the pass manager... PM.add(P); @@ -383,6 +388,9 @@ if (!DisableDITypeMap) Context.enableDebugTypeODRUniquing(); + if (PassRemarksWithHotness) + Context.setDiagnosticHotnessRequested(true); + // Load the input module... std::unique_ptr M = parseIRFile(InputFilename, Err, Context);