14#include <mlir/IR/DialectImplementation.h>
16#include <llvm/ADT/APInt.h>
17#include <llvm/ADT/Hashing.h>
22 static mlir::FailureOr<llvm::APInt>
parse(mlir::AsmParser &parser) {
23 auto loc = parser.getCurrentLocation();
25 auto result = parser.parseOptionalInteger(val);
26 if (!result.has_value() || *result) {
27 return parser.emitError(loc,
"expected integer value");
39 APIntValue(llvm::APInt apInt) : value(std::move(apInt)) {}
41 const llvm::APInt &
getValue()
const {
return value; }
42 operator const llvm::APInt &()
const {
return value; }
45 return llvm::APInt::isSameValue(lhs.value, rhs.value);
49 unsigned activeBits = key.value.getActiveBits();
50 llvm::APInt canonical = key.value.trunc(activeBits == 0 ? 1 : activeBits);
51 return llvm::hash_value(canonical);
60 if (mlir::failed(value)) {
61 return mlir::failure();
66inline llvm::APInt
toAPInt(int64_t i) {
return llvm::APInt(64, i); }
67inline int64_t
fromAPInt(
const llvm::APInt &i) {
return i.getSExtValue(); }
70inline bool isNullOrEmpty(mlir::DenseArrayAttr a) {
return !a || a.empty(); }
71inline bool isNullOrEmpty(mlir::DictionaryAttr a) {
return !a || a.empty(); }
73inline void appendWithoutType(mlir::raw_ostream &os, mlir::Attribute a) { a.print(os,
true); }
79 mlir::AsmPrinter &printer, mlir::ArrayRef<mlir::Attribute> attrs,
80 const mlir::StringRef &separator
Storage key for APInts whose numeric value is independent of bit width.
const llvm::APInt & getValue() const
friend bool operator==(const APIntValue &lhs, const APIntValue &rhs)
APIntValue(llvm::APInt apInt)
friend llvm::hash_code hash_value(const APIntValue &key)
void printAttrs(AsmPrinter &printer, ArrayRef< Attribute > attrs, const StringRef &separator)
std::string stringWithoutType(mlir::Attribute a)
bool isNullOrEmpty(mlir::ArrayAttr a)
APInt toAPInt(const DynamicAPInt &val, unsigned bitWidth)
mlir::FailureOr< APIntValue > parseAPIntValue(mlir::AsmParser &parser)
int64_t fromAPInt(const llvm::APInt &i)
void appendWithoutType(mlir::raw_ostream &os, mlir::Attribute a)
std::string buildStringViaCallback(Func &&appendFn, Args &&...args)
Generate a string by calling the given appendFn with an llvm::raw_ostream & as the first argument fol...
static mlir::FailureOr< llvm::APInt > parse(mlir::AsmParser &parser)