Changeset View
Changeset View
Standalone View
Standalone View
mlir/include/mlir/IR/BuiltinAttributes.h
Show First 20 Lines • Show All 879 Lines • ▼ Show 20 Lines | std::function<T(ptrdiff_t)> mapFn = | ||||
for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i) | for (unsigned i = 0, e = flatSparseIndices.size(); i != e; ++i) | ||||
if (flatSparseIndices[i] == index) | if (flatSparseIndices[i] == index) | ||||
return *std::next(valueIt, i); | return *std::next(valueIt, i); | ||||
// Otherwise, return the zero value. | // Otherwise, return the zero value. | ||||
return zeroValue; | return zeroValue; | ||||
}; | }; | ||||
return iterator<T>(llvm::seq<ptrdiff_t>(0, getNumElements()).begin(), mapFn); | return iterator<T>(llvm::seq<ptrdiff_t>(0, getNumElements()).begin(), mapFn); | ||||
} | } | ||||
} // end namespace mlir. | |||||
//===----------------------------------------------------------------------===// | |||||
// StringAttr | |||||
//===----------------------------------------------------------------------===// | |||||
/// Define comparisons for StringAttr against nullptr and itself to avoid the | |||||
/// StringRef overloads from being chosen when not desirable. | |||||
inline bool operator==(StringAttr lhs, std::nullptr_t) { return !lhs; } | |||||
inline bool operator!=(StringAttr lhs, std::nullptr_t) { | |||||
return static_cast<bool>(lhs); | |||||
} | |||||
inline bool operator==(StringAttr lhs, StringAttr rhs) { | |||||
return (Attribute)lhs == (Attribute)rhs; | |||||
} | |||||
inline bool operator!=(StringAttr lhs, StringAttr rhs) { return !(lhs == rhs); } | |||||
/// Allow direct comparison with StringRef. | |||||
inline bool operator==(StringAttr lhs, StringRef rhs) { | |||||
return lhs.getValue() == rhs; | |||||
} | |||||
inline bool operator!=(StringAttr lhs, StringRef rhs) { return !(lhs == rhs); } | |||||
inline bool operator==(StringRef lhs, StringAttr rhs) { | |||||
return rhs.getValue() == lhs; | |||||
} | |||||
inline bool operator!=(StringRef lhs, StringAttr rhs) { return !(lhs == rhs); } | |||||
inline Type StringAttr::getType() const { return Attribute::getType(); } | |||||
} // end namespace mlir | |||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
// Attribute Utilities | // Attribute Utilities | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
namespace llvm { | namespace llvm { | ||||
template <> | template <> | ||||
struct DenseMapInfo<mlir::StringAttr> : public DenseMapInfo<mlir::Attribute> { | |||||
static mlir::StringAttr getEmptyKey() { | |||||
lattner: Randomly, this alone will be really handy. I have built a lot of densemaps with "attribute" as… | |||||
const void *pointer = llvm::DenseMapInfo<const void *>::getEmptyKey(); | |||||
return mlir::StringAttr::getFromOpaquePointer(pointer); | |||||
} | |||||
static mlir::StringAttr getTombstoneKey() { | |||||
const void *pointer = llvm::DenseMapInfo<const void *>::getTombstoneKey(); | |||||
return mlir::StringAttr::getFromOpaquePointer(pointer); | |||||
} | |||||
}; | |||||
template <> | |||||
struct PointerLikeTypeTraits<mlir::StringAttr> | |||||
: public PointerLikeTypeTraits<mlir::Attribute> { | |||||
static inline mlir::StringAttr getFromVoidPointer(void *p) { | |||||
return mlir::StringAttr::getFromOpaquePointer(p); | |||||
} | |||||
}; | |||||
template <> | |||||
struct PointerLikeTypeTraits<mlir::SymbolRefAttr> | struct PointerLikeTypeTraits<mlir::SymbolRefAttr> | ||||
: public PointerLikeTypeTraits<mlir::Attribute> { | : public PointerLikeTypeTraits<mlir::Attribute> { | ||||
static inline mlir::SymbolRefAttr getFromVoidPointer(void *ptr) { | static inline mlir::SymbolRefAttr getFromVoidPointer(void *ptr) { | ||||
return PointerLikeTypeTraits<mlir::Attribute>::getFromVoidPointer(ptr) | return mlir::SymbolRefAttr::getFromOpaquePointer(ptr); | ||||
.cast<mlir::SymbolRefAttr>(); | |||||
} | } | ||||
}; | }; | ||||
} // namespace llvm | } // namespace llvm | ||||
#endif // MLIR_IR_BUILTINATTRIBUTES_H | #endif // MLIR_IR_BUILTINATTRIBUTES_H |
Randomly, this alone will be really handy. I have built a lot of densemaps with "attribute" as the key instead of StringAttr just to work around this :-)