CIRCT 20.0.0git
Loading...
Searching...
No Matches
SeqTypes.cpp
Go to the documentation of this file.
1//===- SeqTypes.cpp - Seq types code defs ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implementation logic for Seq data types.
10//
11//===----------------------------------------------------------------------===//
12
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/BuiltinTypes.h"
18#include "mlir/IR/Diagnostics.h"
19#include "mlir/IR/DialectImplementation.h"
20#include "mlir/IR/StorageUniquerSupport.h"
21#include "mlir/IR/Types.h"
22#include "llvm/ADT/StringExtras.h"
23#include "llvm/ADT/TypeSwitch.h"
24
25using namespace mlir;
26using namespace circt;
27using namespace seq;
28
29//===----------------------------------------------------------------------===//
30/// Tablegen Type Definitions
31//===----------------------------------------------------------------------===//
32
33#define GET_TYPEDEF_CLASSES
34#include "circt/Dialect/Seq/SeqTypes.cpp.inc"
35
36void SeqDialect::registerTypes() {
37 addTypes<
38#define GET_TYPEDEF_LIST
39#include "circt/Dialect/Seq/SeqTypes.cpp.inc"
40 >();
41}
42
43//===----------------------------------------------------------------------===//
44// Utilities
45//===----------------------------------------------------------------------===//
46
48 if (hw::type_isa<seq::ClockType>(ty))
49 return true;
50 if (hw::isHWIntegerType(ty) && hw::getBitWidth(ty) == 1)
51 return true;
52 return false;
53}
54
55//===----------------------------------------------------------------------===//
56// HLMemType
57//===----------------------------------------------------------------------===//
58
59HLMemType HLMemType::cloneWith(std::optional<ArrayRef<int64_t>> shape,
60 Type elementType) const {
61 return HLMemType::get(elementType.getContext(), shape.value_or(getShape()),
63}
64
65llvm::SmallVector<Type> HLMemType::getAddressTypes() const {
66 auto *ctx = getContext();
67 llvm::SmallVector<Type> addressTypes;
68 for (auto dim : getShape())
69 addressTypes.push_back(IntegerType::get(ctx, llvm::Log2_64_Ceil(dim)));
70 return addressTypes;
71}
72
73Type HLMemType::parse(mlir::AsmParser &odsParser) {
74 llvm::SmallVector<int64_t> shape;
75 Type elementType;
76 if (odsParser.parseLess() ||
77 odsParser.parseDimensionList(shape, /*allowDynamic=*/false,
78 /*withTrailingX=*/true) ||
79 odsParser.parseType(elementType) || odsParser.parseGreater())
80 return {};
81
82 return HLMemType::get(odsParser.getContext(), shape, elementType);
83}
84
85void HLMemType::print(AsmPrinter &odsPrinter) const {
86 odsPrinter << '<';
87 for (auto dim : getShape())
88 odsPrinter << dim << 'x';
89 odsPrinter << getElementType();
90 odsPrinter << '>';
91}
92
93LogicalResult
94HLMemType::verify(llvm::function_ref<::mlir::InFlightDiagnostic()> emitError,
95 llvm::ArrayRef<int64_t> shape, Type elementType) {
96 if (shape.empty())
97 return emitError() << "shape must have at least one dimension.";
98 return success();
99}
MlirType elementType
Definition CHIRRTL.cpp:29
bool isClockOrI1Type(Type ty)
Returns true if the type is i1 or seq.clock
Definition SeqTypes.cpp:47
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition seq.py:1