Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/IR/OperationSupport.h
Show All 13 Lines | |||||
#ifndef MLIR_IR_OPERATION_SUPPORT_H | #ifndef MLIR_IR_OPERATION_SUPPORT_H | ||||
#define MLIR_IR_OPERATION_SUPPORT_H | #define MLIR_IR_OPERATION_SUPPORT_H | ||||
#include "mlir/IR/Attributes.h" | #include "mlir/IR/Attributes.h" | ||||
#include "mlir/IR/Identifier.h" | #include "mlir/IR/Identifier.h" | ||||
#include "mlir/IR/Location.h" | #include "mlir/IR/Location.h" | ||||
#include "mlir/IR/Types.h" | #include "mlir/IR/Types.h" | ||||
#include "mlir/IR/Value.h" | #include "mlir/IR/Value.h" | ||||
#include "mlir/Support/LogicalResult.h" | #include "mlir/Support/InterfaceSupport.h" | ||||
#include "llvm/ADT/BitmaskEnum.h" | #include "llvm/ADT/BitmaskEnum.h" | ||||
#include "llvm/ADT/PointerUnion.h" | #include "llvm/ADT/PointerUnion.h" | ||||
#include "llvm/Support/PointerLikeTypeTraits.h" | #include "llvm/Support/PointerLikeTypeTraits.h" | ||||
#include "llvm/Support/TrailingObjects.h" | #include "llvm/Support/TrailingObjects.h" | ||||
#include <memory> | #include <memory> | ||||
namespace mlir { | namespace mlir { | ||||
class Block; | class Block; | ||||
▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | public: | ||||
bool hasProperty(OperationProperty property) const { | bool hasProperty(OperationProperty property) const { | ||||
return opProperties & static_cast<OperationProperties>(property); | return opProperties & static_cast<OperationProperties>(property); | ||||
} | } | ||||
/// Returns an instance of the concept object for the given interface if it | /// Returns an instance of the concept object for the given interface if it | ||||
/// was registered to this operation, null otherwise. This should not be used | /// was registered to this operation, null otherwise. This should not be used | ||||
/// directly. | /// directly. | ||||
template <typename T> typename T::Concept *getInterface() const { | template <typename T> typename T::Concept *getInterface() const { | ||||
return reinterpret_cast<typename T::Concept *>( | return interfaceMap.lookup<T>(); | ||||
getRawInterface(T::getInterfaceID())); | |||||
} | } | ||||
/// Returns if the operation has a particular trait. | /// Returns if the operation has a particular trait. | ||||
template <template <typename T> class Trait> bool hasTrait() const { | template <template <typename T> class Trait> bool hasTrait() const { | ||||
return hasRawTrait(TypeID::get<Trait>()); | return hasRawTrait(TypeID::get<Trait>()); | ||||
} | } | ||||
/// Look up the specified operation in the specified MLIRContext and return a | /// Look up the specified operation in the specified MLIRContext and return a | ||||
/// pointer to it if present. Otherwise, return a null pointer. | /// pointer to it if present. Otherwise, return a null pointer. | ||||
static const AbstractOperation *lookup(StringRef opName, | static const AbstractOperation *lookup(StringRef opName, | ||||
MLIRContext *context); | MLIRContext *context); | ||||
/// This constructor is used by Dialect objects when they register the list of | /// This constructor is used by Dialect objects when they register the list of | ||||
/// operations they contain. | /// operations they contain. | ||||
template <typename T> static AbstractOperation get(Dialect &dialect) { | template <typename T> static AbstractOperation get(Dialect &dialect) { | ||||
return AbstractOperation( | return AbstractOperation( | ||||
T::getOperationName(), dialect, T::getOperationProperties(), | T::getOperationName(), dialect, T::getOperationProperties(), | ||||
TypeID::get<T>(), T::parseAssembly, T::printAssembly, | TypeID::get<T>(), T::parseAssembly, T::printAssembly, | ||||
T::verifyInvariants, T::foldHook, T::getCanonicalizationPatterns, | T::verifyInvariants, T::foldHook, T::getCanonicalizationPatterns, | ||||
T::getRawInterface, T::hasTrait); | T::getInterfaceMap(), T::hasTrait); | ||||
} | } | ||||
private: | private: | ||||
AbstractOperation( | AbstractOperation( | ||||
StringRef name, Dialect &dialect, OperationProperties opProperties, | StringRef name, Dialect &dialect, OperationProperties opProperties, | ||||
TypeID typeID, | TypeID typeID, | ||||
ParseResult (&parseAssembly)(OpAsmParser &parser, OperationState &result), | ParseResult (&parseAssembly)(OpAsmParser &parser, OperationState &result), | ||||
void (&printAssembly)(Operation *op, OpAsmPrinter &p), | void (&printAssembly)(Operation *op, OpAsmPrinter &p), | ||||
LogicalResult (&verifyInvariants)(Operation *op), | LogicalResult (&verifyInvariants)(Operation *op), | ||||
LogicalResult (&foldHook)(Operation *op, ArrayRef<Attribute> operands, | LogicalResult (&foldHook)(Operation *op, ArrayRef<Attribute> operands, | ||||
SmallVectorImpl<OpFoldResult> &results), | SmallVectorImpl<OpFoldResult> &results), | ||||
void (&getCanonicalizationPatterns)(OwningRewritePatternList &results, | void (&getCanonicalizationPatterns)(OwningRewritePatternList &results, | ||||
MLIRContext *context), | MLIRContext *context), | ||||
void *(&getRawInterface)(TypeID interfaceID), | detail::InterfaceMap &&interfaceMap, bool (&hasTrait)(TypeID traitID)) | ||||
bool (&hasTrait)(TypeID traitID)) | |||||
: name(name), dialect(dialect), typeID(typeID), | : name(name), dialect(dialect), typeID(typeID), | ||||
parseAssembly(parseAssembly), printAssembly(printAssembly), | parseAssembly(parseAssembly), printAssembly(printAssembly), | ||||
verifyInvariants(verifyInvariants), foldHook(foldHook), | verifyInvariants(verifyInvariants), foldHook(foldHook), | ||||
getCanonicalizationPatterns(getCanonicalizationPatterns), | getCanonicalizationPatterns(getCanonicalizationPatterns), | ||||
opProperties(opProperties), getRawInterface(getRawInterface), | opProperties(opProperties), interfaceMap(std::move(interfaceMap)), | ||||
hasRawTrait(hasTrait) {} | hasRawTrait(hasTrait) {} | ||||
/// The properties of the operation. | /// The properties of the operation. | ||||
const OperationProperties opProperties; | const OperationProperties opProperties; | ||||
/// Returns a raw instance of the concept for the given interface id if it is | /// A map of interfaces that were registered to this operation. | ||||
/// registered to this operation, nullptr otherwise. This should not be used | detail::InterfaceMap interfaceMap; | ||||
/// directly. | |||||
void *(&getRawInterface)(TypeID interfaceID); | |||||
/// This hook returns if the operation contains the trait corresponding | /// This hook returns if the operation contains the trait corresponding | ||||
/// to the given TypeID. | /// to the given TypeID. | ||||
bool (&hasRawTrait)(TypeID traitID); | bool (&hasRawTrait)(TypeID traitID); | ||||
}; | }; | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// NamedAttrList | // NamedAttrList | ||||
▲ Show 20 Lines • Show All 797 Lines • Show Last 20 Lines |