LLVM 22.0.0git
GCOVProfiling.cpp
Go to the documentation of this file.
1//===- GCOVProfiling.cpp - Insert edge counters for gcov profiling --------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This pass implements GCOV-style profiling. When this pass is run it emits
10// "gcno" files next to the existing source, and instruments the code that runs
11// to records the edges between blocks that run and emit a complementary "gcda"
12// file on exit.
13//
14//===----------------------------------------------------------------------===//
15
16#include "llvm/ADT/Hashing.h"
17#include "llvm/ADT/MapVector.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/ADT/Sequence.h"
20#include "llvm/ADT/StringMap.h"
24#include "llvm/IR/DebugInfo.h"
25#include "llvm/IR/DebugLoc.h"
27#include "llvm/IR/IRBuilder.h"
30#include "llvm/IR/Module.h"
32#include "llvm/Support/CRC.h"
34#include "llvm/Support/Debug.h"
36#include "llvm/Support/Path.h"
37#include "llvm/Support/Regex.h"
44#include <algorithm>
45#include <memory>
46#include <string>
47#include <utility>
48
49using namespace llvm;
51
52#define DEBUG_TYPE "insert-gcov-profiling"
53
54enum : uint32_t {
56
57 GCOV_TAG_FUNCTION = 0x01000000,
58 GCOV_TAG_BLOCKS = 0x01410000,
59 GCOV_TAG_ARCS = 0x01430000,
60 GCOV_TAG_LINES = 0x01450000,
61};
62
63static cl::opt<std::string> DefaultGCOVVersion("default-gcov-version",
64 cl::init("0000"), cl::Hidden,
66
67static cl::opt<bool> AtomicCounter("gcov-atomic-counter", cl::Hidden,
68 cl::desc("Make counter updates atomic"));
69
70// Returns the number of words which will be used to represent this string.
71static unsigned wordsOfString(StringRef s) {
72 // Length + NUL-terminated string + 0~3 padding NULs.
73 return (s.size() / 4) + 2;
74}
75
78 Options.EmitNotes = true;
79 Options.EmitData = true;
80 Options.NoRedZone = false;
81 Options.Atomic = AtomicCounter;
82
83 if (DefaultGCOVVersion.size() != 4) {
84 reportFatalUsageError(Twine("Invalid -default-gcov-version: ") +
86 }
87 memcpy(Options.Version, DefaultGCOVVersion.c_str(), 4);
88 return Options;
89}
90
91namespace {
92class GCOVFunction;
93
94class GCOVProfiler {
95public:
96 GCOVProfiler()
97 : GCOVProfiler(GCOVOptions::getDefault(), *vfs::getRealFileSystem()) {}
98 GCOVProfiler(const GCOVOptions &Opts, vfs::FileSystem &VFS)
99 : Options(Opts), VFS(VFS) {}
100 bool
101 runOnModule(Module &M, function_ref<BlockFrequencyInfo *(Function &F)> GetBFI,
102 function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
103 std::function<const TargetLibraryInfo &(Function &F)> GetTLI);
104
105 void write(uint32_t i) {
106 char Bytes[4];
107 endian::write32(Bytes, i, Endian);
108 os->write(Bytes, 4);
109 }
110 void writeString(StringRef s) {
111 write(wordsOfString(s) - 1);
112 os->write(s.data(), s.size());
113 os->write_zeros(4 - s.size() % 4);
114 }
115 void writeBytes(const char *Bytes, int Size) { os->write(Bytes, Size); }
116 vfs::FileSystem &getVirtualFileSystem() const { return VFS; }
117
118private:
119 // Create the .gcno files for the Module based on DebugInfo.
120 bool
121 emitProfileNotes(NamedMDNode *CUNode, bool HasExecOrFork,
122 function_ref<BlockFrequencyInfo *(Function &F)> GetBFI,
123 function_ref<BranchProbabilityInfo *(Function &F)> GetBPI,
124 function_ref<const TargetLibraryInfo &(Function &F)> GetTLI);
125
126 Function *createInternalFunction(FunctionType *FTy, StringRef Name,
127 StringRef MangledType = "");
128
129 void emitGlobalConstructor(
130 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP);
131 void emitModuleInitFunctionPtrs(
132 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP);
133
134 bool isFunctionInstrumented(const Function &F);
135 std::vector<Regex> createRegexesFromString(StringRef RegexesStr);
136 static bool doesFilenameMatchARegex(StringRef Filename,
137 std::vector<Regex> &Regexes);
138
139 // Get pointers to the functions in the runtime library.
140 FunctionCallee getStartFileFunc(const TargetLibraryInfo *TLI);
141 FunctionCallee getEmitFunctionFunc(const TargetLibraryInfo *TLI);
142 FunctionCallee getEmitArcsFunc(const TargetLibraryInfo *TLI);
143 FunctionCallee getSummaryInfoFunc();
144 FunctionCallee getEndFileFunc();
145
146 // Add the function to write out all our counters to the global destructor
147 // list.
148 Function *
149 insertCounterWriteout(ArrayRef<std::pair<GlobalVariable *, MDNode *>>);
150 Function *insertReset(ArrayRef<std::pair<GlobalVariable *, MDNode *>>);
151
152 bool AddFlushBeforeForkAndExec();
153
154 enum class GCovFileType { GCNO, GCDA };
155 std::string mangleName(const DICompileUnit *CU, GCovFileType FileType);
156
157 GCOVOptions Options;
158 llvm::endianness Endian;
159 raw_ostream *os;
160 int Version = 0;
161
162 // Checksum, produced by hash of EdgeDestinations
163 SmallVector<uint32_t, 4> FileChecksums;
164
165 Module *M = nullptr;
166 std::function<const TargetLibraryInfo &(Function &F)> GetTLI;
167 LLVMContext *Ctx = nullptr;
169 std::vector<Regex> FilterRe;
170 std::vector<Regex> ExcludeRe;
171 DenseSet<const BasicBlock *> ExecBlocks;
172 StringMap<bool> InstrumentedFiles;
173 vfs::FileSystem &VFS;
174};
175
176struct BBInfo {
177 BBInfo *Group;
178 uint32_t Index;
179 uint32_t Rank = 0;
180
181 BBInfo(unsigned Index) : Group(this), Index(Index) {}
182 std::string infoString() const {
183 return (Twine("Index=") + Twine(Index)).str();
184 }
185};
186
187struct Edge {
188 // This class implements the CFG edges. Note the CFG can be a multi-graph.
189 // So there might be multiple edges with same SrcBB and DestBB.
190 const BasicBlock *SrcBB;
191 const BasicBlock *DestBB;
192 uint64_t Weight;
193 BasicBlock *Place = nullptr;
194 uint32_t SrcNumber, DstNumber;
195 bool InMST = false;
196 bool Removed = false;
197 bool IsCritical = false;
198
199 Edge(const BasicBlock *Src, const BasicBlock *Dest, uint64_t W = 1)
200 : SrcBB(Src), DestBB(Dest), Weight(W) {}
201
202 // Return the information string of an edge.
203 std::string infoString() const {
204 return (Twine(Removed ? "-" : " ") + (InMST ? " " : "*") +
205 (IsCritical ? "c" : " ") + " W=" + Twine(Weight))
206 .str();
207 }
208};
209}
210
212 if (!SP->getLinkageName().empty())
213 return SP->getLinkageName();
214 return SP->getName();
215}
216
217/// Extract a filename for a DIScope.
218///
219/// Prefer relative paths in the coverage notes. Clang also may split
220/// up absolute paths into a directory and filename component. When
221/// the relative path doesn't exist, reconstruct the absolute path.
223 SmallString<128> Path;
224 StringRef RelPath = SP->getFilename();
225 if (VFS.exists(RelPath))
226 Path = RelPath;
227 else
228 sys::path::append(Path, SP->getDirectory(), SP->getFilename());
229 return Path;
230}
231
232namespace {
233 class GCOVRecord {
234 protected:
235 GCOVProfiler *P;
236
237 GCOVRecord(GCOVProfiler *P) : P(P) {}
238
239 void write(uint32_t i) { P->write(i); }
240 void writeString(StringRef s) { P->writeString(s); }
241 void writeBytes(const char *Bytes, int Size) { P->writeBytes(Bytes, Size); }
242 };
243
244 class GCOVFunction;
245 class GCOVBlock;
246
247 // Constructed only by requesting it from a GCOVBlock, this object stores a
248 // list of line numbers and a single filename, representing lines that belong
249 // to the block.
250 class GCOVLines : public GCOVRecord {
251 public:
252 StringRef getFilename() { return Filename; }
253
254 void addLine(uint32_t Line) {
255 assert(Line != 0 && "Line zero is not a valid real line number.");
256 Lines.push_back(Line);
257 }
258
259 uint32_t length() const {
260 return 1 + wordsOfString(Filename) + Lines.size();
261 }
262
263 void writeOut() {
264 write(0);
265 writeString(Filename);
266 for (uint32_t L : Lines)
267 write(L);
268 }
269
270 GCOVLines(GCOVProfiler *P, StringRef F)
271 : GCOVRecord(P), Filename(std::string(F)) {}
272
273 private:
274 std::string Filename;
276 };
277
278
279 // Represent a basic block in GCOV. Each block has a unique number in the
280 // function, number of lines belonging to each block, and a set of edges to
281 // other blocks.
282 class GCOVBlock : public GCOVRecord {
283 public:
284 GCOVLines &getFile(StringRef Filename) {
285 if (Lines.empty() || Lines.back().getFilename() != Filename)
286 Lines.emplace_back(P, Filename);
287 return Lines.back();
288 }
289
290 void addEdge(GCOVBlock &Successor, uint32_t Flags) {
291 OutEdges.emplace_back(&Successor, Flags);
292 }
293
294 void writeOut() {
295 uint32_t Len = 3;
296
297 for (auto &L : Lines)
298 Len += L.length();
299
301 write(Len);
302 write(Number);
303
304 for (auto &L : Lines)
305 L.writeOut();
306 write(0);
307 write(0);
308 }
309
310 GCOVBlock(const GCOVBlock &RHS) : GCOVRecord(RHS), Number(RHS.Number) {
311 // Only allow copy before edges and lines have been added. After that,
312 // there are inter-block pointers (eg: edges) that won't take kindly to
313 // blocks being copied or moved around.
314 assert(Lines.empty());
315 assert(OutEdges.empty());
316 }
317
318 uint32_t Number;
320
321 private:
322 friend class GCOVFunction;
323
324 GCOVBlock(GCOVProfiler *P, uint32_t Number)
325 : GCOVRecord(P), Number(Number) {}
326
328 };
329
330 // A function has a unique identifier, a checksum (we leave as zero) and a
331 // set of blocks and a map of edges between blocks. This is the only GCOV
332 // object users can construct, the blocks and lines will be rooted here.
333 class GCOVFunction : public GCOVRecord {
334 public:
335 GCOVFunction(GCOVProfiler *P, Function *F, const DISubprogram *SP,
336 unsigned EndLine, uint32_t Ident, int Version)
337 : GCOVRecord(P), SP(SP), EndLine(EndLine), Ident(Ident),
338 Version(Version), EntryBlock(P, 0), ReturnBlock(P, 1) {
339 LLVM_DEBUG(dbgs() << "Function: " << getFunctionName(SP) << "\n");
340 uint32_t i = 2;
341 for (BasicBlock &BB : *F)
342 Blocks.insert(std::make_pair(&BB, GCOVBlock(P, i++)));
343
344 std::string FunctionNameAndLine;
345 raw_string_ostream FNLOS(FunctionNameAndLine);
346 FNLOS << getFunctionName(SP) << SP->getLine();
347 FuncChecksum = hash_value(FunctionNameAndLine);
348 }
349
350 GCOVBlock &getBlock(const BasicBlock *BB) {
351 return Blocks.find(const_cast<BasicBlock *>(BB))->second;
352 }
353
354 GCOVBlock &getEntryBlock() { return EntryBlock; }
355 GCOVBlock &getReturnBlock() {
356 return ReturnBlock;
357 }
358
359 uint32_t getFuncChecksum() const {
360 return FuncChecksum;
361 }
362
363 void writeOut(uint32_t CfgChecksum) {
365 SmallString<128> Filename = getFilename(SP, P->getVirtualFileSystem());
366 uint32_t BlockLen = 3 + wordsOfString(getFunctionName(SP));
367 BlockLen += 1 + wordsOfString(Filename) + 4;
368
369 write(BlockLen);
370 write(Ident);
371 write(FuncChecksum);
372 write(CfgChecksum);
373 writeString(getFunctionName(SP));
374
375 write(SP->isArtificial()); // artificial
376 writeString(Filename);
377 write(SP->getLine()); // start_line
378 write(0); // start_column
379 // EndLine is the last line with !dbg. It is not the } line as in GCC,
380 // but good enough.
381 write(EndLine);
382 write(0); // end_column
383
384 // Emit count of blocks.
386 write(1);
387 write(Blocks.size() + 2);
388 LLVM_DEBUG(dbgs() << (Blocks.size() + 1) << " blocks\n");
389
390 // Emit edges between blocks.
391 const uint32_t Outgoing = EntryBlock.OutEdges.size();
392 if (Outgoing) {
394 write(Outgoing * 2 + 1);
395 write(EntryBlock.Number);
396 for (const auto &E : EntryBlock.OutEdges) {
397 write(E.first->Number);
398 write(E.second);
399 }
400 }
401 for (auto &It : Blocks) {
402 const GCOVBlock &Block = It.second;
403 if (Block.OutEdges.empty()) continue;
404
406 write(Block.OutEdges.size() * 2 + 1);
407 write(Block.Number);
408 for (const auto &E : Block.OutEdges) {
409 write(E.first->Number);
410 write(E.second);
411 }
412 }
413
414 // Emit lines for each block.
415 for (auto &It : Blocks)
416 It.second.writeOut();
417 }
418
419 public:
420 const DISubprogram *SP;
421 unsigned EndLine;
422 uint32_t Ident;
423 uint32_t FuncChecksum;
424 int Version;
425 MapVector<BasicBlock *, GCOVBlock> Blocks;
426 GCOVBlock EntryBlock;
427 GCOVBlock ReturnBlock;
428 };
429}
430
431// RegexesStr is a string containing differents regex separated by a semi-colon.
432// For example "foo\..*$;bar\..*$".
433std::vector<Regex> GCOVProfiler::createRegexesFromString(StringRef RegexesStr) {
434 std::vector<Regex> Regexes;
435 while (!RegexesStr.empty()) {
436 std::pair<StringRef, StringRef> HeadTail = RegexesStr.split(';');
437 if (!HeadTail.first.empty()) {
438 Regex Re(HeadTail.first);
439 std::string Err;
440 if (!Re.isValid(Err)) {
441 Ctx->emitError(Twine("Regex ") + HeadTail.first +
442 " is not valid: " + Err);
443 }
444 Regexes.emplace_back(std::move(Re));
445 }
446 RegexesStr = HeadTail.second;
447 }
448 return Regexes;
449}
450
451bool GCOVProfiler::doesFilenameMatchARegex(StringRef Filename,
452 std::vector<Regex> &Regexes) {
453 for (Regex &Re : Regexes)
454 if (Re.match(Filename))
455 return true;
456 return false;
457}
458
459bool GCOVProfiler::isFunctionInstrumented(const Function &F) {
460 if (FilterRe.empty() && ExcludeRe.empty()) {
461 return true;
462 }
463 SmallString<128> Filename = getFilename(F.getSubprogram(), VFS);
464 auto It = InstrumentedFiles.find(Filename);
465 if (It != InstrumentedFiles.end()) {
466 return It->second;
467 }
468
469 SmallString<256> RealPath;
470 StringRef RealFilename;
471
472 // Path can be
473 // /usr/lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/*.h so for
474 // such a case we must get the real_path.
475 if (VFS.getRealPath(Filename, RealPath)) {
476 // real_path can fail with path like "foo.c".
477 RealFilename = Filename;
478 } else {
479 RealFilename = RealPath;
480 }
481
482 bool ShouldInstrument;
483 if (FilterRe.empty()) {
484 ShouldInstrument = !doesFilenameMatchARegex(RealFilename, ExcludeRe);
485 } else if (ExcludeRe.empty()) {
486 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe);
487 } else {
488 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe) &&
489 !doesFilenameMatchARegex(RealFilename, ExcludeRe);
490 }
491 InstrumentedFiles[Filename] = ShouldInstrument;
492 return ShouldInstrument;
493}
494
495std::string GCOVProfiler::mangleName(const DICompileUnit *CU,
496 GCovFileType OutputType) {
497 bool Notes = OutputType == GCovFileType::GCNO;
498
499 if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) {
500 for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
501 MDNode *N = GCov->getOperand(i);
502 bool ThreeElement = N->getNumOperands() == 3;
503 if (!ThreeElement && N->getNumOperands() != 2)
504 continue;
505 if (dyn_cast<MDNode>(N->getOperand(ThreeElement ? 2 : 1)) != CU)
506 continue;
507
508 if (ThreeElement) {
509 // These nodes have no mangling to apply, it's stored mangled in the
510 // bitcode.
511 MDString *NotesFile = dyn_cast<MDString>(N->getOperand(0));
512 MDString *DataFile = dyn_cast<MDString>(N->getOperand(1));
513 if (!NotesFile || !DataFile)
514 continue;
515 return std::string(Notes ? NotesFile->getString()
516 : DataFile->getString());
517 }
518
519 MDString *GCovFile = dyn_cast<MDString>(N->getOperand(0));
520 if (!GCovFile)
521 continue;
522
523 SmallString<128> Filename = GCovFile->getString();
524 sys::path::replace_extension(Filename, Notes ? "gcno" : "gcda");
525 return std::string(Filename);
526 }
527 }
528
530 sys::path::replace_extension(Filename, Notes ? "gcno" : "gcda");
531 StringRef FName = sys::path::filename(Filename);
532 ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory();
533 if (!CWD)
534 return std::string(FName);
535 SmallString<128> CurPath{*CWD};
536 sys::path::append(CurPath, FName);
537 return std::string(CurPath);
538}
539
540bool GCOVProfiler::runOnModule(
543 std::function<const TargetLibraryInfo &(Function &F)> GetTLI) {
544 this->M = &M;
545 this->GetTLI = std::move(GetTLI);
546 Ctx = &M.getContext();
547
548 NamedMDNode *CUNode = M.getNamedMetadata("llvm.dbg.cu");
549 if (!CUNode || (!Options.EmitNotes && !Options.EmitData))
550 return false;
551
552 bool HasExecOrFork = AddFlushBeforeForkAndExec();
553
554 FilterRe = createRegexesFromString(Options.Filter);
555 ExcludeRe = createRegexesFromString(Options.Exclude);
556 emitProfileNotes(CUNode, HasExecOrFork, GetBFI, GetBPI, this->GetTLI);
557 return true;
558}
559
562
563 GCOVProfiler Profiler(GCOVOpts, *VFS);
566
567 auto GetBFI = [&FAM](Function &F) {
568 return &FAM.getResult<BlockFrequencyAnalysis>(F);
569 };
570 auto GetBPI = [&FAM](Function &F) {
571 return &FAM.getResult<BranchProbabilityAnalysis>(F);
572 };
573 auto GetTLI = [&FAM](Function &F) -> const TargetLibraryInfo & {
574 return FAM.getResult<TargetLibraryAnalysis>(F);
575 };
576
577 if (!Profiler.runOnModule(M, GetBFI, GetBPI, GetTLI))
578 return PreservedAnalyses::all();
579
581}
582
583static bool functionHasLines(const Function &F, unsigned &EndLine) {
584 // Check whether this function actually has any source lines. Not only
585 // do these waste space, they also can crash gcov.
586 EndLine = 0;
587 for (const auto &BB : F) {
588 for (const auto &I : BB) {
589 const DebugLoc &Loc = I.getDebugLoc();
590 if (!Loc)
591 continue;
592
593 // Artificial lines such as calls to the global constructors.
594 if (Loc.getLine() == 0) continue;
595 EndLine = std::max(EndLine, Loc.getLine());
596
597 return true;
598 }
599 }
600 return false;
601}
602
604 if (!F.hasPersonalityFn()) return false;
605
606 EHPersonality Personality = classifyEHPersonality(F.getPersonalityFn());
607 return isScopedEHPersonality(Personality);
608}
609
610bool GCOVProfiler::AddFlushBeforeForkAndExec() {
611 const TargetLibraryInfo *TLI = nullptr;
614 for (auto &F : M->functions()) {
615 TLI = TLI == nullptr ? &GetTLI(F) : TLI;
616 for (auto &I : instructions(F)) {
617 if (CallInst *CI = dyn_cast<CallInst>(&I)) {
618 if (Function *Callee = CI->getCalledFunction()) {
619 LibFunc LF;
620 if (TLI->getLibFunc(*Callee, LF)) {
621 if (LF == LibFunc_fork) {
622#if !defined(_WIN32)
623 Forks.push_back(CI);
624#endif
625 } else if (LF == LibFunc_execl || LF == LibFunc_execle ||
626 LF == LibFunc_execlp || LF == LibFunc_execv ||
627 LF == LibFunc_execvp || LF == LibFunc_execve ||
628 LF == LibFunc_execvpe || LF == LibFunc_execvP) {
629 Execs.push_back(CI);
630 }
631 }
632 }
633 }
634 }
635 }
636
637 for (auto *F : Forks) {
638 IRBuilder<> Builder(F);
639 BasicBlock *Parent = F->getParent();
640 auto NextInst = ++F->getIterator();
641
642 // We've a fork so just reset the counters in the child process
643 FunctionType *FTy = FunctionType::get(Builder.getInt32Ty(), {}, false);
644 FunctionCallee GCOVFork = M->getOrInsertFunction(
645 "__gcov_fork", FTy,
646 TLI->getAttrList(Ctx, {}, /*Signed=*/true, /*Ret=*/true));
647 F->setCalledFunction(GCOVFork);
648
649 // We split just after the fork to have a counter for the lines after
650 // Anyway there's a bug:
651 // void foo() { fork(); }
652 // void bar() { foo(); blah(); }
653 // then "blah();" will be called 2 times but showed as 1
654 // because "blah()" belongs to the same block as "foo();"
655 Parent->splitBasicBlock(NextInst);
656
657 // back() is a br instruction with a debug location
658 // equals to the one from NextAfterFork
659 // So to avoid to have two debug locs on two blocks just change it
660 DebugLoc Loc = F->getDebugLoc();
661 Parent->back().setDebugLoc(Loc);
662 }
663
664 for (auto *E : Execs) {
665 IRBuilder<> Builder(E);
666 BasicBlock *Parent = E->getParent();
667 auto NextInst = ++E->getIterator();
668
669 // Since the process is replaced by a new one we need to write out gcdas
670 // No need to reset the counters since they'll be lost after the exec**
671 FunctionType *FTy = FunctionType::get(Builder.getVoidTy(), {}, false);
672 FunctionCallee WriteoutF =
673 M->getOrInsertFunction("llvm_writeout_files", FTy);
674 Builder.CreateCall(WriteoutF);
675
676 DebugLoc Loc = E->getDebugLoc();
677 Builder.SetInsertPoint(&*NextInst);
678 // If the exec** fails we must reset the counters since they've been
679 // dumped
680 FunctionCallee ResetF = M->getOrInsertFunction("llvm_reset_counters", FTy);
681 Builder.CreateCall(ResetF)->setDebugLoc(Loc);
682 ExecBlocks.insert(Parent);
683 Parent->splitBasicBlock(NextInst);
684 Parent->back().setDebugLoc(Loc);
685 }
686
687 return !Forks.empty() || !Execs.empty();
688}
689
691 const DenseSet<const BasicBlock *> &ExecBlocks) {
692 if (E.InMST || E.Removed)
693 return nullptr;
694
695 BasicBlock *SrcBB = const_cast<BasicBlock *>(E.SrcBB);
696 BasicBlock *DestBB = const_cast<BasicBlock *>(E.DestBB);
697 // For a fake edge, instrument the real BB.
698 if (SrcBB == nullptr)
699 return DestBB;
700 if (DestBB == nullptr)
701 return SrcBB;
702
703 auto CanInstrument = [](BasicBlock *BB) -> BasicBlock * {
704 // There are basic blocks (such as catchswitch) cannot be instrumented.
705 // If the returned first insertion point is the end of BB, skip this BB.
706 if (BB->getFirstInsertionPt() == BB->end())
707 return nullptr;
708 return BB;
709 };
710
711 // Instrument the SrcBB if it has a single successor,
712 // otherwise, the DestBB if this is not a critical edge.
713 Instruction *TI = SrcBB->getTerminator();
714 if (TI->getNumSuccessors() <= 1 && !ExecBlocks.count(SrcBB))
715 return CanInstrument(SrcBB);
716 if (!E.IsCritical)
717 return CanInstrument(DestBB);
718
719 // Some IndirectBr critical edges cannot be split by the previous
720 // SplitIndirectBrCriticalEdges call. Bail out.
721 const unsigned SuccNum = GetSuccessorNumber(SrcBB, DestBB);
722 BasicBlock *InstrBB =
723 isa<IndirectBrInst>(TI) ? nullptr : SplitCriticalEdge(TI, SuccNum);
724 if (!InstrBB)
725 return nullptr;
726
727 MST.addEdge(SrcBB, InstrBB, 0);
728 MST.addEdge(InstrBB, DestBB, 0).InMST = true;
729 E.Removed = true;
730
731 return CanInstrument(InstrBB);
732}
733
734#ifndef NDEBUG
736 size_t ID = 0;
737 for (const auto &E : make_pointee_range(MST.allEdges())) {
738 GCOVBlock &Src = E.SrcBB ? GF.getBlock(E.SrcBB) : GF.getEntryBlock();
739 GCOVBlock &Dst = E.DestBB ? GF.getBlock(E.DestBB) : GF.getReturnBlock();
740 dbgs() << " Edge " << ID++ << ": " << Src.Number << "->" << Dst.Number
741 << E.infoString() << "\n";
742 }
743}
744#endif
745
746bool GCOVProfiler::emitProfileNotes(
747 NamedMDNode *CUNode, bool HasExecOrFork,
750 function_ref<const TargetLibraryInfo &(Function &F)> GetTLI) {
751 {
752 uint8_t c3 = Options.Version[0];
753 uint8_t c2 = Options.Version[1];
754 uint8_t c1 = Options.Version[2];
755 Version = c3 >= 'A' ? (c3 - 'A') * 100 + (c2 - '0') * 10 + c1 - '0'
756 : (c3 - '0') * 10 + c1 - '0';
757 }
758 // Emit .gcno files that are compatible with GCC 11.1.
759 if (Version < 111) {
760 Version = 111;
761 memcpy(Options.Version, "B11*", 4);
762 }
763
764 bool EmitGCDA = Options.EmitData;
765 for (unsigned i = 0, e = CUNode->getNumOperands(); i != e; ++i) {
766 // Each compile unit gets its own .gcno file. This means that whether we run
767 // this pass over the original .o's as they're produced, or run it after
768 // LTO, we'll generate the same .gcno files.
769
770 auto *CU = cast<DICompileUnit>(CUNode->getOperand(i));
771
772 // Skip module skeleton (and module) CUs.
773 if (CU->getDWOId())
774 continue;
775
776 std::vector<uint8_t> EdgeDestinations;
778
779 Endian = M->getDataLayout().isLittleEndian() ? llvm::endianness::little
781 unsigned FunctionIdent = 0;
782 for (auto &F : M->functions()) {
783 DISubprogram *SP = F.getSubprogram();
784 unsigned EndLine;
785 if (!SP) continue;
786 if (!functionHasLines(F, EndLine) || !isFunctionInstrumented(F))
787 continue;
788 // TODO: Functions using scope-based EH are currently not supported.
789 if (isUsingScopeBasedEH(F)) continue;
790 if (F.hasFnAttribute(llvm::Attribute::NoProfile))
791 continue;
792 if (F.hasFnAttribute(llvm::Attribute::SkipProfile))
793 continue;
794
795 // Add the function line number to the lines of the entry block
796 // to have a counter for the function definition.
797 uint32_t Line = SP->getLine();
798 auto Filename = getFilename(SP, VFS);
799
800 BranchProbabilityInfo *BPI = GetBPI(F);
801 BlockFrequencyInfo *BFI = GetBFI(F);
802
803 // Split indirectbr critical edges here before computing the MST rather
804 // than later in getInstrBB() to avoid invalidating it.
805 SplitIndirectBrCriticalEdges(F, /*IgnoreBlocksWithoutPHI=*/false, BPI,
806 BFI);
807
808 CFGMST<Edge, BBInfo> MST(F, /*InstrumentFuncEntry=*/false,
809 /*InstrumentLoopEntries=*/false, BPI, BFI);
810
811 // getInstrBB can split basic blocks and push elements to AllEdges.
812 for (size_t I : llvm::seq<size_t>(0, MST.numEdges())) {
813 auto &E = *MST.allEdges()[I];
814 // For now, disable spanning tree optimization when fork or exec* is
815 // used.
816 if (HasExecOrFork)
817 E.InMST = false;
818 E.Place = getInstrBB(MST, E, ExecBlocks);
819 }
820 // Basic blocks in F are finalized at this point.
821 BasicBlock &EntryBlock = F.getEntryBlock();
822 Funcs.push_back(std::make_unique<GCOVFunction>(this, &F, SP, EndLine,
823 FunctionIdent++, Version));
824 GCOVFunction &Func = *Funcs.back();
825
826 // Some non-tree edges are IndirectBr which cannot be split. Ignore them
827 // as well.
828 llvm::erase_if(MST.allEdges(), [](std::unique_ptr<Edge> &E) {
829 return E->Removed || (!E->InMST && !E->Place);
830 });
831 const size_t Measured =
832 std::stable_partition(
833 MST.allEdges().begin(), MST.allEdges().end(),
834 [](std::unique_ptr<Edge> &E) { return E->Place; }) -
835 MST.allEdges().begin();
836 for (size_t I : llvm::seq<size_t>(0, Measured)) {
837 Edge &E = *MST.allEdges()[I];
838 GCOVBlock &Src =
839 E.SrcBB ? Func.getBlock(E.SrcBB) : Func.getEntryBlock();
840 GCOVBlock &Dst =
841 E.DestBB ? Func.getBlock(E.DestBB) : Func.getReturnBlock();
842 E.SrcNumber = Src.Number;
843 E.DstNumber = Dst.Number;
844 }
845 std::stable_sort(
846 MST.allEdges().begin(), MST.allEdges().begin() + Measured,
847 [](const std::unique_ptr<Edge> &L, const std::unique_ptr<Edge> &R) {
848 return L->SrcNumber != R->SrcNumber ? L->SrcNumber < R->SrcNumber
849 : L->DstNumber < R->DstNumber;
850 });
851
852 for (const Edge &E : make_pointee_range(MST.allEdges())) {
853 GCOVBlock &Src =
854 E.SrcBB ? Func.getBlock(E.SrcBB) : Func.getEntryBlock();
855 GCOVBlock &Dst =
856 E.DestBB ? Func.getBlock(E.DestBB) : Func.getReturnBlock();
857 Src.addEdge(Dst, E.Place ? 0 : uint32_t(GCOV_ARC_ON_TREE));
858 }
859
860 // Artificial functions such as global initializers
861 if (!SP->isArtificial())
862 Func.getBlock(&EntryBlock).getFile(Filename).addLine(Line);
863
864 LLVM_DEBUG(dumpEdges(MST, Func));
865
866 for (auto &GB : Func.Blocks) {
867 const BasicBlock &BB = *GB.first;
868 auto &Block = GB.second;
869 for (auto Succ : Block.OutEdges) {
870 uint32_t Idx = Succ.first->Number;
871 do EdgeDestinations.push_back(Idx & 255);
872 while ((Idx >>= 8) > 0);
873 }
874
875 for (const auto &I : BB) {
876 const DebugLoc &Loc = I.getDebugLoc();
877 if (!Loc)
878 continue;
879
880 // Artificial lines such as calls to the global constructors.
881 if (Loc.getLine() == 0 || Loc.isImplicitCode())
882 continue;
883
884 if (Line == Loc.getLine()) continue;
885 Line = Loc.getLine();
886 MDNode *Scope = Loc.getScope();
887 if (SP != getDISubprogram(Scope))
888 continue;
889
890 GCOVLines &Lines = Block.getFile(getFilename(Loc->getScope(), VFS));
891 Lines.addLine(Loc.getLine());
892 }
893 Line = 0;
894 }
895 if (EmitGCDA) {
896 DISubprogram *SP = F.getSubprogram();
897 ArrayType *CounterTy = ArrayType::get(Type::getInt64Ty(*Ctx), Measured);
899 *M, CounterTy, false, GlobalValue::InternalLinkage,
900 Constant::getNullValue(CounterTy), "__llvm_gcov_ctr");
901 const llvm::Triple &Triple = M->getTargetTriple();
903 Counters->setSection("__llvm_gcov_ctr_section");
904 CountersBySP.emplace_back(Counters, SP);
905
906 for (size_t I : llvm::seq<size_t>(0, Measured)) {
907 const Edge &E = *MST.allEdges()[I];
908 IRBuilder<> Builder(E.Place, E.Place->getFirstInsertionPt());
909 Value *V = Builder.CreateConstInBoundsGEP2_64(
910 Counters->getValueType(), Counters, 0, I);
911 // Disable sanitizers to decrease size bloat. We don't expect
912 // sanitizers to catch interesting issues.
913 Instruction *Inst;
914 if (Options.Atomic) {
915 Inst = Builder.CreateAtomicRMW(AtomicRMWInst::Add, V,
916 Builder.getInt64(1), MaybeAlign(),
918 } else {
919 LoadInst *OldCount =
920 Builder.CreateLoad(Builder.getInt64Ty(), V, "gcov_ctr");
921 OldCount->setNoSanitizeMetadata();
922 Value *NewCount = Builder.CreateAdd(OldCount, Builder.getInt64(1));
923 Inst = Builder.CreateStore(NewCount, V);
924 }
925 Inst->setNoSanitizeMetadata();
926 }
927 }
928 }
929
930 char Tmp[4];
931 JamCRC JC;
932 JC.update(EdgeDestinations);
933 uint32_t Stamp = JC.getCRC();
934 FileChecksums.push_back(Stamp);
935
936 if (Options.EmitNotes) {
937 std::error_code EC;
938 raw_fd_ostream out(mangleName(CU, GCovFileType::GCNO), EC,
940 if (EC) {
941 Ctx->emitError(
942 Twine("failed to open coverage notes file for writing: ") +
943 EC.message());
944 continue;
945 }
946 os = &out;
947 if (Endian == llvm::endianness::big) {
948 out.write("gcno", 4);
949 out.write(Options.Version, 4);
950 } else {
951 out.write("oncg", 4);
952 std::reverse_copy(Options.Version, Options.Version + 4, Tmp);
953 out.write(Tmp, 4);
954 }
955 write(Stamp);
956 writeString("."); // unuseful current_working_directory
957 write(0); // unuseful has_unexecuted_blocks
958
959 for (auto &Func : Funcs)
960 Func->writeOut(Stamp);
961
962 write(0);
963 write(0);
964 out.close();
965 }
966
967 if (EmitGCDA) {
968 const llvm::Triple &Triple = M->getTargetTriple();
970 emitModuleInitFunctionPtrs(CountersBySP);
971 else
972 emitGlobalConstructor(CountersBySP);
973 EmitGCDA = false;
974 }
975 }
976 return true;
977}
978
979Function *GCOVProfiler::createInternalFunction(FunctionType *FTy,
980 StringRef Name,
981 StringRef MangledType /*=""*/) {
983 FTy, GlobalValue::InternalLinkage, 0, Name, M);
984 F->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
985 F->addFnAttr(Attribute::NoUnwind);
986 if (Options.NoRedZone)
987 F->addFnAttr(Attribute::NoRedZone);
988 if (!MangledType.empty())
989 setKCFIType(*M, *F, MangledType);
990 return F;
991}
992
993void GCOVProfiler::emitGlobalConstructor(
994 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
995 Function *WriteoutF = insertCounterWriteout(CountersBySP);
996 Function *ResetF = insertReset(CountersBySP);
997
998 // Create a small bit of code that registers the "__llvm_gcov_writeout" to
999 // be executed at exit and the "__llvm_gcov_reset" function to be executed
1000 // when "__gcov_flush" is called.
1001 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
1002 Function *F = createInternalFunction(FTy, "__llvm_gcov_init", "_ZTSFvvE");
1003 F->addFnAttr(Attribute::NoInline);
1004
1005 BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", F);
1006 IRBuilder<> Builder(BB);
1007
1008 FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
1009 auto *PFTy = PointerType::get(*Ctx, 0);
1010 FTy = FunctionType::get(Builder.getVoidTy(), {PFTy, PFTy}, false);
1011
1012 // Initialize the environment and register the local writeout, flush and
1013 // reset functions.
1014 FunctionCallee GCOVInit = M->getOrInsertFunction("llvm_gcov_init", FTy);
1015 Builder.CreateCall(GCOVInit, {WriteoutF, ResetF});
1016 Builder.CreateRetVoid();
1017
1018 appendToGlobalCtors(*M, F, 0);
1019}
1020
1021void GCOVProfiler::emitModuleInitFunctionPtrs(
1022 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
1023 Function *WriteoutF = insertCounterWriteout(CountersBySP);
1024 Function *ResetF = insertReset(CountersBySP);
1025
1026 // Instead of creating a function call and add it to the constructors list,
1027 // create a global variable in the __llvm_covinit section so the functions
1028 // can be registered by a constructor in the runtime.
1029
1030 auto &Ctx = M->getContext();
1031
1032 Type *InitFuncDataTy[] = {
1033#define COVINIT_FUNC(Type, LLVMType, Name, Init) LLVMType,
1035 };
1036
1037 auto STy = StructType::get(Ctx, ArrayRef(InitFuncDataTy));
1038
1039 Constant *InitFuncPtrs[] = {
1040#define COVINIT_FUNC(Type, LLVMType, Name, Init) Init,
1042 };
1043
1044 auto *CovInitGV =
1045 new GlobalVariable(*M, STy, false, GlobalValue::PrivateLinkage, nullptr,
1046 "__llvm_covinit_functions");
1047 CovInitGV->setInitializer(ConstantStruct::get(STy, InitFuncPtrs));
1048 CovInitGV->setVisibility(GlobalValue::VisibilityTypes::DefaultVisibility);
1049 CovInitGV->setSection(getInstrProfSectionName(
1050 IPSK_covinit, M->getTargetTriple().getObjectFormat()));
1051 CovInitGV->setAlignment(Align(INSTR_PROF_DATA_ALIGNMENT));
1052 CovInitGV->setConstant(true);
1053}
1054
1055FunctionCallee GCOVProfiler::getStartFileFunc(const TargetLibraryInfo *TLI) {
1056 Type *Args[] = {
1057 PointerType::getUnqual(*Ctx), // const char *orig_filename
1058 Type::getInt32Ty(*Ctx), // uint32_t version
1059 Type::getInt32Ty(*Ctx), // uint32_t checksum
1060 };
1061 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
1062 return M->getOrInsertFunction("llvm_gcda_start_file", FTy,
1063 TLI->getAttrList(Ctx, {1, 2}, /*Signed=*/false));
1064}
1065
1066FunctionCallee GCOVProfiler::getEmitFunctionFunc(const TargetLibraryInfo *TLI) {
1067 Type *Args[] = {
1068 Type::getInt32Ty(*Ctx), // uint32_t ident
1069 Type::getInt32Ty(*Ctx), // uint32_t func_checksum
1070 Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum
1071 };
1072 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
1073 return M->getOrInsertFunction("llvm_gcda_emit_function", FTy,
1074 TLI->getAttrList(Ctx, {0, 1, 2}, /*Signed=*/false));
1075}
1076
1077FunctionCallee GCOVProfiler::getEmitArcsFunc(const TargetLibraryInfo *TLI) {
1078 Type *Args[] = {
1079 Type::getInt32Ty(*Ctx), // uint32_t num_counters
1080 PointerType::getUnqual(*Ctx), // uint64_t *counters
1081 };
1082 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), Args, false);
1083 return M->getOrInsertFunction("llvm_gcda_emit_arcs", FTy,
1084 TLI->getAttrList(Ctx, {0}, /*Signed=*/false));
1085}
1086
1087FunctionCallee GCOVProfiler::getSummaryInfoFunc() {
1088 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
1089 return M->getOrInsertFunction("llvm_gcda_summary_info", FTy);
1090}
1091
1092FunctionCallee GCOVProfiler::getEndFileFunc() {
1093 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
1094 return M->getOrInsertFunction("llvm_gcda_end_file", FTy);
1095}
1096
1097Function *GCOVProfiler::insertCounterWriteout(
1098 ArrayRef<std::pair<GlobalVariable *, MDNode *> > CountersBySP) {
1099 FunctionType *WriteoutFTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
1100 Function *WriteoutF = M->getFunction("__llvm_gcov_writeout");
1101 if (!WriteoutF)
1102 WriteoutF =
1103 createInternalFunction(WriteoutFTy, "__llvm_gcov_writeout", "_ZTSFvvE");
1104 WriteoutF->addFnAttr(Attribute::NoInline);
1105
1106 BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", WriteoutF);
1107 IRBuilder<> Builder(BB);
1108
1109 auto *TLI = &GetTLI(*WriteoutF);
1110
1111 FunctionCallee StartFile = getStartFileFunc(TLI);
1112 FunctionCallee EmitFunction = getEmitFunctionFunc(TLI);
1113 FunctionCallee EmitArcs = getEmitArcsFunc(TLI);
1114 FunctionCallee SummaryInfo = getSummaryInfoFunc();
1115 FunctionCallee EndFile = getEndFileFunc();
1116
1117 NamedMDNode *CUNodes = M->getNamedMetadata("llvm.dbg.cu");
1118 if (!CUNodes) {
1119 Builder.CreateRetVoid();
1120 return WriteoutF;
1121 }
1122
1123 // Collect the relevant data into a large constant data structure that we can
1124 // walk to write out everything.
1125 StructType *StartFileCallArgsTy = StructType::create(
1126 {Builder.getPtrTy(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1127 "start_file_args_ty");
1128 StructType *EmitFunctionCallArgsTy = StructType::create(
1129 {Builder.getInt32Ty(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1130 "emit_function_args_ty");
1131 auto *PtrTy = Builder.getPtrTy();
1132 StructType *EmitArcsCallArgsTy =
1133 StructType::create({Builder.getInt32Ty(), PtrTy}, "emit_arcs_args_ty");
1134 StructType *FileInfoTy = StructType::create(
1135 {StartFileCallArgsTy, Builder.getInt32Ty(), PtrTy, PtrTy}, "file_info");
1136
1137 Constant *Zero32 = Builder.getInt32(0);
1138 // Build an explicit array of two zeros for use in ConstantExpr GEP building.
1139 Constant *TwoZero32s[] = {Zero32, Zero32};
1140
1142 for (int i : llvm::seq<int>(0, CUNodes->getNumOperands())) {
1143 auto *CU = cast<DICompileUnit>(CUNodes->getOperand(i));
1144
1145 // Skip module skeleton (and module) CUs.
1146 if (CU->getDWOId())
1147 continue;
1148
1149 std::string FilenameGcda = mangleName(CU, GCovFileType::GCDA);
1150 uint32_t CfgChecksum = FileChecksums.empty() ? 0 : FileChecksums[i];
1151 auto *StartFileCallArgs = ConstantStruct::get(
1152 StartFileCallArgsTy,
1153 {Builder.CreateGlobalString(FilenameGcda),
1154 Builder.getInt32(endian::read32be(Options.Version)),
1155 Builder.getInt32(CfgChecksum)});
1156
1157 SmallVector<Constant *, 8> EmitFunctionCallArgsArray;
1158 SmallVector<Constant *, 8> EmitArcsCallArgsArray;
1159 for (int j : llvm::seq<int>(0, CountersBySP.size())) {
1160 uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[j]->getFuncChecksum();
1161 EmitFunctionCallArgsArray.push_back(ConstantStruct::get(
1162 EmitFunctionCallArgsTy,
1163 {Builder.getInt32(j),
1164 Builder.getInt32(FuncChecksum),
1165 Builder.getInt32(CfgChecksum)}));
1166
1167 GlobalVariable *GV = CountersBySP[j].first;
1168 unsigned Arcs = cast<ArrayType>(GV->getValueType())->getNumElements();
1169 EmitArcsCallArgsArray.push_back(ConstantStruct::get(
1170 EmitArcsCallArgsTy,
1171 {Builder.getInt32(Arcs), ConstantExpr::getInBoundsGetElementPtr(
1172 GV->getValueType(), GV, TwoZero32s)}));
1173 }
1174 // Create global arrays for the two emit calls.
1175 int CountersSize = CountersBySP.size();
1176 assert(CountersSize == (int)EmitFunctionCallArgsArray.size() &&
1177 "Mismatched array size!");
1178 assert(CountersSize == (int)EmitArcsCallArgsArray.size() &&
1179 "Mismatched array size!");
1180 auto *EmitFunctionCallArgsArrayTy =
1181 ArrayType::get(EmitFunctionCallArgsTy, CountersSize);
1182 auto *EmitFunctionCallArgsArrayGV = new GlobalVariable(
1183 *M, EmitFunctionCallArgsArrayTy, /*isConstant*/ true,
1185 ConstantArray::get(EmitFunctionCallArgsArrayTy,
1186 EmitFunctionCallArgsArray),
1187 Twine("__llvm_internal_gcov_emit_function_args.") + Twine(i));
1188 auto *EmitArcsCallArgsArrayTy =
1189 ArrayType::get(EmitArcsCallArgsTy, CountersSize);
1190 EmitFunctionCallArgsArrayGV->setUnnamedAddr(
1192 auto *EmitArcsCallArgsArrayGV = new GlobalVariable(
1193 *M, EmitArcsCallArgsArrayTy, /*isConstant*/ true,
1195 ConstantArray::get(EmitArcsCallArgsArrayTy, EmitArcsCallArgsArray),
1196 Twine("__llvm_internal_gcov_emit_arcs_args.") + Twine(i));
1197 EmitArcsCallArgsArrayGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
1198
1200 FileInfoTy,
1201 {StartFileCallArgs, Builder.getInt32(CountersSize),
1202 ConstantExpr::getInBoundsGetElementPtr(EmitFunctionCallArgsArrayTy,
1203 EmitFunctionCallArgsArrayGV,
1204 TwoZero32s),
1206 EmitArcsCallArgsArrayTy, EmitArcsCallArgsArrayGV, TwoZero32s)}));
1207 }
1208
1209 // If we didn't find anything to actually emit, bail on out.
1210 if (FileInfos.empty()) {
1211 Builder.CreateRetVoid();
1212 return WriteoutF;
1213 }
1214
1215 // To simplify code, we cap the number of file infos we write out to fit
1216 // easily in a 32-bit signed integer. This gives consistent behavior between
1217 // 32-bit and 64-bit systems without requiring (potentially very slow) 64-bit
1218 // operations on 32-bit systems. It also seems unreasonable to try to handle
1219 // more than 2 billion files.
1220 if ((int64_t)FileInfos.size() > (int64_t)INT_MAX)
1221 FileInfos.resize(INT_MAX);
1222
1223 // Create a global for the entire data structure so we can walk it more
1224 // easily.
1225 auto *FileInfoArrayTy = ArrayType::get(FileInfoTy, FileInfos.size());
1226 auto *FileInfoArrayGV = new GlobalVariable(
1227 *M, FileInfoArrayTy, /*isConstant*/ true, GlobalValue::InternalLinkage,
1228 ConstantArray::get(FileInfoArrayTy, FileInfos),
1229 "__llvm_internal_gcov_emit_file_info");
1230 FileInfoArrayGV->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
1231
1232 // Create the CFG for walking this data structure.
1233 auto *FileLoopHeader =
1234 BasicBlock::Create(*Ctx, "file.loop.header", WriteoutF);
1235 auto *CounterLoopHeader =
1236 BasicBlock::Create(*Ctx, "counter.loop.header", WriteoutF);
1237 auto *FileLoopLatch = BasicBlock::Create(*Ctx, "file.loop.latch", WriteoutF);
1238 auto *ExitBB = BasicBlock::Create(*Ctx, "exit", WriteoutF);
1239
1240 // We always have at least one file, so just branch to the header.
1241 Builder.CreateBr(FileLoopHeader);
1242
1243 // The index into the files structure is our loop induction variable.
1244 Builder.SetInsertPoint(FileLoopHeader);
1245 PHINode *IV = Builder.CreatePHI(Builder.getInt32Ty(), /*NumReservedValues*/ 2,
1246 "file_idx");
1247 IV->addIncoming(Builder.getInt32(0), BB);
1248 auto *FileInfoPtr = Builder.CreateInBoundsGEP(
1249 FileInfoArrayTy, FileInfoArrayGV, {Builder.getInt32(0), IV});
1250 auto *StartFileCallArgsPtr =
1251 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0, "start_file_args");
1252 auto *StartFileCall = Builder.CreateCall(
1253 StartFile,
1254 {Builder.CreateLoad(StartFileCallArgsTy->getElementType(0),
1255 Builder.CreateStructGEP(StartFileCallArgsTy,
1256 StartFileCallArgsPtr, 0),
1257 "filename"),
1258 Builder.CreateLoad(StartFileCallArgsTy->getElementType(1),
1259 Builder.CreateStructGEP(StartFileCallArgsTy,
1260 StartFileCallArgsPtr, 1),
1261 "version"),
1262 Builder.CreateLoad(StartFileCallArgsTy->getElementType(2),
1263 Builder.CreateStructGEP(StartFileCallArgsTy,
1264 StartFileCallArgsPtr, 2),
1265 "stamp")});
1266 if (auto AK = TLI->getExtAttrForI32Param(false))
1267 StartFileCall->addParamAttr(2, AK);
1268 auto *NumCounters = Builder.CreateLoad(
1269 FileInfoTy->getElementType(1),
1270 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1), "num_ctrs");
1271 auto *EmitFunctionCallArgsArray =
1272 Builder.CreateLoad(FileInfoTy->getElementType(2),
1273 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2),
1274 "emit_function_args");
1275 auto *EmitArcsCallArgsArray = Builder.CreateLoad(
1276 FileInfoTy->getElementType(3),
1277 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3), "emit_arcs_args");
1278 auto *EnterCounterLoopCond =
1279 Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters);
1280 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
1281
1282 Builder.SetInsertPoint(CounterLoopHeader);
1283 auto *JV = Builder.CreatePHI(Builder.getInt32Ty(), /*NumReservedValues*/ 2,
1284 "ctr_idx");
1285 JV->addIncoming(Builder.getInt32(0), FileLoopHeader);
1286 auto *EmitFunctionCallArgsPtr = Builder.CreateInBoundsGEP(
1287 EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
1288 auto *EmitFunctionCall = Builder.CreateCall(
1289 EmitFunction,
1290 {Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1291 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1292 EmitFunctionCallArgsPtr, 0),
1293 "ident"),
1294 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1295 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1296 EmitFunctionCallArgsPtr, 1),
1297 "func_checkssum"),
1298 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1299 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1300 EmitFunctionCallArgsPtr, 2),
1301 "cfg_checksum")});
1302 if (auto AK = TLI->getExtAttrForI32Param(false)) {
1303 EmitFunctionCall->addParamAttr(0, AK);
1304 EmitFunctionCall->addParamAttr(1, AK);
1305 EmitFunctionCall->addParamAttr(2, AK);
1306 }
1307 auto *EmitArcsCallArgsPtr =
1308 Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
1309 auto *EmitArcsCall = Builder.CreateCall(
1310 EmitArcs,
1311 {Builder.CreateLoad(
1312 EmitArcsCallArgsTy->getElementType(0),
1313 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0),
1314 "num_counters"),
1315 Builder.CreateLoad(
1316 EmitArcsCallArgsTy->getElementType(1),
1317 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 1),
1318 "counters")});
1319 if (auto AK = TLI->getExtAttrForI32Param(false))
1320 EmitArcsCall->addParamAttr(0, AK);
1321 auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1));
1322 auto *CounterLoopCond = Builder.CreateICmpSLT(NextJV, NumCounters);
1323 Builder.CreateCondBr(CounterLoopCond, CounterLoopHeader, FileLoopLatch);
1324 JV->addIncoming(NextJV, CounterLoopHeader);
1325
1326 Builder.SetInsertPoint(FileLoopLatch);
1327 Builder.CreateCall(SummaryInfo, {});
1328 Builder.CreateCall(EndFile, {});
1329 auto *NextIV = Builder.CreateAdd(IV, Builder.getInt32(1), "next_file_idx");
1330 auto *FileLoopCond =
1331 Builder.CreateICmpSLT(NextIV, Builder.getInt32(FileInfos.size()));
1332 Builder.CreateCondBr(FileLoopCond, FileLoopHeader, ExitBB);
1333 IV->addIncoming(NextIV, FileLoopLatch);
1334
1335 Builder.SetInsertPoint(ExitBB);
1336 Builder.CreateRetVoid();
1337
1338 return WriteoutF;
1339}
1340
1341Function *GCOVProfiler::insertReset(
1342 ArrayRef<std::pair<GlobalVariable *, MDNode *>> CountersBySP) {
1343 FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false);
1344 Function *ResetF = M->getFunction("__llvm_gcov_reset");
1345 if (!ResetF)
1346 ResetF = createInternalFunction(FTy, "__llvm_gcov_reset", "_ZTSFvvE");
1347 ResetF->addFnAttr(Attribute::NoInline);
1348
1349 BasicBlock *Entry = BasicBlock::Create(*Ctx, "entry", ResetF);
1350 IRBuilder<> Builder(Entry);
1351 LLVMContext &C = Entry->getContext();
1352
1353 // Zero out the counters.
1354 for (const auto &I : CountersBySP) {
1355 GlobalVariable *GV = I.first;
1356 auto *GVTy = cast<ArrayType>(GV->getValueType());
1357 Builder.CreateMemSet(GV, Constant::getNullValue(Type::getInt8Ty(C)),
1358 GVTy->getNumElements() *
1359 GVTy->getElementType()->getScalarSizeInBits() / 8,
1360 GV->getAlign());
1361 }
1362
1363 Type *RetTy = ResetF->getReturnType();
1364 if (RetTy->isVoidTy())
1365 Builder.CreateRetVoid();
1366 else if (RetTy->isIntegerTy())
1367 // Used if __llvm_gcov_reset was implicitly declared.
1368 Builder.CreateRet(ConstantInt::get(RetTy, 0));
1369 else
1370 report_fatal_error("invalid return type for __llvm_gcov_reset");
1371
1372 return ResetF;
1373}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
Expand Atomic instructions
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides the interface for the GCOV style profiler pass.
static unsigned wordsOfString(StringRef s)
static bool functionHasLines(const Function &F, unsigned &EndLine)
static bool isUsingScopeBasedEH(Function &F)
static void dumpEdges(CFGMST< Edge, BBInfo > &MST, GCOVFunction &GF)
static BasicBlock * getInstrBB(CFGMST< Edge, BBInfo > &MST, Edge &E, const DenseSet< const BasicBlock * > &ExecBlocks)
static cl::opt< std::string > DefaultGCOVVersion("default-gcov-version", cl::init("0000"), cl::Hidden, cl::ValueRequired)
static SmallString< 128 > getFilename(const DIScope *SP, vfs::FileSystem &VFS)
Extract a filename for a DIScope.
static StringRef getFunctionName(const DISubprogram *SP)
static cl::opt< bool > AtomicCounter("gcov-atomic-counter", cl::Hidden, cl::desc("Make counter updates atomic"))
@ GCOV_TAG_LINES
Definition GCOV.cpp:38
@ GCOV_ARC_ON_TREE
Definition GCOV.cpp:32
@ GCOV_TAG_ARCS
Definition GCOV.cpp:37
@ GCOV_TAG_FUNCTION
Definition GCOV.cpp:35
@ GCOV_TAG_BLOCKS
Definition GCOV.cpp:36
Module.h This file contains the declarations for the Module class.
#define INSTR_PROF_DATA_ALIGNMENT
static LVOptions Options
Definition LVOptions.cpp:25
static void addEdge(SmallVectorImpl< LazyCallGraph::Edge > &Edges, DenseMap< LazyCallGraph::Node *, int > &EdgeIndexMap, LazyCallGraph::Node &N, LazyCallGraph::Edge::Kind EK)
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
#define P(N)
FunctionAnalysisManager FAM
std::pair< BasicBlock *, BasicBlock * > Edge
This file contains some templates that are useful if you are working with the STL at all.
Provides some synthesis utilities to produce sequences of values.
#define LLVM_DEBUG(...)
Definition Debug.h:114
Defines the virtual file system interface vfs::FileSystem.
Value * RHS
static const uint32_t IV[8]
Definition blake3_impl.h:83
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
@ Add
*p = old + v
LLVM Basic Block Representation.
Definition BasicBlock.h:62
iterator end()
Definition BasicBlock.h:472
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
const Function * getParent() const
Return the enclosing method, or null if none.
Definition BasicBlock.h:213
const Instruction & back() const
Definition BasicBlock.h:484
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition BasicBlock.h:206
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
Definition BasicBlock.h:233
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Analysis pass which computes BranchProbabilityInfo.
Analysis providing branch probability information.
An union-find based Minimum Spanning Tree for CFG.
Definition CFGMST.h:40
Edge & addEdge(BasicBlock *Src, BasicBlock *Dest, uint64_t W)
Definition CFGMST.h:304
const std::vector< std::unique_ptr< Edge > > & allEdges() const
Definition CFGMST.h:341
This class represents a function call, abstracting a target machine's calling convention.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
Definition Constants.h:1301
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
Definition Constant.h:43
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
uint64_t getDWOId() const
Base class for scope-like contexts.
StringRef getFilename() const
Subprogram description. Uses SubclassData1.
A debug info location.
Definition DebugLoc.h:124
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
Represents either an error or a value T.
Definition ErrorOr.h:56
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
Definition Function.cpp:637
static Function * createWithDefaultAttr(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Creates a function with some attributes recorded in llvm.module.flags and the LLVMContext applied.
Definition Function.cpp:380
Type * getReturnType() const
Returns the type of the ret val.
Definition Function.h:214
GCOVBlock - Collects block information.
Definition GCOV.h:283
GCOVBlock(uint32_t N)
Definition GCOV.h:290
GCOVFunction - Collects function information.
Definition GCOV.h:237
GCOVFunction(GCOVFile &file)
Definition GCOV.h:242
LLVM_ABI StringRef getFilename() const
Definition GCOV.cpp:353
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
@ DefaultVisibility
The GV is visible.
Definition GlobalValue.h:68
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
@ InternalLinkage
Rename collisions when linking (static functions).
Definition GlobalValue.h:60
Type * getValueType() const
MaybeAlign getAlign() const
Returns the alignment of the given variable.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition IRBuilder.h:2780
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI void setNoSanitizeMetadata()
Sets the nosanitize metadata on this instruction.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
uint32_t getCRC() const
Definition CRC.h:53
LLVM_ABI void update(ArrayRef< uint8_t > Data)
Definition CRC.cpp:103
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
An instruction for reading from memory.
Metadata node.
Definition Metadata.h:1078
const MDOperand & getOperand(unsigned I) const
Definition Metadata.h:1442
A single uniqued string.
Definition Metadata.h:721
LLVM_ABI StringRef getString() const
Definition Metadata.cpp:618
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
A tuple of MDNodes.
Definition Metadata.h:1757
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
Definition Analysis.h:115
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void resize(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition StringRef.h:702
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:143
constexpr size_t size() const
size - Get the string size.
Definition StringRef.h:146
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition StringRef.h:140
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Definition Type.cpp:414
static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition Type.cpp:620
Type * getElementType(unsigned N) const
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
AttributeList getAttrList(LLVMContext *C, ArrayRef< unsigned > ArgNos, bool Signed, bool Ret=false, AttributeList AL=AttributeList()) const
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
Definition Triple.h:437
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:298
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:281
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
Definition Type.cpp:295
bool isIntegerTy() const
True if this is an instance of IntegerType.
Definition Type.h:240
bool isVoidTy() const
Return true if this is 'void'.
Definition Type.h:139
LLVM Value Representation.
Definition Value.h:75
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:180
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
Definition ilist_node.h:123
A raw_ostream that writes to a file descriptor.
The virtual file system interface.
virtual bool exists(const Twine &Path)
Check whether Path exists.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ Entry
Definition COFF.h:862
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ BasicBlock
Various leaf nodes.
Definition ISDOpcodes.h:81
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
Definition RDFGraph.h:393
void write32(void *P, uint32_t V, endianness E)
Definition Endian.h:455
uint32_t read32be(const void *P)
Definition Endian.h:441
LLVM_ABI void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
Definition Path.cpp:480
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:577
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
Definition Path.cpp:456
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
LLVM_ABI unsigned GetSuccessorNumber(const BasicBlock *BB, const BasicBlock *Succ)
Search for the specified successor of basic block BB and return its position in the terminator instru...
Definition CFG.cpp:80
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:644
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
FunctionAddr NumCounters
Definition InstrProf.h:91
LLVM_ABI bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)
LLVM_ABI std::string getInstrProfSectionName(InstrProfSectKind IPSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)
Return the name of the profile section corresponding to IPSK.
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
Definition iterator.h:336
FunctionAddr VTableAddr uintptr_t uintptr_t Version
Definition InstrProf.h:302
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
Definition DWP.cpp:622
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:548
LLVM_ABI BasicBlock * SplitCriticalEdge(Instruction *TI, unsigned SuccNum, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions(), const Twine &BBName="")
If this edge is a critical edge, insert a new node to split the critical edge.
ArrayRef(const T &OneElt) -> ArrayRef< T >
LLVM_ABI void appendToGlobalCtors(Module &M, Function *F, int Priority, Constant *Data=nullptr)
Append F to the list of global ctors of module M with the given Priority.
LLVM_ABI void setKCFIType(Module &M, Function &F, StringRef MangledType)
Sets the KCFI type for the function.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:560
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Definition STLExtras.h:2100
auto seq(T Begin, T End)
Iterate over an integral type from Begin up to - but not including - End.
Definition Sequence.h:305
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
endianness
Definition bit.h:71
LLVM_ABI DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:180
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static LLVM_ABI GCOVOptions getDefault()
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106