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);
166 std::vector<Regex> FilterRe;
167 std::vector<Regex> ExcludeRe;
178 std::string infoString()
const {
192 bool Removed =
false;
193 bool IsCritical =
false;
196 : SrcBB(Src), DestBB(Dest), Weight(
W) {}
199 std::string infoString()
const {
200 return (
Twine(Removed ?
"-" :
" ") + (InMST ?
" " :
"*") +
201 (IsCritical ?
"c" :
" ") +
" W=" +
Twine(Weight))
208 if (!SP->getLinkageName().empty())
209 return SP->getLinkageName();
233 GCOVRecord(GCOVProfiler *
P) :
P(
P) {}
236 void writeString(
StringRef s) {
P->writeString(s); }
237 void writeBytes(
const char *Bytes,
int Size) {
P->writeBytes(Bytes,
Size); }
246 class GCOVLines :
public GCOVRecord {
249 assert(Line != 0 &&
"Line zero is not a valid real line number.");
250 Lines.push_back(Line);
259 writeString(Filename);
279 return LinesByFile.try_emplace(Filename,
P, Filename).first->second;
283 OutEdges.emplace_back(&
Successor, Flags);
289 for (
auto &
I : LinesByFile) {
290 Len +=
I.second.length();
300 return LHS->getKey() <
RHS->getKey();
302 for (
auto &
I : SortedLinesByFile)
303 I->getValue().writeOut();
312 assert(LinesByFile.empty());
335 : GCOVRecord(
P), SP(SP), EndLine(EndLine), Ident(Ident),
342 std::string FunctionNameAndLine;
345 FuncChecksum =
hash_value(FunctionNameAndLine);
352 GCOVBlock &getEntryBlock() {
return EntryBlock; }
361 void writeOut(
uint32_t CfgChecksum) {
373 write(SP->isArtificial());
374 writeString(Filename);
375 write(SP->getLine());
389 const uint32_t Outgoing = EntryBlock.OutEdges.size();
392 write(Outgoing * 2 + 1);
393 write(EntryBlock.Number);
394 for (
const auto &E : EntryBlock.OutEdges) {
395 write(E.first->Number);
401 if (
Block.OutEdges.empty())
continue;
406 for (
const auto &E :
Block.OutEdges) {
407 write(E.first->Number);
414 It.second.writeOut();
431std::vector<Regex> GCOVProfiler::createRegexesFromString(
StringRef RegexesStr) {
432 std::vector<Regex> Regexes;
433 while (!RegexesStr.
empty()) {
434 std::pair<StringRef, StringRef> HeadTail = RegexesStr.
split(
';');
435 if (!HeadTail.first.empty()) {
436 Regex Re(HeadTail.first);
438 if (!Re.isValid(Err)) {
439 Ctx->emitError(
Twine(
"Regex ") + HeadTail.first +
440 " is not valid: " + Err);
442 Regexes.emplace_back(std::move(Re));
444 RegexesStr = HeadTail.second;
449bool GCOVProfiler::doesFilenameMatchARegex(
StringRef Filename,
450 std::vector<Regex> &Regexes) {
451 for (
Regex &Re : Regexes)
452 if (Re.match(Filename))
457bool GCOVProfiler::isFunctionInstrumented(
const Function &
F) {
458 if (FilterRe.empty() && ExcludeRe.empty()) {
462 auto It = InstrumentedFiles.find(Filename);
463 if (It != InstrumentedFiles.end()) {
477 RealFilename = RealPath;
480 bool ShouldInstrument;
481 if (FilterRe.empty()) {
482 ShouldInstrument = !doesFilenameMatchARegex(RealFilename, ExcludeRe);
483 }
else if (ExcludeRe.empty()) {
484 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe);
486 ShouldInstrument = doesFilenameMatchARegex(RealFilename, FilterRe) &&
487 !doesFilenameMatchARegex(RealFilename, ExcludeRe);
489 InstrumentedFiles[
Filename] = ShouldInstrument;
490 return ShouldInstrument;
494 GCovFileType OutputType) {
495 bool Notes = OutputType == GCovFileType::GCNO;
497 if (
NamedMDNode *GCov =
M->getNamedMetadata(
"llvm.gcov")) {
498 for (
int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
499 MDNode *
N = GCov->getOperand(i);
500 bool ThreeElement =
N->getNumOperands() == 3;
501 if (!ThreeElement &&
N->getNumOperands() != 2)
503 if (dyn_cast<MDNode>(
N->getOperand(ThreeElement ? 2 : 1)) !=
CU)
509 MDString *NotesFile = dyn_cast<MDString>(
N->getOperand(0));
510 MDString *DataFile = dyn_cast<MDString>(
N->getOperand(1));
511 if (!NotesFile || !DataFile)
513 return std::string(Notes ? NotesFile->
getString()
517 MDString *GCovFile = dyn_cast<MDString>(
N->getOperand(0));
523 return std::string(Filename);
532 return std::string(FName);
534 return std::string(CurPath);
537bool GCOVProfiler::runOnModule(
542 this->GetTLI = std::move(GetTLI);
543 Ctx = &
M.getContext();
545 NamedMDNode *CUNode =
M.getNamedMetadata(
"llvm.dbg.cu");
549 bool HasExecOrFork = AddFlushBeforeForkAndExec();
551 FilterRe = createRegexesFromString(
Options.Filter);
552 ExcludeRe = createRegexesFromString(
Options.Exclude);
553 emitProfileNotes(CUNode, HasExecOrFork, GetBFI, GetBPI, this->GetTLI);
560 GCOVProfiler Profiler(GCOVOpts);
574 if (!Profiler.runOnModule(M, GetBFI, GetBPI, GetTLI))
584 for (
const auto &BB :
F) {
585 for (
const auto &
I : BB) {
588 if (isa<DbgInfoIntrinsic>(&
I))
continue;
595 if (Loc.
getLine() == 0)
continue;
596 EndLine = std::max(EndLine, Loc.
getLine());
605 if (!
F.hasPersonalityFn())
return false;
611bool GCOVProfiler::AddFlushBeforeForkAndExec() {
615 for (
auto &
F :
M->functions()) {
616 TLI = TLI ==
nullptr ? &GetTLI(
F) : TLI;
618 if (
CallInst *CI = dyn_cast<CallInst>(&
I)) {
619 if (
Function *Callee = CI->getCalledFunction()) {
622 if (LF == LibFunc_fork) {
626 }
else if (LF == LibFunc_execl || LF == LibFunc_execle ||
627 LF == LibFunc_execlp || LF == LibFunc_execv ||
628 LF == LibFunc_execvp || LF == LibFunc_execve ||
629 LF == LibFunc_execvpe || LF == LibFunc_execvP) {
638 for (
auto *
F : Forks) {
641 auto NextInst = ++
F->getIterator();
648 F->setCalledFunction(GCOVFork);
665 for (
auto *E : Execs) {
674 M->getOrInsertFunction(
"llvm_writeout_files", FTy);
675 Builder.CreateCall(WriteoutF);
678 Builder.SetInsertPoint(&*NextInst);
681 FunctionCallee ResetF =
M->getOrInsertFunction(
"llvm_reset_counters", FTy);
682 Builder.CreateCall(ResetF)->setDebugLoc(Loc);
683 ExecBlocks.insert(Parent);
688 return !Forks.empty() || !Execs.empty();
693 if (E.InMST || E.Removed)
699 if (SrcBB ==
nullptr)
701 if (DestBB ==
nullptr)
716 return CanInstrument(SrcBB);
718 return CanInstrument(DestBB);
728 MST.
addEdge(SrcBB, InstrBB, 0);
729 MST.
addEdge(InstrBB, DestBB, 0).InMST =
true;
732 return CanInstrument(InstrBB);
739 GCOVBlock &Src = E.SrcBB ? GF.getBlock(E.SrcBB) : GF.getEntryBlock();
740 GCOVBlock &Dst = E.DestBB ? GF.getBlock(E.DestBB) : GF.getReturnBlock();
741 dbgs() <<
" Edge " <<
ID++ <<
": " << Src.Number <<
"->" << Dst.Number
742 << E.infoString() <<
"\n";
747bool GCOVProfiler::emitProfileNotes(
756 Version = c3 >=
'A' ? (c3 -
'A') * 100 + (c2 -
'0') * 10 + c1 -
'0'
757 : (c3 -
'0') * 10 + c1 -
'0';
762 memcpy(
Options.Version,
"B11*", 4);
765 bool EmitGCDA =
Options.EmitData;
777 std::vector<uint8_t> EdgeDestinations;
782 unsigned FunctionIdent = 0;
783 for (
auto &
F :
M->functions()) {
791 if (
F.hasFnAttribute(llvm::Attribute::NoProfile))
793 if (
F.hasFnAttribute(llvm::Attribute::SkipProfile))
813 for (
size_t I : llvm::seq<size_t>(0, MST.numEdges())) {
814 auto &E = *MST.allEdges()[
I];
823 Funcs.push_back(std::make_unique<GCOVFunction>(
this, &
F, SP, EndLine,
830 return E->Removed || (!E->InMST && !E->Place);
832 const size_t Measured =
833 std::stable_partition(
834 MST.allEdges().begin(), MST.allEdges().end(),
835 [](std::unique_ptr<Edge> &E) { return E->Place; }) -
836 MST.allEdges().begin();
837 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
838 Edge &E = *MST.allEdges()[
I];
840 E.SrcBB ?
Func.getBlock(E.SrcBB) :
Func.getEntryBlock();
842 E.DestBB ?
Func.getBlock(E.DestBB) :
Func.getReturnBlock();
843 E.SrcNumber = Src.Number;
844 E.DstNumber = Dst.Number;
847 MST.allEdges().begin(), MST.allEdges().begin() + Measured,
848 [](
const std::unique_ptr<Edge> &L,
const std::unique_ptr<Edge> &R) {
849 return L->SrcNumber != R->SrcNumber ? L->SrcNumber < R->SrcNumber
850 : L->DstNumber < R->DstNumber;
855 E.SrcBB ?
Func.getBlock(E.SrcBB) :
Func.getEntryBlock();
857 E.DestBB ?
Func.getBlock(E.DestBB) :
Func.getReturnBlock();
862 if (!SP->isArtificial())
863 Func.getBlock(&EntryBlock).getFile(Filename).addLine(Line);
867 for (
auto &GB :
Func.Blocks) {
869 auto &
Block = GB.second;
870 for (
auto Succ :
Block.OutEdges) {
872 do EdgeDestinations.push_back(
Idx & 255);
873 while ((
Idx >>= 8) > 0);
876 for (
const auto &
I : BB) {
879 if (isa<DbgInfoIntrinsic>(&
I))
continue;
889 if (Line == Loc.
getLine())
continue;
909 Counters->setSection(
"__llvm_gcov_ctr_section");
912 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
913 const Edge &E = *MST.allEdges()[
I];
914 IRBuilder<> Builder(E.Place, E.Place->getFirstInsertionPt());
915 Value *
V = Builder.CreateConstInBoundsGEP2_64(
926 Builder.CreateLoad(Builder.getInt64Ty(), V,
"gcov_ctr");
928 Value *NewCount = Builder.CreateAdd(OldCount, Builder.getInt64(1));
929 Inst = Builder.CreateStore(NewCount, V);
938 JC.
update(EdgeDestinations);
948 Twine(
"failed to open coverage notes file for writing: ") +
954 out.write(
"gcno", 4);
957 out.write(
"oncg", 4);
965 for (
auto &Func : Funcs)
966 Func->writeOut(Stamp);
976 emitModuleInitFunctionPtrs(CountersBySP);
978 emitGlobalConstructor(CountersBySP);
991 F->addFnAttr(Attribute::NoUnwind);
993 F->addFnAttr(Attribute::NoRedZone);
994 if (!MangledType.
empty())
999void GCOVProfiler::emitGlobalConstructor(
1000 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
1001 Function *WriteoutF = insertCounterWriteout(CountersBySP);
1002 Function *ResetF = insertReset(CountersBySP);
1008 Function *
F = createInternalFunction(FTy,
"__llvm_gcov_init",
"_ZTSFvvE");
1009 F->addFnAttr(Attribute::NoInline);
1020 FunctionCallee GCOVInit =
M->getOrInsertFunction(
"llvm_gcov_init", FTy);
1021 Builder.CreateCall(GCOVInit, {WriteoutF, ResetF});
1022 Builder.CreateRetVoid();
1027void GCOVProfiler::emitModuleInitFunctionPtrs(
1028 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
1029 Function *WriteoutF = insertCounterWriteout(CountersBySP);
1030 Function *ResetF = insertReset(CountersBySP);
1036 auto &Ctx =
M->getContext();
1038 Type *InitFuncDataTy[] = {
1039#define COVINIT_FUNC(Type, LLVMType, Name, Init) LLVMType,
1046#define COVINIT_FUNC(Type, LLVMType, Name, Init) Init,
1052 "__llvm_covinit_functions");
1057 CovInitGV->setAlignment(
Align(INSTR_PROF_DATA_ALIGNMENT));
1058 CovInitGV->setConstant(
true);
1068 return M->getOrInsertFunction(
"llvm_gcda_start_file", FTy,
1079 return M->getOrInsertFunction(
"llvm_gcda_emit_function", FTy,
1089 return M->getOrInsertFunction(
"llvm_gcda_emit_arcs", FTy,
1095 return M->getOrInsertFunction(
"llvm_gcda_summary_info", FTy);
1100 return M->getOrInsertFunction(
"llvm_gcda_end_file", FTy);
1103Function *GCOVProfiler::insertCounterWriteout(
1104 ArrayRef<std::pair<GlobalVariable *, MDNode *> > CountersBySP) {
1106 Function *WriteoutF =
M->getFunction(
"__llvm_gcov_writeout");
1109 createInternalFunction(WriteoutFTy,
"__llvm_gcov_writeout",
"_ZTSFvvE");
1110 WriteoutF->
addFnAttr(Attribute::NoInline);
1115 auto *TLI = &GetTLI(*WriteoutF);
1123 NamedMDNode *CUNodes =
M->getNamedMetadata(
"llvm.dbg.cu");
1125 Builder.CreateRetVoid();
1132 {Builder.getPtrTy(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1133 "start_file_args_ty");
1135 {Builder.getInt32Ty(), Builder.getInt32Ty(), Builder.getInt32Ty()},
1136 "emit_function_args_ty");
1137 auto *PtrTy = Builder.getPtrTy();
1141 {StartFileCallArgsTy, Builder.
getInt32Ty(), PtrTy, PtrTy},
"file_info");
1143 Constant *Zero32 = Builder.getInt32(0);
1145 Constant *TwoZero32s[] = {Zero32, Zero32};
1149 auto *
CU = cast<DICompileUnit>(CUNodes->
getOperand(i));
1155 std::string FilenameGcda = mangleName(
CU, GCovFileType::GCDA);
1158 StartFileCallArgsTy,
1159 {Builder.CreateGlobalString(FilenameGcda),
1161 Builder.getInt32(CfgChecksum)});
1165 for (
int j : llvm::seq<int>(0, CountersBySP.
size())) {
1166 uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[
j]->getFuncChecksum();
1168 EmitFunctionCallArgsTy,
1169 {Builder.getInt32(j),
1170 Builder.getInt32(FuncChecksum),
1171 Builder.getInt32(CfgChecksum)}));
1174 unsigned Arcs = cast<ArrayType>(GV->
getValueType())->getNumElements();
1181 int CountersSize = CountersBySP.
size();
1182 assert(CountersSize == (
int)EmitFunctionCallArgsArray.size() &&
1183 "Mismatched array size!");
1184 assert(CountersSize == (
int)EmitArcsCallArgsArray.
size() &&
1185 "Mismatched array size!");
1186 auto *EmitFunctionCallArgsArrayTy =
1189 *M, EmitFunctionCallArgsArrayTy,
true,
1192 EmitFunctionCallArgsArray),
1193 Twine(
"__llvm_internal_gcov_emit_function_args.") +
Twine(i));
1194 auto *EmitArcsCallArgsArrayTy =
1196 EmitFunctionCallArgsArrayGV->setUnnamedAddr(
1199 *M, EmitArcsCallArgsArrayTy,
true,
1202 Twine(
"__llvm_internal_gcov_emit_arcs_args.") +
Twine(i));
1207 {StartFileCallArgs, Builder.getInt32(CountersSize),
1209 EmitFunctionCallArgsArrayGV,
1212 EmitArcsCallArgsArrayTy, EmitArcsCallArgsArrayGV, TwoZero32s)}));
1216 if (FileInfos.
empty()) {
1217 Builder.CreateRetVoid();
1226 if ((int64_t)FileInfos.
size() > (int64_t)INT_MAX)
1227 FileInfos.
resize(INT_MAX);
1235 "__llvm_internal_gcov_emit_file_info");
1239 auto *FileLoopHeader =
1241 auto *CounterLoopHeader =
1247 Builder.CreateBr(FileLoopHeader);
1250 Builder.SetInsertPoint(FileLoopHeader);
1251 PHINode *
IV = Builder.CreatePHI(Builder.getInt32Ty(), 2,
1253 IV->addIncoming(Builder.getInt32(0), BB);
1254 auto *FileInfoPtr = Builder.CreateInBoundsGEP(
1255 FileInfoArrayTy, FileInfoArrayGV, {Builder.getInt32(0),
IV});
1256 auto *StartFileCallArgsPtr =
1257 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0,
"start_file_args");
1258 auto *StartFileCall = Builder.CreateCall(
1261 Builder.CreateStructGEP(StartFileCallArgsTy,
1262 StartFileCallArgsPtr, 0),
1265 Builder.CreateStructGEP(StartFileCallArgsTy,
1266 StartFileCallArgsPtr, 1),
1269 Builder.CreateStructGEP(StartFileCallArgsTy,
1270 StartFileCallArgsPtr, 2),
1272 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1273 StartFileCall->addParamAttr(2, AK);
1274 auto *NumCounters = Builder.CreateLoad(
1275 FileInfoTy->getElementType(1),
1276 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1),
"num_ctrs");
1277 auto *EmitFunctionCallArgsArray =
1278 Builder.CreateLoad(FileInfoTy->getElementType(2),
1279 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2),
1280 "emit_function_args");
1281 auto *EmitArcsCallArgsArray = Builder.CreateLoad(
1282 FileInfoTy->getElementType(3),
1283 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3),
"emit_arcs_args");
1284 auto *EnterCounterLoopCond =
1285 Builder.CreateICmpSLT(Builder.getInt32(0), NumCounters);
1286 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
1288 Builder.SetInsertPoint(CounterLoopHeader);
1289 auto *JV = Builder.CreatePHI(Builder.getInt32Ty(), 2,
1291 JV->addIncoming(Builder.getInt32(0), FileLoopHeader);
1292 auto *EmitFunctionCallArgsPtr = Builder.CreateInBoundsGEP(
1293 EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
1294 auto *EmitFunctionCall = Builder.CreateCall(
1296 {Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1297 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1298 EmitFunctionCallArgsPtr, 0),
1300 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1301 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1302 EmitFunctionCallArgsPtr, 1),
1304 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1305 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1306 EmitFunctionCallArgsPtr, 2),
1308 if (
auto AK = TLI->getExtAttrForI32Param(
false)) {
1309 EmitFunctionCall->addParamAttr(0, AK);
1310 EmitFunctionCall->addParamAttr(1, AK);
1311 EmitFunctionCall->addParamAttr(2, AK);
1313 auto *EmitArcsCallArgsPtr =
1314 Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
1315 auto *EmitArcsCall = Builder.CreateCall(
1317 {Builder.CreateLoad(
1319 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0),
1323 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 1),
1325 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1326 EmitArcsCall->addParamAttr(0, AK);
1327 auto *NextJV = Builder.CreateAdd(JV, Builder.getInt32(1));
1328 auto *CounterLoopCond = Builder.CreateICmpSLT(NextJV, NumCounters);
1329 Builder.CreateCondBr(CounterLoopCond, CounterLoopHeader, FileLoopLatch);
1330 JV->addIncoming(NextJV, CounterLoopHeader);
1332 Builder.SetInsertPoint(FileLoopLatch);
1333 Builder.CreateCall(SummaryInfo, {});
1334 Builder.CreateCall(EndFile, {});
1335 auto *NextIV = Builder.CreateAdd(
IV, Builder.getInt32(1),
"next_file_idx");
1336 auto *FileLoopCond =
1337 Builder.CreateICmpSLT(NextIV, Builder.getInt32(FileInfos.
size()));
1338 Builder.CreateCondBr(FileLoopCond, FileLoopHeader, ExitBB);
1339 IV->addIncoming(NextIV, FileLoopLatch);
1341 Builder.SetInsertPoint(ExitBB);
1342 Builder.CreateRetVoid();
1347Function *GCOVProfiler::insertReset(
1348 ArrayRef<std::pair<GlobalVariable *, MDNode *>> CountersBySP) {
1350 Function *ResetF =
M->getFunction(
"__llvm_gcov_reset");
1352 ResetF = createInternalFunction(FTy,
"__llvm_gcov_reset",
"_ZTSFvvE");
1360 for (
const auto &
I : CountersBySP) {
1364 GVTy->getNumElements() *
1365 GVTy->getElementType()->getScalarSizeInBits() / 8,
1370 if (
RetTy->isVoidTy())
1371 Builder.CreateRetVoid();
1372 else if (
RetTy->isIntegerTy())
1374 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 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 cl::opt< std::string > DefaultGCOVVersion("default-gcov-version", cl::init("0000"), cl::Hidden, cl::ValueRequired)
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.