CIRCT 20.0.0git
Loading...
Searching...
No Matches
RTGVisitors.h
Go to the documentation of this file.
1//===- RTGVisitors.h - RTG Dialect Visitors ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines visitors that make it easier to work with RTG IR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
14#define CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
15
21#include "llvm/ADT/TypeSwitch.h"
22
23namespace circt {
24namespace rtg {
25
26/// This helps visit TypeOp nodes.
27template <typename ConcreteType, typename ResultType = void,
28 typename... ExtraArgs>
30public:
31 ResultType dispatchOpVisitor(Operation *op, ExtraArgs... args) {
32 auto *thisCast = static_cast<ConcreteType *>(this);
33 return TypeSwitch<Operation *, ResultType>(op)
34 .template Case<
35 // Bags
36 BagCreateOp, BagSelectRandomOp, BagDifferenceOp, BagUnionOp,
37 BagUniqueSizeOp,
38 // Labels
39 LabelDeclOp, LabelUniqueDeclOp, LabelOp,
40 // Registers
41 FixedRegisterOp, VirtualRegisterOp,
42 // RTG tests
43 TestOp, TargetOp, YieldOp,
44 // Sequences
45 SequenceOp, SequenceClosureOp, InvokeSequenceOp,
46 // Sets
47 SetCreateOp, SetSelectRandomOp, SetDifferenceOp, SetUnionOp,
48 SetSizeOp>([&](auto expr) -> ResultType {
49 return thisCast->visitOp(expr, args...);
50 })
51 .template Case<ContextResourceOpInterface>(
52 [&](auto expr) -> ResultType {
53 return thisCast->visitContextResourceOp(expr, args...);
54 })
55 .Default([&](auto expr) -> ResultType {
56 if (op->getDialect() ==
57 op->getContext()->getLoadedDialect<RTGDialect>())
58 return visitInvalidTypeOp(op, args...);
59
60 return thisCast->visitExternalOp(op, args...);
61 });
62 }
63
64 /// This callback is invoked on any RTG operations not handled properly by the
65 /// TypeSwitch.
66 ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) {
67 op->emitOpError("Unknown RTG operation: ") << op->getName();
68 abort();
69 }
70
71 /// This callback is invoked on any operations that are not
72 /// handled by the concrete visitor.
73 ResultType visitUnhandledOp(Operation *op, ExtraArgs... args);
74
75 ResultType visitContextResourceOp(ContextResourceOpInterface op,
76 ExtraArgs... args) {
77 return static_cast<ConcreteType *>(this)->visitUnhandledOp(op, args...);
78 }
79
80 ResultType visitExternalOp(Operation *op, ExtraArgs... args) {
81 return ResultType();
82 }
83
84#define HANDLE(OPTYPE, OPKIND) \
85 ResultType visitOp(OPTYPE op, ExtraArgs... args) { \
86 return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \
87 }
88
89 HANDLE(SequenceOp, Unhandled);
90 HANDLE(SequenceClosureOp, Unhandled);
91 HANDLE(InvokeSequenceOp, Unhandled);
92 HANDLE(SetCreateOp, Unhandled);
93 HANDLE(SetSelectRandomOp, Unhandled);
94 HANDLE(SetDifferenceOp, Unhandled);
95 HANDLE(SetUnionOp, Unhandled);
96 HANDLE(SetSizeOp, Unhandled);
97 HANDLE(BagCreateOp, Unhandled);
98 HANDLE(BagSelectRandomOp, Unhandled);
99 HANDLE(BagDifferenceOp, Unhandled);
100 HANDLE(BagUnionOp, Unhandled);
101 HANDLE(BagUniqueSizeOp, Unhandled);
102 HANDLE(LabelDeclOp, Unhandled);
103 HANDLE(LabelUniqueDeclOp, Unhandled);
104 HANDLE(LabelOp, Unhandled);
105 HANDLE(TestOp, Unhandled);
106 HANDLE(TargetOp, Unhandled);
107 HANDLE(YieldOp, Unhandled);
108 HANDLE(FixedRegisterOp, Unhandled);
109 HANDLE(VirtualRegisterOp, Unhandled);
110#undef HANDLE
111};
112
113/// This helps visit TypeOp nodes.
114template <typename ConcreteType, typename ResultType = void,
115 typename... ExtraArgs>
117public:
118 ResultType dispatchTypeVisitor(Type type, ExtraArgs... args) {
119 auto *thisCast = static_cast<ConcreteType *>(this);
120 return TypeSwitch<Type, ResultType>(type)
121 .template Case<SequenceType, SetType, BagType, DictType, LabelType,
122 IndexType, IntegerType>([&](auto expr) -> ResultType {
123 return thisCast->visitType(expr, args...);
124 })
125 .template Case<ContextResourceTypeInterface>(
126 [&](auto expr) -> ResultType {
127 return thisCast->visitContextResourceType(expr, args...);
128 })
129 .Default([&](auto expr) -> ResultType {
130 if (&type.getDialect() ==
131 type.getContext()->getLoadedDialect<RTGDialect>())
132 return visitInvalidType(type, args...);
133
134 return thisCast->visitExternalType(type, args...);
135 });
136 }
137
138 /// This callback is invoked on any RTG types not handled properly by the
139 /// TypeSwitch.
140 ResultType visitInvalidType(Type type, ExtraArgs... args) {
141 llvm::errs() << "Unknown RTG type: " << type << "\n";
142 abort();
143 }
144
145 /// This callback is invoked on any types that are not
146 /// handled by the concrete visitor.
147 ResultType visitUnhandledType(Type type, ExtraArgs... args);
148
149 ResultType visitContextResourceType(ContextResourceTypeInterface type,
150 ExtraArgs... args) {
151 return static_cast<ConcreteType *>(this)->visitUnhandledType(type, args...);
152 }
153
154 ResultType visitExternalType(Type type, ExtraArgs... args) {
155 return ResultType();
156 }
157
158#define HANDLE(TYPETYPE, TYPEKIND) \
159 ResultType visitType(TYPETYPE type, ExtraArgs... args) { \
160 return static_cast<ConcreteType *>(this)->visit##TYPEKIND##Type(type, \
161 args...); \
162 }
163
164 HANDLE(SequenceType, Unhandled);
165 HANDLE(SetType, Unhandled);
166 HANDLE(BagType, Unhandled);
167 HANDLE(DictType, Unhandled);
168 HANDLE(IndexType, Unhandled);
169 HANDLE(IntegerType, Unhandled);
170 HANDLE(LabelType, Unhandled);
171#undef HANDLE
172};
173
174} // namespace rtg
175} // namespace circt
176
177#endif // CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
This helps visit TypeOp nodes.
Definition RTGVisitors.h:29
HANDLE(YieldOp, Unhandled)
ResultType visitExternalOp(Operation *op, ExtraArgs... args)
Definition RTGVisitors.h:80
HANDLE(TestOp, Unhandled)
ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args)
This callback is invoked on any RTG operations not handled properly by the TypeSwitch.
Definition RTGVisitors.h:66
HANDLE(BagUniqueSizeOp, Unhandled)
HANDLE(BagCreateOp, Unhandled)
HANDLE(LabelUniqueDeclOp, Unhandled)
HANDLE(SetUnionOp, Unhandled)
HANDLE(VirtualRegisterOp, Unhandled)
HANDLE(BagDifferenceOp, Unhandled)
HANDLE(FixedRegisterOp, Unhandled)
HANDLE(BagUnionOp, Unhandled)
ResultType visitContextResourceOp(ContextResourceOpInterface op, ExtraArgs... args)
Definition RTGVisitors.h:75
HANDLE(SetDifferenceOp, Unhandled)
HANDLE(TargetOp, Unhandled)
HANDLE(SetSizeOp, Unhandled)
HANDLE(SetCreateOp, Unhandled)
HANDLE(SetSelectRandomOp, Unhandled)
HANDLE(BagSelectRandomOp, Unhandled)
ResultType dispatchOpVisitor(Operation *op, ExtraArgs... args)
Definition RTGVisitors.h:31
HANDLE(LabelDeclOp, Unhandled)
HANDLE(SequenceClosureOp, Unhandled)
ResultType visitUnhandledOp(Operation *op, ExtraArgs... args)
This callback is invoked on any operations that are not handled by the concrete visitor.
HANDLE(LabelOp, Unhandled)
HANDLE(SequenceOp, Unhandled)
HANDLE(InvokeSequenceOp, Unhandled)
This helps visit TypeOp nodes.
HANDLE(BagType, Unhandled)
ResultType dispatchTypeVisitor(Type type, ExtraArgs... args)
HANDLE(IndexType, Unhandled)
HANDLE(DictType, Unhandled)
HANDLE(IntegerType, Unhandled)
HANDLE(SequenceType, Unhandled)
HANDLE(SetType, Unhandled)
HANDLE(LabelType, Unhandled)
ResultType visitExternalType(Type type, ExtraArgs... args)
ResultType visitContextResourceType(ContextResourceTypeInterface type, ExtraArgs... args)
ResultType visitInvalidType(Type type, ExtraArgs... args)
This callback is invoked on any RTG types not handled properly by the TypeSwitch.
ResultType visitUnhandledType(Type type, ExtraArgs... args)
This callback is invoked on any types that are not handled by the concrete visitor.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition rtg.py:1