17 #include "mlir/Pass/Pass.h"
21 #define GEN_PASS_DEF_DROPNAME
22 #include "circt/Dialect/FIRRTL/Passes.h.inc"
26 using namespace circt;
27 using namespace firrtl;
30 struct DropNamesPass :
public circt::firrtl::impl::DropNameBase<DropNamesPass> {
32 this->preserveMode = preserveMode;
35 enum ModAction {
Drop, Keep, Demote };
37 void runOnOperation()
override {
38 size_t namesDropped = 0;
39 size_t namesChanged = 0;
42 dropNamesIf(namesChanged, namesDropped, [](FNamableOp op) {
44 return ModAction::Drop;
45 return ModAction::Demote;
49 dropNamesIf(namesChanged, namesDropped,
50 [](FNamableOp op) {
return ModAction::Drop; });
53 dropNamesIf(namesChanged, namesDropped, [](FNamableOp op) {
54 auto name = op.getName();
56 return ModAction::Drop;
57 if (name.starts_with(
"_"))
58 return ModAction::Demote;
59 return ModAction::Keep;
63 dropNamesIf(namesChanged, namesDropped, [](FNamableOp op) {
65 return ModAction::Demote;
66 return ModAction::Keep;
69 numNamesConverted += namesChanged;
70 numNamesDropped += namesDropped;
74 size_t dropNamesIf(
size_t &namesChanged,
size_t &namesDropped,
75 llvm::function_ref<ModAction(FNamableOp)> pred) {
76 size_t changedNames = 0;
78 auto droppableNameAttr =
80 getOperation()->walk([&](FNamableOp op) {
83 op.setNameAttr(emptyNameAttr);
84 op.setNameKindAttr(droppableNameAttr);
87 case ModAction::Demote:
88 op.setNameKindAttr(droppableNameAttr);
101 std::unique_ptr<mlir::Pass>
103 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)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
bool isUselessName(StringRef name)
Return true if this is a possibly useless temporary name.