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>
50 if (std::optional<MemorySlot> slot =
61 std::optional<MemorySlot> slot =
getParentSlot(operand, rootSlot, aliasMap);
64 if (uniqueAliasPtr && uniqueAliasPtr != slot->ptr)
66 uniqueAliasPtr = slot->ptr;
75 PromotableAliaserInterface aliaser;
84static std::optional<SmallVector<ChainStep>>
89 while (current != rootSlot.
ptr) {
90 auto it = aliasMap.find(current);
91 if (it == aliasMap.end())
93 OpOperand *operand = it->second.aliasedSlotPointerOperand;
94 auto aliaser = cast<PromotableAliaserInterface>(operand->
getOwner());
95 std::optional<MemorySlot> parent =
99 chain.push_back(ChainStep{aliaser, operand, *parent, it->second.slot});
100 current = operand->
get();
110 std::optional<SmallVector<ChainStep>> chain =
114 Value current = slotValue;
116 for (ChainStep &step : llvm::reverse(*chain)) {
117 current = step.aliaser.projectSlotValueToAliasValue(
118 *step.aliasedSlotPointerOperand, step.parentSlot, step.aliasSlot,
128 Value rootReachingDef,
132 std::optional<SmallVector<ChainStep>> chainOpt =
143 Value current = rootReachingDef;
144 for (
int i =
static_cast<int>(chain.size()) - 1; i >= 0; --i) {
145 perStepReachingDef[i] = current;
146 current = chain[i].aliaser.projectSlotValueToAliasValue(
147 *chain[i].aliasedSlotPointerOperand, chain[i].parentSlot,
148 chain[i].aliasSlot, current, builder);
155 current = aliasValue;
156 for (
size_t i = 0; i < chain.size(); ++i) {
157 current = chain[i].aliaser.projectAliasValueToSlotValue(
158 *chain[i].aliasedSlotPointerOperand, chain[i].parentSlot,
159 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.
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.
operand_range getOperands()
Returns an iterator on the underlying Value's.
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.