14#include "mlir/IR/Attributes.h"
15#include "mlir/IR/BuiltinDialect.h"
16#include "mlir/IR/BuiltinTypes.h"
17#include "mlir/IR/Matchers.h"
18#include "mlir/IR/PatternMatch.h"
19#include "mlir/IR/Region.h"
20#include "mlir/IR/Types.h"
21#include "mlir/IR/Value.h"
22#include "mlir/Interfaces/FunctionImplementation.h"
23#include "llvm/ADT/ArrayRef.h"
24#include "llvm/ADT/SmallVector.h"
31 if (
auto sig = dyn_cast<RefType>(type))
32 type = sig.getNestedType();
33 if (
auto array = dyn_cast<hw::ArrayType>(type))
34 return array.getNumElements();
35 if (
auto tup = dyn_cast<hw::StructType>(type))
36 return tup.getElements().size();
37 return type.getIntOrFloatBitWidth();
41 if (
auto sig = dyn_cast<RefType>(type))
42 type = sig.getNestedType();
43 if (
auto array = dyn_cast<hw::ArrayType>(type))
44 return array.getElementType();
48template <
typename... OpTypes>
50 for (
auto *user : op->getUsers()) {
51 if (isa<OpTypes...>(user))
61OpFoldResult llhd::ConstantTimeOp::fold(FoldAdaptor adaptor) {
62 assert(adaptor.getOperands().empty() &&
"const has no operands");
63 return getValueAttr();
66void llhd::ConstantTimeOp::build(OpBuilder &builder, OperationState &result,
67 uint64_t time,
const StringRef &timeUnit,
68 unsigned delta,
unsigned epsilon) {
69 auto *ctx = builder.getContext();
70 auto attr = TimeAttr::get(ctx, time, timeUnit, delta, epsilon);
71 return build(builder, result, TimeType::get(ctx), attr);
79 unsigned index, Type resultType) {
80 return TypeSwitch<Type, Value>(val.getType())
81 .Case<hw::StructType>([&](hw::StructType ty) -> Value {
83 ty.getElements()[index].name);
85 .Case<hw::ArrayType>([&](hw::ArrayType ty) -> Value {
88 builder.getIntegerType(llvm::Log2_64_Ceil(ty.getNumElements())),
92 .Case<IntegerType>([&](IntegerType ty) -> Value {
94 resultType.getIntOrFloatBitWidth());
100 setNameFn(getResult(), *
getName());
108static std::optional<DenseMap<Attribute, Type>>
110 int width = type.getIntOrFloatBitWidth();
116 SmallVector<bool> startIndices(width,
false);
117 for (Operation *user : value.getUsers()) {
118 if (
auto extract = dyn_cast<SigExtractOp>(user)) {
120 if (matchPattern(extract.getLowBit(), m_ConstantInt(&lowBit))) {
121 startIndices[lowBit.getZExtValue()] =
true;
122 int64_t highBit = lowBit.getZExtValue() + extract.getResultWidth();
124 startIndices[highBit] =
true;
128 if (isa<ProbeOp, DriveOp>(user)) {
138 DenseMap<Attribute, Type> destructured;
139 for (
int start = 0; start < width;) {
141 while (end < width && !startIndices[end])
144 int runLength = end - start;
147 {IntegerAttr::get(IndexType::get(type.getContext()), start),
148 IntegerType::get(type.getContext(), runLength)});
155static std::optional<DenseMap<Attribute, Type>>
160 if (
auto intType = dyn_cast<IntegerType>(type)) {
163 auto destructurable = llvm::dyn_cast<DestructurableTypeInterface>(type);
166 return destructurable.getSubelementIndexMap();
170SmallVector<DestructurableMemorySlot> SignalOp::getDestructurableSlots() {
171 auto type = getType().getNestedType();
175 if (!
hasUserOfKind<SigExtractOp, SigArrayGetOp, SigStructExtractOp,
176 SigArraySliceOp>(*
this))
180 if (!destructuredType)
182 return {DestructurableMemorySlot{{getResult(), type}, *destructuredType}};
185DenseMap<Attribute, MemorySlot> SignalOp::destructure(
186 const DestructurableMemorySlot &slot,
187 const SmallPtrSetImpl<Attribute> &usedIndices, OpBuilder &builder,
188 SmallVectorImpl<DestructurableAllocationOpInterface> &newAllocators) {
189 assert(slot.ptr == getResult());
190 builder.setInsertionPointAfter(*
this);
192 DenseMap<Attribute, Type> subelementTypes = slot.subelementTypes;
193 DenseMap<Attribute, MemorySlot> slotMap;
194 SmallVector<std::pair<unsigned, Type>> indices;
195 for (
auto attr : usedIndices) {
196 assert(isa<IntegerAttr>(attr));
197 auto elemType = subelementTypes.at(attr);
198 assert(elemType &&
"used index must exist");
199 indices.push_back({cast<IntegerAttr>(attr).getInt(), elemType});
202 llvm::sort(indices, [](
auto a,
auto b) {
return a.first <
b.first; });
204 for (
auto [index, type] : indices) {
206 auto sigOp = SignalOp::create(builder,
getLoc(), getNameAttr(), init);
207 newAllocators.push_back(sigOp);
208 slotMap.try_emplace<MemorySlot>(
209 IntegerAttr::get(IndexType::get(getContext()), index),
210 {sigOp.getResult(), type});
216std::optional<DestructurableAllocationOpInterface>
217SignalOp::handleDestructuringComplete(
const DestructurableMemorySlot &slot,
218 OpBuilder &builder) {
219 assert(slot.ptr == getResult());
235 if (op.getResultWidth() == op.getInputWidth() &&
236 cast<IntegerAttr>(operands[1]).getValue().isZero())
237 return op.getInput();
242OpFoldResult llhd::SigExtractOp::fold(FoldAdaptor adaptor) {
248 return std::max<int64_t>(0, std::min(a2, b2) - std::max(a1, b1));
252 SmallVectorImpl<std::pair<unsigned, Value>> &sorted) {
253 for (
auto [attr, mem] : subslots) {
254 assert(isa<IntegerAttr>(attr));
255 sorted.push_back({cast<IntegerAttr>(attr).getInt(), mem.ptr});
258 llvm::sort(sorted, [](
auto a,
auto b) {
return a.first < b.first; });
262 SmallVectorImpl<std::pair<unsigned, Type>> &sorted) {
263 for (
auto [attr, mem] : subslots) {
264 assert(isa<IntegerAttr>(attr));
265 sorted.push_back({cast<IntegerAttr>(attr).getInt(), mem});
268 llvm::sort(sorted, [](
auto a,
auto b) {
return a.first < b.first; });
271bool SigExtractOp::canRewire(
const DestructurableMemorySlot &slot,
272 SmallPtrSetImpl<Attribute> &usedIndices,
273 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
274 const DataLayout &dataLayout) {
275 if (slot.ptr != getInput())
279 if (!type.isSignlessInteger())
281 if (!matchPattern(getLowBit(), m_ConstantInt(&idx)))
287 for (Operation *user : getResult().getUsers()) {
288 if (!isa<ProbeOp, DriveOp>(user))
292 SmallVector<std::pair<unsigned, Type>> elements;
295 int64_t index = idx.getZExtValue();
297 int64_t coveredBits = 0;
298 for (
auto [start, type] : elements) {
299 int64_t subslotWidth = type.getIntOrFloatBitWidth();
304 usedIndices.insert(IntegerAttr::get(IndexType::get(getContext()), start));
305 coveredBits += overlap;
308 if (coveredBits != width)
311 mustBeSafelyUsed.emplace_back<MemorySlot>({getResult(), type});
315DeletionKind SigExtractOp::rewire(
const DestructurableMemorySlot &slot,
316 DenseMap<Attribute, MemorySlot> &subslots,
318 const DataLayout &dataLayout) {
320 [[maybe_unused]]
bool result = matchPattern(getLowBit(), m_ConstantInt(&idx));
323 int64_t idxVal = idx.getZExtValue();
325 SmallVector<std::pair<unsigned, Value>> elements;
328 for (Operation *user :
llvm::make_early_inc_range(getResult().getUsers())) {
329 builder.setInsertionPoint(user);
331 if (
auto probeOp = dyn_cast<ProbeOp>(user)) {
332 SmallVector<Value> values;
333 for (
auto [start, value] : elements) {
334 int64_t subslotWidth = cast<RefType>(value.getType())
336 .getIntOrFloatBitWidth();
338 start + subslotWidth);
341 values.push_back(ProbeOp::create(builder, probeOp.getLoc(), value));
343 std::reverse(values.begin(), values.end());
344 Value value = comb::ConcatOp::create(builder, probeOp.getLoc(), values);
345 probeOp.replaceAllUsesWith(value);
351 auto driveOp = cast<DriveOp>(user);
352 for (
auto [start, sig] : elements) {
353 int64_t subslotWidth =
354 cast<RefType>(sig.getType()).getNestedType().getIntOrFloatBitWidth();
361 start - idxVal, subslotWidth);
362 DriveOp::create(builder, driveOp.getLoc(), sig, val, driveOp.getTime(),
363 driveOp.getEnable());
368 return DeletionKind::Delete;
371LogicalResult SigExtractOp::ensureOnlySafeAccesses(
372 const MemorySlot &slot, SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
373 const DataLayout &dataLayout) {
381OpFoldResult llhd::SigArraySliceOp::fold(FoldAdaptor adaptor) {
382 auto lowIndex = dyn_cast_or_null<IntegerAttr>(adaptor.getLowIndex());
387 if (getResultWidth() == getInputWidth() && lowIndex.getValue().isZero())
395 PatternRewriter &rewriter) {
396 IntegerAttr indexAttr;
397 if (!matchPattern(op.getLowIndex(), m_Constant(&indexAttr)))
403 if (matchPattern(op.getInput(),
404 m_Op<Op>(matchers::m_Any(), m_Constant(&a)))) {
405 auto sliceOp = op.getInput().template getDefiningOp<Op>();
406 rewriter.modifyOpInPlace(op, [&]() {
407 op.getInputMutable().assign(sliceOp.getInput());
409 rewriter, op->getLoc(), a.getValue() + indexAttr.getValue());
410 op.getLowIndexMutable().assign(newIndex);
419LogicalResult llhd::SigArraySliceOp::canonicalize(llhd::SigArraySliceOp op,
420 PatternRewriter &rewriter) {
428bool SigArrayGetOp::canRewire(
const DestructurableMemorySlot &slot,
429 SmallPtrSetImpl<Attribute> &usedIndices,
430 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
431 const DataLayout &dataLayout) {
432 if (slot.ptr != getInput())
435 if (!matchPattern(getIndex(), m_ConstantInt(&idx)))
438 IntegerAttr::get(IndexType::get(getContext()), idx.getZExtValue());
439 if (!slot.subelementTypes.contains(index))
441 usedIndices.insert(index);
442 mustBeSafelyUsed.emplace_back<MemorySlot>(
443 {getResult(), cast<RefType>(getResult().getType()).getNestedType()});
447DeletionKind SigArrayGetOp::rewire(
const DestructurableMemorySlot &slot,
448 DenseMap<Attribute, MemorySlot> &subslots,
450 const DataLayout &dataLayout) {
452 bool result = matchPattern(getIndex(), m_ConstantInt(&idx));
456 IntegerAttr::get(IndexType::get(getContext()), idx.getZExtValue());
457 auto it = subslots.find(index);
458 assert(it != subslots.end());
459 replaceAllUsesWith(it->getSecond().ptr);
460 return DeletionKind::Delete;
463LogicalResult SigArrayGetOp::ensureOnlySafeAccesses(
464 const MemorySlot &slot, SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
465 const DataLayout &dataLayout) {
473LogicalResult llhd::SigStructExtractOp::inferReturnTypes(
474 MLIRContext *
context, std::optional<Location> loc, ValueRange operands,
475 DictionaryAttr attrs, mlir::OpaqueProperties properties,
476 mlir::RegionRange regions, SmallVectorImpl<Type> &results) {
477 typename SigStructExtractOp::Adaptor adaptor(operands, attrs, properties,
479 auto nestedType = cast<RefType>(adaptor.getInput().getType()).getNestedType();
483 if (
auto structType = dyn_cast<hw::StructType>(nestedType)) {
484 fieldType = structType.getFieldType(adaptor.getField());
485 }
else if (
auto unionType = dyn_cast<hw::UnionType>(nestedType)) {
486 fieldType = unionType.getFieldType(adaptor.getField());
488 context->getDiagEngine().emit(loc.value_or(UnknownLoc()),
489 DiagnosticSeverity::Error)
490 <<
"expected struct or union type";
495 context->getDiagEngine().emit(loc.value_or(UnknownLoc()),
496 DiagnosticSeverity::Error)
497 <<
"invalid field name specified";
500 results.push_back(RefType::get(fieldType));
504bool SigStructExtractOp::canRewire(
505 const DestructurableMemorySlot &slot,
506 SmallPtrSetImpl<Attribute> &usedIndices,
507 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
508 const DataLayout &dataLayout) {
509 if (slot.ptr != getInput())
512 auto nestedType = cast<RefType>(getInput().getType()).getNestedType();
513 std::optional<uint32_t> index;
516 if (
auto structType = dyn_cast<hw::StructType>(nestedType))
517 index = structType.getFieldIndex(getFieldAttr());
518 else if (
auto unionType = dyn_cast<hw::UnionType>(nestedType))
519 index = unionType.getFieldIndex(getFieldAttr());
525 auto indexAttr = IntegerAttr::get(IndexType::get(getContext()), *index);
526 if (!slot.subelementTypes.contains(indexAttr))
528 usedIndices.insert(indexAttr);
529 mustBeSafelyUsed.emplace_back<MemorySlot>(
530 {getResult(), cast<RefType>(getResult().getType()).getNestedType()});
535SigStructExtractOp::rewire(
const DestructurableMemorySlot &slot,
536 DenseMap<Attribute, MemorySlot> &subslots,
537 OpBuilder &builder,
const DataLayout &dataLayout) {
538 auto nestedType = cast<RefType>(getInput().getType()).getNestedType();
539 std::optional<unsigned> index;
540 if (
auto structTy = dyn_cast<hw::StructType>(nestedType))
541 index = structTy.getFieldIndex(getFieldAttr());
542 else if (
auto unionTy = dyn_cast<hw::UnionType>(nestedType))
543 index = unionTy.getFieldIndex(getFieldAttr());
544 assert(index.has_value());
545 auto indexAttr = IntegerAttr::get(IndexType::get(getContext()), *index);
546 auto it = subslots.find(indexAttr);
547 assert(it != subslots.end());
548 replaceAllUsesWith(it->getSecond().ptr);
549 return DeletionKind::Delete;
552LogicalResult SigStructExtractOp::ensureOnlySafeAccesses(
553 const MemorySlot &slot, SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
554 const DataLayout &dataLayout) {
562bool ProbeOp::canRewire(
const DestructurableMemorySlot &slot,
563 SmallPtrSetImpl<Attribute> &usedIndices,
564 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
565 const DataLayout &dataLayout) {
566 for (
auto [key, _] : slot.subelementTypes)
567 usedIndices.insert(key);
569 return isa<hw::StructType, hw::ArrayType, IntegerType>(slot.elemType);
572DeletionKind ProbeOp::rewire(
const DestructurableMemorySlot &slot,
573 DenseMap<Attribute, MemorySlot> &subslots,
574 OpBuilder &builder,
const DataLayout &dataLayout) {
575 SmallVector<std::pair<unsigned, Value>> elements;
576 SmallVector<Value> probed;
578 for (
auto [_, val] : elements)
579 probed.push_back(ProbeOp::create(builder,
getLoc(), val));
582 TypeSwitch<Type, Value>(getType())
583 .Case<hw::StructType>([&](
auto ty) {
587 .Case<hw::ArrayType>([&](
auto ty) {
588 std::reverse(probed.begin(), probed.end());
591 .Case<IntegerType>([&](
auto ty) {
592 std::reverse(probed.begin(), probed.end());
593 return comb::ConcatOp::create(builder,
getLoc(), probed);
596 replaceAllUsesWith(repl);
597 return DeletionKind::Delete;
601ProbeOp::ensureOnlySafeAccesses(
const MemorySlot &slot,
602 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
603 const DataLayout &dataLayout) {
607void ProbeOp::getEffects(
608 SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
610 if (mayHaveSSADominance(*getOperation()->getParentRegion()))
611 effects.emplace_back(MemoryEffects::Read::get(), &getSignalMutable());
618LogicalResult llhd::DriveOp::fold(FoldAdaptor adaptor,
619 SmallVectorImpl<OpFoldResult> &result) {
623 if (matchPattern(getEnable(), m_One())) {
624 getEnableMutable().clear();
631LogicalResult llhd::DriveOp::canonicalize(llhd::DriveOp op,
632 PatternRewriter &rewriter) {
636 if (matchPattern(op.getEnable(), m_Zero())) {
637 rewriter.eraseOp(op);
644bool DriveOp::canRewire(
const DestructurableMemorySlot &slot,
645 SmallPtrSetImpl<Attribute> &usedIndices,
646 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
647 const DataLayout &dataLayout) {
648 for (
auto [key, _] : slot.subelementTypes)
649 usedIndices.insert(key);
651 return isa<hw::StructType, hw::ArrayType, IntegerType>(slot.elemType);
654DeletionKind DriveOp::rewire(
const DestructurableMemorySlot &slot,
655 DenseMap<Attribute, MemorySlot> &subslots,
656 OpBuilder &builder,
const DataLayout &dataLayout) {
657 SmallVector<std::pair<unsigned, Value>> driven;
660 for (
auto [idx, sig] : driven) {
661 Type nestedType = cast<RefType>(sig.getType()).getNestedType();
665 getTime(), getEnable());
668 return DeletionKind::Delete;
672DriveOp::ensureOnlySafeAccesses(
const MemorySlot &slot,
673 SmallVectorImpl<MemorySlot> &mustBeSafelyUsed,
674 const DataLayout &dataLayout) {
682LogicalResult ProcessOp::canonicalize(ProcessOp op, PatternRewriter &rewriter) {
683 if (!op.getBody().hasOneBlock())
686 auto &block = op.getBody().front();
687 auto haltOp = dyn_cast<HaltOp>(block.getTerminator());
691 if (op.getNumResults() == 0 && block.getOperations().size() == 1) {
692 rewriter.eraseOp(op);
697 if (!llvm::all_of(block.without_terminator(), [](
auto &bodyOp) {
698 return bodyOp.template hasTrait<OpTrait::ConstantLike>();
702 auto yieldOperands = haltOp.getYieldOperands();
705 llvm::BitVector operandsToErase(yieldOperands.size());
707 for (
auto [operandNo, operand] :
llvm::enumerate(yieldOperands)) {
708 auto *defOp = operand.getDefiningOp();
709 if (defOp && defOp->hasTrait<OpTrait::ConstantLike>()) {
712 if (!defOp->getParentRegion()->isProperAncestor(&op.getBody())) {
713 defOp->moveBefore(op);
715 rewriter.replaceAllUsesWith(op.getResult(operandNo), operand);
716 operandsToErase.set(operandNo);
722 if (!uniqueOperands.contains(operand)) {
723 const auto newPos = uniqueOperands.size();
724 uniqueOperands.insert(std::make_pair(operand, newPos));
725 origToNewPos.insert(std::make_pair(operandNo, newPos));
727 auto firstOccurrencePos = uniqueOperands.lookup(operand);
728 origToNewPos.insert(std::make_pair(operandNo, firstOccurrencePos));
729 operandsToErase.set(operandNo);
733 const auto countOperandsToErase = operandsToErase.count();
734 if (countOperandsToErase == 0)
739 if (countOperandsToErase == op.getNumResults()) {
740 rewriter.eraseOp(op);
744 rewriter.modifyOpInPlace(haltOp,
745 [&] { haltOp->eraseOperands(operandsToErase); });
747 SmallVector<Type> resultTypes = llvm::to_vector(haltOp->getOperandTypes());
748 auto newProcessOp = ProcessOp::create(rewriter, op.getLoc(), resultTypes,
749 op->getOperands(), op->getAttrs());
750 newProcessOp.getBody().takeBody(op.getBody());
753 for (
auto oldResult : op.getResults()) {
754 auto newResultPos = origToNewPos.find(oldResult.getResultNumber());
755 if (newResultPos == origToNewPos.end())
757 auto newResult = newProcessOp.getResult(newResultPos->getSecond());
758 rewriter.replaceAllUsesWith(oldResult, newResult);
761 rewriter.eraseOp(op);
769LogicalResult CombinationalOp::canonicalize(CombinationalOp op,
770 PatternRewriter &rewriter) {
773 if (op.getBody().hasOneBlock() && isMemoryEffectFree(op)) {
774 auto &block = op.getBody().front();
775 auto *terminator = block.getTerminator();
776 rewriter.inlineBlockBefore(&block, op, ValueRange{});
777 rewriter.replaceOp(op, terminator->getOperands());
778 rewriter.eraseOp(terminator);
789 ValueRange yieldOperands) {
791 auto *parentOp = op->getParentOp();
792 SmallVector<Type> resultTypes;
793 TypeSwitch<Operation *>(parentOp)
794 .Case<ProcessOp, CombinationalOp>([&](
auto op) {
795 resultTypes.append(op.getResultTypes().begin(),
796 op.getResultTypes().end());
798 .Case<FinalOp>([](
auto) {})
799 .Case<GlobalSignalOp>(
800 [&](
auto op) { resultTypes.push_back(op.getType()); });
803 if (yieldOperands.size() != resultTypes.size())
804 return op->emitOpError()
805 <<
"has " << yieldOperands.size()
806 <<
" yield operands, but enclosing '" << parentOp->getName()
807 <<
"' returns " << resultTypes.size();
810 for (
unsigned i = 0; i < yieldOperands.size(); ++i)
811 if (yieldOperands[i].getType() != resultTypes[i])
812 return op->emitError()
813 <<
"type of yield operand " << i <<
" ("
814 << yieldOperands[i].getType() <<
") does not match enclosing '"
815 << parentOp->getName() <<
"' result type (" << resultTypes[i]
821LogicalResult WaitOp::verify() {
829LogicalResult HaltOp::verify() {
837LogicalResult YieldOp::verify() {
842struct IntegerTypeInterface
843 :
public DestructurableTypeInterface::ExternalModel<IntegerTypeInterface,
845 std::optional<DenseMap<Attribute, Type>>
859 Type getTypeAtIndex(Type type, Attribute index)
const {
861 llvm_unreachable(
"Not implemented");
867 registry.addExtension(+[](MLIRContext *ctx, BuiltinDialect *dialect) {
868 IntegerType::attachInterface<IntegerTypeInterface>(*ctx);
871 ctx->loadDialect<comb::CombDialect>();
879LogicalResult GlobalSignalOp::verifyRegions() {
880 if (
auto *block = getInitBlock()) {
881 auto &terminator = block->back();
882 if (!isa<YieldOp>(terminator))
883 return emitOpError() <<
"must have a 'llhd.yield' terminator";
888Block *GlobalSignalOp::getInitBlock() {
889 if (getInitRegion().
empty())
891 return &getInitRegion().front();
899GetGlobalSignalOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
902 symbolTable.lookupNearestSymbolFrom(*
this, getGlobalNameAttr());
904 return emitOpError() <<
"references unknown symbol " << getGlobalNameAttr();
907 auto signal = dyn_cast<GlobalSignalOp>(symbol);
909 return emitOpError() <<
"must reference a 'llhd.global_signal', but "
910 << getGlobalNameAttr() <<
" is a '"
911 << symbol->getName() <<
"'";
914 auto expType = signal.getType();
915 auto actType = getType().getNestedType();
916 if (expType != actType)
917 return emitOpError() <<
"returns a " << actType <<
" reference, but "
918 << getGlobalNameAttr() <<
" is of type " << expType;
927ParseResult CoroutineOp::parse(OpAsmParser &parser, OperationState &result) {
929 [](Builder &builder, ArrayRef<Type> argTypes, ArrayRef<Type> results,
930 function_interface_impl::VariadicFlag,
931 std::string &) {
return builder.getFunctionType(argTypes, results); };
933 return function_interface_impl::parseFunctionOp(
934 parser, result,
false,
935 getFunctionTypeAttrName(result.name), buildFuncType,
936 getArgAttrsAttrName(result.name), getResAttrsAttrName(result.name));
939void CoroutineOp::print(OpAsmPrinter &p) {
940 function_interface_impl::printFunctionOp(
941 p, *
this,
false, getFunctionTypeAttrName(),
942 getArgAttrsAttrName(), getResAttrsAttrName());
950CallCoroutineOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
951 auto calleeName = getCalleeAttr();
953 symbolTable.lookupNearestSymbolFrom<CoroutineOp>(*
this, calleeName);
955 return emitOpError() <<
"'" << calleeName.getValue()
956 <<
"' does not reference a valid 'llhd.coroutine'";
958 auto type = coroutine.getFunctionType();
959 if (type.getNumInputs() != getNumOperands())
960 return emitOpError() <<
"has " << getNumOperands()
961 <<
" operands, but callee expects "
962 << type.getNumInputs();
964 for (
unsigned i = 0, e = type.getNumInputs(); i != e; ++i)
965 if (getOperand(i).getType() != type.getInput(i))
966 return emitOpError() <<
"operand " << i <<
" type mismatch: expected "
967 << type.getInput(i) <<
", got "
968 << getOperand(i).getType();
970 if (type.getNumResults() != getNumResults())
971 return emitOpError() <<
"has " << getNumResults()
972 <<
" results, but callee returns "
973 << type.getNumResults();
975 for (
unsigned i = 0, e = type.getNumResults(); i != e; ++i)
976 if (getResult(i).getType() != type.getResult(i))
977 return emitOpError() <<
"result " << i <<
" type mismatch: expected "
978 << type.getResult(i) <<
", got "
979 << getResult(i).getType();
988#define GET_OP_CLASSES
989#include "circt/Dialect/LLHD/LLHD.cpp.inc"
990#include "circt/Dialect/LLHD/LLHDEnums.cpp.inc"
assert(baseType &&"element must be base type")
static std::unique_ptr< Context > context
static void getSortedPtrs(DenseMap< Attribute, MemorySlot > &subslots, SmallVectorImpl< std::pair< unsigned, Value > > &sorted)
static LogicalResult verifyYieldResults(Operation *op, ValueRange yieldOperands)
static bool hasUserOfKind(Operation *op)
static int64_t intervalOverlap(int64_t a1, int64_t a2, int64_t b1, int64_t b2)
static LogicalResult canonicalizeSigPtrArraySliceOp(Op op, PatternRewriter &rewriter)
static std::optional< DenseMap< Attribute, Type > > getIntegerSubelementIndexMap(Type type, Value value)
static std::optional< DenseMap< Attribute, Type > > getSubelementIndexMap(Type type, Value value)
static OpFoldResult foldSigPtrExtractOp(Op op, ArrayRef< Attribute > operands)
static Value getValueAtIndex(OpBuilder &builder, Location loc, Value val, unsigned index, Type resultType)
static Location getLoc(DefSlot slot)
static InstancePath empty
create(elements, Type result_type=None)
create(elements, Type result_type=None)
StringAttr getName(ArrayAttr names, size_t idx)
Return the name at the specified index of the ArrayAttr or null if it cannot be determined.
unsigned getLLHDTypeWidth(Type type)
Type getLLHDElementType(Type type)
void registerDestructableIntegerExternalModel(mlir::DialectRegistry ®istry)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
function_ref< void(Value, StringRef)> OpAsmSetValueNameFn