51#define DEBUG_TYPE "insert-gcov-profiling"
67 cl::desc(
"Make counter updates atomic"));
72 return (s.
size() / 4) + 2;
95 GCOVProfiler() : GCOVProfiler(
GCOVOptions::getDefault()) {}
110 os->write_zeros(4 - s.
size() % 4);
112 void writeBytes(
const char *Bytes,
int Size) { os->write(Bytes,
Size); }
117 emitProfileNotes(
NamedMDNode *CUNode,
bool HasExecOrFork,
124 void emitGlobalConstructor(
127 bool isFunctionInstrumented(
const Function &
F);
128 std::vector<Regex> createRegexesFromString(
StringRef RegexesStr);
129 static bool doesFilenameMatchARegex(
StringRef Filename,
130 std::vector<Regex> &Regexes);
142 insertCounterWriteout(
ArrayRef<std::pair<GlobalVariable *, MDNode *>>);
145 bool AddFlushBeforeForkAndExec();
147 enum class GCovFileType { GCNO, GCDA };
148 std::string mangleName(
const DICompileUnit *
CU, GCovFileType FileType);
161 std::vector<Regex> FilterRe;
162 std::vector<Regex> ExcludeRe;
173 std::string infoString()
const {
187 bool Removed =
false;
188 bool IsCritical =
false;
191 : SrcBB(Src), DestBB(Dest), Weight(
W) {}
194 std::string infoString()
const {
195 return (
Twine(Removed ?
"-" :
" ") + (InMST ?
" " :
"*") +
196 (IsCritical ?
"c" :
" ") +
" W=" +
Twine(Weight))
203 if (!SP->getLinkageName().empty())
204 return SP->getLinkageName();
228 GCOVRecord(GCOVProfiler *
P) :
P(
P) {}
231 void writeString(
StringRef s) {
P->writeString(s); }
232 void writeBytes(
const char *Bytes,
int Size) {
P->writeBytes(Bytes,
Size); }
241 class GCOVLines :
public GCOVRecord {
244 assert(Line != 0 &&
"Line zero is not a valid real line number.");
245 Lines.push_back(Line);
254 writeString(Filename);
274 return LinesByFile.try_emplace(Filename,
P, Filename).first->second;
278 OutEdges.emplace_back(&
Successor, Flags);
284 for (
auto &
I : LinesByFile) {
285 Len +=
I.second.length();
295 return LHS->getKey() <
RHS->getKey();
297 for (
auto &
I : SortedLinesByFile)
298 I->getValue().writeOut();
307 assert(LinesByFile.empty());
330 : GCOVRecord(
P), SP(SP), EndLine(EndLine), Ident(Ident),
333 bool ExitBlockBeforeBody =
Version >= 48;
334 uint32_t i = ExitBlockBeforeBody ? 2 : 1;
337 if (!ExitBlockBeforeBody)
338 ReturnBlock.Number = i;
340 std::string FunctionNameAndLine;
344 FuncChecksum =
hash_value(FunctionNameAndLine);
351 GCOVBlock &getEntryBlock() {
return EntryBlock; }
360 void writeOut(
uint32_t CfgChecksum) {
377 writeString(Filename);
378 write(SP->getLine());
380 write(SP->isArtificial());
381 writeString(Filename);
382 write(SP->getLine());
395 for (
int i =
Blocks.size() + 2; i; --i)
404 const uint32_t Outgoing = EntryBlock.OutEdges.size();
407 write(Outgoing * 2 + 1);
408 write(EntryBlock.Number);
409 for (
const auto &E : EntryBlock.OutEdges) {
410 write(E.first->Number);
416 if (
Block.OutEdges.empty())
continue;
421 for (
const auto &E :
Block.OutEdges) {
422 write(E.first->Number);
429 It.second.writeOut();
446std::vector<Regex> GCOVProfiler::createRegexesFromString(
StringRef RegexesStr) {
447 std::vector<Regex> Regexes;
448 while (!RegexesStr.
empty()) {
449 std::pair<StringRef, StringRef> HeadTail = RegexesStr.
split(
';');
450 if (!HeadTail.first.empty()) {
451 Regex Re(HeadTail.first);
453 if (!Re.isValid(Err)) {
454 Ctx->emitError(
Twine(
"Regex ") + HeadTail.first +
455 " is not valid: " + Err);
457 Regexes.emplace_back(std::move(Re));
459 RegexesStr = HeadTail.second;
464bool GCOVProfiler::doesFilenameMatchARegex(
StringRef Filename,
465 std::vector<Regex> &Regexes) {
466 for (
Regex &Re : Regexes)
467 if (Re.match(Filename))
472bool GCOVProfiler::isFunctionInstrumented(
const Function &
F) {
473 if (FilterRe.empty() && ExcludeRe.empty()) {
477 auto It = InstrumentedFiles.find(Filename);
478 if (It != InstrumentedFiles.end()) {
492 RealFilename = RealPath;
495 bool ShouldInstrument;
496 if (FilterRe.empty()) {
497 ShouldInstrument = !doesFilenameMatchARegex(RealFilename, ExcludeRe);
498 }
else if (ExcludeRe.empty()) {
499 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe);
501 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe) &&
502 !doesFilenameMatchARegex(RealFilename, ExcludeRe);
504 InstrumentedFiles[
Filename] = ShouldInstrument;
505 return ShouldInstrument;
509 GCovFileType OutputType) {
510 bool Notes = OutputType == GCovFileType::GCNO;
512 if (
NamedMDNode *GCov =
M->getNamedMetadata(
"llvm.gcov")) {
513 for (
int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
514 MDNode *
N = GCov->getOperand(i);
515 bool ThreeElement =
N->getNumOperands() == 3;
516 if (!ThreeElement &&
N->getNumOperands() != 2)
518 if (dyn_cast<MDNode>(
N->getOperand(ThreeElement ? 2 : 1)) !=
CU)
524 MDString *NotesFile = dyn_cast<MDString>(
N->getOperand(0));
525 MDString *DataFile = dyn_cast<MDString>(
N->getOperand(1));
526 if (!NotesFile || !DataFile)
528 return std::string(Notes ? NotesFile->
getString()
532 MDString *GCovFile = dyn_cast<MDString>(
N->getOperand(0));
538 return std::string(Filename);
547 return std::string(FName);
549 return std::string(CurPath);
552bool GCOVProfiler::runOnModule(
557 this->GetTLI = std::move(GetTLI);
558 Ctx = &
M.getContext();
560 NamedMDNode *CUNode =
M.getNamedMetadata(
"llvm.dbg.cu");
564 bool HasExecOrFork = AddFlushBeforeForkAndExec();
566 FilterRe = createRegexesFromString(
Options.Filter);
567 ExcludeRe = createRegexesFromString(
Options.Exclude);
568 emitProfileNotes(CUNode, HasExecOrFork, GetBFI, GetBPI, this->GetTLI);
575 GCOVProfiler Profiler(GCOVOpts);
589 if (!Profiler.runOnModule(M, GetBFI, GetBPI, GetTLI))
599 for (
const auto &BB :
F) {
600 for (
const auto &
I : BB) {
603 if (isa<DbgInfoIntrinsic>(&
I))
continue;
610 if (Loc.
getLine() == 0)
continue;
611 EndLine = std::max(EndLine, Loc.
getLine());
620 if (!
F.hasPersonalityFn())
return false;
626bool GCOVProfiler::AddFlushBeforeForkAndExec() {
630 for (
auto &
F :
M->functions()) {
631 TLI = TLI ==
nullptr ? &GetTLI(
F) : TLI;
633 if (
CallInst *CI = dyn_cast<CallInst>(&
I)) {
634 if (
Function *Callee = CI->getCalledFunction()) {
637 if (LF == LibFunc_fork) {
641 }
else if (LF == LibFunc_execl || LF == LibFunc_execle ||
642 LF == LibFunc_execlp || LF == LibFunc_execv ||
643 LF == LibFunc_execvp || LF == LibFunc_execve ||
644 LF == LibFunc_execvpe || LF == LibFunc_execvP) {
653 for (
auto *
F : Forks) {
656 auto NextInst = ++
F->getIterator();
663 F->setCalledFunction(GCOVFork);
680 for (
auto *E : Execs) {
689 M->getOrInsertFunction(
"llvm_writeout_files", FTy);
690 Builder.CreateCall(WriteoutF);
693 Builder.SetInsertPoint(&*NextInst);
696 FunctionCallee ResetF =
M->getOrInsertFunction(
"llvm_reset_counters", FTy);
697 Builder.CreateCall(ResetF)->setDebugLoc(Loc);
698 ExecBlocks.insert(Parent);
703 return !Forks.empty() || !Execs.empty();
708 if (E.InMST || E.Removed)
714 if (SrcBB ==
nullptr)
716 if (DestBB ==
nullptr)
731 return CanInstrument(SrcBB);
733 return CanInstrument(DestBB);
743 MST.
addEdge(SrcBB, InstrBB, 0);
744 MST.
addEdge(InstrBB, DestBB, 0).InMST =
true;
747 return CanInstrument(InstrBB);
754 GCOVBlock &Src = E.SrcBB ? GF.getBlock(E.SrcBB) : GF.getEntryBlock();
755 GCOVBlock &Dst = E.DestBB ? GF.getBlock(E.DestBB) : GF.getReturnBlock();
756 dbgs() <<
" Edge " <<
ID++ <<
": " << Src.Number <<
"->" << Dst.Number
757 << E.infoString() <<
"\n";
762bool GCOVProfiler::emitProfileNotes(
769 uint8_t c3 =
Options.Version[0];
770 uint8_t c2 =
Options.Version[1];
771 uint8_t c1 =
Options.Version[2];
772 Version = c3 >=
'A' ? (c3 -
'A') * 100 + (c2 -
'0') * 10 + c1 -
'0'
773 : (c3 -
'0') * 10 + c1 -
'0';
776 bool EmitGCDA =
Options.EmitData;
788 std::vector<uint8_t> EdgeDestinations;
793 unsigned FunctionIdent = 0;
794 for (
auto &
F :
M->functions()) {
802 if (
F.hasFnAttribute(llvm::Attribute::NoProfile))
804 if (
F.hasFnAttribute(llvm::Attribute::SkipProfile))
823 for (
size_t I : llvm::seq<size_t>(0, MST.numEdges())) {
824 auto &E = *MST.allEdges()[
I];
833 Funcs.push_back(std::make_unique<GCOVFunction>(
this, &
F, SP, EndLine,
840 return E->Removed || (!E->InMST && !E->Place);
842 const size_t Measured =
843 std::stable_partition(
844 MST.allEdges().begin(), MST.allEdges().end(),
845 [](std::unique_ptr<Edge> &E) { return E->Place; }) -
846 MST.allEdges().begin();
847 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
848 Edge &E = *MST.allEdges()[
I];
850 E.SrcBB ?
Func.getBlock(E.SrcBB) :
Func.getEntryBlock();
852 E.DestBB ?
Func.getBlock(E.DestBB) :
Func.getReturnBlock();
853 E.SrcNumber = Src.Number;
854 E.DstNumber = Dst.Number;
857 MST.allEdges().begin(), MST.allEdges().begin() + Measured,
858 [](
const std::unique_ptr<Edge> &L,
const std::unique_ptr<Edge> &R) {
859 return L->SrcNumber != R->SrcNumber ? L->SrcNumber < R->SrcNumber
860 : L->DstNumber < R->DstNumber;
865 E.SrcBB ?
Func.getBlock(E.SrcBB) :
Func.getEntryBlock();
867 E.DestBB ?
Func.getBlock(E.DestBB) :
Func.getReturnBlock();
872 if (!SP->isArtificial())
873 Func.getBlock(&EntryBlock).getFile(Filename).addLine(Line);
877 for (
auto &GB :
Func.Blocks) {
879 auto &
Block = GB.second;
880 for (
auto Succ :
Block.OutEdges) {
882 do EdgeDestinations.push_back(
Idx & 255);
883 while ((
Idx >>= 8) > 0);
886 for (
const auto &
I : BB) {
889 if (isa<DbgInfoIntrinsic>(&
I))
continue;
899 if (Line == Loc.
getLine())
continue;
919 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
920 const Edge &E = *MST.allEdges()[
I];
921 IRBuilder<> Builder(E.Place, E.Place->getFirstInsertionPt());
922 Value *
V = Builder.CreateConstInBoundsGEP2_64(
933 Builder.CreateLoad(Builder.getInt64Ty(), V,
"gcov_ctr");
935 Value *NewCount = Builder.CreateAdd(OldCount, Builder.getInt64(1));
936 Inst = Builder.CreateStore(NewCount, V);
945 JC.
update(EdgeDestinations);
955 Twine(
"failed to open coverage notes file for writing: ") +
961 out.write(
"gcno", 4);
964 out.write(
"oncg", 4);
974 for (
auto &Func : Funcs)
975 Func->writeOut(Stamp);
983 emitGlobalConstructor(CountersBySP);
996 F->addFnAttr(Attribute::NoUnwind);
998 F->addFnAttr(Attribute::NoRedZone);
999 if (!MangledType.
empty())
1004void GCOVProfiler::emitGlobalConstructor(
1005 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
1006 Function *WriteoutF = insertCounterWriteout(CountersBySP);
1007 Function *ResetF = insertReset(CountersBySP);
1013 Function *
F = createInternalFunction(FTy,
"__llvm_gcov_init",
"_ZTSFvvE");
1014 F->addFnAttr(Attribute::NoInline);
1025 FunctionCallee GCOVInit =
M->getOrInsertFunction(
"llvm_gcov_init", FTy);
1026 Builder.CreateCall(GCOVInit, {WriteoutF, ResetF});
1027 Builder.CreateRetVoid();
1039 return M->getOrInsertFunction(
"llvm_gcda_start_file", FTy,
1050 return M->getOrInsertFunction(
"llvm_gcda_emit_function", FTy,
1060 return M->getOrInsertFunction(
"llvm_gcda_emit_arcs", FTy,
1066 return M->getOrInsertFunction(
"llvm_gcda_summary_info", FTy);
1071 return M->getOrInsertFunction(
"llvm_gcda_end_file", FTy);
1074Function *GCOVProfiler::insertCounterWriteout(
1075 ArrayRef<std::pair<GlobalVariable *, MDNode *> > CountersBySP) {
1077 Function *WriteoutF =
M->getFunction(
"__llvm_gcov_writeout");
1080 createInternalFunction(WriteoutFTy,
"__llvm_gcov_writeout",
"_ZTSFvvE");
1081 WriteoutF->
addFnAttr(Attribute::NoInline);
1086 auto *TLI = &GetTLI(*WriteoutF);
1094 NamedMDNode *CUNodes =
M->getNamedMetadata(
"llvm.dbg.cu");
1096 Builder.CreateRetVoid();
1103 {Builder.getPtrTy(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1104 "start_file_args_ty");
1106 {Builder.getInt32Ty(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1107 "emit_function_args_ty");
1108 auto *PtrTy = Builder.getPtrTy();
1112 {StartFileCallArgsTy, Builder.
getInt32Ty(), PtrTy, PtrTy},
"file_info");
1114 Constant *Zero32 = Builder.getInt32(0);
1116 Constant *TwoZero32s[] = {Zero32, Zero32};
1120 auto *
CU = cast<DICompileUnit>(CUNodes->
getOperand(i));
1126 std::string FilenameGcda = mangleName(
CU, GCovFileType::GCDA);
1129 StartFileCallArgsTy,
1130 {Builder.CreateGlobalStringPtr(FilenameGcda),
1132 Builder.getInt32(CfgChecksum)});
1136 for (
int j : llvm::seq<int>(0, CountersBySP.
size())) {
1137 uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[
j]->getFuncChecksum();
1139 EmitFunctionCallArgsTy,
1140 {Builder.getInt32(j),
1141 Builder.getInt32(FuncChecksum),
1142 Builder.getInt32(CfgChecksum)}));
1145 unsigned Arcs = cast<ArrayType>(GV->
getValueType())->getNumElements();
1152 int CountersSize = CountersBySP.
size();
1153 assert(CountersSize == (
int)EmitFunctionCallArgsArray.size() &&
1154 "Mismatched array size!");
1155 assert(CountersSize == (
int)EmitArcsCallArgsArray.
size() &&
1156 "Mismatched array size!");
1157 auto *EmitFunctionCallArgsArrayTy =
1160 *M, EmitFunctionCallArgsArrayTy,
true,
1163 EmitFunctionCallArgsArray),
1164 Twine(
"__llvm_internal_gcov_emit_function_args.") +
Twine(i));
1165 auto *EmitArcsCallArgsArrayTy =
1167 EmitFunctionCallArgsArrayGV->setUnnamedAddr(
1170 *M, EmitArcsCallArgsArrayTy,
true,
1173 Twine(
"__llvm_internal_gcov_emit_arcs_args.") +
Twine(i));
1178 {StartFileCallArgs, Builder.getInt32(CountersSize),
1180 EmitFunctionCallArgsArrayGV,
1183 EmitArcsCallArgsArrayTy, EmitArcsCallArgsArrayGV, TwoZero32s)}));
1187 if (FileInfos.
empty()) {
1188 Builder.CreateRetVoid();
1197 if ((int64_t)FileInfos.
size() > (int64_t)INT_MAX)
1198 FileInfos.
resize(INT_MAX);
1206 "__llvm_internal_gcov_emit_file_info");
1210 auto *FileLoopHeader =
1212 auto *CounterLoopHeader =
1218 Builder.CreateBr(FileLoopHeader);
1221 Builder.SetInsertPoint(FileLoopHeader);
1222 PHINode *
IV = Builder.CreatePHI(Builder.getInt32Ty(), 2,
1224 IV->addIncoming(Builder.getInt32(0), BB);
1225 auto *FileInfoPtr = Builder.CreateInBoundsGEP(
1226 FileInfoArrayTy, FileInfoArrayGV, {Builder.getInt32(0),
IV});
1227 auto *StartFileCallArgsPtr =
1228 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0,
"start_file_args");
1229 auto *StartFileCall = Builder.CreateCall(
1232 Builder.CreateStructGEP(StartFileCallArgsTy,
1233 StartFileCallArgsPtr, 0),
1236 Builder.CreateStructGEP(StartFileCallArgsTy,
1237 StartFileCallArgsPtr, 1),
1240 Builder.CreateStructGEP(StartFileCallArgsTy,
1241 StartFileCallArgsPtr, 2),
1243 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1244 StartFileCall->addParamAttr(2, AK);
1245 auto *NumCounters = Builder.CreateLoad(
1246 FileInfoTy->getElementType(1),
1247 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1),
"num_ctrs");
1248 auto *EmitFunctionCallArgsArray =
1249 Builder.CreateLoad(FileInfoTy->getElementType(2),
1250 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2),
1251 "emit_function_args");
1252 auto *EmitArcsCallArgsArray = Builder.CreateLoad(
1253 FileInfoTy->getElementType(3),
1254 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3),
"emit_arcs_args");
1255 auto *EnterCounterLoopCond =
1256 Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters);
1257 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
1259 Builder.SetInsertPoint(CounterLoopHeader);
1260 auto *JV = Builder.CreatePHI(Builder.getInt32Ty(), 2,
1262 JV->addIncoming(Builder.getInt32(0), FileLoopHeader);
1263 auto *EmitFunctionCallArgsPtr = Builder.CreateInBoundsGEP(
1264 EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
1265 auto *EmitFunctionCall = Builder.CreateCall(
1267 {Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1268 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1269 EmitFunctionCallArgsPtr, 0),
1271 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1272 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1273 EmitFunctionCallArgsPtr, 1),
1275 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1276 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1277 EmitFunctionCallArgsPtr, 2),
1279 if (
auto AK = TLI->getExtAttrForI32Param(
false)) {
1280 EmitFunctionCall->addParamAttr(0, AK);
1281 EmitFunctionCall->addParamAttr(1, AK);
1282 EmitFunctionCall->addParamAttr(2, AK);
1284 auto *EmitArcsCallArgsPtr =
1285 Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
1286 auto *EmitArcsCall = Builder.CreateCall(
1288 {Builder.CreateLoad(
1290 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0),
1294 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 1),
1296 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1297 EmitArcsCall->addParamAttr(0, AK);
1298 auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1));
1299 auto *CounterLoopCond = Builder.CreateICmpSLT(NextJV, NumCounters);
1300 Builder.CreateCondBr(CounterLoopCond, CounterLoopHeader, FileLoopLatch);
1301 JV->addIncoming(NextJV, CounterLoopHeader);
1303 Builder.SetInsertPoint(FileLoopLatch);
1304 Builder.CreateCall(SummaryInfo, {});
1305 Builder.CreateCall(EndFile, {});
1306 auto *NextIV = Builder.CreateAdd(
IV, Builder.getInt32(1),
"next_file_idx");
1307 auto *FileLoopCond =
1308 Builder.CreateICmpSLT(NextIV, Builder.getInt32(FileInfos.
size()));
1309 Builder.CreateCondBr(FileLoopCond, FileLoopHeader, ExitBB);
1310 IV->addIncoming(NextIV, FileLoopLatch);
1312 Builder.SetInsertPoint(ExitBB);
1313 Builder.CreateRetVoid();
1318Function *GCOVProfiler::insertReset(
1319 ArrayRef<std::pair<GlobalVariable *, MDNode *>> CountersBySP) {
1321 Function *ResetF =
M->getFunction(
"__llvm_gcov_reset");
1323 ResetF = createInternalFunction(FTy,
"__llvm_gcov_reset",
"_ZTSFvvE");
1331 for (
const auto &
I : CountersBySP) {
1335 GVTy->getNumElements() *
1336 GVTy->getElementType()->getScalarSizeInBits() / 8,
1341 if (
RetTy->isVoidTy())
1342 Builder.CreateRetVoid();
1343 else if (
RetTy->isIntegerTy())
1345 Builder.CreateRet(ConstantInt::get(
RetTy, 0));
This file defines the StringMap class.
Expand Atomic instructions
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
DenseMap< Block *, BlockRelaxAux > Blocks
This file provides the interface for the GCOV style profiler pass.
static unsigned wordsOfString(StringRef s)
static cl::opt< std::string > DefaultGCOVVersion("default-gcov-version", cl::init("408*"), cl::Hidden, cl::ValueRequired)
static bool functionHasLines(const Function &F, unsigned &EndLine)
static bool isUsingScopeBasedEH(Function &F)
static void dumpEdges(CFGMST< Edge, BBInfo > &MST, GCOVFunction &GF)
static SmallString< 128 > getFilename(const DISubprogram *SP)
Extract a filename for a DISubprogram.
static BasicBlock * getInstrBB(CFGMST< Edge, BBInfo > &MST, Edge &E, const DenseSet< const BasicBlock * > &ExecBlocks)
static StringRef getFunctionName(const DISubprogram *SP)
static cl::opt< bool > AtomicCounter("gcov-atomic-counter", cl::Hidden, cl::desc("Make counter updates atomic"))
static void addEdge(SmallVectorImpl< LazyCallGraph::Edge > &Edges, DenseMap< LazyCallGraph::Node *, int > &EdgeIndexMap, LazyCallGraph::Node &N, LazyCallGraph::Edge::Kind EK)
This file implements a map that provides insertion order iteration.
Module.h This file contains the declarations for the Module class.
FunctionAnalysisManager FAM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Provides some synthesis utilities to produce sequences of values.
static const uint32_t IV[8]
A container for analyses that lazily runs them and caches their results.
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),...
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM Basic Block Representation.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
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...
const Instruction & back() const
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.
Edge & addEdge(BasicBlock *Src, BasicBlock *Dest, uint64_t W)
const std::vector< std::unique_ptr< Edge > > & allEdges() const
This class represents a function call, abstracting a target machine's calling convention.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static Constant * getInBoundsGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList)
Create an "inbounds" getelementptr.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
StringRef getFilename() const
StringRef getName() const
StringRef getDirectory() const
MDNode * getScope() const
bool isImplicitCode() const
Check if the DebugLoc corresponds to an implicit code.
Implements a dense probed hash-table based set.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static 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.
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.
Type * getReturnType() const
Returns the type of the ret val.
GCOVBlock - Collects block information.
GCOVFunction - Collects function information.
StringRef getFilename() const
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
MaybeAlign getAlign() const
Returns the alignment of the given variable or function.
@ InternalLinkage
Rename collisions when linking (static functions).
Type * getValueType() const
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
void setNoSanitizeMetadata()
Sets the nosanitize metadata on this instruction.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void update(ArrayRef< uint8_t > Data)
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
StringRef getString() const
This class implements a map that also provides access to all stored values in a deterministic order.
A Module instance is used to store all the information related to an LLVM module.
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static Type * getVoidTy(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
LLVM Value Representation.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
An efficient, type-erasing, non-owning reference to a callable.
self_iterator getIterator()
A raw_ostream that writes to a file descriptor.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
NodeAddr< FuncNode * > Func
void write32(void *P, uint32_t V, endianness E)
uint32_t read32be(const void *P)
std::error_code real_path(const Twine &path, SmallVectorImpl< char > &output, bool expand_tilde=false)
Collapse all .
bool exists(const basic_file_status &status)
Does file exist?
std::error_code current_path(SmallVectorImpl< char > &result)
Get the current path.
void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
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...
bool SplitIndirectBrCriticalEdges(Function &F, bool IgnoreBlocksWithoutPHI, BranchProbabilityInfo *BPI=nullptr, BlockFrequencyInfo *BFI=nullptr)
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)
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue)
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
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.
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.
void setKCFIType(Module &M, Function &F, StringRef MangledType)
Sets the KCFI type for the function.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Implement std::hash so that hash_code can be used in STL containers.
static GCOVOptions getDefault()
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.