14 #ifndef MLIR_INTERFACES_SIDEEFFECTINTERFACES_H
15 #define MLIR_INTERFACES_SIDEEFFECTINTERFACES_H
20 namespace SideEffects {
29 template <
typename DerivedEffect,
typename BaseEffect = Effect>
30 class Base :
public BaseEffect {
38 static bool classof(const ::mlir::SideEffects::Effect *effect) {
43 static DerivedEffect *
get() {
44 return BaseEffect::template get<DerivedEffect>();
56 template <
typename DerivedEffect>
57 static DerivedEffect *
get() {
58 static_assert(std::is_base_of<Effect, DerivedEffect>::value,
59 "expected DerivedEffect to inherit from Effect");
61 static DerivedEffect instance;
84 template <
typename DerivedResource,
typename BaseResource = Resource>
85 class Base :
public BaseResource {
90 static DerivedResource *
get() {
91 static DerivedResource instance;
123 StringRef
getName() final {
return "<Default>"; }
130 StringRef
getName() final {
return "AutomaticAllocationScope"; }
138 template <
typename EffectT>
142 : effect(effect), resource(resource), stage(0),
143 effectOnFullRegion(false) {}
146 : effect(effect), resource(resource), stage(stage),
147 effectOnFullRegion(effectOnFullRegion) {}
148 template <
typename T,
150 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
154 : effect(effect), resource(resource), value(value), stage(0),
155 effectOnFullRegion(false) {}
156 template <
typename T,
158 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
162 : effect(effect), resource(resource), value(value), stage(stage),
163 effectOnFullRegion(effectOnFullRegion) {}
166 : effect(effect), resource(resource), value(symbol), stage(0),
167 effectOnFullRegion(false) {}
169 bool effectOnFullRegion,
171 : effect(effect), resource(resource), value(symbol), stage(stage),
172 effectOnFullRegion(effectOnFullRegion) {}
175 : effect(effect), resource(resource), parameters(parameters), stage(0),
176 effectOnFullRegion(false) {}
178 bool effectOnFullRegion,
180 : effect(effect), resource(resource), parameters(parameters),
181 stage(stage), effectOnFullRegion(effectOnFullRegion) {}
182 template <
typename T,
184 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
188 : effect(effect), resource(resource), value(value),
189 parameters(parameters), stage(0), effectOnFullRegion(false) {}
190 template <
typename T,
192 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
195 bool effectOnFullRegion,
197 : effect(effect), resource(resource), value(value),
198 parameters(parameters), stage(stage),
199 effectOnFullRegion(effectOnFullRegion) {}
202 : effect(effect), resource(resource), value(symbol),
203 parameters(parameters), stage(0), effectOnFullRegion(false) {}
205 int stage,
bool effectOnFullRegion,
207 : effect(effect), resource(resource), value(symbol),
208 parameters(parameters), stage(stage),
209 effectOnFullRegion(effectOnFullRegion) {}
217 if (!value || llvm::isa_and_present<SymbolRefAttr>(value)) {
220 if (
OpOperand *operand = llvm::dyn_cast_if_present<OpOperand *>(value)) {
221 return operand->get();
223 if (
OpResult result = llvm::dyn_cast_if_present<OpResult>(value)) {
226 return cast_if_present<BlockArgument>(value);
231 template <
typename T,
233 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
236 return value ? dyn_cast_if_present<T>(value) :
nullptr;
242 return value ? llvm::dyn_cast_if_present<SymbolRefAttr>(value)
279 bool effectOnFullRegion;
283 namespace Speculation {
315 template <
typename ConcreteType>
317 :
public TraitBase<ConcreteType, HasRecursiveMemoryEffects> {};
323 template <
typename ConcreteType>
325 :
public TraitBase<ConcreteType, RecursivelySpeculatableImplTrait> {
334 template <
typename ConcreteType>
336 :
public TraitBase<ConcreteType, AlwaysSpeculatableImplTrait> {
348 namespace MemoryEffects {
354 template <
typename DerivedEffect>
387 template <
typename EffectTy>
392 template <
typename EffectTy>
397 template <
typename ValueTy,
typename EffectTy>
401 template <
typename... EffectTys>
405 template <
typename... EffectTys>
410 template <
typename ValueTy,
typename... EffectTys>
444 std::optional<llvm::SmallVector<MemoryEffects::EffectInstance>>
467 #include "mlir/Interfaces/SideEffectInterfaces.h.inc"
Attributes are known-constant values of operations.
This class represents an operand of an operation.
This is a value defined by a result of an operation.
This trait indicates that the memory effects of an operation includes the effects of operations neste...
Helper class for implementing traits.
Operation is the basic unit of execution within MLIR.
This class represents a specific instance of an effect.
EffectInstance(EffectT *effect, T value, Attribute parameters, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, T value, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, SymbolRefAttr symbol, Attribute parameters, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
bool getEffectOnFullRegion() const
Return if this side effect act on every single value of resource.
int getStage() const
Return the effect happen stage.
EffectInstance(EffectT *effect, SymbolRefAttr symbol, Attribute parameters, Resource *resource=DefaultResource::get())
T getEffectValue() const
Returns the OpOperand effect is applied on, or nullptr if there isn't a known value being effected.
EffectInstance(EffectT *effect, SymbolRefAttr symbol, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, T value, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, Resource *resource=DefaultResource::get())
SymbolRefAttr getSymbolRef() const
Return the symbol reference the effect is applied on, or nullptr if there isn't a known smbol being a...
EffectInstance(EffectT *effect, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, Attribute parameters, Resource *resource=DefaultResource::get())
Resource * getResource() const
Return the resource that the effect applies to.
EffectInstance(EffectT *effect, T value, Attribute parameters, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
Attribute getParameters() const
Return the parameters of the effect, if any.
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.
EffectInstance(EffectT *effect, Attribute parameters, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, SymbolRefAttr symbol, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
This base class is used for derived effects that are non-parametric.
static TypeID getEffectID()
Return the unique identifier for the base effects class.
static bool classof(const ::mlir::SideEffects::Effect *effect)
'classof' used to support llvm style cast functionality.
static DerivedEffect * get()
Returns a unique instance for the derived effect class.
This class represents a base class for a specific effect type.
TypeID getEffectID() const
Return the unique identifier for the base effects class.
static DerivedEffect * get()
Returns a unique instance for the given effect class.
This base class is used for derived effects that are non-parametric.
static DerivedResource * get()
Returns a unique instance for the given effect class.
static TypeID getResourceID()
Return the unique identifier for the base resource class.
static bool classof(const Resource *resource)
'classof' used to support llvm style cast functionality.
This class represents a specific resource that an effect applies to.
TypeID getResourceID() const
Return the unique identifier for the base resource class.
virtual StringRef getName()=0
Return a string name of the resource.
virtual ~Resource()=default
This class provides an efficient unique identifier for a specific C++ type.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
constexpr auto RecursivelySpeculatable
Speculatability
This enum is returned from the getSpeculatability method in the ConditionallySpeculatable op interfac...
@ RecursivelySpeculatable
@ NotSpeculatable
The Operation in question cannot be speculatively executed.
constexpr auto Speculatable
constexpr auto NotSpeculatable
Include the generated interface declarations.
bool hasSingleEffect(Operation *op)
Returns true if op has only an effect of type EffectTy.
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 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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
std::optional< llvm::SmallVector< MemoryEffects::EffectInstance > > getEffectsRecursively(Operation *rootOp)
Returns the side effects of an operation.
bool hasEffect(Operation *op)
Returns true if op has an effect of type EffectTy.
The following effect indicates that the operation allocates from some resource.
This class represents the base class used for memory effects.
static bool classof(const SideEffects::Effect *effect)
Include the definitions of the side effect interfaces.
The following effect indicates that the operation frees some resource that has been allocated.
The following effect indicates that the operation reads from some resource.
The following effect indicates that the operation writes to some resource.
This trait marks an op (which must be tagged as implementing the ConditionallySpeculatable interface)...
Speculation::Speculatability getSpeculatability()
This trait marks an op (which must be tagged as implementing the ConditionallySpeculatable interface)...
Speculation::Speculatability getSpeculatability()
An automatic allocation-scope resource that is valid in the context of a parent AutomaticAllocationSc...
StringRef getName() final
Return a string name of the resource.
A conservative default resource kind.
StringRef getName() final
Return a string name of the resource.