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"
37struct ESILowerTypesPass
38 :
public circt::esi::impl::LowerESITypesBase<ESILowerTypesPass> {
39 void runOnOperation()
override;
45class LowerTypesConverter :
public TypeConverter {
47 LowerTypesConverter() {
48 addConversion([](Type t) {
return t; });
49 addConversion([](WindowType window) {
return window.getLoweredType(); });
50 addSourceMaterialization(wrapMaterialization);
51 addTargetMaterialization(unwrapMaterialization);
55 static mlir::Value wrapMaterialization(OpBuilder &b, WindowType resultType,
56 ValueRange inputs, Location loc) {
57 if (inputs.size() != 1)
59 auto wrap = b.create<WrapWindow>(loc, resultType, inputs[0]);
60 return wrap.getWindow();
63 static mlir::Value unwrapMaterialization(OpBuilder &b,
64 hw::UnionType resultType,
65 ValueRange inputs, Location loc) {
66 if (inputs.size() != 1 || !isa<WindowType>(inputs[0].getType()))
68 auto unwrap = b.create<UnwrapWindow>(loc, resultType, inputs[0]);
74void ESILowerTypesPass::runOnOperation() {
75 ConversionTarget target(getContext());
78 target.markUnknownOpDynamicallyLegal([](Operation *op) {
79 return TypeSwitch<Operation *, bool>(op)
80 .Case([](igraph::InstanceOpInterface inst) {
82 llvm::any_of(inst->getOperandTypes(), hw::type_isa<WindowType>) ||
83 llvm::any_of(inst->getResultTypes(), hw::type_isa<WindowType>));
85 .Case([](hw::HWMutableModuleLike mod) {
87 return hw::type_isa<WindowType>(p.type);
89 return !(llvm::any_of(mod.getPortList(), isWindowPort));
91 .Default([](Operation *op) {
92 if (op->hasTrait<OpTrait::ReturnLike>())
93 return !llvm::any_of(op->getOperandTypes(),
94 hw::type_isa<WindowType>);
99 LowerTypesConverter types;
100 RewritePatternSet
patterns(&getContext());
103 applyPartialConversion(getOperation(), target, std::move(
patterns))))
107std::unique_ptr<OperationPass<ModuleOp>>
109 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...
This holds the name, type, direction of a module's ports.