MLIR 24.0.0git
SideEffectInterfaces.h
Go to the documentation of this file.
1//===- SideEffectInterfaces.h - SideEffect in MLIR --------------*- 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// This file contains traits, interfaces, and utilities for defining and
10// querying the side effects of an operation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef MLIR_INTERFACES_SIDEEFFECTINTERFACES_H
15#define MLIR_INTERFACES_SIDEEFFECTINTERFACES_H
16
18#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/MapVector.h"
20#include "llvm/ADT/PointerUnion.h"
21#include "llvm/ADT/Twine.h"
22#include <cstdint>
23
24namespace mlir {
25namespace SideEffects {
26//===----------------------------------------------------------------------===//
27// Effects
28//===----------------------------------------------------------------------===//
29
30/// This class represents a base class for a specific effect type.
31class Effect {
32public:
33 /// This base class is used for derived effects that are non-parametric.
34 template <typename DerivedEffect, typename BaseEffect = Effect>
35 class Base : public BaseEffect {
36 public:
38
39 /// Return the unique identifier for the base effects class.
41
42 /// 'classof' used to support llvm style cast functionality.
43 static bool classof(const ::mlir::SideEffects::Effect *effect) {
44 return effect->getEffectID() == BaseT::getEffectID();
45 }
46
47 /// Returns a unique instance for the derived effect class.
48 static DerivedEffect *get() {
49 return BaseEffect::template get<DerivedEffect>();
50 }
51 using BaseEffect::get;
52
53 protected:
54 Base() : BaseEffect(BaseT::getEffectID()) {}
55 };
56
57 /// Return the unique identifier for the base effects class.
58 TypeID getEffectID() const { return id; }
59
60 /// Returns a unique instance for the given effect class.
61 template <typename DerivedEffect>
62 static DerivedEffect *get() {
63 static_assert(std::is_base_of<Effect, DerivedEffect>::value,
64 "expected DerivedEffect to inherit from Effect");
65
66 static DerivedEffect instance;
67 return &instance;
68 }
69
70protected:
71 Effect(TypeID id) : id(id) {}
72
73private:
74 /// The id of the derived effect class.
75 TypeID id;
76};
77
78//===----------------------------------------------------------------------===//
79// Resources
80//===----------------------------------------------------------------------===//
81
82/// This class represents a specific resource that an effect applies to. This
83/// class represents an abstract interface for a given resource. Resources
84/// form a hierarchy via getParent(); disjointness (isDisjointFrom) is used to
85/// determine whether effects can conflict.
86///
87/// Scope: The resource hierarchy is for disjointness of *abstract* resources
88/// (e.g. addressable memory vs. runtime state). It is deliberately *not*
89/// intended for fine-grained regions with specific addresses/sizes, or for
90/// alias classes / offset-based disambiguation; such concerns are out of scope
91/// and should be handled by alias analysis or other mechanisms.
92class Resource {
93public:
94 virtual ~Resource() = default;
95
96 /// This base class is used for derived effects that are non-parametric.
97 template <typename DerivedResource, typename BaseResource = Resource>
98 class Base : public BaseResource {
99 public:
100 /// Use the current instantiation so get()/getResourceID() refer to this
101 /// hierarchy's singleton, not Base<DerivedResource, Resource>'s.
103
104 /// Returns a unique instance for the given effect class.
105 static DerivedResource *get() {
106 static DerivedResource instance;
107 return &instance;
108 }
109
110 /// Return the unique identifier for the base resource class.
112
113 /// 'classof' used to support llvm style cast functionality. Returns true
114 /// iff the resource is the same as or a descendant of this resource type
115 /// in the hierarchy (so isa/cast work for ancestor checks).
116 static bool classof(const Resource *resource) {
117 return resource->isSubresourceOf(BaseT::get());
118 }
119
120 protected:
121 Base() : BaseResource(BaseT::getResourceID()) {}
122 /// Constructor for use when this type is used as a parent (BaseResource);
123 /// allows the derived resource to pass its TypeID so the hierarchy is
124 /// correct.
125 Base(TypeID id) : BaseResource(id) {}
126 };
127
128 /// Return the unique identifier for the base resource class.
129 TypeID getResourceID() const { return id; }
130
131 /// Return a string name of the resource.
132 virtual StringRef getName() const = 0;
133
134 /// Return the parent resource in the hierarchy.
135 virtual Resource *getParent() const;
136
137 /// Returns true if this resource is addressable (effects on it can alias
138 /// pointer-based memory). Default is true.
139 virtual bool isAddressable() const { return true; }
140
141 /// Returns true if this resource is a subresource of (or equal to) another.
142 bool isSubresourceOf(const Resource *other) const {
143 for (const Resource *r = this; r != nullptr; r = r->getParent()) {
144#ifdef EXPENSIVE_CHECKS
145 r->verifyImmediateParentAddressability();
146#endif // EXPENSIVE_CHECKS
147 if (r == other)
148 return true;
149 }
150 return false;
151 }
152
153 /// Returns true if this resource is disjoint from another. Two resources are
154 /// disjoint if neither is an ancestor of the other.
155 bool isDisjointFrom(const Resource *other) const {
156 return !isSubresourceOf(other) && !other->isSubresourceOf(this);
157 }
158
159protected:
160 Resource(TypeID id) : id(id) {}
161
162private:
163#ifdef EXPENSIVE_CHECKS
164 /// Verifies the single-link invariant: an addressable resource must not have
165 /// a non-addressable parent. Used from isSubresourceOf() under
166 /// EXPENSIVE_CHECKS so the invariant is checked when the hierarchy is
167 /// traversed.
168 void verifyImmediateParentAddressability() const {
169 Resource *parent = getParent();
170 if (parent && isAddressable() && !parent->isAddressable())
171 llvm::report_fatal_error(
172 llvm::Twine("Resource '") + getName() +
173 "' is addressable but has non-addressable parent '" +
174 parent->getName() + "'");
175 }
176#endif // EXPENSIVE_CHECKS
177
178 /// The id of the derived resource class.
179 TypeID id;
180};
181
182/// The default resource kind. It serves as the root of the resource hierarchy:
183/// all resources that do not override getParent() have DefaultResource as their
184/// parent.
185struct DefaultResource : public Resource::Base<DefaultResource> {
186 DefaultResource() = default;
187 StringRef getName() const override { return "<Default>"; }
188 Resource *getParent() const override { return nullptr; }
189
190protected:
191 /// For use when this type is the parent of another resource; allows the
192 /// derived resource to pass its TypeID so the hierarchy is correct.
194};
195
196/// All resources that do not override getParent() have DefaultResource
197/// as their parent.
199
200/// An automatic allocation-scope resource that is valid in the context of a
201/// parent AutomaticAllocationScope trait.
203 : public Resource::Base<AutomaticAllocationScopeResource, DefaultResource> {
204 StringRef getName() const final { return "AutomaticAllocationScope"; }
205 Resource *getParent() const override { return DefaultResource::get(); }
206};
207
208/// This class represents a specific instance of an effect. It contains the
209/// effect being applied, a resource that corresponds to where the effect is
210/// applied, and an optional symbol reference or value(either operand, result,
211/// or region entry argument) that the effect is applied to, and an optional
212/// parameters attribute further specifying the details of the effect.
213template <typename EffectT>
215public:
216 EffectInstance(EffectT *effect, Resource *resource = DefaultResource::get())
217 : effect(effect), resource(resource), stage(0),
218 effectOnFullRegion(false) {}
219 EffectInstance(EffectT *effect, int stage, bool effectOnFullRegion,
220 Resource *resource = DefaultResource::get())
221 : effect(effect), resource(resource), stage(stage),
222 effectOnFullRegion(effectOnFullRegion) {}
223 template <typename T,
224 std::enable_if_t<
225 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
226 bool> = true>
227 EffectInstance(EffectT *effect, T value,
228 Resource *resource = DefaultResource::get())
229 : effect(effect), resource(resource), value(value), stage(0),
230 effectOnFullRegion(false) {
231 checkResourceAllowsValue();
232 }
233 template <typename T,
234 std::enable_if_t<
235 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
236 bool> = true>
237 EffectInstance(EffectT *effect, T value, int stage, bool effectOnFullRegion,
238 Resource *resource = DefaultResource::get())
239 : effect(effect), resource(resource), value(value), stage(stage),
240 effectOnFullRegion(effectOnFullRegion) {
241 checkResourceAllowsValue();
242 }
243 EffectInstance(EffectT *effect, SymbolRefAttr symbol,
244 Resource *resource = DefaultResource::get())
245 : effect(effect), resource(resource), value(symbol), stage(0),
246 effectOnFullRegion(false) {}
247 EffectInstance(EffectT *effect, SymbolRefAttr symbol, int stage,
248 bool effectOnFullRegion,
249 Resource *resource = DefaultResource::get())
250 : effect(effect), resource(resource), value(symbol), stage(stage),
251 effectOnFullRegion(effectOnFullRegion) {}
252 EffectInstance(EffectT *effect, Attribute parameters,
253 Resource *resource = DefaultResource::get())
254 : effect(effect), resource(resource), parameters(parameters), stage(0),
255 effectOnFullRegion(false) {}
256 EffectInstance(EffectT *effect, Attribute parameters, int stage,
257 bool effectOnFullRegion,
258 Resource *resource = DefaultResource::get())
259 : effect(effect), resource(resource), parameters(parameters),
260 stage(stage), effectOnFullRegion(effectOnFullRegion) {}
261 template <typename T,
262 std::enable_if_t<
263 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
264 bool> = true>
265 EffectInstance(EffectT *effect, T value, Attribute parameters,
266 Resource *resource = DefaultResource::get())
267 : effect(effect), resource(resource), value(value),
268 parameters(parameters), stage(0), effectOnFullRegion(false) {
269 checkResourceAllowsValue();
270 }
271 template <typename T,
272 std::enable_if_t<
273 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
274 bool> = true>
275 EffectInstance(EffectT *effect, T value, Attribute parameters, int stage,
276 bool effectOnFullRegion,
277 Resource *resource = DefaultResource::get())
278 : effect(effect), resource(resource), value(value),
279 parameters(parameters), stage(stage),
280 effectOnFullRegion(effectOnFullRegion) {
281 checkResourceAllowsValue();
282 }
283 EffectInstance(EffectT *effect, SymbolRefAttr symbol, Attribute parameters,
284 Resource *resource = DefaultResource::get())
285 : effect(effect), resource(resource), value(symbol),
286 parameters(parameters), stage(0), effectOnFullRegion(false) {}
287 EffectInstance(EffectT *effect, SymbolRefAttr symbol, Attribute parameters,
288 int stage, bool effectOnFullRegion,
289 Resource *resource = DefaultResource::get())
290 : effect(effect), resource(resource), value(symbol),
291 parameters(parameters), stage(stage),
292 effectOnFullRegion(effectOnFullRegion) {}
293
294 /// Return the effect being applied.
295 EffectT *getEffect() const { return effect; }
296
297 /// Return the value the effect is applied on, or nullptr if there isn't a
298 /// known value being affected.
299 Value getValue() const {
300 if (!value || llvm::isa_and_present<SymbolRefAttr>(value)) {
301 return Value();
302 }
303 if (OpOperand *operand = llvm::dyn_cast_if_present<OpOperand *>(value)) {
304 return operand->get();
305 }
306 if (OpResult result = llvm::dyn_cast_if_present<OpResult>(value)) {
307 return result;
308 }
309 return cast_if_present<BlockArgument>(value);
310 }
311
312 /// Returns the OpOperand effect is applied on, or nullptr if there isn't a
313 /// known value being effected.
314 template <typename T,
315 std::enable_if_t<
316 llvm::is_one_of<T, OpOperand *, OpResult, BlockArgument>::value,
317 bool> = true>
318 T getEffectValue() const {
319 return value ? dyn_cast_if_present<T>(value) : nullptr;
320 }
321
322 /// Return the symbol reference the effect is applied on, or nullptr if there
323 /// isn't a known smbol being affected.
324 SymbolRefAttr getSymbolRef() const {
325 return value ? llvm::dyn_cast_if_present<SymbolRefAttr>(value)
326 : SymbolRefAttr();
327 }
328
329 /// Return the resource that the effect applies to.
330 Resource *getResource() const { return resource; }
331
332 /// Return the parameters of the effect, if any.
333 Attribute getParameters() const { return parameters; }
334
335 /// Return the effect happen stage.
336 int getStage() const { return stage; }
337
338 /// Return if this side effect act on every single value of resource.
339 bool getEffectOnFullRegion() const { return effectOnFullRegion; }
340
341private:
342 /// Effect on a non-addressable resource cannot have an associated Value.
343 void checkResourceAllowsValue() {
344 if (value && resource && !resource->isAddressable())
345 llvm::report_fatal_error(
346 llvm::Twine("EffectInstance: resource '") + resource->getName() +
347 "' is non-addressable and cannot have an associated Value");
348 }
349
350 /// The specific effect being applied.
351 EffectT *effect;
352
353 /// The resource that the given value resides in.
354 Resource *resource;
355
356 /// The Symbol, OpOperand, OpResult or BlockArgument that the effect applies
357 /// to. This is optionally null.
359
360 /// Additional parameters of the effect instance. An attribute is used for
361 /// type-safe structured storage and context-based uniquing. Concrete effects
362 /// can use this at their convenience. This is optionally null.
363 Attribute parameters;
364
365 // The stage side effect happen. Side effect with a lower stage
366 // number happen earlier than those with a higher stage number
367 int stage;
368
369 // Does this side effect act on every single value of resource.
370 bool effectOnFullRegion;
371};
372} // namespace SideEffects
373
374namespace Speculation {
375/// This enum is returned from the `getSpeculatability` method in the
376/// `ConditionallySpeculatable` op interface.
377enum class Speculatability {
378 /// The Operation in question cannot be speculatively executed. This could be
379 /// because it may invoke undefined behavior or have other side effects.
381
382 // The Operation in question can be speculatively executed. It does not have
383 // any side effects or undefined behavior.
385
386 // The Operation in question can be speculatively executed if all the
387 // operations in all attached regions can also be speculatively executed.
389};
390
395} // namespace Speculation
396
397//===----------------------------------------------------------------------===//
398// SideEffect Traits
399//===----------------------------------------------------------------------===//
400
401namespace OpTrait {
402/// This trait indicates that the memory effects of an operation includes the
403/// effects of operations nested within its regions. If the operation has no
404/// derived effects interfaces, the operation itself can be assumed to have no
405/// memory effects.
406template <typename ConcreteType>
408 : public TraitBase<ConcreteType, HasRecursiveMemoryEffects> {};
409
410/// This trait marks an op (which must be tagged as implementing the
411/// ConditionallySpeculatable interface) as being recursively speculatable.
412/// This means that said op can be speculated only if all the instructions in
413/// all the regions attached to the op can be speculated.
414template <typename ConcreteType>
416 : public TraitBase<ConcreteType, RecursivelySpeculatableImplTrait> {
417
421};
422
423/// This trait marks an op (which must be tagged as implementing the
424/// ConditionallySpeculatable interface) as being always speculatable.
425template <typename ConcreteType>
427 : public TraitBase<ConcreteType, AlwaysSpeculatableImplTrait> {
428
432};
433} // namespace OpTrait
434
435//===----------------------------------------------------------------------===//
436// Operation Memory-Effect Modeling
437//===----------------------------------------------------------------------===//
438
439namespace MemoryEffects {
440/// This class represents the base class used for memory effects.
443
444 /// A base class for memory effects that provides helper utilities.
445 template <typename DerivedEffect>
447
448 static bool classof(const SideEffects::Effect *effect);
449};
451
452/// The following effect indicates that the operation allocates from some
453/// resource. An 'allocate' effect implies only allocation of the resource, and
454/// not any visible mutation or dereference.
455struct Allocate : public Effect::Base<Allocate> {};
456
457/// The following effect indicates that the operation frees some resource that
458/// has been allocated. An 'allocate' effect implies only de-allocation of the
459/// resource, and not any visible allocation, mutation or dereference.
460struct Free : public Effect::Base<Free> {};
461
462/// The following effect indicates that the operation reads from some resource.
463/// A 'read' effect implies only dereferencing of the resource, and not any
464/// visible mutation.
465struct Read : public Effect::Base<Read> {};
466
467/// The following effect indicates that the operation writes to some resource. A
468/// 'write' effect implies only mutating a resource, and not any visible
469/// dereference or read.
470struct Write : public Effect::Base<Write> {};
471} // namespace MemoryEffects
472
473//===----------------------------------------------------------------------===//
474// SideEffect Utilities
475//===----------------------------------------------------------------------===//
476
477/// Return "true" if `op` has unknown effects. I.e., the effects of the
478/// operation itself are unknown and the operation does not derive its effects
479/// from its nested operations. (`HasRecursiveMemoryEffects` trait is not
480/// implemented or it is unknown whether it is implemented or not.)
482
483/// Returns "true" if `op` has only an effect of type `EffectTy`. Returns
484/// "false" if `op` has unknown effects or other/additional effects. Recursive
485/// effects are not taken into account.
486template <typename EffectTy>
487bool hasSingleEffect(Operation *op);
488
489/// Returns "true" if `op` has only an effect of type `EffectTy` on `value`.
490/// Returns "false" if `op` has unknown effects or other/additional effects.
491/// Recursive effects are not taken into account.
492template <typename EffectTy>
493bool hasSingleEffect(Operation *op, Value value);
494
495/// Returns "true" if `op` has only an effect of type `EffectTy` on `value` of
496/// type `ValueTy`. Returns "false" if `op` has unknown effects or
497/// other/additional effects. Recursive effects are not taken into account.
498template <typename ValueTy, typename EffectTy>
499bool hasSingleEffect(Operation *op, ValueTy value);
500
501/// Returns "true" if `op` has an effect of type `EffectTy`. Returns "false" if
502/// `op` has unknown effects. Recursive effects are not taken into account.
503template <typename... EffectTys>
504bool hasEffect(Operation *op);
505
506/// Returns "true" if `op` has an effect of type `EffectTy` on `value`. Returns
507/// "false" if `op` has unknown effects. Recursive effects are not taken into
508/// account.
509template <typename... EffectTys>
510bool hasEffect(Operation *op, Value value);
511
512/// Returns "true" if `op` has an effect of type `EffectTy` on `value` of type
513/// `ValueTy`. Returns "false" if `op` has unknown effects. Recursive effects
514/// are not taken into account.
515template <typename ValueTy, typename... EffectTys>
516bool hasEffect(Operation *op, ValueTy value);
517
518/// Returns "true" if `op` might have an effect of type `EffectTy`. Returns
519/// "true" if the op has unknown effects. Recursive effects are not taken into
520/// account.
521template <typename... EffectTys>
523 return hasUnknownEffects(op) || hasEffect<EffectTys...>(op);
524}
525
526/// Returns "true" if `op` might have an effect of type `EffectTy` on `value`.
527/// Returns "true" if the op has unknown effects. Recursive effects are not
528/// taken into account.
529template <typename... EffectTys>
531 return hasUnknownEffects(op) || hasEffect<EffectTys...>(op, value);
532}
533
534/// Returns "true" if `op` might have an effect of type `EffectTy` on `value`
535/// of type `ValueTy`. Returns "true" if the op has unknown effects. Recursive
536/// effects are not taken into account.
537template <typename ValueTy, typename... EffectTys>
538bool mightHaveEffect(Operation *op, ValueTy value) {
539 return hasUnknownEffects(op) || hasEffect<EffectTys...>(op, value);
540}
541
542/// Return true if the given operation is unused, and has no side effects on
543/// memory that prevent erasing.
544bool isOpTriviallyDead(Operation *op);
545
546/// Return true if the given operation would be dead if unused, and has no side
547/// effects on memory that would prevent erasing. This is equivalent to checking
548/// `isOpTriviallyDead` if `op` was unused.
549///
550/// Note: Terminators and symbols are never considered to be trivially dead.
551bool wouldOpBeTriviallyDead(Operation *op);
552
553/// A cache for repeated deadness queries on nested operations. Report erasure
554/// of scheduled operations and blocks before destroying them.
556public:
557 enum class State : uint8_t { Alive, Dead };
558
559 /// Return true if the operation is unused and can be erased. Terminators and
560 /// symbols cannot be erased. Uses are checked on every query.
562
563 /// Report a change to this operation or its nested IR. For a move, report
564 /// the previous parent operation with scheduleAncestorInvalidation.
566
567 /// Invalidate the cached effects of this operation and its ancestors.
569
570 /// Report a change to a block and its contents. For a move, report the
571 /// previous parent operation with scheduleAncestorInvalidation.
572 void scheduleBlockInvalidation(Block *block);
573
574 /// Call before an empty block is detached and destroyed.
575 void notifyBlockErased(Block *block);
576
577 /// Call once for each erased operation before it is detached or destroyed.
578 /// Report descendants before their parent.
580
581private:
583 enum class Request { Ancestors, Subtree, Cancelled };
584 void enqueue(Target target, Request request);
585 void cancel(Target target);
586 void removeCancelled();
587 void flushInvalidations();
588
590
591 // Each target has one slot. A subtree request upgrades an ancestor request
592 // in place. For a block, the subtree consists of its current contents.
593 // Mark erased targets and compact in bulk to avoid shifting the remaining
594 // slots on every erasure. Compact before dereferencing targets or once at
595 // least half the slots are cancelled.
597 size_t numCancelled = 0;
598};
599
600/// Returns true if the given operation is free of memory effects.
601///
602/// An operation is free of memory effects if its implementation of
603/// `MemoryEffectOpInterface` indicates that it has no memory effects. For
604/// example, it may implement `NoMemoryEffect` in ODS. Alternatively, if the
605/// operation has the `HasRecursiveMemoryEffects` trait, then it is free of
606/// memory effects if all of its nested operations are free of memory effects.
607///
608/// If the operation has both, then it is free of memory effects if both
609/// conditions are satisfied.
611
612/// Returns the side effects of an operation. If the operation has
613/// RecursiveMemoryEffects, include all side effects of child operations.
614///
615/// std::nullopt indicates that an option did not have a memory effect interface
616/// and so no result could be obtained. An empty vector indicates that there
617/// were no memory effects found (but every operation implemented the memory
618/// effect interface or has RecursiveMemoryEffects). If the vector contains
619/// multiple effects, these effects may be duplicates.
620std::optional<llvm::SmallVector<MemoryEffects::EffectInstance>>
622
623/// Returns true if the given operation is speculatable, i.e. has no undefined
624/// behavior or other side effects.
625///
626/// An operation can indicate that it is speculatable by implementing the
627/// getSpeculatability hook in the ConditionallySpeculatable op interface.
628bool isSpeculatable(Operation *op);
629
630/// Returns true if the given operation is pure, i.e., is speculatable that does
631/// not touch memory.
632///
633/// This function is the C++ equivalent of the `Pure` trait.
634bool isPure(Operation *op);
635
636} // namespace mlir
637
638//===----------------------------------------------------------------------===//
639// SideEffect Interfaces
640//===----------------------------------------------------------------------===//
641
642/// Include the definitions of the side effect interfaces.
643#include "mlir/Interfaces/SideEffectInterfaces.h.inc"
644
645#endif // MLIR_INTERFACES_SIDEEFFECTINTERFACES_H
false
Parses a map_entries map type from a string format back into its numeric value.
Attributes are known-constant values of operations.
Definition Attributes.h:25
Block represents an ordered list of Operations.
Definition Block.h:34
A cache for repeated deadness queries on nested operations.
void scheduleBlockInvalidation(Block *block)
Report a change to a block and its contents.
bool isOpTriviallyDead(Operation *op)
Return true if the operation is unused and can be erased.
void scheduleAncestorInvalidation(Operation *op)
Invalidate the cached effects of this operation and its ancestors.
void notifyOperationErased(Operation *op)
Call once for each erased operation before it is detached or destroyed.
void scheduleInvalidation(Operation *op)
Report a change to this operation or its nested IR.
void notifyBlockErased(Block *block)
Call before an empty block is detached and destroyed.
This class represents an operand of an operation.
Definition Value.h:256
This is a value defined by a result of an operation.
Definition Value.h:456
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.
Definition Operation.h:87
This class represents a specific instance of an effect.
Resource * getResource() const
Return the resource that the effect applies to.
EffectT * getEffect() const
Return the effect being applied.
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())
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.
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 DerivedEffect * get()
Returns a unique instance for the derived effect class.
static bool classof(const ::mlir::SideEffects::Effect *effect)
'classof' used to support llvm style cast functionality.
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.
Base(TypeID id)
Constructor for use when this type is used as a parent (BaseResource); allows the derived resource to...
static DerivedResource * get()
Returns a unique instance for the given effect class.
Base< DerivedResource, BaseResource > BaseT
Use the current instantiation so get()/getResourceID() refer to this hierarchy's singleton,...
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.
bool isSubresourceOf(const Resource *other) const
Returns true if this resource is a subresource of (or equal to) another.
virtual Resource * getParent() const
Return the parent resource in the hierarchy.
virtual bool isAddressable() const
Returns true if this resource is addressable (effects on it can alias pointer-based memory).
virtual StringRef getName() const =0
Return a string name of the resource.
bool isDisjointFrom(const Resource *other) const
Returns true if this resource is disjoint from another.
virtual ~Resource()=default
This class provides an efficient unique identifier for a specific C++ type.
Definition TypeID.h:107
static TypeID get()
Construct a type info object for the given type T.
Definition TypeID.h:245
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
SideEffects::EffectInstance< Effect > EffectInstance
constexpr auto RecursivelySpeculatable
Speculatability
This enum is returned from the getSpeculatability method in the ConditionallySpeculatable op interfac...
@ 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.
std::optional< llvm::SmallVector< MemoryEffects::EffectInstance > > getEffectsRecursively(Operation *rootOp)
Returns the side effects of an operation.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
Definition LLVM.h:123
bool hasEffect(Operation *op)
Returns "true" if op has an effect of type EffectTy.
bool hasUnknownEffects(Operation *op)
Return "true" if op has unknown effects.
bool mightHaveEffect(Operation *op)
Returns "true" if op might have an effect of type EffectTy.
The following effect indicates that the operation allocates from some resource.
SideEffects::Effect::Base< DerivedEffect, Effect > Base
A base class for memory effects that provides helper utilities.
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)...
An automatic allocation-scope resource that is valid in the context of a parent AutomaticAllocationSc...
Resource * getParent() const override
Return the parent resource in the hierarchy.
StringRef getName() const final
Return a string name of the resource.
StringRef getName() const override
Return a string name of the resource.
Resource * getParent() const override
Return the parent resource in the hierarchy.
DefaultResource(TypeID id)
For use when this type is the parent of another resource; allows the derived resource to pass its Typ...