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;
336 Blocks.insert(std::make_pair(&BB,
GCOVBlock(
P, i++)));
337 if (!ExitBlockBeforeBody)
338 ReturnBlock.Number = i;
340 std::string FunctionNameAndLine;
344 FuncChecksum =
hash_value(FunctionNameAndLine);
348 return Blocks.find(
const_cast<BasicBlock *
>(BB))->second;
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());
394 write(Blocks.size() + 2);
395 for (
int i = Blocks.size() + 2; i; --i)
399 write(Blocks.size() + 2);
404 const uint32_t Outgoing = EntryBlock.OutEdges.size();
407 write(Outgoing * 2 + 1);
408 write(EntryBlock.Number);
409 for (
const auto &
E : EntryBlock.OutEdges) {
414 for (
auto &It : Blocks) {
416 if (
Block.OutEdges.empty())
continue;
421 for (
const auto &
E :
Block.OutEdges) {
428 for (
auto &It : Blocks)
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)) {
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;
917 for (
size_t I : llvm::seq<size_t>(0, Measured)) {
918 const Edge &
E = *MST.AllEdges[
I];
937 JC.
update(EdgeDestinations);
947 Twine(
"failed to open coverage notes file for writing: ") +
952 if (Endian == support::endianness::big) {
953 out.write(
"gcno", 4);
956 out.write(
"oncg", 4);
966 for (
auto &Func : Funcs)
967 Func->writeOut(Stamp);
975 emitGlobalConstructor(CountersBySP);
988 F->addFnAttr(Attribute::NoUnwind);
990 F->addFnAttr(Attribute::NoRedZone);
991 if (!MangledType.
empty())
996void GCOVProfiler::emitGlobalConstructor(
997 SmallVectorImpl<std::pair<GlobalVariable *, MDNode *>> &CountersBySP) {
998 Function *WriteoutF = insertCounterWriteout(CountersBySP);
999 Function *ResetF = insertReset(CountersBySP);
1005 Function *
F = createInternalFunction(FTy,
"__llvm_gcov_init",
"_ZTSFvvE");
1006 F->addFnAttr(Attribute::NoInline);
1017 FunctionCallee GCOVInit =
M->getOrInsertFunction(
"llvm_gcov_init", FTy);
1018 Builder.CreateCall(GCOVInit, {WriteoutF, ResetF});
1031 return M->getOrInsertFunction(
"llvm_gcda_start_file", FTy,
1042 return M->getOrInsertFunction(
"llvm_gcda_emit_function", FTy,
1052 return M->getOrInsertFunction(
"llvm_gcda_emit_arcs", FTy,
1058 return M->getOrInsertFunction(
"llvm_gcda_summary_info", FTy);
1063 return M->getOrInsertFunction(
"llvm_gcda_end_file", FTy);
1066Function *GCOVProfiler::insertCounterWriteout(
1067 ArrayRef<std::pair<GlobalVariable *, MDNode *> > CountersBySP) {
1069 Function *WriteoutF =
M->getFunction(
"__llvm_gcov_writeout");
1072 createInternalFunction(WriteoutFTy,
"__llvm_gcov_writeout",
"_ZTSFvvE");
1073 WriteoutF->
addFnAttr(Attribute::NoInline);
1078 auto *TLI = &GetTLI(*WriteoutF);
1086 NamedMDNode *CUNodes =
M->getNamedMetadata(
"llvm.dbg.cu");
1096 "start_file_args_ty");
1099 "emit_function_args_ty");
1102 "emit_arcs_args_ty");
1105 EmitFunctionCallArgsTy->getPointerTo(),
1106 EmitArcsCallArgsTy->getPointerTo()},
1111 Constant *TwoZero32s[] = {Zero32, Zero32};
1115 auto *
CU = cast<DICompileUnit>(CUNodes->
getOperand(i));
1121 std::string FilenameGcda = mangleName(
CU, GCovFileType::GCDA);
1124 StartFileCallArgsTy,
1125 {
Builder.CreateGlobalStringPtr(FilenameGcda),
1127 Builder.getInt32(CfgChecksum)});
1131 for (
int j : llvm::seq<int>(0, CountersBySP.
size())) {
1132 uint32_t FuncChecksum = Funcs.empty() ? 0 : Funcs[
j]->getFuncChecksum();
1134 EmitFunctionCallArgsTy,
1136 Builder.getInt32(FuncChecksum),
1137 Builder.getInt32(CfgChecksum)}));
1140 unsigned Arcs = cast<ArrayType>(GV->
getValueType())->getNumElements();
1147 int CountersSize = CountersBySP.
size();
1148 assert(CountersSize == (
int)EmitFunctionCallArgsArray.size() &&
1149 "Mismatched array size!");
1150 assert(CountersSize == (
int)EmitArcsCallArgsArray.
size() &&
1151 "Mismatched array size!");
1152 auto *EmitFunctionCallArgsArrayTy =
1155 *M, EmitFunctionCallArgsArrayTy,
true,
1158 EmitFunctionCallArgsArray),
1159 Twine(
"__llvm_internal_gcov_emit_function_args.") +
Twine(i));
1160 auto *EmitArcsCallArgsArrayTy =
1162 EmitFunctionCallArgsArrayGV->setUnnamedAddr(
1165 *M, EmitArcsCallArgsArrayTy,
true,
1168 Twine(
"__llvm_internal_gcov_emit_arcs_args.") +
Twine(i));
1173 {StartFileCallArgs,
Builder.getInt32(CountersSize),
1175 EmitFunctionCallArgsArrayGV,
1178 EmitArcsCallArgsArrayTy, EmitArcsCallArgsArrayGV, TwoZero32s)}));
1182 if (FileInfos.
empty()) {
1192 if ((int64_t)FileInfos.
size() > (int64_t)INT_MAX)
1193 FileInfos.
resize(INT_MAX);
1201 "__llvm_internal_gcov_emit_file_info");
1205 auto *FileLoopHeader =
1207 auto *CounterLoopHeader =
1213 Builder.CreateBr(FileLoopHeader);
1216 Builder.SetInsertPoint(FileLoopHeader);
1219 IV->addIncoming(
Builder.getInt32(0), BB);
1220 auto *FileInfoPtr =
Builder.CreateInBoundsGEP(
1221 FileInfoArrayTy, FileInfoArrayGV, {
Builder.getInt32(0),
IV});
1222 auto *StartFileCallArgsPtr =
1223 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 0,
"start_file_args");
1224 auto *StartFileCall =
Builder.CreateCall(
1227 Builder.CreateStructGEP(StartFileCallArgsTy,
1228 StartFileCallArgsPtr, 0),
1231 Builder.CreateStructGEP(StartFileCallArgsTy,
1232 StartFileCallArgsPtr, 1),
1235 Builder.CreateStructGEP(StartFileCallArgsTy,
1236 StartFileCallArgsPtr, 2),
1238 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1239 StartFileCall->addParamAttr(2, AK);
1240 auto *NumCounters =
Builder.CreateLoad(
1241 FileInfoTy->getElementType(1),
1242 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 1),
"num_ctrs");
1243 auto *EmitFunctionCallArgsArray =
1244 Builder.CreateLoad(FileInfoTy->getElementType(2),
1245 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 2),
1246 "emit_function_args");
1247 auto *EmitArcsCallArgsArray =
Builder.CreateLoad(
1248 FileInfoTy->getElementType(3),
1249 Builder.CreateStructGEP(FileInfoTy, FileInfoPtr, 3),
"emit_arcs_args");
1250 auto *EnterCounterLoopCond =
1252 Builder.CreateCondBr(EnterCounterLoopCond, CounterLoopHeader, FileLoopLatch);
1254 Builder.SetInsertPoint(CounterLoopHeader);
1257 JV->addIncoming(
Builder.getInt32(0), FileLoopHeader);
1258 auto *EmitFunctionCallArgsPtr =
Builder.CreateInBoundsGEP(
1259 EmitFunctionCallArgsTy, EmitFunctionCallArgsArray, JV);
1260 auto *EmitFunctionCall =
Builder.CreateCall(
1262 {
Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(0),
1263 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1264 EmitFunctionCallArgsPtr, 0),
1266 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(1),
1267 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1268 EmitFunctionCallArgsPtr, 1),
1270 Builder.CreateLoad(EmitFunctionCallArgsTy->getElementType(2),
1271 Builder.CreateStructGEP(EmitFunctionCallArgsTy,
1272 EmitFunctionCallArgsPtr, 2),
1274 if (
auto AK = TLI->getExtAttrForI32Param(
false)) {
1275 EmitFunctionCall->addParamAttr(0, AK);
1276 EmitFunctionCall->addParamAttr(1, AK);
1277 EmitFunctionCall->addParamAttr(2, AK);
1279 auto *EmitArcsCallArgsPtr =
1280 Builder.CreateInBoundsGEP(EmitArcsCallArgsTy, EmitArcsCallArgsArray, JV);
1281 auto *EmitArcsCall =
Builder.CreateCall(
1284 EmitArcsCallArgsTy->getElementType(0),
1285 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 0),
1288 EmitArcsCallArgsTy->getElementType(1),
1289 Builder.CreateStructGEP(EmitArcsCallArgsTy, EmitArcsCallArgsPtr, 1),
1291 if (
auto AK = TLI->getExtAttrForI32Param(
false))
1292 EmitArcsCall->addParamAttr(0, AK);
1294 auto *CounterLoopCond =
Builder.CreateICmpSLT(NextJV, NumCounters);
1295 Builder.CreateCondBr(CounterLoopCond, CounterLoopHeader, FileLoopLatch);
1296 JV->addIncoming(NextJV, CounterLoopHeader);
1298 Builder.SetInsertPoint(FileLoopLatch);
1299 Builder.CreateCall(SummaryInfo, {});
1300 Builder.CreateCall(EndFile, {});
1301 auto *NextIV =
Builder.CreateAdd(
IV,
Builder.getInt32(1),
"next_file_idx");
1302 auto *FileLoopCond =
1304 Builder.CreateCondBr(FileLoopCond, FileLoopHeader, ExitBB);
1305 IV->addIncoming(NextIV, FileLoopLatch);
1307 Builder.SetInsertPoint(ExitBB);
1313Function *GCOVProfiler::insertReset(
1314 ArrayRef<std::pair<GlobalVariable *, MDNode *>> CountersBySP) {
1316 Function *ResetF =
M->getFunction(
"__llvm_gcov_reset");
1318 ResetF = createInternalFunction(FTy,
"__llvm_gcov_reset",
"_ZTSFvvE");
1326 for (
const auto &
I : CountersBySP) {
1330 GVTy->getNumElements() *
1331 GVTy->getElementType()->getScalarSizeInBits() / 8,
1336 if (
RetTy->isVoidTy())
1338 else if (
RetTy->isIntegerTy())
This file defines the StringMap class.
amdgpu Simplify well known AMD library false FunctionCallee Callee
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
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.
print must be executed print the must be executed context for all instructions
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(const BasicBlock *Src, const 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 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.
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.
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)
static PointerType * getInt64PtrTy(LLVMContext &C, unsigned AS=0)
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)
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.
Error write(MCStreamer &Out, ArrayRef< std::string > Inputs)
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)
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.
static GCOVOptions getDefault()
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.