11#include "llvm/ADT/APFloat.h"
12#include "llvm/Support/CheckedArithmetic.h"
13#include "llvm/Support/MathExtras.h"
23#include "mlir/IR/BuiltinTypeInterfaces.cpp.inc"
30 return cast<FloatType>(type).getWidth();
35 auto floatType = cast<FloatType>(type);
36 APInt intVal =
readBits(rawData.data(), 0, floatType.getWidth());
37 APFloat floatVal(floatType.getFloatSemantics(), intVal);
38 return FloatAttr::get(type, floatVal);
44 auto floatType = cast<FloatType>(type);
45 auto floatAttr = dyn_cast<FloatAttr>(attr);
46 if (!floatAttr || floatAttr.getType() != type)
49 llvm::divideCeil(floatType.getWidth(),
static_cast<unsigned>(CHAR_BIT));
50 size_t bitPos =
result.size() * CHAR_BIT;
52 writeBits(
result.data(), bitPos, floatAttr.getValue().bitcastToAPInt());
60unsigned FloatType::getWidth() {
61 return APFloat::semanticsSizeInBits(getFloatSemantics());
64unsigned FloatType::getFPMantissaWidth() {
65 return APFloat::semanticsPrecision(getFloatSemantics());
74 for (int64_t dim : shape) {
75 auto result = llvm::checkedMul(num, dim);
85 std::optional<int64_t> num = tryGetNumElements(shape);
86 assert(num.has_value() &&
"integer overflow in element count computation");
90 for (int64_t dim : shape)
Attributes are known-constant values of operations.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
llvm::APInt readBits(const char *rawData, size_t bitPos, size_t bitWidth)
Read bitWidth bits from byte-aligned position in rawData and return as an APInt.
LogicalResult convertFloatTypeFromAttribute(Type type, Attribute attr, llvm::SmallVectorImpl< char > &result)
Float type implementation of DenseElementTypeInterface::convertFromAttribute.
size_t getFloatTypeDenseElementBitSize(Type type)
Float type implementation of DenseElementTypeInterface::getDenseElementBitSize.
Attribute convertFloatTypeToAttribute(Type type, llvm::ArrayRef< char > rawData)
Float type implementation of DenseElementTypeInterface::convertToAttribute.
void writeBits(char *rawData, size_t bitPos, llvm::APInt value)
Write value to byte-aligned position bitPos in rawData.
Include the generated interface declarations.