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) {}
150 : effect(effect), resource(resource), value(value), stage(0),
151 effectOnFullRegion(false) {}
153 bool effectOnFullRegion,
155 : effect(effect), resource(resource), value(value), stage(stage),
156 effectOnFullRegion(effectOnFullRegion) {}
159 : effect(effect), resource(resource), value(symbol), stage(0),
160 effectOnFullRegion(false) {}
162 bool effectOnFullRegion,
164 : effect(effect), resource(resource), value(symbol), stage(stage),
165 effectOnFullRegion(effectOnFullRegion) {}
168 : effect(effect), resource(resource), parameters(parameters), stage(0),
169 effectOnFullRegion(false) {}
171 bool effectOnFullRegion,
173 : effect(effect), resource(resource), parameters(parameters),
174 stage(stage), effectOnFullRegion(effectOnFullRegion) {}
177 : effect(effect), resource(resource), value(value),
178 parameters(parameters), stage(0), effectOnFullRegion(false) {}
180 bool effectOnFullRegion,
182 : effect(effect), resource(resource), value(value),
183 parameters(parameters), stage(stage),
184 effectOnFullRegion(effectOnFullRegion) {}
187 : effect(effect), resource(resource), value(symbol),
188 parameters(parameters), stage(0), effectOnFullRegion(false) {}
190 int stage,
bool effectOnFullRegion,
192 : effect(effect), resource(resource), value(symbol),
193 parameters(parameters), stage(stage),
194 effectOnFullRegion(effectOnFullRegion) {}
202 return value ? llvm::dyn_cast_if_present<Value>(value) :
Value();
208 return value ? llvm::dyn_cast_if_present<SymbolRefAttr>(value)
244 bool effectOnFullRegion;
248 namespace Speculation {
280 template <
typename ConcreteType>
282 :
public TraitBase<ConcreteType, HasRecursiveMemoryEffects> {};
288 template <
typename ConcreteType>
290 :
public TraitBase<ConcreteType, RecursivelySpeculatableImplTrait> {
299 template <
typename ConcreteType>
301 :
public TraitBase<ConcreteType, AlwaysSpeculatableImplTrait> {
313 namespace MemoryEffects {
319 template <
typename DerivedEffect>
354 template <
typename EffectTy>
360 template <
typename... EffectTys>
394 std::optional<llvm::SmallVector<MemoryEffects::EffectInstance>>
417 #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, int stage, bool effectOnFullRegion, Resource *resource=DefaultResource::get())
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, 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())
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, 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.
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, Value value, 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 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...
std::optional< llvm::SmallVector< MemoryEffects::EffectInstance > > getEffectsRecursively(Operation *rootOp)
Returns the side effects of an operation.
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.