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) {}
145 : effect(effect), resource(resource), value(value) {}
148 : effect(effect), resource(resource), value(symbol) {}
151 : effect(effect), resource(resource), parameters(parameters) {}
154 : effect(effect), resource(resource), value(value),
155 parameters(parameters) {}
158 : effect(effect), resource(resource), value(symbol),
159 parameters(parameters) {}
171 return value ? llvm::dyn_cast_if_present<SymbolRefAttr>(value) : SymbolRefAttr();
197 namespace Speculation {
229 template <
typename ConcreteType>
231 :
public TraitBase<ConcreteType, HasRecursiveMemoryEffects> {};
237 template <
typename ConcreteType>
239 :
public TraitBase<ConcreteType, RecursivelySpeculatableImplTrait> {
248 template <
typename ConcreteType>
250 :
public TraitBase<ConcreteType, AlwaysSpeculatableImplTrait> {
262 namespace MemoryEffects {
268 template <
typename DerivedEffect>
303 template <
typename EffectTy>
309 template <
typename... EffectTys>
353 #include "mlir/Interfaces/SideEffectInterfaces.h.inc"
Attributes are known-constant values of operations.
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, Value value, Attribute parameters, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, Value value, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, SymbolRefAttr symbol, Attribute parameters, Resource *resource=DefaultResource::get())
EffectInstance(EffectT *effect, SymbolRefAttr symbol, 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, Attribute parameters, Resource *resource=DefaultResource::get())
Resource * getResource() const
Return the resource that the effect applies to.
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.
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
This header declares functions that assit 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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
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.