[FIRRTL] Add DropNamesPass (#3254)

This commit adds a pass `DropNamesPass` to change names to droppable
in order to disable name preservation. The pass walks `FNamableOp` and 
drop their names. This pass should be executed in the very early pipeline 
so that other passes can get more freedom about their names.
This commit is contained in:
Hideto Ueno 2022-06-09 19:02:54 +09:00 committed by GitHub
parent ed4ffb0920
commit b1d0aacb8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 0 deletions

View File

@ -96,6 +96,8 @@ createMergeConnectionsPass(bool enableAggressiveMerging = false);
std::unique_ptr<mlir::Pass> createInjectDUTHierarchyPass();
std::unique_ptr<mlir::Pass> createDropNamesPass();
std::unique_ptr<mlir::Pass> createExtractInstancesPass();
/// Generate the code for registering passes.

View File

@ -466,4 +466,21 @@ def MemToRegOfVec : Pass<"firrtl-mem-to-reg-of-vec", "firrtl::CircuitOp"> {
let constructor = "circt::firrtl::createMemToRegOfVecPass()";
}
def DropName : Pass<"firrtl-drop-names", "firrtl::FModuleOp"> {
let summary = "Drop interesting names";
let description = [{
This pass changes names of namable ops to droppable so that
we can disable full name preservation. For example,
before:
```mlir
%a = firrtl.node interesting_name %input
```
after:
```mlir
%a = firrtl.node droppable_name %input
```
}];
let constructor = "circt::firrtl::createDropNamesPass()";
}
#endif // CIRCT_DIALECT_FIRRTL_PASSES_TD

View File

@ -4,6 +4,7 @@ add_circt_dialect_library(CIRCTFIRRTLTransforms
CheckCombCycles.cpp
CreateSiFiveMetadata.cpp
Dedup.cpp
DropName.cpp
EmitOMIR.cpp
ExpandWhens.cpp
ExtractInstances.cpp

View File

@ -0,0 +1,34 @@
//===- DropName.cpp - Drop Names -----------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines the DropName pass.
//
//===----------------------------------------------------------------------===//
#include "PassDetails.h"
#include "circt/Dialect/FIRRTL/FIRRTLOps.h"
#include "circt/Dialect/FIRRTL/Passes.h"
using namespace circt;
using namespace firrtl;
namespace {
struct DropNamesPass : public DropNameBase<DropNamesPass> {
void runOnOperation() override {
getOperation()->walk([](FNamableOp op) {
if (!op.hasDroppableName())
op.dropName();
});
}
};
} // end anonymous namespace
std::unique_ptr<mlir::Pass> circt::firrtl::createDropNamesPass() {
return std::make_unique<DropNamesPass>();
}

View File

@ -0,0 +1,9 @@
// RUN: circt-opt --pass-pipeline='firrtl.circuit(firrtl.module(firrtl-drop-names))' %s | FileCheck %s
firrtl.circuit "Foo" {
// CHECK: firrtl.module @Foo
firrtl.module @Foo() {
// CHECK-NEXT: %a = firrtl.wire droppable_name : !firrtl.uint<1>
%a = firrtl.wire : !firrtl.uint<1>
}
}

View File

@ -329,6 +329,11 @@ static cl::opt<bool> stripDebugInfo(
cl::desc("Disable source locator information in output Verilog"),
cl::init(false), cl::cat(mainCategory));
static cl::opt<bool> dropName(
"drop-names",
cl::desc("Disable full name preservation by dropping interesting names"),
cl::init(false), cl::cat(mainCategory));
/// Create a simple canonicalizer pass.
static std::unique_ptr<Pass> createSimpleCanonicalizerPass() {
mlir::GreedyRewriteConfig config;
@ -456,6 +461,11 @@ processBuffer(MLIRContext &context, TimingScope &ts, llvm::SourceMgr &sourceMgr,
pm.nest<firrtl::CircuitOp>().addPass(firrtl::createLowerFIRRTLAnnotationsPass(
disableAnnotationsUnknown, disableAnnotationsClassless));
// TODO: Move this to the O1 pipeline.
if (dropName)
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
firrtl::createDropNamesPass());
if (!disableOptimization)
pm.nest<firrtl::CircuitOp>().nest<firrtl::FModuleOp>().addPass(
createCSEPass());