29 #define DEBUG_TYPE "memoryssa" 46 auto Cached = CachedPreviousDef.find(BB);
47 if (Cached != CachedPreviousDef.end())
48 return Cached->second;
55 VisitedBlocks.insert(BB);
57 MemoryAccess *Result = getPreviousDefFromEnd(Pred, CachedPreviousDef);
58 CachedPreviousDef.insert({BB, Result});
62 if (VisitedBlocks.count(BB)) {
67 CachedPreviousDef.insert({BB, Result});
71 if (VisitedBlocks.insert(BB).second) {
78 bool UniqueIncomingAccess =
true;
82 auto *IncomingAccess = getPreviousDefFromEnd(Pred, CachedPreviousDef);
84 SingleAccess = IncomingAccess;
85 else if (IncomingAccess != SingleAccess)
86 UniqueIncomingAccess =
false;
97 auto *Result = tryRemoveTrivialPhi(Phi, PhiOps);
99 if (Result == Phi && UniqueIncomingAccess && SingleAccess) {
106 Result = SingleAccess;
107 }
else if (Result == Phi && !(UniqueIncomingAccess && SingleAccess)) {
109 Phi = MSSA->createMemoryPhi(BB);
125 InsertedPHIs.push_back(Phi);
131 VisitedBlocks.erase(BB);
132 CachedPreviousDef.insert({BB, Result});
143 if (
auto *LocalResult = getPreviousDefInBlock(MA))
146 return getPreviousDefRecursive(MA->
getBlock(), CachedPreviousDef);
158 if (!isa<MemoryUse>(MA)) {
161 if (Iter != Defs->rend())
167 if (!isa<MemoryUse>(U))
168 return cast<MemoryAccess>(&U);
184 return &*Defs->rbegin();
187 return getPreviousDefRecursive(BB, CachedPreviousDef);
197 if (
MemoryPhi *UsePhi = dyn_cast<MemoryPhi>(&*U))
198 tryRemoveTrivialPhi(UsePhi);
208 assert(Phi &&
"Can only remove concrete Phi.");
210 return tryRemoveTrivialPhi(Phi, OperRange);
212 template <
class RangeType>
216 if (NonOptPhis.count(Phi))
221 for (
auto &
Op : Operands) {
223 if (
Op == Phi ||
Op == Same)
228 Same = cast<MemoryAccess>(&*
Op);
240 return recursePhi(Same);
244 InsertedPHIs.clear();
260 if (!RenameUses && !InsertedPHIs.empty()) {
263 assert((!Defs || (++Defs->begin() == Defs->end())) &&
264 "Block may have only a Phi or no defs");
267 if (RenameUses && InsertedPHIs.size()) {
275 if (
auto *MD = dyn_cast<MemoryDef>(FirstDef))
276 FirstDef = MD->getDefiningAccess();
282 for (
auto &MP : InsertedPHIs)
283 if (
MemoryPhi *Phi = cast_or_null<MemoryPhi>(MP))
294 assert(i != -1 &&
"Should have found the basic block in the phi");
313 InsertedPHIs.clear();
317 bool DefBeforeSameBlock =
false;
319 !(isa<MemoryPhi>(DefBefore) &&
320 std::find(InsertedPHIs.begin(), InsertedPHIs.end(), DefBefore) !=
322 DefBeforeSameBlock =
true;
328 if (DefBeforeSameBlock) {
333 return !isa<MemoryUse>(Usr) && Usr != MD;
345 unsigned NewPhiIndex = InsertedPHIs.size();
346 if (!DefBeforeSameBlock) {
371 for (
const auto &VH : InsertedPHIs)
372 if (
const auto *RealPHI = cast_or_null<MemoryPhi>(VH))
373 DefiningBlocks.
insert(RealPHI->getBlock());
379 for (
auto *BBIDF : IDFBlocks) {
382 MPhi = MSSA->createMemoryPhi(BBIDF);
391 NonOptPhis.insert(MPhi);
393 for (
auto &MPhi : NewInsertedPHIs) {
394 auto *BBIDF = MPhi->getBlock();
397 MPhi->addIncoming(getPreviousDefFromEnd(Pred, CachedPreviousDef), Pred);
403 NewPhiIndex = InsertedPHIs.
size();
404 for (
auto &MPhi : NewInsertedPHIs) {
405 InsertedPHIs.push_back(&*MPhi);
406 FixupList.push_back(&*MPhi);
409 FixupList.push_back(MD);
414 unsigned NewPhiIndexEnd = InsertedPHIs.size();
416 while (!FixupList.empty()) {
417 unsigned StartingPHISize = InsertedPHIs.size();
418 fixupDefs(FixupList);
421 FixupList.append(InsertedPHIs.begin() + StartingPHISize, InsertedPHIs.end());
425 unsigned NewPhiSize = NewPhiIndexEnd - NewPhiIndex;
427 tryRemoveTrivialPhis(
ArrayRef<WeakVH>(&InsertedPHIs[NewPhiIndex], NewPhiSize));
438 if (
auto *MD = dyn_cast<MemoryDef>(FirstDef))
444 for (
auto &MP : InsertedPHIs) {
445 MemoryPhi *Phi = dyn_cast_or_null<MemoryPhi>(MP);
455 for (
auto &Var : Vars) {
456 MemoryAccess *NewDef = dyn_cast_or_null<MemoryAccess>(Var);
464 if (
MemoryPhi *Phi = dyn_cast<MemoryPhi>(NewDef))
465 NonOptPhis.erase(Phi);
468 if (++DefIter != Defs->end()) {
469 cast<MemoryDef>(DefIter)->setDefiningAccess(NewDef);
483 while (!Worklist.
empty()) {
489 auto *FirstDef = &*Defs->begin();
491 assert(!isa<MemoryPhi>(FirstDef) &&
492 "Should have already handled phi nodes!");
496 "Should have dominated the new access");
501 cast<MemoryDef>(FirstDef)->setDefiningAccess(getPreviousDef(FirstDef));
505 for (
const auto *S :
successors(FixupBlock)) {
513 if (!Seen.
insert(S).second)
524 MPhi->unorderedDeleteIncomingBlock(From);
525 tryRemoveTrivialPhi(MPhi);
541 tryRemoveTrivialPhi(MPhi);
548 bool CloneWasSimplified,
551 if (
MemoryDef *DefMUD = dyn_cast<MemoryDef>(InsnDefining)) {
554 assert(DefMUDI &&
"Found MemoryUseOrDef with no Instruction.");
556 cast_or_null<Instruction>(VMap.
lookup(DefMUDI))) {
558 if (!CloneWasSimplified)
559 assert(InsnDefining &&
"Defining instruction cannot be nullptr.");
560 else if (!InsnDefining || isa<MemoryUse>(InsnDefining)) {
562 auto DefIt = DefMUD->getDefsIterator();
567 "Previous def must exist");
569 &*(--DefIt), VMap, MPhiMap, CloneWasSimplified, MSSA);
574 MemoryPhi *DefPhi = cast<MemoryPhi>(InsnDefining);
576 InsnDefining = NewDefPhi;
578 assert(InsnDefining &&
"Defining instruction cannot be nullptr.");
585 bool CloneWasSimplified) {
600 dyn_cast_or_null<Instruction>(VMap.
lookup(Insn))) {
604 MPhiMap, CloneWasSimplified, MSSA),
605 CloneWasSimplified ?
nullptr : MUD,
606 CloneWasSimplified ?
false :
true);
622 auto *NewMPhi = MSSA->createMemoryPhi(BEBlock);
623 bool HasUniqueIncomingValue =
true;
625 for (
unsigned I = 0,
E = MPhi->getNumIncomingValues();
I !=
E; ++
I) {
628 if (IBB != Preheader) {
629 NewMPhi->addIncoming(IV, IBB);
630 if (HasUniqueIncomingValue) {
633 else if (UniqueValue != IV)
634 HasUniqueIncomingValue =
false;
641 auto *AccFromPreheader = MPhi->getIncomingValueForBlock(Preheader);
642 MPhi->setIncomingValue(0, AccFromPreheader);
643 MPhi->setIncomingBlock(0, Preheader);
644 for (
unsigned I = MPhi->getNumIncomingValues() - 1;
I >= 1; --
I)
645 MPhi->unorderedDeleteIncoming(
I);
646 MPhi->addIncoming(NewMPhi, BEBlock);
650 tryRemoveTrivialPhi(NewMPhi);
656 bool IgnoreIncomingWithNoClones) {
660 assert(Phi && NewPhi &&
"Invalid Phi nodes.");
670 else if (IgnoreIncomingWithNoClones)
677 if (!NewPhiBBPreds.
count(IncBB))
681 if (
MemoryUseOrDef *IncMUD = dyn_cast<MemoryUseOrDef>(IncomingAccess)) {
684 assert(IncI &&
"Found MemoryUseOrDef with no Instruction.");
686 cast_or_null<Instruction>(VMap.
lookup(IncI))) {
689 "MemoryUseOrDef cannot be null, all preds processed.");
692 NewPhi->addIncoming(IncMUD, IncBB);
694 MemoryPhi *IncPhi = cast<MemoryPhi>(IncomingAccess);
698 NewPhi->addIncoming(IncPhi, IncBB);
709 "Cloned block should have no accesses");
713 MemoryPhi *NewPhi = MSSA->createMemoryPhi(NewBlock);
714 MPhiMap[MPhi] = NewPhi;
717 cloneUsesAndDefs(BB, NewBlock, VMap, MPhiMap);
720 for (
auto BB : llvm::concat<BasicBlock *const>(LoopBlocks, ExitBlocks))
723 for (
auto BB : llvm::concat<BasicBlock *const>(LoopBlocks, ExitBlocks))
726 FixPhiIncomingValues(MPhi, cast<MemoryPhi>(NewPhi));
741 MPhiMap[MPhi] = MPhi->getIncomingValueForBlock(P1);
742 cloneUsesAndDefs(BB, P1, VM, MPhiMap,
true);
745 template <
typename Iter>
746 void MemorySSAUpdater::privateUpdateExitBlocksForClonedLoop(
751 for (
auto *Exit : ExitBlocks)
764 privateUpdateExitBlocksForClonedLoop(ExitBlocks,
std::begin(Arr),
771 auto GetPtr = [&](
const std::unique_ptr<ValueToValueMapTy> &
I) {
774 using MappedIteratorType =
777 auto MapBegin = MappedIteratorType(VMaps.begin(), GetPtr);
778 auto MapEnd = MappedIteratorType(VMaps.end(), GetPtr);
779 privateUpdateExitBlocksForClonedLoop(ExitBlocks, MapBegin, MapEnd, DT);
786 for (
auto &Update : Updates) {
787 if (Update.getKind() == DT.
Insert)
788 InsertUpdates.
push_back({DT.Insert, Update.getFrom(), Update.getTo()});
790 RevDeleteUpdates.
push_back({DT.
Insert, Update.getFrom(), Update.getTo()});
793 if (!RevDeleteUpdates.
empty()) {
809 for (
auto &Update : RevDeleteUpdates)
828 return &*(--Defs->
end());
833 for (
auto &Pair : children<GraphDiffInvBBPair>({GD, BB})) {
848 if (IDom->getBlock() != BB) {
849 BB = IDom->getBlock();
855 assert(Count == 1 && Pred &&
"Single predecessor expected.");
868 auto FindNearestCommonDominator =
871 for (
auto *BB : BBSet)
878 auto GetNoLongerDomBlocks =
881 if (PrevIDom == CurrIDom)
883 BlocksPrevDom.push_back(PrevIDom);
887 if (UpIDom == CurrIDom)
889 BlocksPrevDom.push_back(UpIDom);
914 for (
auto &Edge : Updates) {
916 auto &AddedBlockSet = PredMap[BB].Added;
917 AddedBlockSet.
insert(Edge.getFrom());
923 for (
auto &BBPredPair : PredMap) {
924 auto *BB = BBPredPair.first;
925 const auto &AddedBlockSet = BBPredPair.second.Added;
926 auto &PrevBlockSet = BBPredPair.second.Prev;
927 for (
auto &Pair : children<GraphDiffInvBBPair>({GD, BB})) {
929 if (!AddedBlockSet.count(Pi))
930 PrevBlockSet.insert(Pi);
931 EdgeCountMap[{Pi, BB}]++;
934 if (PrevBlockSet.empty()) {
935 assert(
pred_size(BB) == AddedBlockSet.size() &&
"Duplicate edges added.");
938 <<
"Adding a predecessor to a block with no predecessors. " 939 "This must be an edge added to a new, likely cloned, block. " 940 "Its memory accesses must be already correct, assuming completed " 941 "via the updateExitBlocksForClonedLoop API. " 942 "Assert a single such edge is added so no phi addition or " 943 "additional processing is required.\n");
944 assert(AddedBlockSet.size() == 1 &&
945 "Can only handle adding one predecessor to a new block.");
952 for (
auto *BB : NewBlocks)
960 for (
auto &Edge : Updates) {
962 if (PredMap.count(BB) && !MSSA->getMemoryAccess(BB))
963 InsertedPhis.
push_back(MSSA->createMemoryPhi(BB));
967 for (
auto &BBPredPair : PredMap) {
968 auto *BB = BBPredPair.first;
969 const auto &PrevBlockSet = BBPredPair.second.Prev;
970 const auto &AddedBlockSet = BBPredPair.second.Added;
971 assert(!PrevBlockSet.empty() &&
972 "At least one previous predecessor must exist.");
981 for (
auto *AddedPred : AddedBlockSet) {
982 auto *DefPn = GetLastDef(AddedPred);
983 assert(DefPn !=
nullptr &&
"Unable to find last definition.");
984 LastDefAddedPred[AddedPred] = DefPn;
987 MemoryPhi *NewPhi = MSSA->getMemoryAccess(BB);
991 for (
auto *Pred : AddedBlockSet) {
992 auto *LastDefForPred = LastDefAddedPred[Pred];
993 for (
int I = 0,
E = EdgeCountMap[{Pred, BB}];
I <
E; ++
I)
999 auto *P1 = *PrevBlockSet.begin();
1004 bool InsertPhi =
false;
1005 for (
auto LastDefPredPair : LastDefAddedPred)
1006 if (DefP1 != LastDefPredPair.second) {
1022 for (
auto *Pred : AddedBlockSet) {
1023 auto *LastDefForPred = LastDefAddedPred[Pred];
1024 for (
int I = 0,
E = EdgeCountMap[{Pred, BB}];
I <
E; ++
I)
1027 for (
auto *Pred : PrevBlockSet)
1028 for (
int I = 0,
E = EdgeCountMap[{Pred, BB}];
I <
E; ++
I)
1035 BasicBlock *PrevIDom = FindNearestCommonDominator(PrevBlockSet);
1036 assert(PrevIDom &&
"Previous IDom should exists");
1038 assert(NewIDom &&
"BB should have a new valid idom");
1040 "New idom should dominate old idom");
1041 GetNoLongerDomBlocks(PrevIDom, NewIDom, BlocksWithDefsToReplace);
1044 tryRemoveTrivialPhis(InsertedPhis);
1048 for (
auto &VH : InsertedPhis)
1049 if (
auto *MPhi = cast_or_null<MemoryPhi>(VH))
1050 BlocksToProcess.
push_back(MPhi->getBlock());
1054 if (!BlocksToProcess.
empty()) {
1057 BlocksToProcess.
end());
1063 for (
auto *BBIDF : IDFBlocks)
1064 if (!MSSA->getMemoryAccess(BBIDF)) {
1065 auto *IDFPhi = MSSA->createMemoryPhi(BBIDF);
1066 InsertedPhis.push_back(IDFPhi);
1067 PhisToFill.
insert(IDFPhi);
1070 for (
auto *BBIDF : IDFBlocks) {
1071 auto *IDFPhi = MSSA->getMemoryAccess(BBIDF);
1072 assert(IDFPhi &&
"Phi must exist");
1073 if (!PhisToFill.
count(IDFPhi)) {
1076 for (
unsigned I = 0,
E = IDFPhi->getNumIncomingValues();
I <
E; ++
I)
1077 IDFPhi->setIncomingValue(
I, GetLastDef(IDFPhi->getIncomingBlock(
I)));
1079 for (
auto &Pair : children<GraphDiffInvBBPair>({GD, BBIDF})) {
1081 IDFPhi->addIncoming(GetLastDef(Pi), Pi);
1090 for (
auto *BlockWithDefsToReplace : BlocksWithDefsToReplace) {
1091 if (
auto DefsList = MSSA->getWritableBlockDefs(BlockWithDefsToReplace)) {
1092 for (
auto &DefToReplaceUses : *DefsList) {
1093 BasicBlock *DominatingBlock = DefToReplaceUses.getBlock();
1095 E = DefToReplaceUses.use_end();
1100 if (
MemoryPhi *UsrPhi = dyn_cast<MemoryPhi>(Usr)) {
1101 BasicBlock *DominatedBlock = UsrPhi->getIncomingBlock(U);
1102 if (!DT.
dominates(DominatingBlock, DominatedBlock))
1103 U.
set(GetLastDef(DominatedBlock));
1106 if (!DT.
dominates(DominatingBlock, DominatedBlock)) {
1107 if (
auto *DomBlPhi = MSSA->getMemoryAccess(DominatedBlock))
1111 assert(IDom &&
"Block must have a valid IDom.");
1112 U.
set(GetLastDef(IDom->getBlock()));
1114 cast<MemoryUseOrDef>(Usr)->resetOptimized();
1121 tryRemoveTrivialPhis(InsertedPhis);
1125 template <
class WhereType>
1129 for (
auto *U : What->
users())
1130 if (
MemoryPhi *PhiUser = dyn_cast<MemoryPhi>(U))
1131 NonOptPhis.insert(PhiUser);
1137 MSSA->moveTo(What, BB, Where);
1140 if (
auto *MD = dyn_cast<MemoryDef>(What))
1162 if (Where != MemorySSA::InsertionPlace::BeforeTerminator)
1163 return moveTo(What, BB, Where);
1165 if (
auto *Where = MSSA->getMemoryAccess(BB->
getTerminator()))
1168 return moveTo(What, BB, MemorySSA::InsertionPlace::End);
1182 if ((FirstInNew = MSSA->getMemoryAccess(&
I)))
1185 auto *MUD = cast<MemoryUseOrDef>(FirstInNew);
1190 : cast<MemoryUseOrDef>(&*NextIt);
1194 Accs = MSSA->getWritableBlockAccesses(From);
1201 auto *Defs = MSSA->getWritableBlockDefs(From);
1202 if (Defs && !Defs->empty())
1203 if (
auto *Phi = dyn_cast<MemoryPhi>(&*Defs->begin()))
1204 tryRemoveTrivialPhi(Phi);
1210 assert(MSSA->getBlockAccesses(To) ==
nullptr &&
1211 "To block is expected to be free of MemoryAccesses.");
1212 moveAllAccesses(From, To, Start);
1214 if (
MemoryPhi *MPhi = MSSA->getMemoryAccess(Succ))
1215 MPhi->setIncomingBlock(MPhi->getBasicBlockIndex(From), To);
1221 "From block is expected to have a single predecessor (To).");
1222 moveAllAccesses(From, To, Start);
1224 if (
MemoryPhi *MPhi = MSSA->getMemoryAccess(Succ))
1225 MPhi->setIncomingBlock(MPhi->getBasicBlockIndex(From), To);
1235 MA = cast<MemoryAccess>(
Arg);
1244 bool IdenticalEdgesWereMerged) {
1245 assert(!MSSA->getWritableBlockAccesses(New) &&
1246 "Access list should be null for a new block.");
1247 MemoryPhi *Phi = MSSA->getMemoryAccess(Old);
1252 "Should have moved all predecessors.");
1255 assert(!Preds.
empty() &&
"Must be moving at least one predecessor to the " 1256 "new immediate predecessor.");
1257 MemoryPhi *NewPhi = MSSA->createMemoryPhi(New);
1261 if (!IdenticalEdgesWereMerged)
1263 "If identical edges were not merged, we cannot have duplicate " 1264 "blocks in the predecessors");
1266 if (PredsSet.count(B)) {
1267 NewPhi->addIncoming(MA, B);
1268 if (!IdenticalEdgesWereMerged)
1274 Phi->addIncoming(NewPhi, New);
1275 tryRemoveTrivialPhi(NewPhi);
1280 assert(!MSSA->isLiveOnEntryDef(MA) &&
1281 "Trying to remove the live on entry def");
1285 if (
MemoryPhi *MP = dyn_cast<MemoryPhi>(MA)) {
1292 assert((NewDefTarget || MP->use_empty()) &&
1293 "We can't delete this memory phi");
1295 NewDefTarget = cast<MemoryUseOrDef>(MA)->getDefiningAccess();
1301 if (!isa<MemoryUse>(MA) && !MA->
use_empty()) {
1317 if (
auto *MUD = dyn_cast<MemoryUseOrDef>(U.
getUser()))
1318 MUD->resetOptimized();
1322 U.
set(NewDefTarget);
1328 MSSA->removeFromLookups(MA);
1329 MSSA->removeFromLists(MA);
1332 if (!PhisToCheck.
empty()) {
1335 PhisToCheck.
clear();
1337 unsigned PhisSize = PhisToOptimize.size();
1338 while (PhisSize-- > 0)
1340 cast_or_null<MemoryPhi>(PhisToOptimize.pop_back_val()))
1341 tryRemoveTrivialPhi(MP);
1350 assert(TI &&
"Basic block expected to have a terminator instruction");
1352 if (!DeadBlocks.count(Succ))
1353 if (
MemoryPhi *MP = MSSA->getMemoryAccess(Succ)) {
1354 MP->unorderedDeleteIncomingBlock(BB);
1355 tryRemoveTrivialPhi(MP);
1368 for (
auto AB = Acc->begin(), AE = Acc->end(); AB != AE;) {
1371 MSSA->removeFromLookups(MA);
1372 MSSA->removeFromLists(MA);
1377 void MemorySSAUpdater::tryRemoveTrivialPhis(
ArrayRef<WeakVH> UpdatedPHIs) {
1378 for (
auto &VH : UpdatedPHIs)
1379 if (
auto *MPhi = cast_or_null<MemoryPhi>(VH))
1380 tryRemoveTrivialPhi(MPhi);
1396 MPhi->unorderedDeleteIncomingBlock(BB);
1401 tryRemoveTrivialPhis(UpdatedPHIs);
1411 if (
auto *MPhi = MSSA->getMemoryAccess(Succ)) {
1412 MPhi->unorderedDeleteIncomingBlock(BB);
1417 tryRemoveTrivialPhis(UpdatedPHIs);
1423 MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition);
1424 MSSA->insertIntoListsForBlock(NewAccess, BB, Point);
1431 "New and old access must be in the same block");
1432 MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition);
1433 MSSA->insertIntoListsBefore(NewAccess, InsertPt->
getBlock(),
1441 "New and old access must be in the same block");
1442 MemoryUseOrDef *NewAccess = MSSA->createDefinedAccess(I, Definition);
1443 MSSA->insertIntoListsBefore(NewAccess, InsertPt->
getBlock(),
const_iterator end(StringRef path)
Get end iterator over path.
AccessList * getWritableBlockAccesses(const BasicBlock *BB) const
bool hasNPredecessors(unsigned N) const
Return true if this block has exactly N predecessors.
static MemoryAccess * onlySingleValue(MemoryPhi *MP)
If all arguments of a MemoryPHI are defined by the same incoming argument, return that argument...
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
void dropAllReferences()
Drop all references to operands.
This class represents lattice values for constants.
AllAccessType::self_iterator getIterator()
Get the iterators for the all access list and the defs only list We default to the all access list...
bool dominates(const MemoryAccess *A, const MemoryAccess *B) const
Given two memory accesses in potentially different blocks, determine whether MemoryAccess A dominates...
MemoryAccess * getDefiningAccess() const
Get the access that produces the memory state used by this Use.
void updateExitBlocksForClonedLoop(ArrayRef< BasicBlock *> ExitBlocks, const ValueToValueMapTy &VMap, DominatorTree &DT)
Update phi nodes in exit block successors following cloning.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
void applyInsertUpdates(ArrayRef< CFGUpdate > Updates, DominatorTree &DT)
Apply CFG insert updates, analogous with the DT edge updates.
void push_back(const T &Elt)
const AccessList * getBlockAccesses(const BasicBlock *BB) const
Return the list of MemoryAccess's for a given basic block.
void changeToUnreachable(const Instruction *I)
Instruction I will be changed to an unreachable.
void insertUse(MemoryUse *Use, bool RenameUses=false)
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
void moveAfter(MemoryUseOrDef *What, MemoryUseOrDef *Where)
Represents a read-write access to memory, whether it is a must-alias, or a may-alias.
NodeT * findNearestCommonDominator(NodeT *A, NodeT *B) const
findNearestCommonDominator - Find nearest common dominator basic block for basic block A and B...
int getBasicBlockIndex(const BasicBlock *BB) const
Return the first index of the specified basic block in the value list for this PHI.
reverse_iterator rbegin()
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...
DefsOnlyType::self_iterator getDefsIterator()
void calculate(SmallVectorImpl< NodeTy *> &IDFBlocks)
Calculate iterated dominance frontiers.
iterator end()
Get an iterator to the end of the SetVector.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
void setIncomingValue(unsigned I, MemoryAccess *V)
iterator begin()
Instruction iterator methods.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Represents read-only accesses to memory.
void removeEdge(BasicBlock *From, BasicBlock *To)
Update the MemoryPhi in To following an edge deletion between From and To.
void renamePass(BasicBlock *BB, MemoryAccess *IncomingVal, SmallPtrSetImpl< BasicBlock *> &Visited)
block_iterator block_begin()
MemoryUseOrDef * createDefinedAccess(Instruction *, MemoryAccess *, const MemoryUseOrDef *Template=nullptr, bool CreationMustSucceed=true)
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Encapsulates MemorySSA, including all data associated with memory accesses.
void applyUpdates(ArrayRef< CFGUpdate > Updates, DominatorTree &DT)
Apply CFG updates, analogous with the DT edge updates.
const DefsList * getBlockDefs(const BasicBlock *BB) const
Return the list of MemoryDef's and MemoryPhi's for a given basic block.
void insertIntoListsForBlock(MemoryAccess *, const BasicBlock *, InsertionPlace)
mir Rename Register Operands
A simple intrusive list implementation.
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
bool insert(const value_type &X)
Insert a new element into the SetVector.
MemoryUseOrDef * getMemoryAccess(const Instruction *I) const
Given a memory Mod/Ref'ing instruction, get the MemorySSA access associated with it.
const BasicBlock * getUniquePredecessor() const
Return the predecessor of this block if it has a unique predecessor block.
iterator begin()
Get an iterator to the beginning of the SetVector.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
static void ValueIsRAUWd(Value *Old, Value *New)
static bool ProcessBlock(BasicBlock &BB, DominatorTree &DT, LoopInfo &LI, AAResults &AA)
MemoryUseOrDef * createMemoryAccessBefore(Instruction *I, MemoryAccess *Definition, MemoryUseOrDef *InsertPt)
Create a MemoryAccess in MemorySSA before or after an existing MemoryAccess.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
MemoryAccess * getIncomingValue(unsigned I) const
Return incoming value number x.
use_iterator_impl< Use > use_iterator
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static constexpr UpdateKind Insert
void updatePhisWhenInsertingUniqueBackedgeBlock(BasicBlock *LoopHeader, BasicBlock *LoopPreheader, BasicBlock *BackedgeBlock)
Update MemorySSA when inserting a unique backedge block for a loop.
AllAccessType::reverse_self_iterator getReverseIterator()
LLVM Basic Block Representation.
static void setMemoryPhiValueForBlock(MemoryPhi *MP, const BasicBlock *BB, MemoryAccess *NewDef)
Conditional or Unconditional Branch instruction.
Value handle that tracks a Value across RAUW.
size_t size() const
size - Get the array size.
DomTreeNodeBase * getIDom() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void removeDuplicatePhiEdgesBetween(const BasicBlock *From, const BasicBlock *To)
Update the MemoryPhi in To to have a single incoming edge from From, following a CFG change that repl...
void addIncoming(MemoryAccess *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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...
InsertionPlace
Used in various insertion functions to specify whether we are talking about the beginning or end of a...
void moveAllAfterSpliceBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start)
From block was spliced into From and To.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Interval::pred_iterator pred_end(Interval *I)
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
void updateForClonedLoop(const LoopBlocksRPO &LoopBlocks, ArrayRef< BasicBlock *> ExitBlocks, const ValueToValueMapTy &VM, bool IgnoreIncomingWithNoClones=false)
Update MemorySSA after a loop was cloned, given the blocks in RPO order, the exit blocks and a 1:1 ma...
MemoryAccess * createMemoryAccessInBB(Instruction *I, MemoryAccess *Definition, const BasicBlock *BB, MemorySSA::InsertionPlace Point)
Create a MemoryAccess in MemorySSA at a specified point in a block, with a specified clobbering defin...
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
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...
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void moveToPlace(MemoryUseOrDef *What, BasicBlock *BB, MemorySSA::InsertionPlace Where)
void setDefiningBlocks(const SmallPtrSetImpl< NodeTy *> &Blocks)
Give the IDF calculator the set of blocks in which the value is defined.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
A SetVector that performs no allocations if smaller than a certain size.
void setDefiningAccess(MemoryAccess *DMA, bool Optimized=false, Optional< AliasResult > AR=MayAlias)
unsigned getNumOperands() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
BlockVerifier::State From
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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.
void wireOldPredecessorsToNewImmediatePredecessor(BasicBlock *Old, BasicBlock *New, ArrayRef< BasicBlock *> Preds, bool IdenticalEdgesWereMerged=true)
A new empty BasicBlock (New) now branches directly to Old.
static MemoryAccess * getNewDefiningAccessForClone(MemoryAccess *MA, const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap, bool CloneWasSimplified, MemorySSA *MSSA)
BasicBlock * getBlock() const
pred_range predecessors(BasicBlock *BB)
MemoryAccess * getLiveOnEntryDef() const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void clear()
Completely clear the SetVector.
Class that has the common methods + fields of memory uses/defs.
iterator_range< user_iterator > users()
unsigned getNumIncomingValues() const
Return the number of incoming edges.
BasicBlock * getIncomingBlock(unsigned I) const
Return incoming basic block number i.
block_iterator block_end()
LLVM_NODISCARD bool empty() const
unsigned pred_size(const BasicBlock *BB)
Get the number of predecessors of BB.
bool empty() const
Determine if the SetVector is empty or not.
MemoryUseOrDef * createMemoryAccessAfter(Instruction *I, MemoryAccess *Definition, MemoryAccess *InsertPt)
void moveAllAfterMergeBlocks(BasicBlock *From, BasicBlock *To, Instruction *Start)
From block was merged into To.
bool isLiveOnEntryDef(const MemoryAccess *MA) const
Return true if MA represents the live on entry value.
reverse_iterator rend(StringRef path)
Get reverse end iterator over path.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator insert(iterator I, reference Node)
Insert a node by reference; never copies.
Wrapper class to LoopBlocksDFS that provides a standard begin()/end() interface for the DFS reverse p...
void removeMemoryAccess(MemoryAccess *, bool OptimizePhis=false)
Remove a MemoryAccess from MemorySSA, including updating all definitions and uses.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void removeBlocks(const SmallSetVector< BasicBlock *, 8 > &DeadBlocks)
Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
user_iterator user_begin()
void insertDef(MemoryDef *Def, bool RenameUses=false)
Insert a definition into the MemorySSA IR.
succ_range successors(Instruction *I)
DefsOnlyType::reverse_self_iterator getReverseDefsIterator()
This file exposes an interface to building/using memory SSA to walk memory instructions using a use/d...
Represents phi nodes for memory accesses.
DefsList * getWritableBlockDefs(const BasicBlock *BB) const
OutputIt copy(R &&Range, OutputIt Out)
void moveBefore(MemoryUseOrDef *What, MemoryUseOrDef *Where)
void updateForClonedBlockIntoPred(BasicBlock *BB, BasicBlock *P1, const ValueToValueMapTy &VM)
void changeCondBranchToUnconditionalTo(const BranchInst *BI, const BasicBlock *To)
Conditional branch BI is changed or replaced with an unconditional branch to To.
bool empty() const
empty - Check if the array is empty.
const BasicBlock * getParent() const