forked from OSchip/llvm-project
Add more intrumentation/runtime helper interfaces (NFC)
This patch converts the remaining references to literal strings for names of profile runtime entites (such as profile runtime hook, runtime hook use function, profile init method, register function etc). Also added documentation for all the new interfaces. llvm-svn: 251093
This commit is contained in:
parent
b9d5459d5a
commit
8ee08b0f70
|
@ -28,36 +28,91 @@
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
|
/// Return the name of data section containing profile counter variables.
|
||||||
inline StringRef getInstrProfCountersSectionName(bool AddSegment) {
|
inline StringRef getInstrProfCountersSectionName(bool AddSegment) {
|
||||||
return AddSegment ? "__DATA,__llvm_prf_cnts" : "__llvm_prf_cnts";
|
return AddSegment ? "__DATA,__llvm_prf_cnts" : "__llvm_prf_cnts";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the name of data section containing names of instrumented
|
||||||
|
/// functions.
|
||||||
inline StringRef getInstrProfNameSectionName(bool AddSegment) {
|
inline StringRef getInstrProfNameSectionName(bool AddSegment) {
|
||||||
return AddSegment ? "__DATA,__llvm_prf_names" : "__llvm_prf_names";
|
return AddSegment ? "__DATA,__llvm_prf_names" : "__llvm_prf_names";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the name of the data section containing per-function control
|
||||||
|
/// data.
|
||||||
inline StringRef getInstrProfDataSectionName(bool AddSegment) {
|
inline StringRef getInstrProfDataSectionName(bool AddSegment) {
|
||||||
return AddSegment ? "__DATA,__llvm_prf_data" : "__llvm_prf_data";
|
return AddSegment ? "__DATA,__llvm_prf_data" : "__llvm_prf_data";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the name of the section containing function coverage mapping
|
||||||
|
/// data.
|
||||||
inline StringRef getInstrProfCoverageSectionName(bool AddSegment) {
|
inline StringRef getInstrProfCoverageSectionName(bool AddSegment) {
|
||||||
return AddSegment ? "__DATA,__llvm_covmap" : "__llvm_covmap";
|
return AddSegment ? "__DATA,__llvm_covmap" : "__llvm_covmap";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the name prefix of variables containing instrumented function names.
|
||||||
inline StringRef getInstrProfNameVarPrefix() { return "__llvm_profile_name_"; }
|
inline StringRef getInstrProfNameVarPrefix() { return "__llvm_profile_name_"; }
|
||||||
|
|
||||||
|
/// Return the name prefix of variables containing per-function control data.
|
||||||
inline StringRef getInstrProfDataVarPrefix() { return "__llvm_profile_data_"; }
|
inline StringRef getInstrProfDataVarPrefix() { return "__llvm_profile_data_"; }
|
||||||
|
|
||||||
|
/// Return the name prefix of profile counter variables.
|
||||||
inline StringRef getInstrProfCountersVarPrefix() {
|
inline StringRef getInstrProfCountersVarPrefix() {
|
||||||
return "__llvm_profile_counters_";
|
return "__llvm_profile_counters_";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the name prefix of the COMDAT group for instrumentation variables
|
||||||
|
/// associated with a COMDAT function.
|
||||||
inline StringRef getInstrProfComdatPrefix() { return "__llvm_profile_vars_"; }
|
inline StringRef getInstrProfComdatPrefix() { return "__llvm_profile_vars_"; }
|
||||||
|
|
||||||
|
/// Return the name of a covarage mapping variable (internal linkage)
|
||||||
|
/// for each instrumented source module. Such variables are allocated
|
||||||
|
/// in the __llvm_covmap section.
|
||||||
inline StringRef getCoverageMappingVarName() {
|
inline StringRef getCoverageMappingVarName() {
|
||||||
return "__llvm_coverage_mapping";
|
return "__llvm_coverage_mapping";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the name of function that registers all the per-function control
|
||||||
|
/// data at program startup time by calling __llvm_register_function. This
|
||||||
|
/// function has internal linkage and is called by __llvm_profile_init
|
||||||
|
/// runtime method. This function is not generated for these platforms:
|
||||||
|
/// Darwin, Linux, and FreeBSD.
|
||||||
|
inline StringRef getInstrProfRegFuncsName() {
|
||||||
|
return "__llvm_profile_register_functions";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the name of the runtime interface that registers per-function control
|
||||||
|
/// data for one instrumented function.
|
||||||
|
inline StringRef getInstrProfRegFuncName() {
|
||||||
|
return "__llvm_profile_register_function";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the name of the runtime initialization method that is generated by
|
||||||
|
/// the compiler. The function calls __llvm_profile_register_functions and
|
||||||
|
/// __llvm_profile_override_default_filename functions if needed. This function
|
||||||
|
/// has internal linkage and invoked at startup time via init_array.
|
||||||
|
inline StringRef getInstrProfInitFuncName() { return "__llvm_profile_init"; }
|
||||||
|
|
||||||
|
/// Return the name of the hook variable defined in profile runtime library.
|
||||||
|
/// A reference to the variable causes the linker to link in the runtime
|
||||||
|
/// initialization module (which defines the hook variable).
|
||||||
|
inline StringRef getInstrProfRuntimeHookVarName() {
|
||||||
|
return "__llvm_profile_runtime";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the name of the compiler generated function that references the
|
||||||
|
/// runtime hook variable. The function is a weak global.
|
||||||
|
inline StringRef getInstrProfRuntimeHookVarUseFuncName() {
|
||||||
|
return "__llvm_profile_runtime_user";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Return the name of the profile runtime interface that overrides the default
|
||||||
|
/// profile data file name.
|
||||||
|
inline StringRef getInstrProfFileOverriderFuncName() {
|
||||||
|
return "__llvm_profile_override_default_filename";
|
||||||
|
}
|
||||||
|
|
||||||
const std::error_category &instrprof_category();
|
const std::error_category &instrprof_category();
|
||||||
|
|
||||||
enum class instrprof_error {
|
enum class instrprof_error {
|
||||||
|
|
|
@ -271,15 +271,14 @@ void InstrProfiling::emitRegistration() {
|
||||||
auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
|
auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
|
||||||
auto *RegisterFTy = FunctionType::get(VoidTy, false);
|
auto *RegisterFTy = FunctionType::get(VoidTy, false);
|
||||||
auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage,
|
auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage,
|
||||||
"__llvm_profile_register_functions", M);
|
getInstrProfRegFuncsName(), M);
|
||||||
RegisterF->setUnnamedAddr(true);
|
RegisterF->setUnnamedAddr(true);
|
||||||
if (Options.NoRedZone)
|
if (Options.NoRedZone) RegisterF->addFnAttr(Attribute::NoRedZone);
|
||||||
RegisterF->addFnAttr(Attribute::NoRedZone);
|
|
||||||
|
|
||||||
auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false);
|
auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false);
|
||||||
auto *RuntimeRegisterF =
|
auto *RuntimeRegisterF =
|
||||||
Function::Create(RuntimeRegisterTy, GlobalVariable::ExternalLinkage,
|
Function::Create(RuntimeRegisterTy, GlobalVariable::ExternalLinkage,
|
||||||
"__llvm_profile_register_function", M);
|
getInstrProfRegFuncName(), M);
|
||||||
|
|
||||||
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
|
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
|
||||||
for (Value *Data : UsedVars)
|
for (Value *Data : UsedVars)
|
||||||
|
@ -288,26 +287,22 @@ void InstrProfiling::emitRegistration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstrProfiling::emitRuntimeHook() {
|
void InstrProfiling::emitRuntimeHook() {
|
||||||
const char *const RuntimeVarName = "__llvm_profile_runtime";
|
|
||||||
const char *const RuntimeUserName = "__llvm_profile_runtime_user";
|
|
||||||
|
|
||||||
// If the module's provided its own runtime, we don't need to do anything.
|
// If the module's provided its own runtime, we don't need to do anything.
|
||||||
if (M->getGlobalVariable(RuntimeVarName))
|
if (M->getGlobalVariable(getInstrProfRuntimeHookVarName())) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// Declare an external variable that will pull in the runtime initialization.
|
// Declare an external variable that will pull in the runtime initialization.
|
||||||
auto *Int32Ty = Type::getInt32Ty(M->getContext());
|
auto *Int32Ty = Type::getInt32Ty(M->getContext());
|
||||||
auto *Var =
|
auto *Var =
|
||||||
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
|
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
|
||||||
nullptr, RuntimeVarName);
|
nullptr, getInstrProfRuntimeHookVarName());
|
||||||
|
|
||||||
// Make a function that uses it.
|
// Make a function that uses it.
|
||||||
auto *User =
|
auto *User = Function::Create(FunctionType::get(Int32Ty, false),
|
||||||
Function::Create(FunctionType::get(Int32Ty, false),
|
GlobalValue::LinkOnceODRLinkage,
|
||||||
GlobalValue::LinkOnceODRLinkage, RuntimeUserName, M);
|
getInstrProfRuntimeHookVarUseFuncName(), M);
|
||||||
User->addFnAttr(Attribute::NoInline);
|
User->addFnAttr(Attribute::NoInline);
|
||||||
if (Options.NoRedZone)
|
if (Options.NoRedZone) User->addFnAttr(Attribute::NoRedZone);
|
||||||
User->addFnAttr(Attribute::NoRedZone);
|
|
||||||
User->setVisibility(GlobalValue::HiddenVisibility);
|
User->setVisibility(GlobalValue::HiddenVisibility);
|
||||||
|
|
||||||
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
|
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
|
||||||
|
@ -350,19 +345,17 @@ void InstrProfiling::emitUses() {
|
||||||
void InstrProfiling::emitInitialization() {
|
void InstrProfiling::emitInitialization() {
|
||||||
std::string InstrProfileOutput = Options.InstrProfileOutput;
|
std::string InstrProfileOutput = Options.InstrProfileOutput;
|
||||||
|
|
||||||
Constant *RegisterF = M->getFunction("__llvm_profile_register_functions");
|
Constant *RegisterF = M->getFunction(getInstrProfRegFuncsName());
|
||||||
if (!RegisterF && InstrProfileOutput.empty())
|
if (!RegisterF && InstrProfileOutput.empty()) return;
|
||||||
return;
|
|
||||||
|
|
||||||
// Create the initialization function.
|
// Create the initialization function.
|
||||||
auto *VoidTy = Type::getVoidTy(M->getContext());
|
auto *VoidTy = Type::getVoidTy(M->getContext());
|
||||||
auto *F =
|
auto *F = Function::Create(FunctionType::get(VoidTy, false),
|
||||||
Function::Create(FunctionType::get(VoidTy, false),
|
GlobalValue::InternalLinkage,
|
||||||
GlobalValue::InternalLinkage, "__llvm_profile_init", M);
|
getInstrProfInitFuncName(), M);
|
||||||
F->setUnnamedAddr(true);
|
F->setUnnamedAddr(true);
|
||||||
F->addFnAttr(Attribute::NoInline);
|
F->addFnAttr(Attribute::NoInline);
|
||||||
if (Options.NoRedZone)
|
if (Options.NoRedZone) F->addFnAttr(Attribute::NoRedZone);
|
||||||
F->addFnAttr(Attribute::NoRedZone);
|
|
||||||
|
|
||||||
// Add the basic block and the necessary calls.
|
// Add the basic block and the necessary calls.
|
||||||
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
|
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
|
||||||
|
@ -371,9 +364,8 @@ void InstrProfiling::emitInitialization() {
|
||||||
if (!InstrProfileOutput.empty()) {
|
if (!InstrProfileOutput.empty()) {
|
||||||
auto *Int8PtrTy = Type::getInt8PtrTy(M->getContext());
|
auto *Int8PtrTy = Type::getInt8PtrTy(M->getContext());
|
||||||
auto *SetNameTy = FunctionType::get(VoidTy, Int8PtrTy, false);
|
auto *SetNameTy = FunctionType::get(VoidTy, Int8PtrTy, false);
|
||||||
auto *SetNameF =
|
auto *SetNameF = Function::Create(SetNameTy, GlobalValue::ExternalLinkage,
|
||||||
Function::Create(SetNameTy, GlobalValue::ExternalLinkage,
|
getInstrProfFileOverriderFuncName(), M);
|
||||||
"__llvm_profile_override_default_filename", M);
|
|
||||||
|
|
||||||
// Create variable for profile name.
|
// Create variable for profile name.
|
||||||
Constant *ProfileNameConst =
|
Constant *ProfileNameConst =
|
||||||
|
|
Loading…
Reference in New Issue