diff options
Diffstat (limited to 'mlir/include')
-rw-r--r-- | mlir/include/mlir/IR/Operation.h | 7 | ||||
-rw-r--r-- | mlir/include/mlir/IR/OperationSupport.h | 8 | ||||
-rw-r--r-- | mlir/include/mlir/Interfaces/SideEffects.h | 23 | ||||
-rw-r--r-- | mlir/include/mlir/Interfaces/SideEffects.td | 17 | ||||
-rw-r--r-- | mlir/include/mlir/TableGen/SideEffects.h | 8 | ||||
-rw-r--r-- | mlir/include/mlir/Transforms/FoldUtils.h | 3 |
6 files changed, 35 insertions, 31 deletions
diff --git a/mlir/include/mlir/IR/Operation.h b/mlir/include/mlir/IR/Operation.h index 781dbcd..4183845 100644 --- a/mlir/include/mlir/IR/Operation.h +++ b/mlir/include/mlir/IR/Operation.h @@ -407,13 +407,6 @@ public: return false; } - /// Returns whether the operation has side-effects. - bool hasNoSideEffect() { - if (auto *absOp = getAbstractOperation()) - return absOp->hasProperty(OperationProperty::NoSideEffect); - return false; - } - /// Represents the status of whether an operation is a terminator. We /// represent an 'unknown' status because we want to support unregistered /// terminators. diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h index 2d4a968..8928886 100644 --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -68,19 +68,15 @@ enum class OperationProperty { /// results. Commutative = 0x1, - /// This bit is set for operations that have no side effects: that means that - /// they do not read or write memory, or access any hidden state. - NoSideEffect = 0x2, - /// This bit is set for an operation if it is a terminator: that means /// an operation at the end of a block. - Terminator = 0x4, + Terminator = 0x2, /// This bit is set for operations that are completely isolated from above. /// This is used for operations whose regions are explicit capture only, i.e. /// they are never allowed to implicitly reference values defined above the /// parent operation. - IsolatedFromAbove = 0x8, + IsolatedFromAbove = 0x4, }; /// This is a "type erased" representation of a registered operation. This diff --git a/mlir/include/mlir/Interfaces/SideEffects.h b/mlir/include/mlir/Interfaces/SideEffects.h index 96714da..e0fd175 100644 --- a/mlir/include/mlir/Interfaces/SideEffects.h +++ b/mlir/include/mlir/Interfaces/SideEffects.h @@ -163,15 +163,6 @@ private: //===----------------------------------------------------------------------===// namespace OpTrait { -/// This trait indicates that an operation never has side effects. -template <typename ConcreteType> -class HasNoSideEffect : public TraitBase<ConcreteType, HasNoSideEffect> { -public: - static AbstractOperation::OperationProperties getTraitProperties() { - return static_cast<AbstractOperation::OperationProperties>( - OperationProperty::NoSideEffect); - } -}; /// This trait indicates that the side effects of an operation includes the /// effects of operations nested within its regions. If the operation has no /// derived effects interfaces, the operation itself can be assumed to have no @@ -221,10 +212,24 @@ struct Write : public Effect::Base<Write> {}; //===----------------------------------------------------------------------===// // SideEffect Interfaces +//===----------------------------------------------------------------------===// /// Include the definitions of the side effect interfaces. #include "mlir/Interfaces/SideEffectInterfaces.h.inc" +//===----------------------------------------------------------------------===// +// SideEffect Utilities +//===----------------------------------------------------------------------===// + +/// Return true if the given operation is unused, and has no side effects on +/// memory that prevent erasing. +bool isOpTriviallyDead(Operation *op); + +/// Return true if the given operation would be dead if unused, and has no side +/// effects on memory that would prevent erasing. This is equivalent to checking +/// `isOpTriviallyDead` if `op` was unused. +bool wouldOpBeTriviallyDead(Operation *op); + } // end namespace mlir #endif // MLIR_INTERFACES_SIDEEFFECTS_H diff --git a/mlir/include/mlir/Interfaces/SideEffects.td b/mlir/include/mlir/Interfaces/SideEffects.td index ebf3da6..8bb4072 100644 --- a/mlir/include/mlir/Interfaces/SideEffects.td +++ b/mlir/include/mlir/Interfaces/SideEffects.td @@ -98,6 +98,13 @@ class EffectOpInterfaceBase<string name, string baseEffect> getEffects(effects); return effects.empty(); } + + /// Returns if the given operation has no effects for this interface. + static bool hasNoEffect(Operation *op) { + if (auto interface = dyn_cast<}] # name # [{>(op)) + return interface.hasNoEffect(); + return op->hasTrait<OpTrait::HasRecursiveSideEffects>(); + } }]; // The base effect name of this interface. @@ -108,11 +115,8 @@ class EffectOpInterfaceBase<string name, string baseEffect> // effect interfaces to define their effects. class SideEffect<EffectOpInterfaceBase interface, string effectName, string resourceName> : OpVariableDecorator { - /// The parent interface that the effect belongs to. - string interfaceTrait = interface.trait; - /// The name of the base effects class. - string baseEffect = interface.baseEffectName; + string baseEffectName = interface.baseEffectName; /// The derived effect that is being applied. string effect = effectName; @@ -128,6 +132,9 @@ class SideEffectsTraitBase<EffectOpInterfaceBase parentInterface, /// The name of the interface trait to use. let trait = parentInterface.trait; + /// The name of the base effects class. + string baseEffectName = parentInterface.baseEffectName; + /// The derived effects being applied. list<SideEffect> effects = staticEffects; } @@ -193,7 +200,7 @@ def MemWrite : MemWrite<"">; //===----------------------------------------------------------------------===// // Op has no side effect. -def NoSideEffect : NativeOpTrait<"HasNoSideEffect">; +def NoSideEffect : MemoryEffects<[]>; // Op has recursively computed side effects. def RecursiveSideEffects : NativeOpTrait<"HasRecursiveSideEffects">; diff --git a/mlir/include/mlir/TableGen/SideEffects.h b/mlir/include/mlir/TableGen/SideEffects.h index c93502c..eb2a068 100644 --- a/mlir/include/mlir/TableGen/SideEffects.h +++ b/mlir/include/mlir/TableGen/SideEffects.h @@ -27,10 +27,7 @@ public: StringRef getName() const; // Return the name of the base C++ effect. - StringRef getBaseName() const; - - // Return the name of the parent interface trait. - StringRef getInterfaceTrait() const; + StringRef getBaseEffectName() const; // Return the name of the resource class. StringRef getResource() const; @@ -46,6 +43,9 @@ public: // Return the effects that are attached to the side effect interface. Operator::var_decorator_range getEffects() const; + // Return the name of the base C++ effect. + StringRef getBaseEffectName() const; + static bool classof(const OpTrait *t); }; diff --git a/mlir/include/mlir/Transforms/FoldUtils.h b/mlir/include/mlir/Transforms/FoldUtils.h index 56a78b1..83ce3bf 100644 --- a/mlir/include/mlir/Transforms/FoldUtils.h +++ b/mlir/include/mlir/Transforms/FoldUtils.h @@ -106,6 +106,9 @@ public: return op; } + /// Clear out any constants cached inside of the folder. + void clear(); + private: /// This map keeps track of uniqued constants by dialect, attribute, and type. /// A constant operation materializes an attribute with a type. Dialects may |