13 #include "../PassDetails.h"
20 #include "mlir/IR/BuiltinTypes.h"
21 #include "mlir/Interfaces/ControlFlowInterfaces.h"
22 #include "mlir/Pass/Pass.h"
23 #include "mlir/Transforms/DialectConversion.h"
27 #define GEN_PASS_DEF_LOWERESITYPES
28 #include "circt/Dialect/ESI/ESIPasses.h.inc"
32 using namespace circt;
37 struct ESILowerTypesPass
38 :
public circt::esi::impl::LowerESITypesBase<ESILowerTypesPass> {
39 void runOnOperation()
override;
45 class LowerTypesConverter :
public TypeConverter {
47 LowerTypesConverter() {
48 addConversion([](Type t) {
return t; });
49 addConversion([](WindowType window) {
return window.getLoweredType(); });
50 addSourceMaterialization(wrapMaterialization);
51 addArgumentMaterialization(wrapMaterialization);
52 addTargetMaterialization(unwrapMaterialization);
56 static std::optional<mlir::Value> wrapMaterialization(OpBuilder &b,
57 WindowType resultType,
60 if (inputs.size() != 1)
62 auto wrap = b.create<WrapWindow>(loc, resultType, inputs[0]);
63 return wrap.getWindow();
66 static std::optional<mlir::Value>
67 unwrapMaterialization(OpBuilder &b, hw::UnionType resultType,
68 ValueRange inputs, Location loc) {
69 if (inputs.size() != 1 || !isa<WindowType>(inputs[0].getType()))
71 auto unwrap = b.create<UnwrapWindow>(loc, resultType, inputs[0]);
77 void ESILowerTypesPass::runOnOperation() {
78 ConversionTarget target(getContext());
81 target.markUnknownOpDynamicallyLegal([](Operation *op) {
82 return TypeSwitch<Operation *, bool>(op)
83 .Case([](igraph::InstanceOpInterface inst) {
85 llvm::any_of(inst->getOperandTypes(), hw::type_isa<WindowType>) ||
86 llvm::any_of(inst->getResultTypes(), hw::type_isa<WindowType>));
88 .Case([](hw::HWMutableModuleLike mod) {
89 auto isWindowPort = [](hw::PortInfo p) {
90 return hw::type_isa<WindowType>(p.type);
92 return !(llvm::any_of(mod.getPortList(), isWindowPort));
94 .Default([](Operation *op) {
95 if (op->hasTrait<OpTrait::ReturnLike>())
96 return !llvm::any_of(op->getOperandTypes(),
97 hw::type_isa<WindowType>);
102 LowerTypesConverter types;
103 RewritePatternSet
patterns(&getContext());
106 applyPartialConversion(getOperation(), target, std::move(
patterns))))
110 std::unique_ptr<OperationPass<ModuleOp>>
112 return std::make_unique<ESILowerTypesPass>();
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
std::unique_ptr< OperationPass< ModuleOp > > createESITypeLoweringPass()
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Generic pattern which replaces an operation by one of the same operation name, but with converted att...