CIRCT 24.0.0git
Loading...
Searching...
No Matches
OMOps.cpp
Go to the documentation of this file.
1//===- OMOps.cpp - Object Model operation definitions ---------------------===//
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// This file contains the Object Model operation definitions.
10//
11//===----------------------------------------------------------------------===//
12
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/ImplicitLocOpBuilder.h"
18#include "mlir/IR/SymbolTable.h"
19#include "llvm/ADT/STLExtras.h"
20
21using namespace mlir;
22using namespace circt::om;
23
24//===----------------------------------------------------------------------===//
25// Custom Printers and Parsers
26//===----------------------------------------------------------------------===//
27
28static ParseResult parseBasePathString(OpAsmParser &parser, PathAttr &path) {
29 auto *context = parser.getContext();
30 auto loc = parser.getCurrentLocation();
31 std::string rawPath;
32 if (parser.parseString(&rawPath))
33 return failure();
34 if (parseBasePath(context, rawPath, path))
35 return parser.emitError(loc, "invalid base path");
36 return success();
37}
38
39static void printBasePathString(OpAsmPrinter &p, Operation *op, PathAttr path) {
40 p << '\"';
41 llvm::interleave(
42 path, p,
43 [&](const PathElement &elt) {
44 p << elt.module.getValue() << '/' << elt.instance.getValue();
45 },
46 ":");
47 p << '\"';
48}
49
50static ParseResult parsePathString(OpAsmParser &parser, PathAttr &path,
51 StringAttr &module, StringAttr &ref,
52 StringAttr &field) {
53
54 auto *context = parser.getContext();
55 auto loc = parser.getCurrentLocation();
56 std::string rawPath;
57 if (parser.parseString(&rawPath))
58 return failure();
59 if (parsePath(context, rawPath, path, module, ref, field))
60 return parser.emitError(loc, "invalid path");
61 return success();
62}
63
64static void printPathString(OpAsmPrinter &p, Operation *op, PathAttr path,
65 StringAttr module, StringAttr ref,
66 StringAttr field) {
67 p << '\"';
68 for (const auto &elt : path)
69 p << elt.module.getValue() << '/' << elt.instance.getValue() << ':';
70 if (!module.getValue().empty())
71 p << module.getValue();
72 if (!ref.getValue().empty())
73 p << '>' << ref.getValue();
74 if (!field.getValue().empty())
75 p << field.getValue();
76 p << '\"';
77}
78
79static ParseResult parseFieldLocs(OpAsmParser &parser, ArrayAttr &fieldLocs) {
80 if (parser.parseOptionalKeyword("field_locs"))
81 return success();
82 if (parser.parseLParen() || parser.parseAttribute(fieldLocs) ||
83 parser.parseRParen()) {
84 return failure();
85 }
86 return success();
87}
88
89static void printFieldLocs(OpAsmPrinter &printer, Operation *op,
90 ArrayAttr fieldLocs) {
91 mlir::OpPrintingFlags flags;
92 if (!flags.shouldPrintDebugInfo() || !fieldLocs)
93 return;
94 printer << "field_locs(";
95 printer.printAttribute(fieldLocs);
96 printer << ")";
97}
98
99//===----------------------------------------------------------------------===//
100// Shared definitions
101//===----------------------------------------------------------------------===//
102static ParseResult parseClassFieldsList(OpAsmParser &parser,
103 SmallVectorImpl<Attribute> &fieldNames,
104 SmallVectorImpl<Type> &fieldTypes) {
105
106 llvm::StringMap<SMLoc> nameLocMap;
107 auto parseElt = [&]() -> ParseResult {
108 // Parse the field name.
109 std::string fieldName;
110 if (parser.parseKeywordOrString(&fieldName))
111 return failure();
112 SMLoc currLoc = parser.getCurrentLocation();
113 if (nameLocMap.count(fieldName)) {
114 parser.emitError(currLoc, "field \"")
115 << fieldName << "\" is defined twice";
116 parser.emitError(nameLocMap[fieldName]) << "previous definition is here";
117 return failure();
118 }
119 nameLocMap[fieldName] = currLoc;
120 fieldNames.push_back(StringAttr::get(parser.getContext(), fieldName));
121
122 // Parse the field type.
123 fieldTypes.emplace_back();
124 if (parser.parseColonType(fieldTypes.back()))
125 return failure();
126
127 return success();
128 };
129
130 return parser.parseCommaSeparatedList(OpAsmParser::Delimiter::Paren,
131 parseElt);
132}
133
134template <typename ClassTy>
135static ParseResult parseClassLike(OpAsmParser &parser, OperationState &state) {
136 // Parse the optional symbol visibility.
137 (void)mlir::impl::parseOptionalVisibilityKeyword(parser, state.attributes);
138
139 // Parse the Class symbol name.
140 StringAttr symName;
141 if (parser.parseSymbolName(symName, ClassTy::getSymNameAttrName(state.name),
142 state.attributes))
143 return failure();
144
145 // Parse the formal parameters.
146 SmallVector<OpAsmParser::Argument> args;
147 if (parser.parseArgumentList(args, OpAsmParser::Delimiter::Paren,
148 /*allowType=*/true, /*allowAttrs=*/false))
149 return failure();
150
151 SmallVector<Type> fieldTypes;
152 SmallVector<Attribute> fieldNames;
153 if (succeeded(parser.parseOptionalArrow()))
154 if (failed(parseClassFieldsList(parser, fieldNames, fieldTypes)))
155 return failure();
156
157 SmallVector<NamedAttribute> fieldTypesMap;
158 if (!fieldNames.empty()) {
159 for (auto [name, type] : zip(fieldNames, fieldTypes))
160 fieldTypesMap.push_back(
161 NamedAttribute(cast<StringAttr>(name), TypeAttr::get(type)));
162 }
163 auto *ctx = parser.getContext();
164 state.addAttribute("fieldNames", mlir::ArrayAttr::get(ctx, fieldNames));
165 state.addAttribute("fieldTypes",
166 mlir::DictionaryAttr::get(ctx, fieldTypesMap));
167
168 // Parse the optional attribute dictionary.
169 if (failed(parser.parseOptionalAttrDictWithKeyword(state.attributes)))
170 return failure();
171
172 // Parse the body.
173 Region *region = state.addRegion();
174 if (parser.parseRegion(*region, args))
175 return failure();
176
177 // If the region was empty, add an empty block so it's still a SizedRegion<1>.
178 if (region->empty())
179 region->emplaceBlock();
180
181 // Remember the formal parameter names in an attribute.
182 auto argNames = llvm::map_range(args, [&](OpAsmParser::Argument arg) {
183 return StringAttr::get(parser.getContext(), arg.ssaName.name.drop_front());
184 });
185 state.addAttribute(
186 "formalParamNames",
187 ArrayAttr::get(parser.getContext(), SmallVector<Attribute>(argNames)));
188
189 return success();
190}
191
192static void printClassLike(ClassLike classLike, OpAsmPrinter &printer) {
193 printer << " ";
194
195 // Print the optional symbol visibility.
196 StringRef visibilityAttrName =
197 mlir::SymbolOpInterface::getDefaultVisibilityAttrName();
198 if (auto visibility =
199 classLike->getAttrOfType<StringAttr>(visibilityAttrName))
200 printer << visibility.getValue() << ' ';
201
202 // Print the Class symbol name.
203 printer.printSymbolName(classLike.getSymName());
204
205 // Retrieve the formal parameter names and values.
206 auto argNames = SmallVector<StringRef>(
207 classLike.getFormalParamNames().getAsValueRange<StringAttr>());
208 ArrayRef<BlockArgument> args = classLike.getBodyBlock()->getArguments();
209
210 // Print the formal parameters.
211 printer << '(';
212 for (size_t i = 0, e = args.size(); i < e; ++i) {
213 printer << '%' << argNames[i] << ": " << args[i].getType();
214 if (i < e - 1)
215 printer << ", ";
216 }
217 printer << ") ";
218
219 ArrayRef<Attribute> fieldNames =
220 cast<ArrayAttr>(classLike->getAttr("fieldNames")).getValue();
221
222 if (!fieldNames.empty()) {
223 printer << " -> (";
224 for (size_t i = 0, e = fieldNames.size(); i < e; ++i) {
225 if (i != 0)
226 printer << ", ";
227 StringAttr name = cast<StringAttr>(fieldNames[i]);
228 printer.printKeywordOrString(name.getValue());
229 printer << ": ";
230 Type type = classLike.getFieldType(name).value();
231 printer.printType(type);
232 }
233 printer << ") ";
234 }
235
236 // Print the optional attribute dictionary.
237 SmallVector<StringRef> elidedAttrs{
238 classLike.getSymNameAttrName(), classLike.getFormalParamNamesAttrName(),
239 visibilityAttrName, "fieldTypes", "fieldNames"};
240 printer.printOptionalAttrDictWithKeyword(classLike.getOperation()->getAttrs(),
241 elidedAttrs);
242
243 // Print the body.
244 printer.printRegion(classLike.getBody(), /*printEntryBlockArgs=*/false,
245 /*printBlockTerminators=*/true);
246}
247
248LogicalResult verifyClassLike(ClassLike classLike) {
249 // Verify the formal parameter names match up with the values.
250 if (classLike.getFormalParamNames().size() !=
251 classLike.getBodyBlock()->getArguments().size()) {
252 auto error = classLike.emitOpError(
253 "formal parameter name list doesn't match formal parameter value list");
254 error.attachNote(classLike.getLoc())
255 << "formal parameter names: " << classLike.getFormalParamNames();
256 error.attachNote(classLike.getLoc())
257 << "formal parameter values: "
258 << classLike.getBodyBlock()->getArguments();
259 return error;
260 }
261
262 return success();
263}
264
265void getClassLikeAsmBlockArgumentNames(ClassLike classLike, Region &region,
266 OpAsmSetValueNameFn setNameFn) {
267 // Retrieve the formal parameter names and values.
268 auto argNames = SmallVector<StringRef>(
269 classLike.getFormalParamNames().getAsValueRange<StringAttr>());
270 ArrayRef<BlockArgument> args = classLike.getBodyBlock()->getArguments();
271
272 // Use the formal parameter names as the SSA value names.
273 for (size_t i = 0, e = args.size(); i < e; ++i)
274 setNameFn(args[i], argNames[i]);
275}
276
277NamedAttribute makeFieldType(StringAttr name, Type type) {
278 return NamedAttribute(name, TypeAttr::get(type));
279}
280
281NamedAttribute makeFieldIdx(MLIRContext *ctx, mlir::StringAttr name,
282 unsigned i) {
283 return NamedAttribute(StringAttr(name),
284 mlir::IntegerAttr::get(mlir::IndexType::get(ctx), i));
285}
286
287std::optional<Type> getClassLikeFieldType(ClassLike classLike,
288 StringAttr name) {
289 DictionaryAttr fieldTypes = mlir::cast<DictionaryAttr>(
290 classLike.getOperation()->getAttr("fieldTypes"));
291 Attribute type = fieldTypes.get(name);
292 if (auto field = dyn_cast_or_null<TypeAttr>(type))
293 return field.getValue();
294 return std::nullopt;
295}
296
297void replaceClassLikeFieldTypes(ClassLike classLike,
298 AttrTypeReplacer &replacer) {
299 classLike->setAttr("fieldTypes", cast<DictionaryAttr>(replacer.replace(
300 classLike.getFieldTypes())));
301}
302
303//===----------------------------------------------------------------------===//
304// ClassOp
305//===----------------------------------------------------------------------===//
306
307ParseResult circt::om::ClassOp::parse(OpAsmParser &parser,
308 OperationState &state) {
309 return parseClassLike<ClassOp>(parser, state);
310}
311
312circt::om::ClassOp circt::om::ClassOp::buildSimpleClassOp(
313 OpBuilder &odsBuilder, Location loc, Twine name,
314 ArrayRef<StringRef> formalParamNames, ArrayRef<StringRef> fieldNames,
315 ArrayRef<Type> fieldTypes) {
316 circt::om::ClassOp classOp = circt::om::ClassOp::create(
317 odsBuilder, loc, odsBuilder.getStringAttr(name), /*sym_visibility=*/{},
318 odsBuilder.getStrArrayAttr(formalParamNames),
319 odsBuilder.getStrArrayAttr(fieldNames),
320 odsBuilder.getDictionaryAttr(llvm::map_to_vector(
321 llvm::zip(fieldNames, fieldTypes), [&](auto field) -> NamedAttribute {
322 return NamedAttribute(odsBuilder.getStringAttr(std::get<0>(field)),
323 TypeAttr::get(std::get<1>(field)));
324 })));
325 Block *body = &classOp.getRegion().emplaceBlock();
326 auto prevLoc = odsBuilder.saveInsertionPoint();
327 odsBuilder.setInsertionPointToEnd(body);
328
329 mlir::SmallVector<Attribute> locAttrs(fieldNames.size(), LocationAttr(loc));
330
331 ClassFieldsOp::create(odsBuilder, loc,
332 llvm::map_to_vector(fieldTypes,
333 [&](Type type) -> Value {
334 return body->addArgument(type,
335 loc);
336 }),
337 odsBuilder.getArrayAttr(locAttrs));
338
339 odsBuilder.restoreInsertionPoint(prevLoc);
340
341 return classOp;
342}
343
344void circt::om::ClassOp::print(OpAsmPrinter &printer) {
345 printClassLike(*this, printer);
346}
347
348LogicalResult circt::om::ClassOp::verify() { return verifyClassLike(*this); }
349
350LogicalResult circt::om::ClassOp::verifyRegions() {
351 auto fieldsOp =
352 dyn_cast_or_null<ClassFieldsOp>(this->getBodyBlock()->getTerminator());
353 if (!fieldsOp)
354 return this->emitOpError("expected terminator to be ClassFieldsOp");
355
356 // The number of results matches the number of terminator operands.
357 if (fieldsOp.getNumOperands() != this->getFieldNames().size()) {
358 auto diag = this->emitOpError()
359 << "returns '" << this->getFieldNames().size()
360 << "' fields, but its terminator returned '"
361 << fieldsOp.getNumOperands() << "' fields";
362 return diag.attachNote(fieldsOp.getLoc()) << "see terminator:";
363 }
364
365 // The type of each result matches the corresponding terminator operand type.
366 auto types = this->getFieldTypes();
367 for (auto [fieldName, terminatorOperandType] :
368 llvm::zip(this->getFieldNames(), fieldsOp.getOperandTypes())) {
369
370 auto fieldNameAttr = dyn_cast_or_null<StringAttr>(fieldName);
371 if (!fieldNameAttr)
372 return this->emitOpError("field name is not a StringAttr");
373
374 if (auto fieldType = types.get(fieldNameAttr))
375 if (auto typeAttr = dyn_cast<TypeAttr>(fieldType))
376 if (typeAttr.getValue() == terminatorOperandType)
377 continue;
378
379 auto diag = this->emitOpError()
380 << "returns different field types than its terminator";
381 return diag.attachNote(fieldsOp.getLoc()) << "see terminator:";
382 }
383
384 return success();
385}
386
387void circt::om::ClassOp::getAsmBlockArgumentNames(
388 Region &region, OpAsmSetValueNameFn setNameFn) {
389 getClassLikeAsmBlockArgumentNames(*this, region, setNameFn);
390}
391
392std::optional<mlir::Type>
393circt::om::ClassOp::getFieldType(mlir::StringAttr field) {
394 return getClassLikeFieldType(*this, field);
395}
396
397void circt::om::ClassOp::replaceFieldTypes(AttrTypeReplacer replacer) {
398 replaceClassLikeFieldTypes(*this, replacer);
399}
400
401void circt::om::ClassOp::updateFields(
402 mlir::ArrayRef<mlir::Location> newLocations,
403 mlir::ArrayRef<mlir::Value> newValues,
404 mlir::ArrayRef<mlir::Attribute> newNames) {
405
406 auto fieldsOp = getFieldsOp();
407 assert(fieldsOp && "The fields op should exist");
408 // Get field names.
409 SmallVector<Attribute> names(getFieldNamesAttr().getAsRange<StringAttr>());
410 // Get the field types.
411 SmallVector<NamedAttribute> fieldTypes(getFieldTypesAttr().getValue());
412 // Get the field values.
413 SmallVector<Value> fieldVals(fieldsOp.getFields());
414 // Get the field locations.
415 Location fieldOpLoc = fieldsOp->getLoc();
416
417 // Extract the locations per field.
418 SmallVector<Location> locations;
419 if (auto fl = dyn_cast<FusedLoc>(fieldOpLoc)) {
420 auto metadataArr = dyn_cast<ArrayAttr>(fl.getMetadata());
421 assert(metadataArr && "Expected the metadata for the fused location");
422 auto r = metadataArr.getAsRange<LocationAttr>();
423 locations.append(r.begin(), r.end());
424 } else {
425 // Assume same loc for every field.
426 locations.append(names.size(), fieldOpLoc);
427 }
428
429 // Append the new names, locations and values.
430 names.append(newNames.begin(), newNames.end());
431 locations.append(newLocations.begin(), newLocations.end());
432 fieldVals.append(newValues.begin(), newValues.end());
433
434 // Construct the new field types from values and names.
435 for (auto [v, n] : llvm::zip(newValues, newNames))
436 fieldTypes.emplace_back(
437 NamedAttribute(llvm::cast<StringAttr>(n), TypeAttr::get(v.getType())));
438
439 // Keep the locations as array on the metadata.
440 SmallVector<Attribute> locationsAttr;
441 llvm::for_each(locations, [&](Location &l) {
442 locationsAttr.push_back(cast<Attribute>(l));
443 });
444
445 ImplicitLocOpBuilder builder(getLoc(), *this);
446 // Update the field names attribute.
447 setFieldNamesAttr(builder.getArrayAttr(names));
448 // Update the fields type attribute.
449 setFieldTypesAttr(builder.getDictionaryAttr(fieldTypes));
450 fieldsOp.getFieldsMutable().assign(fieldVals);
451 // Update the location.
452 fieldsOp->setLoc(builder.getFusedLoc(
453 locations, ArrayAttr::get(getContext(), locationsAttr)));
454}
455
456void circt::om::ClassOp::addNewFieldsOp(mlir::OpBuilder &builder,
457 mlir::ArrayRef<Location> locs,
458 mlir::ArrayRef<Value> values) {
459 // Store the original locations as a metadata array so that unique locations
460 // are preserved as a mapping from field index to location
461 assert(locs.size() == values.size() && "Expected a location per value");
462 mlir::SmallVector<Attribute> locAttrs;
463 for (auto loc : locs) {
464 locAttrs.push_back(cast<Attribute>(LocationAttr(loc)));
465 }
466 // Also store the locations incase there's some other analysis that might
467 // be able to use the default FusedLoc representation.
468 ClassFieldsOp::create(builder, builder.getFusedLoc(locs), values,
469 builder.getArrayAttr(locAttrs));
470}
471
472mlir::Location circt::om::ClassOp::getFieldLocByIndex(size_t i) {
473 auto fieldsOp = this->getFieldsOp();
474 auto fieldLocs = fieldsOp.getFieldLocs();
475 if (!fieldLocs.has_value())
476 return fieldsOp.getLoc();
477 assert(i < fieldLocs.value().size() &&
478 "field index too large for location array");
479 return cast<LocationAttr>(fieldLocs.value()[i]);
480}
481
482//===----------------------------------------------------------------------===//
483// ClassExternOp
484//===----------------------------------------------------------------------===//
485
486ParseResult circt::om::ClassExternOp::parse(OpAsmParser &parser,
487 OperationState &state) {
488 return parseClassLike<ClassExternOp>(parser, state);
489}
490
491void circt::om::ClassExternOp::print(OpAsmPrinter &printer) {
492 printClassLike(*this, printer);
493}
494
495LogicalResult circt::om::ClassExternOp::verify() {
496 if (failed(verifyClassLike(*this))) {
497 return failure();
498 }
499 // Verify body is empty
500 if (!this->getBodyBlock()->getOperations().empty()) {
501 return this->emitOpError("external class body should be empty");
502 }
503
504 return success();
505}
506
507void circt::om::ClassExternOp::getAsmBlockArgumentNames(
508 Region &region, OpAsmSetValueNameFn setNameFn) {
509 getClassLikeAsmBlockArgumentNames(*this, region, setNameFn);
510}
511
512std::optional<mlir::Type>
513circt::om::ClassExternOp::getFieldType(mlir::StringAttr field) {
514 return getClassLikeFieldType(*this, field);
515}
516
517void circt::om::ClassExternOp::replaceFieldTypes(AttrTypeReplacer replacer) {
518 replaceClassLikeFieldTypes(*this, replacer);
519}
520
521//===----------------------------------------------------------------------===//
522// ClassFieldsOp
523//===----------------------------------------------------------------------===//
524//
525LogicalResult circt::om::ClassFieldsOp::verify() {
526 auto fieldLocs = this->getFieldLocs();
527 if (fieldLocs.has_value()) {
528 auto fieldLocsVal = fieldLocs.value();
529 if (fieldLocsVal.size() != this->getFields().size()) {
530 auto error = this->emitOpError("size of field_locs (")
531 << fieldLocsVal.size()
532 << ") does not match number of fields ("
533 << this->getFields().size() << ")";
534 }
535 }
536 return success();
537}
538
539//===----------------------------------------------------------------------===//
540// ObjectOp
541//===----------------------------------------------------------------------===//
542
543void circt::om::ObjectOp::build(::mlir::OpBuilder &odsBuilder,
544 ::mlir::OperationState &odsState,
545 om::ClassOp classOp,
546 ::mlir::ValueRange actualParams) {
547 return build(odsBuilder, odsState,
548 om::ClassType::get(odsBuilder.getContext(),
549 mlir::FlatSymbolRefAttr::get(classOp)),
550 mlir::FlatSymbolRefAttr::get(classOp.getNameAttr()),
551 actualParams);
552}
553
554static FailureOr<ClassLike>
555verifyClassLikeSymbolUser(Operation *op, SymbolTableCollection &symbolTable,
556 ClassType resultType, StringAttr className) {
557 StringAttr resultClassName = resultType.getClassName().getAttr();
558 if (resultClassName != className)
559 return op->emitOpError("result type (")
560 << resultClassName << ") does not match referred to class ("
561 << className << ')';
562
563 auto classDef = dyn_cast_or_null<ClassLike>(
564 symbolTable.lookupNearestSymbolFrom(op, className));
565 if (!classDef)
566 return op->emitOpError("refers to non-existant class (")
567 << className << ')';
568 return classDef;
569}
570
571LogicalResult
572circt::om::ObjectOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
573 auto classDef =
574 verifyClassLikeSymbolUser((*this), symbolTable, getResult().getType(),
575 getClassNameAttr().getAttr());
576 if (failed(classDef))
577 return failure();
578
579 auto actualTypes = getActualParams().getTypes();
580 auto formalTypes = classDef->getBodyBlock()->getArgumentTypes();
581
582 // Verify the actual parameter list matches the formal parameter list.
583 if (actualTypes.size() != formalTypes.size()) {
584 auto error = emitOpError(
585 "actual parameter list doesn't match formal parameter list");
586 error.attachNote(classDef->getLoc())
587 << "formal parameters: " << classDef->getBodyBlock()->getArguments();
588 error.attachNote(getLoc()) << "actual parameters: " << getActualParams();
589 return error;
590 }
591
592 // Verify the actual parameter types match the formal parameter types.
593 for (size_t i = 0, e = actualTypes.size(); i < e; ++i) {
594 if (actualTypes[i] != formalTypes[i]) {
595 return emitOpError("actual parameter type (")
596 << actualTypes[i] << ") doesn't match formal parameter type ("
597 << formalTypes[i] << ')';
598 }
599 }
600
601 return success();
602}
603
604//===----------------------------------------------------------------------===//
605// ObjectFieldOp
606//===----------------------------------------------------------------------===//
607
608LogicalResult
609circt::om::ObjectFieldOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
610 auto classType = getObject().getType();
611 auto className = classType.getClassName().getAttr();
612
613 // Verify the referred-to class exists.
614 auto classDef = dyn_cast_or_null<ClassLike>(
615 symbolTable.lookupNearestSymbolFrom(*this, className));
616 if (!classDef)
617 return emitOpError("class ") << className << " was not found";
618
619 // Verify the field exists in the class.
620 auto fieldName = getFieldAttr();
621 std::optional<Type> fieldType = classDef.getFieldType(fieldName);
622 if (!fieldType) {
623 auto diag = emitOpError("referenced non-existent field ") << fieldName;
624 diag.attachNote(classDef.getLoc()) << "class defined here";
625 return diag;
626 }
627
628 // Verify the result type matches the field type.
629 if (getResult().getType() != fieldType.value())
630 return emitOpError("expected type ")
631 << getResult().getType() << ", but accessed field has type "
632 << fieldType.value();
633 return success();
634}
635
636//===----------------------------------------------------------------------===//
637// ElaboratedObjectOp
638//===----------------------------------------------------------------------===//
639
640void circt::om::ElaboratedObjectOp::build(OpBuilder &odsBuilder,
641 OperationState &odsState,
642 om::ClassLike classOp,
643 ValueRange fieldValues) {
644 return build(odsBuilder, odsState,
645 om::ClassType::get(
646 odsBuilder.getContext(),
647 mlir::FlatSymbolRefAttr::get(classOp.getSymNameAttr())),
648 mlir::FlatSymbolRefAttr::get(classOp.getSymNameAttr()),
649 fieldValues);
650}
651
652LogicalResult circt::om::ElaboratedObjectOp::verifySymbolUses(
653 SymbolTableCollection &symbolTable) {
654 auto classDef =
655 verifyClassLikeSymbolUser((*this), symbolTable, getResult().getType(),
656 getClassNameAttr().getAttr());
657 if (failed(classDef))
658 return failure();
659
660 auto fieldNames = classDef->getFieldNames();
661 auto fieldValues = getFieldValues();
662 if (fieldValues.size() != fieldNames.size())
663 return emitOpError("field value list doesn't match class field list, "
664 "expected ")
665 << fieldNames.size() << " values but got " << fieldValues.size();
666
667 for (auto [fieldName, fieldValue] : llvm::zip(fieldNames, fieldValues)) {
668 Type expectedType =
669 classDef->getFieldType(cast<StringAttr>(fieldName)).value();
670 if (fieldValue.getType() != expectedType)
671 return emitOpError("field value type for ")
672 << cast<StringAttr>(fieldName) << " (" << fieldValue.getType()
673 << ") doesn't match class field type (" << expectedType << ')';
674 }
675
676 return success();
677}
678
679//===----------------------------------------------------------------------===//
680// ConstantOp
681//===----------------------------------------------------------------------===//
682
683void circt::om::ConstantOp::build(::mlir::OpBuilder &odsBuilder,
684 ::mlir::OperationState &odsState,
685 ::mlir::TypedAttr constVal) {
686 return build(odsBuilder, odsState, constVal.getType(), constVal);
687}
688
689OpFoldResult circt::om::ConstantOp::fold(FoldAdaptor adaptor) {
690 assert(adaptor.getOperands().empty() && "constant has no operands");
691 return getValueAttr();
692}
693
694//===----------------------------------------------------------------------===//
695// ListCreateOp
696//===----------------------------------------------------------------------===//
697
698void circt::om::ListCreateOp::print(OpAsmPrinter &p) {
699 p << " ";
700 p.printOperands(getInputs());
701 p.printOptionalAttrDict((*this)->getAttrs());
702 p << " : " << getType().getElementType();
703}
704
705ParseResult circt::om::ListCreateOp::parse(OpAsmParser &parser,
706 OperationState &result) {
707 llvm::SmallVector<OpAsmParser::UnresolvedOperand, 16> operands;
708 Type elemType;
709
710 if (parser.parseOperandList(operands) ||
711 parser.parseOptionalAttrDict(result.attributes) || parser.parseColon() ||
712 parser.parseType(elemType))
713 return failure();
714 result.addTypes({circt::om::ListType::get(elemType)});
715
716 for (auto operand : operands)
717 if (parser.resolveOperand(operand, elemType, result.operands))
718 return failure();
719 return success();
720}
721
722//===----------------------------------------------------------------------===//
723// BasePathCreateOp
724//===----------------------------------------------------------------------===//
725
726LogicalResult
727BasePathCreateOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
728 auto hierPath = symbolTable.lookupNearestSymbolFrom<hw::HierPathOp>(
729 *this, getTargetAttr());
730 if (!hierPath)
731 return emitOpError("invalid symbol reference");
732 return success();
733}
734
735//===----------------------------------------------------------------------===//
736// PathCreateOp
737//===----------------------------------------------------------------------===//
738
739LogicalResult
740PathCreateOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
741 auto hierPath = symbolTable.lookupNearestSymbolFrom<hw::HierPathOp>(
742 *this, getTargetAttr());
743 if (!hierPath)
744 return emitOpError("invalid symbol reference");
745 return success();
746}
747
748//===----------------------------------------------------------------------===//
749// IntegerBinaryOp (arithmetic)
750//===----------------------------------------------------------------------===//
751
752static APSInt getAPSIntForOMIntegerAttr(circt::om::IntegerAttr attr) {
753 auto value = attr.getValue();
754 if (value.getType().isSignedInteger())
755 return value.getAPSInt();
756
757 // OM integers use signed semantics, but their underlying IntegerAttr may be
758 // signless. Construct an APSInt with signed interpretation explicitly instead
759 // of calling IntegerAttr::getAPSInt(), which asserts for signless integers.
760 return APSInt(value.getValue(), /*isUnsigned=*/false);
761}
762
764 llvm::function_ref<FailureOr<APSInt>(const APSInt &, const APSInt &)>;
765
766static OpFoldResult foldIntegerBinaryArithmetic(Attribute lhsAttr,
767 Attribute rhsAttr,
768 IntegerBinaryFn evaluate) {
769 auto lhs = dyn_cast_or_null<circt::om::IntegerAttr>(lhsAttr);
770 auto rhs = dyn_cast_or_null<circt::om::IntegerAttr>(rhsAttr);
771 if (!lhs || !rhs)
772 return {};
773 // Extend values if necessary to match bitwidth. Most interesting arithmetic
774 // on APSInt asserts that both operands are the same bitwidth, but the
775 // IntegerAttrs we are working with may have used the smallest necessary
776 // bitwidth to represent the number they hold, and won't necessarily match.
777 APSInt lhsVal = getAPSIntForOMIntegerAttr(lhs);
778 APSInt rhsVal = getAPSIntForOMIntegerAttr(rhs);
779 if (lhsVal.getBitWidth() > rhsVal.getBitWidth())
780 rhsVal = rhsVal.extend(lhsVal.getBitWidth());
781 else if (rhsVal.getBitWidth() > lhsVal.getBitWidth())
782 lhsVal = lhsVal.extend(rhsVal.getBitWidth());
783
784 // Perform arbitrary precision signed integer binary arithmetic.
785 auto result = evaluate(lhsVal, rhsVal);
786 if (failed(result))
787 return {};
788
789 // Return the result as a new om::IntegerAttr.
790 auto *ctx = lhsAttr.getContext();
791 return circt::om::IntegerAttr::get(
792 ctx, mlir::IntegerAttr::get(ctx, result.value()));
793}
794
795//===----------------------------------------------------------------------===//
796// IntegerAddOp
797//===----------------------------------------------------------------------===//
798
799OpFoldResult IntegerAddOp::fold(FoldAdaptor adaptor) {
801 adaptor.getLhs(), adaptor.getRhs(),
802 [](const APSInt &lhs, const APSInt &rhs) { return success(lhs + rhs); });
803}
804
805//===----------------------------------------------------------------------===//
806// IntegerMulOp
807//===----------------------------------------------------------------------===//
808
809OpFoldResult IntegerMulOp::fold(FoldAdaptor adaptor) {
811 adaptor.getLhs(), adaptor.getRhs(),
812 [](const APSInt &lhs, const APSInt &rhs) { return success(lhs * rhs); });
813}
814
815//===----------------------------------------------------------------------===//
816// IntegerShrOp
817//===----------------------------------------------------------------------===//
818
819OpFoldResult IntegerShrOp::fold(FoldAdaptor adaptor) {
821 adaptor.getLhs(), adaptor.getRhs(),
822 [&](const APSInt &lhs, const APSInt &rhs) -> FailureOr<APSInt> {
823 // Check non-negative constraint from operation semantics.
824 if (!rhs.isNonNegative())
825 return (emitOpError("shift amount must be non-negative"), failure());
826 // Check size constraint from implementation detail of using
827 // getExtValue.
828 if (!rhs.isRepresentableByInt64())
829 return (emitOpError("shift amount must be representable in 64 bits"),
830 failure());
831 return success(lhs >> rhs.getExtValue());
832 });
833}
834
835//===----------------------------------------------------------------------===//
836// IntegerShlOp
837//===----------------------------------------------------------------------===//
838
839OpFoldResult IntegerShlOp::fold(FoldAdaptor adaptor) {
841 adaptor.getLhs(), adaptor.getRhs(),
842 [&](const APSInt &lhs, const APSInt &rhs) -> FailureOr<APSInt> {
843 // Check non-negative constraint from operation semantics.
844 if (!rhs.isNonNegative())
845 return (emitOpError("shift amount must be non-negative"), failure());
846 // Check size constraint from implementation detail of using
847 // getExtValue.
848 if (!rhs.isRepresentableByInt64())
849 return (emitOpError("shift amount must be representable in 64 bits"),
850 failure());
851 int64_t shiftAmt = rhs.getExtValue();
852 // Extend lhs to lhsWidth + shiftAmt bits so no bits are truncated.
853 return success(lhs.extend(lhs.getBitWidth() + shiftAmt) << shiftAmt);
854 });
855}
856
857//===----------------------------------------------------------------------===//
858// StringConcatOp
859//===----------------------------------------------------------------------===//
860
861OpFoldResult StringConcatOp::fold(FoldAdaptor adaptor) {
862 // Fold single-operand concat to just the operand.
863 if (getStrings().size() == 1) {
864 if (auto strAttr = adaptor.getStrings()[0])
865 return strAttr;
866
867 return getStrings()[0];
868 }
869
870 // Check if all operands are constant strings before accumulating.
871 if (!llvm::all_of(adaptor.getStrings(), [](Attribute operand) {
872 return isa_and_nonnull<StringAttr>(operand);
873 }))
874 return {};
875
876 // All operands are constant strings, concatenate them.
877 SmallString<64> result;
878 for (auto operand : adaptor.getStrings())
879 result += cast<StringAttr>(operand).getValue();
880
881 return StringAttr::get(result, getResult().getType());
882}
883
884namespace {
885/// Flatten nested string.concat operations into a single concat.
886/// string.concat(a, string.concat(b, c), d) -> string.concat(a, b, c, d)
887class FlattenOMStringConcat : public mlir::OpRewritePattern<StringConcatOp> {
888public:
889 using OpRewritePattern::OpRewritePattern;
890
891 LogicalResult
892 matchAndRewrite(StringConcatOp concat,
893 mlir::PatternRewriter &rewriter) const override {
894
895 // Check if any operands are nested concats with a single use. Only inline
896 // single-use nested concats to avoid fighting with DCE.
897 bool hasNestedConcat = llvm::any_of(concat.getStrings(), [](Value operand) {
898 auto nestedConcat = operand.getDefiningOp<StringConcatOp>();
899 return nestedConcat && operand.hasOneUse();
900 });
901
902 if (!hasNestedConcat)
903 return failure();
904
905 // Flatten nested concats that have a single use.
906 SmallVector<Value> flatOperands;
907 for (auto input : concat.getStrings()) {
908 if (auto nestedConcat = input.getDefiningOp<StringConcatOp>();
909 nestedConcat && input.hasOneUse())
910 llvm::append_range(flatOperands, nestedConcat.getStrings());
911 else
912 flatOperands.push_back(input);
913 }
914
915 rewriter.modifyOpInPlace(concat,
916 [&]() { concat->setOperands(flatOperands); });
917 return success();
918 }
919};
920
921/// Merge consecutive constant strings in a concat and remove empty strings.
922/// string.concat("a", "b", x, "", "c", "d") -> string.concat("ab", x, "cd")
923class MergeAdjacentOMStringConstants
924 : public mlir::OpRewritePattern<StringConcatOp> {
925public:
926 using OpRewritePattern::OpRewritePattern;
927
928 LogicalResult
929 matchAndRewrite(StringConcatOp concat,
930 mlir::PatternRewriter &rewriter) const override {
931
932 SmallVector<Value> newOperands;
933 SmallString<64> accumulatedLit;
934 SmallVector<ConstantOp> accumulatedOps;
935 bool changed = false;
936
937 auto flushLiterals = [&]() {
938 if (accumulatedOps.empty())
939 return;
940
941 // If only one literal, reuse it.
942 if (accumulatedOps.size() == 1) {
943 newOperands.push_back(accumulatedOps[0]);
944 } else {
945 // Multiple literals - merge them.
946 auto newLit = rewriter.createOrFold<ConstantOp>(
947 concat.getLoc(),
948 StringAttr::get(accumulatedLit, concat.getResult().getType()));
949 newOperands.push_back(newLit);
950 changed = true;
951 }
952 accumulatedLit.clear();
953 accumulatedOps.clear();
954 };
955
956 for (auto operand : concat.getStrings()) {
957 if (auto litOp = operand.getDefiningOp<ConstantOp>()) {
958 if (auto strAttr = dyn_cast<StringAttr>(litOp.getValue())) {
959 // Skip empty strings.
960 if (strAttr.getValue().empty()) {
961 changed = true;
962 continue;
963 }
964 accumulatedLit += strAttr.getValue();
965 accumulatedOps.push_back(litOp);
966 continue;
967 }
968 }
969
970 flushLiterals();
971 newOperands.push_back(operand);
972 }
973
974 // Flush any remaining literals.
975 flushLiterals();
976
977 if (!changed)
978 return failure();
979
980 // If no operands remain, replace with empty string.
981 if (newOperands.empty())
982 return rewriter.replaceOpWithNewOp<ConstantOp>(
983 concat, StringAttr::get("", concat.getResult().getType())),
984 success();
985
986 // Single-operand case is handled by the folder.
987 rewriter.modifyOpInPlace(concat,
988 [&]() { concat->setOperands(newOperands); });
989 return success();
990 }
991};
992
993} // namespace
994
995void StringConcatOp::getCanonicalizationPatterns(RewritePatternSet &results,
996 MLIRContext *context) {
997 results.insert<FlattenOMStringConcat, MergeAdjacentOMStringConstants>(
998 context);
999}
1000
1001//===----------------------------------------------------------------------===//
1002// PropEqOp
1003//===----------------------------------------------------------------------===//
1004
1005static FailureOr<mlir::Attribute>
1006evaluateBinaryEquality(mlir::Attribute lhsAttr, mlir::Attribute rhsAttr) {
1007 auto resultType = mlir::IntegerType::get(lhsAttr.getContext(), 1);
1008
1009 // String equality.
1010 if (auto lhs = dyn_cast<mlir::StringAttr>(lhsAttr))
1011 if (auto rhs = dyn_cast<mlir::StringAttr>(rhsAttr))
1012 return mlir::Attribute(
1013 mlir::IntegerAttr::get(resultType, lhs == rhs ? 1 : 0));
1014
1015 // OM integer equality (arbitrary precision).
1016 if (auto lhs = dyn_cast<circt::om::IntegerAttr>(lhsAttr))
1017 if (auto rhs = dyn_cast<circt::om::IntegerAttr>(rhsAttr)) {
1018 APSInt lhsVal = getAPSIntForOMIntegerAttr(lhs);
1019 APSInt rhsVal = getAPSIntForOMIntegerAttr(rhs);
1020 if (lhsVal.getBitWidth() > rhsVal.getBitWidth())
1021 rhsVal = rhsVal.extend(lhsVal.getBitWidth());
1022 else if (rhsVal.getBitWidth() > lhsVal.getBitWidth())
1023 lhsVal = lhsVal.extend(rhsVal.getBitWidth());
1024 return mlir::Attribute(
1025 mlir::IntegerAttr::get(resultType, lhsVal == rhsVal ? 1 : 0));
1026 }
1027
1028 // Boolean (i1) equality.
1029 if (auto lhs = dyn_cast<mlir::IntegerAttr>(lhsAttr))
1030 if (auto rhs = dyn_cast<mlir::IntegerAttr>(rhsAttr))
1031 return mlir::Attribute(
1032 mlir::IntegerAttr::get(resultType, lhs == rhs ? 1 : 0));
1033
1034 return failure();
1035}
1036
1037OpFoldResult PropEqOp::fold(FoldAdaptor adaptor) {
1038 auto lhsAttr = adaptor.getLhs();
1039 auto rhsAttr = adaptor.getRhs();
1040 if (!lhsAttr || !rhsAttr)
1041 return {};
1042
1043 auto result = evaluateBinaryEquality(lhsAttr, rhsAttr);
1044 if (failed(result))
1045 return {};
1046
1047 return *result;
1048}
1049
1050//===----------------------------------------------------------------------===//
1051// IntegerAndOp / IntegerOrOp / IntegerXorOp
1052//===----------------------------------------------------------------------===//
1053
1054static OpFoldResult foldIntegerBitwise(Attribute lhsAttr, Attribute rhsAttr,
1055 IntegerBinaryFn evaluate) {
1056 auto lhsInt = dyn_cast_or_null<mlir::IntegerAttr>(lhsAttr);
1057 auto rhsInt = dyn_cast_or_null<mlir::IntegerAttr>(rhsAttr);
1058 if (!lhsInt || !rhsInt)
1059 return {};
1060 APSInt lhsVal(lhsInt.getValue());
1061 APSInt rhsVal(rhsInt.getValue());
1062 auto result = evaluate(lhsVal, rhsVal);
1063 if (failed(result))
1064 return {};
1065 return mlir::IntegerAttr::get(
1066 lhsInt.getType(), result->extOrTrunc(lhsInt.getValue().getBitWidth()));
1067}
1068
1069// Returns true if attr is an IntegerAttr whose value is all-zeros.
1070static bool isZeroInt(Attribute a) {
1071 auto i = dyn_cast_or_null<mlir::IntegerAttr>(a);
1072 return i && i.getValue().isZero();
1073}
1074
1075// Returns true if attr is an IntegerAttr whose value is all-ones.
1076static bool isAllOnesInt(Attribute a) {
1077 auto i = dyn_cast_or_null<mlir::IntegerAttr>(a);
1078 return i && i.getValue().isAllOnes();
1079}
1080
1081OpFoldResult IntegerAndOp::fold(FoldAdaptor adaptor) {
1082 if (auto result = foldIntegerBitwise(
1083 adaptor.getLhs(), adaptor.getRhs(),
1084 [](const APSInt &lhs, const APSInt &rhs) {
1085 return success(APSInt(lhs & rhs, /*isUnsigned=*/false));
1086 }))
1087 return result;
1088 // AND with all-zeros is always zero.
1089 if (isZeroInt(adaptor.getLhs()) || isZeroInt(adaptor.getRhs()))
1090 return mlir::IntegerAttr::get(getResult().getType(),
1091 APInt::getZero(getType().getWidth()));
1092 // AND with all-ones is identity.
1093 if (isAllOnesInt(adaptor.getLhs()))
1094 return getRhs();
1095 if (isAllOnesInt(adaptor.getRhs()))
1096 return getLhs();
1097 return {};
1098}
1099
1100OpFoldResult IntegerOrOp::fold(FoldAdaptor adaptor) {
1101 if (auto result = foldIntegerBitwise(
1102 adaptor.getLhs(), adaptor.getRhs(),
1103 [](const APSInt &lhs, const APSInt &rhs) {
1104 return success(APSInt(lhs | rhs, /*isUnsigned=*/false));
1105 }))
1106 return result;
1107 // OR with all-ones is always all-ones.
1108 if (isAllOnesInt(adaptor.getLhs()) || isAllOnesInt(adaptor.getRhs()))
1109 return mlir::IntegerAttr::get(getResult().getType(),
1110 APInt::getAllOnes(getType().getWidth()));
1111 // OR with all-zeros is identity.
1112 if (isZeroInt(adaptor.getLhs()))
1113 return getRhs();
1114 if (isZeroInt(adaptor.getRhs()))
1115 return getLhs();
1116 return {};
1117}
1118
1119OpFoldResult IntegerXorOp::fold(FoldAdaptor adaptor) {
1120 if (auto result = foldIntegerBitwise(
1121 adaptor.getLhs(), adaptor.getRhs(),
1122 [](const APSInt &lhs, const APSInt &rhs) {
1123 return success(APSInt(lhs ^ rhs, /*isUnsigned=*/false));
1124 }))
1125 return result;
1126 // XOR with all-zeros is identity.
1127 if (isZeroInt(adaptor.getLhs()))
1128 return getRhs();
1129 if (isZeroInt(adaptor.getRhs()))
1130 return getLhs();
1131 return {};
1132}
1133
1134//===----------------------------------------------------------------------===//
1135// UnknownValueOp
1136//===----------------------------------------------------------------------===//
1137
1138LogicalResult circt::om::UnknownValueOp::verifySymbolUses(
1139 SymbolTableCollection &symbolTable) {
1140
1141 // Unknown values of non-class type don't need to be verified.
1142 auto classType = dyn_cast<ClassType>(getType());
1143 if (!classType)
1144 return success();
1145
1146 // Verify the referred to ClassOp exists.
1147 auto className = classType.getClassName();
1148 if (symbolTable.lookupNearestSymbolFrom<ClassLike>(*this, className))
1149 return success();
1150
1151 return emitOpError() << "refers to non-existant class (\""
1152 << className.getValue() << "\")";
1153}
1154
1155//===----------------------------------------------------------------------===//
1156// TableGen generated logic.
1157//===----------------------------------------------------------------------===//
1158
1159#define GET_OP_CLASSES
1160#include "circt/Dialect/OM/OM.cpp.inc"
assert(baseType &&"element must be base type")
static std::unique_ptr< Context > context
static Location getLoc(DefSlot slot)
Definition Mem2Reg.cpp:222
static OpFoldResult foldIntegerBitwise(Attribute lhsAttr, Attribute rhsAttr, IntegerBinaryFn evaluate)
Definition OMOps.cpp:1054
LogicalResult verifyClassLike(ClassLike classLike)
Definition OMOps.cpp:248
std::optional< Type > getClassLikeFieldType(ClassLike classLike, StringAttr name)
Definition OMOps.cpp:287
void getClassLikeAsmBlockArgumentNames(ClassLike classLike, Region &region, OpAsmSetValueNameFn setNameFn)
Definition OMOps.cpp:265
static ParseResult parseBasePathString(OpAsmParser &parser, PathAttr &path)
Definition OMOps.cpp:28
static ParseResult parsePathString(OpAsmParser &parser, PathAttr &path, StringAttr &module, StringAttr &ref, StringAttr &field)
Definition OMOps.cpp:50
static APSInt getAPSIntForOMIntegerAttr(circt::om::IntegerAttr attr)
Definition OMOps.cpp:752
static void printBasePathString(OpAsmPrinter &p, Operation *op, PathAttr path)
Definition OMOps.cpp:39
llvm::function_ref< FailureOr< APSInt >(const APSInt &, const APSInt &)> IntegerBinaryFn
Definition OMOps.cpp:764
static FailureOr< ClassLike > verifyClassLikeSymbolUser(Operation *op, SymbolTableCollection &symbolTable, ClassType resultType, StringAttr className)
Definition OMOps.cpp:555
static void printFieldLocs(OpAsmPrinter &printer, Operation *op, ArrayAttr fieldLocs)
Definition OMOps.cpp:89
static bool isZeroInt(Attribute a)
Definition OMOps.cpp:1070
static ParseResult parseFieldLocs(OpAsmParser &parser, ArrayAttr &fieldLocs)
Definition OMOps.cpp:79
static ParseResult parseClassFieldsList(OpAsmParser &parser, SmallVectorImpl< Attribute > &fieldNames, SmallVectorImpl< Type > &fieldTypes)
Definition OMOps.cpp:102
static FailureOr< mlir::Attribute > evaluateBinaryEquality(mlir::Attribute lhsAttr, mlir::Attribute rhsAttr)
Definition OMOps.cpp:1006
static void printClassLike(ClassLike classLike, OpAsmPrinter &printer)
Definition OMOps.cpp:192
void replaceClassLikeFieldTypes(ClassLike classLike, AttrTypeReplacer &replacer)
Definition OMOps.cpp:297
NamedAttribute makeFieldType(StringAttr name, Type type)
Definition OMOps.cpp:277
NamedAttribute makeFieldIdx(MLIRContext *ctx, mlir::StringAttr name, unsigned i)
Definition OMOps.cpp:281
static void printPathString(OpAsmPrinter &p, Operation *op, PathAttr path, StringAttr module, StringAttr ref, StringAttr field)
Definition OMOps.cpp:64
static ParseResult parseClassLike(OpAsmParser &parser, OperationState &state)
Definition OMOps.cpp:135
static OpFoldResult foldIntegerBinaryArithmetic(Attribute lhsAttr, Attribute rhsAttr, IntegerBinaryFn evaluate)
Definition OMOps.cpp:766
static bool isAllOnesInt(Attribute a)
Definition OMOps.cpp:1076
static Block * getBodyBlock(FModuleLike mod)
static InstancePath empty
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition CalyxOps.cpp:56
uint64_t getWidth(Type t)
Definition ESIPasses.cpp:32
void error(Twine message)
Definition LSPUtils.cpp:16
ParseResult parsePath(MLIRContext *context, StringRef spelling, PathAttr &path, StringAttr &module, StringAttr &ref, StringAttr &field)
Parse a target string in to a path.
Definition OMUtils.cpp:182
ParseResult parseBasePath(MLIRContext *context, StringRef spelling, PathAttr &path)
Parse a target string of the form "Foo/bar:Bar/baz" in to a base path.
Definition OMUtils.cpp:177
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn
Definition LLVM.h:193
A module name, and the name of an instance inside that module.
mlir::StringAttr mlir::StringAttr instance