LLVM  4.0.0
Macros | Enumerations | Functions | Variables
PGOInstrumentation.cpp File Reference
#include "llvm/Transforms/PGOInstrumentation.h"
#include "CFGMST.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/BranchProbabilityInfo.h"
#include "llvm/Analysis/CFG.h"
#include "llvm/Analysis/IndirectCallSiteVisitor.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/ProfileData/ProfileCommon.h"
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/JamCRC.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include <algorithm>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
Include dependency graph for PGOInstrumentation.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "pgo-instrumentation"
 

Enumerations

enum  VisitMode
 The select instruction visitor plays three roles specified by the mode. More...
 

Functions

 STATISTIC (NumOfPGOInstrument,"Number of edges instrumented.")
 
 STATISTIC (NumOfPGOSelectInsts,"Number of select instruction instrumented.")
 
 STATISTIC (NumOfPGOEdge,"Number of edges.")
 
 STATISTIC (NumOfPGOBB,"Number of basic-blocks.")
 
 STATISTIC (NumOfPGOSplit,"Number of critical edge splits.")
 
 STATISTIC (NumOfPGOFunc,"Number of functions having valid profile counts.")
 
 STATISTIC (NumOfPGOMismatch,"Number of functions having mismatch profile.")
 
 STATISTIC (NumOfPGOMissing,"Number of functions without profile.")
 
 STATISTIC (NumOfPGOICall,"Number of indirect call value instrumentations.")
 
 INITIALIZE_PASS_BEGIN (PGOInstrumentationGenLegacyPass,"pgo-instr-gen","PGO instrumentation.", false, false) INITIALIZE_PASS_END(PGOInstrumentationGenLegacyPass
 
 INITIALIZE_PASS_BEGIN (PGOInstrumentationUseLegacyPass,"pgo-instr-use","Read PGO instrumentation profile.", false, false) INITIALIZE_PASS_END(PGOInstrumentationUseLegacyPass
 
static void createIRLevelProfileFlagVariable (Module &M)
 
static void collectComdatMembers (Module &M, std::unordered_multimap< Comdat *, GlobalValue * > &ComdatMembers)
 
static bool InstrumentAllFunctions (Module &M, function_ref< BranchProbabilityInfo *(Function &)> LookupBPI, function_ref< BlockFrequencyInfo *(Function &)> LookupBFI)
 
static bool annotateAllFunctions (Module &M, StringRef ProfileFileName, function_ref< BranchProbabilityInfo *(Function &)> LookupBPI, function_ref< BlockFrequencyInfo *(Function &)> LookupBFI)
 

Variables

static cl::opt< std::string > PGOTestProfileFile ("pgo-test-profile-file", cl::init(""), cl::Hidden, cl::value_desc("filename"), cl::desc("Specify the path of profile data file. This is""mainly for test purpose."))
 
static cl::opt< boolDisableValueProfiling ("disable-vp", cl::init(false), cl::Hidden, cl::desc("Disable Value Profiling"))
 
static cl::opt< unsignedMaxNumAnnotations ("icp-max-annotations", cl::init(3), cl::Hidden, cl::ZeroOrMore, cl::desc("Max number of annotations for a single indirect ""call callsite"))
 
static cl::opt< boolDoComdatRenaming ("do-comdat-renaming", cl::init(false), cl::Hidden, cl::desc("Append function hash to the name of COMDAT function to avoid ""function hash mismatch due to the preinliner"))
 
static cl::opt< boolPGOWarnMissing ("pgo-warn-missing-function", cl::init(false), cl::Hidden)
 
static cl::opt< boolNoPGOWarnMismatch ("no-pgo-warn-mismatch", cl::init(false), cl::Hidden)
 
static cl::opt< boolNoPGOWarnMismatchComdat ("no-pgo-warn-mismatch-comdat", cl::init(true), cl::Hidden)
 
static cl::opt< boolPGOInstrSelect ("pgo-instr-select", cl::init(true), cl::Hidden)
 
pgo instr gen
 
pgo instr PGO instrumentation
 
pgo instr PGO false
 
pgo instr use
 
pgo instr Read PGO instrumentation profile
 

Macro Definition Documentation

#define DEBUG_TYPE   "pgo-instrumentation"

Definition at line 86 of file PGOInstrumentation.cpp.

Enumeration Type Documentation

enum VisitMode

The select instruction visitor plays three roles specified by the mode.

In VM_counting mode, it simply counts the number of select instructions. In VM_instrument mode, it inserts code to count the number times TrueValue of select is taken. In VM_annotate mode, it reads the profile data and annotate the select instruction with metadata.

Definition at line 153 of file PGOInstrumentation.cpp.

Function Documentation

static bool annotateAllFunctions ( Module M,
StringRef  ProfileFileName,
function_ref< BranchProbabilityInfo *(Function &)>  LookupBPI,
function_ref< BlockFrequencyInfo *(Function &)>  LookupBFI 
)
static
static void collectComdatMembers ( Module M,
std::unordered_multimap< Comdat *, GlobalValue * > &  ComdatMembers 
)
static

Definition at line 1091 of file PGOInstrumentation.cpp.

References DoComdatRenaming.

Referenced by annotateAllFunctions(), and InstrumentAllFunctions().

static void createIRLevelProfileFlagVariable ( Module M)
static
INITIALIZE_PASS_BEGIN ( PGOInstrumentationGenLegacyPass  ,
"pgo-instr-gen ,
"PGO instrumentation."  ,
false  ,
false   
)
INITIALIZE_PASS_BEGIN ( PGOInstrumentationUseLegacyPass  ,
"pgo-instr-use ,
"Read PGO instrumentation profile."  ,
false  ,
false   
)
static bool InstrumentAllFunctions ( Module M,
function_ref< BranchProbabilityInfo *(Function &)>  LookupBPI,
function_ref< BlockFrequencyInfo *(Function &)>  LookupBFI 
)
static
STATISTIC ( NumOfPGOInstrument  ,
"Number of edges instrumented."   
)
STATISTIC ( NumOfPGOSelectInsts  ,
"Number of select instruction instrumented."   
)
STATISTIC ( NumOfPGOEdge  ,
"Number of edges."   
)
STATISTIC ( NumOfPGOBB  ,
"Number of basic-blocks."   
)
STATISTIC ( NumOfPGOSplit  ,
"Number of critical edge splits."   
)
STATISTIC ( NumOfPGOFunc  ,
"Number of functions having valid profile counts."   
)
STATISTIC ( NumOfPGOMismatch  ,
"Number of functions having mismatch profile."   
)
STATISTIC ( NumOfPGOMissing  ,
"Number of functions without profile."   
)
STATISTIC ( NumOfPGOICall  ,
"Number of indirect call value instrumentations."   
)

Variable Documentation

cl::opt<bool> DisableValueProfiling("disable-vp", cl::init(false), cl::Hidden, cl::desc("Disable Value Profiling"))
static
cl::opt<bool> DoComdatRenaming("do-comdat-renaming", cl::init(false), cl::Hidden, cl::desc("Append function hash to the name of COMDAT function to avoid ""function hash mismatch due to the preinliner"))
static

Referenced by collectComdatMembers().

pgo instr Read PGO instrumentation false

Definition at line 252 of file PGOInstrumentation.cpp.

pgo instr gen

Definition at line 252 of file PGOInstrumentation.cpp.

pgo instr PGO instrumentation

Definition at line 252 of file PGOInstrumentation.cpp.

cl::opt<unsigned> MaxNumAnnotations("icp-max-annotations", cl::init(3), cl::Hidden, cl::ZeroOrMore, cl::desc("Max number of annotations for a single indirect ""call callsite"))
static
cl::opt<bool> NoPGOWarnMismatch("no-pgo-warn-mismatch", cl::init(false), cl::Hidden)
static
cl::opt<bool> NoPGOWarnMismatchComdat("no-pgo-warn-mismatch-comdat", cl::init(true), cl::Hidden)
static
cl::opt<bool> PGOInstrSelect("pgo-instr-select", cl::init(true), cl::Hidden)
static
cl::opt<std::string> PGOTestProfileFile("pgo-test-profile-file", cl::init(""), cl::Hidden, cl::value_desc("filename"), cl::desc("Specify the path of profile data file. This is""mainly for test purpose."))
static
cl::opt<bool> PGOWarnMissing("pgo-warn-missing-function", cl::init(false), cl::Hidden)
static
pgo instr Read PGO instrumentation profile

Definition at line 264 of file PGOInstrumentation.cpp.

pgo instr use

Definition at line 264 of file PGOInstrumentation.cpp.