Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LowerLayers.cpp
Go to the documentation of this file.
1//===- LowerLayers.cpp - Lower Layers by Convention -------------*- C++ -*-===//
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// This pass lowers FIRRTL layers based on their specified convention.
9//
10//===----------------------------------------------------------------------===//
11
21#include "circt/Support/Utils.h"
22#include "mlir/Pass/Pass.h"
23#include "llvm/ADT/PostOrderIterator.h"
24#include "llvm/ADT/SmallPtrSet.h"
25#include "llvm/Support/Debug.h"
26#include "llvm/Support/Mutex.h"
27
28#define DEBUG_TYPE "firrtl-lower-layers"
29
30namespace circt {
31namespace firrtl {
32#define GEN_PASS_DEF_LOWERLAYERS
33#include "circt/Dialect/FIRRTL/Passes.h.inc"
34} // namespace firrtl
35} // namespace circt
36
37using namespace circt;
38using namespace firrtl;
39
40namespace {
41
42/// Indicates the kind of reference that was captured.
43enum class ConnectKind {
44 /// A normal captured value. This is a read of a value outside the
45 /// layerblock.
46 NonRef,
47 /// A reference. This is a destination of a ref define.
48 Ref
49};
50
51struct ConnectInfo {
52 Value value;
53 ConnectKind kind;
54};
55
56/// The delimiters that should be used for a given generated name. These vary
57/// for modules and files, as well as by convention.
58enum class Delimiter { BindModule = '_', BindFile = '-', InlineMacro = '$' };
59
60/// This struct contains pre-allocated "safe" names that parallel regions can
61/// use to create names in the global namespace. This is allocated per-layer
62/// block.
63struct LayerBlockGlobals {
64 /// If the layer needs to create a module, use this name.
65 StringRef moduleName;
66
67 /// If the layer needs to create a hw::HierPathOp, use this name.
68 StringRef hierPathName;
69};
70
71} // namespace
72
73// A mapping of an old InnerRefAttr to the new inner symbol and module name that
74// need to be spliced into the old InnerRefAttr. This is used to fix
75// hierarchical path operations after layers are converted to modules.
77 DenseMap<hw::InnerRefAttr, std::pair<hw::InnerSymAttr, StringAttr>>;
78
79//===----------------------------------------------------------------------===//
80// Naming Helpers
81//===----------------------------------------------------------------------===//
82
83static void appendName(StringRef name, SmallString<32> &output,
84 bool toLower = false,
85 Delimiter delimiter = Delimiter::BindFile) {
86 if (name.empty())
87 return;
88 if (!output.empty())
89 output.push_back(static_cast<char>(delimiter));
90 output.append(name);
91 if (!toLower)
92 return;
93 auto i = output.size() - name.size();
94 output[i] = llvm::toLower(output[i]);
95}
96
97static void appendName(const ArrayRef<FlatSymbolRefAttr> &names,
98 SmallString<32> &output, bool toLower = false,
99 Delimiter delimiter = Delimiter::BindFile) {
100 for (auto name : names)
101 appendName(name.getValue(), output, toLower, delimiter);
102}
103
104static void appendName(SymbolRefAttr name, SmallString<32> &output,
105 bool toLower = false,
106 Delimiter delimiter = Delimiter::BindFile) {
107 appendName(name.getRootReference(), output, toLower, delimiter);
108 appendName(name.getNestedReferences(), output, toLower, delimiter);
109}
110
111/// For a layer `@A::@B::@C` in module Module,
112/// the generated module is called `Module_A_B_C`.
113static SmallString<32> moduleNameForLayer(StringRef moduleName,
114 SymbolRefAttr layerName) {
115 SmallString<32> result;
116 appendName(moduleName, result, /*toLower=*/false,
117 /*delimiter=*/Delimiter::BindModule);
118 appendName(layerName, result, /*toLower=*/false,
119 /*delimiter=*/Delimiter::BindModule);
120 return result;
121}
122
123static SmallString<32> hierPathNameForLayer(StringRef moduleName,
124 SymbolRefAttr layerName) {
125 SmallString<32> result("__lowerLayers_path");
126 appendName(moduleName, result, /*toLower=*/false,
127 /*delimiter=*/Delimiter::BindModule);
128 appendName(layerName, result, /*toLower=*/false,
129 /*delimiter=*/Delimiter::BindModule);
130 return result;
131}
132
133/// For a layerblock `@A::@B::@C`,
134/// the generated instance is called `a_b_c`.
135static SmallString<32> instanceNameForLayer(SymbolRefAttr layerName) {
136 SmallString<32> result;
137 appendName(layerName, result, /*toLower=*/true,
138 /*delimiter=*/Delimiter::BindModule);
139 return result;
140}
141
142static SmallString<32> fileNameForLayer(StringRef moduleName, StringAttr root,
143 ArrayRef<FlatSymbolRefAttr> nested) {
144 SmallString<32> result;
145 result.append("layers");
146 appendName(moduleName, result);
147 appendName(root, result);
148 appendName(nested, result);
149 result.append(".sv");
150 return result;
151}
152
153/// For all layerblocks `@A::@B::@C` in a module called Module,
154/// the output filename is `layers-Module-A-B-C.sv`.
155static SmallString<32> fileNameForLayer(StringRef moduleName,
156 SymbolRefAttr layerName) {
157 return fileNameForLayer(moduleName, layerName.getRootReference(),
158 layerName.getNestedReferences());
159}
160
161/// For all layerblocks `@A::@B::@C` in a module called Module,
162/// the include-guard macro is `layers_Module_A_B_C`.
163static SmallString<32> guardMacroNameForLayer(StringRef moduleName,
164 SymbolRefAttr layerName) {
165 SmallString<32> result;
166 result.append("layers");
167 appendName(moduleName, result, false, Delimiter::BindModule);
168 appendName(layerName, result, false, Delimiter::BindModule);
169 return result;
170}
171
172/// For a layerblock `@A::@B::@C`, the verilog macro is `A_B_C`.
173static SmallString<32>
174macroNameForLayer(StringRef circuitName,
175 ArrayRef<FlatSymbolRefAttr> layerName) {
176 SmallString<32> result("layer");
177 for (auto part : layerName)
178 appendName(part, result, /*toLower=*/false,
179 /*delimiter=*/Delimiter::InlineMacro);
180 return result;
181}
182
183//===----------------------------------------------------------------------===//
184// LowerLayersPass
185//===----------------------------------------------------------------------===//
186
187namespace {
188/// Information about each bind file we are emitting. During a prepass, we walk
189/// the modules to find layerblocks, creating an emit::FileOp for each bound
190/// layer used under each module. As we do this, we build a table of these info
191/// objects for quick lookup later.
192struct BindFileInfo {
193 /// The filename of the bind file _without_ a directory.
194 StringAttr filename;
195 /// Where to insert bind statements into the bind file.
196 Block *body;
197};
198} // namespace
199
201 : public circt::firrtl::impl::LowerLayersBase<LowerLayersPass> {
202 using Base::Base;
203
204 hw::OutputFileAttr getOutputFile(SymbolRefAttr layerName) {
205 auto layer = symbolToLayer.lookup(layerName);
206 if (!layer)
207 return nullptr;
208 return layer->getAttrOfType<hw::OutputFileAttr>("output_file");
209 }
210
211 hw::OutputFileAttr outputFileForLayer(StringRef moduleName,
212 SymbolRefAttr layerName) {
213 if (auto file = getOutputFile(layerName))
214 return hw::OutputFileAttr::getFromDirectoryAndFilename(
215 &getContext(), file.getDirectory(),
216 fileNameForLayer(moduleName, layerName),
217 /*excludeFromFileList=*/true);
218 return hw::OutputFileAttr::getFromFilename(
219 &getContext(), fileNameForLayer(moduleName, layerName),
220 /*excludeFromFileList=*/true);
221 }
222
223 /// Safely build a new module with a given namehint. This handles geting a
224 /// lock to modify the top-level circuit.
225 FModuleOp buildNewModule(OpBuilder &builder, LayerBlockOp layerBlock);
226
227 /// Strip layer colors from the module's interface.
228 FailureOr<InnerRefMap> runOnModuleLike(FModuleLike moduleLike);
229
230 /// Extract layerblocks and strip probe colors from all ops under the module.
231 LogicalResult runOnModuleBody(FModuleOp moduleOp, InnerRefMap &innerRefMap);
232
233 /// Update the module's port types to remove any explicit layer requirements
234 /// from any probe types.
235 void removeLayersFromPorts(FModuleLike moduleLike);
236
237 /// Update the value's type to remove any layers from any probe types.
238 void removeLayersFromValue(Value value);
239
240 /// Lower an inline layerblock to an ifdef block.
241 void lowerInlineLayerBlock(LayerOp layer, LayerBlockOp layerBlock);
242
243 /// Build macro declarations and cache information about the layers.
244 void preprocessLayers(CircuitNamespace &ns, OpBuilder &b, LayerOp layer,
245 StringRef circuitName,
246 SmallVector<FlatSymbolRefAttr> &stack);
248
249 /// For each module, build a bindfile for each bound-layer, if needed.
251
252 /// Build the bindfile skeletons for each module. Set up a table which tells
253 /// us for each module/layer pair, where to insert the bind operations.
255
256 /// Build the bindfile skeleton for a module.
258 FModuleOp module);
259
260 /// Record the supposed bindfiles for any known layers of the ext module.
262 FExtModuleOp extModule);
263
264 /// Build a bindfile skeleton for a particular module and layer.
266 OpBuilder &b, SymbolRefAttr layerName, LayerOp layer);
267
268 /// Entry point for the function.
269 void runOnOperation() override;
270
271 /// Indicates exclusive access to modify the circuitNamespace and the circuit.
272 llvm::sys::SmartMutex<true> *circuitMutex;
273
274 /// A map of layer blocks to "safe" global names which are fine to create in
275 /// the circuit namespace.
276 DenseMap<LayerBlockOp, LayerBlockGlobals> layerBlockGlobals;
277
278 /// A map from inline layers to their macro names.
279 DenseMap<LayerOp, FlatSymbolRefAttr> macroNames;
280
281 /// A mapping of symbol name to layer operation. This also serves as an
282 /// iterable list of all layers declared in a circuit. We use a map vector so
283 /// that the iteration order matches the order of declaration in the circuit.
284 /// This order is not required for correctness, it helps with legibility.
285 llvm::MapVector<SymbolRefAttr, LayerOp> symbolToLayer;
286
287 /// Utility for creating hw::HierPathOp.
289
290 /// A mapping from module*layer to bindfile name.
291 DenseMap<Operation *, DenseMap<LayerOp, BindFileInfo>> bindFiles;
292};
293
294/// Multi-process safe function to build a module in the circuit and return it.
295/// The name provided is only a namehint for the module---a unique name will be
296/// generated if there are conflicts with the namehint in the circuit-level
297/// namespace.
298FModuleOp LowerLayersPass::buildNewModule(OpBuilder &builder,
299 LayerBlockOp layerBlock) {
300 auto location = layerBlock.getLoc();
301 auto namehint = layerBlockGlobals.lookup(layerBlock).moduleName;
302 llvm::sys::SmartScopedLock<true> instrumentationLock(*circuitMutex);
303 FModuleOp newModule = FModuleOp::create(
304 builder, location, builder.getStringAttr(namehint),
305 ConventionAttr::get(builder.getContext(), Convention::Internal),
306 ArrayRef<PortInfo>{}, ArrayAttr{});
307 if (auto dir = getOutputFile(layerBlock.getLayerNameAttr())) {
308 assert(dir.isDirectory());
309 newModule->setAttr("output_file", dir);
310 }
311 SymbolTable::setSymbolVisibility(newModule, SymbolTable::Visibility::Private);
312 return newModule;
313}
314
316 auto type = dyn_cast<RefType>(value.getType());
317 if (!type || !type.getLayer())
318 return;
319 value.setType(type.removeLayer());
320}
321
322void LowerLayersPass::removeLayersFromPorts(FModuleLike moduleLike) {
323 auto oldTypeAttrs = moduleLike.getPortTypesAttr();
324 SmallVector<Attribute> newTypeAttrs;
325 newTypeAttrs.reserve(oldTypeAttrs.size());
326 bool changed = false;
327
328 for (auto typeAttr : oldTypeAttrs.getAsRange<TypeAttr>()) {
329 if (auto refType = dyn_cast<RefType>(typeAttr.getValue())) {
330 if (refType.getLayer()) {
331 typeAttr = TypeAttr::get(refType.removeLayer());
332 changed = true;
333 }
334 }
335 newTypeAttrs.push_back(typeAttr);
336 }
337
338 if (!changed)
339 return;
340
341 moduleLike.setPortTypesAttr(
342 ArrayAttr::get(moduleLike.getContext(), newTypeAttrs));
343
344 if (auto moduleOp = dyn_cast<FModuleOp>(moduleLike.getOperation())) {
345 for (auto arg : moduleOp.getBodyBlock()->getArguments())
347 }
348}
349
350FailureOr<InnerRefMap>
351LowerLayersPass::runOnModuleLike(FModuleLike moduleLike) {
352 LLVM_DEBUG({
353 llvm::dbgs() << "Module: " << moduleLike.getModuleName() << "\n";
354 llvm::dbgs() << " Examining Layer Blocks:\n";
355 });
356
357 // Strip away layers from the interface of the module-like op.
358 InnerRefMap innerRefMap;
359 auto result =
360 TypeSwitch<Operation *, LogicalResult>(moduleLike.getOperation())
361 .Case<FModuleOp>([&](auto op) {
362 op.setLayers({});
364 return runOnModuleBody(op, innerRefMap);
365 })
366 .Case<FExtModuleOp>([&](auto op) {
367 op.setKnownLayers({});
368 op.setLayers({});
370 return success();
371 })
372 .Case<FIntModuleOp, FMemModuleOp>([&](auto op) {
373 op.setLayers({});
375 return success();
376 })
377 .Case<ClassOp, ExtClassOp>([](auto) { return success(); })
378 .Default(
379 [](auto *op) { return op->emitError("unknown module-like op"); });
380
381 if (failed(result))
382 return failure();
383
384 return innerRefMap;
385}
386
388 LayerBlockOp layerBlock) {
389 if (!layerBlock.getBody()->empty()) {
390 OpBuilder builder(layerBlock);
391 auto macroName = macroNames[layer];
392 auto ifDef = builder.create<sv::IfDefOp>(layerBlock.getLoc(), macroName);
393 ifDef.getBodyRegion().takeBody(layerBlock.getBodyRegion());
394 }
395 layerBlock.erase();
396}
397
398LogicalResult LowerLayersPass::runOnModuleBody(FModuleOp moduleOp,
399 InnerRefMap &innerRefMap) {
400 hw::InnerSymbolNamespace ns(moduleOp);
401
402 // A cache of values to nameable ops that can be used
403 DenseMap<Value, Operation *> nodeCache;
404
405 // Get or create a node op for a value captured by a layer block.
406 auto getOrCreateNodeOp = [&](Value operand,
407 ImplicitLocOpBuilder &builder) -> Operation * {
408 // Use the cache hit.
409 auto *nodeOp = nodeCache.lookup(operand);
410 if (nodeOp)
411 return nodeOp;
412
413 // Create a new node. Put it in the cache and use it.
414 OpBuilder::InsertionGuard guard(builder);
415 builder.setInsertionPointAfterValue(operand);
416 SmallString<16> nameHint;
417 // Try to generate a "good" name hint to use for the node.
418 if (auto *definingOp = operand.getDefiningOp()) {
419 if (auto instanceOp = dyn_cast<InstanceOp>(definingOp)) {
420 nameHint.append(instanceOp.getName());
421 nameHint.push_back('_');
422 nameHint.append(
423 instanceOp.getPortName(cast<OpResult>(operand).getResultNumber()));
424 } else if (auto opName = definingOp->getAttrOfType<StringAttr>("name")) {
425 nameHint.append(opName);
426 }
427 }
428 return nodeOp = NodeOp::create(builder, operand.getLoc(), operand,
429 nameHint.empty() ? "_layer_probe"
430 : StringRef(nameHint));
431 };
432
433 // Determine the replacement for an operand within the current region. Keep a
434 // densemap of replacements around to avoid creating the same hardware
435 // multiple times.
436 DenseMap<Value, Value> replacements;
437 auto getReplacement = [&](Operation *user, Value value) -> Value {
438 auto it = replacements.find(value);
439 if (it != replacements.end())
440 return it->getSecond();
441
442 ImplicitLocOpBuilder localBuilder(value.getLoc(), &getContext());
443 Value replacement;
444
445 auto layerBlockOp = user->getParentOfType<LayerBlockOp>();
446 localBuilder.setInsertionPointToStart(layerBlockOp.getBody());
447
448 // If the operand is "special", e.g., it has no XMR representation, then we
449 // need to clone it.
450 //
451 // TODO: Change this to recursively clone. This will matter once FString
452 // operations have operands.
453 if (type_isa<FStringType>(value.getType())) {
454 localBuilder.setInsertionPoint(user);
455 replacement = localBuilder.clone(*value.getDefiningOp())->getResult(0);
456 replacements.insert({value, replacement});
457 return replacement;
458 }
459
460 // If the operand is an XMR ref, then we _have_ to clone it.
461 auto *definingOp = value.getDefiningOp();
462 if (isa_and_present<XMRRefOp>(definingOp)) {
463 replacement = localBuilder.clone(*definingOp)->getResult(0);
464 replacements.insert({value, replacement});
465 return replacement;
466 }
467
468 // Determine the replacement value for the captured operand. There are
469 // three cases that can occur:
470 //
471 // 1. Capturing something zero-width. Create a zero-width constant zero.
472 // 2. Capture an expression or instance port. Drop a node and XMR deref
473 // that.
474 // 3. Capture something that can handle an inner sym. XMR deref that.
475 //
476 // Note: (3) can be either an operation or a _module_ port.
477 auto baseType = type_cast<FIRRTLBaseType>(value.getType());
478 if (baseType && baseType.getBitWidthOrSentinel() == 0) {
479 OpBuilder::InsertionGuard guard(localBuilder);
480 auto zeroUIntType = UIntType::get(localBuilder.getContext(), 0);
481 replacement = localBuilder.createOrFold<BitCastOp>(
482 value.getType(), ConstantOp::create(localBuilder, zeroUIntType,
483 getIntZerosAttr(zeroUIntType)));
484 } else {
485 auto *definingOp = value.getDefiningOp();
486 hw::InnerRefAttr innerRef;
487 if (definingOp) {
488 // Always create a node. This is a trade-off between optimizations and
489 // dead code. By adding the node, this allows the original path to be
490 // better optimized, but will leave dead code in the design. If the
491 // node is not created, then the output is less optimized. Err on the
492 // side of dead code. This dead node _may_ be eventually inlined by
493 // `ExportVerilog`. However, this is not guaranteed.
494 definingOp = getOrCreateNodeOp(value, localBuilder);
495 innerRef = getInnerRefTo(
496 definingOp, [&](auto) -> hw::InnerSymbolNamespace & { return ns; });
497 } else {
498 auto portIdx = cast<BlockArgument>(value).getArgNumber();
499 innerRef = getInnerRefTo(
500 cast<FModuleLike>(*moduleOp), portIdx,
501 [&](auto) -> hw::InnerSymbolNamespace & { return ns; });
502 }
503
504 hw::HierPathOp hierPathOp;
505 {
506 // TODO: Move to before parallel region to avoid the lock.
507 auto insertPoint = OpBuilder::InsertPoint(moduleOp->getBlock(),
508 Block::iterator(moduleOp));
509 llvm::sys::SmartScopedLock<true> circuitLock(*circuitMutex);
510 hierPathOp = hierPathCache->getOrCreatePath(
511 localBuilder.getArrayAttr({innerRef}), localBuilder.getLoc(),
512 insertPoint, layerBlockGlobals.lookup(layerBlockOp).hierPathName);
513 hierPathOp.setVisibility(SymbolTable::Visibility::Private);
514 }
515
516 replacement = XMRDerefOp::create(localBuilder, value.getType(),
517 hierPathOp.getSymNameAttr());
518 }
519
520 replacements.insert({value, replacement});
521
522 return replacement;
523 };
524
525 // A map of instance ops to modules that this pass creates. This is used to
526 // check if this was an instance that we created and to do fast module
527 // dereferencing (avoiding a symbol table).
528 DenseMap<InstanceOp, FModuleOp> createdInstances;
529
530 // Check that the preconditions for this pass are met. Reject any ops which
531 // must have been removed before this runs.
532 auto opPreconditionCheck = [](Operation *op) -> LogicalResult {
533 // LowerXMR op removal postconditions.
534 if (isa<RefCastOp, RefDefineOp, RefResolveOp, RefSendOp, RefSubOp,
535 RWProbeOp>(op))
536 return op->emitOpError()
537 << "cannot be handled by the lower-layers pass. This should have "
538 "already been removed by the lower-xmr pass.";
539
540 return success();
541 };
542
543 // Post-order traversal that expands a layer block into its parent. Because of
544 // the pass precondition that this runs _after_ `LowerXMR`, not much has to
545 // happen here. All of the following do happen, though:
546 //
547 // 1. Any layer coloring is stripped.
548 // 2. Layers with Inline convention are converted to SV ifdefs.
549 // 3. Layers with Bind convention are converted to new modules and then
550 // instantiated at their original location. Any captured values are either
551 // moved, cloned, or converted to XMR deref ops.
552 // 4. Move instances created from earlier (3) conversions out of later (3)
553 // conversions. This is necessary to avoid a SystemVerilog-illegal
554 // bind-under-bind. (See Section 23.11 of 1800-2023.)
555 // 5. Keep track of special ops (ops with inner symbols or verbatims) which
556 // need to have something updated because of the new instance hierarchy
557 // being created.
558 //
559 // Remember, this is post-order, in-order. Child layer blocks are visited
560 // before parents. Any nested regions _within_ the layer block are also
561 // visited before the outer layer block.
562 auto result = moduleOp.walk<mlir::WalkOrder::PostOrder>([&](Operation *op) {
563 if (failed(opPreconditionCheck(op)))
564 return WalkResult::interrupt();
565
566 // Strip layer requirements from any op that might represent a probe.
567 for (auto result : op->getResults())
568 removeLayersFromValue(result);
569
570 // If the op is an instance, clear the enablelayers attribute.
571 if (auto instance = dyn_cast<InstanceOp>(op))
572 instance.setLayers({});
573
574 auto layerBlock = dyn_cast<LayerBlockOp>(op);
575 if (!layerBlock)
576 return WalkResult::advance();
577
578 // After this point, we are dealing with a layer block.
579 auto layer = symbolToLayer.lookup(layerBlock.getLayerName());
580
581 if (layer.getConvention() == LayerConvention::Inline) {
582 lowerInlineLayerBlock(layer, layerBlock);
583 return WalkResult::advance();
584 }
585
586 // After this point, we are dealing with a bind convention layer block.
587 assert(layer.getConvention() == LayerConvention::Bind);
588
589 // Clear the replacements so that none are re-used across layer blocks.
590 replacements.clear();
591 OpBuilder builder(moduleOp);
592 SmallVector<hw::InnerSymAttr> innerSyms;
593 SmallVector<sv::VerbatimOp> verbatims;
594 DenseSet<Operation *> spilledSubOps;
595 auto layerBlockWalkResult = layerBlock.walk([&](Operation *op) {
596 // Error if pass preconditions are not met.
597 if (failed(opPreconditionCheck(op)))
598 return WalkResult::interrupt();
599
600 // Specialized handling of subfields, subindexes, and subaccesses which
601 // need to be spilled and nodes that referred to spilled nodes. If these
602 // are kept in the module, then the XMR is going to be bidirectional. Fix
603 // this for subfield and subindex by moving these ops outside the
604 // layerblock. Try to fix this for subaccess and error if the move can't
605 // be made because the index is defined inside the layerblock. (This case
606 // is exceedingly rare given that subaccesses are almost always unexepcted
607 // when this pass runs.) Additionally, if any nodes are seen that are
608 // transparently referencing a spilled op, spill the node, too. The node
609 // provides an anchor for an inner symbol (which subfield, subindex, and
610 // subaccess do not).
611 if (isa<SubfieldOp, SubindexOp>(op)) {
612 auto input = op->getOperand(0);
613 if (!firrtl::type_cast<FIRRTLBaseType>(input.getType()).isPassive() &&
614 !isAncestorOfValueOwner(layerBlock, input)) {
615 op->moveBefore(layerBlock);
616 spilledSubOps.insert(op);
617 }
618 return WalkResult::advance();
619 }
620 if (auto subOp = dyn_cast<SubaccessOp>(op)) {
621 auto input = subOp.getInput();
622 if (firrtl::type_cast<FIRRTLBaseType>(input.getType()).isPassive())
623 return WalkResult::advance();
624
625 if (!isAncestorOfValueOwner(layerBlock, input) &&
626 !isAncestorOfValueOwner(layerBlock, subOp.getIndex())) {
627 subOp->moveBefore(layerBlock);
628 spilledSubOps.insert(op);
629 return WalkResult::advance();
630 }
631 auto diag = op->emitOpError()
632 << "has a non-passive operand and captures a value defined "
633 "outside its enclosing bind-convention layerblock. The "
634 "'LowerLayers' pass cannot lower this as it would "
635 "create an output port on the resulting module.";
636 diag.attachNote(layerBlock.getLoc())
637 << "the layerblock is defined here";
638 return WalkResult::interrupt();
639 }
640 if (auto nodeOp = dyn_cast<NodeOp>(op)) {
641 auto *definingOp = nodeOp.getInput().getDefiningOp();
642 if (definingOp &&
643 spilledSubOps.contains(nodeOp.getInput().getDefiningOp())) {
644 op->moveBefore(layerBlock);
645 return WalkResult::advance();
646 }
647 }
648
649 // Record any operations inside the layer block which have inner symbols.
650 // Theses may have symbol users which need to be updated.
651 //
652 // Note: this needs to _not_ index spilled NodeOps above.
653 if (auto symOp = dyn_cast<hw::InnerSymbolOpInterface>(op))
654 if (auto innerSym = symOp.getInnerSymAttr())
655 innerSyms.push_back(innerSym);
656
657 // Handle instance ops that were created from nested layer blocks. These
658 // ops need to be moved outside the layer block to avoid nested binds.
659 // Nested binds are illegal in the SystemVerilog specification (and
660 // checked by FIRRTL verification).
661 //
662 // For each value defined in this layer block which drives a port of one
663 // of these instances, create an output reference type port on the
664 // to-be-created module and drive it with the value. Move the instance
665 // outside the layer block. We will hook it up later once we replace the
666 // layer block with an instance.
667 if (auto instOp = dyn_cast<InstanceOp>(op)) {
668 // Ignore instances which this pass did not create.
669 if (!createdInstances.contains(instOp))
670 return WalkResult::advance();
671
672 LLVM_DEBUG({
673 llvm::dbgs()
674 << " Found instance created from nested layer block:\n"
675 << " module: " << instOp.getModuleName() << "\n"
676 << " instance: " << instOp.getName() << "\n";
677 });
678 instOp->moveBefore(layerBlock);
679 return WalkResult::advance();
680 }
681
682 // Handle captures. For any captured operands, convert them to a suitable
683 // replacement value. The `getReplacement` function will automatically
684 // reuse values whenever possible.
685 for (size_t i = 0, e = op->getNumOperands(); i != e; ++i) {
686 auto operand = op->getOperand(i);
687
688 // If the operand is in this layer block, do nothing.
689 //
690 // Note: This check is what avoids handling ConnectOp destinations.
691 if (isAncestorOfValueOwner(layerBlock, operand))
692 continue;
693
694 op->setOperand(i, getReplacement(op, operand));
695 }
696
697 if (auto verbatim = dyn_cast<sv::VerbatimOp>(op))
698 verbatims.push_back(verbatim);
699
700 return WalkResult::advance();
701 });
702
703 if (layerBlockWalkResult.wasInterrupted())
704 return WalkResult::interrupt();
705
706 // Create the new module. This grabs a lock to modify the circuit.
707 FModuleOp newModule = buildNewModule(builder, layerBlock);
708 SymbolTable::setSymbolVisibility(newModule,
709 SymbolTable::Visibility::Private);
710 newModule.getBody().takeBody(layerBlock.getRegion());
711
712 LLVM_DEBUG({
713 llvm::dbgs() << " New Module: "
714 << layerBlockGlobals.lookup(layerBlock).moduleName << "\n";
715 });
716
717 // Replace the original layer block with an instance. Hook up the
718 // instance. Intentionally create instance with probe ports which do
719 // not have an associated layer. This is illegal IR that will be
720 // made legal by the end of the pass. This is done to avoid having
721 // to revisit and rewrite each instance everytime it is moved into a
722 // parent layer.
723 builder.setInsertionPointAfter(layerBlock);
724 auto instanceName = instanceNameForLayer(layerBlock.getLayerName());
725 auto innerSym =
726 hw::InnerSymAttr::get(builder.getStringAttr(ns.newName(instanceName)));
727
728 auto instanceOp = InstanceOp::create(
729 builder, layerBlock.getLoc(), /*moduleName=*/newModule,
730 /*name=*/
731 instanceName, NameKindEnum::DroppableName,
732 /*annotations=*/ArrayRef<Attribute>{},
733 /*portAnnotations=*/ArrayRef<Attribute>{}, /*lowerToBind=*/false,
734 /*doNotPrint=*/true, innerSym);
735
736 auto outputFile = outputFileForLayer(moduleOp.getModuleNameAttr(),
737 layerBlock.getLayerName());
738 instanceOp->setAttr("output_file", outputFile);
739
740 createdInstances.try_emplace(instanceOp, newModule);
741
742 // create the bind op.
743 {
744 auto builder = OpBuilder::atBlockEnd(bindFiles[moduleOp][layer].body);
745 BindOp::create(builder, layerBlock.getLoc(), moduleOp.getModuleNameAttr(),
746 instanceOp.getInnerSymAttr().getSymName());
747 }
748
749 LLVM_DEBUG(llvm::dbgs() << " moved inner refs:\n");
750 for (hw::InnerSymAttr innerSym : innerSyms) {
751 auto oldInnerRef = hw::InnerRefAttr::get(moduleOp.getModuleNameAttr(),
752 innerSym.getSymName());
753 auto splice = std::make_pair(instanceOp.getInnerSymAttr(),
754 newModule.getModuleNameAttr());
755 innerRefMap.insert({oldInnerRef, splice});
756 LLVM_DEBUG(llvm::dbgs() << " - ref: " << oldInnerRef << "\n"
757 << " splice: " << splice.first << ", "
758 << splice.second << "\n";);
759 }
760
761 // Update verbatims that target operations extracted alongside.
762 if (!verbatims.empty()) {
763 mlir::AttrTypeReplacer replacer;
764 replacer.addReplacement(
765 [&innerRefMap](hw::InnerRefAttr ref) -> std::optional<Attribute> {
766 auto it = innerRefMap.find(ref);
767 if (it != innerRefMap.end())
768 return hw::InnerRefAttr::get(it->second.second, ref.getName());
769 return std::nullopt;
770 });
771 for (auto verbatim : verbatims)
772 replacer.replaceElementsIn(verbatim);
773 }
774
775 layerBlock.erase();
776
777 return WalkResult::advance();
778 });
779 return success(!result.wasInterrupted());
780}
781
783 LayerOp layer, StringRef circuitName,
784 SmallVector<FlatSymbolRefAttr> &stack) {
785 stack.emplace_back(FlatSymbolRefAttr::get(layer.getSymNameAttr()));
786 ArrayRef stackRef(stack);
787 symbolToLayer.insert(
788 {SymbolRefAttr::get(stackRef.front().getAttr(), stackRef.drop_front()),
789 layer});
790 if (layer.getConvention() == LayerConvention::Inline) {
791 auto *ctx = &getContext();
792 auto macName = macroNameForLayer(circuitName, stack);
793 auto symName = ns.newName(macName);
794
795 auto symNameAttr = StringAttr::get(ctx, symName);
796 auto macNameAttr = StringAttr();
797 if (macName != symName)
798 macNameAttr = StringAttr::get(ctx, macName);
799
800 sv::MacroDeclOp::create(b, layer->getLoc(), symNameAttr, ArrayAttr(),
801 macNameAttr);
802 macroNames[layer] = FlatSymbolRefAttr::get(&getContext(), symNameAttr);
803 }
804 for (auto child : layer.getOps<LayerOp>())
805 preprocessLayers(ns, b, child, circuitName, stack);
806 stack.pop_back();
807}
808
810 auto circuit = getOperation();
811 auto circuitName = circuit.getName();
812 for (auto layer : circuit.getOps<LayerOp>()) {
813 OpBuilder b(layer);
814 SmallVector<FlatSymbolRefAttr> stack;
815 preprocessLayers(ns, b, layer, circuitName, stack);
816 }
817}
818
820 InstanceGraphNode *node, OpBuilder &b,
821 SymbolRefAttr layerName, LayerOp layer) {
822 assert(layer.getConvention() == LayerConvention::Bind);
823 auto module = node->getModule<FModuleOp>();
824 auto loc = module.getLoc();
825
826 // Compute the include guard macro name.
827 auto macroName = guardMacroNameForLayer(module.getModuleName(), layerName);
828 auto macroSymbol = ns.newName(macroName);
829 auto macroNameAttr = StringAttr::get(&getContext(), macroName);
830 auto macroSymbolAttr = StringAttr::get(&getContext(), macroSymbol);
831 auto macroSymbolRefAttr = FlatSymbolRefAttr::get(macroSymbolAttr);
832
833 // Compute the base name for the bind file.
834 auto bindFileName = fileNameForLayer(module.getName(), layerName);
835
836 // Build the full output path using the filename of the bindfile and the
837 // output directory of the layer, if any.
838 auto dir = layer->getAttrOfType<hw::OutputFileAttr>("output_file");
839 StringAttr filename = StringAttr::get(&getContext(), bindFileName);
840 StringAttr path;
841 if (dir)
842 path = StringAttr::get(&getContext(),
843 Twine(dir.getDirectory()) + bindFileName);
844 else
845 path = filename;
846
847 // Declare the macro for the include guard.
848 sv::MacroDeclOp::create(b, loc, macroSymbolAttr, ArrayAttr{}, macroNameAttr);
849
850 // Create the emit op.
851 auto bindFile = emit::FileOp::create(b, loc, path);
852 OpBuilder::InsertionGuard _(b);
853 b.setInsertionPointToEnd(bindFile.getBody());
854
855 // Create the #ifndef for the include guard.
856 auto includeGuard = sv::IfDefOp::create(b, loc, macroSymbolRefAttr);
857 b.createBlock(&includeGuard.getElseRegion());
858
859 // Create the #define for the include guard.
860 sv::MacroDefOp::create(b, loc, macroSymbolRefAttr);
861
862 // Create IR to enable any parent layers.
863 auto parent = layer->getParentOfType<LayerOp>();
864 while (parent) {
865 // If the parent is bound-in, we enable it by including the bindfile.
866 // The parent bindfile will enable all ancestors.
867 if (parent.getConvention() == LayerConvention::Bind) {
868 auto target = bindFiles[module][parent].filename;
869 sv::IncludeOp::create(b, loc, IncludeStyle::Local, target);
870 break;
871 }
872
873 // If the parent layer is inline, we can only assert that the parent is
874 // already enabled.
875 if (parent.getConvention() == LayerConvention::Inline) {
876 auto parentMacroSymbolRefAttr = macroNames[parent];
877 auto parentGuard = sv::IfDefOp::create(b, loc, parentMacroSymbolRefAttr);
878 OpBuilder::InsertionGuard guard(b);
879 b.createBlock(&parentGuard.getElseRegion());
880 auto message = StringAttr::get(&getContext(),
881 Twine(parent.getName()) + " not enabled");
882 sv::MacroErrorOp::create(b, loc, message);
883 parent = parent->getParentOfType<LayerOp>();
884 continue;
885 }
886
887 // Unknown Layer convention.
888 llvm_unreachable("unknown layer convention");
889 }
890
891 // Create IR to include bind files for child modules. If a module is
892 // instantiated more than once, we only need to include the bindfile once.
893 SmallPtrSet<Operation *, 8> seen;
894 for (auto *record : *node) {
895 auto *child = record->getTarget()->getModule().getOperation();
896 if (!std::get<bool>(seen.insert(child)))
897 continue;
898 auto files = bindFiles[child];
899 auto lookup = files.find(layer);
900 if (lookup != files.end())
901 sv::IncludeOp::create(b, loc, IncludeStyle::Local,
902 lookup->second.filename);
903 }
904
905 // Save the bind file information for later.
906 auto &info = bindFiles[module][layer];
907 info.filename = filename;
908 info.body = includeGuard.getElseBlock();
909}
910
912 InstanceGraphNode *node,
913 FModuleOp module) {
914
915 OpBuilder b(&getContext());
916 b.setInsertionPointAfter(module);
917
918 // Create a bind file only if the layer is used under the module.
919 llvm::SmallDenseSet<LayerOp> layersRequiringBindFiles;
920
921 // If the module is public, create a bind file for all layers.
922 if (module.isPublic() || emitAllBindFiles)
923 for (auto [_, layer] : symbolToLayer)
924 if (layer.getConvention() == LayerConvention::Bind)
925 layersRequiringBindFiles.insert(layer);
926
927 // Handle layers used directly in this module.
928 module->walk([&](LayerBlockOp layerBlock) {
929 auto layer = symbolToLayer[layerBlock.getLayerNameAttr()];
930 if (layer.getConvention() == LayerConvention::Inline)
931 return;
932
933 // Create a bindfile for any layer directly used in the module.
934 layersRequiringBindFiles.insert(layer);
935
936 // Determine names for all modules that will be created.
937 auto moduleName = module.getModuleName();
938 auto layerName = layerBlock.getLayerName();
939
940 // A name hint for the module created from this layerblock.
941 auto layerBlockModuleName = moduleNameForLayer(moduleName, layerName);
942
943 // A name hint for the hier-path-op which targets the bound-in instance of
944 // the module created from this layerblock.
945 auto layerBlockHierPathName = hierPathNameForLayer(moduleName, layerName);
946
947 LayerBlockGlobals globals;
948 globals.moduleName = ns.newName(layerBlockModuleName);
949 globals.hierPathName = ns.newName(layerBlockHierPathName);
950 layerBlockGlobals.insert({layerBlock, globals});
951 });
952
953 // Create a bindfile for layers used indirectly under this module.
954 for (auto *record : *node) {
955 auto *child = record->getTarget()->getModule().getOperation();
956 for (auto [layer, _] : bindFiles[child])
957 layersRequiringBindFiles.insert(layer);
958 }
959
960 // Build the bindfiles for any layer seen under this module. The bindfiles are
961 // emitted in the order which they are declared, for readability.
962 for (auto [sym, layer] : symbolToLayer)
963 if (layersRequiringBindFiles.contains(layer))
964 buildBindFile(ns, node, b, sym, layer);
965}
966
968 InstanceGraphNode *node,
969 FExtModuleOp extModule) {
970 // For each known layer of the extmodule, compute and record the bindfile
971 // name. When a layer is known, its parent layers are implicitly known,
972 // so compute bindfiles for parent layers too. Use a set to avoid
973 // repeated work, which can happen if, for example, both a child layer and
974 // a parent layer are explicitly declared to be known.
975 auto known = extModule.getKnownLayersAttr().getAsRange<SymbolRefAttr>();
976 if (known.empty())
977 return;
978
979 auto moduleName = extModule.getModuleName();
980 auto &files = bindFiles[extModule];
981 SmallPtrSet<Operation *, 8> seen;
982
983 for (auto name : known) {
984 auto layer = symbolToLayer[name];
985 auto rootLayerName = name.getRootReference();
986 auto nestedLayerNames = name.getNestedReferences();
987 while (layer && std::get<bool>(seen.insert(layer))) {
988 if (layer.getConvention() == LayerConvention::Bind) {
989 BindFileInfo info;
990 auto filename =
991 fileNameForLayer(moduleName, rootLayerName, nestedLayerNames);
992 info.filename = StringAttr::get(&getContext(), filename);
993 info.body = nullptr;
994 files.insert({layer, info});
995 }
996 layer = layer->getParentOfType<LayerOp>();
997 if (!nestedLayerNames.empty())
998 nestedLayerNames = nestedLayerNames.drop_back();
999 }
1000 }
1001}
1002
1004 InstanceGraphNode *node) {
1005 auto *op = node->getModule().getOperation();
1006 if (!op)
1007 return;
1008
1009 if (auto module = dyn_cast<FModuleOp>(op))
1010 return preprocessModule(ns, node, module);
1011
1012 if (auto extModule = dyn_cast<FExtModuleOp>(op))
1013 return preprocessExtModule(ns, node, extModule);
1014}
1015
1016/// Create the bind file skeleton for each layer, for each module.
1018 InstanceGraph &ig) {
1019 DenseSet<InstanceGraphNode *> visited;
1020 for (auto *root : ig)
1021 for (auto *node : llvm::post_order_ext(root, visited))
1022 preprocessModuleLike(ns, node);
1023}
1024
1025/// Process a circuit to remove all layer blocks in each module and top-level
1026/// layer definition.
1028 LLVM_DEBUG(
1029 llvm::dbgs() << "==----- Running LowerLayers "
1030 "-------------------------------------------------===\n");
1031 CircuitOp circuitOp = getOperation();
1032
1033 // Initialize members which cannot be initialized automatically.
1034 llvm::sys::SmartMutex<true> mutex;
1035 circuitMutex = &mutex;
1036
1037 auto *ig = &getAnalysis<InstanceGraph>();
1038 CircuitNamespace ns(circuitOp);
1040 &ns, OpBuilder::InsertPoint(getOperation().getBodyBlock(),
1041 getOperation().getBodyBlock()->begin()));
1042 hierPathCache = &hpc;
1043
1044 preprocessLayers(ns);
1045 preprocessModules(ns, *ig);
1046
1047 auto mergeMaps = [](auto &&a, auto &&b) {
1048 if (failed(a))
1049 return std::forward<decltype(a)>(a);
1050 if (failed(b))
1051 return std::forward<decltype(b)>(b);
1052
1053 for (auto bb : *b)
1054 a->insert(bb);
1055 return std::forward<decltype(a)>(a);
1056 };
1057
1058 // Lower the layer blocks of each module.
1059 SmallVector<FModuleLike> modules(
1060 circuitOp.getBodyBlock()->getOps<FModuleLike>());
1061 auto failureOrInnerRefMap = transformReduce(
1062 circuitOp.getContext(), modules, FailureOr<InnerRefMap>(InnerRefMap{}),
1063 mergeMaps, [this](FModuleLike mod) -> FailureOr<InnerRefMap> {
1064 return runOnModuleLike(mod);
1065 });
1066 if (failed(failureOrInnerRefMap))
1067 return signalPassFailure();
1068 auto &innerRefMap = *failureOrInnerRefMap;
1069
1070 // Rewrite any hw::HierPathOps which have namepaths that contain rewritting
1071 // inner refs.
1072 //
1073 // TODO: This unnecessarily computes a new namepath for every hw::HierPathOp
1074 // even if that namepath is not used. It would be better to only build the
1075 // new namepath when a change is needed, e.g., by recording updates to the
1076 // namepath.
1077 for (hw::HierPathOp hierPathOp : circuitOp.getOps<hw::HierPathOp>()) {
1078 SmallVector<Attribute> newNamepath;
1079 bool modified = false;
1080 for (auto attr : hierPathOp.getNamepath()) {
1081 hw::InnerRefAttr innerRef = dyn_cast<hw::InnerRefAttr>(attr);
1082 if (!innerRef) {
1083 newNamepath.push_back(attr);
1084 continue;
1085 }
1086 auto it = innerRefMap.find(innerRef);
1087 if (it == innerRefMap.end()) {
1088 newNamepath.push_back(attr);
1089 continue;
1090 }
1091
1092 auto &[inst, mod] = it->getSecond();
1093 newNamepath.push_back(
1094 hw::InnerRefAttr::get(innerRef.getModule(), inst.getSymName()));
1095 newNamepath.push_back(hw::InnerRefAttr::get(mod, innerRef.getName()));
1096 modified = true;
1097 }
1098 if (modified)
1099 hierPathOp.setNamepathAttr(
1100 ArrayAttr::get(circuitOp.getContext(), newNamepath));
1101 }
1102
1103 // All layers definitions can now be deleted.
1104 for (auto layerOp :
1105 llvm::make_early_inc_range(circuitOp.getBodyBlock()->getOps<LayerOp>()))
1106 layerOp.erase();
1107
1108 // Cleanup state.
1109 circuitMutex = nullptr;
1110 layerBlockGlobals.clear();
1111 macroNames.clear();
1112 symbolToLayer.clear();
1113 hierPathCache = nullptr;
1114 bindFiles.clear();
1115}
assert(baseType &&"element must be base type")
Delimiter
Definition HWOps.cpp:116
static SmallString< 32 > guardMacroNameForLayer(StringRef moduleName, SymbolRefAttr layerName)
For all layerblocks @A::@B::@C in a module called Module, the include-guard macro is layers_Module_A_...
static SmallString< 32 > instanceNameForLayer(SymbolRefAttr layerName)
For a layerblock @A::@B::@C, the generated instance is called a_b_c.
static void appendName(StringRef name, SmallString< 32 > &output, bool toLower=false, Delimiter delimiter=Delimiter::BindFile)
DenseMap< hw::InnerRefAttr, std::pair< hw::InnerSymAttr, StringAttr > > InnerRefMap
static SmallString< 32 > moduleNameForLayer(StringRef moduleName, SymbolRefAttr layerName)
For a layer @A::@B::@C in module Module, the generated module is called Module_A_B_C.
static SmallString< 32 > fileNameForLayer(StringRef moduleName, StringAttr root, ArrayRef< FlatSymbolRefAttr > nested)
static SmallString< 32 > macroNameForLayer(StringRef circuitName, ArrayRef< FlatSymbolRefAttr > layerName)
For a layerblock @A::@B::@C, the verilog macro is A_B_C.
static SmallString< 32 > hierPathNameForLayer(StringRef moduleName, SymbolRefAttr layerName)
static Block * getBodyBlock(FModuleLike mod)
void runOnOperation() override
Entry point for the function.
void removeLayersFromPorts(FModuleLike moduleLike)
Update the module's port types to remove any explicit layer requirements from any probe types.
FailureOr< InnerRefMap > runOnModuleLike(FModuleLike moduleLike)
Strip layer colors from the module's interface.
void preprocessModuleLike(CircuitNamespace &ns, InstanceGraphNode *node)
Build the bindfile skeletons for each module.
void preprocessModule(CircuitNamespace &ns, InstanceGraphNode *node, FModuleOp module)
Build the bindfile skeleton for a module.
DenseMap< LayerOp, FlatSymbolRefAttr > macroNames
A map from inline layers to their macro names.
hw::OutputFileAttr outputFileForLayer(StringRef moduleName, SymbolRefAttr layerName)
void preprocessExtModule(CircuitNamespace &ns, InstanceGraphNode *node, FExtModuleOp extModule)
Record the supposed bindfiles for any known layers of the ext module.
void lowerInlineLayerBlock(LayerOp layer, LayerBlockOp layerBlock)
Lower an inline layerblock to an ifdef block.
llvm::MapVector< SymbolRefAttr, LayerOp > symbolToLayer
A mapping of symbol name to layer operation.
void buildBindFile(CircuitNamespace &ns, InstanceGraphNode *node, OpBuilder &b, SymbolRefAttr layerName, LayerOp layer)
Build a bindfile skeleton for a particular module and layer.
void preprocessModules(CircuitNamespace &ns, InstanceGraph &ig)
For each module, build a bindfile for each bound-layer, if needed.
LogicalResult runOnModuleBody(FModuleOp moduleOp, InnerRefMap &innerRefMap)
Extract layerblocks and strip probe colors from all ops under the module.
hw::OutputFileAttr getOutputFile(SymbolRefAttr layerName)
hw::HierPathCache * hierPathCache
Utility for creating hw::HierPathOp.
FModuleOp buildNewModule(OpBuilder &builder, LayerBlockOp layerBlock)
Safely build a new module with a given namehint.
void removeLayersFromValue(Value value)
Update the value's type to remove any layers from any probe types.
void preprocessLayers(CircuitNamespace &ns, OpBuilder &b, LayerOp layer, StringRef circuitName, SmallVector< FlatSymbolRefAttr > &stack)
Build macro declarations and cache information about the layers.
DenseMap< Operation *, DenseMap< LayerOp, BindFileInfo > > bindFiles
A mapping from module*layer to bindfile name.
DenseMap< LayerBlockOp, LayerBlockGlobals > layerBlockGlobals
A map of layer blocks to "safe" global names which are fine to create in the circuit namespace.
llvm::sys::SmartMutex< true > * circuitMutex
Indicates exclusive access to modify the circuitNamespace and the circuit.
StringRef newName(const Twine &name)
Return a unique name, derived from the input name, and add the new name to the internal namespace.
Definition Namespace.h:87
This graph tracks modules and where they are instantiated.
This is a Node in the InstanceGraph.
auto getModule()
Get the module that this node is tracking.
hw::InnerRefAttr getInnerRefTo(const hw::InnerSymTarget &target, GetNamespaceCallback getNamespace)
Obtain an inner reference to the target (operation or port), adding an inner symbol as necessary.
IntegerAttr getIntZerosAttr(Type type)
Utility for generating a constant zero attribute.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
static ResultTy transformReduce(MLIRContext *context, IterTy begin, IterTy end, ResultTy init, ReduceFuncTy reduce, TransformFuncTy transform)
Wrapper for llvm::parallelTransformReduce that performs the transform_reduce serially when MLIR multi...
Definition Utils.h:40
bool isAncestorOfValueOwner(Operation *op, Value value)
Return true if a Value is created "underneath" an operation.
Definition Utils.h:27
The namespace of a CircuitOp, generally inhabited by modules.
Definition Namespace.h:24