52#define DEBUG_TYPE "insert-gcov-profiling"
68 cl::desc(
"Make counter updates atomic"));
73 return (s.
size() / 4) + 2;
96 GCOVProfiler() : GCOVProfiler(
GCOVOptions::getDefault()) {}
111 os->write_zeros(4 - s.
size() % 4);
113 void writeBytes(
const char *Bytes,
int Size) { os->write(Bytes,
Size); }
118 emitProfileNotes(
NamedMDNode *CUNode,
bool HasExecOrFork,
126 void emitGlobalConstructor(
128 void emitModuleInitFunctionPtrs(
131 bool isFunctionInstrumented(
const Function &
F);
132 std::vector<Regex> createRegexesFromString(
StringRef RegexesStr);
133 static bool doesFilenameMatchARegex(
StringRef Filename,
134 std::vector<Regex> &Regexes);
146 insertCounterWriteout(
ArrayRef<std::pair<GlobalVariable *, MDNode *>>);
149 bool AddFlushBeforeForkAndExec();
151 enum class GCovFileType { GCNO, GCDA };
152 std::string mangleName(
const DICompileUnit *
CU, GCovFileType FileType);
165 std::vector<Regex> FilterRe;
166 std::vector<Regex> ExcludeRe;
177 std::string infoString()
const {
191 bool Removed =
false;
192 bool IsCritical =
false;
195 : SrcBB(Src), DestBB(Dest), Weight(
W) {}
198 std::string infoString()
const {
199 return (
Twine(Removed ?
"-" :
" ") + (InMST ?
" " :
"*") +
200 (IsCritical ?
"c" :
" ") +
" W=" +
Twine(Weight))
207 if (!SP->getLinkageName().empty())
208 return SP->getLinkageName();
232 GCOVRecord(GCOVProfiler *
P) :
P(
P) {}
235 void writeString(
StringRef s) {
P->writeString(s); }
236 void writeBytes(
const char *Bytes,
int Size) {
P->writeBytes(Bytes,
Size); }
245 class GCOVLines :
public GCOVRecord {
248 assert(Line != 0 &&
"Line zero is not a valid real line number.");
249 Lines.push_back(Line);
258 writeString(Filename);
278 return LinesByFile.try_emplace(Filename,
P, Filename).first->second;
282 OutEdges.emplace_back(&
Successor, Flags);
288 for (
auto &
I : LinesByFile) {
289 Len +=
I.second.length();
299 return LHS->getKey() <
RHS->getKey();
301 for (
auto &
I : SortedLinesByFile)
302 I->getValue().writeOut();
311 assert(LinesByFile.empty());
334 : GCOVRecord(
P), SP(SP), EndLine(EndLine), Ident(Ident),
337 bool ExitBlockBeforeBody =
Version >= 48;
338 uint32_t i = ExitBlockBeforeBody ? 2 : 1;
341 if (!ExitBlockBeforeBody)
342 ReturnBlock.Number = i;
344 std::string FunctionNameAndLine;
347 FuncChecksum =
hash_value(FunctionNameAndLine);
354 GCOVBlock &getEntryBlock() {
return EntryBlock; }
363 void writeOut(
uint32_t CfgChecksum) {
380 writeString(Filename);
381 write(SP->getLine());
383 write(SP->isArtificial());
384 writeString(Filename);
385 write(SP->getLine());
398 for (
int i =
Blocks.size() + 2; i; --i)
407 const uint32_t Outgoing = EntryBlock.OutEdges.size();
410 write(Outgoing * 2 + 1);
411 write(EntryBlock.Number);
412 for (
const auto &E : EntryBlock.OutEdges) {
413 write(E.first->Number);
419 if (
Block.OutEdges.empty())
continue;
424 for (
const auto &E :
Block.OutEdges) {
425 write(E.first->Number);
432 It.second.writeOut();
449std::vector<Regex> GCOVProfiler::createRegexesFromString(
StringRef RegexesStr) {
450 std::vector<Regex> Regexes;
451 while (!RegexesStr.
empty()) {
452 std::pair<StringRef, StringRef> HeadTail = RegexesStr.
split(
';');
453 if (!HeadTail.first.empty()) {
454 Regex Re(HeadTail.first);
456 if (!Re.isValid(Err)) {
457 Ctx->emitError(
Twine(
"Regex ") + HeadTail.first +
458 " is not valid: " + Err);
460 Regexes.emplace_back(std::move(Re));
462 RegexesStr = HeadTail.second;
467bool GCOVProfiler::doesFilenameMatchARegex(
StringRef Filename,
468 std::vector<Regex> &Regexes) {
469 for (
Regex &Re : Regexes)
470 if (Re.match(Filename))
475bool GCOVProfiler::isFunctionInstrumented(
const Function &
F) {
476 if (FilterRe.empty() && ExcludeRe.empty()) {
480 auto It = InstrumentedFiles.find(Filename);
481 if (It != InstrumentedFiles.end()) {
495 RealFilename = RealPath;
498 bool ShouldInstrument;
499 if (FilterRe.empty()) {
500 ShouldInstrument = !doesFilenameMatchARegex(RealFilename, ExcludeRe);
501 }
else if (ExcludeRe.empty()) {
502 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe);
504 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe) &&
505 !doesFilenameMatchARegex(RealFilename, ExcludeRe);
507 InstrumentedFiles[
Filename] = ShouldInstrument;
508 return ShouldInstrument;
512 GCovFileType OutputType) {
513 bool Notes = OutputType == GCovFileType::GCNO;
515 if (
NamedMDNode *GCov =
M->getNamedMetadata(
"llvm.gcov")) {
516 for (
int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
517 MDNode *
N = GCov->getOperand(i);
518 bool ThreeElement =
N->getNumOperands() == 3;
519 if (!ThreeElement &&
N->getNumOperands() != 2)
521 if (dyn_cast<MDNode>(
N->getOperand(ThreeElement ? 2 : 1)) !=
CU)
527 MDString *NotesFile = dyn_cast<MDString>(
N->getOperand(0));
528 MDString *DataFile = dyn_cast<MDString>(
N->getOperand(1));
529 if (!NotesFile || !DataFile)
531 return std::string(Notes ? NotesFile->
getString()
535 MDString *GCovFile = dyn_cast<MDString>(
N->getOperand(0));
541 return std::string(Filename);
550 return std::string(FName);
552 return std::string(CurPath);
555bool GCOVProfiler::runOnModule(
560 this->GetTLI = std::move(GetTLI);
561 Ctx = &
M.getContext();
563 NamedMDNode *CUNode =
M.getNamedMetadata(
"llvm.dbg.cu");
567 bool HasExecOrFork = AddFlushBeforeForkAndExec();
569 FilterRe = createRegexesFromString(
Options.Filter);
570 ExcludeRe = createRegexesFromString(
Options.Exclude);
571 emitProfileNotes(CUNode, HasExecOrFork, GetBFI, GetBPI, this->GetTLI);
578 GCOVProfiler Profiler(GCOVOpts);
592 if (!Profiler.runOnModule(M, GetBFI, GetBPI, GetTLI))
602 for (
const auto &BB :
F) {
603 for (
const auto &
I : BB) {
606 if (isa<DbgInfoIntrinsic>(&
I))
continue;
613 if (Loc.
getLine() == 0)
continue;
614 EndLine = std::max(EndLine, Loc.
getLine());
623 if (!
F.hasPersonalityFn())
return false;
629bool GCOVProfiler::AddFlushBeforeForkAndExec() {
633 for (
auto &
F :
M->functions()) {
634 TLI = TLI ==
nullptr ? &GetTLI(
F) : TLI;
636 if (
CallInst *CI = dyn_cast<CallInst>(&
I)) {
637 if (
Function *Callee = CI->getCalledFunction()) {
640 if (LF == LibFunc_fork) {
644 }
else if (LF == LibFunc_execl || LF == LibFunc_execle ||
645 LF == LibFunc_execlp || LF == LibFunc_execv ||
646 LF == LibFunc_execvp || LF == LibFunc_execve ||
647 LF == LibFunc_execvpe || LF == LibFunc_execvP) {
656 for (
auto *
F : Forks) {
659 auto NextInst = ++
F->getIterator();
666 F->setCalledFunction(GCOVFork);
683 for (
auto *E : Execs) {
692 M->getOrInsertFunction(
"llvm_writeout_files", FTy);
693 Builder.CreateCall(WriteoutF);
696 Builder.SetInsertPoint(&*NextInst);
699 FunctionCallee ResetF =
M->getOrInsertFunction(
"llvm_reset_counters", FTy);
700 Builder.CreateCall(ResetF)->setDebugLoc(Loc);
701 ExecBlocks.insert(Parent);
706 return !Forks.empty() || !Execs.empty();
711 if (E.InMST || E.Removed)
717 if (SrcBB ==
nullptr)
719 if (DestBB ==
nullptr)
734 return CanInstrument(SrcBB);
736 return CanInstrument(DestBB);
746 MST.
addEdge(SrcBB, InstrBB, 0);
747 MST.
addEdge(InstrBB, DestBB, 0).InMST =
true;
750 return CanInstrument(InstrBB);
757 GCOVBlock &Src = E.SrcBB ? GF.getBlock(E.SrcBB) : GF.getEntryBlock();
758 GCOVBlock &Dst = E.DestBB ? GF.getBlock(E.DestBB) : GF.getReturnBlock();
759 dbgs() <<
" Edge " <<
ID++ <<
": " << Src.Number <<
"->" << Dst.Number
760 << E.infoString() <<
"\n";
765bool GCOVProfiler::emitProfileNotes(
775 Version = c3 >=
'A' ? (c3 -
'A') * 100 + (c2 -
'0') * 10 + c1 -
'0'
776 : (c3 -
'0') * 10 + c1 -
'0';
779 bool EmitGCDA =
Options.EmitData;
791 std::vector<uint8_t> EdgeDestinations;
796 unsigned FunctionIdent = 0;
797 for (
auto &
F :
M->functions()) {
805 if (
F.hasFnAttribute(llvm::Attribute::NoProfile))
807 if (
F.hasFnAttribute(llvm::Attribute::SkipProfile))
827 for (
size_t I : llvm::seq<size_t>(0, MST.numEdges())) {
828 auto &E = *MST.allEdges()[
I];
837 Funcs.push_back(std::make_unique<GCOVFunction>(
this, &
F, SP, EndLine,
844 return E->Removed || (!E->InMST && !E->Place);
846 const size_t Measured =
847 std::stable_partition(
848 MST.allEdges().begin(), MST.allEdges().end(),
849 [](std::unique_ptr<Edge> &E) { return E->Place; }) -
850 MST.allEdges().begin();
851 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
852 Edge &E = *MST.allEdges()[
I];
854 E.SrcBB ?
Func.getBlock(E.SrcBB) :
Func.getEntryBlock();
856 E.DestBB ?
Func.getBlock(E.DestBB) :
Func.getReturnBlock();
857 E.SrcNumber = Src.Number;
858 E.DstNumber = Dst.Number;
861 MST.allEdges().begin(), MST.allEdges().begin() + Measured,
862 [](
const std::unique_ptr<Edge> &L,
const std::unique_ptr<Edge> &R) {
863 return L->SrcNumber != R->SrcNumber ? L->SrcNumber < R->SrcNumber
864 : L->DstNumber < R->DstNumber;
869 E.SrcBB ?
Func.getBlock(E.SrcBB) :
Func.getEntryBlock();
871 E.DestBB ?
Func.getBlock(E.DestBB) :
Func.getReturnBlock();
876 if (!SP->isArtificial())
877 Func.getBlock(&EntryBlock).getFile(Filename).addLine(Line);
881 for (
auto &GB :
Func.Blocks) {
883 auto &
Block = GB.second;
884 for (
auto Succ :
Block.OutEdges) {
886 do EdgeDestinations.push_back(
Idx & 255);
887 while ((
Idx >>= 8) > 0);
890 for (
const auto &
I : BB) {
893 if (isa<DbgInfoIntrinsic>(&
I))
continue;
903 if (Line == Loc.
getLine())
continue;
923 Counters->setSection(
"__llvm_gcov_ctr_section");
926 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
927 const Edge &E = *MST.allEdges()[
I];
928 IRBuilder<> Builder(E.Place, E.Place->getFirstInsertionPt());
929 Value *
V = Builder.CreateConstInBoundsGEP2_64(
940 Builder.CreateLoad(Builder.getInt64Ty(), V,
"gcov_ctr");
942 Value *NewCount = Builder.CreateAdd(OldCount, Builder.getInt64(1));
943 Inst = Builder.CreateStore(NewCount, V);
952 JC.
update(EdgeDestinations);
962 Twine(
"failed to open coverage notes file for writing: ") +
968 out.write(
"gcno", 4);
971 out.write(
"oncg", 4);
981 for (
auto &Func : Funcs)
982 Func->writeOut(Stamp);
992 emitModuleInitFunctionPtrs(CountersBySP);
994 emitGlobalConstructor(CountersBySP);
1007 F->addFnAttr(Attribute::NoUnwind);
1009 F->addFnAttr(Attribute::NoRedZone);
1010 if (!MangledType.
empty())
1015void GCOVProfiler::emitGlobalConstructor(
1016 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
1017 Function *WriteoutF = insertCounterWriteout(CountersBySP);
1018 Function *ResetF = insertReset(CountersBySP);
1024 Function *
F = createInternalFunction(FTy,
"__llvm_gcov_init",
"_ZTSFvvE");
1025 F->addFnAttr(Attribute::NoInline);
1036 FunctionCallee GCOVInit =
M->getOrInsertFunction(
"llvm_gcov_init", FTy);
1037 Builder.CreateCall(GCOVInit, {WriteoutF, ResetF});
1038 Builder.CreateRetVoid();
1043void GCOVProfiler::emitModuleInitFunctionPtrs(
1044 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
1045 Function *WriteoutF = insertCounterWriteout(CountersBySP);
1046 Function *ResetF = insertReset(CountersBySP);
1052 auto &Ctx =
M->getContext();
1054 Type *InitFuncDataTy[] = {
1055#define COVINIT_FUNC(Type, LLVMType, Name, Init) LLVMType,
1062#define COVINIT_FUNC(Type, LLVMType, Name, Init) Init,
1068 "__llvm_covinit_functions");
1073 CovInitGV->setAlignment(
Align(INSTR_PROF_DATA_ALIGNMENT));
1074 CovInitGV->setConstant(
true);
1084 return M->getOrInsertFunction(
"llvm_gcda_start_file", FTy,
1095 return M->getOrInsertFunction(
"llvm_gcda_emit_function", FTy,
1105 return M->getOrInsertFunction(
"llvm_gcda_emit_arcs", FTy,
1111 return M->getOrInsertFunction(
"llvm_gcda_summary_info", FTy);
1116 return M->getOrInsertFunction(
"llvm_gcda_end_file", FTy);
1119Function *GCOVProfiler::insertCounterWriteout(
1120 ArrayRef<std::pair<GlobalVariable *, MDNode *> > CountersBySP) {
1122 Function *WriteoutF =
M->getFunction(
"__llvm_gcov_writeout");
1125 createInternalFunction(WriteoutFTy,
"__llvm_gcov_writeout",
"_ZTSFvvE");
1126 WriteoutF->
addFnAttr(Attribute::NoInline);
1131 auto *TLI = &GetTLI(*WriteoutF);
1139 NamedMDNode *CUNodes =
M->getNamedMetadata(
"llvm.dbg.cu");
1141 Builder.CreateRetVoid();
1148 {Builder.getPtrTy(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1149 "start_file_args_ty");
1151 {Builder.getInt32Ty(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1152 "emit_function_args_ty");
1153 auto *PtrTy = Builder.getPtrTy();
1157 {StartFileCallArgsTy, Builder.
getInt32Ty(), PtrTy, PtrTy},
"file_info");
1159 Constant *Zero32 = Builder.getInt32(0);
1161 Constant *TwoZero32s[] = {Zero32, Zero32};
1165 auto *
CU = cast<DICompileUnit>(CUNodes->
getOperand(i));
1171 std::string FilenameGcda = mangleName(
CU, GCovFileType::GCDA);
1174 StartFileCallArgsTy,
1175 {Builder.CreateGlobalString(FilenameGcda),
1177 Builder.getInt32(CfgChecksum)});
1181 for (
int j : llvm::seq<int>(0, CountersBySP.
size())) {
1182 uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[
j]->getFuncChecksum();
1184 EmitFunctionCallArgsTy,
1185 {Builder.getInt32(j),
1186 Builder.getInt32(FuncChecksum),
1187 Builder.getInt32(CfgChecksum)}));
1190 unsigned Arcs = cast<ArrayType>(GV->
getValueType())->getNumElements();
1197 int CountersSize = CountersBySP.
size();
1198 assert(CountersSize == (
int)EmitFunctionCallArgsArray.size() &&
1199 "Mismatched array size!");
1200 assert(CountersSize == (
int)EmitArcsCallArgsArray.
size() &&
1201 "Mismatched array size!");
1202 auto *EmitFunctionCallArgsArrayTy =
1205 *M, EmitFunctionCallArgsArrayTy,
true,
1208 EmitFunctionCallArgsArray),
1209 Twine(
"__llvm_internal_gcov_emit_function_args.") +
Twine(i));
1210 auto *EmitArcsCallArgsArrayTy =
1212 EmitFunctionCallArgsArrayGV->setUnnamedAddr(
1215 *M, EmitArcsCallArgsArrayTy,
true,
1218 Twine(
"__llvm_internal_gcov_emit_arcs_args.") +
Twine(i));
1223 {StartFileCallArgs, Builder.getInt32(CountersSize),
1225 EmitFunctionCallArgsArrayGV,
1228 EmitArcsCallArgsArrayTy, EmitArcsCallArgsArrayGV, TwoZero32s)}));
1232 if (FileInfos.
empty()) {
1233 Builder.CreateRetVoid();
1242 if ((int64_t)FileInfos.
size() > (int64_t)INT_MAX)
1243 FileInfos.
resize(INT_MAX);
1251 "__llvm_internal_gcov_emit_file_info");
1255 auto *FileLoopHeader =
1257 auto *CounterLoopHeader =
1263 Builder.CreateBr(FileLoopHeader);
1266 Builder.SetInsertPoint(FileLoopHeader);
1267 PHINode *
IV = Builder.CreatePHI(Builder.getInt32Ty(), 2,
1269 IV->addIncoming(Builder.getInt32(0), BB);
1270 auto *FileInfoPtr = Builder.CreateInBoundsGEP(
1271 FileInfoArrayTy, FileInfoArrayGV, {Builder.getInt32(0),
IV});
1272 auto *StartFileCallArgsPtr =
1273 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0,
"start_file_args");
1274 auto *StartFileCall = Builder.CreateCall(
1277 Builder.CreateStructGEP(StartFileCallArgsTy,
1278 StartFileCallArgsPtr, 0),
1281 Builder.CreateStructGEP(StartFileCallArgsTy,
1282 StartFileCallArgsPtr, 1),
1285 Builder.CreateStructGEP(StartFileCallArgsTy,
1286 StartFileCallArgsPtr, 2),
1288 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1289 StartFileCall->addParamAttr(2, AK);
1290 auto *NumCounters = Builder.CreateLoad(
1291 FileInfoTy->getElementType(1),
1292 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1),
"num_ctrs");
1293 auto *EmitFunctionCallArgsArray =
1294 Builder.CreateLoad(FileInfoTy->getElementType(2),
1295 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2),
1296 "emit_function_args");
1297 auto *EmitArcsCallArgsArray = Builder.CreateLoad(
1298 FileInfoTy->getElementType(3),
1299 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3),
"emit_arcs_args");
1300 auto *EnterCounterLoopCond =
1301 Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters);
1302 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
1304 Builder.SetInsertPoint(CounterLoopHeader);
1305 auto *JV = Builder.CreatePHI(Builder.getInt32Ty(), 2,
1307 JV->addIncoming(Builder.getInt32(0), FileLoopHeader);
1308 auto *EmitFunctionCallArgsPtr = Builder.CreateInBoundsGEP(
1309 EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
1310 auto *EmitFunctionCall = Builder.CreateCall(
1312 {Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1313 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1314 EmitFunctionCallArgsPtr, 0),
1316 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1317 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1318 EmitFunctionCallArgsPtr, 1),
1320 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1321 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1322 EmitFunctionCallArgsPtr, 2),
1324 if (
auto AK = TLI->getExtAttrForI32Param(
false)) {
1325 EmitFunctionCall->addParamAttr(0, AK);
1326 EmitFunctionCall->addParamAttr(1, AK);
1327 EmitFunctionCall->addParamAttr(2, AK);
1329 auto *EmitArcsCallArgsPtr =
1330 Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
1331 auto *EmitArcsCall = Builder.CreateCall(
1333 {Builder.CreateLoad(
1335 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0),
1339 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 1),
1341 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1342 EmitArcsCall->addParamAttr(0, AK);
1343 auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1));
1344 auto *CounterLoopCond = Builder.CreateICmpSLT(NextJV, NumCounters);
1345 Builder.CreateCondBr(CounterLoopCond, CounterLoopHeader, FileLoopLatch);
1346 JV->addIncoming(NextJV, CounterLoopHeader);
1348 Builder.SetInsertPoint(FileLoopLatch);
1349 Builder.CreateCall(SummaryInfo, {});
1350 Builder.CreateCall(EndFile, {});
1351 auto *NextIV = Builder.CreateAdd(
IV, Builder.getInt32(1),
"next_file_idx");
1352 auto *FileLoopCond =
1353 Builder.CreateICmpSLT(NextIV, Builder.getInt32(FileInfos.
size()));
1354 Builder.CreateCondBr(FileLoopCond, FileLoopHeader, ExitBB);
1355 IV->addIncoming(NextIV, FileLoopLatch);
1357 Builder.SetInsertPoint(ExitBB);
1358 Builder.CreateRetVoid();
1363Function *GCOVProfiler::insertReset(
1364 ArrayRef<std::pair<GlobalVariable *, MDNode *>> CountersBySP) {
1366 Function *ResetF =
M->getFunction(
"__llvm_gcov_reset");
1368 ResetF = createInternalFunction(FTy,
"__llvm_gcov_reset",
"_ZTSFvvE");
1376 for (
const auto &
I : CountersBySP) {
1380 GVTy->getNumElements() *
1381 GVTy->getElementType()->getScalarSizeInBits() / 8,
1386 if (
RetTy->isVoidTy())
1387 Builder.CreateRetVoid();
1388 else if (
RetTy->isIntegerTy())
1390 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"))
Module.h This file contains the declarations for the Module class.
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.
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.
@ DefaultVisibility
The GV is visible.
@ PrivateLinkage
Like Internal, but omit from symbol table.
@ 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 * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
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.
Triple - Helper class for working with autoconf configuration names.
ObjectFormatType getObjectFormat() const
Get the object format for this triple.
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)
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)
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static GCOVOptions getDefault()
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.