@@ -313,112 +313,6 @@ void getAsmBlockArgumentNamesImpl(Operation *op, mlir::Region ®ion,
313313static ParseResult parseNameKind (OpAsmParser &parser,
314314 firrtl::NameKindEnumAttr &result);
315315
316- // ===----------------------------------------------------------------------===//
317- // Layer Verification Utilities
318- // ===----------------------------------------------------------------------===//
319-
320- // / Get the ambient layers active at the given op.
321- static LayerSet getAmbientLayersAt (Operation *op) {
322- // Crawl through the parent ops, accumulating all ambient layers at the given
323- // operation.
324- LayerSet result;
325- for (; op != nullptr ; op = op->getParentOp ()) {
326- if (auto module = dyn_cast<FModuleLike>(op)) {
327- auto layers = module .getLayersAttr ().getAsRange <SymbolRefAttr>();
328- result.insert (layers.begin (), layers.end ());
329- break ;
330- }
331- if (auto layerblock = dyn_cast<LayerBlockOp>(op)) {
332- result.insert (layerblock.getLayerName ());
333- continue ;
334- }
335- }
336- return result;
337- }
338-
339- // / Get the ambient layer requirements at the definition site of the value.
340- static LayerSet getAmbientLayersFor (Value value) {
341- return getAmbientLayersAt (getFieldRefFromValue (value).getDefiningOp ());
342- }
343-
344- // / Get the effective layer requirements for the given value.
345- // / The effective layers for a value is the union of
346- // / - the ambient layers for the cannonical storage location.
347- // / - any explicit layer annotations in the value's type.
348- static LayerSet getLayersFor (Value value) {
349- auto result = getAmbientLayersFor (value);
350- if (auto type = dyn_cast<RefType>(value.getType ()))
351- if (auto layer = type.getLayer ())
352- result.insert (type.getLayer ());
353- return result;
354- }
355-
356- // / Check that the source layer is compatible with the destination layer.
357- // / Either the source and destination are identical, or the source-layer
358- // / is a parent of the destination. For example `A` is compatible with `A.B.C`,
359- // / because any definition valid in `A` is also valid in `A.B.C`.
360- static bool isLayerCompatibleWith (mlir::SymbolRefAttr srcLayer,
361- mlir::SymbolRefAttr dstLayer) {
362- // A non-colored probe may be cast to any colored probe.
363- if (!srcLayer)
364- return true ;
365-
366- // A colored probe cannot be cast to an uncolored probe.
367- if (!dstLayer)
368- return false ;
369-
370- // Return true if the srcLayer is a prefix of the dstLayer.
371- if (srcLayer.getRootReference () != dstLayer.getRootReference ())
372- return false ;
373-
374- auto srcNames = srcLayer.getNestedReferences ();
375- auto dstNames = dstLayer.getNestedReferences ();
376- if (dstNames.size () < srcNames.size ())
377- return false ;
378-
379- return llvm::all_of (llvm::zip_first (srcNames, dstNames),
380- [](auto x) { return std::get<0 >(x) == std::get<1 >(x); });
381- }
382-
383- // / Check that the source layer is present in the destination layers.
384- static bool isLayerCompatibleWith (SymbolRefAttr srcLayer,
385- const LayerSet &dstLayers) {
386- // fast path: the required layer is directly listed in the provided layers.
387- if (dstLayers.contains (srcLayer))
388- return true ;
389-
390- // Slow path: the required layer is not directly listed in the provided
391- // layers, but the layer may still be provided by a nested layer.
392- return any_of (dstLayers, [=](SymbolRefAttr dstLayer) {
393- return isLayerCompatibleWith (srcLayer, dstLayer);
394- });
395- }
396-
397- // / Check that the source layers are all present in the destination layers.
398- // / True if all source layers are present in the destination.
399- // / Outputs the set of source layers that are missing in the destination.
400- static bool isLayerSetCompatibleWith (const LayerSet &src, const LayerSet &dst,
401- SmallVectorImpl<SymbolRefAttr> &missing) {
402- for (auto srcLayer : src)
403- if (!isLayerCompatibleWith (srcLayer, dst))
404- missing.push_back (srcLayer);
405-
406- llvm::sort (missing, LayerSetCompare ());
407- return missing.empty ();
408- }
409-
410- static LogicalResult checkLayerCompatibility (
411- Operation *op, const LayerSet &src, const LayerSet &dst,
412- const Twine &errorMsg,
413- const Twine ¬eMsg = Twine(" missing layer requirements" )) {
414- SmallVector<SymbolRefAttr> missing;
415- if (isLayerSetCompatibleWith (src, dst, missing))
416- return success ();
417- interleaveComma (missing, op->emitOpError (errorMsg).attachNote ()
418- << noteMsg << " : " );
419- return failure ();
420- }
421-
422316// ===----------------------------------------------------------------------===//
423317// CircuitOp
424318// ===----------------------------------------------------------------------===//
0 commit comments