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(); }
41 if (
auto reg = dyn_cast<rtg::RegisterAttrInterface>(getValueAttr())) {
42 setNameFn(getResult(),
reg.getRegisterAssembly());
51LogicalResult SequenceOp::verifyRegions() {
52 if (TypeRange(getSequenceType().getElementTypes()) !=
53 getBody()->getArgumentTypes())
54 return emitOpError(
"sequence type does not match block argument types");
59ParseResult SequenceOp::parse(OpAsmParser &parser, OperationState &result) {
61 if (parser.parseSymbolName(
62 result.getOrAddProperties<SequenceOp::Properties>().sym_name))
66 SmallVector<OpAsmParser::Argument> arguments;
67 if (parser.parseArgumentList(arguments, OpAsmParser::Delimiter::Paren,
71 SmallVector<Type> argTypes;
72 SmallVector<Location> argLocs;
73 argTypes.reserve(arguments.size());
74 argLocs.reserve(arguments.size());
75 for (
auto &arg : arguments) {
76 argTypes.push_back(arg.type);
77 argLocs.push_back(arg.sourceLoc ? *arg.sourceLoc : result.location);
79 Type type = SequenceType::get(result.getContext(), argTypes);
80 result.getOrAddProperties<SequenceOp::Properties>().sequenceType =
83 auto loc = parser.getCurrentLocation();
84 if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
86 if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
87 return parser.emitError(loc)
88 <<
"'" << result.name.getStringRef() <<
"' op ";
92 std::unique_ptr<Region> bodyRegionRegion = std::make_unique<Region>();
93 if (parser.parseRegion(*bodyRegionRegion, arguments))
96 if (bodyRegionRegion->empty()) {
97 bodyRegionRegion->emplaceBlock();
98 bodyRegionRegion->addArguments(argTypes, argLocs);
100 result.addRegion(std::move(bodyRegionRegion));
105void SequenceOp::print(OpAsmPrinter &p) {
107 p.printSymbolName(getSymNameAttr().getValue());
109 llvm::interleaveComma(getBody()->getArguments(), p,
110 [&](
auto arg) { p.printRegionArgument(arg); });
112 p.printOptionalAttrDictWithKeyword(
113 (*this)->getAttrs(), {getSymNameAttrName(), getSequenceTypeAttrName()});
115 p.printRegion(getBodyRegion(),
false);
118mlir::SymbolTable::Visibility SequenceOp::getVisibility() {
119 return mlir::SymbolTable::Visibility::Private;
122void SequenceOp::setVisibility(mlir::SymbolTable::Visibility visibility) {
124 assert(
false &&
"cannot change visibility of sequence");
132GetSequenceOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
134 symbolTable.lookupNearestSymbolFrom<SequenceOp>(*
this, getSequenceAttr());
137 <<
"'" << getSequence()
138 <<
"' does not reference a valid 'rtg.sequence' operation";
140 if (
seq.getSequenceType() != getType())
141 return emitOpError(
"referenced 'rtg.sequence' op's type does not match");
150LogicalResult SubstituteSequenceOp::verify() {
151 if (getReplacements().
empty())
152 return emitOpError(
"must at least have one replacement value");
154 if (getReplacements().size() >
155 getSequence().getType().getElementTypes().size())
157 "must not have more replacement values than sequence arguments");
159 if (getReplacements().getTypes() !=
160 getSequence().getType().getElementTypes().take_front(
161 getReplacements().size()))
162 return emitOpError(
"replacement types must match the same number of "
163 "sequence argument types from the front");
168LogicalResult SubstituteSequenceOp::inferReturnTypes(
169 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
170 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
171 SmallVectorImpl<Type> &inferredReturnTypes) {
172 ArrayRef<Type> argTypes =
173 cast<SequenceType>(operands[0].getType()).getElementTypes();
175 SequenceType::get(context, argTypes.drop_front(operands.size() - 1));
176 inferredReturnTypes.push_back(seqType);
180ParseResult SubstituteSequenceOp::parse(::mlir::OpAsmParser &parser,
181 ::mlir::OperationState &result) {
182 OpAsmParser::UnresolvedOperand sequenceRawOperand;
183 SmallVector<OpAsmParser::UnresolvedOperand, 4> replacementsOperands;
184 Type sequenceRawType;
186 if (parser.parseOperand(sequenceRawOperand) || parser.parseLParen())
189 auto replacementsOperandsLoc = parser.getCurrentLocation();
190 if (parser.parseOperandList(replacementsOperands) || parser.parseRParen() ||
191 parser.parseColon() || parser.parseType(sequenceRawType) ||
192 parser.parseOptionalAttrDict(result.attributes))
195 if (!isa<SequenceType>(sequenceRawType))
196 return parser.emitError(parser.getNameLoc())
197 <<
"'sequence' must be handle to a sequence or sequence family, but "
201 if (parser.resolveOperand(sequenceRawOperand, sequenceRawType,
205 if (parser.resolveOperands(replacementsOperands,
206 cast<SequenceType>(sequenceRawType)
208 .take_front(replacementsOperands.size()),
209 replacementsOperandsLoc, result.operands))
212 SmallVector<Type> inferredReturnTypes;
213 if (failed(inferReturnTypes(
214 parser.getContext(), result.location, result.operands,
215 result.attributes.getDictionary(parser.getContext()),
216 result.getRawProperties(), result.regions, inferredReturnTypes)))
219 result.addTypes(inferredReturnTypes);
223void SubstituteSequenceOp::print(OpAsmPrinter &p) {
224 p <<
' ' << getSequence() <<
"(" << getReplacements()
225 <<
") : " << getSequence().getType();
226 p.printOptionalAttrDict((*this)->getAttrs(), {});
233LogicalResult InterleaveSequencesOp::verify() {
234 if (getSequences().
empty())
235 return emitOpError(
"must have at least one sequence in the list");
240OpFoldResult InterleaveSequencesOp::fold(FoldAdaptor adaptor) {
241 if (getSequences().size() == 1)
242 return getSequences()[0];
251ParseResult SetCreateOp::parse(OpAsmParser &parser, OperationState &result) {
252 llvm::SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
255 if (parser.parseOperandList(operands) ||
256 parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() ||
257 parser.parseType(elemType))
260 result.addTypes({SetType::get(result.getContext(), elemType)});
262 for (
auto operand : operands)
263 if (parser.resolveOperand(operand, elemType, result.operands))
269void SetCreateOp::print(OpAsmPrinter &p) {
271 p.printOperands(getElements());
272 p.printOptionalAttrDict((*this)->getAttrs());
273 p <<
" : " << getSet().getType().getElementType();
276LogicalResult SetCreateOp::verify() {
277 if (getElements().size() > 0) {
280 if (getElements()[0].getType() != getSet().getType().getElementType())
281 return emitOpError() <<
"operand types must match set element type";
291LogicalResult SetCartesianProductOp::inferReturnTypes(
292 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
293 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
294 SmallVectorImpl<Type> &inferredReturnTypes) {
295 if (operands.empty()) {
297 return mlir::emitError(*loc) <<
"at least one set must be provided";
301 SmallVector<Type> elementTypes;
302 for (
auto operand : operands)
303 elementTypes.push_back(cast<SetType>(operand.getType()).getElementType());
304 inferredReturnTypes.push_back(
305 SetType::get(rtg::TupleType::get(context, elementTypes)));
313ParseResult BagCreateOp::parse(OpAsmParser &parser, OperationState &result) {
314 llvm::SmallVector<OpAsmParser::UnresolvedOperand, 16> elementOperands,
318 if (!parser.parseOptionalLParen()) {
320 OpAsmParser::UnresolvedOperand elementOperand, multipleOperand;
321 if (parser.parseOperand(multipleOperand) || parser.parseKeyword(
"x") ||
322 parser.parseOperand(elementOperand))
325 elementOperands.push_back(elementOperand);
326 multipleOperands.push_back(multipleOperand);
328 if (parser.parseOptionalComma()) {
329 if (parser.parseRParen())
336 if (parser.parseColon() || parser.parseType(elemType) ||
337 parser.parseOptionalAttrDict(result.attributes))
340 result.addTypes({BagType::get(result.getContext(), elemType)});
342 for (
auto operand : elementOperands)
343 if (parser.resolveOperand(operand, elemType, result.operands))
346 for (
auto operand : multipleOperands)
347 if (parser.resolveOperand(operand, IndexType::
get(result.getContext()),
354void BagCreateOp::print(OpAsmPrinter &p) {
356 if (!getElements().
empty())
358 llvm::interleaveComma(llvm::zip(getElements(), getMultiples()), p,
359 [&](
auto elAndMultiple) {
360 auto [el, multiple] = elAndMultiple;
361 p << multiple <<
" x " << el;
363 if (!getElements().
empty())
366 p <<
" : " << getBag().getType().getElementType();
367 p.printOptionalAttrDict((*this)->getAttrs());
370LogicalResult BagCreateOp::verify() {
371 if (!llvm::all_equal(getElements().getTypes()))
372 return emitOpError() <<
"types of all elements must match";
374 if (getElements().size() > 0)
375 if (getElements()[0].getType() != getBag().getType().getElementType())
376 return emitOpError() <<
"operand types must match bag element type";
385LogicalResult TupleCreateOp::inferReturnTypes(
386 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
387 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
388 SmallVectorImpl<Type> &inferredReturnTypes) {
389 SmallVector<Type> elementTypes;
390 for (
auto operand : operands)
391 elementTypes.push_back(operand.getType());
392 inferredReturnTypes.push_back(rtg::TupleType::get(context, elementTypes));
400LogicalResult TupleExtractOp::inferReturnTypes(
401 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
402 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
403 SmallVectorImpl<Type> &inferredReturnTypes) {
404 assert(operands.size() == 1 &&
"must have exactly one operand");
406 auto tupleTy = dyn_cast<rtg::TupleType>(operands[0].getType());
407 size_t idx = properties.as<Properties *>()->getIndex().getInt();
410 return mlir::emitError(*loc) <<
"only RTG tuples are supported";
414 if (tupleTy.getFieldTypes().size() <= idx) {
416 return mlir::emitError(*loc)
418 <<
") must be smaller than number of elements in tuple ("
419 << tupleTy.getFieldTypes().size() <<
")";
423 inferredReturnTypes.push_back(tupleTy.getFieldTypes()[idx]);
431LogicalResult VirtualRegisterOp::inferReturnTypes(
432 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
433 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
434 SmallVectorImpl<Type> &inferredReturnTypes) {
435 auto allowedRegs = properties.as<Properties *>()->getAllowedRegs();
436 inferredReturnTypes.push_back(allowedRegs.getType());
444LogicalResult ContextSwitchOp::verify() {
445 auto elementTypes = getSequence().getType().getElementTypes();
446 if (elementTypes.size() != 3)
447 return emitOpError(
"sequence type must have exactly 3 element types");
449 if (getFrom().getType() != elementTypes[0])
451 "first sequence element type must match 'from' attribute type");
453 if (getTo().getType() != elementTypes[1])
455 "second sequence element type must match 'to' attribute type");
457 auto seqTy = dyn_cast<SequenceType>(elementTypes[2]);
458 if (!seqTy || !seqTy.getElementTypes().empty())
460 "third sequence element type must be a fully substituted sequence");
469LogicalResult TestOp::verifyRegions() {
470 if (!getTargetType().entryTypesMatch(getBody()->getArgumentTypes()))
471 return emitOpError(
"argument types must match dict entry types");
476LogicalResult TestOp::verify() {
477 if (getTemplateName().
empty())
478 return emitOpError(
"template name must not be empty");
483LogicalResult TestOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
484 if (!getTargetAttr())
488 symbolTable.lookupNearestSymbolFrom<TargetOp>(*
this, getTargetAttr());
491 <<
"'" << *getTarget()
492 <<
"' does not reference a valid 'rtg.target' operation";
496 size_t targetIdx = 0;
497 auto targetEntries = target.getTarget().getEntries();
498 for (
auto testEntry : getTargetType().getEntries()) {
500 while (targetIdx < targetEntries.size() &&
501 targetEntries[targetIdx].name.getValue() < testEntry.name.getValue())
505 if (targetIdx >= targetEntries.size() ||
506 targetEntries[targetIdx].name != testEntry.name ||
507 targetEntries[targetIdx].type != testEntry.type) {
508 return emitOpError(
"referenced 'rtg.target' op's type is invalid: "
509 "missing entry called '")
510 << testEntry.name.getValue() <<
"' of type " << testEntry.type;
517ParseResult TestOp::parse(OpAsmParser &parser, OperationState &result) {
519 StringAttr symNameAttr;
520 if (parser.parseSymbolName(symNameAttr))
523 result.getOrAddProperties<TestOp::Properties>().sym_name = symNameAttr;
526 SmallVector<OpAsmParser::Argument> arguments;
527 SmallVector<StringAttr> names;
529 auto parseOneArgument = [&]() -> ParseResult {
531 if (parser.parseKeywordOrString(&name) || parser.parseEqual() ||
532 parser.parseArgument(arguments.emplace_back(),
true,
536 names.push_back(StringAttr::get(result.getContext(), name));
539 if (parser.parseCommaSeparatedList(OpAsmParser::Delimiter::Paren,
540 parseOneArgument,
" in argument list"))
543 SmallVector<Type> argTypes;
544 SmallVector<DictEntry> entries;
545 SmallVector<Location> argLocs;
546 argTypes.reserve(arguments.size());
547 argLocs.reserve(arguments.size());
548 for (
auto [name, arg] :
llvm::zip(names, arguments)) {
549 argTypes.push_back(arg.type);
550 argLocs.push_back(arg.sourceLoc ? *arg.sourceLoc : result.location);
551 entries.push_back({name, arg.type});
553 auto emitError = [&]() -> InFlightDiagnostic {
554 return parser.emitError(parser.getCurrentLocation());
556 Type type = DictType::getChecked(emitError, result.getContext(),
557 ArrayRef<DictEntry>(entries));
560 result.getOrAddProperties<TestOp::Properties>().targetType =
563 std::string templateName;
564 if (!parser.parseOptionalKeyword(
"template")) {
565 auto loc = parser.getCurrentLocation();
566 if (parser.parseString(&templateName))
569 if (templateName.empty())
570 return parser.emitError(loc,
"template name must not be empty");
573 StringAttr templateNameAttr = symNameAttr;
574 if (!templateName.empty())
575 templateNameAttr = StringAttr::get(result.getContext(), templateName);
577 StringAttr targetName;
578 if (!parser.parseOptionalKeyword(
"target"))
579 if (parser.parseSymbolName(targetName))
582 result.getOrAddProperties<TestOp::Properties>().templateName =
584 result.getOrAddProperties<TestOp::Properties>().target = targetName;
586 auto loc = parser.getCurrentLocation();
587 if (parser.parseOptionalAttrDictWithKeyword(result.attributes))
589 if (failed(verifyInherentAttrs(result.name, result.attributes, [&]() {
590 return parser.emitError(loc)
591 <<
"'" << result.name.getStringRef() <<
"' op ";
595 std::unique_ptr<Region> bodyRegionRegion = std::make_unique<Region>();
596 if (parser.parseRegion(*bodyRegionRegion, arguments))
599 if (bodyRegionRegion->empty()) {
600 bodyRegionRegion->emplaceBlock();
601 bodyRegionRegion->addArguments(argTypes, argLocs);
603 result.addRegion(std::move(bodyRegionRegion));
608void TestOp::print(OpAsmPrinter &p) {
610 p.printSymbolName(getSymNameAttr().getValue());
612 SmallString<32> resultNameStr;
613 llvm::interleaveComma(
614 llvm::zip(getTargetType().getEntries(), getBody()->getArguments()), p,
615 [&](
auto entryAndArg) {
616 auto [entry, arg] = entryAndArg;
617 p << entry.name.getValue() <<
" = ";
618 p.printRegionArgument(arg);
622 if (getSymNameAttr() != getTemplateNameAttr())
623 p <<
" template " << getTemplateNameAttr();
625 if (getTargetAttr()) {
627 p.printSymbolName(getTargetAttr().getValue());
630 p.printOptionalAttrDictWithKeyword(
631 (*this)->getAttrs(), {getSymNameAttrName(), getTargetTypeAttrName(),
632 getTargetAttrName(), getTemplateNameAttrName()});
634 p.printRegion(getBodyRegion(),
false);
637void TestOp::getAsmBlockArgumentNames(Region ®ion,
639 for (
auto [entry, arg] :
640 llvm::zip(getTargetType().getEntries(), region.getArguments()))
641 setNameFn(arg, entry.name.getValue());
648LogicalResult TargetOp::verifyRegions() {
649 if (!getTarget().entryTypesMatch(
650 getBody()->getTerminator()->getOperandTypes()))
651 return emitOpError(
"terminator operand types must match dict entry types");
660LogicalResult ValidateOp::verify() {
661 if (!getRef().getType().isValidContentType(getValue().getType()))
663 "result type must be a valid content type for the ref value");
672LogicalResult ArrayCreateOp::verify() {
673 if (!getElements().
empty() &&
674 getElements()[0].getType() != getType().getElementType())
675 return emitOpError(
"operand types must match array element type, expected ")
676 << getType().getElementType() <<
" but got "
677 << getElements()[0].getType();
682ParseResult ArrayCreateOp::parse(OpAsmParser &parser, OperationState &result) {
683 SmallVector<OpAsmParser::UnresolvedOperand> operands;
686 if (parser.parseOperandList(operands) || parser.parseColon() ||
688 parser.parseOptionalAttrDict(result.attributes))
691 if (failed(parser.resolveOperands(operands,
elementType, result.operands)))
699void ArrayCreateOp::print(OpAsmPrinter &p) {
701 p.printOperands(getElements());
702 p <<
" : " << getType().getElementType();
703 p.printOptionalAttrDict((*this)->getAttrs(), {});
710LogicalResult MemoryBlockDeclareOp::verify() {
713 "base address width must match memory block address width");
717 "end address width must match memory block address width");
719 if (getBaseAddress().ugt(getEndAddress()))
721 "base address must be smaller than or equal to the end address");
726ParseResult MemoryBlockDeclareOp::parse(OpAsmParser &parser,
727 OperationState &result) {
728 SmallVector<OpAsmParser::UnresolvedOperand> operands;
729 MemoryBlockType memoryBlockType;
732 if (parser.parseLSquare())
735 auto startLoc = parser.getCurrentLocation();
736 if (parser.parseInteger(start))
739 if (parser.parseMinus())
742 auto endLoc = parser.getCurrentLocation();
743 if (parser.parseInteger(end) || parser.parseRSquare() ||
744 parser.parseColonType(memoryBlockType) ||
745 parser.parseOptionalAttrDict(result.attributes))
748 auto width = memoryBlockType.getAddressWidth();
749 auto adjustAPInt = [&](APInt value, llvm::SMLoc loc) -> FailureOr<APInt> {
750 if (value.getBitWidth() > width) {
751 if (!value.isIntN(width))
752 return parser.emitError(
754 "address out of range for memory block with address width ")
757 return value.trunc(width);
760 if (value.getBitWidth() < width)
761 return value.zext(width);
766 auto startRes = adjustAPInt(start, startLoc);
767 auto endRes = adjustAPInt(end, endLoc);
768 if (failed(startRes) || failed(endRes))
771 auto intType = IntegerType::get(result.getContext(), width);
772 result.addAttribute(getBaseAddressAttrName(result.name),
773 IntegerAttr::get(intType, *startRes));
774 result.addAttribute(getEndAddressAttrName(result.name),
775 IntegerAttr::get(intType, *endRes));
777 result.addTypes(memoryBlockType);
781void MemoryBlockDeclareOp::print(OpAsmPrinter &p) {
782 SmallVector<char> str;
783 getBaseAddress().toString(str, 16,
false,
false,
false);
787 getEndAddress().toString(str, 16,
false,
false,
false);
788 p << str <<
"] : " << getType();
789 p.printOptionalAttrDict((*this)->getAttrs(),
790 {getBaseAddressAttrName(), getEndAddressAttrName()});
797LogicalResult MemoryBaseAddressOp::inferReturnTypes(
798 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
799 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
800 SmallVectorImpl<Type> &inferredReturnTypes) {
801 if (operands.empty())
803 auto memTy = dyn_cast<MemoryType>(operands[0].getType());
806 inferredReturnTypes.push_back(
807 ImmediateType::get(context, memTy.getAddressWidth()));
815LogicalResult ConcatImmediateOp::inferReturnTypes(
816 MLIRContext *context, std::optional<Location> loc, ValueRange operands,
817 DictionaryAttr attributes, OpaqueProperties properties, RegionRange regions,
818 SmallVectorImpl<Type> &inferredReturnTypes) {
819 if (operands.empty()) {
821 return mlir::emitError(*loc) <<
"at least one operand must be provided";
825 unsigned totalWidth = 0;
826 for (
auto operand : operands) {
827 auto immType = dyn_cast<ImmediateType>(operand.getType());
830 return mlir::emitError(*loc)
831 <<
"all operands must be of immediate type";
834 totalWidth += immType.getWidth();
837 inferredReturnTypes.push_back(ImmediateType::get(context, totalWidth));
841OpFoldResult ConcatImmediateOp::fold(FoldAdaptor adaptor) {
843 if (getOperands().size() == 1)
844 return getOperands()[0];
847 if (llvm::all_of(adaptor.getOperands(), [](Attribute attr) {
848 return isa_and_nonnull<ImmediateAttr>(attr);
850 auto result = APInt::getZeroWidth();
851 for (
auto attr : adaptor.getOperands())
852 result = result.
concat(cast<ImmediateAttr>(attr).getValue());
854 return ImmediateAttr::get(getContext(), result);
864LogicalResult SliceImmediateOp::verify() {
865 auto srcWidth = getInput().getType().getWidth();
866 auto dstWidth = getResult().getType().getWidth();
868 if (getLowBit() >= srcWidth)
869 return emitOpError(
"from bit too large for input (got ")
870 << getLowBit() <<
", but input width is " << srcWidth <<
")";
872 if (srcWidth - getLowBit() < dstWidth)
873 return emitOpError(
"slice does not fit in input (trying to extract ")
874 << dstWidth <<
" bits starting at index " << getLowBit()
875 <<
", but only " << (srcWidth - getLowBit())
876 <<
" bits are available)";
881OpFoldResult SliceImmediateOp::fold(FoldAdaptor adaptor) {
882 if (
auto inputAttr = dyn_cast_or_null<ImmediateAttr>(adaptor.getInput())) {
883 auto resultWidth = getType().getWidth();
884 APInt sliced = inputAttr.getValue().extractBits(resultWidth, getLowBit());
885 return ImmediateAttr::get(getContext(), sliced);
896 ArrayRef<Attribute> substitutes) {
897 if (substitutes.empty() || formatString.empty())
900 auto original = formatString.getValue().str();
902 for (
auto [i, subst] : llvm::enumerate(substitutes)) {
903 auto substInt = dyn_cast_or_null<IntegerAttr>(subst);
904 std::string substString;
905 if (!substInt && curr == i) {
910 substString =
"{{" + std::to_string(curr++) +
"}}";
912 substString = std::to_string(substInt.getValue().getZExtValue());
915 std::string from =
"{{" + std::to_string(i) +
"}}";
916 while ((startPos = original.find(from, startPos)) != std::string::npos) {
917 original.replace(startPos, from.length(), substString);
921 return StringAttr::get(formatString.getContext(), original);
924template <
typename OpTy>
926 auto newFormatString =
928 if (newFormatString == op.getFormatStringAttr())
931 op.setFormatStringAttr(newFormatString);
933 SmallVector<Value> newArgs;
934 for (
auto [arg, attr] : llvm::zip(op.getArgs(), adaptor.getArgs())) {
936 newArgs.push_back(arg);
938 op.getArgsMutable().assign(newArgs);
940 return op.getLabel();
943OpFoldResult LabelUniqueDeclOp::fold(FoldAdaptor adaptor) {
947OpFoldResult LabelDeclOp::fold(FoldAdaptor adaptor) {
955#define GET_OP_CLASSES
956#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 StringAttr substituteFormatString(StringAttr formatString, ArrayRef< Attribute > substitutes)
OpFoldResult labelDeclFolder(OpTy op, typename OpTy::FoldAdaptor adaptor)
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
reg(value, clock, reset=None, reset_value=None, name=None, sym_name=None)