16#include "mlir/IR/Builders.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/ADT/SmallString.h"
29ConstantOp::inferReturnTypes(MLIRContext *context, std::optional<Location> loc,
30 ValueRange operands, DictionaryAttr attributes,
31 OpaqueProperties properties, RegionRange regions,
32 SmallVectorImpl<Type> &inferredReturnTypes) {
33 inferredReturnTypes.push_back(
34 properties.as<Properties *>()->getValue().getType());
38OpFoldResult ConstantOp::fold(FoldAdaptor adaptor) {
return getValueAttr(); }
44LogicalResult SequenceOp::verifyRegions() {
45 if (TypeRange(getSequenceType().getElementTypes()) !=
46 getBody()->getArgumentTypes())
47 return emitOpError(
"sequence type does not match block argument types");
52ParseResult SequenceOp::parse(OpAsmParser &parser, OperationState &result) {
54 if (parser.parseSymbolName(
55 result.getOrAddProperties<SequenceOp::Properties>().sym_name))
59 SmallVector<OpAsmParser::Argument> arguments;
60 if (parser.parseArgumentList(arguments, OpAsmParser::Delimiter::Paren,
64 SmallVector<Type> argTypes;
65 SmallVector<Location> argLocs;
66 argTypes.reserve(arguments.size());
67 argLocs.reserve(arguments.size());
68 for (
auto &arg : arguments) {
69 argTypes.push_back(arg.type);
70 argLocs.push_back(arg.sourceLoc ? *arg.sourceLoc : result.location);
72 Type type = SequenceType::get(result.getContext(), argTypes);
73 result.getOrAddProperties<SequenceOp::Properties>().sequenceType =
76 auto loc = parser.getCurrentLocation();
77 if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
79 if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
80 return parser.emitError(loc)
81 <<
"'" << result.name.getStringRef() <<
"' op ";
85 std::unique_ptr<Region> bodyRegionRegion = std::make_unique<Region>();
86 if (parser.parseRegion(*bodyRegionRegion, arguments))
89 if (bodyRegionRegion->empty()) {
90 bodyRegionRegion->emplaceBlock();
91 bodyRegionRegion->addArguments(argTypes, argLocs);
93 result.addRegion(std::move(bodyRegionRegion));
98void SequenceOp::print(OpAsmPrinter &p) {
100 p.printSymbolName(getSymNameAttr().getValue());
102 llvm::interleaveComma(getBody()->getArguments(), p,
103 [&](
auto arg) { p.printRegionArgument(arg); });
105 p.printOptionalAttrDictWithKeyword(
106 (*this)->getAttrs(), {getSymNameAttrName(), getSequenceTypeAttrName()});
108 p.printRegion(getBodyRegion(),
false);
111mlir::SymbolTable::Visibility SequenceOp::getVisibility() {
112 return mlir::SymbolTable::Visibility::Private;
115void SequenceOp::setVisibility(mlir::SymbolTable::Visibility visibility) {
117 assert(
false &&
"cannot change visibility of sequence");
125GetSequenceOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
127 symbolTable.lookupNearestSymbolFrom<SequenceOp>(*
this, getSequenceAttr());
130 <<
"'" << getSequence()
131 <<
"' does not reference a valid 'rtg.sequence' operation";
133 if (
seq.getSequenceType() != getType())
134 return emitOpError(
"referenced 'rtg.sequence' op's type does not match");
143LogicalResult SubstituteSequenceOp::verify() {
144 if (getReplacements().
empty())
145 return emitOpError(
"must at least have one replacement value");
147 if (getReplacements().size() >
148 getSequence().getType().getElementTypes().size())
150 "must not have more replacement values than sequence arguments");
152 if (getReplacements().getTypes() !=
153 getSequence().getType().getElementTypes().take_front(
154 getReplacements().size()))
155 return emitOpError(
"replacement types must match the same number of "
156 "sequence argument types from the front");
161LogicalResult SubstituteSequenceOp::inferReturnTypes(
162 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
163 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
164 SmallVectorImpl<Type> &inferredReturnTypes) {
165 ArrayRef<Type> argTypes =
166 cast<SequenceType>(operands[0].getType()).getElementTypes();
168 SequenceType::get(context, argTypes.drop_front(operands.size() - 1));
169 inferredReturnTypes.push_back(seqType);
173ParseResult SubstituteSequenceOp::parse(::mlir::OpAsmParser &parser,
174 ::mlir::OperationState &result) {
175 OpAsmParser::UnresolvedOperand sequenceRawOperand;
176 SmallVector<OpAsmParser::UnresolvedOperand, 4> replacementsOperands;
177 Type sequenceRawType;
179 if (parser.parseOperand(sequenceRawOperand) || parser.parseLParen())
182 auto replacementsOperandsLoc = parser.getCurrentLocation();
183 if (parser.parseOperandList(replacementsOperands) || parser.parseRParen() ||
184 parser.parseColon() || parser.parseType(sequenceRawType) ||
185 parser.parseOptionalAttrDict(result.attributes))
188 if (!isa<SequenceType>(sequenceRawType))
189 return parser.emitError(parser.getNameLoc())
190 <<
"'sequence' must be handle to a sequence or sequence family, but "
194 if (parser.resolveOperand(sequenceRawOperand, sequenceRawType,
198 if (parser.resolveOperands(replacementsOperands,
199 cast<SequenceType>(sequenceRawType)
201 .take_front(replacementsOperands.size()),
202 replacementsOperandsLoc, result.operands))
205 SmallVector<Type> inferredReturnTypes;
206 if (failed(inferReturnTypes(
207 parser.getContext(), result.location, result.operands,
208 result.attributes.getDictionary(parser.getContext()),
209 result.getRawProperties(), result.regions, inferredReturnTypes)))
212 result.addTypes(inferredReturnTypes);
216void SubstituteSequenceOp::print(OpAsmPrinter &p) {
217 p <<
' ' << getSequence() <<
"(" << getReplacements()
218 <<
") : " << getSequence().getType();
219 p.printOptionalAttrDict((*this)->getAttrs(), {});
226LogicalResult InterleaveSequencesOp::verify() {
227 if (getSequences().
empty())
228 return emitOpError(
"must have at least one sequence in the list");
233OpFoldResult InterleaveSequencesOp::fold(FoldAdaptor adaptor) {
234 if (getSequences().size() == 1)
235 return getSequences()[0];
244ParseResult SetCreateOp::parse(OpAsmParser &parser, OperationState &result) {
245 llvm::SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
248 if (parser.parseOperandList(operands) ||
249 parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() ||
250 parser.parseType(elemType))
253 result.addTypes({SetType::get(result.getContext(), elemType)});
255 for (
auto operand : operands)
256 if (parser.resolveOperand(operand, elemType, result.operands))
262void SetCreateOp::print(OpAsmPrinter &p) {
264 p.printOperands(getElements());
265 p.printOptionalAttrDict((*this)->getAttrs());
266 p <<
" : " << getSet().getType().getElementType();
269LogicalResult SetCreateOp::verify() {
270 if (getElements().size() > 0) {
273 if (getElements()[0].getType() != getSet().getType().getElementType())
274 return emitOpError() <<
"operand types must match set element type";
284LogicalResult SetCartesianProductOp::inferReturnTypes(
285 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
286 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
287 SmallVectorImpl<Type> &inferredReturnTypes) {
288 if (operands.empty()) {
290 return mlir::emitError(*loc) <<
"at least one set must be provided";
294 SmallVector<Type> elementTypes;
295 for (
auto operand : operands)
296 elementTypes.push_back(cast<SetType>(operand.getType()).getElementType());
297 inferredReturnTypes.push_back(
298 SetType::get(rtg::TupleType::get(context, elementTypes)));
306ParseResult BagCreateOp::parse(OpAsmParser &parser, OperationState &result) {
307 llvm::SmallVector<OpAsmParser::UnresolvedOperand, 16> elementOperands,
311 if (!parser.parseOptionalLParen()) {
313 OpAsmParser::UnresolvedOperand elementOperand, multipleOperand;
314 if (parser.parseOperand(multipleOperand) || parser.parseKeyword(
"x") ||
315 parser.parseOperand(elementOperand))
318 elementOperands.push_back(elementOperand);
319 multipleOperands.push_back(multipleOperand);
321 if (parser.parseOptionalComma()) {
322 if (parser.parseRParen())
329 if (parser.parseColon() || parser.parseType(elemType) ||
330 parser.parseOptionalAttrDict(result.attributes))
333 result.addTypes({BagType::get(result.getContext(), elemType)});
335 for (
auto operand : elementOperands)
336 if (parser.resolveOperand(operand, elemType, result.operands))
339 for (
auto operand : multipleOperands)
340 if (parser.resolveOperand(operand, IndexType::
get(result.getContext()),
347void BagCreateOp::print(OpAsmPrinter &p) {
349 if (!getElements().
empty())
351 llvm::interleaveComma(llvm::zip(getElements(), getMultiples()), p,
352 [&](
auto elAndMultiple) {
353 auto [el, multiple] = elAndMultiple;
354 p << multiple <<
" x " << el;
356 if (!getElements().
empty())
359 p <<
" : " << getBag().getType().getElementType();
360 p.printOptionalAttrDict((*this)->getAttrs());
363LogicalResult BagCreateOp::verify() {
364 if (!llvm::all_equal(getElements().getTypes()))
365 return emitOpError() <<
"types of all elements must match";
367 if (getElements().size() > 0)
368 if (getElements()[0].getType() != getBag().getType().getElementType())
369 return emitOpError() <<
"operand types must match bag element type";
378LogicalResult TupleCreateOp::inferReturnTypes(
379 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
380 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
381 SmallVectorImpl<Type> &inferredReturnTypes) {
382 SmallVector<Type> elementTypes;
383 for (
auto operand : operands)
384 elementTypes.push_back(operand.getType());
385 inferredReturnTypes.push_back(rtg::TupleType::get(context, elementTypes));
393LogicalResult TupleExtractOp::inferReturnTypes(
394 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
395 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
396 SmallVectorImpl<Type> &inferredReturnTypes) {
397 assert(operands.size() == 1 &&
"must have exactly one operand");
399 auto tupleTy = dyn_cast<rtg::TupleType>(operands[0].getType());
400 size_t idx = properties.as<Properties *>()->getIndex().getInt();
403 return mlir::emitError(*loc) <<
"only RTG tuples are supported";
407 if (tupleTy.getFieldTypes().size() <= idx) {
409 return mlir::emitError(*loc)
411 <<
") must be smaller than number of elements in tuple ("
412 << tupleTy.getFieldTypes().size() <<
")";
416 inferredReturnTypes.push_back(tupleTy.getFieldTypes()[idx]);
424LogicalResult FixedRegisterOp::inferReturnTypes(
425 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
426 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
427 SmallVectorImpl<Type> &inferredReturnTypes) {
428 inferredReturnTypes.push_back(
429 properties.as<Properties *>()->getReg().getType());
433OpFoldResult FixedRegisterOp::fold(FoldAdaptor adaptor) {
return getRegAttr(); }
439LogicalResult VirtualRegisterOp::verify() {
440 if (getAllowedRegs().
empty())
441 return emitOpError(
"must have at least one allowed register");
443 if (llvm::any_of(getAllowedRegs(), [](Attribute attr) {
444 return !isa<RegisterAttrInterface>(attr);
446 return emitOpError(
"all elements must be of RegisterAttrInterface");
448 if (!llvm::all_equal(
449 llvm::map_range(getAllowedRegs().getAsRange<RegisterAttrInterface>(),
450 [](
auto attr) {
return attr.getType(); })))
451 return emitOpError(
"all allowed registers must be of the same type");
456LogicalResult VirtualRegisterOp::inferReturnTypes(
457 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
458 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
459 SmallVectorImpl<Type> &inferredReturnTypes) {
460 auto allowedRegs = properties.as<Properties *>()->getAllowedRegs();
461 if (allowedRegs.empty()) {
463 return mlir::emitError(*loc,
"must have at least one allowed register");
468 auto regAttr = dyn_cast<RegisterAttrInterface>(allowedRegs[0]);
471 return mlir::emitError(
472 *loc,
"allowed register attributes must be of RegisterAttrInterface");
476 inferredReturnTypes.push_back(regAttr.getType());
484LogicalResult ContextSwitchOp::verify() {
485 auto elementTypes = getSequence().getType().getElementTypes();
486 if (elementTypes.size() != 3)
487 return emitOpError(
"sequence type must have exactly 3 element types");
489 if (getFrom().getType() != elementTypes[0])
491 "first sequence element type must match 'from' attribute type");
493 if (getTo().getType() != elementTypes[1])
495 "second sequence element type must match 'to' attribute type");
497 auto seqTy = dyn_cast<SequenceType>(elementTypes[2]);
498 if (!seqTy || !seqTy.getElementTypes().empty())
500 "third sequence element type must be a fully substituted sequence");
509LogicalResult TestOp::verifyRegions() {
510 if (!getTargetType().entryTypesMatch(getBody()->getArgumentTypes()))
511 return emitOpError(
"argument types must match dict entry types");
516LogicalResult TestOp::verify() {
517 if (getTemplateName().
empty())
518 return emitOpError(
"template name must not be empty");
523LogicalResult TestOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
524 if (!getTargetAttr())
528 symbolTable.lookupNearestSymbolFrom<TargetOp>(*
this, getTargetAttr());
531 <<
"'" << *getTarget()
532 <<
"' does not reference a valid 'rtg.target' operation";
536 size_t targetIdx = 0;
537 auto targetEntries = target.getTarget().getEntries();
538 for (
auto testEntry : getTargetType().getEntries()) {
540 while (targetIdx < targetEntries.size() &&
541 targetEntries[targetIdx].name.getValue() < testEntry.name.getValue())
545 if (targetIdx >= targetEntries.size() ||
546 targetEntries[targetIdx].name != testEntry.name ||
547 targetEntries[targetIdx].type != testEntry.type) {
548 return emitOpError(
"referenced 'rtg.target' op's type is invalid: "
549 "missing entry called '")
550 << testEntry.name.getValue() <<
"' of type " << testEntry.type;
557ParseResult TestOp::parse(OpAsmParser &parser, OperationState &result) {
559 StringAttr symNameAttr;
560 if (parser.parseSymbolName(symNameAttr))
563 result.getOrAddProperties<TestOp::Properties>().sym_name = symNameAttr;
566 SmallVector<OpAsmParser::Argument> arguments;
567 SmallVector<StringAttr> names;
569 auto parseOneArgument = [&]() -> ParseResult {
571 if (parser.parseKeywordOrString(&name) || parser.parseEqual() ||
572 parser.parseArgument(arguments.emplace_back(),
true,
576 names.push_back(StringAttr::get(result.getContext(), name));
579 if (parser.parseCommaSeparatedList(OpAsmParser::Delimiter::Paren,
580 parseOneArgument,
" in argument list"))
583 SmallVector<Type> argTypes;
584 SmallVector<DictEntry> entries;
585 SmallVector<Location> argLocs;
586 argTypes.reserve(arguments.size());
587 argLocs.reserve(arguments.size());
588 for (
auto [name, arg] :
llvm::zip(names, arguments)) {
589 argTypes.push_back(arg.type);
590 argLocs.push_back(arg.sourceLoc ? *arg.sourceLoc : result.location);
591 entries.push_back({name, arg.type});
593 auto emitError = [&]() -> InFlightDiagnostic {
594 return parser.emitError(parser.getCurrentLocation());
596 Type type = DictType::getChecked(emitError, result.getContext(),
597 ArrayRef<DictEntry>(entries));
600 result.getOrAddProperties<TestOp::Properties>().targetType =
603 std::string templateName;
604 if (!parser.parseOptionalKeyword(
"template")) {
605 auto loc = parser.getCurrentLocation();
606 if (parser.parseString(&templateName))
609 if (templateName.empty())
610 return parser.emitError(loc,
"template name must not be empty");
613 StringAttr templateNameAttr = symNameAttr;
614 if (!templateName.empty())
615 templateNameAttr = StringAttr::get(result.getContext(), templateName);
617 StringAttr targetName;
618 if (!parser.parseOptionalKeyword(
"target"))
619 if (parser.parseSymbolName(targetName))
622 result.getOrAddProperties<TestOp::Properties>().templateName =
624 result.getOrAddProperties<TestOp::Properties>().target = targetName;
626 auto loc = parser.getCurrentLocation();
627 if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
629 if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
630 return parser.emitError(loc)
631 <<
"'" << result.name.getStringRef() <<
"' op ";
635 std::unique_ptr<Region> bodyRegionRegion = std::make_unique<Region>();
636 if (parser.parseRegion(*bodyRegionRegion, arguments))
639 if (bodyRegionRegion->empty()) {
640 bodyRegionRegion->emplaceBlock();
641 bodyRegionRegion->addArguments(argTypes, argLocs);
643 result.addRegion(std::move(bodyRegionRegion));
648void TestOp::print(OpAsmPrinter &p) {
650 p.printSymbolName(getSymNameAttr().getValue());
652 SmallString<32> resultNameStr;
653 llvm::interleaveComma(
654 llvm::zip(getTargetType().getEntries(), getBody()->getArguments()), p,
655 [&](
auto entryAndArg) {
656 auto [entry, arg] = entryAndArg;
657 p << entry.name.getValue() <<
" = ";
658 p.printRegionArgument(arg);
662 if (getSymNameAttr() != getTemplateNameAttr())
663 p <<
" template " << getTemplateNameAttr();
665 if (getTargetAttr()) {
667 p.printSymbolName(getTargetAttr().getValue());
670 p.printOptionalAttrDictWithKeyword(
671 (*this)->getAttrs(), {getSymNameAttrName(), getTargetTypeAttrName(),
672 getTargetAttrName(), getTemplateNameAttrName()});
674 p.printRegion(getBodyRegion(),
false);
677void TestOp::getAsmBlockArgumentNames(Region ®ion,
679 for (
auto [entry, arg] :
680 llvm::zip(getTargetType().getEntries(), region.getArguments()))
681 setNameFn(arg, entry.name.getValue());
688LogicalResult TargetOp::verifyRegions() {
689 if (!getTarget().entryTypesMatch(
690 getBody()->getTerminator()->getOperandTypes()))
691 return emitOpError(
"terminator operand types must match dict entry types");
700LogicalResult ValidateOp::verify() {
701 if (!getRef().getType().isValidContentType(getValue().getType()))
703 "result type must be a valid content type for the ref value");
712LogicalResult ArrayCreateOp::verify() {
713 if (!getElements().
empty() &&
714 getElements()[0].getType() != getType().getElementType())
715 return emitOpError(
"operand types must match array element type, expected ")
716 << getType().getElementType() <<
" but got "
717 << getElements()[0].getType();
722ParseResult ArrayCreateOp::parse(OpAsmParser &parser, OperationState &result) {
723 SmallVector<OpAsmParser::UnresolvedOperand> operands;
726 if (parser.parseOperandList(operands) || parser.parseColon() ||
728 parser.parseOptionalAttrDict(result.attributes))
731 if (failed(parser.resolveOperands(operands,
elementType, result.operands)))
739void ArrayCreateOp::print(OpAsmPrinter &p) {
741 p.printOperands(getElements());
742 p <<
" : " << getType().getElementType();
743 p.printOptionalAttrDict((*this)->getAttrs(), {});
750LogicalResult MemoryBlockDeclareOp::verify() {
753 "base address width must match memory block address width");
757 "end address width must match memory block address width");
759 if (getBaseAddress().ugt(getEndAddress()))
761 "base address must be smaller than or equal to the end address");
766ParseResult MemoryBlockDeclareOp::parse(OpAsmParser &parser,
767 OperationState &result) {
768 SmallVector<OpAsmParser::UnresolvedOperand> operands;
769 MemoryBlockType memoryBlockType;
772 if (parser.parseLSquare())
775 auto startLoc = parser.getCurrentLocation();
776 if (parser.parseInteger(start))
779 if (parser.parseMinus())
782 auto endLoc = parser.getCurrentLocation();
783 if (parser.parseInteger(end) || parser.parseRSquare() ||
784 parser.parseColonType(memoryBlockType) ||
785 parser.parseOptionalAttrDict(result.attributes))
788 auto width = memoryBlockType.getAddressWidth();
789 auto adjustAPInt = [&](APInt value, llvm::SMLoc loc) -> FailureOr<APInt> {
790 if (value.getBitWidth() > width) {
791 if (!value.isIntN(width))
792 return parser.emitError(
794 "address out of range for memory block with address width ")
797 return value.trunc(width);
800 if (value.getBitWidth() < width)
801 return value.zext(width);
806 auto startRes = adjustAPInt(start, startLoc);
807 auto endRes = adjustAPInt(end, endLoc);
808 if (failed(startRes) || failed(endRes))
811 auto intType = IntegerType::get(result.getContext(), width);
812 result.addAttribute(getBaseAddressAttrName(result.name),
813 IntegerAttr::get(intType, *startRes));
814 result.addAttribute(getEndAddressAttrName(result.name),
815 IntegerAttr::get(intType, *endRes));
817 result.addTypes(memoryBlockType);
821void MemoryBlockDeclareOp::print(OpAsmPrinter &p) {
822 SmallVector<char> str;
823 getBaseAddress().toString(str, 16,
false,
false,
false);
827 getEndAddress().toString(str, 16,
false,
false,
false);
828 p << str <<
"] : " << getType();
829 p.printOptionalAttrDict((*this)->getAttrs(),
830 {getBaseAddressAttrName(), getEndAddressAttrName()});
837LogicalResult MemoryBaseAddressOp::inferReturnTypes(
838 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
839 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
840 SmallVectorImpl<Type> &inferredReturnTypes) {
841 if (operands.empty())
843 auto memTy = dyn_cast<MemoryType>(operands[0].getType());
846 inferredReturnTypes.push_back(
847 ImmediateType::get(context, memTy.getAddressWidth()));
855LogicalResult ConcatImmediateOp::inferReturnTypes(
856 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
857 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
858 SmallVectorImpl<Type> &inferredReturnTypes) {
859 if (operands.empty()) {
861 return mlir::emitError(*loc) <<
"at least one operand must be provided";
865 unsigned totalWidth = 0;
866 for (
auto operand : operands) {
867 auto immType = dyn_cast<ImmediateType>(operand.getType());
870 return mlir::emitError(*loc)
871 <<
"all operands must be of immediate type";
874 totalWidth += immType.getWidth();
877 inferredReturnTypes.push_back(ImmediateType::get(context, totalWidth));
881OpFoldResult ConcatImmediateOp::fold(FoldAdaptor adaptor) {
883 if (getOperands().size() == 1)
884 return getOperands()[0];
887 if (llvm::all_of(adaptor.getOperands(), [](Attribute attr) {
888 return isa_and_nonnull<ImmediateAttr>(attr);
890 auto result = APInt::getZeroWidth();
891 for (
auto attr : adaptor.getOperands())
892 result = result.
concat(cast<ImmediateAttr>(attr).getValue());
894 return ImmediateAttr::get(getContext(), result);
904LogicalResult SliceImmediateOp::verify() {
905 auto srcWidth = getInput().getType().getWidth();
906 auto dstWidth = getResult().getType().getWidth();
908 if (getLowBit() >= srcWidth)
909 return emitOpError(
"from bit too large for input (got ")
910 << getLowBit() <<
", but input width is " << srcWidth <<
")";
912 if (srcWidth - getLowBit() < dstWidth)
913 return emitOpError(
"slice does not fit in input (trying to extract ")
914 << dstWidth <<
" bits starting at index " << getLowBit()
915 <<
", but only " << (srcWidth - getLowBit())
916 <<
" bits are available)";
921OpFoldResult SliceImmediateOp::fold(FoldAdaptor adaptor) {
922 if (
auto inputAttr = dyn_cast_or_null<ImmediateAttr>(adaptor.getInput())) {
923 auto resultWidth = getType().getWidth();
924 APInt sliced = inputAttr.getValue().extractBits(resultWidth, getLowBit());
925 return ImmediateAttr::get(getContext(), sliced);
935#define GET_OP_CLASSES
936#include "circt/Dialect/RTG/IR/RTG.cpp.inc"
assert(baseType &&"element must be base type")
static SmallVector< T > concat(const SmallVectorImpl< T > &a, const SmallVectorImpl< T > &b)
Returns a new vector containing the concatenation of vectors a and b.
static size_t getAddressWidth(size_t depth)
static InstancePath empty
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
int64_t getBitWidth(mlir::Type type)
Return the hardware bit width of a type.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn