19 #include "mlir/IR/Threading.h"
21 using namespace circt;
22 using namespace firrtl;
32 if (
auto base = type_dyn_cast<FIRRTLBaseType>(type)) {
36 if (
auto refType = type_dyn_cast<RefType>(type)) {
37 if (
auto converted =
convertType(refType.getType()))
46 class DropConstPass :
public DropConstBase<DropConstPass> {
47 void runOnOperation()
override {
48 mlir::parallelForEach(
49 &getContext(), getOperation().getOps<firrtl::FModuleLike>(),
52 module->walk([](Operation *op) {
53 if (
auto constCastOp = dyn_cast<ConstCastOp>(op)) {
55 constCastOp.getResult().replaceAllUsesWith(
56 constCastOp.getInput());
62 for (
auto ®ion : op->getRegions())
63 for (
auto &block : region.getBlocks())
64 for (
auto argument : block.getArguments())
65 if (
auto convertedType =
convertType(argument.getType()))
66 argument.setType(convertedType);
68 for (
auto result : op->getResults())
69 if (
auto convertedType =
convertType(result.getType()))
70 result.setType(convertedType);
74 SmallVector<Attribute> portTypes;
75 portTypes.reserve(module.getNumPorts());
76 bool convertedAny =
false;
77 llvm::transform(module.getPortTypes(), std::back_inserter(portTypes),
78 [&](Attribute type) -> Attribute {
79 if (auto convertedType = convertType(
80 cast<TypeAttr>(type).getValue())) {
82 return TypeAttr::get(convertedType);
87 module->setAttr(FModuleLike::getPortTypesAttrName(),
91 markAnalysesPreserved<InstanceGraph>();
97 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.