@@ -773,7 +773,8 @@ struct GrandCentralPass
773
773
DenseMap<Attribute, sv::InterfaceOp> interfaceMap;
774
774
775
775
// / Emit the hierarchy yaml file.
776
- void emitHierarchyYamlFile (SmallVectorImpl<sv::InterfaceOp> &intfs);
776
+ void emitHierarchyYamlFile (StringRef yamlPath,
777
+ SmallVectorImpl<sv::InterfaceOp> &intfs);
777
778
};
778
779
779
780
} // namespace
@@ -1915,6 +1916,12 @@ void GrandCentralPass::runOnOperation() {
1915
1916
llvm::dbgs () << " \n " ;
1916
1917
});
1917
1918
1919
+ // per-YAML output list of interfaces.
1920
+ llvm::SmallMapVector<StringAttr, SmallVector<sv::InterfaceOp, 0 >, 1 >
1921
+ interfaceYAMLMap;
1922
+ if (maybeHierarchyFileYAML.has_value ())
1923
+ interfaceYAMLMap[maybeHierarchyFileYAML.value ()] = {};
1924
+
1918
1925
// Scan entire design for View operations.
1919
1926
SmallVector<ViewIntrinsicOp> views;
1920
1927
circuitOp.walk ([&views](ViewIntrinsicOp view) { views.push_back (view); });
@@ -1923,8 +1930,8 @@ void GrandCentralPass::runOnOperation() {
1923
1930
// built exist. However, still generate the YAML file if the annotation for
1924
1931
// this was passed in because some flows expect this.
1925
1932
if (worklist.empty () && views.empty ()) {
1926
- SmallVector<sv::InterfaceOp, 0 > interfaceVec;
1927
- emitHierarchyYamlFile (interfaceVec );
1933
+ for ( auto &[yamlPath, intfs] : interfaceYAMLMap)
1934
+ emitHierarchyYamlFile (yamlPath. getValue (), intfs );
1928
1935
return markAllAnalysesPreserved ();
1929
1936
}
1930
1937
@@ -2254,8 +2261,8 @@ void GrandCentralPass::runOnOperation() {
2254
2261
mod->erase ();
2255
2262
}
2256
2263
2257
- SmallVector<sv::InterfaceOp, 0 > interfaceVec;
2258
- emitHierarchyYamlFile (interfaceVec );
2264
+ for ( auto &[yamlPath, intfs] : interfaceYAMLMap)
2265
+ emitHierarchyYamlFile (yamlPath. getValue (), intfs );
2259
2266
return ;
2260
2267
}
2261
2268
@@ -2311,7 +2318,6 @@ void GrandCentralPass::runOnOperation() {
2311
2318
// will use XMRs to drive the interface. If extraction info is available,
2312
2319
// then the top-level instantiate interface will be marked for extraction via
2313
2320
// a SystemVerilog bind.
2314
- SmallVector<sv::InterfaceOp, 2 > interfaceVec;
2315
2321
SmallDenseMap<FModuleLike, SmallVector<InterfaceElemsBuilder>>
2316
2322
companionToInterfaceMap;
2317
2323
auto compareInterfaceSignal = [&](InterfaceElemsBuilder &lhs,
@@ -2481,7 +2487,8 @@ void GrandCentralPass::runOnOperation() {
2481
2487
2482
2488
++numViews;
2483
2489
2484
- interfaceVec.push_back (topIface);
2490
+ if (maybeHierarchyFileYAML.has_value ())
2491
+ interfaceYAMLMap[maybeHierarchyFileYAML.value ()].push_back (topIface);
2485
2492
2486
2493
// Instantiate the interface inside the companion.
2487
2494
builder.setInsertionPointToStart (companionModule.getBodyBlock ());
@@ -2567,6 +2574,7 @@ void GrandCentralPass::runOnOperation() {
2567
2574
sv::InterfaceOp topIface;
2568
2575
auto containingOutputFileAttr =
2569
2576
viewParentMod->getAttrOfType <hw::OutputFileAttr>(" output_file" );
2577
+ auto yamlPath = view.getYamlFileAttr ();
2570
2578
for (const auto &ifaceBuilder : interfaceBuilder) {
2571
2579
auto builder = OpBuilder::atBlockEnd (getOperation ().getBodyBlock ());
2572
2580
auto loc = getOperation ().getLoc ();
@@ -2599,7 +2607,7 @@ void GrandCentralPass::runOnOperation() {
2599
2607
// If we need to generate a YAML representation of this interface,
2600
2608
// then add an attribute indicating that this `sv::VerbatimOp` is
2601
2609
// actually a description.
2602
- if (maybeHierarchyFileYAML )
2610
+ if (yamlPath )
2603
2611
descriptionOp->setAttr (" firrtl.grandcentral.yaml.type" ,
2604
2612
builder.getStringAttr (" description" ));
2605
2613
}
@@ -2609,7 +2617,7 @@ void GrandCentralPass::runOnOperation() {
2609
2617
2610
2618
// If we need to generate a YAML representation of the interface, then
2611
2619
// add attributes that describe what this `sv::VerbatimOp` is.
2612
- if (maybeHierarchyFileYAML ) {
2620
+ if (yamlPath ) {
2613
2621
if (str->instantiation )
2614
2622
instanceOp->setAttr (" firrtl.grandcentral.yaml.type" ,
2615
2623
builder.getStringAttr (" instance" ));
@@ -2634,7 +2642,8 @@ void GrandCentralPass::runOnOperation() {
2634
2642
2635
2643
++numViews;
2636
2644
2637
- interfaceVec.push_back (topIface);
2645
+ if (yamlPath)
2646
+ interfaceYAMLMap[yamlPath].push_back (topIface);
2638
2647
2639
2648
// Instantiate the interface before the view and the XMR's we inserted
2640
2649
// above.
@@ -2646,7 +2655,8 @@ void GrandCentralPass::runOnOperation() {
2646
2655
view.erase ();
2647
2656
}
2648
2657
2649
- emitHierarchyYamlFile (interfaceVec);
2658
+ for (auto &[yamlPath, intfs] : interfaceYAMLMap)
2659
+ emitHierarchyYamlFile (yamlPath.getValue (), intfs);
2650
2660
2651
2661
// Signal pass failure if any errors were found while examining circuit
2652
2662
// annotations.
@@ -2656,13 +2666,7 @@ void GrandCentralPass::runOnOperation() {
2656
2666
}
2657
2667
2658
2668
void GrandCentralPass::emitHierarchyYamlFile (
2659
- SmallVectorImpl<sv::InterfaceOp> &intfs) {
2660
- // If a `GrandCentralHierarchyFileAnnotation` was passed in, generate a YAML
2661
- // representation of the interfaces that we produced with the filename that
2662
- // that annotation provided.
2663
- if (!maybeHierarchyFileYAML)
2664
- return ;
2665
-
2669
+ StringRef yamlPath, SmallVectorImpl<sv::InterfaceOp> &intfs) {
2666
2670
CircuitOp circuitOp = getOperation ();
2667
2671
2668
2672
std::string yamlString;
@@ -2673,10 +2677,9 @@ void GrandCentralPass::emitHierarchyYamlFile(
2673
2677
2674
2678
auto builder = OpBuilder::atBlockBegin (circuitOp.getBodyBlock ());
2675
2679
builder.create <sv::VerbatimOp>(builder.getUnknownLoc (), yamlString)
2676
- ->setAttr (" output_file" ,
2677
- hw::OutputFileAttr::getFromFilename (
2678
- &getContext (), maybeHierarchyFileYAML->getValue (),
2679
- /* excludeFromFileList=*/ true ));
2680
+ ->setAttr (" output_file" , hw::OutputFileAttr::getFromFilename (
2681
+ &getContext (), yamlPath,
2682
+ /* excludeFromFileList=*/ true ));
2680
2683
LLVM_DEBUG ({ llvm::dbgs () << " Generated YAML:" << yamlString << " \n " ; });
2681
2684
}
2682
2685
0 commit comments