101 using namespace llvm;
104 #define DEBUG_TYPE "wholeprogramdevirt" 107 "wholeprogramdevirt-summary-action",
108 cl::desc(
"What to do with the summary when running this pass"),
111 "Import typeid resolutions from summary and globals"),
113 "Export typeid resolutions to summary and globals")),
117 "wholeprogramdevirt-read-summary",
118 cl::desc(
"Read summary from given YAML file before running pass"),
122 "wholeprogramdevirt-write-summary",
123 cl::desc(
"Write summary to given YAML file after running pass"),
129 cl::desc(
"Maximum number of call targets per " 130 "call site to enable branch funnels"));
135 cl::desc(
"Print index-based devirtualization messages"));
142 bool IsAfter, uint64_t
Size) {
144 uint64_t MinByte = 0;
172 std::vector<ArrayRef<uint8_t>> Used;
175 :
Target.TM->Bits->Before.BytesUsed;
176 uint64_t
Offset = IsAfter ? MinByte -
Target.minAfterBytes()
177 : MinByte -
Target.minBeforeBytes();
182 Used.push_back(VTUsed.
slice(Offset));
187 for (
unsigned I = 0;; ++
I) {
188 uint8_t BitsUsed = 0;
189 for (
auto &&
B : Used)
192 if (BitsUsed != 0xff)
193 return (MinByte +
I) * 8 +
199 for (
unsigned I = 0;; ++
I) {
200 for (
auto &&
B : Used) {
202 while ((
I + Byte) <
B.size() && Byte < (Size / 8)) {
208 return (MinByte +
I) * 8;
216 unsigned BitWidth, int64_t &OffsetByte, uint64_t &OffsetBit) {
218 OffsetByte = -(AllocBefore / 8 + 1);
220 OffsetByte = -((AllocBefore + 7) / 8 + (BitWidth + 7) / 8);
221 OffsetBit = AllocBefore % 8;
225 Target.setBeforeBit(AllocBefore);
227 Target.setBeforeBytes(AllocBefore, (BitWidth + 7) / 8);
233 unsigned BitWidth, int64_t &OffsetByte, uint64_t &OffsetBit) {
235 OffsetByte = AllocAfter / 8;
237 OffsetByte = (AllocAfter + 7) / 8;
238 OffsetBit = AllocAfter % 8;
242 Target.setAfterBit(AllocAfter);
244 Target.setAfterBytes(AllocAfter, (BitWidth + 7) / 8);
280 const VTableSlot &RHS) {
281 return LHS.TypeID == RHS.TypeID && LHS.ByteOffset == RHS.ByteOffset;
310 struct VirtualCallSite {
317 unsigned *NumUnsafeUses;
328 <<
NV(
"Optimization", OptName)
329 <<
": devirtualized a call to " 330 <<
NV(
"FunctionName", TargetName));
333 void replaceAndErase(
338 emitRemark(OptName, TargetName, OREGetter);
339 CS->replaceAllUsesWith(New);
342 II->getUnwindDest()->removePredecessor(II->getParent());
344 CS->eraseFromParent();
354 struct CallSiteInfo {
359 std::vector<VirtualCallSite> CallSites;
364 bool AllCallSitesDevirted =
true;
371 bool SummaryHasTypeTestAssumeUsers =
false;
380 std::vector<FunctionSummary *> SummaryTypeCheckedLoadUsers;
381 std::vector<FunctionSummary *> SummaryTypeTestAssumeUsers;
383 bool isExported()
const {
384 return SummaryHasTypeTestAssumeUsers ||
385 !SummaryTypeCheckedLoadUsers.empty();
389 SummaryTypeCheckedLoadUsers.push_back(FS);
390 AllCallSitesDevirted =
false;
394 SummaryTypeTestAssumeUsers.push_back(FS);
395 SummaryHasTypeTestAssumeUsers =
true;
396 AllCallSitesDevirted =
false;
400 AllCallSitesDevirted =
true;
403 SummaryTypeCheckedLoadUsers.clear();
408 struct VTableSlotInfo {
415 std::map<std::vector<uint64_t>, CallSiteInfo> ConstCSInfo;
417 void addCallSite(
Value *VTable,
CallSite CS,
unsigned *NumUnsafeUses);
420 CallSiteInfo &findCallSiteInfo(
CallSite CS);
423 CallSiteInfo &VTableSlotInfo::findCallSiteInfo(
CallSite CS) {
424 std::vector<uint64_t>
Args;
426 if (!CI || CI->getBitWidth() > 64 || CS.
arg_empty())
430 if (!CI || CI->getBitWidth() > 64)
432 Args.push_back(CI->getZExtValue());
434 return ConstCSInfo[
Args];
438 unsigned *NumUnsafeUses) {
439 auto &CSI = findCallSiteInfo(CS);
440 CSI.AllCallSitesDevirted =
false;
441 CSI.CallSites.push_back({VTable, CS, NumUnsafeUses});
444 struct DevirtModule {
471 std::map<CallInst *, unsigned> NumUnsafeUsesForTypeTest;
478 : M(M), AARGetter(AARGetter), LookupDomTree(LookupDomTree),
479 ExportSummary(ExportSummary), ImportSummary(ImportSummary),
485 RemarksEnabled(areRemarksEnabled()), OREGetter(OREGetter) {
486 assert(!(ExportSummary && ImportSummary));
489 bool areRemarksEnabled();
491 void scanTypeTestUsers(
Function *TypeTestFunc);
492 void scanTypeCheckedLoadUsers(
Function *TypeCheckedLoadFunc);
494 void buildTypeIdentifierMap(
495 std::vector<VTableBits> &
Bits,
498 tryFindVirtualCallTargets(std::vector<VirtualCallTarget> &TargetsForSlot,
499 const std::set<TypeMemberInfo> &TypeMemberInfos,
500 uint64_t ByteOffset);
502 void applySingleImplDevirt(VTableSlotInfo &SlotInfo,
Constant *TheFn,
506 VTableSlotInfo &SlotInfo,
509 void applyICallBranchFunnel(VTableSlotInfo &SlotInfo,
Constant *
JT,
512 VTableSlotInfo &SlotInfo,
515 bool tryEvaluateFunctionsWithArgs(
519 void applyUniformRetValOpt(CallSiteInfo &CSInfo,
StringRef FnName,
522 CallSiteInfo &CSInfo,
530 bool shouldExportConstantsAsAbsoluteSymbols();
550 void applyUniqueRetValOpt(CallSiteInfo &CSInfo,
StringRef FnName,
bool IsOne,
552 bool tryUniqueRetValOpt(
unsigned BitWidth,
554 CallSiteInfo &CSInfo,
558 void applyVirtualConstProp(CallSiteInfo &CSInfo,
StringRef FnName,
561 VTableSlotInfo &SlotInfo,
567 void importResolution(VTableSlot Slot, VTableSlotInfo &SlotInfo);
571 void removeRedundantTypeTests();
587 std::set<GlobalValue::GUID> &ExportedGUIDs;
591 std::map<ValueInfo, std::vector<VTableSlotSummary>> &LocalWPDTargetsMap;
597 std::set<GlobalValue::GUID> &ExportedGUIDs,
598 std::map<
ValueInfo, std::vector<VTableSlotSummary>> &LocalWPDTargetsMap)
599 : ExportSummary(ExportSummary), ExportedGUIDs(ExportedGUIDs),
600 LocalWPDTargetsMap(LocalWPDTargetsMap) {}
602 bool tryFindVirtualCallTargets(std::vector<ValueInfo> &TargetsForSlot,
604 uint64_t ByteOffset);
608 VTableSlotInfo &SlotInfo,
610 std::set<ValueInfo> &DevirtTargets);
615 struct WholeProgramDevirt :
public ModulePass {
618 bool UseCommandLine =
false;
623 WholeProgramDevirt() :
ModulePass(ID), UseCommandLine(
true) {
629 :
ModulePass(ID), ExportSummary(ExportSummary),
630 ImportSummary(ImportSummary) {
634 bool runOnModule(
Module &M)
override {
643 std::unique_ptr<OptimizationRemarkEmitter> ORE;
645 ORE = std::make_unique<OptimizationRemarkEmitter>(
F);
650 return this->getAnalysis<DominatorTreeWrapperPass>(
F).getDomTree();
654 return DevirtModule::runForTesting(M,
LegacyAARGetter(*
this), OREGetter,
657 return DevirtModule(M,
LegacyAARGetter(*
this), OREGetter, LookupDomTree,
658 ExportSummary, ImportSummary)
672 "Whole program devirtualization",
false,
false)
678 char WholeProgramDevirt::
ID = 0;
683 return new WholeProgramDevirt(ExportSummary, ImportSummary);
698 if (!DevirtModule(M, AARGetter, OREGetter, LookupDomTree, ExportSummary,
708 std::map<
ValueInfo, std::vector<VTableSlotSummary>> &LocalWPDTargetsMap) {
709 DevirtIndex(Summary, ExportedGUIDs, LocalWPDTargetsMap).run();
715 std::map<
ValueInfo, std::vector<VTableSlotSummary>> &LocalWPDTargetsMap) {
716 for (
auto &
T : LocalWPDTargetsMap) {
719 assert(
VI.getSummaryList().size() == 1 &&
720 "Devirt of local target has more than one copy");
721 auto &S =
VI.getSummaryList()[0];
722 if (!isExported(S->modulePath(),
VI))
726 for (
auto &SlotSummary :
T.second) {
729 auto WPDRes = TIdSum->WPDRes.find(SlotSummary.ByteOffset);
730 assert(WPDRes != TIdSum->WPDRes.end());
732 WPDRes->second.SingleImplName,
740 bool DevirtModule::runForTesting(
751 auto ReadSummaryFile =
754 yaml::Input
In(ReadSummaryFile->getBuffer());
761 M, AARGetter, OREGetter, LookupDomTree,
773 yaml::Output Out(OS);
780 void DevirtModule::buildTypeIdentifierMap(
781 std::vector<VTableBits> &
Bits,
788 GV.getMetadata(LLVMContext::MD_type, Types);
789 if (GV.isDeclaration() || Types.
empty())
795 Bits.back().GV = &GV;
796 Bits.back().ObjectSize =
798 BitsPtr = &Bits.back();
806 cast<ConstantAsMetadata>(
Type->getOperand(0))->getValue())
809 TypeIdMap[
TypeID].insert({BitsPtr, Offset});
814 bool DevirtModule::tryFindVirtualCallTargets(
815 std::vector<VirtualCallTarget> &TargetsForSlot,
816 const std::set<TypeMemberInfo> &TypeMemberInfos, uint64_t ByteOffset) {
832 if (
Fn->
getName() ==
"__cxa_pure_virtual")
835 TargetsForSlot.push_back({
Fn, &
TM});
839 return !TargetsForSlot.
empty();
842 bool DevirtIndex::tryFindVirtualCallTargets(
844 uint64_t ByteOffset) {
859 bool LocalFound =
false;
860 for (
auto &S :
P.VTableVI.getSummaryList()) {
867 VS = cast<GlobalVarSummary>(S->getBaseObject());
872 if (VTP.VTableOffset !=
P.AddressPointOffset + ByteOffset)
875 TargetsForSlot.push_back(VTP.FuncVI);
880 return !TargetsForSlot.empty();
883 void DevirtModule::applySingleImplDevirt(VTableSlotInfo &SlotInfo,
884 Constant *TheFn,
bool &IsExported) {
885 auto Apply = [&](CallSiteInfo &CSInfo) {
886 for (
auto &&VCallSite : CSInfo.CallSites) {
888 VCallSite.emitRemark(
"single-impl",
891 TheFn, VCallSite.CS.getCalledValue()->
getType()));
893 if (VCallSite.NumUnsafeUses)
894 --*VCallSite.NumUnsafeUses;
896 if (CSInfo.isExported())
900 Apply(SlotInfo.CSInfo);
901 for (
auto &
P : SlotInfo.ConstCSInfo)
914 bool IsExported =
false;
917 auto AddCalls = [&](CallSiteInfo &CSInfo) {
918 for (
auto *
FS : CSInfo.SummaryTypeCheckedLoadUsers) {
919 FS->addCall({Callee, CI});
920 IsExported |= S->modulePath() !=
FS->modulePath();
922 for (
auto *
FS : CSInfo.SummaryTypeTestAssumeUsers) {
923 FS->addCall({Callee, CI});
924 IsExported |= S->modulePath() !=
FS->modulePath();
928 for (
auto &
P : SlotInfo.ConstCSInfo)
933 bool DevirtModule::trySingleImplDevirt(
939 Function *TheFn = TargetsForSlot[0].Fn;
940 for (
auto &&
Target : TargetsForSlot)
946 TargetsForSlot[0].WasDevirt =
true;
948 bool IsExported =
false;
949 applySingleImplDevirt(SlotInfo, TheFn, IsExported);
957 std::string NewName = (TheFn->
getName() +
"$merged").str();
967 if (GO.getComdat() ==
C)
989 VTableSlotInfo &SlotInfo,
991 std::set<ValueInfo> &DevirtTargets) {
994 auto TheFn = TargetsForSlot[0];
995 for (
auto &&
Target : TargetsForSlot)
1000 auto Size = TheFn.getSummaryList().size();
1006 for (
auto &S : TheFn.getSummaryList())
1012 DevirtTargets.insert(TheFn);
1014 auto &S = TheFn.getSummaryList()[0];
1015 bool IsExported =
AddCalls(SlotInfo, TheFn);
1017 ExportedGUIDs.insert(TheFn.getGUID());
1028 TheFn.name(), ExportSummary.
getModuleHash(S->modulePath()));
1030 LocalWPDTargetsMap[TheFn].push_back(SlotSummary);
1044 void DevirtModule::tryICallBranchFunnel(
1054 bool HasNonDevirt = !SlotInfo.CSInfo.AllCallSitesDevirted;
1056 for (
auto &
P : SlotInfo.ConstCSInfo)
1057 if (!
P.second.AllCallSitesDevirted) {
1058 HasNonDevirt =
true;
1068 if (isa<MDString>(Slot.TypeID)) {
1071 getGlobalName(Slot, {},
"branch_funnel"), &M);
1076 "branch_funnel", &M);
1080 std::vector<Value *> JTArgs;
1081 JTArgs.push_back(JT->arg_begin());
1082 for (
auto &
T : TargetsForSlot) {
1083 JTArgs.push_back(getMemberAddr(
T.TM));
1084 JTArgs.push_back(
T.Fn);
1095 bool IsExported =
false;
1096 applyICallBranchFunnel(SlotInfo, JT, IsExported);
1101 void DevirtModule::applyICallBranchFunnel(VTableSlotInfo &SlotInfo,
1103 auto Apply = [&](CallSiteInfo &CSInfo) {
1104 if (CSInfo.isExported())
1106 if (CSInfo.AllCallSitesDevirted)
1108 for (
auto &&VCallSite : CSInfo.CallSites) {
1118 VCallSite.emitRemark(
"branch-funnel",
1123 std::vector<Type *> NewArgs;
1124 NewArgs.push_back(Int8PtrTy);
1126 NewArgs.push_back(
T);
1133 std::vector<Value *>
Args;
1134 Args.push_back(IRB.CreateBitCast(VCallSite.VTable, Int8PtrTy));
1140 NewCS = IRB.CreateCall(NewFT, IRB.CreateBitCast(JT, NewFTPtr),
Args);
1142 NewCS = IRB.CreateInvoke(
1143 NewFT, IRB.CreateBitCast(JT, NewFTPtr),
1149 std::vector<AttributeSet> NewArgAttrs;
1160 CS->eraseFromParent();
1163 if (VCallSite.NumUnsafeUses)
1164 --*VCallSite.NumUnsafeUses;
1171 Apply(SlotInfo.CSInfo);
1172 for (
auto &
P : SlotInfo.ConstCSInfo)
1176 bool DevirtModule::tryEvaluateFunctionsWithArgs(
1182 if (
Target.Fn->arg_size() != Args.
size() + 1)
1189 for (
unsigned I = 0;
I != Args.
size(); ++
I) {
1191 Target.Fn->getFunctionType()->getParamType(
I + 1));
1198 if (!Eval.EvaluateFunction(
Target.Fn, RetVal, EvalArgs) ||
1199 !isa<ConstantInt>(
RetVal))
1201 Target.RetVal = cast<ConstantInt>(
RetVal)->getZExtValue();
1206 void DevirtModule::applyUniformRetValOpt(CallSiteInfo &CSInfo,
StringRef FnName,
1207 uint64_t TheRetVal) {
1208 for (
auto Call : CSInfo.CallSites)
1209 Call.replaceAndErase(
1210 "uniform-ret-val", FnName, RemarksEnabled, OREGetter,
1212 CSInfo.markDevirt();
1215 bool DevirtModule::tryUniformRetValOpt(
1220 uint64_t TheRetVal = TargetsForSlot[0].RetVal;
1222 if (
Target.RetVal != TheRetVal)
1225 if (CSInfo.isExported()) {
1227 Res->
Info = TheRetVal;
1230 applyUniformRetValOpt(CSInfo, TargetsForSlot[0].
Fn->
getName(), TheRetVal);
1232 for (
auto &&
Target : TargetsForSlot)
1237 std::string DevirtModule::getGlobalName(VTableSlot Slot,
1240 std::string FullName =
"__typeid_";
1242 OS << cast<MDString>(Slot.TypeID)->getString() <<
'_' << Slot.ByteOffset;
1243 for (uint64_t
Arg : Args)
1249 bool DevirtModule::shouldExportConstantsAsAbsoluteSymbols() {
1257 getGlobalName(Slot, Args, Name), C, &M);
1264 if (shouldExportConstantsAsAbsoluteSymbols()) {
1286 if (!shouldExportConstantsAsAbsoluteSymbols())
1289 Constant *C = importGlobal(Slot, Args, Name);
1295 if (GV->hasMetadata(LLVMContext::MD_absolute_symbol))
1298 auto SetAbsRange = [&](uint64_t Min, uint64_t Max) {
1301 GV->setMetadata(LLVMContext::MD_absolute_symbol,
1305 if (AbsWidth == IntPtrTy->getBitWidth())
1306 SetAbsRange(~0ull, ~0ull);
1308 SetAbsRange(0, 1ull << AbsWidth);
1312 void DevirtModule::applyUniqueRetValOpt(CallSiteInfo &CSInfo,
StringRef FnName,
1315 for (
auto &&Call : CSInfo.CallSites) {
1319 B.CreateBitCast(Call.VTable, Int8PtrTy), UniqueMemberAddr);
1320 Cmp =
B.CreateZExt(Cmp, Call.CS->getType());
1321 Call.replaceAndErase(
"unique-ret-val", FnName, RemarksEnabled, OREGetter,
1324 CSInfo.markDevirt();
1333 bool DevirtModule::tryUniqueRetValOpt(
1338 auto tryUniqueRetValOptFor = [&](
bool IsOne) {
1341 if (
Target.RetVal == (IsOne ? 1 : 0)) {
1344 UniqueMember =
Target.TM;
1352 Constant *UniqueMemberAddr = getMemberAddr(UniqueMember);
1353 if (CSInfo.isExported()) {
1357 exportGlobal(Slot, Args,
"unique_member", UniqueMemberAddr);
1361 applyUniqueRetValOpt(CSInfo, TargetsForSlot[0].
Fn->
getName(), IsOne,
1366 for (
auto &&
Target : TargetsForSlot)
1372 if (BitWidth == 1) {
1373 if (tryUniqueRetValOptFor(
true))
1375 if (tryUniqueRetValOptFor(
false))
1381 void DevirtModule::applyVirtualConstProp(CallSiteInfo &CSInfo,
StringRef FnName,
1383 for (
auto Call : CSInfo.CallSites) {
1384 auto *RetType = cast<IntegerType>(Call.CS.getType());
1387 B.CreateGEP(Int8Ty,
B.CreateBitCast(Call.VTable, Int8PtrTy), Byte);
1388 if (RetType->getBitWidth() == 1) {
1389 Value *Bits =
B.CreateLoad(Int8Ty, Addr);
1390 Value *BitsAndBit =
B.CreateAnd(Bits, Bit);
1392 Call.replaceAndErase(
"virtual-const-prop-1-bit", FnName, RemarksEnabled,
1393 OREGetter, IsBitSet);
1395 Value *ValAddr =
B.CreateBitCast(Addr, RetType->getPointerTo());
1396 Value *Val =
B.CreateLoad(RetType, ValAddr);
1397 Call.replaceAndErase(
"virtual-const-prop", FnName, RemarksEnabled,
1401 CSInfo.markDevirt();
1404 bool DevirtModule::tryVirtualConstProp(
1411 unsigned BitWidth = RetType->getBitWidth();
1426 if (
Target.Fn->isDeclaration() ||
1429 Target.Fn->arg_empty() || !
Target.Fn->arg_begin()->use_empty() ||
1430 Target.Fn->getReturnType() != RetType)
1434 for (
auto &&CSByConstantArg : SlotInfo.ConstCSInfo) {
1435 if (!tryEvaluateFunctionsWithArgs(TargetsForSlot, CSByConstantArg.first))
1440 ResByArg = &Res->
ResByArg[CSByConstantArg.first];
1442 if (tryUniformRetValOpt(TargetsForSlot, CSByConstantArg.second, ResByArg))
1445 if (tryUniqueRetValOpt(BitWidth, TargetsForSlot, CSByConstantArg.second,
1446 ResByArg, Slot, CSByConstantArg.first))
1451 uint64_t AllocBefore =
1453 uint64_t AllocAfter =
1458 uint64_t TotalPaddingBefore = 0, TotalPaddingAfter = 0;
1459 for (
auto &&
Target : TargetsForSlot) {
1460 TotalPaddingBefore += std::max<int64_t>(
1461 (AllocBefore + 7) / 8 -
Target.allocatedBeforeBytes() - 1, 0);
1462 TotalPaddingAfter += std::max<int64_t>(
1463 (AllocAfter + 7) / 8 -
Target.allocatedAfterBytes() - 1, 0);
1468 if (std::min(TotalPaddingBefore, TotalPaddingAfter) > 128)
1475 if (TotalPaddingBefore <= TotalPaddingAfter)
1483 for (
auto &&
Target : TargetsForSlot)
1487 if (CSByConstantArg.second.isExported()) {
1489 exportConstant(Slot, CSByConstantArg.first,
"byte", OffsetByte,
1491 exportConstant(Slot, CSByConstantArg.first,
"bit", 1ULL << OffsetBit,
1498 applyVirtualConstProp(CSByConstantArg.second,
1499 TargetsForSlot[0].Fn->
getName(), ByteConst, BitConst);
1542 NewInit->getType(), NewGV,
1547 Alias->takeName(B.
GV);
1553 bool DevirtModule::areRemarksEnabled() {
1554 const auto &FL = M.getFunctionList();
1565 void DevirtModule::scanTypeTestUsers(
Function *TypeTestFunc) {
1582 auto &DT = LookupDomTree(*CI->getFunction());
1586 if (!Assumes.
empty()) {
1588 cast<MetadataAsValue>(CI->getArgOperand(1))->getMetadata();
1596 if (SeenCallSites.
insert(Call.CS).second)
1597 CallSlots[{TypeId, Call.Offset}].addCallSite(Ptr, Call.CS,
nullptr);
1602 for (
auto Assume : Assumes)
1603 Assume->eraseFromParent();
1606 if (CI->use_empty())
1607 CI->eraseFromParent();
1611 void DevirtModule::scanTypeCheckedLoadUsers(
Function *TypeCheckedLoadFunc) {
1614 for (
auto I = TypeCheckedLoadFunc->
use_begin(),
1615 E = TypeCheckedLoadFunc->
use_end();
1622 Value *Ptr = CI->getArgOperand(0);
1624 Value *TypeIdValue = CI->getArgOperand(2);
1625 Metadata *TypeId = cast<MetadataAsValue>(TypeIdValue)->getMetadata();
1630 bool HasNonCallUses =
false;
1631 auto &DT = LookupDomTree(*CI->getFunction());
1633 HasNonCallUses, CI, DT);
1642 (LoadedPtrs.
size() == 1 && !HasNonCallUses) ? LoadedPtrs[0] : CI);
1649 LoadedPtr->eraseFromParent();
1653 IRBuilder<> CallB((Preds.
size() == 1 && !HasNonCallUses) ? Preds[0] : CI);
1658 Pred->eraseFromParent();
1665 if (!CI->use_empty()) {
1668 Pair = B.CreateInsertValue(Pair, LoadedValue, {0});
1669 Pair = B.CreateInsertValue(Pair, TypeTestCall, {1});
1674 auto &NumUnsafeUses = NumUnsafeUsesForTypeTest[TypeTestCall];
1675 NumUnsafeUses = DevirtCalls.
size();
1683 CallSlots[{TypeId, Call.Offset}].addCallSite(Ptr, Call.CS,
1687 CI->eraseFromParent();
1691 void DevirtModule::importResolution(VTableSlot Slot, VTableSlotInfo &SlotInfo) {
1696 ImportSummary->getTypeIdSummary(TypeId->getString());
1699 auto ResI = TidSummary->
WPDRes.find(Slot.ByteOffset);
1700 if (ResI == TidSummary->
WPDRes.end())
1714 bool IsExported =
false;
1715 applySingleImplDevirt(SlotInfo, SingleImpl, IsExported);
1719 for (
auto &CSByConstantArg : SlotInfo.ConstCSInfo) {
1720 auto I = Res.
ResByArg.find(CSByConstantArg.first);
1723 auto &ResByArg =
I->second;
1728 switch (ResByArg.TheKind) {
1730 applyUniformRetValOpt(CSByConstantArg.second,
"", ResByArg.Info);
1734 importGlobal(Slot, CSByConstantArg.first,
"unique_member");
1735 applyUniqueRetValOpt(CSByConstantArg.second,
"", ResByArg.Info,
1740 Constant *Byte = importConstant(Slot, CSByConstantArg.first,
"byte",
1742 Constant *Bit = importConstant(Slot, CSByConstantArg.first,
"bit", Int8Ty,
1744 applyVirtualConstProp(CSByConstantArg.second,
"", Byte, Bit);
1756 M.getOrInsertFunction(getGlobalName(Slot, {},
"branch_funnel"),
1759 bool IsExported =
false;
1760 applyICallBranchFunnel(SlotInfo, JT, IsExported);
1765 void DevirtModule::removeRedundantTypeTests() {
1767 for (
auto &&U : NumUnsafeUsesForTypeTest) {
1768 if (U.second == 0) {
1770 U.first->eraseFromParent();
1775 bool DevirtModule::run() {
1781 (ImportSummary && ImportSummary->partiallySplitLTOUnits()))
1793 if (!ExportSummary &&
1794 (!TypeTestFunc || TypeTestFunc->
use_empty() || !AssumeFunc ||
1796 (!TypeCheckedLoadFunc || TypeCheckedLoadFunc->
use_empty()))
1799 if (TypeTestFunc && AssumeFunc)
1800 scanTypeTestUsers(TypeTestFunc);
1802 if (TypeCheckedLoadFunc)
1803 scanTypeCheckedLoadUsers(TypeCheckedLoadFunc);
1805 if (ImportSummary) {
1806 for (
auto &S : CallSlots)
1807 importResolution(S.first, S.second);
1809 removeRedundantTypeTests();
1817 std::vector<VTableBits>
Bits;
1819 buildTypeIdentifierMap(Bits, TypeIdMap);
1820 if (TypeIdMap.
empty())
1824 if (ExportSummary) {
1826 for (
auto &
P : TypeIdMap) {
1827 if (
auto *TypeId = dyn_cast<MDString>(
P.first))
1832 for (
auto &
P : *ExportSummary) {
1833 for (
auto &S :
P.second.SummaryList) {
1839 for (
Metadata *MD : MetadataByGUID[VF.GUID]) {
1840 CallSlots[{MD, VF.Offset}].CSInfo.addSummaryTypeTestAssumeUser(
FS);
1844 for (
Metadata *MD : MetadataByGUID[VF.GUID]) {
1845 CallSlots[{MD, VF.Offset}].CSInfo.addSummaryTypeCheckedLoadUser(
FS);
1849 FS->type_test_assume_const_vcalls()) {
1850 for (
Metadata *MD : MetadataByGUID[
VC.VFunc.GUID]) {
1851 CallSlots[{MD,
VC.VFunc.Offset}]
1852 .ConstCSInfo[
VC.Args]
1853 .addSummaryTypeTestAssumeUser(
FS);
1857 FS->type_checked_load_const_vcalls()) {
1858 for (
Metadata *MD : MetadataByGUID[
VC.VFunc.GUID]) {
1859 CallSlots[{MD,
VC.VFunc.Offset}]
1860 .ConstCSInfo[
VC.Args]
1861 .addSummaryTypeCheckedLoadUser(
FS);
1869 bool DidVirtualConstProp =
false;
1870 std::map<std::string, Function*> DevirtTargets;
1871 for (
auto &S : CallSlots) {
1875 std::vector<VirtualCallTarget> TargetsForSlot;
1876 if (tryFindVirtualCallTargets(TargetsForSlot, TypeIdMap[S.first.TypeID],
1877 S.first.ByteOffset)) {
1879 if (ExportSummary && isa<MDString>(S.first.TypeID))
1880 Res = &ExportSummary
1882 cast<MDString>(S.first.TypeID)->getString())
1883 .WPDRes[S.first.ByteOffset];
1885 if (!trySingleImplDevirt(ExportSummary, TargetsForSlot, S.second, Res)) {
1886 DidVirtualConstProp |=
1887 tryVirtualConstProp(TargetsForSlot, S.second, Res, S.first);
1889 tryICallBranchFunnel(TargetsForSlot, S.second, Res, S.first);
1894 for (
const auto &
T : TargetsForSlot)
1896 DevirtTargets[
T.Fn->getName()] =
T.Fn;
1903 if (ExportSummary && isa<MDString>(S.first.TypeID)) {
1906 for (
auto FS : S.second.CSInfo.SummaryTypeCheckedLoadUsers)
1907 FS->addTypeTest(GUID);
1908 for (
auto &CCS : S.second.ConstCSInfo)
1909 for (
auto FS : CCS.second.SummaryTypeCheckedLoadUsers)
1910 FS->addTypeTest(GUID);
1914 if (RemarksEnabled) {
1916 for (
const auto &DT : DevirtTargets) {
1919 using namespace ore;
1922 <<
NV(
"FunctionName", DT.first));
1926 removeRedundantTypeTests();
1930 if (DidVirtualConstProp)
1938 GV.eraseMetadata(LLVMContext::MD_vcall_visibility);
1943 void DevirtIndex::run() {
1953 for (
auto &
P : ExportSummary) {
1954 for (
auto &S :
P.second.SummaryList) {
1960 for (
StringRef Name : NameByGUID[VF.GUID]) {
1961 CallSlots[{
Name, VF.Offset}].CSInfo.addSummaryTypeTestAssumeUser(
FS);
1965 for (
StringRef Name : NameByGUID[VF.GUID]) {
1966 CallSlots[{
Name, VF.Offset}].CSInfo.addSummaryTypeCheckedLoadUser(
FS);
1970 FS->type_test_assume_const_vcalls()) {
1971 for (
StringRef Name : NameByGUID[
VC.VFunc.GUID]) {
1972 CallSlots[{
Name,
VC.VFunc.Offset}]
1973 .ConstCSInfo[
VC.Args]
1974 .addSummaryTypeTestAssumeUser(
FS);
1978 FS->type_checked_load_const_vcalls()) {
1979 for (
StringRef Name : NameByGUID[
VC.VFunc.GUID]) {
1980 CallSlots[{
Name,
VC.VFunc.Offset}]
1981 .ConstCSInfo[
VC.Args]
1982 .addSummaryTypeCheckedLoadUser(
FS);
1988 std::set<ValueInfo> DevirtTargets;
1990 for (
auto &S : CallSlots) {
1994 std::vector<ValueInfo> TargetsForSlot;
1995 auto TidSummary = ExportSummary.getTypeIdCompatibleVtableSummary(S.first.TypeID);
1997 if (tryFindVirtualCallTargets(TargetsForSlot, *TidSummary,
1998 S.first.ByteOffset)) {
2000 &ExportSummary.getOrInsertTypeIdSummary(S.first.TypeID)
2001 .WPDRes[S.first.ByteOffset];
2003 if (!trySingleImplDevirt(TargetsForSlot, S.first, S.second, Res,
2012 for (
const auto &DT : DevirtTargets)
2013 errs() <<
"Devirtualized call to " << DT <<
"\n";
void setVisibility(VisibilityTypes V)
StringRef getSection() const
Get the custom section of this global if it has one.
unsigned getAlignment() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool hasLocalLinkage() const
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
DiagnosticInfoOptimizationBase::Argument NV
Whole program devirtualization
static unsigned getHashValue(const VTableSlot &I)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
A Module instance is used to store all the information related to an LLVM module. ...
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant *> IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst *> &Assumes, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.test, find all devirtualizable call sites based on the call ...
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Global variable summary information to aid decisions and implementation of importing.
VirtualCallTarget(Function *Fn, const TypeMemberInfo *TM)
Implements a dense probed hash-table based set.
void push_back(const T &Elt)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Helper for check-and-exit error handling.
void initializeWholeProgramDevirtPass(PassRegistry &)
This class represents a function call, abstracting a target machine's calling convention.
An immutable pass that tracks lazily created AssumptionCache objects.
An efficient, type-erasing, non-owning reference to a callable.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
uint64_t Info
Additional information for the resolution:
Like Internal, but omit from symbol table.
void setCallingConv(CallingConv::ID CC)
Set the calling convention of the call.
Externally visible function.
const std::map< std::string, TypeIdCompatibleVtableInfo > & typeIdCompatibleVtableMap() const
static cl::opt< unsigned > ClThreshold("wholeprogramdevirt-branch-funnel-threshold", cl::Hidden, cl::init(10), cl::ZeroOrMore, cl::desc("Maximum number of call targets per " "call site to enable branch funnels"))
This class implements a map that also provides access to all stored values in a deterministic order...
Analysis pass which computes a DominatorTree.
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
static IntegerType * getInt64Ty(LLVMContext &C)
MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR)
Returns the memory access properties of this copy of the function.
Virtual constant propagation.
const TypeIdSummary * getTypeIdSummary(StringRef TypeId) const
This returns either a pointer to the type id summary (if present in the summary map) or null (if not ...
void setAfterReturnValues(MutableArrayRef< VirtualCallTarget > Targets, uint64_t AllocAfter, unsigned BitWidth, int64_t &OffsetByte, uint64_t &OffsetBit)
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
static bool AddCalls(VTableSlotInfo &SlotInfo, const ValueInfo &Callee)
static Optional< bool > isBigEndian(const ArrayRef< int64_t > ByteOffsets, int64_t FirstOffset)
FunctionType * getFunctionType() const
static bool isLocalLinkage(LinkageTypes Linkage)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool partiallySplitLTOUnits() const
CallingConv::ID getCallingConv() const
Get the calling convention of the call.
Export information to summary.
const char * getName() const
getName - Get the target name.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
void setBeforeReturnValues(MutableArrayRef< VirtualCallTarget > Targets, uint64_t AllocBefore, unsigned BitWidth, int64_t &OffsetByte, uint64_t &OffsetBit)
unsigned countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
void findDevirtualizableCallsForTypeCheckedLoad(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< Instruction *> &LoadedPtrs, SmallVectorImpl< Instruction *> &Preds, bool &HasNonCallUses, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.checked.load, find all devirtualizable call sites based on t...
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module...
LLVMContext & getContext() const
Get the global data context.
The returned value is undefined.
void updateIndexWPDForExports(ModuleSummaryIndex &Summary, function_ref< bool(StringRef, ValueInfo)> isExported, std::map< ValueInfo, std::vector< VTableSlotSummary >> &LocalWPDTargetsMap)
Call after cross-module importing to update the recorded single impl devirt target names for any loca...
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
static bool isEqual(const VTableSlotSummary &LHS, const VTableSlotSummary &RHS)
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local...
This class is a functor to be used in legacy module or SCC passes for computing AA results for a func...
TypeID
Definitions of all of the base types for the Type system.
No attributes have been set.
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
void setName(const Twine &Name)
Change the name of the value.
Type * getType() const
Return the type of the instruction that generated this call site.
static bool isEqual(const VTableSlot &LHS, const VTableSlot &RHS)
enum llvm::WholeProgramDevirtResolution::Kind TheKind
InstrTy * getInstruction() const
Uniform return value optimization.
static VTableSlot getTombstoneKey()
Class to represent function types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
Type * getType() const
All values are typed, get the type of this value.
AttributeSet getParamAttributes(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
LinkageTypes getLinkage() const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
The file should be opened in text mode on platforms that make this distinction.
Class to represent pointers.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
initializer< Ty > init(const Ty &Val)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
VisibilityTypes getVisibility() const
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
void runWholeProgramDevirtOnIndex(ModuleSummaryIndex &Summary, std::set< GlobalValue::GUID > &ExportedGUIDs, std::map< ValueInfo, std::vector< VTableSlotSummary >> &LocalWPDTargetsMap)
Perform index-based whole program devirtualization on the Summary index.
unsigned getNumArgOperands() const
Import information from summary.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
A call site that could be devirtualized.
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
This file contains the declarations for the subclasses of Constant, which represent the different fla...
AttributeList getAttributes() const
Get the parameter attributes of the call.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
A manager for alias analyses.
std::pair< iterator, bool > insert(const ValueT &V)
Class to accumulate and hold information about a callee.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
INITIALIZE_PASS_BEGIN(WholeProgramDevirt, "wholeprogramdevirt", "Whole program devirtualization", false, false) INITIALIZE_PASS_END(WholeProgramDevirt
ArrayRef< Type * > params() const
Expected< T > errorOrToExpected(ErrorOr< T > &&EO)
Convert an ErrorOr<T> to an Expected<T>.
Represent the analysis usage information of a pass.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
static Type * getVoidTy(LLVMContext &C)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void reserve(size_type NumEntries)
Grow the densemap so that it can contain at least NumEntries items before resizing again...
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
LLVM_NODISCARD bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Class to represent integer types.
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Constant * stripPointerCasts() const
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
Triple - Helper class for working with autoconf configuration names.
An "identifier" for a virtual function.
Struct that holds a reference to a particular GUID in a global value summary.
This class evaluates LLVM IR, producing the Constant representing each SSA instruction.
Value * CreateGEP(Value *Ptr, ArrayRef< Value *> IdxList, const Twine &Name="")
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
This is the shared class of boolean and integer constants.
void setSelectionKind(SelectionKind Val)
static VTableSlotSummary getTombstoneKey()
Align max(MaybeAlign Lhs, Align Rhs)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Single implementation devirtualization.
static bool isAvailableExternallyLinkage(LinkageTypes Linkage)
Type * getReturnType() const
unsigned getProgramAddressSpace() const
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 BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
ArrayRef< VirtFuncOffset > vTableFuncs() const
static ConstantInt * getTrue(LLVMContext &Context)
void setLinkage(LinkageTypes LT)
std::string SingleImplName
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Target - Wrapper for Target specific information.
unsigned getNumAttrSets() const
A specification for a virtual function call with all constant integer arguments.
BBTy * getParent() const
Get the basic block containing the call site.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array...
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
const Comdat * getComdat() const
ModulePass * createWholeProgramDevirtPass(ModuleSummaryIndex *ExportSummary, const ModuleSummaryIndex *ImportSummary)
This pass implements whole-program devirtualization using type metadata.
std::vector< uint8_t > Bytes
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
A raw_ostream that writes to a file descriptor.
static IntegerType * getInt32Ty(LLVMContext &C)
uint64_t findLowestOffset(ArrayRef< VirtualCallTarget > Targets, bool IsAfter, uint64_t Size)
LLVM_NODISCARD bool empty() const
StringRef getValueAsString() const
Return the attribute's value as a string.
StringRef getName() const
Return a constant reference to the value's name.
static VTableSlot getEmptyKey()
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
Rename collisions when linking (static functions).
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value *> Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Provides passes for computing function attributes based on interprocedural analyses.
Function summary information to aid decisions and implementation of importing.
LLVM_NODISCARD bool empty() const
static VTableSlotSummary getEmptyKey()
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
bool isCall() const
Return true if a CallInst is enclosed.
static cl::opt< bool > PrintSummaryDevirt("wholeprogramdevirt-print-index-based", cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::desc("Print index-based devirtualization messages"))
static cl::opt< PassSummaryAction > ClSummaryAction("wholeprogramdevirt-summary-action", cl::desc("What to do with the summary when running this pass"), cl::values(clEnumValN(PassSummaryAction::None, "none", "Do nothing"), clEnumValN(PassSummaryAction::Import, "import", "Import typeid resolutions from summary and globals"), clEnumValN(PassSummaryAction::Export, "export", "Export typeid resolutions to summary and globals")), cl::Hidden)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
A raw_ostream that writes to an std::string.
LLVM Value Representation.
static const Function * getParent(const Value *V)
AttributeSet getFnAttributes() const
The function attributes are returned.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
static Constant * getAnon(ArrayRef< Constant *> V, bool Packed=false)
Return an anonymous struct that has the specified elements.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
const TypeMemberInfo * TM
iterator_range< global_iterator > globals()
iterator_range< global_object_iterator > global_objects()
StringRef - Represent a constant reference to a string, i.e.
This is the interface for LLVM's primary stateless and local alias analysis.
static cl::opt< std::string > ClReadSummary("wholeprogramdevirt-read-summary", cl::desc("Read summary from given YAML file before running pass"), cl::Hidden)
static cl::opt< std::string > ClWriteSummary("wholeprogramdevirt-write-summary", cl::desc("Write summary to given YAML file after running pass"), cl::Hidden)
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
static IntegerType * getInt8Ty(LLVMContext &C)
void setSection(StringRef S)
Change the section for this global.
static unsigned getHashValue(const VTableSlotSummary &I)
Constant * getPointerAtOffset(Constant *I, uint64_t Offset, Module &M)
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
The following data structures summarize type metadata information.
ValTy * getArgOperand(unsigned i) const
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
Unique return value optimization.
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
FunTy * getCaller() const
Return the caller function for this call site.