diff --git a/mlir/include/mlir/IR/Value.h b/mlir/include/mlir/IR/Value.h --- a/mlir/include/mlir/IR/Value.h +++ b/mlir/include/mlir/IR/Value.h @@ -94,25 +94,15 @@ public: constexpr Value(detail::ValueImpl *impl = nullptr) : impl(impl) {} - template - bool isa() const { - return llvm::isa(*this); - } + template bool isa() const { return llvm::isa(*this); } - template - U dyn_cast() const { - return llvm::dyn_cast(*this); - } + template U dyn_cast() const { return llvm::dyn_cast(*this); } - template - U dyn_cast_or_null() const { + template U dyn_cast_or_null() const { return llvm::dyn_cast_if_present(*this); } - template - U cast() const { - return llvm::cast(*this); - } + template U cast() const { return llvm::cast(*this); } explicit operator bool() const { return impl; } bool operator==(const Value &other) const { return impl == other.impl; } @@ -138,8 +128,7 @@ /// If this value is the result of an operation of type OpTy, return the /// operation that defines it. - template - OpTy getDefiningOp() const { + template OpTy getDefiningOp() const { return llvm::dyn_cast_or_null(getDefiningOp()); } @@ -529,10 +518,21 @@ return reinterpret_cast(pointer); } }; +template +struct DenseMapInfo> + : public DenseMapInfo { + static mlir::detail::TypedValue getEmptyKey() { + void *pointer = llvm::DenseMapInfo::getEmptyKey(); + return reinterpret_cast(pointer); + } + static mlir::detail::TypedValue getTombstoneKey() { + void *pointer = llvm::DenseMapInfo::getTombstoneKey(); + return reinterpret_cast(pointer); + } +}; /// Allow stealing the low bits of a value. -template <> -struct PointerLikeTypeTraits { +template <> struct PointerLikeTypeTraits { public: static inline void *getAsVoidPointer(mlir::Value value) { return const_cast(value.getAsOpaquePointer()); @@ -561,6 +561,14 @@ return reinterpret_cast(pointer); } }; +template +struct PointerLikeTypeTraits> + : public PointerLikeTypeTraits { +public: + static inline mlir::detail::TypedValue getFromVoidPointer(void *pointer) { + return reinterpret_cast(pointer); + } +}; /// Add support for llvm style casts. We provide a cast between To and From if /// From is mlir::Value or derives from it.