13 #ifndef CIRCT_DIALECT_FIRRTL_FIRRTLVISITORS_H
14 #define CIRCT_DIALECT_FIRRTL_FIRRTLVISITORS_H
17 #include "mlir/IR/BuiltinOps.h"
18 #include "llvm/ADT/TypeSwitch.h"
24 template <
typename ConcreteType,
typename ResultType = void,
25 typename... ExtraArgs>
29 auto *thisCast =
static_cast<ConcreteType *
>(
this);
30 return TypeSwitch<Operation *, ResultType>(op)
33 ConstantOp, SpecialConstantOp, AggregateConstantOp, InvalidValueOp,
34 SubfieldOp, SubindexOp, SubaccessOp, IsTagOp, SubtagOp,
35 BundleCreateOp, VectorCreateOp, FEnumCreateOp, MultibitMuxOp,
36 TagExtractOp, OpenSubfieldOp, OpenSubindexOp, ObjectSubfieldOp,
38 AddPrimOp, SubPrimOp, MulPrimOp, DivPrimOp, RemPrimOp, AndPrimOp,
41 ElementwiseOrPrimOp, ElementwiseAndPrimOp, ElementwiseXorPrimOp,
43 LEQPrimOp, LTPrimOp, GEQPrimOp, GTPrimOp, EQPrimOp, NEQPrimOp,
45 CatPrimOp, DShlPrimOp, DShlwPrimOp, DShrPrimOp,
47 AsSIntPrimOp, AsUIntPrimOp, AsAsyncResetPrimOp, AsClockPrimOp,
48 CvtPrimOp, NegPrimOp, NotPrimOp, AndRPrimOp, OrRPrimOp, XorRPrimOp,
50 IsXIntrinsicOp, PlusArgsValueIntrinsicOp, PlusArgsTestIntrinsicOp,
51 SizeOfIntrinsicOp, ClockGateIntrinsicOp, ClockInverterIntrinsicOp,
52 ClockDividerIntrinsicOp, LTLAndIntrinsicOp, LTLOrIntrinsicOp,
53 LTLDelayIntrinsicOp, LTLConcatIntrinsicOp, LTLNotIntrinsicOp,
54 LTLImplicationIntrinsicOp, LTLEventuallyIntrinsicOp,
55 LTLClockIntrinsicOp, LTLDisableIntrinsicOp, Mux2CellIntrinsicOp,
56 Mux4CellIntrinsicOp, HasBeenResetIntrinsicOp,
58 BitsPrimOp, HeadPrimOp, MuxPrimOp, PadPrimOp, ShlPrimOp, ShrPrimOp,
59 TailPrimOp, VerbatimExprOp, HWStructCastOp, BitCastOp, RefSendOp,
60 RefResolveOp, RefSubOp, RWProbeOp, XMRRefOp, XMRDerefOp,
62 UninferredResetCastOp, ConstCastOp, RefCastOp,
64 StringConstantOp, FIntegerConstantOp, BoolConstantOp,
65 DoubleConstantOp, ListCreateOp, UnresolvedPathOp, PathOp>(
66 [&](
auto expr) -> ResultType {
67 return thisCast->visitExpr(expr, args...);
69 .Default([&](
auto expr) -> ResultType {
70 return thisCast->visitInvalidExpr(op, args...);
76 op->emitOpError(
"unknown FIRRTL expression");
98 #define HANDLE(OPTYPE, OPKIND) \
99 ResultType visitExpr(OPTYPE op, ExtraArgs... args) { \
100 return static_cast<ConcreteType *>(this)->visit##OPKIND##Expr(op, \
164 HANDLE(PlusArgsValueIntrinsicOp, Unhandled);
165 HANDLE(PlusArgsTestIntrinsicOp, Unhandled);
168 HANDLE(ClockInverterIntrinsicOp, Unhandled);
169 HANDLE(ClockDividerIntrinsicOp, Unhandled);
175 HANDLE(LTLImplicationIntrinsicOp, Unhandled);
176 HANDLE(LTLEventuallyIntrinsicOp, Unhandled);
178 HANDLE(LTLDisableIntrinsicOp, Unhandled);
181 HANDLE(HasBeenResetIntrinsicOp, Unhandled);
202 HANDLE(UninferredResetCastOp, Unhandled);
219 template <
typename ConcreteType,
typename ResultType = void,
220 typename... ExtraArgs>
224 auto *thisCast =
static_cast<ConcreteType *
>(
this);
225 return TypeSwitch<Operation *, ResultType>(op)
226 .template Case<AttachOp, ConnectOp, StrictConnectOp, RefDefineOp,
227 ForceOp, PrintFOp, SkipOp, StopOp, WhenOp, AssertOp,
228 AssumeOp, CoverOp, PropAssignOp, RefForceOp,
229 RefForceInitialOp, RefReleaseOp, RefReleaseInitialOp,
230 FPGAProbeIntrinsicOp, VerifAssertIntrinsicOp,
231 VerifAssumeIntrinsicOp, UnclockedAssumeIntrinsicOp,
232 VerifCoverIntrinsicOp, LayerBlockOp>(
233 [&](
auto opNode) -> ResultType {
234 return thisCast->visitStmt(opNode, args...);
236 .Default([&](
auto expr) -> ResultType {
237 return thisCast->visitInvalidStmt(op, args...);
243 op->emitOpError(
"unknown firrtl stmt");
253 #define HANDLE(OPTYPE) \
254 ResultType visitStmt(OPTYPE op, ExtraArgs... args) { \
255 return static_cast<ConcreteType *>(this)->visitUnhandledStmt(op, args...); \
286 template <
typename ConcreteType,
typename ResultType = void,
287 typename... ExtraArgs>
291 auto *thisCast =
static_cast<ConcreteType *
>(
this);
292 return TypeSwitch<Operation *, ResultType>(op)
293 .template Case<InstanceOp, ObjectOp, MemOp, NodeOp, RegOp, RegResetOp,
294 WireOp, VerbatimWireOp>([&](
auto opNode) -> ResultType {
295 return thisCast->visitDecl(opNode, args...);
297 .Default([&](
auto expr) -> ResultType {
298 return thisCast->visitInvalidDecl(op, args...);
304 op->emitOpError(
"unknown firrtl decl");
314 #define HANDLE(OPTYPE) \
315 ResultType visitDecl(OPTYPE op, ExtraArgs... args) { \
316 return static_cast<ConcreteType *>(this)->visitUnhandledDecl(op, args...); \
337 template <
typename ConcreteType,
typename ResultType = void,
338 typename... ExtraArgs>
340 :
public ExprVisitor<ConcreteType, ResultType, ExtraArgs...>,
341 public StmtVisitor<ConcreteType, ResultType, ExtraArgs...>,
342 public DeclVisitor<ConcreteType, ResultType, ExtraArgs...> {
364 return static_cast<ConcreteType *
>(
this)->
visitInvalidOp(op, args...);
ExprVisitor is a visitor for FIRRTL declaration nodes.
ResultType dispatchDeclVisitor(Operation *op, ExtraArgs... args)
ResultType visitInvalidDecl(Operation *op, ExtraArgs... args)
This callback is invoked on any non-Decl operations.
ResultType visitUnhandledDecl(Operation *op, ExtraArgs... args)
This callback is invoked on any Decl operations that are not handled by the concrete visitor.
ExprVisitor is a visitor for FIRRTL expression nodes.
HANDLE(ListCreateOp, Unhandled)
HANDLE(DoubleConstantOp, Unhandled)
HANDLE(LTLNotIntrinsicOp, Unhandled)
HANDLE(PadPrimOp, Unhandled)
HANDLE(SubPrimOp, Binary)
HANDLE(ElementwiseXorPrimOp, Unhandled)
HANDLE(ClockDividerIntrinsicOp, Unhandled)
HANDLE(AddPrimOp, Binary)
HANDLE(BitsPrimOp, Unhandled)
HANDLE(RWProbeOp, Unhandled)
HANDLE(LTLAndIntrinsicOp, Unhandled)
HANDLE(OpenSubfieldOp, Unhandled)
HANDLE(BoolConstantOp, Unhandled)
HANDLE(AndRPrimOp, Unary)
HANDLE(HeadPrimOp, Unhandled)
HANDLE(ClockInverterIntrinsicOp, Unhandled)
HANDLE(LTLDisableIntrinsicOp, Unhandled)
HANDLE(BitCastOp, Unhandled)
HANDLE(SubindexOp, Unhandled)
HANDLE(HasBeenResetIntrinsicOp, Unhandled)
HANDLE(SubfieldOp, Unhandled)
HANDLE(DShrPrimOp, Binary)
HANDLE(AsUIntPrimOp, Unary)
HANDLE(LTLDelayIntrinsicOp, Unhandled)
HANDLE(RefCastOp, Unhandled)
HANDLE(ElementwiseOrPrimOp, Unhandled)
HANDLE(MultibitMuxOp, Unhandled)
HANDLE(XorRPrimOp, Unary)
HANDLE(ConstCastOp, Unhandled)
HANDLE(Mux4CellIntrinsicOp, Unhandled)
HANDLE(StringConstantOp, Unhandled)
HANDLE(LTLConcatIntrinsicOp, Unhandled)
HANDLE(TagExtractOp, Unhandled)
HANDLE(UninferredResetCastOp, Unhandled)
HANDLE(XorPrimOp, Binary)
HANDLE(MulPrimOp, Binary)
HANDLE(LTLImplicationIntrinsicOp, Unhandled)
ResultType visitInvalidExpr(Operation *op, ExtraArgs... args)
This callback is invoked on any non-expression operations.
ResultType dispatchExprVisitor(Operation *op, ExtraArgs... args)
HANDLE(RefSubOp, Unhandled)
HANDLE(RemPrimOp, Binary)
HANDLE(Mux2CellIntrinsicOp, Unhandled)
HANDLE(MuxPrimOp, Unhandled)
HANDLE(BundleCreateOp, Unhandled)
HANDLE(PlusArgsTestIntrinsicOp, Unhandled)
HANDLE(FEnumCreateOp, Unhandled)
HANDLE(RefSendOp, Unhandled)
HANDLE(XMRDerefOp, Unhandled)
HANDLE(ShrPrimOp, Unhandled)
HANDLE(UnresolvedPathOp, Unhandled)
HANDLE(PlusArgsValueIntrinsicOp, Unhandled)
HANDLE(LTLOrIntrinsicOp, Unhandled)
HANDLE(CatPrimOp, Binary)
HANDLE(FIntegerConstantOp, Unhandled)
HANDLE(HWStructCastOp, Unhandled)
HANDLE(ClockGateIntrinsicOp, Unhandled)
HANDLE(OpenSubindexOp, Unhandled)
HANDLE(ObjectSubfieldOp, Unhandled)
HANDLE(InvalidValueOp, Unhandled)
HANDLE(SubaccessOp, Unhandled)
HANDLE(DShlPrimOp, Binary)
HANDLE(ShlPrimOp, Unhandled)
HANDLE(IsXIntrinsicOp, Unhandled)
HANDLE(RefResolveOp, Unhandled)
HANDLE(XMRRefOp, Unhandled)
HANDLE(TailPrimOp, Unhandled)
HANDLE(LTLClockIntrinsicOp, Unhandled)
HANDLE(GEQPrimOp, Binary)
HANDLE(ElementwiseAndPrimOp, Unhandled)
ResultType visitUnaryExpr(Operation *op, ExtraArgs... args)
This fallback is invoked on any unary expr that isn't explicitly handled.
HANDLE(SizeOfIntrinsicOp, Unhandled)
ResultType visitUnhandledExpr(Operation *op, ExtraArgs... args)
This callback is invoked on any expression operations that are not handled by the concrete visitor.
HANDLE(LEQPrimOp, Binary)
HANDLE(ConstantOp, Unhandled)
HANDLE(AsAsyncResetPrimOp, Unary)
HANDLE(DShlwPrimOp, Binary)
ResultType visitBinaryExpr(Operation *op, ExtraArgs... args)
This fallback is invoked on any binary expr that isn't explicitly handled.
HANDLE(AggregateConstantOp, Unhandled)
HANDLE(AndPrimOp, Binary)
HANDLE(AsClockPrimOp, Unary)
HANDLE(SpecialConstantOp, Unhandled)
HANDLE(VectorCreateOp, Unhandled)
HANDLE(LTLEventuallyIntrinsicOp, Unhandled)
HANDLE(DivPrimOp, Binary)
HANDLE(NEQPrimOp, Binary)
HANDLE(SubtagOp, Unhandled)
HANDLE(VerbatimExprOp, Unhandled)
HANDLE(IsTagOp, Unhandled)
HANDLE(AsSIntPrimOp, Unary)
HANDLE(PathOp, Unhandled)
FIRRTLVisitor allows you to visit all of the expr/stmt/decls with one class declaration.
ResultType dispatchVisitor(Operation *op, ExtraArgs... args)
This is the main entrypoint for the FIRRTLVisitor.
ResultType visitInvalidOp(Operation *op, ExtraArgs... args)
visitInvalidOp is an override point for non-FIRRTL dialect operations.
ResultType visitUnhandledExpr(Operation *op, ExtraArgs... args)
ResultType visitUnhandledOp(Operation *op, ExtraArgs... args)
visitUnhandledOp is an override point for FIRRTL dialect ops that the concrete visitor didn't bother ...
ResultType visitUnhandledStmt(Operation *op, ExtraArgs... args)
ResultType visitUnhandledDecl(Operation *op, ExtraArgs... args)
ResultType visitInvalidDecl(Operation *op, ExtraArgs... args)
ResultType visitIntrinsicOp(GenericIntrinsicOp *op, ExtraArgs... args)
Special handling for generic intrinsic op which aren't quite expressions nor statements in the usual ...
ResultType visitInvalidExpr(Operation *op, ExtraArgs... args)
ResultType visitInvalidStmt(Operation *op, ExtraArgs... args)
ExprVisitor is a visitor for FIRRTL statement nodes.
HANDLE(VerifCoverIntrinsicOp)
HANDLE(RefForceInitialOp)
ResultType dispatchStmtVisitor(Operation *op, ExtraArgs... args)
HANDLE(UnclockedAssumeIntrinsicOp)
HANDLE(VerifAssertIntrinsicOp)
ResultType visitUnhandledStmt(Operation *op, ExtraArgs... args)
This callback is invoked on any Stmt operations that are not handled by the concrete visitor.
HANDLE(RefReleaseInitialOp)
HANDLE(FPGAProbeIntrinsicOp)
ResultType visitInvalidStmt(Operation *op, ExtraArgs... args)
This callback is invoked on any non-Stmt operations.
HANDLE(VerifAssumeIntrinsicOp)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.