MLIR 24.0.0git
MemorySlotInterfaces.h
Go to the documentation of this file.
1//===-- Mem2RegInterfaces.h - Mem2Reg interfaces ----------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef MLIR_INTERFACES_MEMORYSLOTINTERFACES_H
10#define MLIR_INTERFACES_MEMORYSLOTINTERFACES_H
11
12#include "mlir/IR/Dominance.h"
14
15#include "llvm/ADT/DenseMap.h"
16
17namespace mlir {
18
19/// Represents a slot in memory. This is generated by an allocating operation
20/// (for example alloca).
21struct MemorySlot {
22 /// Pointer to the memory slot, used by operations to refer to it.
24 /// Type of the value contained in the slot.
26};
27
28/// Memory slot attached with information about its destructuring procedure.
30 /// Maps an index within the memory slot to the corresponding subelement type.
32};
33
34/// Returned by operation promotion logic requesting the deletion of an
35/// operation.
36enum class DeletionKind {
37 /// Keep the operation after promotion.
39 /// Delete the operation after promotion.
41};
42
43} // namespace mlir
44
45#include "mlir/Interfaces/MemorySlotOpInterfaces.h.inc"
46#include "mlir/Interfaces/MemorySlotTypeInterfaces.h.inc"
47
48namespace mlir {
49
50/// An entry in a `PromotableAliasMap`: the memory slot defined by an aliaser
51/// operation and its source operand.
53 /// The slot defined by the aliaser (its `ptr` is the map key).
55 /// The aliaser operand whose value is the parent slot's pointer.
57};
58
59/// Maps an alias slot pointer (a result of a `PromotableAliaserInterface` op)
60/// reachable from a root slot to its `PromotableSlotAliasInfo`.
62 llvm::SmallDenseMap<Value, PromotableSlotAliasInfo, 4>;
63
64/// Populates `aliasMap` with alias entries produced by `aliaser` for operands
65/// that already alias `rootSlot`. This should be called during a forward slice
66/// traversal from `rootSlot.ptr` to ensure topological ordering.
67void populatePromotableAliasMap(PromotableAliaserInterface aliaser,
68 const MemorySlot &rootSlot,
69 PromotableAliasMap &aliasMap);
70
71/// Returns a `MemorySlot` for the operand of `op` that aliases `rootSlot.ptr`
72/// (either the root itself or a known entry in `aliasMap`), providing the
73/// alias's element type. Returns `nullopt` if no operand of `op` reaches
74/// `rootSlot`. If `op` reaches `rootSlot` through multiple distinct aliases
75/// (e.g., a memcpy between two aliases of the same root), the result is one
76/// of them; use `referencesAtMostOneAliasOfSlot` to rule this out.
77/// If `op` owns its wrapped blocking uses (e.g., `vector.mask` wrapping a
78/// `vector.transfer_read`), the wrapped operation's operands are considered
79/// instead.
80std::optional<MemorySlot> getOpAliasSlot(Operation *op,
81 const MemorySlot &rootSlot,
82 const PromotableAliasMap &aliasMap);
83
84/// Returns true if `op`'s operands reach `rootSlot` through at most one
85/// distinct alias pointer (the root itself or a single `aliasMap` entry).
86/// Multiple operands referencing the same alias are allowed. This is used to
87/// guard `PromotableMemOpInterface` calls, which assume a single slot per
88/// operation. If `op` owns its wrapped blocking uses (e.g., `vector.mask`
89/// wrapping a `vector.transfer_read`), the wrapped operation's operands are
90/// considered instead.
92 const PromotableAliasMap &aliasMap);
93
94/// Walks the alias chain from `rootSlot` down to `aliasSlot`. Calls
95/// `projectSlotValueToAliasValue` at each step to convert `slotValue`
96/// (initially the root slot's value) to `aliasSlot`'s value. Returns a null
97/// value if any projection fails.
98Value convertSlotValueToAliasValue(Value slotValue, const MemorySlot &aliasSlot,
99 const MemorySlot &rootSlot,
100 const PromotableAliasMap &aliasMap,
101 OpBuilder &builder);
102
103/// Walks the alias chain from `aliasSlot` back up to `rootSlot`. Calls
104/// `projectAliasValueToSlotValue` at each step to convert `aliasValue`
105/// (initially `aliasSlot`'s value) to the root slot's value.
106/// `rootReachingDef` is the current value of the root slot; it is projected
107/// down to each intermediate slot to provide the reaching definition required
108/// by partial sub-aliases.
110 const MemorySlot &aliasSlot,
111 Value rootReachingDef,
112 const MemorySlot &rootSlot,
113 const PromotableAliasMap &aliasMap,
114 OpBuilder &builder);
115
116} // namespace mlir
117
118#endif // MLIR_INTERFACES_MEMORYSLOTINTERFACES_H
This class helps build Operations.
Definition Builders.h:210
This class represents an operand of an operation.
Definition Value.h:256
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
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.
DeletionKind
Returned by operation promotion logic requesting the deletion of an operation.
@ Keep
Keep the operation after promotion.
@ Delete
Delete the operation after promotion.
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
Definition LLVM.h:123
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...
Memory slot attached with information about its destructuring procedure.
DenseMap< Attribute, Type > subelementTypes
Maps an index within the memory slot to the corresponding subelement type.
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.
An entry in a PromotableAliasMap: the memory slot defined by an aliaser operation and its source oper...
OpOperand * aliasedSlotPointerOperand
The aliaser operand whose value is the parent slot's pointer.
MemorySlot slot
The slot defined by the aliaser (its ptr is the map key).