11#include "mlir/IR/Builders.h"
12#include "mlir/IR/DialectImplementation.h"
13#include "llvm/ADT/TypeSwitch.h"
37 return (
value.getBitWidth() == key.getBitWidth() &&
value == key);
41 return llvm::hash_value(key);
56Type ImmediateAttr::getType()
const {
57 return ImmediateType::get(getContext(), getValue().
getBitWidth());
60APInt ImmediateAttr::getValue()
const {
return getImpl()->value; }
62Attribute ImmediateAttr::parse(AsmParser &odsParser, Type odsType) {
63 llvm::SMLoc loc = odsParser.getCurrentLocation();
68 if (odsParser.parseLess() || odsParser.parseInteger(width) ||
69 odsParser.parseComma() || odsParser.parseInteger(val) ||
70 odsParser.parseGreater())
74 if (
auto immTy = llvm::dyn_cast_or_null<ImmediateType>(odsType)) {
75 if (immTy.getWidth() != width) {
76 odsParser.emitError(loc) <<
"explicit immediate type bit-width does not "
77 "match attribute bit-width, "
78 << immTy.getWidth() <<
" vs " << width;
83 if (width > val.getBitWidth()) {
87 val = val.sext(width);
88 }
else if (width < val.getBitWidth()) {
92 val.isNegative() ? val.getSignificantBits() : val.getActiveBits();
93 if (width < neededBits) {
94 odsParser.emitError(loc)
95 <<
"integer value out-of-range for bit-width " << width;
98 val = val.trunc(width);
101 return ImmediateAttr::get(odsParser.getContext(), val);
104void ImmediateAttr::print(AsmPrinter &odsPrinter)
const {
105 odsPrinter <<
"<" << getValue().getBitWidth() <<
", " << getValue() <<
">";
112void RTGDialect::registerAttributes() {
114#define GET_ATTRDEF_LIST
115#include "circt/Dialect/RTG/IR/RTGAttributes.cpp.inc"
119#define GET_ATTRDEF_CLASSES
120#include "circt/Dialect/RTG/IR/RTGAttributes.cpp.inc"
int64_t getBitWidth(mlir::Type type)
Return the hardware bit width of a type.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.