21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SetVector.h"
23#include "llvm/Support/DebugLog.h"
24#include "llvm/Support/GenericIteratedDominanceFrontier.h"
27#define GEN_PASS_DEF_MEM2REG
28#include "mlir/Transforms/Passes.h.inc"
31#define DEBUG_TYPE "mem2reg"
134using BlockingUsesMap =
136using RegionBlockingUsesMap =
137 llvm::SmallMapVector<Region *, BlockingUsesMap, 2>;
143struct RegionPromotionInfo {
150struct MemorySlotPromotionInfo {
159 RegionBlockingUsesMap userToBlockingUses;
168 bool needsAnyReplacedValuesVisit =
false;
174class MemorySlotPromotionAnalyzer {
178 : slot(slot), dominance(dominance), dataLayout(dataLayout) {}
182 std::optional<MemorySlotPromotionInfo> computeInfo();
196 computeBlockingUses(RegionBlockingUsesMap &userToBlockingUses,
199 bool &needsAnyReplacedValuesVisit);
205 void computeMergePoints(
Region *region,
231class MemorySlotPromoter {
233 MemorySlotPromoter(
MemorySlot slot, PromotableAllocationOpInterface allocator,
235 const DataLayout &dataLayout, MemorySlotPromotionInfo info,
237 BlockIndexCache &blockIndexCache);
244 std::optional<PromotableAllocationOpInterface> promoteSlot();
271 void promoteInRegion(
Region *region,
Value reachingDef);
276 void visitReplacedValuesForRegion(
277 Region *region,
ArrayRef<std::pair<Operation *, Value>> replacedValues);
282 void removeBlockingUses(
Region *region);
286 void removeUnusedItems();
290 Value getOrCreateDefaultValue();
293 PromotableAllocationOpInterface allocator;
311 llvm::SmallSetVector<Operation *, 8> toErase;
315 MemorySlotPromotionInfo info;
323 BlockIndexCache &blockIndexCache;
328MemorySlotPromoter::MemorySlotPromoter(
329 MemorySlot slot, PromotableAllocationOpInterface allocator,
332 BlockIndexCache &blockIndexCache)
333 : slot(slot), allocator(allocator), builder(builder), dominance(dominance),
334 dataLayout(dataLayout), info(std::move(info)), statistics(statistics),
335 blockIndexCache(blockIndexCache) {
337 auto isResultOrNewBlockArgument = [&]() {
339 return arg.getOwner()->getParentOp() == allocator;
343 assert(isResultOrNewBlockArgument() &&
344 "a slot must be a result of the allocator or an argument of the child "
345 "regions of the allocator");
349Value MemorySlotPromoter::getOrCreateDefaultValue() {
353 OpBuilder::InsertionGuard guard(builder);
355 return defaultValue = allocator.getDefaultValue(slot, builder);
361 auto memOp = dyn_cast_or_null<PromotableMemOpInterface>(op->
getParentOp());
362 return memOp && memOp.ownsWrappedBlockingUses() ? memOp : op;
365LogicalResult MemorySlotPromotionAnalyzer::computeBlockingUses(
366 RegionBlockingUsesMap &userToBlockingUses,
376 auto slotPtrRegionOp =
377 dyn_cast<RegionKindInterface>(slotPtrRegion->
getParentOp());
378 if (slotPtrRegionOp &&
387 SmallPtrSet<OpOperand *, 4> &blockingUses =
389 blockingUses.insert(&use);
393 RegionSet regionsWithDirectUse;
395 RegionSet regionsWithDirectStore;
404 SmallPtrSet<Operation *, 4> visitedWrappers;
405 for (Operation *op : forwardSlice) {
409 if (user != op && !visitedWrappers.insert(user).second)
412 auto *blockingUsesMapIt = userToBlockingUses.find(user->
getParentRegion());
413 if (blockingUsesMapIt == userToBlockingUses.end())
415 BlockingUsesMap &blockingUsesMap = blockingUsesMapIt->second;
416 auto *it = blockingUsesMap.find(user);
417 if (it == blockingUsesMap.end())
421 if (
auto aliaser = dyn_cast<PromotableAliaserInterface>(user))
424 SmallPtrSet<OpOperand *, 4> &blockingUses = it->second;
426 SmallVector<OpOperand *> newBlockingUses;
429 if (
auto promotable = dyn_cast<PromotableOpInterface>(user)) {
430 if (!promotable.canUsesBeRemoved(blockingUses, newBlockingUses,
434 if (promotable.requiresReplacedValues())
435 needsAnyReplacedValuesVisit =
true;
436 }
else if (
auto promotable = dyn_cast<PromotableMemOpInterface>(user)) {
443 MemorySlot aliasSlot =
445 if (!promotable.canUsesBeRemoved(aliasSlot, blockingUses, newBlockingUses,
452 if (promotable.storesTo(aliasSlot))
464 assert((user == op || newBlockingUses.empty()) &&
465 "an op owning wrapped blocking uses must not add new blocking uses");
468 for (OpOperand *blockingUse : newBlockingUses) {
469 assert(llvm::is_contained(user->
getResults(), blockingUse->get()));
472 SmallPtrSetImpl<OpOperand *> &newUserBlockingUseSet =
474 newUserBlockingUseSet.insert(blockingUse);
480 auto visitRegions = [&](SmallVector<Region *> ®ionsToPropagateFrom,
481 bool hasValueStores) {
482 while (!regionsToPropagateFrom.empty()) {
483 Region *region = regionsToPropagateFrom.pop_back_val();
486 regionsToPromote.contains(region))
489 RegionPromotionInfo ®ionInfo = regionsToPromote[region];
490 regionInfo.hasValueStores = hasValueStores;
492 auto promotableParentOp =
493 dyn_cast<PromotableRegionOpInterface>(region->
getParentOp());
494 if (!promotableParentOp)
497 if (!promotableParentOp.isRegionPromotable(slot, region, hasValueStores))
508 SmallVector<Region *> regionsToPropagateFrom(regionsWithDirectStore.begin(),
509 regionsWithDirectStore.end());
510 if (
failed(visitRegions(regionsToPropagateFrom,
true)))
514 regionsToPropagateFrom.clear();
515 regionsToPropagateFrom.append(regionsWithDirectUse.begin(),
516 regionsWithDirectUse.end());
517 if (
failed(visitRegions(regionsToPropagateFrom,
false)))
524void MemorySlotPromotionAnalyzer::computeMergePoints(
531 idfCalculator.setDefiningBlocks(definingBlocks);
534 idfCalculator.calculate(mergePointsVec);
536 mergePoints.insert_range(mergePointsVec);
539bool MemorySlotPromotionAnalyzer::areMergePointsUsable(
540 SmallPtrSetImpl<Block *> &mergePoints) {
541 for (
Block *mergePoint : mergePoints)
542 for (
Block *pred : mergePoint->getPredecessors())
543 if (!isa<BranchOpInterface>(pred->getTerminator()))
549std::optional<MemorySlotPromotionInfo>
550MemorySlotPromotionAnalyzer::computeInfo() {
551 MemorySlotPromotionInfo info;
559 if (
failed(computeBlockingUses(info.userToBlockingUses, info.regionsToPromote,
561 info.needsAnyReplacedValuesVisit)))
573 auto collectStoringBlocks = [&](Value ptr,
const MemorySlot &ptrSlot) {
574 for (OpOperand &use : ptr.
getUses()) {
576 if (
auto storeOp = dyn_cast<PromotableMemOpInterface>(user))
577 if (storeOp.storesTo(ptrSlot))
581 collectStoringBlocks(slot.
ptr, slot);
582 for (
auto &[aliasPtr, aliasInfo] : info.aliasMap)
583 collectStoringBlocks(aliasPtr, aliasInfo.slot);
584 for (
auto &[region, regionInfo] : info.regionsToPromote)
585 if (regionInfo.hasValueStores)
592 for (
auto &[region, defBlocks] : definingBlocks)
593 computeMergePoints(region, defBlocks, info.mergePoints);
598 if (!areMergePointsUsable(info.mergePoints))
604Value MemorySlotPromoter::promoteInBlock(
Block *block, Value reachingDef) {
605 SmallVector<Operation *> blockOps;
607 blockOps.push_back(&op);
608 for (Operation *op : blockOps) {
610 if (
auto memOp = dyn_cast<PromotableMemOpInterface>(op)) {
611 if (info.userToBlockingUses[memOp->getParentRegion()].contains(memOp))
612 reachingDefs.insert({memOp, reachingDef});
614 MemorySlot aliasSlot =
616 if (memOp.storesTo(aliasSlot)) {
626 reachingDef = getOrCreateDefaultValue();
627 Value reachingDefAtStore = reachingDef;
628 if (slot.
ptr != aliasSlot.
ptr) {
633 reachingDef, aliasSlot, slot, info.aliasMap, builder);
634 assert(reachingDefAtStore &&
635 "projectSlotValueToAliasValue contract violation");
638 memOp.getStored(aliasSlot, builder, reachingDefAtStore, dataLayout);
639 assert(stored &&
"a memory operation storing to a slot must provide a "
640 "new definition of the slot");
644 replacedValuesMap[memOp] = stored;
645 if (aliasSlot.
ptr != slot.
ptr) {
647 slot, info.aliasMap, builder);
648 assert(stored &&
"projectAliasValueToSlotValue contract violation");
650 reachingDef = stored;
656 if (
auto promotableRegionOp = dyn_cast<PromotableRegionOpInterface>(op)) {
657 bool needsPromotion =
false;
658 bool hasValueStores =
false;
659 for (Region ®ion : op->getRegions()) {
660 auto regionInfoIt = info.regionsToPromote.find(®ion);
661 if (regionInfoIt == info.regionsToPromote.end())
663 needsPromotion =
true;
664 if (!regionInfoIt->second.hasValueStores)
667 hasValueStores =
true;
671 if (needsPromotion) {
672 llvm::SmallMapVector<Region *, Value, 2> regionsToProcess;
678 reachingDef = getOrCreateDefaultValue();
680 promotableRegionOp.setupPromotion(slot, reachingDef, hasValueStores,
684 for (Region ®ion : op->getRegions())
685 if (info.regionsToPromote.contains(®ion))
687 regionsToProcess.contains(®ion) &&
688 "reaching definition must be provided for a required region");
691 for (
auto &[region, reachingDef] : regionsToProcess) {
693 "region must be part of the operation");
694 if (!info.regionsToPromote.contains(region))
696 promoteInRegion(region, reachingDef);
703 for (Region ®ion : op->getRegions())
707 reachingDef = promotableRegionOp.finalizePromotion(
708 slot, reachingDef, hasValueStores, reachingAtBlockEnd, builder);
713 reachingAtBlockEnd[block] = reachingDef;
717void MemorySlotPromoter::promoteInRegion(Region *region, Value reachingDef) {
719 promoteInBlock(®ion->
front(), reachingDef);
720 regionsInPostOrder.push_back(region);
725 llvm::DomTreeNodeBase<Block> *block;
729 SmallVector<DfsJob> dfsStack;
733 dfsStack.emplace_back<DfsJob>(
734 {domTree.getNode(®ion->
front()), reachingDef});
736 while (!dfsStack.empty()) {
737 DfsJob job = dfsStack.pop_back_val();
738 Block *block = job.block->getBlock();
740 if (info.mergePoints.contains(block)) {
741 BlockArgument blockArgument =
743 job.reachingDef = blockArgument;
746 job.reachingDef = promoteInBlock(block, job.reachingDef);
748 if (
auto terminator = dyn_cast<BranchOpInterface>(block->
getTerminator())) {
749 for (BlockOperand &blockOperand : terminator->getBlockOperands()) {
750 if (info.mergePoints.contains(blockOperand.get())) {
751 if (!job.reachingDef)
752 job.reachingDef = getOrCreateDefaultValue();
754 terminator.getSuccessorOperands(blockOperand.getOperandNumber())
755 .append(job.reachingDef);
760 for (
auto *child : job.block->children())
761 dfsStack.emplace_back<DfsJob>({child, job.reachingDef});
767 regionsInPostOrder.push_back(region);
774 Block *regionEntryBlock) {
775 auto [it,
inserted] = blockIndexCache.try_emplace(regionEntryBlock);
782 for (
auto [
index, block] : llvm::enumerate(topologicalOrder))
783 blockIndices[block] =
index;
793 BlockIndexCache &blockIndexCache) {
806 size_t lhsBlockIndex = topoBlockIndices.at(lhs->getBlock());
807 size_t rhsBlockIndex = topoBlockIndices.at(rhs->getBlock());
808 if (lhsBlockIndex == rhsBlockIndex)
809 return lhs->isBeforeInBlock(rhs);
810 return lhsBlockIndex < rhsBlockIndex;
814void MemorySlotPromoter::removeBlockingUses(Region *region) {
815 auto *blockingUsesMapIt = info.userToBlockingUses.find(region);
816 if (blockingUsesMapIt == info.userToBlockingUses.end())
818 BlockingUsesMap &blockingUsesMap = blockingUsesMapIt->second;
819 if (blockingUsesMap.empty())
825 region = blockingUsesMap.
front().first->getParentRegion();
827 for (
auto &[op, blockingUses] : blockingUsesMap)
828 assert(op->getParentRegion() == region &&
829 "all operations must still be in the same region");
832 llvm::SmallVector<Operation *> usersToRemoveUses(
833 llvm::make_first_range(blockingUsesMap));
839 for (Operation *toPromote : llvm::reverse(usersToRemoveUses)) {
840 if (
auto toPromoteMemOp = dyn_cast<PromotableMemOpInterface>(toPromote)) {
841 Value reachingDef = reachingDefs.lookup(toPromoteMemOp);
848 reachingDef = getOrCreateDefaultValue();
851 MemorySlot aliasSlot =
853 Value reachingDefAtBlockingUse = reachingDef;
854 if (aliasSlot.
ptr != slot.
ptr) {
858 reachingDef, aliasSlot, slot, info.aliasMap, builder);
859 assert(reachingDefAtBlockingUse &&
860 "projectSlotValueToAliasValue contract violation");
862 if (toPromoteMemOp.removeBlockingUses(
863 aliasSlot, blockingUsesMap[toPromote], builder,
864 reachingDefAtBlockingUse, dataLayout) == DeletionKind::Delete)
865 toErase.insert(toPromote);
869 auto toPromoteBasic = cast<PromotableOpInterface>(toPromote);
871 if (toPromoteBasic.removeBlockingUses(blockingUsesMap[toPromote],
872 builder) == DeletionKind::Delete)
873 toErase.insert(toPromote);
877void MemorySlotPromoter::visitReplacedValuesForRegion(
878 Region *region, ArrayRef<std::pair<Operation *, Value>> replacedValues) {
879 auto *blockingUsesMapIt = info.userToBlockingUses.find(region);
880 if (blockingUsesMapIt == info.userToBlockingUses.end())
882 BlockingUsesMap &blockingUsesMap = blockingUsesMapIt->second;
883 if (blockingUsesMap.empty())
886 for (
auto &[op, _] : blockingUsesMap) {
887 auto toVisit = dyn_cast<PromotableOpInterface>(op);
888 if (!toVisit || !toVisit.requiresReplacedValues())
891 toVisit.visitReplacedValues(replacedValues, builder);
895void MemorySlotPromoter::removeUnusedItems() {
901 SmallPtrSet<BlockArgument, 8> mergePointArgsUnused;
902 SmallVector<BlockArgument> usedMergePointArgsToProcess;
909 auto isDefinitelyUsed = [&](BlockArgument arg) {
910 for (
auto &use : arg.getUses()) {
911 if (llvm::is_contained(toErase, use.getOwner()))
917 auto branchOp = dyn_cast<BranchOpInterface>(use.getOwner());
921 std::optional<BlockArgument> successorArgument =
922 branchOp.getSuccessorBlockArgument(use.getOperandNumber());
923 if (!successorArgument)
926 if (!info.mergePoints.contains(successorArgument->getOwner()))
932 bool isLastBlockArgument =
933 successorArgument->getArgNumber() ==
934 successorArgument->getOwner()->getNumArguments() - 1;
935 if (!isLastBlockArgument)
941 for (
Block *mergePoint : info.mergePoints) {
943 if (isDefinitelyUsed(arg))
944 usedMergePointArgsToProcess.push_back(arg);
946 mergePointArgsUnused.insert(arg);
951 while (!usedMergePointArgsToProcess.empty()) {
952 BlockArgument arg = usedMergePointArgsToProcess.pop_back_val();
956 "merge point argument must be the last argument of the merge point");
958 for (BlockOperand &use : mergePoint->
getUses()) {
963 auto branch = cast<BranchOpInterface>(use.getOwner());
964 SuccessorOperands succOperands =
965 branch.getSuccessorOperands(use.getOperandNumber());
975 succOperands.
append(getOrCreateDefaultValue());
977 Value populatedValue = succOperands[arg.
getArgNumber()];
978 auto populatedValueAsArg = dyn_cast<BlockArgument>(populatedValue);
979 if (populatedValueAsArg &&
980 mergePointArgsUnused.erase(populatedValueAsArg))
981 usedMergePointArgsToProcess.push_back(populatedValueAsArg);
985 allocator.handleBlockArgument(slot, arg, builder);
986 if (statistics.newBlockArgumentAmount)
987 (*statistics.newBlockArgumentAmount)++;
1000 auto branch = cast<BranchOpInterface>(use.getOwner());
1002 branch.getSuccessorOperands(use.getOperandNumber());
1022std::optional<PromotableAllocationOpInterface>
1023MemorySlotPromoter::promoteSlot() {
1032 if (info.needsAnyReplacedValuesVisit) {
1034 replacedValues.reserve(replacedValuesMap.size());
1035 for (
const auto &[memOp, value] : replacedValuesMap)
1037 replacedValues.push_back({memOp, value});
1038 for (
Region *region : regionsInPostOrder)
1039 visitReplacedValuesForRegion(region, replacedValues);
1044 for (
Region *region : regionsInPostOrder)
1045 removeBlockingUses(region);
1048 removeUnusedItems();
1051 "after promotion, the slot pointer should not be used anymore");
1053 LDBG() <<
"Promoted memory slot: " << slot.
ptr;
1058 return allocator.handlePromotionComplete(slot, defaultValue, builder);
1065 bool promotedAny =
false;
1070 BlockIndexCache blockIndexCache;
1075 newWorkList.reserve(workList.size());
1077 bool changesInThisRound =
false;
1078 for (PromotableAllocationOpInterface allocator : workList) {
1079 bool changedAllocator =
false;
1080 for (
MemorySlot slot : allocator.getPromotableSlots()) {
1084 MemorySlotPromotionAnalyzer analyzer(slot, dominance, dataLayout);
1085 std::optional<MemorySlotPromotionInfo> info = analyzer.computeInfo();
1087 std::optional<PromotableAllocationOpInterface> newAllocator =
1088 MemorySlotPromoter(slot, allocator, builder, dominance,
1089 dataLayout, std::move(*info), statistics,
1092 changedAllocator =
true;
1096 newWorkList.push_back(*newAllocator);
1103 if (!changedAllocator)
1104 newWorkList.push_back(allocator);
1105 changesInThisRound |= changedAllocator;
1107 if (!changesInThisRound)
1113 workList.swap(newWorkList);
1114 newWorkList.clear();
1125 void runOnOperation()
override {
1130 bool changed =
false;
1132 auto &dataLayoutAnalysis = getAnalysis<DataLayoutAnalysis>();
1133 const DataLayout &dataLayout = dataLayoutAnalysis.getAtOrAbove(scopeOp);
1134 auto &dominance = getAnalysis<DominanceInfo>();
1136 for (Region ®ion : scopeOp->
getRegions()) {
1142 SmallVector<PromotableAllocationOpInterface> allocators;
1144 region.
walk([&](PromotableAllocationOpInterface allocator) {
1145 allocators.emplace_back(allocator);
1150 dominance, statistics)))
1154 markAllAnalysesPreserved();
*if copies could not be generated due to yet unimplemented cases *copyInPlacementStart and copyOutPlacementStart in copyPlacementBlock *specify the insertion points where the incoming copies and outgoing should be inserted(the insertion happens right before the *insertion point). Since `begin` can itself be invalidated due to the memref *rewriting done from this method
static void dominanceSort(SmallVector< Operation * > &ops, Region ®ion, BlockIndexCache &blockIndexCache)
Sorts ops according to dominance.
static const DenseMap< Block *, size_t > & getOrCreateBlockIndices(BlockIndexCache &blockIndexCache, Block *regionEntryBlock)
Gets or creates a block index mapping for the region of which the entry block is regionEntryBlock.
static Operation * getBlockingUseOwner(Operation *op)
Returns op's parent if it owns the blocking uses of op as a wrapped access, or op otherwise.
llvm::IDFCalculatorBase< Block, false > IDFCalculator
This class represents an argument of a Block.
unsigned getArgNumber() const
Returns the number of this argument.
Block * getOwner() const
Returns the block that owns this argument.
A block operand represents an operand that holds a reference to a Block, e.g.
Block represents an ordered list of Operations.
unsigned getNumArguments()
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
OpListType & getOperations()
Operation * getTerminator()
Get the terminator operation of this block.
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
BlockArgListType getArguments()
void eraseArgument(unsigned index)
Erase the argument at 'index' and remove it from the argument list.
The main mechanism for performing data layout queries.
A class for computing basic dominance information.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
This class helps build Operations.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
Operation is the basic unit of execution within MLIR.
Block * getBlock()
Returns the operation block that contains this operation.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
result_range getResults()
Region * getParentRegion()
Returns the region to which the instruction belongs.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Region * getParentRegion()
Return the region containing this region or nullptr if the region is attached to a top-level operatio...
unsigned getRegionNumber()
Return the number of this region in the parent operation.
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
bool hasOneBlock()
Return true if this region has exactly one block.
RetT walk(FnT &&callback)
Walk all nested operations, blocks or regions (including this region), depending on the type of callb...
This class models how operands are forwarded to block arguments in control flow.
void erase(unsigned subStart, unsigned subLen=1)
Erase operands forwarded to the successor.
void append(ValueRange valueRange)
Add new operands that are forwarded to the successor.
unsigned size() const
Returns the amount of operands passed to the successor.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
bool use_empty() const
Returns true if this value has no uses.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
Location getLoc() const
Return the location of this value.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Region * getParentRegion()
Return the Region in which this Value is defined.
DomTree & getDomTree(Region *region) const
void invalidate()
Invalidate dominance info.
Include the generated interface declarations.
SetVector< Block * > getBlocksSortedByDominance(Region ®ion)
Gets a list of blocks that is sorted according to dominance.
bool referencesAtMostOneAliasOfSlot(Operation *op, const MemorySlot &rootSlot, const PromotableAliasMap &aliasMap)
Returns true if op's operands reach rootSlot through at most one distinct alias pointer (the root its...
Value convertSlotValueToAliasValue(Value slotValue, const MemorySlot &aliasSlot, const MemorySlot &rootSlot, const PromotableAliasMap &aliasMap, OpBuilder &builder)
Walks the alias chain from rootSlot down to aliasSlot.
void populatePromotableAliasMap(PromotableAliaserInterface aliaser, const MemorySlot &rootSlot, PromotableAliasMap &aliasMap)
Populates aliasMap with alias entries produced by aliaser for operands that already alias rootSlot.
llvm::SetVector< T, Vector, Set, N > SetVector
Value convertAliasValueToSlotValue(Value aliasValue, const MemorySlot &aliasSlot, Value rootReachingDef, const MemorySlot &rootSlot, const PromotableAliasMap &aliasMap, OpBuilder &builder)
Walks the alias chain from aliasSlot back up to rootSlot.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
llvm::SmallDenseMap< Value, PromotableSlotAliasInfo, 4 > PromotableAliasMap
Maps an alias slot pointer (a result of a PromotableAliaserInterface op) reachable from a root slot t...
std::optional< MemorySlot > getOpAliasSlot(Operation *op, const MemorySlot &rootSlot, const PromotableAliasMap &aliasMap)
Returns a MemorySlot for the operand of op that aliases rootSlot.ptr (either the root itself or a kno...
LogicalResult tryToPromoteMemorySlots(ArrayRef< PromotableAllocationOpInterface > allocators, OpBuilder &builder, const DataLayout &dataLayout, DominanceInfo &dominance, Mem2RegStatistics statistics={})
Attempts to promote the memory slots of the provided allocators.
void getForwardSlice(Operation *op, SetVector< Operation * > *forwardSlice, const ForwardSliceOptions &options={})
Fills forwardSlice with the computed forward slice (i.e.
Statistics collected while applying mem2reg.
llvm::Statistic * promotedAmount
Total amount of memory slots promoted.
Represents a slot in memory.
Type valueType
Type of the value contained in the slot.
Value ptr
Pointer to the memory slot, used by operations to refer to it.