MLIR 23.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"
15
16#include "llvm/ADT/DenseMap.h"
17
18namespace mlir {
19
20/// Represents a slot in memory. This is generated by an allocating operation
21/// (for example alloca).
22struct MemorySlot {
23 /// Pointer to the memory slot, used by operations to refer to it.
25 /// Type of the value contained in the slot.
27};
28
29/// Memory slot attached with information about its destructuring procedure.
31 /// Maps an index within the memory slot to the corresponding subelement type.
33};
34
35/// Returned by operation promotion logic requesting the deletion of an
36/// operation.
37enum class DeletionKind {
38 /// Keep the operation after promotion.
40 /// Delete the operation after promotion.
42};
43
44} // namespace mlir
45
46#include "mlir/Interfaces/MemorySlotOpInterfaces.h.inc"
47#include "mlir/Interfaces/MemorySlotTypeInterfaces.h.inc"
48
49namespace mlir {
50
51/// An entry in a `PromotableAliasMap`: the memory slot defined by an aliaser
52/// operation and its source operand.
54 /// The slot defined by the aliaser (its `ptr` is the map key).
56 /// The aliaser operand whose value is the parent slot's pointer.
58};
59
60/// Maps an alias slot pointer (a result of a `PromotableAliaserInterface` op)
61/// reachable from a root slot to its `PromotableSlotAliasInfo`.
63 llvm::SmallDenseMap<Value, PromotableSlotAliasInfo, 4>;
64
65/// Populates `aliasMap` with alias entries produced by `aliaser` for operands
66/// that already alias `rootSlot`. This should be called during a forward slice
67/// traversal from `rootSlot.ptr` to ensure topological ordering.
68void populatePromotableAliasMap(PromotableAliaserInterface aliaser,
69 const MemorySlot &rootSlot,
70 PromotableAliasMap &aliasMap);
71
72/// Returns a `MemorySlot` for the operand of `op` that aliases `rootSlot.ptr`
73/// (either the root itself or a known entry in `aliasMap`), providing the
74/// alias's element type. Returns `nullopt` if no operand of `op` reaches
75/// `rootSlot`. If `op` reaches `rootSlot` through multiple distinct aliases
76/// (e.g., a memcpy between two aliases of the same root), the result is one
77/// of them; use `referencesAtMostOneAliasOfSlot` to rule this out.
78std::optional<MemorySlot> getOpAliasSlot(Operation *op,
79 const MemorySlot &rootSlot,
80 const PromotableAliasMap &aliasMap);
81
82/// Returns true if `op`'s operands reach `rootSlot` through at most one
83/// distinct alias pointer (the root itself or a single `aliasMap` entry).
84/// Multiple operands referencing the same alias are allowed. This is used to
85/// guard `PromotableMemOpInterface` calls, which assume a single slot per
86/// operation.
88 const PromotableAliasMap &aliasMap);
89
90/// Walks the alias chain from `rootSlot` down to `aliasSlot`. Calls
91/// `projectSlotValueToAliasValue` at each step to convert `slotValue`
92/// (initially the root slot's value) to `aliasSlot`'s value. Returns a null
93/// value if any projection fails.
94Value convertSlotValueToAliasValue(Value slotValue, const MemorySlot &aliasSlot,
95 const MemorySlot &rootSlot,
96 const PromotableAliasMap &aliasMap,
97 OpBuilder &builder);
98
99/// Walks the alias chain from `aliasSlot` back up to `rootSlot`. Calls
100/// `projectAliasValueToSlotValue` at each step to convert `aliasValue`
101/// (initially `aliasSlot`'s value) to the root slot's value.
102/// `rootReachingDef` is the current value of the root slot; it is projected
103/// down to each intermediate slot to provide the reaching definition required
104/// by partial sub-aliases.
106 const MemorySlot &aliasSlot,
107 Value rootReachingDef,
108 const MemorySlot &rootSlot,
109 const PromotableAliasMap &aliasMap,
110 OpBuilder &builder);
111
112} // namespace mlir
113
114#endif // MLIR_INTERFACES_MEMORYSLOTINTERFACES_H
This class helps build Operations.
Definition Builders.h:209
This class represents an operand of an operation.
Definition Value.h:254
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:120
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.
Value ptr
Pointer to the memory slot, used by operations to refer to it.
Type elemType
Type of the value contained in the slot.
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).