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"
44 if (
auto converted =
convertType(refType.getType()))
45 return RefType::get(converted, refType.getForceable(),
53class 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);
73 mod.setPortTypesAttr(ArrayAttr::get(mod.getContext(), portTypes));
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())
97 argument.setType(convertedType);
99 for (
auto result : op->getResults())
101 result.setType(convertedType);
105 markAnalysesPreserved<InstanceGraph>();
static FIRRTLBaseType convertType(FIRRTLBaseType type)
Returns null type if no conversion is needed.
if(parseOptionalKeywordOrOptionalString(parser, result.rawName, found)) return failure()
FIRRTLBaseType getAllConstDroppedType()
Return this type with a 'const' modifiers dropped.
BaseTy type_dyn_cast(Type type)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.