37 #define DEBUG_TYPE "functionattrs"
39 STATISTIC(NumReadNone,
"Number of functions marked readnone");
40 STATISTIC(NumReadOnly,
"Number of functions marked readonly");
41 STATISTIC(NumNoCapture,
"Number of arguments marked nocapture");
42 STATISTIC(NumReadNoneArg,
"Number of arguments marked readnone");
43 STATISTIC(NumReadOnlyArg,
"Number of arguments marked readonly");
44 STATISTIC(NumNoAlias,
"Number of function returns marked noalias");
45 STATISTIC(NumAnnotated,
"Number of attributes added to library functions");
73 void setDoesNotAccessMemory(
Function &
F) {
80 void setOnlyReadsMemory(
Function &F) {
94 void setDoesNotCapture(
Function &F,
unsigned n) {
101 void setOnlyReadsMemory(
Function &F,
unsigned n) {
108 void setDoesNotAlias(
Function &F,
unsigned n) {
118 bool inferPrototypeAttributes(
Function &F);
139 "Deduce function attributes",
false,
false)
150 bool FunctionAttrs::AddReadAttrs(
const CallGraphSCC &SCC) {
156 SCCNodes.
insert((*I)->getFunction());
160 bool ReadsMemory =
false;
194 if (
CS.getCalledFunction() && SCCNodes.
count(
CS.getCalledFunction()))
212 if (!AA->pointsToConstantMemory(Loc,
true)) {
231 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(I)) {
233 if (!LI->isVolatile()) {
235 if (AA->pointsToConstantMemory(Loc,
true))
238 }
else if (
StoreInst *SI = dyn_cast<StoreInst>(I)) {
240 if (!
SI->isVolatile()) {
242 if (AA->pointsToConstantMemory(Loc,
true))
245 }
else if (
VAArgInst *
VI = dyn_cast<VAArgInst>(I)) {
248 if (AA->pointsToConstantMemory(Loc,
true))
265 bool MadeChange =
false;
304 struct ArgumentGraphNode {
309 class ArgumentGraph {
312 typedef std::map<Argument*, ArgumentGraphNode> ArgumentMapTy;
314 ArgumentMapTy ArgumentMap;
322 ArgumentGraphNode SyntheticRoot;
325 ArgumentGraph() { SyntheticRoot.Definition =
nullptr; }
329 iterator
begin() {
return SyntheticRoot.Uses.
begin(); }
330 iterator
end() {
return SyntheticRoot.Uses.
end(); }
331 ArgumentGraphNode *getEntryNode() {
return &SyntheticRoot; }
333 ArgumentGraphNode *operator[](
Argument *
A) {
334 ArgumentGraphNode &Node = ArgumentMap[
A];
336 SyntheticRoot.Uses.push_back(&Node);
346 : Captured(
false), SCCNodes(SCCNodes) {}
348 void tooManyUses()
override { Captured =
true; }
350 bool captured(
const Use *U)
override {
352 if (!
CS.getInstruction()) { Captured =
true;
return true; }
355 if (!F || !SCCNodes.
count(F)) { Captured =
true;
return true; }
360 PI != PE; ++PI, ++AI) {
362 assert(F->
isVarArg() &&
"More params than args in non-varargs call");
372 assert(Found &&
"Capturing call-site captured nothing?");
391 return N->Uses.begin();
394 return N->Uses.end();
400 return AG->getEntryNode();
435 while (!Worklist.
empty()) {
441 case Instruction::BitCast:
442 case Instruction::GetElementPtr:
445 case Instruction::AddrSpaceCast:
448 if (Visited.
insert(&UU).second)
453 case Instruction::Invoke: {
454 bool Captures =
true;
459 auto AddUsersToWorklistIfCapturing = [&] {
462 if (Visited.
insert(&UU).second)
468 AddUsersToWorklistIfCapturing();
476 AddUsersToWorklistIfCapturing();
488 "More params than args in non-varargs call.");
492 if (SCCNodes.
count(AI))
500 AddUsersToWorklistIfCapturing();
508 case Instruction::ICmp:
521 bool FunctionAttrs::AddArgumentAttrs(
const CallGraphSCC &SCC) {
522 bool Changed =
false;
561 if (
A->getType()->isPointerTy() && !
A->hasNoCaptureAttr()) {
562 A->addAttr(AttributeSet::get(F->
getContext(),
A->getArgNo() + 1, B));
572 if (!
A->getType()->isPointerTy())
continue;
573 bool HasNonLocalUses =
false;
574 if (!
A->hasNoCaptureAttr()) {
575 ArgumentUsesTracker Tracker(SCCNodes);
577 if (!Tracker.Captured) {
578 if (Tracker.Uses.empty()) {
580 A->addAttr(AttributeSet::get(F->
getContext(),
A->getArgNo()+1, B));
587 ArgumentGraphNode *Node = AG[
A];
589 UE = Tracker.Uses.end(); UI != UE; ++UI) {
590 Node->Uses.push_back(AG[*UI]);
592 HasNonLocalUses =
true;
598 if (!HasNonLocalUses && !
A->onlyReadsMemory()) {
609 A->addAttr(AttributeSet::get(
A->getContext(),
A->getArgNo() + 1, B));
625 const std::vector<ArgumentGraphNode *> &ArgumentSCC = *
I;
626 if (ArgumentSCC.size() == 1) {
627 if (!ArgumentSCC[0]->Definition)
continue;
630 if (ArgumentSCC[0]->Uses.size() == 1 &&
631 ArgumentSCC[0]->Uses[0] == ArgumentSCC[0]) {
632 Argument *
A = ArgumentSCC[0]->Definition;
640 bool SCCCaptured =
false;
641 for (
auto I = ArgumentSCC.begin(), E = ArgumentSCC.end();
642 I != E && !SCCCaptured; ++
I) {
643 ArgumentGraphNode *Node = *
I;
644 if (Node->Uses.empty()) {
645 if (!Node->Definition->hasNoCaptureAttr())
649 if (SCCCaptured)
continue;
654 for (
auto I = ArgumentSCC.begin(), E = ArgumentSCC.end(); I != E; ++
I) {
655 ArgumentSCCNodes.
insert((*I)->Definition);
658 for (
auto I = ArgumentSCC.begin(), E = ArgumentSCC.end();
659 I != E && !SCCCaptured; ++
I) {
660 ArgumentGraphNode *
N = *
I;
662 UE = N->Uses.end(); UI != UE; ++UI) {
670 if (SCCCaptured)
continue;
672 for (
unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
673 Argument *A = ArgumentSCC[i]->Definition;
691 for (
unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
692 Argument *A = ArgumentSCC[i]->Definition;
709 for (
unsigned i = 0, e = ArgumentSCC.size(); i != e; ++i) {
710 Argument *A = ArgumentSCC[i]->Definition;
725 bool FunctionAttrs::IsFunctionMallocLike(
Function *F,
729 if (
ReturnInst *
Ret = dyn_cast<ReturnInst>(I->getTerminator()))
730 FlowsToReturn.
insert(
Ret->getReturnValue());
732 for (
unsigned i = 0; i != FlowsToReturn.
size(); ++i) {
733 Value *RetVal = FlowsToReturn[i];
735 if (
Constant *
C = dyn_cast<Constant>(RetVal)) {
736 if (!
C->isNullValue() && !isa<UndefValue>(
C))
742 if (isa<Argument>(RetVal))
745 if (
Instruction *RVI = dyn_cast<Instruction>(RetVal))
746 switch (RVI->getOpcode()) {
748 case Instruction::BitCast:
749 case Instruction::GetElementPtr:
750 case Instruction::AddrSpaceCast:
751 FlowsToReturn.
insert(RVI->getOperand(0));
760 PHINode *PN = cast<PHINode>(RVI);
762 FlowsToReturn.
insert(IncValue);
767 case Instruction::Alloca:
770 case Instruction::Invoke: {
774 if (
CS.getCalledFunction() &&
775 SCCNodes.
count(
CS.getCalledFunction()))
790 bool FunctionAttrs::AddNoAliasAttrs(
const CallGraphSCC &SCC) {
796 SCCNodes.
insert((*I)->getFunction());
821 if (!IsFunctionMallocLike(F, SCCNodes))
825 bool MadeChange =
false;
842 bool FunctionAttrs::inferPrototypeAttributes(
Function &F) {
848 if (!(TLI->getLibFunc(F.
getName(), TheLibFunc) && TLI->has(TheLibFunc)))
851 switch (TheLibFunc) {
852 case LibFunc::strlen:
855 setOnlyReadsMemory(F);
857 setDoesNotCapture(F, 1);
859 case LibFunc::strchr:
860 case LibFunc::strrchr:
865 setOnlyReadsMemory(F);
868 case LibFunc::strtol:
869 case LibFunc::strtod:
870 case LibFunc::strtof:
871 case LibFunc::strtoul:
872 case LibFunc::strtoll:
873 case LibFunc::strtold:
874 case LibFunc::strtoull:
879 setDoesNotCapture(F, 2);
880 setOnlyReadsMemory(F, 1);
882 case LibFunc::strcpy:
883 case LibFunc::stpcpy:
884 case LibFunc::strcat:
885 case LibFunc::strncat:
886 case LibFunc::strncpy:
887 case LibFunc::stpncpy:
892 setDoesNotCapture(F, 2);
893 setOnlyReadsMemory(F, 2);
895 case LibFunc::strxfrm:
901 setDoesNotCapture(F, 1);
902 setDoesNotCapture(F, 2);
903 setOnlyReadsMemory(F, 2);
905 case LibFunc::strcmp:
906 case LibFunc::strspn:
907 case LibFunc::strncmp:
908 case LibFunc::strcspn:
909 case LibFunc::strcoll:
910 case LibFunc::strcasecmp:
911 case LibFunc::strncasecmp:
916 setOnlyReadsMemory(F);
918 setDoesNotCapture(F, 1);
919 setDoesNotCapture(F, 2);
921 case LibFunc::strstr:
922 case LibFunc::strpbrk:
925 setOnlyReadsMemory(F);
927 setDoesNotCapture(F, 2);
929 case LibFunc::strtok:
930 case LibFunc::strtok_r:
934 setDoesNotCapture(F, 2);
935 setOnlyReadsMemory(F, 2);
941 setDoesNotCapture(F, 1);
942 setOnlyReadsMemory(F, 1);
944 case LibFunc::setbuf:
945 case LibFunc::setvbuf:
949 setDoesNotCapture(F, 1);
951 case LibFunc::strdup:
952 case LibFunc::strndup:
957 setDoesNotAlias(F, 0);
958 setDoesNotCapture(F, 1);
959 setOnlyReadsMemory(F, 1);
962 case LibFunc::statvfs:
968 setDoesNotCapture(F, 1);
969 setDoesNotCapture(F, 2);
970 setOnlyReadsMemory(F, 1);
972 case LibFunc::sscanf:
978 setDoesNotCapture(F, 1);
979 setDoesNotCapture(F, 2);
980 setOnlyReadsMemory(F, 1);
981 setOnlyReadsMemory(F, 2);
983 case LibFunc::sprintf:
989 setDoesNotCapture(F, 1);
990 setDoesNotCapture(F, 2);
991 setOnlyReadsMemory(F, 2);
993 case LibFunc::snprintf:
999 setDoesNotCapture(F, 1);
1000 setDoesNotCapture(F, 3);
1001 setOnlyReadsMemory(F, 3);
1003 case LibFunc::setitimer:
1009 setDoesNotCapture(F, 2);
1010 setDoesNotCapture(F, 3);
1011 setOnlyReadsMemory(F, 2);
1013 case LibFunc::system:
1018 setDoesNotCapture(F, 1);
1019 setOnlyReadsMemory(F, 1);
1021 case LibFunc::malloc:
1026 setDoesNotAlias(F, 0);
1028 case LibFunc::memcmp:
1033 setOnlyReadsMemory(F);
1035 setDoesNotCapture(F, 1);
1036 setDoesNotCapture(F, 2);
1038 case LibFunc::memchr:
1039 case LibFunc::memrchr:
1042 setOnlyReadsMemory(F);
1046 case LibFunc::modff:
1047 case LibFunc::modfl:
1052 setDoesNotCapture(F, 2);
1054 case LibFunc::memcpy:
1055 case LibFunc::memccpy:
1056 case LibFunc::memmove:
1061 setDoesNotCapture(F, 2);
1062 setOnlyReadsMemory(F, 2);
1064 case LibFunc::memalign:
1067 setDoesNotAlias(F, 0);
1069 case LibFunc::mkdir:
1074 setDoesNotCapture(F, 1);
1075 setOnlyReadsMemory(F, 1);
1077 case LibFunc::mktime:
1082 setDoesNotCapture(F, 1);
1084 case LibFunc::realloc:
1090 setDoesNotAlias(F, 0);
1091 setDoesNotCapture(F, 1);
1098 setDoesNotCapture(F, 2);
1100 case LibFunc::rewind:
1105 setDoesNotCapture(F, 1);
1107 case LibFunc::rmdir:
1109 case LibFunc::realpath:
1114 setDoesNotCapture(F, 1);
1115 setOnlyReadsMemory(F, 1);
1123 setDoesNotCapture(F, 1);
1124 setDoesNotCapture(F, 2);
1125 setOnlyReadsMemory(F, 1);
1126 setOnlyReadsMemory(F, 2);
1128 case LibFunc::readlink:
1134 setDoesNotCapture(F, 1);
1135 setDoesNotCapture(F, 2);
1136 setOnlyReadsMemory(F, 1);
1142 setDoesNotCapture(F, 2);
1143 setOnlyReadsMemory(F, 2);
1145 case LibFunc::bcopy:
1151 setDoesNotCapture(F, 1);
1152 setDoesNotCapture(F, 2);
1153 setOnlyReadsMemory(F, 1);
1161 setOnlyReadsMemory(F);
1162 setDoesNotCapture(F, 1);
1163 setDoesNotCapture(F, 2);
1165 case LibFunc::bzero:
1169 setDoesNotCapture(F, 1);
1171 case LibFunc::calloc:
1176 setDoesNotAlias(F, 0);
1178 case LibFunc::chmod:
1179 case LibFunc::chown:
1183 setDoesNotCapture(F, 1);
1184 setOnlyReadsMemory(F, 1);
1186 case LibFunc::ctermid:
1187 case LibFunc::clearerr:
1188 case LibFunc::closedir:
1192 setDoesNotCapture(F, 1);
1197 case LibFunc::atoll:
1201 setOnlyReadsMemory(F);
1202 setDoesNotCapture(F, 1);
1208 setDoesNotCapture(F, 1);
1209 setOnlyReadsMemory(F, 1);
1211 case LibFunc::fopen:
1218 setDoesNotAlias(F, 0);
1219 setDoesNotCapture(F, 1);
1220 setDoesNotCapture(F, 2);
1221 setOnlyReadsMemory(F, 1);
1222 setOnlyReadsMemory(F, 2);
1224 case LibFunc::fdopen:
1230 setDoesNotAlias(F, 0);
1231 setDoesNotCapture(F, 2);
1232 setOnlyReadsMemory(F, 2);
1236 case LibFunc::fseek:
1237 case LibFunc::ftell:
1238 case LibFunc::fgetc:
1239 case LibFunc::fseeko:
1240 case LibFunc::ftello:
1241 case LibFunc::fileno:
1242 case LibFunc::fflush:
1243 case LibFunc::fclose:
1244 case LibFunc::fsetpos:
1245 case LibFunc::flockfile:
1246 case LibFunc::funlockfile:
1247 case LibFunc::ftrylockfile:
1251 setDoesNotCapture(F, 1);
1253 case LibFunc::ferror:
1257 setDoesNotCapture(F, 1);
1258 setOnlyReadsMemory(F);
1260 case LibFunc::fputc:
1261 case LibFunc::fstat:
1262 case LibFunc::frexp:
1263 case LibFunc::frexpf:
1264 case LibFunc::frexpl:
1265 case LibFunc::fstatvfs:
1269 setDoesNotCapture(F, 2);
1271 case LibFunc::fgets:
1277 setDoesNotCapture(F, 3);
1279 case LibFunc::fread:
1285 setDoesNotCapture(F, 1);
1286 setDoesNotCapture(F, 4);
1288 case LibFunc::fwrite:
1294 setDoesNotCapture(F, 1);
1295 setDoesNotCapture(F, 4);
1297 case LibFunc::fputs:
1303 setDoesNotCapture(F, 1);
1304 setDoesNotCapture(F, 2);
1305 setOnlyReadsMemory(F, 1);
1307 case LibFunc::fscanf:
1308 case LibFunc::fprintf:
1314 setDoesNotCapture(F, 1);
1315 setDoesNotCapture(F, 2);
1316 setOnlyReadsMemory(F, 2);
1318 case LibFunc::fgetpos:
1324 setDoesNotCapture(F, 1);
1325 setDoesNotCapture(F, 2);
1328 case LibFunc::getlogin_r:
1329 case LibFunc::getc_unlocked:
1333 setDoesNotCapture(F, 1);
1335 case LibFunc::getenv:
1339 setOnlyReadsMemory(F);
1340 setDoesNotCapture(F, 1);
1343 case LibFunc::getchar:
1346 case LibFunc::getitimer:
1350 setDoesNotCapture(F, 2);
1352 case LibFunc::getpwnam:
1356 setDoesNotCapture(F, 1);
1357 setOnlyReadsMemory(F, 1);
1359 case LibFunc::ungetc:
1363 setDoesNotCapture(F, 2);
1365 case LibFunc::uname:
1369 setDoesNotCapture(F, 1);
1371 case LibFunc::unlink:
1375 setDoesNotCapture(F, 1);
1376 setOnlyReadsMemory(F, 1);
1378 case LibFunc::unsetenv:
1382 setDoesNotCapture(F, 1);
1383 setOnlyReadsMemory(F, 1);
1385 case LibFunc::utime:
1386 case LibFunc::utimes:
1392 setDoesNotCapture(F, 1);
1393 setDoesNotCapture(F, 2);
1394 setOnlyReadsMemory(F, 1);
1395 setOnlyReadsMemory(F, 2);
1401 setDoesNotCapture(F, 2);
1404 case LibFunc::printf:
1405 case LibFunc::perror:
1409 setDoesNotCapture(F, 1);
1410 setOnlyReadsMemory(F, 1);
1412 case LibFunc::pread:
1416 setDoesNotCapture(F, 2);
1418 case LibFunc::pwrite:
1422 setDoesNotCapture(F, 2);
1423 setOnlyReadsMemory(F, 2);
1425 case LibFunc::putchar:
1428 case LibFunc::popen:
1435 setDoesNotAlias(F, 0);
1436 setDoesNotCapture(F, 1);
1437 setDoesNotCapture(F, 2);
1438 setOnlyReadsMemory(F, 1);
1439 setOnlyReadsMemory(F, 2);
1441 case LibFunc::pclose:
1445 setDoesNotCapture(F, 1);
1447 case LibFunc::vscanf:
1451 setDoesNotCapture(F, 1);
1452 setOnlyReadsMemory(F, 1);
1454 case LibFunc::vsscanf:
1460 setDoesNotCapture(F, 1);
1461 setDoesNotCapture(F, 2);
1462 setOnlyReadsMemory(F, 1);
1463 setOnlyReadsMemory(F, 2);
1465 case LibFunc::vfscanf:
1471 setDoesNotCapture(F, 1);
1472 setDoesNotCapture(F, 2);
1473 setOnlyReadsMemory(F, 2);
1475 case LibFunc::valloc:
1479 setDoesNotAlias(F, 0);
1481 case LibFunc::vprintf:
1485 setDoesNotCapture(F, 1);
1486 setOnlyReadsMemory(F, 1);
1488 case LibFunc::vfprintf:
1489 case LibFunc::vsprintf:
1495 setDoesNotCapture(F, 1);
1496 setDoesNotCapture(F, 2);
1497 setOnlyReadsMemory(F, 2);
1499 case LibFunc::vsnprintf:
1505 setDoesNotCapture(F, 1);
1506 setDoesNotCapture(F, 3);
1507 setOnlyReadsMemory(F, 3);
1513 setDoesNotCapture(F, 1);
1514 setOnlyReadsMemory(F, 1);
1516 case LibFunc::opendir:
1522 setDoesNotAlias(F, 0);
1523 setDoesNotCapture(F, 1);
1524 setOnlyReadsMemory(F, 1);
1526 case LibFunc::tmpfile:
1530 setDoesNotAlias(F, 0);
1532 case LibFunc::times:
1536 setDoesNotCapture(F, 1);
1538 case LibFunc::htonl:
1539 case LibFunc::htons:
1540 case LibFunc::ntohl:
1541 case LibFunc::ntohs:
1543 setDoesNotAccessMemory(F);
1545 case LibFunc::lstat:
1551 setDoesNotCapture(F, 1);
1552 setDoesNotCapture(F, 2);
1553 setOnlyReadsMemory(F, 1);
1555 case LibFunc::lchown:
1559 setDoesNotCapture(F, 1);
1560 setOnlyReadsMemory(F, 1);
1562 case LibFunc::qsort:
1566 setDoesNotCapture(F, 4);
1568 case LibFunc::dunder_strdup:
1569 case LibFunc::dunder_strndup:
1575 setDoesNotAlias(F, 0);
1576 setDoesNotCapture(F, 1);
1577 setOnlyReadsMemory(F, 1);
1579 case LibFunc::dunder_strtok_r:
1584 setDoesNotCapture(F, 2);
1585 setOnlyReadsMemory(F, 2);
1587 case LibFunc::under_IO_getc:
1591 setDoesNotCapture(F, 1);
1593 case LibFunc::under_IO_putc:
1597 setDoesNotCapture(F, 2);
1599 case LibFunc::dunder_isoc99_scanf:
1604 setDoesNotCapture(F, 1);
1605 setOnlyReadsMemory(F, 1);
1607 case LibFunc::stat64:
1608 case LibFunc::lstat64:
1609 case LibFunc::statvfs64:
1615 setDoesNotCapture(F, 1);
1616 setDoesNotCapture(F, 2);
1617 setOnlyReadsMemory(F, 1);
1619 case LibFunc::dunder_isoc99_sscanf:
1625 setDoesNotCapture(F, 1);
1626 setDoesNotCapture(F, 2);
1627 setOnlyReadsMemory(F, 1);
1628 setOnlyReadsMemory(F, 2);
1630 case LibFunc::fopen64:
1637 setDoesNotAlias(F, 0);
1638 setDoesNotCapture(F, 1);
1639 setDoesNotCapture(F, 2);
1640 setOnlyReadsMemory(F, 1);
1641 setOnlyReadsMemory(F, 2);
1643 case LibFunc::fseeko64:
1644 case LibFunc::ftello64:
1648 setDoesNotCapture(F, 1);
1650 case LibFunc::tmpfile64:
1654 setDoesNotAlias(F, 0);
1656 case LibFunc::fstat64:
1657 case LibFunc::fstatvfs64:
1661 setDoesNotCapture(F, 2);
1663 case LibFunc::open64:
1667 setDoesNotCapture(F, 1);
1668 setOnlyReadsMemory(F, 1);
1670 case LibFunc::gettimeofday:
1678 setDoesNotCapture(F, 1);
1679 setDoesNotCapture(F, 2);
1691 bool FunctionAttrs::annotateLibraryCalls(
const CallGraphSCC &SCC) {
1692 bool MadeChange =
false;
1700 MadeChange |= inferPrototypeAttributes(*F);
1707 AA = &getAnalysis<AliasAnalysis>();
1708 TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1710 bool Changed = annotateLibraryCalls(SCC);
1711 Changed |= AddReadAttrs(SCC);
1712 Changed |= AddArgumentAttrs(SCC);
1713 Changed |= AddNoAliasAttrs(SCC);
void initializeFunctionAttrsPass(PassRegistry &)
bool hasNoCaptureAttr() const
Return true if this argument has the nocapture attribute on it in its containing function.
Pass interface - Implemented by all 'passes'.
static ChildIteratorType nodes_end(ArgumentGraph *AG)
ReturnInst - Return a value (possibly void), from a function.
void push_back(const T &Elt)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
const_iterator end(StringRef path)
Get end iterator over path.
iterator_range< use_iterator > uses()
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
LLVM Argument representation.
This callback is used in conjunction with PointerMayBeCaptured.
STATISTIC(NumFunctions,"Total number of functions")
value_type read(const void *memory)
Read a value of a particular endianness from memory.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
unsigned getNumParams() const
getNumParams - Return the number of fixed parameters this function type requires. ...
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
std::vector< CallGraphNode * >::const_iterator iterator
std::error_code remove(const Twine &path, bool IgnoreNonExisting=true)
Remove path.
ModRefBehavior
ModRefBehavior - Summary of how a function affects memory in the program.
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
const_iterator begin(StringRef path)
Get begin iterator over path.
Type * getReturnType() const
LoadInst - an instruction for reading from memory.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
User::op_iterator arg_iterator
arg_iterator - The type of iterator to use when looping over actual arguments at this call site...
void getAnalysisUsage(AnalysisUsage &Info) const override
getAnalysisUsage - For this class, we declare that we require and preserve the call graph...
size_type size() const
Determine the number of elements in the SetVector.
bool doesNotAlias(unsigned n) const
Determine if the parameter does not alias other parameters.
StringRef getName() const
Return a constant reference to the value's name.
Pass * createFunctionAttrsPass()
createFunctionAttrsPass - This pass discovers functions that do not access memory, or only read memory, and gives them the readnone/readonly attribute.
void addAttr(AttributeSet AS)
Add a Attribute to an argument.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
inst_iterator inst_begin(Function *F)
bool doesNotThrow() const
Determine if the function cannot unwind.
SelectInst - This class represents the LLVM 'select' instruction.
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
A Use represents the edge between a Value definition and its users.
INITIALIZE_PASS_BEGIN(FunctionAttrs,"functionattrs","Deduce function attributes", false, false) INITIALIZE_PASS_END(FunctionAttrs
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
No attributes have been set.
Windows NT (Windows on ARM)
Function does not access memory.
Function creates no aliases of pointer.
void removeAttr(AttributeSet AS)
Remove a Attribute from an argument.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
FunctionType - Class to represent function types.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool mayReadFromMemory() const
mayReadFromMemory - Return true if this instruction may read memory.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
StoreInst - an instruction for storing to memory.
void removeAttributes(unsigned i, AttributeSet attr)
removes the attributes from the list of attributes.
bool doesNotAccessMemory() const
Determine if the function does not access memory.
Considered to not alias after call.
bool onlyReadsMemory(ImmutableCallSite CS)
onlyReadsMemory - If the specified call is known to only read from non-volatile memory (or not access...
void setDoesNotCapture(unsigned n)
bool doesNotAccessMemory() const
Determine if the call does not access memory.
static MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
Type * getParamType(unsigned i) const
Parameter type accessors.
friend const_iterator end(StringRef path)
Get end iterator over path.
void setOnlyReadsMemory()
The ModulePass which wraps up a CallGraph and the logic to build it.
static bool mayBeOverridden(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time...
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
This is an important base class in LLVM.
bool hasInAllocaAttr() const
Return true if this argument has the inalloca attribute on it in its containing function.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static ChildIteratorType child_end(NodeType *N)
void setDoesNotAlias(unsigned n)
static NodeType * getEntryNode(NodeType *A)
Represent the analysis usage information of a pass.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
#define INITIALIZE_AG_DEPENDENCY(depName)
static bool doesAccessArgPointees(ModRefBehavior MRB)
doesAccessArgPointees - Return true if functions with the specified behavior are known to potentially...
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
VAArgInst - This class represents the va_arg llvm instruction, which returns an argument of the speci...
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
bool mayWriteToMemory() const
mayWriteToMemory - Return true if this instruction may modify memory.
std::error_code rename(const Twine &from, const Twine &to)
Rename from to to.
Representation for a specific memory location.
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
friend const_iterator begin(StringRef path)
Get begin iterator over path.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void addAttribute(unsigned i, Attribute::AttrKind attr)
adds the attribute to the list of attributes.
Function must not be optimized.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
Function only reads from memory.
void write(void *memory, value_type value)
Write a value to memory with a particular endianness.
bool doesNotCapture(unsigned ArgNo) const
Determine whether this argument is not captured.
ArgumentGraphNode NodeType
static bool onlyAccessesArgPointees(ModRefBehavior MRB)
onlyAccessesArgPointees - Return true if functions with the specified behavior are known to read and ...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
void setDoesNotAccessMemory()
void getAAMetadata(AAMDNodes &N, bool Merge=false) const
getAAMetadata - Fills the AAMDNodes structure with AA metadata from this instruction.
FunctionType * getFunctionType() const
Deduce function attributes
static ChildIteratorType child_begin(NodeType *N)
DoesNotAccessMemory - This function does not perform any non-local loads or stores to memory...
Type * getReturnType() const
LLVM Value Representation.
bool doesNotCapture(unsigned n) const
Determine if the parameter can be captured.
CallGraphSCC - This is a single SCC that a CallGraphSCCPass is run on.
unsigned getOpcode() const
getOpcode() returns a member of one of the enums like Instruction::Add.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
static ChildIteratorType nodes_begin(ArgumentGraph *AG)
std::error_code access(const Twine &Path, AccessMode Mode)
Can the file be accessed?
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
print Print MemDeps of function
C - The default llvm calling convention, compatible with C.
const Value * getFalseValue() const
inst_iterator inst_end(Function *F)
op_range incoming_values()
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
SmallVectorImpl< ArgumentGraphNode * >::iterator ChildIteratorType
static Attribute::AttrKind determinePointerReadAttrs(Argument *A, const SmallPtrSet< Argument *, 8 > &SCCNodes)
static NodeType * getEntryNode(ArgumentGraph *AG)
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...