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()))
45 class DropConstPass :
public DropConstBase<DropConstPass> {
46 void runOnOperation()
override {
47 mlir::parallelForEach(
48 &getContext(), getOperation().getOps<firrtl::FModuleLike>(),
51 module->walk([](Operation *op) {
52 if (
auto constCastOp = dyn_cast<ConstCastOp>(op)) {
54 constCastOp.getResult().replaceAllUsesWith(
55 constCastOp.getInput());
61 for (
auto ®ion : op->getRegions())
62 for (
auto &block : region.getBlocks())
63 for (
auto argument : block.getArguments())
64 if (
auto convertedType =
convertType(argument.getType()))
65 argument.setType(convertedType);
67 for (
auto result : op->getResults())
68 if (
auto convertedType =
convertType(result.getType()))
69 result.setType(convertedType);
73 SmallVector<Attribute> portTypes;
74 portTypes.reserve(module.getNumPorts());
75 bool convertedAny =
false;
76 llvm::transform(module.getPortTypes(), std::back_inserter(portTypes),
77 [&](Attribute type) -> Attribute {
78 if (auto convertedType = convertType(
79 cast<TypeAttr>(type).getValue())) {
81 return TypeAttr::get(convertedType);
86 module->setAttr(FModuleLike::getPortTypesAttrName(),
90 markAnalysesPreserved<InstanceGraph>();
96 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()
This file defines an intermediate representation for circuits acting as an abstraction for constraint...