45 #define DEBUG_TYPE "rewrite-statepoints-for-gc"
78 struct RewriteStatepointsForGC :
public ModulePass {
85 bool runOnModule(
Module &M)
override {
88 Changed |= runOnFunction(
F);
94 stripDereferenceabilityInfo(M);
115 void stripDereferenceabilityInfo(
Module &M);
118 void stripDereferenceabilityInfoFromBody(
Function &
F);
119 void stripDereferenceabilityInfoFromPrototype(
Function &
F);
126 return new RewriteStatepointsForGC();
130 "Make relocations explicit at statepoints",
false,
false)
190 GCPtrLivenessData &Data);
201 if (
const PointerType *PT = dyn_cast<PointerType>(T))
205 return (1 == PT->getAddressSpace());
219 if (
auto VT = dyn_cast<VectorType>(T))
231 if (
VectorType *VT = dyn_cast<VectorType>(Ty))
233 if (
ArrayType *AT = dyn_cast<ArrayType>(Ty))
237 ST->subtypes().begin(),
ST->subtypes().end(),
269 const CallSite &CS, PartiallyConstructedSafepointRecord &result) {
280 temp.
insert(temp.
end(), liveset.begin(), liveset.end());
282 errs() <<
"Live Variables:\n";
283 for (
Value *V : temp) {
284 errs() <<
" " << V->getName();
290 errs() <<
"Number live values: " << liveset.size() <<
"\n";
292 result.liveset = liveset;
306 static std::pair<Value *, bool>
309 cast<VectorType>(I->
getType())->getElementType()->isPointerTy() &&
310 "Illegal to ask for the base pointer of a non-pointer type");
315 if (isa<Argument>(I))
317 return std::make_pair(I,
true);
320 assert(!isa<GlobalVariable>(I) &&
321 "unexpected global variable found in base of vector");
325 if (isa<UndefValue>(I))
328 return std::make_pair(I,
true);
332 if (
Constant *Con = dyn_cast<Constant>(I)) {
333 assert(!isa<GlobalVariable>(I) && !isa<UndefValue>(I) &&
334 "order of checks wrong!");
335 assert(Con->isNullValue() &&
"null is the only case which makes sense");
336 return std::make_pair(Con,
true);
339 if (isa<LoadInst>(I))
340 return std::make_pair(I,
true);
346 Value *InsertIndex = IEI->getOperand(2);
348 if (InsertIndex == Index)
352 if (isa<ConstantInt>(Index) && isa<ConstantInt>(InsertIndex))
359 return std::make_pair(IEI,
false);
362 if (isa<ShuffleVectorInst>(I))
368 return std::make_pair(I,
false);
372 assert((isa<SelectInst>(I) || isa<PHINode>(I)) &&
373 "unknown vector instruction - no base found for vector element");
374 return std::make_pair(I,
false);
387 "Illegal to ask for the base pointer of a non-pointer type");
393 if (
auto *EEI = dyn_cast<ExtractElementInst>(I)) {
394 Value *VectorOperand = EEI->getVectorOperand();
395 Value *Index = EEI->getIndexOperand();
396 std::pair<Value *, bool> pair =
398 Value *VectorBase = pair.first;
423 assert((isa<PHINode>(VectorBase) || isa<SelectInst>(VectorBase)) &&
424 "need to extend findBasePointers for generic vector"
425 "instruction cases");
431 if (isa<Argument>(I))
436 if (isa<GlobalVariable>(I))
442 if (isa<UndefValue>(I))
449 if (
Constant *Con = dyn_cast<Constant>(I)) {
450 assert(!isa<GlobalVariable>(I) && !isa<UndefValue>(I) &&
451 "order of checks wrong!");
460 assert(isa<ConstantPointerNull>(Con) &&
461 "null is the only case which makes sense");
465 if (
CastInst *CI = dyn_cast<CastInst>(I)) {
466 Value *
Def = CI->stripPointerCasts();
470 assert(!isa<CastInst>(Def) &&
"shouldn't find another cast here");
474 if (isa<LoadInst>(I))
482 switch (II->getIntrinsicID()) {
483 case Intrinsic::experimental_gc_result_ptr:
487 case Intrinsic::experimental_gc_statepoint:
488 case Intrinsic::experimental_gc_result_float:
489 case Intrinsic::experimental_gc_result_int:
491 case Intrinsic::experimental_gc_relocate: {
497 case Intrinsic::gcroot:
502 "interaction with the gcroot mechanism is not supported");
508 if (isa<CallInst>(I) || isa<InvokeInst>(I))
513 assert(!isa<LandingPadInst>(I) &&
"Landing Pad is unimplemented");
515 if (isa<AtomicCmpXchgInst>(I))
521 assert(!isa<AtomicRMWInst>(I) &&
"Xchg handled above, all others are "
522 "binary ops which don't apply to pointers");
527 if (isa<ExtractValueInst>(I))
532 assert(!isa<InsertValueInst>(I) &&
533 "Base pointer for a struct is meaningless");
539 assert((isa<SelectInst>(I) || isa<PHINode>(I)) &&
540 "missing instruction case in findBaseDefiningValing");
546 Value *&Cached = Cache[
I];
550 assert(Cache[I] !=
nullptr);
563 auto Found = Cache.find(Def);
564 if (
Found != Cache.end()) {
566 return Found->second;
575 if (!isa<PHINode>(V) && !isa<SelectInst>(V)) {
579 if (isa<Instruction>(V) &&
580 cast<Instruction>(V)->getMetadata(
"is_base_value")) {
597 assert(
status != Base || b);
603 Value *getBase()
const {
return base; }
605 bool isBase()
const {
return getStatus() == Base; }
606 bool isUnknown()
const {
return getStatus() ==
Unknown; }
607 bool isConflict()
const {
return getStatus() == Conflict; }
609 bool operator==(
const PhiState &other)
const {
610 return base == other.base &&
status == other.status;
613 bool operator!=(
const PhiState &other)
const {
return !(*
this == other); }
617 << (base ? base->getName() :
"nullptr") <<
"): ";
629 class MeetPhiStates {
632 explicit MeetPhiStates(
const ConflictStateMapTy &phiStates)
633 : phiStates(phiStates) {}
639 void meetWith(
Value *V) {
640 PhiState otherState = getStateForBDV(V);
641 assert((MeetPhiStates::pureMeet(otherState, currentResult) ==
642 MeetPhiStates::pureMeet(currentResult, otherState)) &&
643 "math is wrong: meet does not commute!");
644 currentResult = MeetPhiStates::pureMeet(otherState, currentResult);
647 PhiState getResult()
const {
return currentResult; }
650 const ConflictStateMapTy &phiStates;
651 PhiState currentResult;
655 PhiState getStateForBDV(
Value *baseValue) {
657 return PhiState(baseValue);
659 return lookupFromMap(baseValue);
663 PhiState lookupFromMap(
Value *V) {
664 auto I = phiStates.find(V);
665 assert(
I != phiStates.end() &&
"lookup failed!");
669 static PhiState pureMeet(
const PhiState &stateA,
const PhiState &stateB) {
670 switch (stateA.getStatus()) {
675 assert(stateA.getBase() &&
"can't be null");
676 if (stateB.isUnknown())
679 if (stateB.isBase()) {
680 if (stateA.getBase() == stateB.getBase()) {
681 assert(stateA == stateB &&
"equality broken!");
684 return PhiState(PhiState::Conflict);
686 assert(stateB.isConflict() &&
"only three states!");
687 return PhiState(PhiState::Conflict);
689 case PhiState::Conflict:
729 ConflictStateMapTy
states;
730 states[def] = PhiState();
741 for (
auto Pair : states) {
742 Value *V = Pair.first;
745 for (
Value *v : Keys) {
747 if (
PHINode *phi = dyn_cast<PHINode>(v)) {
748 assert(phi->getNumIncomingValues() > 0 &&
749 "zero input phis are illegal");
750 for (
Value *InVal : phi->incoming_values()) {
753 states[local] = PhiState();
757 }
else if (
SelectInst *sel = dyn_cast<SelectInst>(v)) {
760 states[local] = PhiState();
765 states[local] = PhiState();
773 errs() <<
"States after initialization:\n";
774 for (
auto Pair : states) {
776 PhiState state = Pair.second;
785 bool progress =
true;
788 size_t oldSize = states.size();
792 for (
auto Pair : states) {
793 MeetPhiStates calculateMeet(states);
794 Value *v = Pair.first;
796 if (
SelectInst *select = dyn_cast<SelectInst>(v)) {
797 calculateMeet.meetWith(
findBaseOrBDV(select->getTrueValue(), cache));
798 calculateMeet.meetWith(
findBaseOrBDV(select->getFalseValue(), cache));
800 for (
Value *Val : cast<PHINode>(v)->incoming_values())
803 PhiState oldState = states[v];
804 PhiState newState = calculateMeet.getResult();
805 if (oldState != newState) {
807 states[v] = newState;
811 assert(oldSize <= states.size());
812 assert(oldSize == states.size() || progress);
816 errs() <<
"States after meet iteration:\n";
817 for (
auto Pair : states) {
819 PhiState state = Pair.second;
831 for (
auto Pair : states) {
832 Value *V = Pair.first;
837 for (
Value *V : Keys) {
839 PhiState state = states[V];
841 assert(!state.isUnknown() &&
"Optimistic algorithm didn't complete!");
842 if (!state.isConflict())
845 if (isa<PHINode>(v)) {
848 assert(num_preds > 0 &&
"how did we reach here");
859 states[v] = PhiState(PhiState::Conflict, phi);
865 undef,
"base_select", sel);
874 basesel->setMetadata(
"is_base_value", md);
875 states[v] = PhiState(PhiState::Conflict, basesel);
880 for (
auto Pair : states) {
882 PhiState state = Pair.second;
885 assert(!state.isUnknown() &&
"Optimistic algorithm didn't complete!");
886 if (!state.isConflict())
889 if (
PHINode *basephi = dyn_cast<PHINode>(state.getBase())) {
890 PHINode *phi = cast<PHINode>(v);
892 for (
unsigned i = 0; i < NumPHIValues; i++) {
905 int blockIndex = basephi->getBasicBlockIndex(InBB);
906 if (blockIndex != -1) {
907 Value *oldBase = basephi->getIncomingValue(blockIndex);
908 basephi->addIncoming(oldBase, InBB);
913 assert(states.count(base));
914 base = states[base].getBase();
915 assert(base !=
nullptr &&
"unknown PhiState!");
926 "sanity -- findBaseOrBDV should be pure!");
936 assert(states.count(base));
937 base = states[base].getBase();
938 assert(base !=
nullptr &&
"unknown PhiState!");
940 assert(base &&
"can't be null");
943 if (base->
getType() != basephi->getType()) {
947 basephi->addIncoming(base, InBB);
949 assert(basephi->getNumIncomingValues() == NumPHIValues);
951 SelectInst *basesel = cast<SelectInst>(state.getBase());
955 for (
int i = 1; i <= 2; i++) {
956 Value *InVal = sel->getOperand(i);
962 assert(states.count(base));
963 base = states[base].getBase();
964 assert(base !=
nullptr &&
"unknown PhiState!");
966 assert(base &&
"can't be null");
980 for (
auto item : states) {
981 Value *v = item.first;
982 Value *base = item.second.getBase();
987 std::string fromstr =
988 cache.count(v) ? (cache[v]->hasName() ? cache[v]->getName() :
"")
990 errs() <<
"Updating base value cache"
992 <<
" from: " << fromstr
997 "must be something we 'know' is a base pointer");
998 if (cache.count(v)) {
1002 "base relation should be stable");
1006 assert(cache.find(def) != cache.end());
1033 Temp.
insert(Temp.
end(), live.begin(), live.end());
1035 for (
Value *ptr : Temp) {
1037 assert(base &&
"failed to find base pointer");
1038 PointerToBase[ptr] = base;
1039 assert((!isa<Instruction>(base) || !isa<Instruction>(ptr) ||
1040 DT->
dominates(cast<Instruction>(base)->getParent(),
1041 cast<Instruction>(ptr)->
getParent())) &&
1042 "The base we found better dominate the derived pointer");
1047 assert(!isa<ConstantPointerNull>(base) &&
1048 "the relocation code needs adjustment to handle the relocation of "
1049 "a null pointer constant without causing false positives in the "
1050 "safepoint ir verifier.");
1058 PartiallyConstructedSafepointRecord &result) {
1065 errs() <<
"Base Pairs (w/o Relocation):\n";
1068 for (
auto Pair : PointerToBase) {
1072 for (
Value *Ptr : Temp) {
1073 Value *Base = PointerToBase[Ptr];
1074 errs() <<
" derived %" << Ptr->getName() <<
" base %" << Base->
getName()
1079 result.PointerToBase = PointerToBase;
1086 PartiallyConstructedSafepointRecord &result);
1093 GCPtrLivenessData RevisedLivenessData;
1095 for (
size_t i = 0; i < records.
size(); i++) {
1096 struct PartiallyConstructedSafepointRecord &
info = records[i];
1119 assert(!isa<PHINode>(Ret->
begin()));
1127 auto itr = std::find(livevec.
begin(), livevec.
end(), val);
1128 assert(livevec.
end() != itr);
1129 size_t index = std::distance(livevec.
begin(), itr);
1130 assert(index < livevec.
size());
1177 const int LiveStart,
1186 for (
unsigned i = 0; i < LiveVariables.
size(); i++) {
1197 M, Intrinsic::experimental_gc_relocate, Types);
1202 LiveStart +
find_index(LiveVariables, BasePtrs[i]));
1205 LiveStart +
find_index(LiveVariables, LiveVariables[i]));
1209 GCRelocateDecl, {StatepointToken, BaseIdx, LiveIdx},
1210 LiveVariables[i]->hasName() ? LiveVariables[i]->getName() +
".relocated"
1216 NewDefs.
push_back(cast<Instruction>(Reloc));
1218 assert(NewDefs.
size() == LiveVariables.
size() &&
1219 "missing or extra redefinition at safepoint");
1227 PartiallyConstructedSafepointRecord &result) {
1228 assert(basePtrs.
size() == liveVariables.
size());
1230 "This method expects to be rewriting a statepoint");
1235 assert(F &&
"must be set");
1238 assert(M &&
"must be set");
1258 const int live_start = args.
size();
1267 Builder.
CreateCall(gc_statepoint_decl, args,
"safepoint_token");
1284 assert(BB->
end() != next &&
"not a terminator, must have next");
1313 assert(!isa<PHINode>(unwindBlock->
begin()) &&
1315 "can't safely insert in this block!");
1323 const unsigned idx = 1;
1327 result.UnwindToken = exceptional_token;
1332 exceptional_token, Builder);
1336 assert(!isa<PHINode>(normalDest->
begin()) &&
1338 "can't safely insert in this block!");
1355 "only valid use before rewrite is gc.result");
1365 result.StatepointToken = token;
1372 struct name_ordering {
1375 bool operator()(name_ordering
const &a, name_ordering
const &b) {
1376 return -1 == a.derived->getName().compare(b.derived->getName());
1382 assert(basevec.
size() == livevec.
size());
1385 for (
size_t i = 0; i < basevec.
size(); i++) {
1387 v.base = basevec[i];
1388 v.derived = livevec[i];
1391 std::sort(temp.begin(), temp.end(), name_ordering());
1392 for (
size_t i = 0; i < basevec.
size(); i++) {
1393 basevec[i] = temp[i].base;
1394 livevec[i] = temp[i].derived;
1405 PartiallyConstructedSafepointRecord &result) {
1406 auto liveset = result.liveset;
1407 auto PointerToBase = result.PointerToBase;
1411 livevec.
reserve(liveset.size());
1412 basevec.
reserve(liveset.size());
1413 for (
Value *L : liveset) {
1416 assert(PointerToBase.find(L) != PointerToBase.end());
1417 Value *base = PointerToBase[L];
1420 assert(livevec.
size() == basevec.
size());
1443 for (
User *U : GCRelocs) {
1444 if (!isa<IntrinsicInst>(U))
1451 Intrinsic::experimental_gc_relocate) {
1456 Value *OriginalValue =
1458 assert(AllocaMap.
count(OriginalValue));
1459 Value *Alloca = AllocaMap[OriginalValue];
1464 assert(RelocatedValue->
getNextNode() &&
"Should always have one since it's not a terminator");
1466 Value *CastedRelocatedValue =
1467 Builder.CreateBitCast(RelocatedValue, cast<AllocaInst>(Alloca)->getAllocatedType(),
1468 RelocatedValue->
hasName() ? RelocatedValue->
getName() +
".casted" :
"");
1471 Store->
insertAfter(cast<Instruction>(CastedRelocatedValue));
1474 VisitedLiveValues.
insert(OriginalValue);
1487 for (
auto RematerializedValuePair: RematerializedValues) {
1488 Instruction *RematerializedValue = RematerializedValuePair.first;
1489 Value *OriginalValue = RematerializedValuePair.second;
1491 assert(AllocaMap.
count(OriginalValue) &&
1492 "Can not find alloca for rematerialized value");
1493 Value *Alloca = AllocaMap[OriginalValue];
1499 VisitedLiveValues.
insert(OriginalValue);
1511 int InitialAllocaNum = 0;
1514 if (isa<AllocaInst>(*
I))
1522 std::size_t NumRematerializedValues = 0;
1527 auto emitAllocaFor = [&](
Value *LiveValue) {
1530 AllocaMap[LiveValue] = Alloca;
1535 for (
unsigned i = 0; i < Live.
size(); i++) {
1536 emitAllocaFor(Live[i]);
1540 for (
size_t i = 0; i < Records.
size(); i++) {
1541 const struct PartiallyConstructedSafepointRecord &Info = Records[i];
1543 for (
auto RematerializedValuePair : Info.RematerializedValues) {
1544 Value *OriginalValue = RematerializedValuePair.second;
1545 if (AllocaMap.
count(OriginalValue) != 0)
1548 emitAllocaFor(OriginalValue);
1549 ++NumRematerializedValues;
1563 for (
size_t i = 0; i < Records.
size(); i++) {
1564 const struct PartiallyConstructedSafepointRecord &Info = Records[i];
1575 if (isa<InvokeInst>(Statepoint)) {
1591 for (
auto Pair : AllocaMap) {
1593 AllocaInst *Alloca = cast<AllocaInst>(Pair.second);
1596 if (VisitedLiveValues.
count(Def)) {
1603 for (
auto *AI : ToClobber) {
1604 auto AIType = cast<PointerType>(AI->getType());
1605 auto PT = cast<PointerType>(AIType->getElementType());
1614 if (
auto II = dyn_cast<InvokeInst>(Statepoint)) {
1615 InsertClobbersAt(II->getNormalDest()->getFirstInsertionPt());
1616 InsertClobbersAt(II->getUnwindDest()->getFirstInsertionPt());
1620 InsertClobbersAt(Next);
1625 for (
auto Pair : AllocaMap) {
1627 Value *Alloca = Pair.second;
1636 if (!isa<ConstantExpr>(U)) {
1646 std::sort(Uses.
begin(), Uses.
end());
1647 auto Last = std::unique(Uses.
begin(), Uses.
end());
1651 if (isa<PHINode>(
Use)) {
1662 Use->replaceUsesOfWith(Def, Load);
1670 if (
Instruction *Inst = dyn_cast<Instruction>(Def)) {
1671 if (
InvokeInst *Invoke = dyn_cast<InvokeInst>(Inst)) {
1674 BasicBlock *NormalDest = Invoke->getNormalDest();
1677 assert(!Inst->isTerminator() &&
1678 "The only TerminatorInst that can produce a value is "
1679 "InvokeInst which is handled above.");
1683 assert(isa<Argument>(Def));
1688 assert(PromotableAllocas.
size() == Live.
size() + NumRematerializedValues &&
1689 "we must have the same allocas with lives");
1690 if (!PromotableAllocas.
empty()) {
1698 if (isa<AllocaInst>(*
I))
1700 assert(InitialAllocaNum == 0 &&
"We must not introduce any extra allocas");
1709 Vec.
erase(std::remove_if(Vec.
begin(), Vec.
end(), [&](
const T &V) {
1710 return !Seen.
insert(V).second;
1737 Func, Values,
"", II->getNormalDest()->getFirstInsertionPt()));
1739 Func, Values,
"", II->getUnwindDest()->getFirstInsertionPt()));
1745 GCPtrLivenessData OriginalLivenessData;
1747 for (
size_t i = 0; i < records.
size(); i++) {
1748 struct PartiallyConstructedSafepointRecord &
info = records[i];
1765 for (
Value *V : LiveSet)
1766 if (isa<VectorType>(V->
getType()))
1769 if (ToSplit.
empty())
1779 for (
Value *V : ToSplit) {
1782 AllocaMap[V] = Alloca;
1788 Elements.
push_back(Builder.CreateExtractElement(V, Builder.getInt32(i)));
1789 ElementMapping[V] = Elements;
1792 Builder.SetInsertPoint(
IP);
1793 Builder.SetCurrentDebugLocation(
IP->getDebugLoc());
1796 ResultVec = Builder.CreateInsertElement(ResultVec, Elements[i],
1797 Builder.getInt32(i));
1801 if (isa<CallInst>(StatepointInst)) {
1805 Replacements[V].first = InsertVectorReform(IP);
1806 Replacements[V].second =
nullptr;
1808 InvokeInst *Invoke = cast<InvokeInst>(StatepointInst);
1812 assert(!isa<PHINode>(NormalDest->begin()));
1814 assert(!isa<PHINode>(UnwindDest->
begin()));
1817 Replacements[V].first = InsertVectorReform(IP);
1819 Replacements[V].second = InsertVectorReform(IP);
1823 for (
Value *V : ToSplit) {
1832 if (
auto Phi = dyn_cast<PHINode>(
I)) {
1833 for (
unsigned i = 0; i < Phi->getNumIncomingValues(); i++)
1834 if (V == Phi->getIncomingValue(i)) {
1836 Alloca,
"", Phi->getIncomingBlock(i)->getTerminator());
1837 Phi->setIncomingValue(i, Load);
1841 I->replaceUsesOfWith(V, Load);
1847 if (
auto I = dyn_cast<Instruction>(V))
1853 Instruction *Replacement = cast<Instruction>(Replacements[V].first);
1854 (
new StoreInst(Replacement, Alloca))->insertAfter(Replacement);
1856 Replacement = cast_or_null<Instruction>(Replacements[V].second);
1858 (
new StoreInst(Replacement, Alloca))->insertAfter(Replacement);
1863 for (
Value *V : ToSplit)
1869 for (
Value *V : ToSplit) {
1870 auto &Elements = ElementMapping[V];
1873 LiveSet.insert(Elements.begin(), Elements.end());
1875 assert(PointerToBase.
count(V));
1876 Value *OldBase = PointerToBase[V];
1877 auto &BaseElements = ElementMapping[OldBase];
1878 PointerToBase.
erase(V);
1879 assert(Elements.size() == BaseElements.size());
1880 for (
unsigned i = 0; i < Elements.size(); i++) {
1881 Value *Elem = Elements[i];
1882 PointerToBase[Elem] = BaseElements[i];
1898 if (CurrentValue == BaseValue) {
1905 GEP->getPointerOperand(),
1909 if (
CastInst *CI = dyn_cast<CastInst>(CurrentValue)) {
1910 Value *
Def = CI->stripPointerCasts();
1914 assert(!isa<CastInst>(Def) &&
"not a pointer cast found");
1915 if (!CI->isNoopCast(CI->getModule()->getDataLayout()))
1934 if (
CastInst *CI = dyn_cast<CastInst>(Instr)) {
1935 assert(CI->isNoopCast(CI->getModule()->getDataLayout()) &&
1936 "non noop cast is found during rematerialization");
1938 Type *SrcTy = CI->getOperand(0)->getType();
1943 Type *ValTy =
GEP->getPointerOperandType()->getPointerElementType();
1949 if (!
GEP->hasAllConstantIndices())
1965 PartiallyConstructedSafepointRecord &Info,
1967 const unsigned int ChainLengthThreshold = 10;
1973 for (
Value *LiveValue: Info.liveset) {
1976 assert(Info.PointerToBase.find(LiveValue) != Info.PointerToBase.end());
1980 Info.PointerToBase[LiveValue]);
1983 ChainToBase.
size() == 0 ||
1984 ChainToBase.
size() > ChainLengthThreshold)
2004 LiveValuesToBeDeleted.
push_back(LiveValue);
2009 std::reverse(ChainToBase.
begin(), ChainToBase.
end());
2014 auto rematerializeChain = [&ChainToBase](
Instruction *InsertBefore) {
2022 assert(isa<GetElementPtrInst>(Instr) || isa<CastInst>(Instr));
2026 ClonedValue->
setName(Instr->getName() +
".remat");
2030 if (LastClonedValue) {
2037 assert(std::find(ChainToBase.begin(), ChainToBase.end(), OpValue) ==
2038 ChainToBase.end() &&
2039 "incorrect use in rematerialization chain");
2044 LastClonedValue = ClonedValue;
2047 assert(LastClonedValue);
2048 return LastClonedValue;
2055 assert(InsertBefore);
2056 Instruction *RematerializedValue = rematerializeChain(InsertBefore);
2057 Info.RematerializedValues[RematerializedValue] = LiveValue;
2067 rematerializeChain(NormalInsertBefore);
2069 rematerializeChain(UnwindInsertBefore);
2071 Info.RematerializedValues[NormalRematerializedValue] = LiveValue;
2072 Info.RematerializedValues[UnwindRematerializedValue] = LiveValue;
2077 for (
auto LiveValue: LiveValuesToBeDeleted) {
2078 Info.liveset.erase(LiveValue);
2086 std::set<CallSite> uniqued;
2087 uniqued.insert(toUpdate.
begin(), toUpdate.
end());
2088 assert(uniqued.size() == toUpdate.
size() &&
"no duplicates please!");
2090 for (
size_t i = 0; i < toUpdate.
size(); i++) {
2093 assert(
isStatepoint(CS) &&
"expected to already be a deopt statepoint");
2104 InvokeInst *invoke = cast<InvokeInst>(
CS.getInstruction());
2119 for (
size_t i = 0; i < toUpdate.size(); i++) {
2125 Value *Arg = cast<Value>(&U);
2127 "support for FCA unimplemented");
2135 records.
reserve(toUpdate.size());
2136 for (
size_t i = 0; i < toUpdate.size(); i++) {
2137 struct PartiallyConstructedSafepointRecord info;
2140 assert(records.
size() == toUpdate.size());
2153 for (
size_t i = 0; i < records.
size(); i++) {
2154 struct PartiallyConstructedSafepointRecord &
info = records[i];
2174 for (
size_t i = 0; i < records.
size(); i++) {
2175 struct PartiallyConstructedSafepointRecord &
info = records[i];
2179 for (
auto Pair : info.PointerToBase) {
2191 for (
size_t i = 0; i < records.
size(); i++) {
2192 struct PartiallyConstructedSafepointRecord &
info = records[i];
2193 errs() <<
"Base Pairs: (w/Relocation)\n";
2194 for (
auto Pair : info.PointerToBase) {
2195 errs() <<
" derived %" << Pair.first->getName() <<
" base %"
2196 << Pair.second->getName() <<
"\n";
2200 for (
size_t i = 0; i < holders.
size(); i++) {
2201 holders[i]->eraseFromParent();
2202 holders[i] =
nullptr;
2211 for (
size_t i = 0; i < records.
size(); i++) {
2212 struct PartiallyConstructedSafepointRecord &
info = records[i];
2213 Instruction *statepoint = toUpdate[i].getInstruction();
2215 info.PointerToBase, DT);
2224 for (
size_t i = 0; i < records.
size(); i++) {
2225 struct PartiallyConstructedSafepointRecord &
info = records[i];
2237 for (
size_t i = 0; i < records.
size(); i++) {
2238 struct PartiallyConstructedSafepointRecord &
info = records[i];
2246 for (
size_t i = 0; i < records.
size(); i++) {
2247 struct PartiallyConstructedSafepointRecord &
info = records[i];
2262 "statepoint must be reachable or liveness is meaningless");
2264 if (!isa<Instruction>(V))
2267 auto LiveInst = cast<Instruction>(V);
2269 "unreachable values should never be live");
2270 assert(DT.
dominates(LiveInst, info.StatepointToken) &&
2271 "basic SSA liveness expectation violated by liveness analysis");
2279 for (
auto ptr : live) {
2280 assert(
isGCPointerType(ptr->getType()) &&
"must be a gc pointer type");
2285 return !records.
empty();
2289 template <
typename AttrHolder>
2293 if (AH.getDereferenceableBytes(Index))
2295 AH.getDereferenceableBytes(Index)));
2296 if (AH.getDereferenceableOrNullBytes(Index))
2298 AH.getDereferenceableOrNullBytes(Index)));
2301 AH.setAttributes(AH.getAttributes().removeAttributes(
2302 Ctx, Index, AttributeSet::get(Ctx, Index, R)));
2306 RewriteStatepointsForGC::stripDereferenceabilityInfoFromPrototype(
Function &
F) {
2310 if (isa<PointerType>(
A.getType()))
2317 void RewriteStatepointsForGC::stripDereferenceabilityInfoFromBody(
Function &F) {
2326 assert(MD->getNumOperands() < 5 &&
"unrecognized metadata shape!");
2327 bool IsImmutableTBAA =
2328 MD->getNumOperands() == 4 &&
2329 mdconst::extract<ConstantInt>(MD->getOperand(3))->getValue() == 1;
2331 if (!IsImmutableTBAA)
2334 MDNode *Base = cast<MDNode>(MD->getOperand(0));
2335 MDNode *Access = cast<MDNode>(MD->getOperand(1));
2337 mdconst::extract<ConstantInt>(MD->getOperand(2))->getZExtValue();
2340 Builder.createTBAAStructTagNode(Base, Access, Offset);
2345 for (
int i = 0, e =
CS.arg_size(); i != e; i++)
2346 if (isa<PointerType>(
CS.getArgument(i)->getType()))
2348 if (isa<PointerType>(
CS.getType()))
2359 const char *FunctionGCName = F.
getGC();
2360 const StringRef StatepointExampleName(
"statepoint-example");
2362 return (StatepointExampleName == FunctionGCName) ||
2363 (CoreCLRName == FunctionGCName);
2368 void RewriteStatepointsForGC::stripDereferenceabilityInfo(
Module &M) {
2375 stripDereferenceabilityInfoFromPrototype(F);
2378 stripDereferenceabilityInfoFromBody(F);
2381 bool RewriteStatepointsForGC::runOnFunction(
Function &F) {
2391 DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>(
F).getDomTree();
2397 bool HasUnreachableStatepoint =
false;
2404 HasUnreachableStatepoint =
true;
2408 bool MadeChange =
false;
2414 if (HasUnreachableStatepoint)
2418 if (ParsePointNeeded.
empty())
2426 if (BB.getUniquePredecessor()) {
2455 if (isa<PHINode>(I))
2461 "support for FCA unimplemented");
2487 "support for FCA unimplemented");
2508 for (
Value *V : Live) {
2509 if (
auto *
I = dyn_cast<Instruction>(V)) {
2513 if (TermOkay && TI ==
I)
2516 "basic SSA liveness expectation violated by liveness analysis");
2533 GCPtrLivenessData &Data) {
2536 auto AddPredsToWorklist = [&](
BasicBlock *BB) {
2540 auto NextItem = [&]() {
2549 Data.LiveSet[&BB].clear();
2554 assert(!Data.LiveSet[&BB].count(
Kill) &&
"live set contains kill");
2559 Data.LiveIn[&BB] = Data.LiveSet[&BB];
2560 set_union(Data.LiveIn[&BB], Data.LiveOut[&BB]);
2562 if (!Data.LiveIn[&BB].empty())
2563 AddPredsToWorklist(&BB);
2567 while (!Worklist.
empty()) {
2573 const auto OldLiveOutSize = LiveOut.
size();
2575 assert(Data.LiveIn.count(Succ));
2579 if (OldLiveOutSize == LiveOut.
size()) {
2585 Data.LiveOut[BB] = LiveOut;
2592 assert(Data.LiveIn.count(BB));
2595 if (OldLiveIn.size() != LiveTmp.
size()) {
2596 Data.LiveIn[BB] = LiveTmp;
2597 AddPredsToWorklist(BB);
2616 assert(Data.LiveOut.count(BB));
2625 LiveOut.erase(Inst);
2626 Out.insert(LiveOut.begin(), LiveOut.end());
2631 PartiallyConstructedSafepointRecord &Info) {
2638 for (
auto KVPair : Info.PointerToBase) {
2639 Bases.
insert(KVPair.second);
2644 for (
auto V : Updated)
2645 if (!Info.PointerToBase.count(V)) {
2646 assert(Bases.
count(V) &&
"can't find base for unexpected live value");
2647 Info.PointerToBase[V] = V;
2652 for (
auto V : Updated) {
2653 assert(Info.PointerToBase.count(V) &&
2654 "must be able to find base for live value");
2661 for (
auto KVPair : Info.PointerToBase)
2662 if (!Updated.count(KVPair.first))
2663 ToErase.
insert(KVPair.first);
2664 for (
auto V : ToErase)
2665 Info.PointerToBase.erase(V);
2668 for (
auto KVPair : Info.PointerToBase)
2669 assert(Updated.count(KVPair.first) &&
"record for non-live value");
2672 Info.liveset = Updated;
Pass interface - Implemented by all 'passes'.
static std::pair< Value *, bool > findBaseDefiningValueOfVector(Value *I, Value *Index=nullptr)
Return a base defining value for the 'Index' element of the given vector instruction 'I'...
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
static void unique_unsorted(SmallVectorImpl< T > &Vec)
Implement a unique function which doesn't require we sort the input vector.
static bool isHandledGCPointerType(Type *T)
BasicBlock * getUniquePredecessor()
Return the predecessor of this block if it has a unique predecessor block.
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.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
LLVM Argument representation.
static Value * findBaseDefiningValueCached(Value *I, DefiningValueMapTy &Cache)
Returns the base defining value for this value.
Instruction * StatepointToken
The new gc.statepoint instruction itself.
static void RemoveDerefAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH, unsigned Index)
static int find_index(ArrayRef< Value * > livevec, Value *val)
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. ...
static bool findRematerializableChainToBasePointer(SmallVectorImpl< Instruction * > &ChainToBase, Value *CurrentValue, Value *BaseValue)
InstrTy * getInstruction() const
Intrinsic::ID getIntrinsicID() const
getIntrinsicID - Return the intrinsic ID of this intrinsic.
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
static void recomputeLiveInValues(GCPtrLivenessData &RevisedLivenessData, const CallSite &CS, PartiallyConstructedSafepointRecord &result)
Given an updated version of the dataflow liveness results, update the liveset and base pointer maps f...
static DenseSet< Value * > computeKillSet(BasicBlock *BB)
static void rematerializeLiveValues(CallSite CS, PartiallyConstructedSafepointRecord &Info, TargetTransformInfo &TTI)
const char * getGC() const
CallInst - This class represents a function call, abstracting a target machine's calling convention...
static void insertRematerializationStores(RematerializedValueMapTy RematerializedValues, DenseMap< Value *, Value * > &AllocaMap, DenseSet< Value * > &VisitedLiveValues)
iterator begin(unsigned Slot) const
Type * getReturnType() const
static void stablize_order(SmallVectorImpl< Value * > &basevec, SmallVectorImpl< Value * > &livevec)
const Function * getParent() const
Return the enclosing method, or null if none.
static Value * findBaseDefiningValue(Value *I)
Helper function for findBasePointer - Will return a value which either a) defines the base pointer fo...
LoadInst - an instruction for reading from memory.
reverse_iterator rbegin()
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
iv Induction Variable Users
void reserve(size_type N)
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
static void computeLiveInValues(DominatorTree &DT, Function &F, GCPtrLivenessData &Data)
Compute the live-in set for every basic block in the function.
static void makeStatepointExplicitImpl(const CallSite &CS, const SmallVectorImpl< llvm::Value * > &basePtrs, const SmallVectorImpl< llvm::Value * > &liveVariables, Pass *P, PartiallyConstructedSafepointRecord &result)
AttributeSet getRetAttributes() const
The attributes for the ret value are returned.
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
AnalysisUsage & addRequired()
rewrite statepoints for Make relocations at false
#define INITIALIZE_PASS_DEPENDENCY(depName)
static unsigned chainToBasePointerCost(SmallVectorImpl< Instruction * > &Chain, TargetTransformInfo &TTI)
static void makeStatepointExplicit(DominatorTree &DT, const CallSite &CS, Pass *P, PartiallyConstructedSafepointRecord &result)
SelectInst - This class represents the LLVM 'select' instruction.
StatepointLiveSetTy liveset
The set of values known to be live accross this safepoint.
bool erase(const ValueT &V)
static CallInst * Create(Value *Func, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
This is the base class for all instructions that perform data casts.
NodeTy * getNextNode()
Get the next node, or 0 for the list tail.
UndefValue - '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...
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
static void CreateGCRelocates(ArrayRef< llvm::Value * > LiveVariables, const int LiveStart, ArrayRef< llvm::Value * > BasePtrs, Instruction *StatepointToken, IRBuilder<> Builder)
Helper function to place all gc relocates necessary for the given statepoint.
static Value * findBasePointer(Value *I, DefiningValueMapTy &cache)
For a given value or instruction, figure out what base ptr it's derived from.
void setName(const Twine &Name)
Change the name of the value.
Instruction * clone() const
clone() - Create a copy of 'this' instruction that is identical in all ways except the following: ...
void pop_back()
Remove the last element of the SetVector.
Function does not access memory.
bool isStatepoint(const ImmutableCallSite &CS)
static cl::opt< bool > PrintLiveSet("spp-print-liveset", cl::Hidden, cl::init(false))
void PromoteMemToReg(ArrayRef< AllocaInst * > Allocas, DominatorTree &DT, AliasSetTracker *AST=nullptr, AssumptionCache *AC=nullptr)
Promote the specified list of alloca instructions into scalar registers, inserting PHI nodes as appro...
bool insert(const value_type &X)
Insert a new element into the SetVector.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
static void insertUseHolderAfter(CallSite &CS, const ArrayRef< Value * > Values, SmallVectorImpl< CallInst * > &Holders)
Insert holders so that each Value is obviously live through the entire lifetime of the call...
ValTy * getCalledValue() const
getCalledValue - Return the pointer to function that is being called.
DenseMap< BasicBlock *, DenseSet< Value * > > LiveIn
Values live into this basic block (i.e.
ArrayType - Class to represent array types.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
This class represents a no-op cast from one type to another.
bool empty() const
Determine if the SetVector is empty or not.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
StoreInst - an instruction for storing to memory.
void SetCurrentDebugLocation(DebugLoc L)
Set location information used by debugging information.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
unsigned getNumElements() const
Return the number of elements in the Vector type.
static void splitVectorValues(Instruction *StatepointInst, StatepointLiveSetTy &LiveSet, DenseMap< Value *, Value * > &PointerToBase, DominatorTree &DT)
Remove any vector of pointers from the liveset by scalarizing them over the statepoint instruction...
void takeName(Value *V)
Transfer the name from V to this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
size_t size() const
size - Get the array size.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
BasicBlock * getNormalDest() const
PointerType - Class to represent pointers.
unsigned getNumIncomingValues() const
getNumIncomingValues - Return the number of incoming edges
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
void FoldSingleEntryPHINodes(BasicBlock *BB, AliasAnalysis *AA=nullptr, MemoryDependenceAnalysis *MemDep=nullptr)
FoldSingleEntryPHINodes - We know that BB has one predecessor.
InstListType::reverse_iterator reverse_iterator
CallSiteTy::arg_iterator gc_args_begin() const
GetElementPtrInst - an instruction for type-safe pointer arithmetic to access elements of arrays and ...
iterator_range< arg_iterator > vm_state_args() const
range adapter for vm state arguments
unsigned getNumSlots() const
Return the number of slots used in this attribute list.
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
InsertElementInst - This instruction inserts a single (scalar) element into a VectorType value...
static void checkBasicSSA(DominatorTree &DT, DenseSet< Value * > &Live, TerminatorInst *TI, bool TermOkay=false)
Check that the items in 'Live' dominate 'TI'.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
Subclasses of this class are all able to terminate a basic block.
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
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.
FunTy * getCalledFunction() const
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
size_type count(const ValueT &V) const
Return 1 if the specified key is in the set, 0 otherwise.
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
This is an important base class in LLVM.
CallSiteTy::arg_iterator gc_args_end() const
const Value * getCondition() const
static cl::opt< unsigned > RematerializationThreshold("spp-rematerialization-threshold", cl::Hidden, cl::init(6))
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
LandingPadInst * getLandingPadInst()
Return the landingpad instruction associated with the landing pad.
iterator_range< arg_iterator > gc_args() const
range adapter for gc arguments
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...
const DebugLoc & getDebugLoc() const
getDebugLoc - Return the debug location for this node as a DebugLoc.
DenseMap< BasicBlock *, DenseSet< Value * > > LiveSet
Values used in this block (and thus live); does not included values killed within this block...
Represent the analysis usage information of a pass.
static Type * getVoidTy(LLVMContext &C)
BasicBlock * getIncomingBlock(unsigned i) const
getIncomingBlock - Return incoming basic block number i.
static void insertRelocationStores(iterator_range< Value::user_iterator > GCRelocs, DenseMap< Value *, Value * > &AllocaMap, DenseSet< Value * > &VisitedLiveValues)
static bool insertParsePoints(Function &F, DominatorTree &DT, Pass *P, SmallVectorImpl< CallSite > &toUpdate)
DenseMap< Instruction *, Value * > RematerializedValueMapTy
RematerializedValueMapTy RematerializedValues
Record live values we are rematerialized instead of relocating.
DenseMap< llvm::Value *, llvm::Value * > PointerToBase
Mapping from live pointers to a base-defining-value.
static void analyzeParsePointLiveness(DominatorTree &DT, GCPtrLivenessData &OriginalLivenessData, const CallSite &CS, PartiallyConstructedSafepointRecord &result)
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
A specialization of it's base class for read-write access to a gc.statepoint.
Interval::pred_iterator pred_end(Interval *I)
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
Wraps a call to a gc.relocate and provides access to it's operands.
rewrite statepoints for gc
bool empty() const
empty - Check if the array is empty.
static bool containsGCPtrType(Type *Ty)
Returns true if this type contains a gc pointer whether we know how to handle that type or not...
static bool order_by_name(llvm::Value *a, llvm::Value *b)
void setTailCall(bool isTC=true)
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
iterator erase(iterator I)
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...
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="")
INITIALIZE_PASS_BEGIN(RewriteStatepointsForGC,"rewrite-statepoints-for-gc","Make relocations explicit at statepoints", false, false) INITIALIZE_PASS_END(RewriteStatepointsForGC
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
static Value * findBaseOrBDV(Value *I, DefiningValueMapTy &Cache)
Return a base pointer for this value if known.
void setMetadata(unsigned KindID, MDNode *Node)
setMetadata - Set the metadata of the specified kind to the specified node.
static bool shouldRewriteStatepointsIn(Function &F)
Returns true if this function should be rewritten by this pass.
static void findLiveReferences(Function &F, DominatorTree &DT, Pass *P, ArrayRef< CallSite > toUpdate, MutableArrayRef< struct PartiallyConstructedSafepointRecord > records)
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
void dump() const
Support for debugging, callable in GDB: V->dump()
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
LLVMContext & getContext() const
Retrieve the LLVM context.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
static cl::opt< bool > PrintBasePointers("spp-print-base-pointers", cl::Hidden, cl::init(false))
static InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
rewrite statepoints for Make relocations at statepoints
A SetVector that performs no allocations if smaller than a certain size.
std::pair< iterator, bool > insert(const ValueT &V)
BasicBlock * getUnwindDest() const
Value * getIncomingValue(unsigned i) const
getIncomingValue - Return incoming value number x
static AttributeSet legalizeCallAttributes(AttributeSet AS)
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.
Type * getType() const
All values are typed, get the type of this value.
DenseMap< Value *, Value * > DefiningValueMapTy
void initializeRewriteStatepointsForGCPass(PassRegistry &)
iterator end(unsigned Slot) const
bool empty() const
Return true if the builder contains no target-independent attributes.
static void findBasePointers(const StatepointLiveSetTy &live, DenseMap< llvm::Value *, llvm::Value * > &PointerToBase, DominatorTree *DT, DefiningValueMapTy &DVCache)
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
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 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...
const BasicBlock & getEntryBlock() const
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
DenseMap< BasicBlock *, DenseSet< Value * > > LiveOut
Values live out of this basic block (i.e.
static bool ClobberNonLive
A range adaptor for a pair of iterators.
VectorType - Class to represent vector types.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
iterator_range< user_iterator > users()
Function only reads from memory.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
iterator insert(iterator I, T &&Elt)
const AttributeSet & getAttributes() const
getAttributes - Return the parameter attributes for this call.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void set_subtract(S1Ty &S1, const S2Ty &S2)
set_subtract(A, B) - Compute A := A - B
bool operator!=(uint64_t V1, const APInt &V2)
const AttributeSet & getAttributes() const
getAttributes - Return the parameter attributes for this invoke.
static cl::opt< bool > PrintLiveSetSize("spp-print-liveset-size", cl::Hidden, cl::init(false))
static IntegerType * getInt32Ty(LLVMContext &C)
iterator_range< inst_iterator > inst_range(Function *F)
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
unsigned getSlotIndex(unsigned Slot) const
Return the index for the given slot.
reverse_iterator rbegin(StringRef path)
Get reverse begin iterator over path.
static void relocationViaAlloca(Function &F, DominatorTree &DT, ArrayRef< Value * > Live, ArrayRef< struct PartiallyConstructedSafepointRecord > Records)
do all the relocation update via allocas and mem2reg
static bool isUnhandledGCPointerType(Type *Ty)
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
bool hasOneUse() const
Return true if there is exactly one user of this value.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
iterator_range< value_op_iterator > operand_values()
const T & back() const
Return the last element of the SetVector.
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
reverse_iterator rend(StringRef path)
Get reverse end iterator over path.
static bool isGCPointerType(const Type *T)
user_iterator user_begin()
Pointer is known to be dereferenceable.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
succ_range successors(BasicBlock *BB)
ModulePass * createRewriteStatepointsForGCPass()
static void computeLiveOutSeed(BasicBlock *BB, DenseSet< Value * > &LiveTmp)
static const Function * getParent(const Value *V)
static cl::opt< bool > TraceLSP("trace-rewrite-statepoints", cl::Hidden, cl::init(false))
void setCallingConv(CallingConv::ID CC)
InvokeInst - Invoke instruction.
IterTy arg_begin() const
arg_begin/arg_end - Return iterators corresponding to the actual argument list for a call site...
StringRef - Represent a constant reference to a string, i.e.
BasicBlock * SplitBlockPredecessors(BasicBlock *BB, ArrayRef< BasicBlock * > Preds, const char *Suffix, AliasAnalysis *AA=nullptr, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, bool PreserveLCSSA=false)
SplitBlockPredecessors - This method introduces at least one new basic block into the function and mo...
bool removeUnreachableBlocks(Function &F)
Remove all blocks that can not be reached from the function's entry.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
Legacy analysis pass which computes a DominatorTree.
bool operator==(uint64_t V1, const APInt &V2)
iterator getFirstInsertionPt()
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
std::error_code status(const Twine &path, file_status &result)
Get file status as if by POSIX stat().
bool isGCResult(const Value *V)
void setIncomingValue(unsigned i, Value *V)
bool isInvoke() const
isInvoke - true if a InvokeInst is enclosed.
AttributeSet addAttributes(LLVMContext &C, unsigned Index, AttributeSet Attrs) const
Add attributes to the attribute set at the given index.
bool isCall() const
isCall - true if a CallInst is enclosed.
bool set_union(S1Ty &S1, const S2Ty &S2)
set_union(A, B) - Compute A := A u B, return whether A changed.
LocationClass< Ty > location(Ty &L)
const BasicBlock * getParent() const
Pointer is either null or dereferenceable.
iterator_range< arg_iterator > args()
IntrinsicInst - A useful wrapper class for inspecting calls to intrinsic functions.
LLVMContext & getContext() const
Get the global data context.
DenseMap< BasicBlock *, DenseSet< Value * > > KillSet
Values defined in this block.
AllocaInst - an instruction to allocate memory on the stack.
DenseSet< llvm::Value * > StatepointLiveSetTy
AttributeSet getFnAttributes() const
The function attributes are returned.