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"
24template <
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,
37 DomainSubfieldOp, ObjectAnyRefCastOp, DomainAnyRefCastOp,
39 AddPrimOp, SubPrimOp, MulPrimOp, DivPrimOp, RemPrimOp, AndPrimOp,
42 ElementwiseOrPrimOp, ElementwiseAndPrimOp, ElementwiseXorPrimOp,
44 LEQPrimOp, LTPrimOp, GEQPrimOp, GTPrimOp, EQPrimOp, NEQPrimOp,
46 CatPrimOp, DShlPrimOp, DShlwPrimOp, DShrPrimOp,
48 AsSIntPrimOp, AsUIntPrimOp, AsAsyncResetPrimOp, AsResetPrimOp,
49 AsClockPrimOp, CvtPrimOp, NegPrimOp, NotPrimOp, AndRPrimOp,
50 OrRPrimOp, XorRPrimOp,
52 IsXIntrinsicOp, PlusArgsValueIntrinsicOp, PlusArgsTestIntrinsicOp,
53 SizeOfIntrinsicOp, ClockGateIntrinsicOp, ClockInverterIntrinsicOp,
54 ClockDividerIntrinsicOp, LTLAndIntrinsicOp, LTLOrIntrinsicOp,
55 LTLIntersectIntrinsicOp, LTLDelayIntrinsicOp, LTLConcatIntrinsicOp,
56 LTLRepeatIntrinsicOp, LTLGoToRepeatIntrinsicOp,
57 LTLNonConsecutiveRepeatIntrinsicOp, LTLNotIntrinsicOp,
58 LTLImplicationIntrinsicOp, LTLUntilIntrinsicOp,
59 LTLEventuallyIntrinsicOp, LTLAcceptOnIntrinsicOp,
60 LTLPastIntrinsicOp, LTLClockIntrinsicOp, Mux2CellIntrinsicOp,
61 Mux4CellIntrinsicOp, HasBeenResetIntrinsicOp,
63 BitsPrimOp, HeadPrimOp, MuxPrimOp, PadPrimOp, ShlPrimOp, ShrPrimOp,
64 TailPrimOp, VerbatimExprOp, HWStructCastOp, BitCastOp, RefSendOp,
65 RefResolveOp, RefSubOp, RWProbeOp, XMRRefOp, XMRDerefOp,
68 UninferredResetCastOp, ConstCastOp, RefCastOp,
70 StringConstantOp, FIntegerConstantOp, BoolConstantOp,
71 DoubleConstantOp, ListCreateOp, ListConcatOp, ListLengthOp,
72 ListContainsOp, OptionCreateOp, OptionGetOrElseOp, UnresolvedPathOp,
73 PathOp, IntegerAddOp, IntegerMulOp, IntegerShrOp, IntegerAndOp,
74 IntegerOrOp, IntegerNotOp, StringConcatOp, PropEqOp, BoolAndOp,
75 BoolOrOp, BoolXorOp, UnknownValueOp,
77 TimeOp, HierarchicalModuleNameOp>([&](
auto expr) -> ResultType {
78 return thisCast->visitExpr(expr, args...);
80 .Default([&](
auto expr) -> ResultType {
81 return thisCast->visitInvalidExpr(op, args...);
87 op->emitOpError(
"unknown FIRRTL expression");
109#define HANDLE(OPTYPE, OPKIND) \
110 ResultType visitExpr(OPTYPE op, ExtraArgs... args) { \
111 return static_cast<ConcreteType *>(this)->visit##OPKIND##Expr(op, \
179 HANDLE(PlusArgsValueIntrinsicOp, Unhandled);
180 HANDLE(PlusArgsTestIntrinsicOp, Unhandled);
183 HANDLE(ClockInverterIntrinsicOp, Unhandled);
184 HANDLE(ClockDividerIntrinsicOp, Unhandled);
187 HANDLE(LTLIntersectIntrinsicOp, Unhandled);
191 HANDLE(LTLGoToRepeatIntrinsicOp, Unhandled);
192 HANDLE(LTLNonConsecutiveRepeatIntrinsicOp, Unhandled);
194 HANDLE(LTLImplicationIntrinsicOp, Unhandled);
196 HANDLE(LTLEventuallyIntrinsicOp, Unhandled);
197 HANDLE(LTLAcceptOnIntrinsicOp, Unhandled);
202 HANDLE(HasBeenResetIntrinsicOp, Unhandled);
224 HANDLE(UninferredResetCastOp, Unhandled);
257 HANDLE(HierarchicalModuleNameOp, Unhandled);
262template <
typename ConcreteType,
typename ResultType = void,
263 typename... ExtraArgs>
267 auto *thisCast =
static_cast<ConcreteType *
>(
this);
268 return TypeSwitch<Operation *, ResultType>(op)
269 .template Case<AttachOp, ConnectOp, MatchingConnectOp, RefDefineOp,
270 DomainDefineOp, ForceOp, PrintFOp, FPrintFOp, FFlushOp,
271 SkipOp, StopOp, WhenOp, AssertOp, AssumeOp, CoverOp,
272 PropAssignOp, RefForceOp, RefForceInitialOp,
273 RefReleaseOp, RefReleaseInitialOp, FPGAProbeIntrinsicOp,
274 VerifAssertIntrinsicOp, VerifAssumeIntrinsicOp,
275 UnclockedAssumeIntrinsicOp, VerifCoverIntrinsicOp,
276 VerifRequireIntrinsicOp, VerifEnsureIntrinsicOp,
277 LayerBlockOp, MatchOp, ViewIntrinsicOp, BindOp>(
278 [&](
auto opNode) -> ResultType {
279 return thisCast->visitStmt(opNode, args...);
281 .Default([&](
auto expr) -> ResultType {
282 return thisCast->visitInvalidStmt(op, args...);
288 op->emitOpError(
"unknown firrtl stmt");
298#define HANDLE(OPTYPE) \
299 ResultType visitStmt(OPTYPE op, ExtraArgs... args) { \
300 return static_cast<ConcreteType *>(this)->visitUnhandledStmt(op, args...); \
339template <
typename ConcreteType,
typename ResultType = void,
340 typename... ExtraArgs>
344 auto *thisCast =
static_cast<ConcreteType *
>(
this);
345 return TypeSwitch<Operation *, ResultType>(op)
346 .template Case<InstanceOp, InstanceChoiceOp, ObjectOp, ObjectCreateOp,
347 MemOp, NodeOp, RegOp, RegResetOp, WireOp, VerbatimWireOp,
348 ContractOp, DomainCreateOp>(
349 [&](
auto opNode) -> ResultType {
350 return thisCast->visitDecl(opNode, args...);
352 .Default([&](
auto expr) -> ResultType {
353 return thisCast->visitInvalidDecl(op, args...);
359 op->emitOpError(
"unknown firrtl decl");
369#define HANDLE(OPTYPE) \
370 ResultType visitDecl(OPTYPE op, ExtraArgs... args) { \
371 return static_cast<ConcreteType *>(this)->visitUnhandledDecl(op, args...); \
391template <
typename ConcreteType,
typename ResultType = void,
392 typename... ExtraArgs>
396 auto *thisCast =
static_cast<ConcreteType *
>(
this);
397 return TypeSwitch<Operation *, ResultType>(op)
398 .template Case<GenericIntrinsicOp, DPICallIntrinsicOp>(
399 [&](
auto expr) -> ResultType {
400 return thisCast->visitStmtExpr(expr, args...);
402 .Default([&](
auto expr) -> ResultType {
403 return thisCast->visitInvalidStmtExpr(op, args...);
409 op->emitOpError(
"unknown FIRRTL stmt expression");
419#define HANDLE(OPTYPE, OPKIND) \
420 ResultType visitStmtExpr(OPTYPE op, ExtraArgs... args) { \
421 return static_cast<ConcreteType *>(this)->visit##OPKIND##StmtExpr( \
438template <
typename ConcreteType,
typename ResultType = void,
439 typename... ExtraArgs>
441 :
public ExprVisitor<ConcreteType, ResultType, ExtraArgs...>,
442 public StmtVisitor<ConcreteType, ResultType, ExtraArgs...>,
443 public DeclVisitor<ConcreteType, ResultType, ExtraArgs...>,
462 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(UnknownValueOp, Unhandled)
HANDLE(LTLUntilIntrinsicOp, Unhandled)
HANDLE(DoubleConstantOp, Unhandled)
HANDLE(LTLNotIntrinsicOp, Unhandled)
HANDLE(ListLengthOp, Unhandled)
HANDLE(PadPrimOp, Unhandled)
HANDLE(SubPrimOp, Binary)
HANDLE(ElementwiseXorPrimOp, Unhandled)
HANDLE(UnsafeDomainCastOp, Unhandled)
HANDLE(ClockDividerIntrinsicOp, Unhandled)
HANDLE(LTLPastIntrinsicOp, Unhandled)
HANDLE(AddPrimOp, Binary)
HANDLE(BitsPrimOp, Unhandled)
HANDLE(RWProbeOp, Unhandled)
HANDLE(LTLAndIntrinsicOp, Unhandled)
HANDLE(OpenSubfieldOp, Unhandled)
HANDLE(BoolConstantOp, Unhandled)
HANDLE(CatPrimOp, Unhandled)
HANDLE(AndRPrimOp, Unary)
HANDLE(HeadPrimOp, Unhandled)
HANDLE(ClockInverterIntrinsicOp, Unhandled)
HANDLE(LTLGoToRepeatIntrinsicOp, Unhandled)
HANDLE(LTLNonConsecutiveRepeatIntrinsicOp, Unhandled)
HANDLE(BitCastOp, Unhandled)
HANDLE(PropEqOp, Unhandled)
HANDLE(SubindexOp, Unhandled)
HANDLE(HasBeenResetIntrinsicOp, Unhandled)
HANDLE(SubfieldOp, Unhandled)
HANDLE(DShrPrimOp, Binary)
HANDLE(AsUIntPrimOp, Unary)
HANDLE(IntegerAndOp, Unhandled)
HANDLE(LTLDelayIntrinsicOp, Unhandled)
HANDLE(RefCastOp, Unhandled)
HANDLE(BoolAndOp, Unhandled)
HANDLE(ElementwiseOrPrimOp, Unhandled)
HANDLE(MultibitMuxOp, Unhandled)
HANDLE(XorRPrimOp, Unary)
HANDLE(ConstCastOp, Unhandled)
HANDLE(StringConcatOp, Unhandled)
HANDLE(Mux4CellIntrinsicOp, Unhandled)
HANDLE(StringConstantOp, Unhandled)
HANDLE(LTLConcatIntrinsicOp, Unhandled)
HANDLE(TagExtractOp, Unhandled)
HANDLE(UninferredResetCastOp, Unhandled)
HANDLE(XorPrimOp, Binary)
HANDLE(DomainAnyRefCastOp, Unhandled)
HANDLE(MulPrimOp, Binary)
HANDLE(LTLImplicationIntrinsicOp, Unhandled)
HANDLE(ListConcatOp, 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(ObjectAnyRefCastOp, Unhandled)
HANDLE(LTLIntersectIntrinsicOp, Unhandled)
HANDLE(RemPrimOp, Binary)
HANDLE(IntegerShrOp, Unhandled)
HANDLE(Mux2CellIntrinsicOp, Unhandled)
HANDLE(TimeOp, Unhandled)
HANDLE(MuxPrimOp, Unhandled)
HANDLE(BundleCreateOp, Unhandled)
HANDLE(PlusArgsTestIntrinsicOp, Unhandled)
HANDLE(FEnumCreateOp, Unhandled)
HANDLE(RefSendOp, Unhandled)
HANDLE(XMRDerefOp, Unhandled)
HANDLE(ShrPrimOp, Unhandled)
HANDLE(IntegerAddOp, Unhandled)
HANDLE(UnresolvedPathOp, Unhandled)
HANDLE(PlusArgsValueIntrinsicOp, Unhandled)
HANDLE(IntegerOrOp, Unhandled)
HANDLE(LTLOrIntrinsicOp, Unhandled)
HANDLE(LTLRepeatIntrinsicOp, Unhandled)
HANDLE(OptionCreateOp, Unhandled)
HANDLE(FIntegerConstantOp, Unhandled)
HANDLE(HWStructCastOp, Unhandled)
HANDLE(DomainSubfieldOp, Unhandled)
HANDLE(ClockGateIntrinsicOp, Unhandled)
HANDLE(OpenSubindexOp, Unhandled)
HANDLE(ObjectSubfieldOp, Unhandled)
HANDLE(InvalidValueOp, Unhandled)
HANDLE(SubaccessOp, Unhandled)
HANDLE(HierarchicalModuleNameOp, Unhandled)
HANDLE(DShlPrimOp, Binary)
HANDLE(ShlPrimOp, Unhandled)
HANDLE(IsXIntrinsicOp, Unhandled)
HANDLE(RefResolveOp, Unhandled)
HANDLE(XMRRefOp, Unhandled)
HANDLE(TailPrimOp, Unhandled)
HANDLE(IntegerMulOp, Unhandled)
HANDLE(IntegerNotOp, 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(OptionGetOrElseOp, Unhandled)
HANDLE(ConstantOp, Unhandled)
HANDLE(BoolXorOp, 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(LTLAcceptOnIntrinsicOp, Unhandled)
HANDLE(ListContainsOp, Unhandled)
HANDLE(AndPrimOp, Binary)
HANDLE(AsClockPrimOp, Unary)
HANDLE(SpecialConstantOp, Unhandled)
HANDLE(VectorCreateOp, Unhandled)
HANDLE(LTLEventuallyIntrinsicOp, Unhandled)
HANDLE(DivPrimOp, Binary)
HANDLE(BoolOrOp, Unhandled)
HANDLE(NEQPrimOp, Binary)
HANDLE(SubtagOp, Unhandled)
HANDLE(VerbatimExprOp, Unhandled)
HANDLE(IsTagOp, Unhandled)
HANDLE(AsResetPrimOp, Unary)
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 visitUnhandledStmtExpr(Operation *op, ExtraArgs... args)
ResultType visitInvalidDecl(Operation *op, ExtraArgs... args)
ResultType visitInvalidExpr(Operation *op, ExtraArgs... args)
ResultType visitInvalidStmtExpr(Operation *op, ExtraArgs... args)
ResultType visitInvalidStmt(Operation *op, ExtraArgs... args)
StmtExprVisitor is a visitor for FIRRTL operation that has an optional result.
HANDLE(DPICallIntrinsicOp, Unhandled)
ResultType visitUnhandledStmtExpr(Operation *op, ExtraArgs... args)
This callback is invoked on any StmtExpr operations that are not handled by the concrete visitor.
ResultType visitInvalidStmtExpr(Operation *op, ExtraArgs... args)
This callback is invoked on any non-StmtExpr operations.
HANDLE(GenericIntrinsicOp, Unhandled)
ResultType dispatchStmtExprVisitor(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(VerifEnsureIntrinsicOp)
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)
HANDLE(MatchingConnectOp)
ResultType visitInvalidStmt(Operation *op, ExtraArgs... args)
This callback is invoked on any non-Stmt operations.
HANDLE(VerifRequireIntrinsicOp)
HANDLE(VerifAssumeIntrinsicOp)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.