18 using namespace circt;
19 using namespace firrtl;
22 struct DropNamesPass :
public DropNameBase<DropNamesPass> {
27 enum ModAction {
Drop, Keep, Demote };
29 void runOnOperation()
override {
30 size_t namesDropped = 0;
31 size_t namesChanged = 0;
34 dropNamesIf(namesChanged, namesDropped, [](FNamableOp op) {
36 return ModAction::Drop;
37 return ModAction::Demote;
41 dropNamesIf(namesChanged, namesDropped,
42 [](FNamableOp op) {
return ModAction::Drop; });
45 dropNamesIf(namesChanged, namesDropped, [](FNamableOp op) {
47 return ModAction::Drop;
48 if (op.getName().starts_with(
"_"))
49 return ModAction::Demote;
50 return ModAction::Keep;
54 dropNamesIf(namesChanged, namesDropped, [](FNamableOp op) {
56 return ModAction::Demote;
57 return ModAction::Keep;
60 numNamesConverted += namesChanged;
61 numNamesDropped += namesDropped;
65 size_t dropNamesIf(
size_t &namesChanged,
size_t &namesDropped,
66 llvm::function_ref<ModAction(FNamableOp)> pred) {
67 size_t changedNames = 0;
68 auto droppableNameAttr =
70 getOperation()->walk([&](FNamableOp op) {
76 case ModAction::Demote:
77 op.setNameKindAttr(droppableNameAttr);
90 std::unique_ptr<mlir::Pass>
92 return std::make_unique<DropNamesPass>(mode);
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
@ None
Don't explicitly preserve any named values.
@ Strip
Strip all names. No name on declaration is preserved.
std::unique_ptr< mlir::Pass > createDropNamesPass(PreserveValues::PreserveMode mode=PreserveValues::None)
bool isUselessName(circt::StringRef name)
Return true if this is a useless temporary name produced by FIRRTL.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...