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"
25 using namespace circt;
30 struct ESILowerTypesPass :
public LowerESITypesBase<ESILowerTypesPass> {
31 void runOnOperation()
override;
37 class LowerTypesConverter :
public TypeConverter {
39 LowerTypesConverter() {
40 addConversion([](Type t) {
return t; });
41 addConversion([](WindowType window) {
return window.getLoweredType(); });
42 addSourceMaterialization(wrapMaterialization);
43 addArgumentMaterialization(wrapMaterialization);
44 addTargetMaterialization(unwrapMaterialization);
48 static std::optional<mlir::Value> wrapMaterialization(OpBuilder &b,
49 WindowType resultType,
54 auto wrap = b.create<WrapWindow>(loc, resultType,
inputs[0]);
55 return wrap.getWindow();
58 static std::optional<mlir::Value>
59 unwrapMaterialization(OpBuilder &b, hw::UnionType resultType,
60 ValueRange
inputs, Location loc) {
61 if (
inputs.size() != 1 || !isa<WindowType>(
inputs[0].getType()))
63 auto unwrap = b.create<UnwrapWindow>(loc, resultType,
inputs[0]);
69 void ESILowerTypesPass::runOnOperation() {
70 ConversionTarget target(getContext());
73 target.markUnknownOpDynamicallyLegal([](Operation *op) {
74 return TypeSwitch<Operation *, bool>(op)
75 .Case([](igraph::InstanceOpInterface inst) {
77 llvm::any_of(inst->getOperandTypes(), hw::type_isa<WindowType>) ||
78 llvm::any_of(inst->getResultTypes(), hw::type_isa<WindowType>));
80 .Case([](hw::HWMutableModuleLike mod) {
81 auto isWindowPort = [](hw::PortInfo p) {
82 return hw::type_isa<WindowType>(p.type);
84 return !(llvm::any_of(mod.getPortList(), isWindowPort));
86 .Default([](Operation *op) {
87 if (op->hasTrait<OpTrait::ReturnLike>())
88 return !llvm::any_of(op->getOperandTypes(),
89 hw::type_isa<WindowType>);
94 LowerTypesConverter types;
95 RewritePatternSet
patterns(&getContext());
98 applyPartialConversion(getOperation(), target, std::move(
patterns))))
102 std::unique_ptr<OperationPass<ModuleOp>>
104 return std::make_unique<ESILowerTypesPass>();
return wrap(CMemoryType::get(unwrap(ctx), baseType, numElements))
static EvaluatorValuePtr unwrap(OMEvaluatorValue c)
llvm::SmallVector< StringAttr > inputs
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...