Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/IR/Attributes.cpp
Show First 20 Lines • Show All 742 Lines • ▼ Show 20 Lines | DenseElementsAttr DenseElementsAttr::get(ShapedType type, | ||||
// Compress the attribute values into a character buffer. | // Compress the attribute values into a character buffer. | ||||
SmallVector<char, 8> data(llvm::divideCeil(storageBitWidth, CHAR_BIT) * | SmallVector<char, 8> data(llvm::divideCeil(storageBitWidth, CHAR_BIT) * | ||||
values.size()); | values.size()); | ||||
APInt intVal; | APInt intVal; | ||||
for (unsigned i = 0, e = values.size(); i < e; ++i) { | for (unsigned i = 0, e = values.size(); i < e; ++i) { | ||||
assert(eltType == values[i].getType() && | assert(eltType == values[i].getType() && | ||||
"expected attribute value to have element type"); | "expected attribute value to have element type"); | ||||
if (eltType.isa<FloatType>()) | |||||
switch (eltType.getKind()) { | |||||
case StandardTypes::BF16: | |||||
case StandardTypes::F16: | |||||
case StandardTypes::F32: | |||||
case StandardTypes::F64: | |||||
intVal = values[i].cast<FloatAttr>().getValue().bitcastToAPInt(); | intVal = values[i].cast<FloatAttr>().getValue().bitcastToAPInt(); | ||||
break; | else if (eltType.isa<IntegerType>()) | ||||
case StandardTypes::Integer: | |||||
case StandardTypes::Index: | |||||
intVal = values[i].cast<IntegerAttr>().getValue(); | intVal = values[i].cast<IntegerAttr>().getValue(); | ||||
break; | else | ||||
default: | |||||
llvm_unreachable("unexpected element type"); | llvm_unreachable("unexpected element type"); | ||||
} | |||||
assert(intVal.getBitWidth() == bitWidth && | assert(intVal.getBitWidth() == bitWidth && | ||||
"expected value to have same bitwidth as element type"); | "expected value to have same bitwidth as element type"); | ||||
writeBits(data.data(), i * storageBitWidth, intVal); | writeBits(data.data(), i * storageBitWidth, intVal); | ||||
} | } | ||||
return DenseIntOrFPElementsAttr::getRaw(type, data, | return DenseIntOrFPElementsAttr::getRaw(type, data, | ||||
/*isSplat=*/(values.size() == 1)); | /*isSplat=*/(values.size() == 1)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 703 Lines • Show Last 20 Lines |