2014-12-09 02:02:35 +08:00
|
|
|
//===-- InstrProfiling.cpp - Frontend instrumentation based profiling -----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass lowers instrprof_increment intrinsics emitted by a frontend for
|
|
|
|
// profiling. It also builds the data structures and initialization code needed
|
|
|
|
// for updating execution counts and emitting the profile at runtime.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-10-23 04:32:12 +08:00
|
|
|
#include "llvm/ProfileData/InstrProf.h"
|
2014-12-09 02:02:35 +08:00
|
|
|
#include "llvm/Transforms/Instrumentation.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/IR/IRBuilder.h"
|
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "instrprof"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class InstrProfiling : public ModulePass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
|
|
|
|
|
|
|
InstrProfiling() : ModulePass(ID) {}
|
|
|
|
|
|
|
|
InstrProfiling(const InstrProfOptions &Options)
|
|
|
|
: ModulePass(ID), Options(Options) {}
|
|
|
|
|
|
|
|
const char *getPassName() const override {
|
|
|
|
return "Frontend instrumentation-based coverage lowering";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnModule(Module &M) override;
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.setPreservesCFG();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
InstrProfOptions Options;
|
|
|
|
Module *M;
|
|
|
|
DenseMap<GlobalVariable *, GlobalVariable *> RegionCounters;
|
|
|
|
std::vector<Value *> UsedVars;
|
|
|
|
|
|
|
|
bool isMachO() const {
|
|
|
|
return Triple(M->getTargetTriple()).isOSBinFormatMachO();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the section name for the counter variables.
|
|
|
|
StringRef getCountersSection() const {
|
2015-10-23 04:32:12 +08:00
|
|
|
return getInstrProfCountersSectionName(isMachO());
|
2014-12-09 02:02:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the section name for the name variables.
|
|
|
|
StringRef getNameSection() const {
|
2015-10-23 04:32:12 +08:00
|
|
|
return getInstrProfNameSectionName(isMachO());
|
2014-12-09 02:02:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the section name for the profile data variables.
|
|
|
|
StringRef getDataSection() const {
|
2015-10-23 04:32:12 +08:00
|
|
|
return getInstrProfDataSectionName(isMachO());
|
2014-12-09 02:02:35 +08:00
|
|
|
}
|
|
|
|
|
2015-02-11 10:52:44 +08:00
|
|
|
/// Get the section name for the coverage mapping data.
|
|
|
|
StringRef getCoverageSection() const {
|
2015-10-23 04:32:12 +08:00
|
|
|
return getInstrProfCoverageSectionName(isMachO());
|
2015-02-11 10:52:44 +08:00
|
|
|
}
|
|
|
|
|
2014-12-09 02:02:35 +08:00
|
|
|
/// Replace instrprof_increment with an increment of the appropriate value.
|
|
|
|
void lowerIncrement(InstrProfIncrementInst *Inc);
|
|
|
|
|
2015-02-11 10:52:44 +08:00
|
|
|
/// Set up the section and uses for coverage data and its references.
|
|
|
|
void lowerCoverageData(GlobalVariable *CoverageData);
|
|
|
|
|
2014-12-09 02:02:35 +08:00
|
|
|
/// Get the region counters for an increment, creating them if necessary.
|
|
|
|
///
|
|
|
|
/// If the counter array doesn't yet exist, the profile data variables
|
|
|
|
/// referring to them will also be created.
|
|
|
|
GlobalVariable *getOrCreateRegionCounters(InstrProfIncrementInst *Inc);
|
|
|
|
|
|
|
|
/// Emit runtime registration functions for each profile data variable.
|
|
|
|
void emitRegistration();
|
|
|
|
|
|
|
|
/// Emit the necessary plumbing to pull in the runtime initialization.
|
|
|
|
void emitRuntimeHook();
|
|
|
|
|
|
|
|
/// Add uses of our data variables and runtime hook.
|
|
|
|
void emitUses();
|
|
|
|
|
2015-05-01 07:49:23 +08:00
|
|
|
/// Create a static initializer for our data, on platforms that need it,
|
|
|
|
/// and for any profile output file that was specified.
|
2014-12-09 02:02:35 +08:00
|
|
|
void emitInitialization();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
char InstrProfiling::ID = 0;
|
|
|
|
INITIALIZE_PASS(InstrProfiling, "instrprof",
|
|
|
|
"Frontend instrumentation-based coverage lowering.", false,
|
|
|
|
false)
|
|
|
|
|
|
|
|
ModulePass *llvm::createInstrProfilingPass(const InstrProfOptions &Options) {
|
|
|
|
return new InstrProfiling(Options);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InstrProfiling::runOnModule(Module &M) {
|
|
|
|
bool MadeChange = false;
|
|
|
|
|
|
|
|
this->M = &M;
|
|
|
|
RegionCounters.clear();
|
|
|
|
UsedVars.clear();
|
|
|
|
|
|
|
|
for (Function &F : M)
|
|
|
|
for (BasicBlock &BB : F)
|
|
|
|
for (auto I = BB.begin(), E = BB.end(); I != E;)
|
|
|
|
if (auto *Inc = dyn_cast<InstrProfIncrementInst>(I++)) {
|
|
|
|
lowerIncrement(Inc);
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
2015-10-23 04:32:12 +08:00
|
|
|
if (GlobalVariable *Coverage =
|
|
|
|
M.getNamedGlobal(getCoverageMappingVarName())) {
|
2015-02-11 10:52:44 +08:00
|
|
|
lowerCoverageData(Coverage);
|
|
|
|
MadeChange = true;
|
|
|
|
}
|
2014-12-09 02:02:35 +08:00
|
|
|
if (!MadeChange)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
emitRegistration();
|
|
|
|
emitRuntimeHook();
|
|
|
|
emitUses();
|
|
|
|
emitInitialization();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
|
|
|
|
GlobalVariable *Counters = getOrCreateRegionCounters(Inc);
|
|
|
|
|
2015-10-14 01:39:10 +08:00
|
|
|
IRBuilder<> Builder(Inc);
|
2014-12-09 02:02:35 +08:00
|
|
|
uint64_t Index = Inc->getIndex()->getZExtValue();
|
2015-06-04 19:45:32 +08:00
|
|
|
Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index);
|
|
|
|
Value *Count = Builder.CreateLoad(Addr, "pgocount");
|
2014-12-09 02:02:35 +08:00
|
|
|
Count = Builder.CreateAdd(Count, Builder.getInt64(1));
|
|
|
|
Inc->replaceAllUsesWith(Builder.CreateStore(Count, Addr));
|
|
|
|
Inc->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
2015-02-11 10:52:44 +08:00
|
|
|
void InstrProfiling::lowerCoverageData(GlobalVariable *CoverageData) {
|
|
|
|
CoverageData->setSection(getCoverageSection());
|
|
|
|
CoverageData->setAlignment(8);
|
|
|
|
|
|
|
|
Constant *Init = CoverageData->getInitializer();
|
|
|
|
// We're expecting { i32, i32, i32, i32, [n x { i8*, i32, i32 }], [m x i8] }
|
|
|
|
// for some C. If not, the frontend's given us something broken.
|
|
|
|
assert(Init->getNumOperands() == 6 && "bad number of fields in coverage map");
|
|
|
|
assert(isa<ConstantArray>(Init->getAggregateElement(4)) &&
|
|
|
|
"invalid function list in coverage map");
|
|
|
|
ConstantArray *Records = cast<ConstantArray>(Init->getAggregateElement(4));
|
|
|
|
for (unsigned I = 0, E = Records->getNumOperands(); I < E; ++I) {
|
|
|
|
Constant *Record = Records->getOperand(I);
|
|
|
|
Value *V = const_cast<Value *>(Record->getOperand(0))->stripPointerCasts();
|
|
|
|
|
|
|
|
assert(isa<GlobalVariable>(V) && "Missing reference to function name");
|
|
|
|
GlobalVariable *Name = cast<GlobalVariable>(V);
|
|
|
|
|
|
|
|
// If we have region counters for this name, we've already handled it.
|
|
|
|
auto It = RegionCounters.find(Name);
|
|
|
|
if (It != RegionCounters.end())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Move the name variable to the right section.
|
|
|
|
Name->setSection(getNameSection());
|
|
|
|
Name->setAlignment(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 02:02:35 +08:00
|
|
|
/// Get the name of a profiling variable for a particular function.
|
2015-10-23 04:32:12 +08:00
|
|
|
static std::string getVarName(InstrProfIncrementInst *Inc, StringRef Prefix) {
|
2014-12-09 02:02:35 +08:00
|
|
|
auto *Arr = cast<ConstantDataArray>(Inc->getName()->getInitializer());
|
|
|
|
StringRef Name = Arr->isCString() ? Arr->getAsCString() : Arr->getAsString();
|
2015-10-23 04:32:12 +08:00
|
|
|
return (Prefix + Name).str();
|
2014-12-09 02:02:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GlobalVariable *
|
|
|
|
InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
|
|
|
|
GlobalVariable *Name = Inc->getName();
|
|
|
|
auto It = RegionCounters.find(Name);
|
|
|
|
if (It != RegionCounters.end())
|
|
|
|
return It->second;
|
|
|
|
|
2015-09-24 06:40:45 +08:00
|
|
|
// Move the name variable to the right section. Place them in a COMDAT group
|
|
|
|
// if the associated function is a COMDAT. This will make sure that
|
|
|
|
// only one copy of counters of the COMDAT function will be emitted after
|
|
|
|
// linking.
|
2015-05-28 03:34:01 +08:00
|
|
|
Function *Fn = Inc->getParent()->getParent();
|
2015-09-24 06:40:45 +08:00
|
|
|
Comdat *ProfileVarsComdat = nullptr;
|
|
|
|
if (Fn->hasComdat())
|
2015-10-23 04:32:12 +08:00
|
|
|
ProfileVarsComdat = M->getOrInsertComdat(
|
|
|
|
StringRef(getVarName(Inc, getInstrProfComdatPrefix())));
|
2014-12-09 02:02:35 +08:00
|
|
|
Name->setSection(getNameSection());
|
|
|
|
Name->setAlignment(1);
|
2015-09-24 06:40:45 +08:00
|
|
|
Name->setComdat(ProfileVarsComdat);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
uint64_t NumCounters = Inc->getNumCounters()->getZExtValue();
|
|
|
|
LLVMContext &Ctx = M->getContext();
|
|
|
|
ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);
|
|
|
|
|
|
|
|
// Create the counters variable.
|
2015-10-23 04:32:12 +08:00
|
|
|
auto *Counters =
|
|
|
|
new GlobalVariable(*M, CounterTy, false, Name->getLinkage(),
|
|
|
|
Constant::getNullValue(CounterTy),
|
|
|
|
getVarName(Inc, getInstrProfCountersVarPrefix()));
|
2014-12-09 02:02:35 +08:00
|
|
|
Counters->setVisibility(Name->getVisibility());
|
|
|
|
Counters->setSection(getCountersSection());
|
|
|
|
Counters->setAlignment(8);
|
2015-09-24 06:40:45 +08:00
|
|
|
Counters->setComdat(ProfileVarsComdat);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
RegionCounters[Inc->getName()] = Counters;
|
|
|
|
|
|
|
|
// Create data variable.
|
|
|
|
auto *NameArrayTy = Name->getType()->getPointerElementType();
|
|
|
|
auto *Int32Ty = Type::getInt32Ty(Ctx);
|
|
|
|
auto *Int64Ty = Type::getInt64Ty(Ctx);
|
|
|
|
auto *Int8PtrTy = Type::getInt8PtrTy(Ctx);
|
|
|
|
auto *Int64PtrTy = Type::getInt64PtrTy(Ctx);
|
|
|
|
|
|
|
|
Type *DataTypes[] = {Int32Ty, Int32Ty, Int64Ty, Int8PtrTy, Int64PtrTy};
|
|
|
|
auto *DataTy = StructType::get(Ctx, makeArrayRef(DataTypes));
|
|
|
|
Constant *DataVals[] = {
|
|
|
|
ConstantInt::get(Int32Ty, NameArrayTy->getArrayNumElements()),
|
|
|
|
ConstantInt::get(Int32Ty, NumCounters),
|
|
|
|
ConstantInt::get(Int64Ty, Inc->getHash()->getZExtValue()),
|
|
|
|
ConstantExpr::getBitCast(Name, Int8PtrTy),
|
|
|
|
ConstantExpr::getBitCast(Counters, Int64PtrTy)};
|
|
|
|
auto *Data = new GlobalVariable(*M, DataTy, true, Name->getLinkage(),
|
|
|
|
ConstantStruct::get(DataTy, DataVals),
|
2015-10-23 04:32:12 +08:00
|
|
|
getVarName(Inc, getInstrProfDataVarPrefix()));
|
2014-12-09 02:02:35 +08:00
|
|
|
Data->setVisibility(Name->getVisibility());
|
|
|
|
Data->setSection(getDataSection());
|
|
|
|
Data->setAlignment(8);
|
2015-09-24 06:40:45 +08:00
|
|
|
Data->setComdat(ProfileVarsComdat);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
// Mark the data variable as used so that it isn't stripped out.
|
|
|
|
UsedVars.push_back(Data);
|
|
|
|
|
|
|
|
return Counters;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstrProfiling::emitRegistration() {
|
|
|
|
// Don't do this for Darwin. compiler-rt uses linker magic.
|
|
|
|
if (Triple(M->getTargetTriple()).isOSDarwin())
|
|
|
|
return;
|
|
|
|
|
2015-10-14 02:39:48 +08:00
|
|
|
// Use linker script magic to get data/cnts/name start/end.
|
2015-10-19 12:17:10 +08:00
|
|
|
if (Triple(M->getTargetTriple()).isOSLinux() ||
|
|
|
|
Triple(M->getTargetTriple()).isOSFreeBSD())
|
|
|
|
return;
|
2015-10-14 02:39:48 +08:00
|
|
|
|
2014-12-09 02:02:35 +08:00
|
|
|
// Construct the function.
|
|
|
|
auto *VoidTy = Type::getVoidTy(M->getContext());
|
|
|
|
auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
|
|
|
|
auto *RegisterFTy = FunctionType::get(VoidTy, false);
|
|
|
|
auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage,
|
2015-10-23 12:22:58 +08:00
|
|
|
getInstrProfRegFuncsName(), M);
|
2014-12-09 02:02:35 +08:00
|
|
|
RegisterF->setUnnamedAddr(true);
|
2015-10-23 12:22:58 +08:00
|
|
|
if (Options.NoRedZone) RegisterF->addFnAttr(Attribute::NoRedZone);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
2015-06-04 19:45:32 +08:00
|
|
|
auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false);
|
2014-12-09 02:02:35 +08:00
|
|
|
auto *RuntimeRegisterF =
|
|
|
|
Function::Create(RuntimeRegisterTy, GlobalVariable::ExternalLinkage,
|
2015-10-23 12:22:58 +08:00
|
|
|
getInstrProfRegFuncName(), M);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
|
|
|
|
for (Value *Data : UsedVars)
|
|
|
|
IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
|
|
|
|
IRB.CreateRetVoid();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstrProfiling::emitRuntimeHook() {
|
|
|
|
|
2015-10-29 12:08:31 +08:00
|
|
|
// We expect the linker to be invoked with -u<hook_var> flag for linux,
|
|
|
|
// for which case there is no need to emit the user function.
|
|
|
|
if (Triple(M->getTargetTriple()).isOSLinux())
|
|
|
|
return;
|
|
|
|
|
2014-12-09 02:02:35 +08:00
|
|
|
// If the module's provided its own runtime, we don't need to do anything.
|
2015-10-23 12:22:58 +08:00
|
|
|
if (M->getGlobalVariable(getInstrProfRuntimeHookVarName())) return;
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
// Declare an external variable that will pull in the runtime initialization.
|
|
|
|
auto *Int32Ty = Type::getInt32Ty(M->getContext());
|
|
|
|
auto *Var =
|
|
|
|
new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
|
2015-10-23 12:22:58 +08:00
|
|
|
nullptr, getInstrProfRuntimeHookVarName());
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
// Make a function that uses it.
|
2015-10-23 12:22:58 +08:00
|
|
|
auto *User = Function::Create(FunctionType::get(Int32Ty, false),
|
|
|
|
GlobalValue::LinkOnceODRLinkage,
|
|
|
|
getInstrProfRuntimeHookVarUseFuncName(), M);
|
2014-12-09 02:02:35 +08:00
|
|
|
User->addFnAttr(Attribute::NoInline);
|
2015-10-23 12:22:58 +08:00
|
|
|
if (Options.NoRedZone) User->addFnAttr(Attribute::NoRedZone);
|
2015-02-26 06:52:20 +08:00
|
|
|
User->setVisibility(GlobalValue::HiddenVisibility);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
|
|
|
|
auto *Load = IRB.CreateLoad(Var);
|
|
|
|
IRB.CreateRet(Load);
|
|
|
|
|
|
|
|
// Mark the user variable as used so that it isn't stripped out.
|
|
|
|
UsedVars.push_back(User);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstrProfiling::emitUses() {
|
|
|
|
if (UsedVars.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
GlobalVariable *LLVMUsed = M->getGlobalVariable("llvm.used");
|
2015-06-04 19:45:32 +08:00
|
|
|
std::vector<Constant *> MergedVars;
|
2014-12-09 02:02:35 +08:00
|
|
|
if (LLVMUsed) {
|
|
|
|
// Collect the existing members of llvm.used.
|
|
|
|
ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer());
|
|
|
|
for (unsigned I = 0, E = Inits->getNumOperands(); I != E; ++I)
|
|
|
|
MergedVars.push_back(Inits->getOperand(I));
|
|
|
|
LLVMUsed->eraseFromParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
Type *i8PTy = Type::getInt8PtrTy(M->getContext());
|
|
|
|
// Add uses for our data.
|
|
|
|
for (auto *Value : UsedVars)
|
|
|
|
MergedVars.push_back(
|
2015-06-04 19:45:32 +08:00
|
|
|
ConstantExpr::getBitCast(cast<Constant>(Value), i8PTy));
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
// Recreate llvm.used.
|
|
|
|
ArrayType *ATy = ArrayType::get(i8PTy, MergedVars.size());
|
2015-06-04 19:45:32 +08:00
|
|
|
LLVMUsed =
|
|
|
|
new GlobalVariable(*M, ATy, false, GlobalValue::AppendingLinkage,
|
|
|
|
ConstantArray::get(ATy, MergedVars), "llvm.used");
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
LLVMUsed->setSection("llvm.metadata");
|
|
|
|
}
|
|
|
|
|
|
|
|
void InstrProfiling::emitInitialization() {
|
2015-05-01 07:49:23 +08:00
|
|
|
std::string InstrProfileOutput = Options.InstrProfileOutput;
|
|
|
|
|
2015-10-23 12:22:58 +08:00
|
|
|
Constant *RegisterF = M->getFunction(getInstrProfRegFuncsName());
|
|
|
|
if (!RegisterF && InstrProfileOutput.empty()) return;
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
// Create the initialization function.
|
|
|
|
auto *VoidTy = Type::getVoidTy(M->getContext());
|
2015-10-23 12:22:58 +08:00
|
|
|
auto *F = Function::Create(FunctionType::get(VoidTy, false),
|
|
|
|
GlobalValue::InternalLinkage,
|
|
|
|
getInstrProfInitFuncName(), M);
|
2014-12-09 02:02:35 +08:00
|
|
|
F->setUnnamedAddr(true);
|
|
|
|
F->addFnAttr(Attribute::NoInline);
|
2015-10-23 12:22:58 +08:00
|
|
|
if (Options.NoRedZone) F->addFnAttr(Attribute::NoRedZone);
|
2014-12-09 02:02:35 +08:00
|
|
|
|
|
|
|
// Add the basic block and the necessary calls.
|
|
|
|
IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
|
2015-05-01 07:49:23 +08:00
|
|
|
if (RegisterF)
|
2015-05-19 06:13:54 +08:00
|
|
|
IRB.CreateCall(RegisterF, {});
|
2015-05-01 07:49:23 +08:00
|
|
|
if (!InstrProfileOutput.empty()) {
|
|
|
|
auto *Int8PtrTy = Type::getInt8PtrTy(M->getContext());
|
|
|
|
auto *SetNameTy = FunctionType::get(VoidTy, Int8PtrTy, false);
|
2015-10-23 12:22:58 +08:00
|
|
|
auto *SetNameF = Function::Create(SetNameTy, GlobalValue::ExternalLinkage,
|
|
|
|
getInstrProfFileOverriderFuncName(), M);
|
2015-05-01 07:49:23 +08:00
|
|
|
|
2015-06-30 04:03:46 +08:00
|
|
|
// Create variable for profile name.
|
2015-05-01 07:49:23 +08:00
|
|
|
Constant *ProfileNameConst =
|
|
|
|
ConstantDataArray::getString(M->getContext(), InstrProfileOutput, true);
|
|
|
|
GlobalVariable *ProfileName =
|
|
|
|
new GlobalVariable(*M, ProfileNameConst->getType(), true,
|
|
|
|
GlobalValue::PrivateLinkage, ProfileNameConst);
|
|
|
|
|
|
|
|
IRB.CreateCall(SetNameF, IRB.CreatePointerCast(ProfileName, Int8PtrTy));
|
|
|
|
}
|
2014-12-09 02:02:35 +08:00
|
|
|
IRB.CreateRetVoid();
|
|
|
|
|
|
|
|
appendToGlobalCtors(*M, F, 0);
|
|
|
|
}
|