79 #define DEBUG_TYPE "rewrite-statepoints-for-gc" 99 #ifdef EXPENSIVE_CHECKS 102 static bool ClobberNonLive =
false;
130 bool Changed =
false;
134 if (
F.isDeclaration() ||
F.empty())
163 class RewriteStatepointsForGCLegacyPass :
public ModulePass {
169 RewriteStatepointsForGCLegacyPass() :
ModulePass(ID), Impl() {
174 bool runOnModule(
Module &M)
override {
175 bool Changed =
false;
178 if (
F.isDeclaration() ||
F.empty())
187 getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F);
189 getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(
F);
190 auto &DT = getAnalysis<DominatorTreeWrapperPass>(
F).getDomTree();
219 return new RewriteStatepointsForGCLegacyPass();
223 "rewrite-statepoints-for-gc",
224 "Make relocations explicit at statepoints",
false,
false)
228 "rewrite-statepoints-for-gc",
229 "Make relocations explicit at statepoints",
false,
false)
294 "Found non-leaf call without deopt info!");
303 GCPtrLivenessData &
Data);
314 if (
auto *PT = dyn_cast<PointerType>(T))
318 return PT->getAddressSpace() == 1;
332 if (
auto VT = dyn_cast<VectorType>(T))
344 if (
VectorType *VT = dyn_cast<VectorType>(Ty))
346 if (
ArrayType *AT = dyn_cast<ArrayType>(Ty))
374 PartiallyConstructedSafepointRecord &Result) {
379 dbgs() <<
"Live Variables:\n";
380 for (
Value *V : LiveSet)
381 dbgs() <<
" " << V->getName() <<
" " << *V <<
"\n";
385 dbgs() <<
"Number live values: " << LiveSet.size() <<
"\n";
387 Result.LiveSet = LiveSet;
402 struct BaseDefiningValueResult {
408 const bool IsKnownBase;
410 BaseDefiningValueResult(
Value *BDV,
bool IsKnownBase)
411 : BDV(BDV), IsKnownBase(IsKnownBase) {
416 assert(!MustBeBase || MustBeBase == IsKnownBase);
434 static BaseDefiningValueResult
439 if (isa<Argument>(I))
441 return BaseDefiningValueResult(I,
true);
443 if (isa<Constant>(I))
449 if (isa<LoadInst>(I))
450 return BaseDefiningValueResult(I,
true);
452 if (isa<InsertElementInst>(I))
456 return BaseDefiningValueResult(I,
false);
458 if (isa<ShuffleVectorInst>(I))
464 return BaseDefiningValueResult(I,
false);
468 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(I))
473 if (
auto *BC = dyn_cast<BitCastInst>(I))
479 if (isa<CallInst>(I) || isa<InvokeInst>(
I))
480 return BaseDefiningValueResult(I,
true);
484 assert((isa<SelectInst>(I) || isa<PHINode>(I)) &&
485 "unknown vector instruction - no base found for vector element");
486 return BaseDefiningValueResult(I,
false);
495 "Illegal to ask for the base pointer of a non-pointer type");
500 if (isa<Argument>(I))
503 return BaseDefiningValueResult(I,
true);
505 if (isa<Constant>(I)) {
516 return BaseDefiningValueResult(
520 if (
CastInst *CI = dyn_cast<CastInst>(I)) {
521 Value *
Def = CI->stripPointerCasts();
524 assert(cast<PointerType>(Def->
getType())->getAddressSpace() ==
525 cast<PointerType>(CI->getType())->getAddressSpace() &&
526 "unsupported addrspacecast");
530 assert(!isa<CastInst>(Def) &&
"shouldn't find another cast here");
534 if (isa<LoadInst>(I))
536 return BaseDefiningValueResult(I,
true);
543 switch (II->getIntrinsicID()) {
547 case Intrinsic::experimental_gc_statepoint:
549 case Intrinsic::experimental_gc_relocate:
554 case Intrinsic::gcroot:
559 "interaction with the gcroot mechanism is not supported");
565 if (isa<CallInst>(I) || isa<InvokeInst>(I))
566 return BaseDefiningValueResult(I,
true);
570 assert(!isa<LandingPadInst>(I) &&
"Landing Pad is unimplemented");
572 if (isa<AtomicCmpXchgInst>(I))
576 return BaseDefiningValueResult(I,
true);
578 assert(!isa<AtomicRMWInst>(I) &&
"Xchg handled above, all others are " 579 "binary ops which don't apply to pointers");
584 if (isa<ExtractValueInst>(I))
585 return BaseDefiningValueResult(I,
true);
589 assert(!isa<InsertValueInst>(I) &&
590 "Base pointer for a struct is meaningless");
596 if (isa<ExtractElementInst>(I))
600 return BaseDefiningValueResult(I,
false);
606 assert((isa<SelectInst>(I) || isa<PHINode>(I)) &&
607 "missing instruction case in findBaseDefiningValing");
608 return BaseDefiningValueResult(I,
false);
613 Value *&Cached = Cache[
I];
619 assert(Cache[I] !=
nullptr);
627 auto Found = Cache.find(Def);
628 if (Found != Cache.end()) {
630 return Found->second;
639 if (!isa<PHINode>(V) && !isa<SelectInst>(V) &&
640 !isa<ExtractElementInst>(V) && !isa<InsertElementInst>(V) &&
641 !isa<ShuffleVectorInst>(V)) {
645 if (isa<Instruction>(V) &&
646 cast<Instruction>(V)->getMetadata(
"is_base_value")) {
665 BDVState() : BaseValue(
nullptr) {}
668 : Status(Status), BaseValue(BaseValue) {
672 explicit BDVState(
Value *BaseValue) : Status(
Base), BaseValue(BaseValue) {}
674 Status getStatus()
const {
return Status; }
675 Value *getBaseValue()
const {
return BaseValue; }
677 bool isBase()
const {
return getStatus() ==
Base; }
678 bool isUnknown()
const {
return getStatus() ==
Unknown; }
679 bool isConflict()
const {
return getStatus() == Conflict; }
682 return BaseValue == Other.BaseValue && Status == Other.Status;
685 bool operator!=(
const BDVState &other)
const {
return !(*
this == other); }
694 switch (getStatus()) {
705 OS <<
" (" << getBaseValue() <<
" - " 706 << (getBaseValue() ? getBaseValue()->getName() :
"nullptr") <<
"): ";
724 switch (LHS.getStatus()) {
729 assert(LHS.getBaseValue() &&
"can't be null");
734 if (LHS.getBaseValue() == RHS.getBaseValue()) {
735 assert(LHS == RHS &&
"equality broken!");
738 return BDVState(BDVState::Conflict);
740 assert(RHS.isConflict() &&
"only three states!");
741 return BDVState(BDVState::Conflict);
743 case BDVState::Conflict:
751 static BDVState
meetBDVState(
const BDVState &LHS,
const BDVState &RHS) {
754 "Math is wrong: meet does not commute!");
791 auto isExpectedBDVType = [](
Value *BDV) {
792 return isa<PHINode>(BDV) || isa<SelectInst>(BDV) ||
793 isa<ExtractElementInst>(BDV) || isa<InsertElementInst>(BDV) ||
794 isa<ShuffleVectorInst>(BDV);
811 while (!Worklist.
empty()) {
815 auto visitIncomingValue = [&](
Value *InVal) {
821 assert(isExpectedBDVType(Base) &&
"the only non-base values " 822 "we see should be base defining values");
823 if (States.
insert(std::make_pair(Base, BDVState())).second)
826 if (
PHINode *PN = dyn_cast<PHINode>(Current)) {
827 for (
Value *InVal : PN->incoming_values())
828 visitIncomingValue(InVal);
829 }
else if (
SelectInst *
SI = dyn_cast<SelectInst>(Current)) {
830 visitIncomingValue(
SI->getTrueValue());
831 visitIncomingValue(
SI->getFalseValue());
832 }
else if (
auto *EE = dyn_cast<ExtractElementInst>(Current)) {
833 visitIncomingValue(EE->getVectorOperand());
834 }
else if (
auto *
IE = dyn_cast<InsertElementInst>(Current)) {
835 visitIncomingValue(
IE->getOperand(0));
836 visitIncomingValue(
IE->getOperand(1));
837 }
else if (
auto *SV = dyn_cast<ShuffleVectorInst>(Current)) {
838 visitIncomingValue(SV->getOperand(0));
839 visitIncomingValue(SV->getOperand(1));
849 for (
auto Pair : States) {
850 LLVM_DEBUG(
dbgs() <<
" " << Pair.second <<
" for " << *Pair.first <<
"\n");
856 auto getStateForBDV = [&](
Value *baseValue) {
858 return BDVState(baseValue);
859 auto I = States.find(baseValue);
860 assert(I != States.end() &&
"lookup failed!");
864 bool Progress =
true;
867 const size_t OldSize = States.size();
874 for (
auto Pair : States) {
875 Value *BDV = Pair.first;
880 auto getStateForInput = [&](
Value *V)
mutable {
882 return getStateForBDV(BDV);
887 NewState =
meetBDVState(NewState, getStateForInput(
SI->getTrueValue()));
890 }
else if (
PHINode *PN = dyn_cast<PHINode>(BDV)) {
891 for (
Value *Val : PN->incoming_values())
892 NewState =
meetBDVState(NewState, getStateForInput(Val));
893 }
else if (
auto *EE = dyn_cast<ExtractElementInst>(BDV)) {
897 meetBDVState(NewState, getStateForInput(EE->getVectorOperand()));
898 }
else if (
auto *
IE = dyn_cast<InsertElementInst>(BDV)){
901 NewState =
meetBDVState(NewState, getStateForInput(
IE->getOperand(0)));
902 NewState =
meetBDVState(NewState, getStateForInput(
IE->getOperand(1)));
906 auto *SV = cast<ShuffleVectorInst>(BDV);
907 NewState =
meetBDVState(NewState, getStateForInput(SV->getOperand(0)));
908 NewState =
meetBDVState(NewState, getStateForInput(SV->getOperand(1)));
911 BDVState OldState = States[BDV];
912 if (OldState != NewState) {
914 States[BDV] = NewState;
918 assert(OldSize == States.size() &&
919 "fixed point shouldn't be adding any new nodes to state");
924 for (
auto Pair : States) {
925 LLVM_DEBUG(
dbgs() <<
" " << Pair.second <<
" for " << *Pair.first <<
"\n");
931 for (
auto Pair : States) {
933 BDVState State = Pair.second;
935 assert(!State.isUnknown() &&
"Optimistic algorithm didn't complete!");
941 if (State.isBase() && isa<ExtractElementInst>(
I) &&
942 isa<VectorType>(State.getBaseValue()->getType())) {
943 auto *EE = cast<ExtractElementInst>(
I);
948 State.getBaseValue(), EE->getIndexOperand(),
"base_ee", EE);
950 States[
I] = BDVState(BDVState::Base, BaseInst);
956 assert(!isa<InsertElementInst>(I) || State.isConflict());
958 if (!State.isConflict())
964 if (isa<PHINode>(I)) {
967 assert(NumPreds > 0 &&
"how did we reach here");
975 }
else if (
auto *EE = dyn_cast<ExtractElementInst>(I)) {
980 }
else if (
auto *
IE = dyn_cast<InsertElementInst>(I)) {
987 auto *SV = cast<ShuffleVectorInst>(
I);
994 Instruction *BaseInst = MakeBaseInstPlaceholder(I);
997 States[
I] = BDVState(BDVState::Conflict, BaseInst);
1015 assert(States.count(BDV));
1016 Base = States[BDV].getBaseValue();
1018 assert(Base &&
"Can't be null");
1028 for (
auto Pair : States) {
1030 BDVState State = Pair.second;
1033 assert(!State.isUnknown() &&
"Optimistic algorithm didn't complete!");
1034 if (!State.isConflict())
1037 if (
PHINode *BasePHI = dyn_cast<PHINode>(State.getBaseValue())) {
1038 PHINode *PN = cast<PHINode>(BDV);
1040 for (
unsigned i = 0; i < NumPHIValues; i++) {
1053 int BlockIndex = BasePHI->getBasicBlockIndex(InBB);
1054 if (BlockIndex != -1) {
1055 Value *OldBase = BasePHI->getIncomingValue(BlockIndex);
1056 BasePHI->addIncoming(OldBase, InBB);
1059 Value *
Base = getBaseForInput(InVal,
nullptr);
1067 "Sanity -- findBaseOrBDV should be pure!");
1076 BasePHI->addIncoming(Base, InBB);
1078 assert(BasePHI->getNumIncomingValues() == NumPHIValues);
1080 dyn_cast<SelectInst>(State.getBaseValue())) {
1085 BaseSI->setTrueValue(getBaseForInput(SI->
getTrueValue(), BaseSI));
1086 BaseSI->setFalseValue(getBaseForInput(SI->
getFalseValue(), BaseSI));
1087 }
else if (
auto *BaseEE =
1088 dyn_cast<ExtractElementInst>(State.getBaseValue())) {
1089 Value *InVal = cast<ExtractElementInst>(BDV)->getVectorOperand();
1092 BaseEE->setOperand(0, getBaseForInput(InVal, BaseEE));
1093 }
else if (
auto *BaseIE = dyn_cast<InsertElementInst>(State.getBaseValue())){
1094 auto *BdvIE = cast<InsertElementInst>(BDV);
1095 auto UpdateOperand = [&](
int OperandIdx) {
1096 Value *InVal = BdvIE->getOperand(OperandIdx);
1097 Value *
Base = getBaseForInput(InVal, BaseIE);
1098 BaseIE->setOperand(OperandIdx, Base);
1103 auto *BaseSV = cast<ShuffleVectorInst>(State.getBaseValue());
1104 auto *BdvSV = cast<ShuffleVectorInst>(BDV);
1105 auto UpdateOperand = [&](
int OperandIdx) {
1106 Value *InVal = BdvSV->getOperand(OperandIdx);
1107 Value *
Base = getBaseForInput(InVal, BaseSV);
1108 BaseSV->setOperand(OperandIdx, Base);
1118 for (
auto Pair : States) {
1119 auto *BDV = Pair.first;
1120 Value *
Base = Pair.second.getBaseValue();
1125 dbgs() <<
"Updating base value cache" 1126 <<
" for: " << BDV->getName() <<
" from: " 1127 << (Cache.count(BDV) ? Cache[BDV]->getName().str() :
"none")
1128 <<
" to: " << Base->
getName() <<
"\n");
1130 if (Cache.count(BDV)) {
1132 "must be something we 'know' is a base pointer");
1136 "base relation should be stable");
1140 assert(Cache.count(Def));
1163 for (
Value *ptr : live) {
1165 assert(base &&
"failed to find base pointer");
1166 PointerToBase[ptr] = base;
1167 assert((!isa<Instruction>(base) || !isa<Instruction>(ptr) ||
1168 DT->
dominates(cast<Instruction>(base)->getParent(),
1169 cast<Instruction>(ptr)->
getParent())) &&
1170 "The base we found better dominate the derived pointer");
1178 PartiallyConstructedSafepointRecord &result) {
1183 errs() <<
"Base Pairs (w/o Relocation):\n";
1184 for (
auto &Pair : PointerToBase) {
1185 errs() <<
" derived ";
1186 Pair.first->printAsOperand(
errs(),
false);
1188 Pair.second->printAsOperand(
errs(),
false);
1193 result.PointerToBase = PointerToBase;
1200 PartiallyConstructedSafepointRecord &result);
1207 GCPtrLivenessData RevisedLivenessData;
1209 for (
size_t i = 0; i < records.
size(); i++) {
1210 struct PartiallyConstructedSafepointRecord &
info = records[i];
1232 "All PHI nodes should have been removed!");
1270 const int LiveStart,
1274 if (LiveVariables.
empty())
1279 assert(ValIt != LiveVec.
end() &&
"Val not found in LiveVec!");
1280 size_t Index = std::distance(LiveVec.
begin(), ValIt);
1281 assert(Index < LiveVec.
size() &&
"Bug in std::find?");
1293 auto getGCRelocateDecl = [&] (
Type *Ty) {
1295 auto AS = Ty->getScalarType()->getPointerAddressSpace();
1297 if (
auto *VT = dyn_cast<VectorType>(Ty))
1308 for (
unsigned i = 0; i < LiveVariables.
size(); i++) {
1311 Builder.
getInt32(LiveStart + FindIndex(LiveVariables, BasePtrs[i]));
1314 Type *Ty = LiveVariables[i]->getType();
1315 if (!TypeToDeclMap.
count(Ty))
1316 TypeToDeclMap[Ty] = getGCRelocateDecl(Ty);
1317 Function *GCRelocateDecl = TypeToDeclMap[Ty];
1321 GCRelocateDecl, {StatepointToken, BaseIdx, LiveIdx},
1333 class DeferredReplacement {
1336 bool IsDeoptimize =
false;
1338 DeferredReplacement() =
default;
1342 assert(Old != New && Old && New &&
1343 "Cannot RAUW equal values or to / from null!");
1345 DeferredReplacement
D;
1351 static DeferredReplacement createDelete(
Instruction *ToErase) {
1352 DeferredReplacement
D;
1357 static DeferredReplacement createDeoptimizeReplacement(
Instruction *Old) {
1361 "Only way to construct a deoptimize deferred replacement");
1363 DeferredReplacement
D;
1365 D.IsDeoptimize =
true;
1370 void doReplacement() {
1374 assert(OldI != NewI &&
"Disallowed at construction?!");
1375 assert((!IsDeoptimize || !New) &&
1376 "Deoptimize intrinsics are not replaced!");
1399 const char *DeoptLowering =
"deopt-lowering";
1411 return "live-through";
1418 PartiallyConstructedSafepointRecord &Result,
1419 std::vector<DeferredReplacement> &Replacements) {
1436 if (
auto TransitionBundle =
1439 TransitionArgs = TransitionBundle->Inputs;
1445 bool IsDeoptimize =
false;
1456 if (DeoptLowering.
equals(
"live-in"))
1459 assert(DeoptLowering.
equals(
"live-through") &&
"Unsupported value!");
1463 if (
Function *F = dyn_cast<Function>(CallTarget)) {
1483 IsDeoptimize =
true;
1489 if (
auto *CI = dyn_cast<CallInst>(Call)) {
1490 CallInst *SPCall = Builder.CreateGCStatepointCall(
1491 StatepointID, NumPatchBytes, CallTarget, Flags, CallArgs,
1492 TransitionArgs, DeoptArgs, GCArgs,
"safepoint_token");
1507 assert(CI->getNextNode() &&
"Not a terminator, must have next!");
1508 Builder.SetInsertPoint(CI->getNextNode());
1509 Builder.SetCurrentDebugLocation(CI->getNextNode()->getDebugLoc());
1511 auto *II = cast<InvokeInst>(Call);
1516 InvokeInst *SPInvoke = Builder.CreateGCStatepointInvoke(
1517 StatepointID, NumPatchBytes, CallTarget, II->getNormalDest(),
1518 II->getUnwindDest(), Flags, CallArgs, TransitionArgs, DeoptArgs, GCArgs,
1519 "statepoint_token");
1532 BasicBlock *UnwindBlock = II->getUnwindDest();
1535 "can't safely insert in this block!");
1538 Builder.SetCurrentDebugLocation(II->getDebugLoc());
1542 Result.UnwindToken = ExceptionalToken;
1549 BasicBlock *NormalDest = II->getNormalDest();
1552 "can't safely insert in this block!");
1559 assert(Token &&
"Should be set in one of the above branches!");
1565 Replacements.push_back(
1566 DeferredReplacement::createDeoptimizeReplacement(Call));
1568 Token->
setName(
"statepoint_token");
1582 Replacements.emplace_back(
1583 DeferredReplacement::createRAUW(Call, GCResult));
1585 Replacements.emplace_back(DeferredReplacement::createDelete(Call));
1589 Result.StatepointToken = Token;
1603 PartiallyConstructedSafepointRecord &Result,
1604 std::vector<DeferredReplacement> &Replacements) {
1605 const auto &LiveSet = Result.LiveSet;
1606 const auto &PointerToBase = Result.PointerToBase;
1610 LiveVec.
reserve(LiveSet.size());
1611 BaseVec.
reserve(LiveSet.size());
1612 for (
Value *L : LiveSet) {
1614 assert(PointerToBase.count(L));
1615 Value *
Base = PointerToBase.find(L)->second;
1634 for (
User *U : GCRelocs) {
1641 Value *Alloca = AllocaMap[OriginalValue];
1647 "Should always have one since it's not a terminator");
1649 Value *CastedRelocatedValue =
1650 Builder.CreateBitCast(Relocate,
1651 cast<AllocaInst>(Alloca)->getAllocatedType(),
1655 Store->
insertAfter(cast<Instruction>(CastedRelocatedValue));
1658 VisitedLiveValues.
insert(OriginalValue);
1669 for (
auto RematerializedValuePair: RematerializedValues) {
1670 Instruction *RematerializedValue = RematerializedValuePair.first;
1671 Value *OriginalValue = RematerializedValuePair.second;
1674 "Can not find alloca for rematerialized value");
1675 Value *Alloca = AllocaMap[OriginalValue];
1681 VisitedLiveValues.
insert(OriginalValue);
1693 int InitialAllocaNum = 0;
1695 if (isa<AllocaInst>(I))
1703 std::size_t NumRematerializedValues = 0;
1709 auto emitAllocaFor = [&](
Value *LiveValue) {
1713 AllocaMap[LiveValue] = Alloca;
1718 for (
Value *V : Live)
1722 for (
const auto &
Info : Records)
1723 for (
auto RematerializedValuePair :
Info.RematerializedValues) {
1724 Value *OriginalValue = RematerializedValuePair.second;
1725 if (AllocaMap.
count(OriginalValue) != 0)
1728 emitAllocaFor(OriginalValue);
1729 ++NumRematerializedValues;
1741 for (
const auto &
Info : Records) {
1752 if (isa<InvokeInst>(Statepoint)) {
1761 if (ClobberNonLive) {
1768 for (
auto Pair : AllocaMap) {
1773 if (VisitedLiveValues.
count(Def)) {
1780 for (
auto *AI : ToClobber) {
1781 auto PT = cast<PointerType>(AI->getAllocatedType());
1790 if (
auto II = dyn_cast<InvokeInst>(Statepoint)) {
1791 InsertClobbersAt(&*II->getNormalDest()->getFirstInsertionPt());
1792 InsertClobbersAt(&*II->getUnwindDest()->getFirstInsertionPt());
1794 InsertClobbersAt(cast<Instruction>(Statepoint)->getNextNode());
1800 for (
auto Pair : AllocaMap) {
1811 if (!isa<ConstantExpr>(U)) {
1822 auto Last = std::unique(Uses.
begin(), Uses.
end());
1826 if (isa<PHINode>(
Use)) {
1839 Use->replaceUsesOfWith(Def, Load);
1847 if (
Instruction *Inst = dyn_cast<Instruction>(Def)) {
1848 if (
InvokeInst *Invoke = dyn_cast<InvokeInst>(Inst)) {
1851 BasicBlock *NormalDest = Invoke->getNormalDest();
1854 assert(!Inst->isTerminator() &&
1855 "The only terminator that can produce a value is " 1856 "InvokeInst which is handled above.");
1860 assert(isa<Argument>(Def));
1865 assert(PromotableAllocas.
size() == Live.size() + NumRematerializedValues &&
1866 "we must have the same allocas with lives");
1867 if (!PromotableAllocas.
empty()) {
1874 if (isa<AllocaInst>(I))
1876 assert(InitialAllocaNum == 0 &&
"We must not introduce any extra allocas");
1901 if (isa<CallInst>(Call)) {
1909 auto *II = cast<InvokeInst>(Call);
1911 Func, Values,
"", &*II->getNormalDest()->getFirstInsertionPt()));
1913 Func, Values,
"", &*II->getUnwindDest()->getFirstInsertionPt()));
1919 GCPtrLivenessData OriginalLivenessData;
1921 for (
size_t i = 0; i < records.
size(); i++) {
1922 struct PartiallyConstructedSafepointRecord &
info = records[i];
1935 Value *CurrentValue) {
1939 GEP->getPointerOperand());
1942 if (
CastInst *CI = dyn_cast<CastInst>(CurrentValue)) {
1943 if (!CI->isNoopCast(CI->getModule()->getDataLayout()))
1953 return CurrentValue;
1964 if (
CastInst *CI = dyn_cast<CastInst>(Instr)) {
1965 assert(CI->isNoopCast(CI->getModule()->getDataLayout()) &&
1966 "non noop cast is found during rematerialization");
1968 Type *SrcTy = CI->getOperand(0)->getType();
1973 Type *ValTy =
GEP->getSourceElementType();
1979 if (!
GEP->hasAllConstantIndices())
1998 for (
unsigned i = 0; i < PhiNum; i++)
2004 for (
unsigned i = 0; i < PhiNum; i++) {
2007 if (CIVI == CurrentIncomingValues.
end())
2009 BasicBlock *CurrentIncomingBB = CIVI->second;
2021 PartiallyConstructedSafepointRecord &
Info,
2023 const unsigned int ChainLengthThreshold = 10;
2029 for (
Value *LiveValue: Info.LiveSet) {
2032 assert(Info.PointerToBase.count(LiveValue));
2033 Value *RootOfChain =
2038 if ( ChainToBase.
size() == 0 ||
2039 ChainToBase.
size() > ChainLengthThreshold)
2044 if (RootOfChain != Info.PointerToBase[LiveValue]) {
2047 if (!OrigRootPhi || !AlternateRootPhi)
2063 assert(Info.LiveSet.count(AlternateRootPhi));
2074 if (isa<InvokeInst>(Call)) {
2082 LiveValuesToBeDeleted.
push_back(LiveValue);
2092 auto rematerializeChain = [&ChainToBase](
2101 assert(isa<GetElementPtrInst>(Instr) || isa<CastInst>(Instr));
2105 ClonedValue->
setName(Instr->getName() +
".remat");
2109 if (LastClonedValue) {
2117 "incorrect use in rematerialization chain");
2120 assert(OpValue != RootOfChain && OpValue != AlternateLiveBase);
2129 if (RootOfChain != AlternateLiveBase)
2133 LastClonedValue = ClonedValue;
2137 return LastClonedValue;
2142 if (isa<CallInst>(Call)) {
2145 Instruction *RematerializedValue = rematerializeChain(
2146 InsertBefore, RootOfChain, Info.PointerToBase[LiveValue]);
2147 Info.RematerializedValues[RematerializedValue] = LiveValue;
2149 auto *Invoke = cast<InvokeInst>(
Call);
2152 &*Invoke->getNormalDest()->getFirstInsertionPt();
2154 &*Invoke->getUnwindDest()->getFirstInsertionPt();
2156 Instruction *NormalRematerializedValue = rematerializeChain(
2157 NormalInsertBefore, RootOfChain, Info.PointerToBase[LiveValue]);
2158 Instruction *UnwindRematerializedValue = rematerializeChain(
2159 UnwindInsertBefore, RootOfChain, Info.PointerToBase[LiveValue]);
2161 Info.RematerializedValues[NormalRematerializedValue] = LiveValue;
2162 Info.RematerializedValues[UnwindRematerializedValue] = LiveValue;
2167 for (
auto LiveValue: LiveValuesToBeDeleted) {
2168 Info.LiveSet.remove(LiveValue);
2177 std::set<CallBase *> Uniqued;
2178 Uniqued.insert(ToUpdate.
begin(), ToUpdate.
end());
2179 assert(Uniqued.size() == ToUpdate.
size() &&
"no duplicates please!");
2210 "support for FCA unimplemented");
2231 for (
size_t i = 0; i < Records.size(); i++) {
2232 PartiallyConstructedSafepointRecord &
info = Records[i];
2250 Holders.reserve(Holders.size() + Records.size());
2251 for (
size_t i = 0; i < Records.size(); i++) {
2252 PartiallyConstructedSafepointRecord &
Info = Records[i];
2255 for (
auto Pair : Info.PointerToBase)
2267 for (
auto &
Info : Records) {
2268 errs() <<
"Base Pairs: (w/Relocation)\n";
2269 for (
auto Pair :
Info.PointerToBase) {
2270 errs() <<
" derived ";
2271 Pair.first->printAsOperand(
errs(),
false);
2273 Pair.second->printAsOperand(
errs(),
false);
2287 for (
auto &
Info : Records)
2288 for (
auto &BasePair :
Info.PointerToBase)
2289 if (isa<Constant>(BasePair.second))
2290 Info.LiveSet.remove(BasePair.first);
2293 CI->eraseFromParent();
2300 for (
size_t i = 0; i < Records.size(); i++)
2306 std::vector<DeferredReplacement> Replacements;
2314 for (
size_t i = 0; i < Records.size(); i++)
2319 for (
auto &PR : Replacements)
2322 Replacements.clear();
2324 for (
auto &
Info : Records) {
2333 Info.LiveSet.clear();
2334 Info.PointerToBase.clear();
2339 for (
size_t i = 0; i < Records.size(); i++) {
2340 PartiallyConstructedSafepointRecord &
Info = Records[i];
2356 "statepoint must be reachable or liveness is meaningless");
2358 if (!isa<Instruction>(V))
2361 auto *LiveInst = cast<Instruction>(V);
2363 "unreachable values should never be live");
2365 "basic SSA liveness expectation violated by liveness analysis");
2373 for (
auto *Ptr : Live)
2375 "must be a gc pointer type");
2379 return !Records.empty();
2383 template <
typename AttrHolder>
2387 if (AH.getDereferenceableBytes(Index))
2389 AH.getDereferenceableBytes(Index)));
2390 if (AH.getDereferenceableOrNullBytes(Index))
2392 AH.getDereferenceableOrNullBytes(Index)));
2397 AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R));
2404 if (isa<PointerType>(
A.getType()))
2416 if (!isa<LoadInst>(I) && !isa<StoreInst>(I))
2431 unsigned ValidMetadataAfterRS4GC[] = {LLVMContext::MD_tbaa,
2432 LLVMContext::MD_range,
2433 LLVMContext::MD_alias_scope,
2434 LLVMContext::MD_nontemporal,
2435 LLVMContext::MD_nonnull,
2436 LLVMContext::MD_align,
2437 LLVMContext::MD_type};
2461 if (
auto *II = dyn_cast<IntrinsicInst>(&I))
2462 if (II->getIntrinsicID() == Intrinsic::invariant_start) {
2463 InvariantStartInstructions.
push_back(II);
2467 if (
MDNode *
Tag = I.getMetadata(LLVMContext::MD_tbaa)) {
2469 I.setMetadata(LLVMContext::MD_tbaa, MutableTBAA);
2474 if (
auto *Call = dyn_cast<CallBase>(&I)) {
2475 for (
int i = 0,
e = Call->
arg_size(); i !=
e; i++)
2479 if (isa<PointerType>(Call->
getType()))
2485 for (
auto *II : InvariantStartInstructions) {
2487 II->eraseFromParent();
2496 const auto &FunctionGCName = F.
getGC();
2497 const StringRef StatepointExampleName(
"statepoint-example");
2499 return (StatepointExampleName == FunctionGCName) ||
2500 (CoreCLRName == FunctionGCName);
2521 "need function body to rewrite statepoints in");
2525 if (
const auto *Call = dyn_cast<CallBase>(&I))
2544 if (NeedsRewrite(I)) {
2550 "no unreachable blocks expected");
2551 ParsePointNeeded.
push_back(cast<CallBase>(&I));
2556 if (ParsePointNeeded.
empty())
2564 if (BB.getUniquePredecessor()) {
2583 if (
auto *BI = dyn_cast<BranchInst>(TI))
2584 if (BI->isConditional())
2585 return dyn_cast<Instruction>(BI->getCondition());
2591 if (
auto *Cond = getConditionInst(TI))
2594 if (isa<ICmpInst>(Cond) && Cond->hasOneUse()) {
2596 Cond->moveBefore(TI);
2606 if (!isa<GetElementPtrInst>(I))
2610 for (
unsigned i = 0; i < I.getNumOperands(); i++)
2622 I.setOperand(0, Splat);
2648 if (isa<PHINode>(I))
2652 for (
Value *V : I.operands()) {
2654 "support for FCA unimplemented");
2674 for (
auto &I : *Succ) {
2681 "support for FCA unimplemented");
2701 for (
Value *V : Live) {
2702 if (
auto *I = dyn_cast<Instruction>(V)) {
2706 if (TermOkay && TI == I)
2709 "basic SSA liveness expectation violated by liveness analysis");
2726 GCPtrLivenessData &Data) {
2732 Data.LiveSet[&BB].clear();
2737 assert(!Data.LiveSet[&BB].count(
Kill) &&
"live set contains kill");
2742 Data.LiveIn[&BB] = Data.LiveSet[&BB];
2743 Data.LiveIn[&BB].set_union(Data.LiveOut[&BB]);
2744 Data.LiveIn[&BB].set_subtract(Data.KillSet[&BB]);
2745 if (!Data.LiveIn[&BB].empty())
2750 while (!Worklist.
empty()) {
2756 const auto OldLiveOutSize = LiveOut.
size();
2758 assert(Data.LiveIn.count(Succ));
2762 if (OldLiveOutSize == LiveOut.
size()) {
2768 Data.LiveOut[BB] = LiveOut;
2775 assert(Data.LiveIn.count(BB));
2778 if (OldLiveIn.size() != LiveTmp.
size()) {
2779 Data.LiveIn[BB] = LiveTmp;
2797 assert(Data.LiveOut.count(BB));
2806 LiveOut.remove(Inst);
2807 Out.insert(LiveOut.begin(), LiveOut.end());
2812 PartiallyConstructedSafepointRecord &
Info) {
2818 for (
auto V : Updated)
2819 if (Info.PointerToBase.insert({V, V}).second) {
2821 "Can't find base for unexpected live value!");
2826 for (
auto V : Updated)
2827 assert(Info.PointerToBase.count(V) &&
2828 "Must be able to find base for live value!");
2834 for (
auto KVPair : Info.PointerToBase)
2835 if (!Updated.count(KVPair.first))
2836 ToErase.
insert(KVPair.first);
2838 for (
auto *V : ToErase)
2839 Info.PointerToBase.erase(V);
2842 for (
auto KVPair : Info.PointerToBase)
2843 assert(Updated.count(KVPair.first) &&
"record for non-live value");
2846 Info.LiveSet = Updated;
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
static void rematerializeLiveValues(CallBase *Call, PartiallyConstructedSafepointRecord &Info, TargetTransformInfo &TTI)
A parsed version of the target data layout string in and methods for querying it. ...
static void unique_unsorted(SmallVectorImpl< T > &Vec)
Implement a unique function which doesn't require we sort the input vector.
static void computeLiveOutSeed(BasicBlock *BB, SetVector< Value *> &LiveTmp)
static bool isHandledGCPointerType(Type *T)
static cl::opt< bool, true > ClobberNonLiveOverride("rs4gc-clobber-non-live", cl::location(ClobberNonLive), cl::Hidden)
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MapVector< Value *, Value * > DefiningValueMapTy
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static void insertRelocationStores(iterator_range< Value::user_iterator > GCRelocs, DenseMap< Value *, AllocaInst *> &AllocaMap, DenseSet< Value *> &VisitedLiveValues)
This class represents an incoming formal argument to a Function.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
static Value * findBaseDefiningValueCached(Value *I, DefiningValueMapTy &Cache)
Returns the base defining value for this value.
static bool AreEquivalentPhiNodes(PHINode &OrigRootPhi, PHINode &AlternateRootPhi)
static BDVState meetBDVStateImpl(const BDVState &LHS, const BDVState &RHS)
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM_NODISCARD T pop_back_val()
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Instruction * StatepointToken
The new gc.statepoint instruction itself.
size_type size() const
Determine the number of elements in the SetVector.
static void stripInvalidMetadataFromInstruction(Instruction &I)
Certain metadata on instructions are invalid after running RS4GC.
Instruction * UnwindToken
Instruction to which exceptional gc relocates are attached Makes it easier to iterate through them du...
A Module instance is used to store all the information related to an LLVM module. ...
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs)
Drop all unknown metadata except for debug locations.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS)
Parse out statepoint directives from the function attributes present in AS.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
static void checkBasicSSA(DominatorTree &DT, SetVector< Value *> &Live, Instruction *TI, bool TermOkay=false)
Check that the items in 'Live' dominate 'TI'.
void push_back(const T &Elt)
static ConstantAggregateZero * get(Type *Ty)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
This class represents a function call, abstracting a target machine's calling convention.
INITIALIZE_PASS_BEGIN(RewriteStatepointsForGCLegacyPass, "rewrite-statepoints-for-gc", "Make relocations explicit at statepoints", false, false) INITIALIZE_PASS_END(RewriteStatepointsForGCLegacyPass
DominatorTree & getDomTree()
Flush DomTree updates and return DomTree.
static void insertUseHolderAfter(CallBase *Call, const ArrayRef< Value *> Values, SmallVectorImpl< CallInst *> &Holders)
Insert holders so that each Value is obviously live through the entire lifetime of the call...
MapVector< BasicBlock *, SetVector< Value * > > KillSet
Values defined in this block.
const Value * getTrueValue() const
The two locations do not alias at all.
Analysis pass providing the TargetTransformInfo.
This instruction constructs a fixed permutation of two input vectors.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
MapVector< BasicBlock *, SetVector< Value * > > LiveSet
Values used in this block (and thus live); does not included values killed within this block...
LLVMContext & getContext() const
All values hold a context through their type.
static void stripNonValidAttributesFromPrototype(Function &F)
MapVector< BasicBlock *, SetVector< Value * > > LiveIn
Values live into this basic block (i.e.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
This class implements a map that also provides access to all stored values in a deterministic order...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Analysis pass which computes a DominatorTree.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
An instruction for reading from memory.
reverse_iterator rbegin()
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
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...
bool isVectorTy() const
True if this is an instance of VectorType.
static void stripNonValidDataFromBody(Function &F)
static BaseDefiningValueResult findBaseDefiningValueOfVector(Value *I)
Return a base defining value for the 'Index' element of the given vector instruction 'I'...
void reserve(size_type N)
static void makeStatepointExplicit(DominatorTree &DT, CallBase *Call, PartiallyConstructedSafepointRecord &Result, std::vector< DeferredReplacement > &Replacements)
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
static void computeLiveInValues(DominatorTree &DT, Function &F, GCPtrLivenessData &Data)
Compute the live-in set for every basic block in the function.
iterator begin()
Instruction iterator methods.
Value * getArgOperand(unsigned i) const
unsigned getAllocaAddrSpace() const
AnalysisUsage & addRequired()
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
#define INITIALIZE_PASS_DEPENDENCY(depName)
static void makeStatepointExplicitImpl(CallBase *Call, const SmallVectorImpl< Value *> &BasePtrs, const SmallVectorImpl< Value *> &LiveVariables, PartiallyConstructedSafepointRecord &Result, std::vector< DeferredReplacement > &Replacements)
static void relocationViaAlloca(Function &F, DominatorTree &DT, ArrayRef< Value *> Live, ArrayRef< PartiallyConstructedSafepointRecord > Records)
Do all the relocation update via allocas and mem2reg.
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
'undef' values are things that do not have specified contents.
static bool isKnownBaseResult(Value *V)
Given the result of a call to findBaseDefiningValue, or findBaseOrBDV, is it known to be a base point...
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
static Value * findBasePointer(Value *I, DefiningValueMapTy &Cache)
For a given value or instruction, figure out what base ptr its derived from.
A Use represents the edge between a Value definition and its users.
Value * getDerivedPtr() const
static Value * findRematerializableChainToBasePointer(SmallVectorImpl< Instruction *> &ChainToBase, Value *CurrentValue)
static bool isGCPointerType(Type *T)
This file contains the simple types necessary to represent the attributes associated with functions a...
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
static ArrayRef< Use > GetDeoptBundleOperands(const CallBase *Call)
void setName(const Twine &Name)
Change the name of the value.
arg_iterator gc_args_begin() const
bool remove(const value_type &X)
Remove an item from the set vector.
void initializeRewriteStatepointsForGCLegacyPassPass(PassRegistry &)
LLVMContext & getContext() const
Retrieve the LLVM context.
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
static cl::opt< bool > PrintLiveSet("spp-print-liveset", cl::Hidden, cl::init(false))
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
Type * getType() const
All values are typed, get the type of this value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool isStatepoint(const CallBase *Call)
const T & getValue() const LLVM_LVALUE_FUNCTION
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
Class to represent array types.
iterator_range< arg_iterator > gc_args() const
range adapter for gc arguments
This class represents a no-op cast from one type to another.
Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
AttrBuilder & remove(const AttrBuilder &B)
Remove the attributes from the builder.
const std::string & getGC() const
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
ModulePass * createRewriteStatepointsForGCLegacyPass()
StatepointLiveSetTy LiveSet
The set of values known to be live across this safepoint.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Analysis containing CSE Info
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
static unsigned chainToBasePointerCost(SmallVectorImpl< Instruction *> &Chain, TargetTransformInfo &TTI)
SetVector< Value * > StatepointLiveSetTy
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
iterator find(const_arg_type_t< KeyT > Val)
static SetVector< Value * > computeKillSet(BasicBlock *BB)
bool isVoidTy() const
Return true if this is 'void'.
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock *> Preds, const char *Suffix, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, bool PreserveLCSSA=false)
This method introduces at least one new basic block into the function and moves some of the predecess...
initializer< Ty > init(const Ty &Val)
Type * getReturnType() const
Returns the type of the ret val.
static void recomputeLiveInValues(GCPtrLivenessData &RevisedLivenessData, CallBase *Call, PartiallyConstructedSafepointRecord &result)
Given an updated version of the dataflow liveness results, update the liveset and base pointer maps f...
static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH, unsigned Index)
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
A set of analyses that are preserved following a run of a transformation pass.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
unsigned arg_size() const
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Value * getCalledValue() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
size_t size() const
size - Get the array size.
This function has undefined behavior.
This is an important base class in LLVM.
bool set_union(const STy &S)
Compute This := This u S, return whether 'This' changed.
static cl::opt< unsigned > RematerializationThreshold("spp-rematerialization-threshold", cl::Hidden, cl::init(6))
Value * getIncomingValueForBlock(const BasicBlock *BB) const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static AttributeList legalizeCallAttributes(AttributeList AL)
std::pair< iterator, bool > insert(const ValueT &V)
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool runOnFunction(Function &F, DominatorTree &, TargetTransformInfo &, const TargetLibraryInfo &)
Optional< uint32_t > NumPatchBytes
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
RematerializedValueMapTy RematerializedValues
Record live values we are rematerialized instead of relocating.
void setCallingConv(CallingConv::ID CC)
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.
A specialization of it's base class for read-write access to a gc.statepoint.
Interval::pred_iterator pred_end(Interval *I)
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
self_iterator getIterator()
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
static void stripNonValidData(Module &M)
The IR fed into RewriteStatepointsForGC may have had attributes and metadata implying dereferenceabil...
void setTailCallKind(TailCallKind TCK)
const Function * getFunction() const
Return the function this instruction belongs to.
static bool containsGCPtrType(Type *Ty)
Returns true if this type contains a gc pointer whether we know how to handle that type or not...
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static StringRef getDeoptLowering(CallBase *Call)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
iterator erase(const_iterator CI)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
static void findLiveSetAtInst(Instruction *inst, GCPtrLivenessData &Data, StatepointLiveSetTy &out)
Given results from the dataflow liveness computation, find the set of live Values at a particular ins...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static Value * findBaseOrBDV(Value *I, DefiningValueMapTy &Cache)
Return a base pointer for this value if known.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
static bool shouldRewriteStatepointsIn(Function &F)
Returns true if this function should be rewritten by this pass.
void sort(IteratorTy Start, IteratorTy End)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static cl::opt< bool > PrintBasePointers("spp-print-base-pointers", cl::Hidden, cl::init(false))
static cl::opt< bool > AllowStatepointWithNoDeoptInfo("rs4gc-allow-statepoint-with-no-deopt-info", cl::Hidden, cl::init(true))
A SetVector that performs no allocations if smaller than a certain size.
arg_iterator gc_args_end() const
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static BDVState meetBDVState(const BDVState &LHS, const BDVState &RHS)
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Module.h This file contains the declarations for the Module class.
Provides information about what library functions are available for the current target.
Indicates that this statepoint is a transition from GC-aware code to code that is not GC-aware...
LLVM_NODISCARD T pop_back_val()
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static BasicBlock * normalizeForInvokeSafepoint(BasicBlock *BB, BasicBlock *InvokeParent, DominatorTree &DT)
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
AttributeList getAttributes() const
Return the parameter attributes for this call.
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
void set_subtract(const STy &S)
Compute This := This - B TODO: We should be able to use set_subtract from SetOperations.h, but SetVector interface is inconsistent with DenseSet.
Value handle that asserts if the Value is deleted.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getVectorNumElements() const
static bool ClobberNonLive
A range adaptor for a pair of iterators.
Class to represent vector types.
static std::string suffixed_name_or(Value *V, StringRef Suffix, StringRef DefaultName)
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
MapVector< AssertingVH< Instruction >, AssertingVH< Value > > RematerializedValueMapTy
bool isStatepointDirectiveAttr(Attribute Attr)
Return true if the Attr is an attribute that is a statepoint directive.
Optional< uint64_t > StatepointID
iterator_range< user_iterator > users()
static const uint64_t DefaultStatepointID
void FoldSingleEntryPHINodes(BasicBlock *BB, MemoryDependenceResults *MemDep=nullptr)
We know that BB has one predecessor.
iterator insert(iterator I, T &&Elt)
const Value * getFalseValue() const
LLVM_NODISCARD bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
Call sites that get wrapped by a gc.statepoint (currently only in RewriteStatepointsForGC and potenti...
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
bool operator!=(uint64_t V1, const APInt &V2)
static void CreateGCRelocates(ArrayRef< Value *> LiveVariables, const int LiveStart, ArrayRef< Value *> BasePtrs, Instruction *StatepointToken, IRBuilder<> Builder)
Helper function to place all gc relocates necessary for the given statepoint.
unsigned getNumUses() const
This method computes the number of uses of this Value.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
static void findLiveReferences(Function &F, DominatorTree &DT, ArrayRef< CallBase *> toUpdate, MutableArrayRef< struct PartiallyConstructedSafepointRecord > records)
static cl::opt< bool > PrintLiveSetSize("spp-print-liveset-size", cl::Hidden, cl::init(false))
bool empty() const
Return true if the builder contains no target-independent attributes.
LLVM_NODISCARD bool empty() const
StringRef getValueAsString() const
Return the attribute's value as a string.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
StringRef getName() const
Return a constant reference to the value's name.
static bool isUnhandledGCPointerType(Type *Ty)
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
unsigned pred_size(const BasicBlock *BB)
Get the number of predecessors of BB.
bool empty() const
Determine if the SetVector is empty or not.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static void findBasePointers(const StatepointLiveSetTy &live, MapVector< Value *, Value *> &PointerToBase, DominatorTree *DT, DefiningValueMapTy &DVCache)
iterator_range< value_op_iterator > operand_values()
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
ilist_iterator< OptionsT, !IsReverse, IsConst > getReverse() const
Get a reverse iterator to the same node.
void preserve()
Mark an analysis as preserved.
static void insertRematerializationStores(const RematerializedValueMapTy &RematerializedValues, DenseMap< Value *, AllocaInst *> &AllocaMap, DenseSet< Value *> &VisitedLiveValues)
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.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
static bool insertParsePoints(Function &F, DominatorTree &DT, TargetTransformInfo &TTI, SmallVectorImpl< CallBase *> &ToUpdate)
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents calls to the gc.relocate intrinsic.
Mark the deopt arguments associated with the statepoint as only being "live-in".
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
A vector that has set insertion semantics.
succ_range successors(Instruction *I)
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.
MapVector< BasicBlock *, SetVector< Value * > > LiveOut
Values live out of this basic block (i.e.
This class implements an extremely fast bulk output stream that can only output to a stream...
void PromoteMemToReg(ArrayRef< AllocaInst *> Allocas, DominatorTree &DT, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
StringRef - Represent a constant reference to a string, i.e.
inst_range instructions(Function *F)
A container for analyses that lazily runs them and caches their results.
const LandingPadInst * getLandingPadInst() const
Return the landingpad instruction associated with the landing pad.
Legacy analysis pass which computes a DominatorTree.
bool operator==(uint64_t V1, const APInt &V2)
MapVector< Value *, Value * > PointerToBase
Mapping from live pointers to a base-defining-value.
void setIncomingValue(unsigned i, Value *V)
static void analyzeParsePointLiveness(DominatorTree &DT, GCPtrLivenessData &OriginalLivenessData, CallBase *Call, PartiallyConstructedSafepointRecord &Result)
bool isEmpty() const
Return true if there are no attributes.
InstListType::reverse_iterator reverse_iterator
MDNode * createMutableTBAAAccessTag(MDNode *Tag)
Return mutable version of the given mutable or immutable TBAA access tag.
LocationClass< Ty > location(Ty &L)
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute >> Attrs)
Create an AttributeList with the specified parameters in it.
iterator_range< arg_iterator > args()
bool empty() const
empty - Check if the array is empty.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
static BaseDefiningValueResult findBaseDefiningValue(Value *I)
Helper function for findBasePointer - Will return a value which either a) defines the base pointer fo...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
unsigned gcArgsStartIdx() const