18 #include "mlir/IR/Threading.h"
19 #include "mlir/Pass/Pass.h"
23 #define GEN_PASS_DEF_DROPCONST
24 #include "circt/Dialect/FIRRTL/Passes.h.inc"
28 using namespace circt;
29 using namespace firrtl;
39 if (
auto base = type_dyn_cast<FIRRTLBaseType>(type)) {
43 if (
auto refType = type_dyn_cast<RefType>(type)) {
44 if (
auto converted =
convertType(refType.getType()))
53 class DropConstPass :
public circt::firrtl::impl::DropConstBase<DropConstPass> {
54 void runOnOperation()
override {
57 auto moduleLikes = getOperation().getOps<FModuleLike>();
58 for (
auto mod : moduleLikes) {
60 SmallVector<Attribute> portTypes;
61 portTypes.reserve(mod.getNumPorts());
62 bool convertedAny =
false;
63 llvm::transform(mod.getPortTypes(), std::back_inserter(portTypes),
64 [&](Attribute type) -> Attribute {
65 if (auto convertedType =
66 convertType(cast<TypeAttr>(type).getValue())) {
68 return TypeAttr::get(convertedType);
78 mlir::parallelForEach(
80 llvm::make_filter_range(moduleLikes, llvm::IsaPred<FModuleOp>),
83 module->walk([](Operation *op) {
84 if (
auto constCastOp = dyn_cast<ConstCastOp>(op)) {
86 constCastOp.getResult().replaceAllUsesWith(
87 constCastOp.getInput());
93 for (
auto ®ion : op->getRegions())
94 for (
auto &block : region.getBlocks())
95 for (
auto argument : block.getArguments())
96 if (
auto convertedType =
convertType(argument.getType()))
97 argument.setType(convertedType);
99 for (
auto result : op->getResults())
100 if (
auto convertedType =
convertType(result.getType()))
101 result.setType(convertedType);
105 markAnalysesPreserved<InstanceGraph>();
111 return std::make_unique<DropConstPass>();
static FIRRTLBaseType convertType(FIRRTLBaseType type)
Returns null type if no conversion is needed.
FIRRTLBaseType getAllConstDroppedType()
Return this type with a 'const' modifiers dropped.
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
std::unique_ptr< mlir::Pass > createDropConstPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.