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());
329 unsigned EndLine,
uint32_t Ident,
int Version)
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) {
416 if (
Block.OutEdges.empty())
continue;
421 for (
const auto &
E :
Block.OutEdges) {
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));
547 return std::string(FName);
549 return std::string(CurPath.
str());
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) {
683 auto NextInst = ++
E->getIterator();
689 M->getOrInsertFunction(
"llvm_writeout_files", FTy);
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;
791 Endian =
M->getDataLayout().isLittleEndian() ? support::endianness::little
792 : support::endianness::big;
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.AllEdges.size())) {
824 auto &
E = *MST.AllEdges[
I];
833 Funcs.push_back(std::make_unique<GCOVFunction>(
this, &
F, SP, EndLine,
834 FunctionIdent++, Version));
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];
936 Inst =
Builder.CreateStore(NewCount, V);
945 JC.
update(EdgeDestinations);
955 Twine(
"failed to open coverage notes file for writing: ") +
960 if (Endian == support::endianness::big) {
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});
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");
1104 "start_file_args_ty");
1107 "emit_function_args_ty");
1110 "emit_arcs_args_ty");
1113 EmitFunctionCallArgsTy->getPointerTo(),
1114 EmitArcsCallArgsTy->getPointerTo()},
1119 Constant *TwoZero32s[] = {Zero32, Zero32};
1123 auto *
CU = cast<DICompileUnit>(CUNodes->
getOperand(i));
1129 std::string FilenameGcda = mangleName(
CU, GCovFileType::GCDA);
1132 StartFileCallArgsTy,
1133 {
Builder.CreateGlobalStringPtr(FilenameGcda),
1135 Builder.getInt32(CfgChecksum)});
1139 for (
int j : llvm::seq<int>(0, CountersBySP.
size())) {
1140 uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[
j]->getFuncChecksum();
1142 EmitFunctionCallArgsTy,
1144 Builder.getInt32(FuncChecksum),
1145 Builder.getInt32(CfgChecksum)}));
1148 unsigned Arcs = cast<ArrayType>(GV->
getValueType())->getNumElements();
1155 int CountersSize = CountersBySP.
size();
1156 assert(CountersSize == (
int)EmitFunctionCallArgsArray.size() &&
1157 "Mismatched array size!");
1158 assert(CountersSize == (
int)EmitArcsCallArgsArray.
size() &&
1159 "Mismatched array size!");
1160 auto *EmitFunctionCallArgsArrayTy =
1163 *M, EmitFunctionCallArgsArrayTy,
true,
1166 EmitFunctionCallArgsArray),
1167 Twine(
"__llvm_internal_gcov_emit_function_args.") +
Twine(i));
1168 auto *EmitArcsCallArgsArrayTy =
1170 EmitFunctionCallArgsArrayGV->setUnnamedAddr(
1173 *M, EmitArcsCallArgsArrayTy,
true,
1176 Twine(
"__llvm_internal_gcov_emit_arcs_args.") +
Twine(i));
1181 {StartFileCallArgs,
Builder.getInt32(CountersSize),
1183 EmitFunctionCallArgsArrayGV,
1186 EmitArcsCallArgsArrayTy, EmitArcsCallArgsArrayGV, TwoZero32s)}));
1190 if (FileInfos.
empty()) {
1200 if ((int64_t)FileInfos.
size() > (int64_t)INT_MAX)
1201 FileInfos.
resize(INT_MAX);
1209 "__llvm_internal_gcov_emit_file_info");
1213 auto *FileLoopHeader =
1215 auto *CounterLoopHeader =
1221 Builder.CreateBr(FileLoopHeader);
1224 Builder.SetInsertPoint(FileLoopHeader);
1227 IV->addIncoming(
Builder.getInt32(0), BB);
1228 auto *FileInfoPtr =
Builder.CreateInBoundsGEP(
1229 FileInfoArrayTy, FileInfoArrayGV, {
Builder.getInt32(0),
IV});
1230 auto *StartFileCallArgsPtr =
1231 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0,
"start_file_args");
1232 auto *StartFileCall =
Builder.CreateCall(
1235 Builder.CreateStructGEP(StartFileCallArgsTy,
1236 StartFileCallArgsPtr, 0),
1239 Builder.CreateStructGEP(StartFileCallArgsTy,
1240 StartFileCallArgsPtr, 1),
1243 Builder.CreateStructGEP(StartFileCallArgsTy,
1244 StartFileCallArgsPtr, 2),
1246 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1247 StartFileCall->addParamAttr(2, AK);
1248 auto *NumCounters =
Builder.CreateLoad(
1249 FileInfoTy->getElementType(1),
1250 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1),
"num_ctrs");
1251 auto *EmitFunctionCallArgsArray =
1252 Builder.CreateLoad(FileInfoTy->getElementType(2),
1253 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2),
1254 "emit_function_args");
1255 auto *EmitArcsCallArgsArray =
Builder.CreateLoad(
1256 FileInfoTy->getElementType(3),
1257 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3),
"emit_arcs_args");
1258 auto *EnterCounterLoopCond =
1260 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
1262 Builder.SetInsertPoint(CounterLoopHeader);
1265 JV->addIncoming(
Builder.getInt32(0), FileLoopHeader);
1266 auto *EmitFunctionCallArgsPtr =
Builder.CreateInBoundsGEP(
1267 EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
1268 auto *EmitFunctionCall =
Builder.CreateCall(
1270 {
Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1271 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1272 EmitFunctionCallArgsPtr, 0),
1274 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1275 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1276 EmitFunctionCallArgsPtr, 1),
1278 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1279 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1280 EmitFunctionCallArgsPtr, 2),
1282 if (
auto AK = TLI->getExtAttrForI32Param(
false)) {
1283 EmitFunctionCall->addParamAttr(0, AK);
1284 EmitFunctionCall->addParamAttr(1, AK);
1285 EmitFunctionCall->addParamAttr(2, AK);
1287 auto *EmitArcsCallArgsPtr =
1288 Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
1289 auto *EmitArcsCall =
Builder.CreateCall(
1292 EmitArcsCallArgsTy->getElementType(0),
1293 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0),
1296 EmitArcsCallArgsTy->getElementType(1),
1297 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 1),
1299 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1300 EmitArcsCall->addParamAttr(0, AK);
1302 auto *CounterLoopCond =
Builder.CreateICmpSLT(NextJV, NumCounters);
1303 Builder.CreateCondBr(CounterLoopCond, CounterLoopHeader, FileLoopLatch);
1304 JV->addIncoming(NextJV, CounterLoopHeader);
1306 Builder.SetInsertPoint(FileLoopLatch);
1307 Builder.CreateCall(SummaryInfo, {});
1308 Builder.CreateCall(EndFile, {});
1309 auto *NextIV =
Builder.CreateAdd(
IV,
Builder.getInt32(1),
"next_file_idx");
1310 auto *FileLoopCond =
1312 Builder.CreateCondBr(FileLoopCond, FileLoopHeader, ExitBB);
1313 IV->addIncoming(NextIV, FileLoopLatch);
1315 Builder.SetInsertPoint(ExitBB);
1321Function *GCOVProfiler::insertReset(
1322 ArrayRef<std::pair<GlobalVariable *, MDNode *>> CountersBySP) {
1324 Function *ResetF =
M->getFunction(
"__llvm_gcov_reset");
1326 ResetF = createInternalFunction(FTy,
"__llvm_gcov_reset",
"_ZTSFvvE");
1334 for (
const auto &
I : CountersBySP) {
1338 GVTy->getNumElements() *
1339 GVTy->getElementType()->getScalarSizeInBits() / 8,
1344 if (
RetTy->isVoidTy())
1346 else if (
RetTy->isIntegerTy())
This file defines the StringMap class.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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"))
Select target instructions out of generic instructions
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 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)
std::vector< std::unique_ptr< Edge > > AllEdges
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(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
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 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...
StringRef str() const
Explicit conversion to StringRef.
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.
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 PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
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.
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...
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, bool ContinueOnCuIndexOverflow)
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)
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.