blob: 37f88d5f95f18006eaf459e6962247f86f631bee [file] [log] [blame]
Justin Bogner61ba2e32014-12-08 18:02:35 +00001//===-- InstrProfiling.cpp - Frontend instrumentation based profiling -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000010// This pass lowers instrprof_* intrinsics emitted by a frontend for profiling.
11// It also builds the data structures and initialization code needed for
12// updating execution counts and emitting the profile at runtime.
Justin Bogner61ba2e32014-12-08 18:02:35 +000013//
14//===----------------------------------------------------------------------===//
15
Xinliang David Li69a00f02016-06-21 02:39:08 +000016#include "llvm/Transforms/InstrProfiling.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000017#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringRef.h"
Justin Bogner61ba2e32014-12-08 18:02:35 +000020#include "llvm/ADT/Triple.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000021#include "llvm/ADT/Twine.h"
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +000022#include "llvm/Analysis/TargetLibraryInfo.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000023#include "llvm/IR/Attributes.h"
24#include "llvm/IR/BasicBlock.h"
25#include "llvm/IR/Constant.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DerivedTypes.h"
28#include "llvm/IR/Function.h"
29#include "llvm/IR/GlobalValue.h"
30#include "llvm/IR/GlobalVariable.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000031#include "llvm/IR/IRBuilder.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000032#include "llvm/IR/Instruction.h"
33#include "llvm/IR/Instructions.h"
Justin Bogner61ba2e32014-12-08 18:02:35 +000034#include "llvm/IR/IntrinsicInst.h"
35#include "llvm/IR/Module.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000036#include "llvm/IR/Type.h"
37#include "llvm/Pass.h"
Betul Buyukkurt6fac1742015-11-18 18:14:55 +000038#include "llvm/ProfileData/InstrProf.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000039#include "llvm/Support/Casting.h"
40#include "llvm/Support/CommandLine.h"
41#include "llvm/Support/Error.h"
42#include "llvm/Support/ErrorHandling.h"
Justin Bogner61ba2e32014-12-08 18:02:35 +000043#include "llvm/Transforms/Utils/ModuleUtils.h"
Eugene Zelenko34c23272017-01-18 00:57:48 +000044#include <algorithm>
45#include <cassert>
46#include <cstddef>
47#include <cstdint>
48#include <string>
Justin Bogner61ba2e32014-12-08 18:02:35 +000049
50using namespace llvm;
51
52#define DEBUG_TYPE "instrprof"
53
Rong Xu48596b62017-04-04 16:42:20 +000054// The start and end values of precise value profile range for memory
55// intrinsic sizes
56cl::opt<std::string> MemOPSizeRange(
57 "memop-size-range",
58 cl::desc("Set the range of size in memory intrinsic calls to be profiled "
59 "precisely, in a format of <start_val>:<end_val>"),
60 cl::init(""));
61
62// The value that considered to be large value in memory intrinsic.
63cl::opt<unsigned> MemOPSizeLarge(
64 "memop-size-large",
65 cl::desc("Set large value thresthold in memory intrinsic size profiling. "
66 "Value of 0 disables the large value profiling."),
67 cl::init(8192));
68
Justin Bogner61ba2e32014-12-08 18:02:35 +000069namespace {
70
Xinliang David Lia82d6c02016-02-08 18:13:49 +000071cl::opt<bool> DoNameCompression("enable-name-compression",
72 cl::desc("Enable name string compression"),
73 cl::init(true));
74
Rong Xu20f5df12017-01-11 20:19:41 +000075cl::opt<bool> DoHashBasedCounterSplit(
76 "hash-based-counter-split",
77 cl::desc("Rename counter variable of a comdat function based on cfg hash"),
78 cl::init(true));
79
Xinliang David Lib628dd32016-05-21 22:55:34 +000080cl::opt<bool> ValueProfileStaticAlloc(
81 "vp-static-alloc",
82 cl::desc("Do static counter allocation for value profiler"),
83 cl::init(true));
Eugene Zelenko34c23272017-01-18 00:57:48 +000084
Xinliang David Lib628dd32016-05-21 22:55:34 +000085cl::opt<double> NumCountersPerValueSite(
86 "vp-counters-per-site",
87 cl::desc("The average number of profile counters allocated "
88 "per value profiling site."),
89 // This is set to a very small value because in real programs, only
90 // a very small percentage of value sites have non-zero targets, e.g, 1/30.
91 // For those sites with non-zero profile, the average number of targets
92 // is usually smaller than 2.
93 cl::init(1.0));
94
Xinliang David Lie6b89292016-04-18 17:47:38 +000095class InstrProfilingLegacyPass : public ModulePass {
96 InstrProfiling InstrProf;
97
Justin Bogner61ba2e32014-12-08 18:02:35 +000098public:
99 static char ID;
Eugene Zelenko34c23272017-01-18 00:57:48 +0000100
101 InstrProfilingLegacyPass() : ModulePass(ID) {}
Xinliang David Lie6b89292016-04-18 17:47:38 +0000102 InstrProfilingLegacyPass(const InstrProfOptions &Options)
103 : ModulePass(ID), InstrProf(Options) {}
Eugene Zelenko34c23272017-01-18 00:57:48 +0000104
Mehdi Amini117296c2016-10-01 02:56:57 +0000105 StringRef getPassName() const override {
Justin Bogner61ba2e32014-12-08 18:02:35 +0000106 return "Frontend instrumentation-based coverage lowering";
107 }
108
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000109 bool runOnModule(Module &M) override {
110 return InstrProf.run(M, getAnalysis<TargetLibraryInfoWrapperPass>().getTLI());
111 }
Justin Bogner61ba2e32014-12-08 18:02:35 +0000112
113 void getAnalysisUsage(AnalysisUsage &AU) const override {
114 AU.setPreservesCFG();
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000115 AU.addRequired<TargetLibraryInfoWrapperPass>();
Justin Bogner61ba2e32014-12-08 18:02:35 +0000116 }
Justin Bogner61ba2e32014-12-08 18:02:35 +0000117};
118
Eugene Zelenko34c23272017-01-18 00:57:48 +0000119} // end anonymous namespace
Justin Bogner61ba2e32014-12-08 18:02:35 +0000120
Sean Silvafd03ac62016-08-09 00:28:38 +0000121PreservedAnalyses InstrProfiling::run(Module &M, ModuleAnalysisManager &AM) {
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000122 auto &TLI = AM.getResult<TargetLibraryAnalysis>(M);
123 if (!run(M, TLI))
Xinliang David Lie6b89292016-04-18 17:47:38 +0000124 return PreservedAnalyses::all();
125
126 return PreservedAnalyses::none();
127}
128
129char InstrProfilingLegacyPass::ID = 0;
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000130INITIALIZE_PASS_BEGIN(
131 InstrProfilingLegacyPass, "instrprof",
132 "Frontend instrumentation-based coverage lowering.", false, false)
133INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
134INITIALIZE_PASS_END(
135 InstrProfilingLegacyPass, "instrprof",
136 "Frontend instrumentation-based coverage lowering.", false, false)
Justin Bogner61ba2e32014-12-08 18:02:35 +0000137
Xinliang David Li69a00f02016-06-21 02:39:08 +0000138ModulePass *
139llvm::createInstrProfilingLegacyPass(const InstrProfOptions &Options) {
Xinliang David Lie6b89292016-04-18 17:47:38 +0000140 return new InstrProfilingLegacyPass(Options);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000141}
142
Xinliang David Li4ca17332016-09-18 18:34:07 +0000143static InstrProfIncrementInst *castToIncrementInst(Instruction *Instr) {
144 InstrProfIncrementInst *Inc = dyn_cast<InstrProfIncrementInstStep>(Instr);
145 if (Inc)
146 return Inc;
147 return dyn_cast<InstrProfIncrementInst>(Instr);
148}
149
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000150bool InstrProfiling::run(Module &M, const TargetLibraryInfo &TLI) {
Justin Bogner61ba2e32014-12-08 18:02:35 +0000151 bool MadeChange = false;
152
153 this->M = &M;
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000154 this->TLI = &TLI;
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000155 NamesVar = nullptr;
156 NamesSize = 0;
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000157 ProfileDataMap.clear();
Justin Bogner61ba2e32014-12-08 18:02:35 +0000158 UsedVars.clear();
Rong Xu48596b62017-04-04 16:42:20 +0000159 getMemOPSizeRangeFromOption(MemOPSizeRange, MemOPSizeRangeStart,
160 MemOPSizeRangeLast);
Vedant Kumar1a6a2b62017-04-15 00:09:57 +0000161 TT = Triple(M.getTargetTriple());
Justin Bogner61ba2e32014-12-08 18:02:35 +0000162
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000163 // We did not know how many value sites there would be inside
164 // the instrumented function. This is counting the number of instrumented
165 // target value sites to enter it as field in the profile data variable.
Rong Xu294572f2016-01-19 18:29:54 +0000166 for (Function &F : M) {
167 InstrProfIncrementInst *FirstProfIncInst = nullptr;
Justin Bogner61ba2e32014-12-08 18:02:35 +0000168 for (BasicBlock &BB : F)
Rong Xu294572f2016-01-19 18:29:54 +0000169 for (auto I = BB.begin(), E = BB.end(); I != E; I++)
170 if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I))
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000171 computeNumValueSiteCounts(Ind);
Rong Xu294572f2016-01-19 18:29:54 +0000172 else if (FirstProfIncInst == nullptr)
173 FirstProfIncInst = dyn_cast<InstrProfIncrementInst>(I);
174
175 // Value profiling intrinsic lowering requires per-function profile data
176 // variable to be created first.
177 if (FirstProfIncInst != nullptr)
178 static_cast<void>(getOrCreateRegionCounters(FirstProfIncInst));
179 }
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000180
181 for (Function &F : M)
182 for (BasicBlock &BB : F)
183 for (auto I = BB.begin(), E = BB.end(); I != E;) {
184 auto Instr = I++;
Xinliang David Li4ca17332016-09-18 18:34:07 +0000185 InstrProfIncrementInst *Inc = castToIncrementInst(&*Instr);
186 if (Inc) {
Justin Bogner61ba2e32014-12-08 18:02:35 +0000187 lowerIncrement(Inc);
188 MadeChange = true;
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000189 } else if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(Instr)) {
190 lowerValueProfileInst(Ind);
191 MadeChange = true;
Justin Bogner61ba2e32014-12-08 18:02:35 +0000192 }
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000193 }
194
Xinliang David Li81056072016-01-07 20:05:49 +0000195 if (GlobalVariable *CoverageNamesVar =
Xinliang David Li440cd702016-01-20 00:24:36 +0000196 M.getNamedGlobal(getCoverageUnusedNamesVarName())) {
Xinliang David Li81056072016-01-07 20:05:49 +0000197 lowerCoverageData(CoverageNamesVar);
Justin Bognerd24e1852015-02-11 02:52:44 +0000198 MadeChange = true;
199 }
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000200
Justin Bogner61ba2e32014-12-08 18:02:35 +0000201 if (!MadeChange)
202 return false;
203
Xinliang David Lib628dd32016-05-21 22:55:34 +0000204 emitVNodes();
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000205 emitNameData();
Justin Bogner61ba2e32014-12-08 18:02:35 +0000206 emitRegistration();
207 emitRuntimeHook();
208 emitUses();
209 emitInitialization();
210 return true;
211}
212
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000213static Constant *getOrInsertValueProfilingCall(Module &M,
Rong Xu60faea12017-03-16 21:15:48 +0000214 const TargetLibraryInfo &TLI,
215 bool IsRange = false) {
Xinliang David Lic7673232015-11-22 00:22:07 +0000216 LLVMContext &Ctx = M.getContext();
217 auto *ReturnTy = Type::getVoidTy(M.getContext());
Rong Xu60faea12017-03-16 21:15:48 +0000218
219 Constant *Res;
220 if (!IsRange) {
221 Type *ParamTypes[] = {
Xinliang David Lic7673232015-11-22 00:22:07 +0000222#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
223#include "llvm/ProfileData/InstrProfData.inc"
Rong Xu60faea12017-03-16 21:15:48 +0000224 };
225 auto *ValueProfilingCallTy =
226 FunctionType::get(ReturnTy, makeArrayRef(ParamTypes), false);
227 Res = M.getOrInsertFunction(getInstrProfValueProfFuncName(),
228 ValueProfilingCallTy);
229 } else {
230 Type *RangeParamTypes[] = {
231#define VALUE_RANGE_PROF 1
232#define VALUE_PROF_FUNC_PARAM(ParamType, ParamName, ParamLLVMType) ParamLLVMType
233#include "llvm/ProfileData/InstrProfData.inc"
234#undef VALUE_RANGE_PROF
235 };
236 auto *ValueRangeProfilingCallTy =
237 FunctionType::get(ReturnTy, makeArrayRef(RangeParamTypes), false);
238 Res = M.getOrInsertFunction(getInstrProfValueRangeProfFuncName(),
239 ValueRangeProfilingCallTy);
240 }
241
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000242 if (Function *FunRes = dyn_cast<Function>(Res)) {
243 if (auto AK = TLI.getExtAttrForI32Param(false))
Reid Klecknera0b45f42017-05-03 18:17:31 +0000244 FunRes->addParamAttr(2, AK);
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000245 }
246 return Res;
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000247}
248
249void InstrProfiling::computeNumValueSiteCounts(InstrProfValueProfileInst *Ind) {
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000250 GlobalVariable *Name = Ind->getName();
251 uint64_t ValueKind = Ind->getValueKind()->getZExtValue();
252 uint64_t Index = Ind->getIndex()->getZExtValue();
253 auto It = ProfileDataMap.find(Name);
254 if (It == ProfileDataMap.end()) {
255 PerFunctionProfileData PD;
256 PD.NumValueSites[ValueKind] = Index + 1;
257 ProfileDataMap[Name] = PD;
258 } else if (It->second.NumValueSites[ValueKind] <= Index)
259 It->second.NumValueSites[ValueKind] = Index + 1;
260}
261
262void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000263 GlobalVariable *Name = Ind->getName();
264 auto It = ProfileDataMap.find(Name);
265 assert(It != ProfileDataMap.end() && It->second.DataVar &&
Xinliang David Li69a00f02016-06-21 02:39:08 +0000266 "value profiling detected in function with no counter incerement");
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000267
268 GlobalVariable *DataVar = It->second.DataVar;
269 uint64_t ValueKind = Ind->getValueKind()->getZExtValue();
270 uint64_t Index = Ind->getIndex()->getZExtValue();
271 for (uint32_t Kind = IPVK_First; Kind < ValueKind; ++Kind)
272 Index += It->second.NumValueSites[Kind];
273
274 IRBuilder<> Builder(Ind);
Rong Xu60faea12017-03-16 21:15:48 +0000275 bool IsRange = (Ind->getValueKind()->getZExtValue() ==
276 llvm::InstrProfValueKind::IPVK_MemOPSize);
277 CallInst *Call = nullptr;
278 if (!IsRange) {
279 Value *Args[3] = {Ind->getTargetValue(),
280 Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
281 Builder.getInt32(Index)};
282 Call = Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI), Args);
283 } else {
Rong Xu48596b62017-04-04 16:42:20 +0000284 Value *Args[6] = {
285 Ind->getTargetValue(),
286 Builder.CreateBitCast(DataVar, Builder.getInt8PtrTy()),
287 Builder.getInt32(Index),
288 Builder.getInt64(MemOPSizeRangeStart),
289 Builder.getInt64(MemOPSizeRangeLast),
290 Builder.getInt64(MemOPSizeLarge == 0 ? INT64_MIN : MemOPSizeLarge)};
Rong Xu60faea12017-03-16 21:15:48 +0000291 Call =
292 Builder.CreateCall(getOrInsertValueProfilingCall(*M, *TLI, true), Args);
293 }
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000294 if (auto AK = TLI->getExtAttrForI32Param(false))
Reid Klecknera0b45f42017-05-03 18:17:31 +0000295 Call->addParamAttr(2, AK);
Marcin Koscielnicki1c2bd1e2016-11-21 11:57:19 +0000296 Ind->replaceAllUsesWith(Call);
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000297 Ind->eraseFromParent();
298}
299
Justin Bogner61ba2e32014-12-08 18:02:35 +0000300void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
301 GlobalVariable *Counters = getOrCreateRegionCounters(Inc);
302
Duncan P. N. Exon Smithe82c2862015-10-13 17:39:10 +0000303 IRBuilder<> Builder(Inc);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000304 uint64_t Index = Inc->getIndex()->getZExtValue();
Diego Novillob3029d22015-06-04 11:45:32 +0000305 Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index);
306 Value *Count = Builder.CreateLoad(Addr, "pgocount");
Xinliang David Lia754c472016-09-20 19:07:22 +0000307 Count = Builder.CreateAdd(Count, Inc->getStep());
Justin Bogner61ba2e32014-12-08 18:02:35 +0000308 Inc->replaceAllUsesWith(Builder.CreateStore(Count, Addr));
309 Inc->eraseFromParent();
310}
311
Xinliang David Li81056072016-01-07 20:05:49 +0000312void InstrProfiling::lowerCoverageData(GlobalVariable *CoverageNamesVar) {
Xinliang David Li81056072016-01-07 20:05:49 +0000313 ConstantArray *Names =
314 cast<ConstantArray>(CoverageNamesVar->getInitializer());
315 for (unsigned I = 0, E = Names->getNumOperands(); I < E; ++I) {
316 Constant *NC = Names->getOperand(I);
317 Value *V = NC->stripPointerCasts();
Justin Bognerd24e1852015-02-11 02:52:44 +0000318 assert(isa<GlobalVariable>(V) && "Missing reference to function name");
319 GlobalVariable *Name = cast<GlobalVariable>(V);
320
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000321 Name->setLinkage(GlobalValue::PrivateLinkage);
322 ReferencedNames.push_back(Name);
Vedant Kumar55891fc2017-02-14 20:03:48 +0000323 NC->dropAllReferences();
Justin Bognerd24e1852015-02-11 02:52:44 +0000324 }
Vedant Kumar55891fc2017-02-14 20:03:48 +0000325 CoverageNamesVar->eraseFromParent();
Justin Bognerd24e1852015-02-11 02:52:44 +0000326}
327
Justin Bogner61ba2e32014-12-08 18:02:35 +0000328/// Get the name of a profiling variable for a particular function.
Xinliang David Li83bc4222015-10-22 20:32:12 +0000329static std::string getVarName(InstrProfIncrementInst *Inc, StringRef Prefix) {
Xinliang David Lid1bab962015-12-12 17:28:03 +0000330 StringRef NamePrefix = getInstrProfNameVarPrefix();
331 StringRef Name = Inc->getName()->getName().substr(NamePrefix.size());
Rong Xu20f5df12017-01-11 20:19:41 +0000332 Function *F = Inc->getParent()->getParent();
333 Module *M = F->getParent();
334 if (!DoHashBasedCounterSplit || !isIRPGOFlagSet(M) ||
335 !canRenameComdatFunc(*F))
336 return (Prefix + Name).str();
337 uint64_t FuncHash = Inc->getHash()->getZExtValue();
338 SmallVector<char, 24> HashPostfix;
339 if (Name.endswith((Twine(".") + Twine(FuncHash)).toStringRef(HashPostfix)))
340 return (Prefix + Name).str();
341 return (Prefix + Name + "." + Twine(FuncHash)).str();
Justin Bogner61ba2e32014-12-08 18:02:35 +0000342}
343
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000344static inline bool shouldRecordFunctionAddr(Function *F) {
345 // Check the linkage
Vedant Kumar9c056c92017-06-13 22:12:35 +0000346 bool HasAvailableExternallyLinkage = F->hasAvailableExternallyLinkage();
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000347 if (!F->hasLinkOnceLinkage() && !F->hasLocalLinkage() &&
Vedant Kumar9c056c92017-06-13 22:12:35 +0000348 !HasAvailableExternallyLinkage)
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000349 return true;
Vedant Kumar9c056c92017-06-13 22:12:35 +0000350
351 // A function marked 'alwaysinline' with available_externally linkage can't
352 // have its address taken. Doing so would create an undefined external ref to
353 // the function, which would fail to link.
354 if (HasAvailableExternallyLinkage &&
355 F->hasFnAttribute(Attribute::AlwaysInline))
356 return false;
357
Rong Xuaf5aeba2016-04-27 21:17:30 +0000358 // Prohibit function address recording if the function is both internal and
359 // COMDAT. This avoids the profile data variable referencing internal symbols
360 // in COMDAT.
361 if (F->hasLocalLinkage() && F->hasComdat())
362 return false;
Vedant Kumar9c056c92017-06-13 22:12:35 +0000363
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000364 // Check uses of this function for other than direct calls or invokes to it.
Xinliang David Li7008ce32016-06-02 16:33:41 +0000365 // Inline virtual functions have linkeOnceODR linkage. When a key method
366 // exists, the vtable will only be emitted in the TU where the key method
367 // is defined. In a TU where vtable is not available, the function won't
Xinliang David Li6c44e9e2016-06-03 23:02:28 +0000368 // be 'addresstaken'. If its address is not recorded here, the profile data
Xinliang David Li69a00f02016-06-21 02:39:08 +0000369 // with missing address may be picked by the linker leading to missing
Xinliang David Li6c44e9e2016-06-03 23:02:28 +0000370 // indirect call target info.
371 return F->hasAddressTaken() || F->hasLinkOnceLinkage();
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000372}
373
Xinliang David Li985ff202016-02-27 23:11:30 +0000374static inline Comdat *getOrCreateProfileComdat(Module &M, Function &F,
Xinliang David Liab361ef2015-12-21 21:52:27 +0000375 InstrProfIncrementInst *Inc) {
Xinliang David Li985ff202016-02-27 23:11:30 +0000376 if (!needsComdatForCounter(F, M))
377 return nullptr;
378
Xinliang David Liab361ef2015-12-21 21:52:27 +0000379 // COFF format requires a COMDAT section to have a key symbol with the same
Vedant Kumar2d5b5d32016-02-03 23:22:43 +0000380 // name. The linker targeting COFF also requires that the COMDAT
Xinliang David Li5fe04552015-12-22 00:11:15 +0000381 // a section is associated to must precede the associating section. For this
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000382 // reason, we must choose the counter var's name as the name of the comdat.
Xinliang David Liab361ef2015-12-21 21:52:27 +0000383 StringRef ComdatPrefix = (Triple(M.getTargetTriple()).isOSBinFormatCOFF()
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000384 ? getInstrProfCountersVarPrefix()
Xinliang David Liab361ef2015-12-21 21:52:27 +0000385 : getInstrProfComdatPrefix());
386 return M.getOrInsertComdat(StringRef(getVarName(Inc, ComdatPrefix)));
387}
388
Xinliang David Lib628dd32016-05-21 22:55:34 +0000389static bool needsRuntimeRegistrationOfSectionRange(const Module &M) {
390 // Don't do this for Darwin. compiler-rt uses linker magic.
391 if (Triple(M.getTargetTriple()).isOSDarwin())
392 return false;
393
394 // Use linker script magic to get data/cnts/name start/end.
395 if (Triple(M.getTargetTriple()).isOSLinux() ||
396 Triple(M.getTargetTriple()).isOSFreeBSD() ||
397 Triple(M.getTargetTriple()).isPS4CPU())
398 return false;
399
400 return true;
401}
402
Justin Bogner61ba2e32014-12-08 18:02:35 +0000403GlobalVariable *
404InstrProfiling::getOrCreateRegionCounters(InstrProfIncrementInst *Inc) {
Xinliang David Li192c7482015-11-05 00:47:26 +0000405 GlobalVariable *NamePtr = Inc->getName();
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000406 auto It = ProfileDataMap.find(NamePtr);
407 PerFunctionProfileData PD;
408 if (It != ProfileDataMap.end()) {
409 if (It->second.RegionCounters)
410 return It->second.RegionCounters;
411 PD = It->second;
412 }
Justin Bogner61ba2e32014-12-08 18:02:35 +0000413
Wei Mi3cc92042015-09-23 22:40:45 +0000414 // Move the name variable to the right section. Place them in a COMDAT group
415 // if the associated function is a COMDAT. This will make sure that
416 // only one copy of counters of the COMDAT function will be emitted after
417 // linking.
Diego Novillodf4837b2015-05-27 19:34:01 +0000418 Function *Fn = Inc->getParent()->getParent();
Wei Mi3cc92042015-09-23 22:40:45 +0000419 Comdat *ProfileVarsComdat = nullptr;
Xinliang David Li985ff202016-02-27 23:11:30 +0000420 ProfileVarsComdat = getOrCreateProfileComdat(*M, *Fn, Inc);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000421
422 uint64_t NumCounters = Inc->getNumCounters()->getZExtValue();
423 LLVMContext &Ctx = M->getContext();
424 ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(Ctx), NumCounters);
425
426 // Create the counters variable.
Xinliang David Li192c7482015-11-05 00:47:26 +0000427 auto *CounterPtr =
428 new GlobalVariable(*M, CounterTy, false, NamePtr->getLinkage(),
Xinliang David Li83bc4222015-10-22 20:32:12 +0000429 Constant::getNullValue(CounterTy),
430 getVarName(Inc, getInstrProfCountersVarPrefix()));
Xinliang David Li192c7482015-11-05 00:47:26 +0000431 CounterPtr->setVisibility(NamePtr->getVisibility());
Vedant Kumar1a6a2b62017-04-15 00:09:57 +0000432 CounterPtr->setSection(
433 getInstrProfSectionName(IPSK_cnts, TT.getObjectFormat()));
Xinliang David Li192c7482015-11-05 00:47:26 +0000434 CounterPtr->setAlignment(8);
435 CounterPtr->setComdat(ProfileVarsComdat);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000436
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000437 auto *Int8PtrTy = Type::getInt8PtrTy(Ctx);
Xinliang David Lib628dd32016-05-21 22:55:34 +0000438 // Allocate statically the array of pointers to value profile nodes for
439 // the current function.
440 Constant *ValuesPtrExpr = ConstantPointerNull::get(Int8PtrTy);
441 if (ValueProfileStaticAlloc && !needsRuntimeRegistrationOfSectionRange(*M)) {
Xinliang David Lib628dd32016-05-21 22:55:34 +0000442 uint64_t NS = 0;
443 for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
444 NS += PD.NumValueSites[Kind];
445 if (NS) {
446 ArrayType *ValuesTy = ArrayType::get(Type::getInt64Ty(Ctx), NS);
447
448 auto *ValuesVar =
449 new GlobalVariable(*M, ValuesTy, false, NamePtr->getLinkage(),
450 Constant::getNullValue(ValuesTy),
451 getVarName(Inc, getInstrProfValuesVarPrefix()));
452 ValuesVar->setVisibility(NamePtr->getVisibility());
Vedant Kumar1a6a2b62017-04-15 00:09:57 +0000453 ValuesVar->setSection(
454 getInstrProfSectionName(IPSK_vals, TT.getObjectFormat()));
Xinliang David Lib628dd32016-05-21 22:55:34 +0000455 ValuesVar->setAlignment(8);
456 ValuesVar->setComdat(ProfileVarsComdat);
457 ValuesPtrExpr =
Eugene Zelenko34c23272017-01-18 00:57:48 +0000458 ConstantExpr::getBitCast(ValuesVar, Type::getInt8PtrTy(Ctx));
Xinliang David Lib628dd32016-05-21 22:55:34 +0000459 }
460 }
461
462 // Create data variable.
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000463 auto *Int16Ty = Type::getInt16Ty(Ctx);
Xinliang David Lib628dd32016-05-21 22:55:34 +0000464 auto *Int16ArrayTy = ArrayType::get(Int16Ty, IPVK_Last + 1);
Xinliang David Li192c7482015-11-05 00:47:26 +0000465 Type *DataTypes[] = {
Xinliang David Li69a00f02016-06-21 02:39:08 +0000466#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) LLVMType,
467#include "llvm/ProfileData/InstrProfData.inc"
Xinliang David Li192c7482015-11-05 00:47:26 +0000468 };
Justin Bogner61ba2e32014-12-08 18:02:35 +0000469 auto *DataTy = StructType::get(Ctx, makeArrayRef(DataTypes));
Xinliang David Li192c7482015-11-05 00:47:26 +0000470
Xinliang David Li69a00f02016-06-21 02:39:08 +0000471 Constant *FunctionAddr = shouldRecordFunctionAddr(Fn)
472 ? ConstantExpr::getBitCast(Fn, Int8PtrTy)
473 : ConstantPointerNull::get(Int8PtrTy);
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000474
Xinliang David Li69a00f02016-06-21 02:39:08 +0000475 Constant *Int16ArrayVals[IPVK_Last + 1];
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000476 for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
477 Int16ArrayVals[Kind] = ConstantInt::get(Int16Ty, PD.NumValueSites[Kind]);
478
Justin Bogner61ba2e32014-12-08 18:02:35 +0000479 Constant *DataVals[] = {
Xinliang David Li69a00f02016-06-21 02:39:08 +0000480#define INSTR_PROF_DATA(Type, LLVMType, Name, Init) Init,
481#include "llvm/ProfileData/InstrProfData.inc"
Xinliang David Li192c7482015-11-05 00:47:26 +0000482 };
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000483 auto *Data = new GlobalVariable(*M, DataTy, false, NamePtr->getLinkage(),
Justin Bogner61ba2e32014-12-08 18:02:35 +0000484 ConstantStruct::get(DataTy, DataVals),
Xinliang David Li83bc4222015-10-22 20:32:12 +0000485 getVarName(Inc, getInstrProfDataVarPrefix()));
Xinliang David Li192c7482015-11-05 00:47:26 +0000486 Data->setVisibility(NamePtr->getVisibility());
Vedant Kumar1a6a2b62017-04-15 00:09:57 +0000487 Data->setSection(getInstrProfSectionName(IPSK_data, TT.getObjectFormat()));
Xinliang David Lic7c1f852015-11-23 18:02:59 +0000488 Data->setAlignment(INSTR_PROF_DATA_ALIGNMENT);
Wei Mi3cc92042015-09-23 22:40:45 +0000489 Data->setComdat(ProfileVarsComdat);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000490
Betul Buyukkurt6fac1742015-11-18 18:14:55 +0000491 PD.RegionCounters = CounterPtr;
492 PD.DataVar = Data;
493 ProfileDataMap[NamePtr] = PD;
494
Justin Bogner61ba2e32014-12-08 18:02:35 +0000495 // Mark the data variable as used so that it isn't stripped out.
496 UsedVars.push_back(Data);
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000497 // Now that the linkage set by the FE has been passed to the data and counter
498 // variables, reset Name variable's linkage and visibility to private so that
499 // it can be removed later by the compiler.
500 NamePtr->setLinkage(GlobalValue::PrivateLinkage);
501 // Collect the referenced names to be used by emitNameData.
502 ReferencedNames.push_back(NamePtr);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000503
Xinliang David Li192c7482015-11-05 00:47:26 +0000504 return CounterPtr;
Justin Bogner61ba2e32014-12-08 18:02:35 +0000505}
506
Xinliang David Lib628dd32016-05-21 22:55:34 +0000507void InstrProfiling::emitVNodes() {
508 if (!ValueProfileStaticAlloc)
509 return;
Xinliang David Li8da773b2016-05-17 20:19:03 +0000510
Xinliang David Lib628dd32016-05-21 22:55:34 +0000511 // For now only support this on platforms that do
512 // not require runtime registration to discover
513 // named section start/end.
514 if (needsRuntimeRegistrationOfSectionRange(*M))
515 return;
Xinliang David Li8da773b2016-05-17 20:19:03 +0000516
Xinliang David Lib628dd32016-05-21 22:55:34 +0000517 size_t TotalNS = 0;
518 for (auto &PD : ProfileDataMap) {
519 for (uint32_t Kind = IPVK_First; Kind <= IPVK_Last; ++Kind)
520 TotalNS += PD.second.NumValueSites[Kind];
521 }
522
523 if (!TotalNS)
524 return;
525
526 uint64_t NumCounters = TotalNS * NumCountersPerValueSite;
Xinliang David Li69a00f02016-06-21 02:39:08 +0000527// Heuristic for small programs with very few total value sites.
528// The default value of vp-counters-per-site is chosen based on
529// the observation that large apps usually have a low percentage
530// of value sites that actually have any profile data, and thus
531// the average number of counters per site is low. For small
532// apps with very few sites, this may not be true. Bump up the
533// number of counters in this case.
Xinliang David Lie4520762016-05-23 19:29:26 +0000534#define INSTR_PROF_MIN_VAL_COUNTS 10
535 if (NumCounters < INSTR_PROF_MIN_VAL_COUNTS)
Xinliang David Li69a00f02016-06-21 02:39:08 +0000536 NumCounters = std::max(INSTR_PROF_MIN_VAL_COUNTS, (int)NumCounters * 2);
Xinliang David Lib628dd32016-05-21 22:55:34 +0000537
538 auto &Ctx = M->getContext();
539 Type *VNodeTypes[] = {
540#define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Init) LLVMType,
541#include "llvm/ProfileData/InstrProfData.inc"
542 };
543 auto *VNodeTy = StructType::get(Ctx, makeArrayRef(VNodeTypes));
544
545 ArrayType *VNodesTy = ArrayType::get(VNodeTy, NumCounters);
546 auto *VNodesVar = new GlobalVariable(
Eugene Zelenko34c23272017-01-18 00:57:48 +0000547 *M, VNodesTy, false, GlobalValue::PrivateLinkage,
Xinliang David Lib628dd32016-05-21 22:55:34 +0000548 Constant::getNullValue(VNodesTy), getInstrProfVNodesVarName());
Vedant Kumar1a6a2b62017-04-15 00:09:57 +0000549 VNodesVar->setSection(
550 getInstrProfSectionName(IPSK_vnodes, TT.getObjectFormat()));
Xinliang David Lib628dd32016-05-21 22:55:34 +0000551 UsedVars.push_back(VNodesVar);
Xinliang David Li8da773b2016-05-17 20:19:03 +0000552}
553
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000554void InstrProfiling::emitNameData() {
555 std::string UncompressedData;
556
557 if (ReferencedNames.empty())
558 return;
559
560 std::string CompressedNameStr;
Vedant Kumar9152fd12016-05-19 03:54:45 +0000561 if (Error E = collectPGOFuncNameStrings(ReferencedNames, CompressedNameStr,
Vedant Kumar43cba732016-05-03 16:53:17 +0000562 DoNameCompression)) {
Eugene Zelenko34c23272017-01-18 00:57:48 +0000563 report_fatal_error(toString(std::move(E)), false);
Vedant Kumar43cba732016-05-03 16:53:17 +0000564 }
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000565
566 auto &Ctx = M->getContext();
Eugene Zelenko34c23272017-01-18 00:57:48 +0000567 auto *NamesVal = ConstantDataArray::getString(
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000568 Ctx, StringRef(CompressedNameStr), false);
Eugene Zelenko34c23272017-01-18 00:57:48 +0000569 NamesVar = new GlobalVariable(*M, NamesVal->getType(), true,
570 GlobalValue::PrivateLinkage, NamesVal,
571 getInstrProfNamesVarName());
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000572 NamesSize = CompressedNameStr.size();
Vedant Kumar1a6a2b62017-04-15 00:09:57 +0000573 NamesVar->setSection(
574 getInstrProfSectionName(IPSK_name, TT.getObjectFormat()));
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000575 UsedVars.push_back(NamesVar);
Vedant Kumar55891fc2017-02-14 20:03:48 +0000576
577 for (auto *NamePtr : ReferencedNames)
578 NamePtr->eraseFromParent();
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000579}
580
Justin Bogner61ba2e32014-12-08 18:02:35 +0000581void InstrProfiling::emitRegistration() {
Xinliang David Li8da773b2016-05-17 20:19:03 +0000582 if (!needsRuntimeRegistrationOfSectionRange(*M))
Xinliang David Liaa0592c2015-10-19 04:17:10 +0000583 return;
Xinliang David Li3dd88172015-10-13 18:39:48 +0000584
Justin Bogner61ba2e32014-12-08 18:02:35 +0000585 // Construct the function.
586 auto *VoidTy = Type::getVoidTy(M->getContext());
587 auto *VoidPtrTy = Type::getInt8PtrTy(M->getContext());
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000588 auto *Int64Ty = Type::getInt64Ty(M->getContext());
Justin Bogner61ba2e32014-12-08 18:02:35 +0000589 auto *RegisterFTy = FunctionType::get(VoidTy, false);
590 auto *RegisterF = Function::Create(RegisterFTy, GlobalValue::InternalLinkage,
Xinliang David Li8ee08b02015-10-23 04:22:58 +0000591 getInstrProfRegFuncsName(), M);
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000592 RegisterF->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
Xinliang David Li69a00f02016-06-21 02:39:08 +0000593 if (Options.NoRedZone)
594 RegisterF->addFnAttr(Attribute::NoRedZone);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000595
Diego Novillob3029d22015-06-04 11:45:32 +0000596 auto *RuntimeRegisterTy = FunctionType::get(VoidTy, VoidPtrTy, false);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000597 auto *RuntimeRegisterF =
598 Function::Create(RuntimeRegisterTy, GlobalVariable::ExternalLinkage,
Xinliang David Li8ee08b02015-10-23 04:22:58 +0000599 getInstrProfRegFuncName(), M);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000600
601 IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", RegisterF));
602 for (Value *Data : UsedVars)
Xinliang David Lia82d6c02016-02-08 18:13:49 +0000603 if (Data != NamesVar)
604 IRB.CreateCall(RuntimeRegisterF, IRB.CreateBitCast(Data, VoidPtrTy));
605
606 if (NamesVar) {
607 Type *ParamTypes[] = {VoidPtrTy, Int64Ty};
608 auto *NamesRegisterTy =
609 FunctionType::get(VoidTy, makeArrayRef(ParamTypes), false);
610 auto *NamesRegisterF =
611 Function::Create(NamesRegisterTy, GlobalVariable::ExternalLinkage,
612 getInstrProfNamesRegFuncName(), M);
613 IRB.CreateCall(NamesRegisterF, {IRB.CreateBitCast(NamesVar, VoidPtrTy),
614 IRB.getInt64(NamesSize)});
615 }
616
Justin Bogner61ba2e32014-12-08 18:02:35 +0000617 IRB.CreateRetVoid();
618}
619
620void InstrProfiling::emitRuntimeHook() {
Xinliang David Li7a88ad62015-10-29 04:08:31 +0000621 // We expect the linker to be invoked with -u<hook_var> flag for linux,
622 // for which case there is no need to emit the user function.
623 if (Triple(M->getTargetTriple()).isOSLinux())
624 return;
625
Justin Bogner61ba2e32014-12-08 18:02:35 +0000626 // If the module's provided its own runtime, we don't need to do anything.
Xinliang David Li69a00f02016-06-21 02:39:08 +0000627 if (M->getGlobalVariable(getInstrProfRuntimeHookVarName()))
628 return;
Justin Bogner61ba2e32014-12-08 18:02:35 +0000629
630 // Declare an external variable that will pull in the runtime initialization.
631 auto *Int32Ty = Type::getInt32Ty(M->getContext());
632 auto *Var =
633 new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage,
Xinliang David Li8ee08b02015-10-23 04:22:58 +0000634 nullptr, getInstrProfRuntimeHookVarName());
Justin Bogner61ba2e32014-12-08 18:02:35 +0000635
636 // Make a function that uses it.
Xinliang David Li8ee08b02015-10-23 04:22:58 +0000637 auto *User = Function::Create(FunctionType::get(Int32Ty, false),
638 GlobalValue::LinkOnceODRLinkage,
639 getInstrProfRuntimeHookVarUseFuncName(), M);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000640 User->addFnAttr(Attribute::NoInline);
Xinliang David Li69a00f02016-06-21 02:39:08 +0000641 if (Options.NoRedZone)
642 User->addFnAttr(Attribute::NoRedZone);
Justin Bogner2e427d42015-02-25 22:52:20 +0000643 User->setVisibility(GlobalValue::HiddenVisibility);
Xinliang David Lia2286082016-05-25 17:17:51 +0000644 if (Triple(M->getTargetTriple()).supportsCOMDAT())
Xinliang David Lif4edae62016-05-24 18:47:38 +0000645 User->setComdat(M->getOrInsertComdat(User->getName()));
Justin Bogner61ba2e32014-12-08 18:02:35 +0000646
647 IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", User));
648 auto *Load = IRB.CreateLoad(Var);
649 IRB.CreateRet(Load);
650
651 // Mark the user variable as used so that it isn't stripped out.
652 UsedVars.push_back(User);
653}
654
655void InstrProfiling::emitUses() {
Evgeniy Stepanovea6d49d2016-10-25 23:53:31 +0000656 if (!UsedVars.empty())
657 appendToUsed(*M, UsedVars);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000658}
659
660void InstrProfiling::emitInitialization() {
Vedant Kumarcd32eba2016-07-21 17:50:07 +0000661 StringRef InstrProfileOutput = Options.InstrProfileOutput;
Justin Bognerba1900c2015-04-30 23:49:23 +0000662
Xinliang David Li6f8c5042016-07-21 23:19:10 +0000663 if (!InstrProfileOutput.empty()) {
664 // Create variable for profile name.
665 Constant *ProfileNameConst =
666 ConstantDataArray::getString(M->getContext(), InstrProfileOutput, true);
667 GlobalVariable *ProfileNameVar = new GlobalVariable(
668 *M, ProfileNameConst->getType(), true, GlobalValue::WeakAnyLinkage,
669 ProfileNameConst, INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR));
Xinliang David Li6f8c5042016-07-21 23:19:10 +0000670 if (TT.supportsCOMDAT()) {
671 ProfileNameVar->setLinkage(GlobalValue::ExternalLinkage);
672 ProfileNameVar->setComdat(M->getOrInsertComdat(
673 StringRef(INSTR_PROF_QUOTE(INSTR_PROF_PROFILE_NAME_VAR))));
674 }
675 }
676
Xinliang David Li8ee08b02015-10-23 04:22:58 +0000677 Constant *RegisterF = M->getFunction(getInstrProfRegFuncsName());
Xinliang David Li6f8c5042016-07-21 23:19:10 +0000678 if (!RegisterF)
Xinliang David Li69a00f02016-06-21 02:39:08 +0000679 return;
Justin Bogner61ba2e32014-12-08 18:02:35 +0000680
681 // Create the initialization function.
682 auto *VoidTy = Type::getVoidTy(M->getContext());
Xinliang David Li8ee08b02015-10-23 04:22:58 +0000683 auto *F = Function::Create(FunctionType::get(VoidTy, false),
684 GlobalValue::InternalLinkage,
685 getInstrProfInitFuncName(), M);
Peter Collingbourne96efdd62016-06-14 21:01:22 +0000686 F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000687 F->addFnAttr(Attribute::NoInline);
Xinliang David Li69a00f02016-06-21 02:39:08 +0000688 if (Options.NoRedZone)
689 F->addFnAttr(Attribute::NoRedZone);
Justin Bogner61ba2e32014-12-08 18:02:35 +0000690
691 // Add the basic block and the necessary calls.
692 IRBuilder<> IRB(BasicBlock::Create(M->getContext(), "", F));
Justin Bognerba1900c2015-04-30 23:49:23 +0000693 if (RegisterF)
David Blaikieff6409d2015-05-18 22:13:54 +0000694 IRB.CreateCall(RegisterF, {});
Justin Bogner61ba2e32014-12-08 18:02:35 +0000695 IRB.CreateRetVoid();
696
697 appendToGlobalCtors(*M, F, 0);
698}