11#include "llvm/ADT/SmallVector.h"
13#include "mlir/Interfaces/MemorySlotOpInterfaces.cpp.inc"
14#include "mlir/Interfaces/MemorySlotTypeInterfaces.cpp.inc"
20static std::optional<MemorySlot>
23 if (aliasPtr == rootSlot.
ptr)
25 auto it = aliasMap.find(aliasPtr);
26 if (it == aliasMap.end())
28 return it->second.slot;
34 for (
OpOperand &operand : aliaser->getOpOperands()) {
35 std::optional<MemorySlot> parentSlot =
40 aliaser.getPromotableSlotAliases(operand, *parentSlot, newSlots);
46std::optional<MemorySlot>
51 if (
auto memOp = dyn_cast<PromotableMemOpInterface>(op);
52 memOp && memOp.ownsWrappedBlockingUses()) {
56 "an op owning wrapped blocking uses must have one single-block "
57 "region holding a wrapped PromotableMemOpInterface op and a "
63 if (std::optional<MemorySlot> slot =
73 if (
auto memOp = dyn_cast<PromotableMemOpInterface>(op);
74 memOp && memOp.ownsWrappedBlockingUses()) {
78 "an op owning wrapped blocking uses must have one single-block "
79 "region holding a wrapped PromotableMemOpInterface op and a "
86 std::optional<MemorySlot> slot =
getParentSlot(operand, rootSlot, aliasMap);
89 if (uniqueAliasPtr && uniqueAliasPtr != slot->ptr)
91 uniqueAliasPtr = slot->ptr;
100 PromotableAliaserInterface aliaser;
109static std::optional<SmallVector<ChainStep>>
114 while (current != rootSlot.
ptr) {
115 auto it = aliasMap.find(current);
116 if (it == aliasMap.end())
118 OpOperand *operand = it->second.aliasedSlotPointerOperand;
119 auto aliaser = cast<PromotableAliaserInterface>(operand->
getOwner());
120 std::optional<MemorySlot> parent =
124 chain.push_back(ChainStep{aliaser, operand, *parent, it->second.slot});
125 current = operand->
get();
135 std::optional<SmallVector<ChainStep>> chain =
139 Value current = slotValue;
141 for (ChainStep &step : llvm::reverse(*chain)) {
142 current = step.aliaser.projectSlotValueToAliasValue(
143 *step.aliasedSlotPointerOperand, step.parentSlot, step.aliasSlot,
153 Value rootReachingDef,
157 std::optional<SmallVector<ChainStep>> chainOpt =
168 Value current = rootReachingDef;
169 for (
int i =
static_cast<int>(chain.size()) - 1; i >= 0; --i) {
170 perStepReachingDef[i] = current;
171 current = chain[i].aliaser.projectSlotValueToAliasValue(
172 *chain[i].aliasedSlotPointerOperand, chain[i].parentSlot,
173 chain[i].aliasSlot, current, builder);
180 current = aliasValue;
181 for (
size_t i = 0; i < chain.size(); ++i) {
182 current = chain[i].aliaser.projectAliasValueToSlotValue(
183 *chain[i].aliasedSlotPointerOperand, chain[i].parentSlot,
184 chain[i].aliasSlot, current, perStepReachingDef[i], builder);
static std::optional< MemorySlot > getParentSlot(Value aliasPtr, const MemorySlot &rootSlot, const PromotableAliasMap &aliasMap)
Returns the slot describing aliasPtr: rootSlot if it is the root, the entry in aliasMap if it's a kno...
static std::optional< SmallVector< ChainStep > > buildAliasChain(const MemorySlot &aliasSlot, const MemorySlot &rootSlot, const PromotableAliasMap &aliasMap)
Walks from aliasSlot back to rootSlot via aliasMap.
OpListType & getOperations()
IRValueT get() const
Return the current value being used by this operand.
This class helps build Operations.
This class represents an operand of an operation.
Operation is the basic unit of execution within MLIR.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
unsigned getNumRegions()
Returns the number of regions held by this operation.
operand_range getOperands()
Returns an iterator on the underlying Value's.
bool hasOneBlock()
Return true if this region has exactly one block.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getOwner() const
Return the owner of this operand.
Include the generated interface declarations.
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.
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::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...
Represents a slot in memory.
Value ptr
Pointer to the memory slot, used by operations to refer to it.