13#include "mlir/IR/Builders.h"
14#include "mlir/IR/DialectImplementation.h"
15#include "llvm/ADT/TypeSwitch.h"
24#define GET_TYPEDEF_CLASSES
25#include "circt/Dialect/Arc/ArcTypes.cpp.inc"
33 if (isa<seq::ClockType>(type))
36 if (
auto intType = dyn_cast<IntegerType>(type))
37 return intType.getWidth();
39 auto computeForArrayType = [&](
auto arrayType) -> std::optional<uint64_t> {
41 auto maybeWidth = computeLLVMBitWidth(arrayType.getElementType());
45 auto width = std::max<uint64_t>(*maybeWidth, 8);
47 auto alignment = llvm::bit_ceil(std::min<uint64_t>(width, 16 * 8));
48 auto alignedWidth = llvm::alignToPowerOf2(width, alignment);
50 return arrayType.getNumElements() * alignedWidth;
53 if (
auto arrayType = dyn_cast<hw::ArrayType>(type))
54 return computeForArrayType(arrayType);
56 if (
auto arrayRefType = dyn_cast<ArrayRefType>(type))
57 return computeForArrayType(arrayRefType);
59 if (
auto structType = dyn_cast<hw::StructType>(type)) {
60 uint64_t structWidth = 0;
61 uint64_t structAlignment = 8;
62 for (
auto element : structType.getElements()) {
64 auto maybeWidth = computeLLVMBitWidth(element.type);
68 auto width = std::max<uint64_t>(*maybeWidth, 8);
70 auto alignment = llvm::bit_ceil(std::min<uint64_t>(width, 16 * 8));
71 auto alignedWidth = llvm::alignToPowerOf2(width, alignment);
74 structWidth = llvm::alignToPowerOf2(structWidth, alignment);
75 structWidth += alignedWidth;
77 structAlignment = std::max<uint64_t>(alignment, structAlignment);
80 return llvm::alignToPowerOf2(structWidth, structAlignment);
90StateType::verify(llvm::function_ref<InFlightDiagnostic()> emitError,
93 return emitError() <<
"state type must have a known bit width; got "
98unsigned MemoryType::getStride() {
99 unsigned stride = (getWordType().getWidth() + 7) / 8;
100 return llvm::alignToPowerOf2(stride, llvm::bit_ceil(std::min(stride, 16U)));
103size_t ArrayRefType::getNumElements()
const {
return getSize(); }
105std::optional<int64_t> ArrayRefType::getBitWidth()
const {
106 auto elementBitWidth = hw::getBitWidth(getElementType());
107 if (elementBitWidth < 0)
115ShapedType ArrayRefType::cloneWith(std::optional<ArrayRef<int64_t>> shape,
117 llvm_unreachable(
"ArrayRefType::cloneWith not implemented!");
120bool ArrayRefType::hasRank()
const {
return true; }
122ArrayRef<int64_t> ArrayRefType::getShape()
const {
123 const uint64_t &size = getImpl()->size;
124 return ArrayRef<int64_t>(
reinterpret_cast<const int64_t *
>(&size), 1);
128 return failure(p.parseXInDimensionList() || p.parseType(
elementType));
136ArrayRefType::verify(llvm::function_ref<InFlightDiagnostic()> emitError,
139 return emitError() <<
"must have nonzero element count";
144void ArcDialect::registerTypes() {
146#define GET_TYPEDEF_LIST
147#include "circt/Dialect/Arc/ArcTypes.cpp.inc"
static void printXInDimList(AsmPrinter &p, Type elementType)
static ParseResult parseXInDimList(AsmParser &p, Type &elementType)
MlirType uint64_t numElements
std::optional< uint64_t > computeLLVMBitWidth(mlir::Type type)
Compute the bit width a type will have when allocated as part of the simulator's storage.
mlir::Type innerType(mlir::Type type)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.