11 #include "llvm/ADT/SmallPtrSet.h"
20 #include "mlir/Interfaces/SideEffectInterfaces.cpp.inc"
27 return isa<Allocate, Free, Read, Write>(effect);
45 while (!effectingOps.empty()) {
46 Operation *op = effectingOps.pop_back_val();
50 bool hasRecursiveEffects =
52 if (hasRecursiveEffects) {
54 for (
auto &block : region) {
55 for (
auto &nestedOp : block)
56 effectingOps.push_back(&nestedOp);
63 if (
auto effectInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
67 effectInterface.getEffects(effects);
72 if (isa<MemoryEffects::Allocate>(it.getEffect()) && it.getValue() &&
73 it.getValue().getDefiningOp() == op)
74 allocResults.insert(it.getValue());
76 if (!llvm::all_of(effects, [&allocResults](
80 if (allocResults.contains(it.
getValue()))
83 return isa<MemoryEffects::Read>(it.
getEffect());
92 if (hasRecursiveEffects)
105 template <
typename EffectTy>
107 auto memOp = dyn_cast<MemoryEffectOpInterface>(op);
111 memOp.getEffects(effects);
112 bool hasSingleEffectOnVal =
false;
116 for (
auto &effect : effects) {
117 if (value && effect.getValue() != value)
119 hasSingleEffectOnVal = isa<EffectTy>(effect.getEffect());
120 if (!hasSingleEffectOnVal)
123 return hasSingleEffectOnVal;
126 template bool mlir::hasSingleEffect<MemoryEffects::Allocate>(
Operation *,
132 template <
typename... EffectTys>
134 auto memOp = dyn_cast<MemoryEffectOpInterface>(op);
138 memOp.getEffects(effects);
140 if (value && effect.
getValue() != value)
142 return isa<EffectTys...>(effect.
getEffect());
150 mlir::hasEffect<MemoryEffects::Write, MemoryEffects::Free>(
Operation *,
Value);
159 if (
auto memInterface = dyn_cast<MemoryEffectOpInterface>(op)) {
160 if (!memInterface.hasNoEffect())
183 auto conditionallySpeculatable = dyn_cast<ConditionallySpeculatable>(op);
184 if (!conditionallySpeculatable)
187 switch (conditionallySpeculatable.getSpeculatability()) {
203 llvm_unreachable(
"Unhandled enum in mlir::isSpeculatable!");
static bool wouldOpBeTriviallyDeadImpl(Operation *rootOp)
Internal implementation of mlir::wouldOpBeTriviallyDead that also considers terminator operations as ...
This trait indicates that the memory effects of an operation includes the effects of operations neste...
This class provides the API for ops that are known to be terminators.
Operation is the basic unit of execution within MLIR.
bool use_empty()
Returns true if this operation has no uses.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
bool mightHaveTrait()
Returns true if the operation might have the provided trait.
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class represents a specific instance of an effect.
EffectT * getEffect() const
Return the effect being applied.
Value getValue() const
Return the value the effect is applied on, or nullptr if there isn't a known value being affected.
This class represents a base class for a specific effect type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
constexpr auto RecursivelySpeculatable
constexpr auto Speculatable
constexpr auto NotSpeculatable
This header declares functions that assist transformations in the MemRef dialect.
bool hasEffect(Operation *op, Value value=nullptr)
Returns true if op has an effect of type EffectTy on value.
bool isPure(Operation *op)
Returns true if the given operation is pure, i.e., is speculatable that does not touch memory.
bool isMemoryEffectFree(Operation *op)
Returns true if the given operation is free of memory effects.
bool wouldOpBeTriviallyDead(Operation *op)
Return true if the given operation would be dead if unused, and has no side effects on memory that wo...
bool hasSingleEffect(Operation *op, Value value=nullptr)
Returns true if op has only an effect of type EffectTy (and of no other type) on value.
bool isSpeculatable(Operation *op)
Returns true if the given operation is speculatable, i.e.
bool isOpTriviallyDead(Operation *op)
Return true if the given operation is unused, and has no side effects on memory that prevent erasing.
static bool classof(const SideEffects::Effect *effect)
Include the definitions of the side effect interfaces.