CIRCT 23.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 // Constants
36 ConstantOp,
37 // Bags
38 BagCreateOp, BagSelectRandomOp, BagDifferenceOp, BagUnionOp,
39 BagUniqueSizeOp, BagConvertToSetOp,
40 // Contexts
41 OnContextOp, ContextSwitchOp,
42 // Labels
43 StringToLabelOp, LabelUniqueDeclOp, LabelOp,
44 // Registers
45 VirtualRegisterOp,
46 // RTG tests
47 TestOp, TargetOp, YieldOp, ValidateOp, TestSuccessOp, TestFailureOp,
48 // Integers
49 RandomNumberInRangeOp,
50 // Sequences
51 SequenceOp, GetSequenceOp, SubstituteSequenceOp,
52 RandomizeSequenceOp, EmbedSequenceOp, InterleaveSequencesOp,
53 // Sets
54 SetCreateOp, SetSelectRandomOp, SetDifferenceOp, SetUnionOp,
55 SetSizeOp, SetCartesianProductOp, SetConvertToBagOp,
56 // Arrays
57 ArrayCreateOp, ArrayExtractOp, ArrayInjectOp, ArraySizeOp,
58 ArrayAppendOp,
59 // Tuples
60 TupleCreateOp, TupleExtractOp,
61 // Immediates
62 IntToImmediateOp, ConcatImmediateOp, SliceImmediateOp,
63 // Memories
64 MemoryAllocOp, MemoryBaseAddressOp, MemorySizeOp,
65 // Memory Blocks
66 MemoryBlockDeclareOp,
67 // Data segment ops
68 SpaceOp, StringDataOp, SegmentOp,
69 // String ops
70 StringConcatOp, IntFormatOp, ImmediateFormatOp, RegisterFormatOp,
71 // Misc ops
72 CommentOp, ConstraintOp, RandomScopeOp>(
73 [&](auto expr) -> ResultType {
74 return thisCast->visitOp(expr, args...);
75 })
76 .Default([&](auto expr) -> ResultType {
77 if (op->getDialect() ==
78 op->getContext()->getLoadedDialect<RTGDialect>())
79 return visitInvalidTypeOp(op, args...);
80
81 return thisCast->visitExternalOp(op, args...);
82 });
83 }
84
85 /// This callback is invoked on any RTG operations not handled properly by the
86 /// TypeSwitch.
87 ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) {
88 op->emitOpError("Unknown RTG operation: ") << op->getName();
89 abort();
90 }
91
92 /// This callback is invoked on any operations that are not
93 /// handled by the concrete visitor.
94 ResultType visitUnhandledOp(Operation *op, ExtraArgs... args);
95
96 ResultType visitExternalOp(Operation *op, ExtraArgs... args) {
97 return ResultType();
98 }
99
100#define HANDLE(OPTYPE, OPKIND) \
101 ResultType visitOp(OPTYPE op, ExtraArgs... args) { \
102 return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \
103 }
104
105 HANDLE(ConstantOp, Unhandled);
106 HANDLE(SequenceOp, Unhandled);
107 HANDLE(GetSequenceOp, Unhandled);
108 HANDLE(SubstituteSequenceOp, Unhandled);
109 HANDLE(RandomizeSequenceOp, Unhandled);
110 HANDLE(InterleaveSequencesOp, Unhandled);
111 HANDLE(EmbedSequenceOp, Unhandled);
112 HANDLE(RandomNumberInRangeOp, Unhandled);
113 HANDLE(OnContextOp, Unhandled);
114 HANDLE(ContextSwitchOp, Unhandled);
115 HANDLE(SetCreateOp, Unhandled);
116 HANDLE(SetSelectRandomOp, Unhandled);
117 HANDLE(SetDifferenceOp, Unhandled);
118 HANDLE(SetUnionOp, Unhandled);
119 HANDLE(SetSizeOp, Unhandled);
120 HANDLE(SetCartesianProductOp, Unhandled);
121 HANDLE(SetConvertToBagOp, Unhandled);
122 HANDLE(BagCreateOp, Unhandled);
123 HANDLE(BagSelectRandomOp, Unhandled);
124 HANDLE(BagDifferenceOp, Unhandled);
125 HANDLE(BagUnionOp, Unhandled);
126 HANDLE(BagUniqueSizeOp, Unhandled);
127 HANDLE(BagConvertToSetOp, Unhandled);
128 HANDLE(ArrayCreateOp, Unhandled);
129 HANDLE(ArrayExtractOp, Unhandled);
130 HANDLE(ArrayInjectOp, Unhandled);
131 HANDLE(ArraySizeOp, Unhandled);
132 HANDLE(ArrayAppendOp, Unhandled);
133 HANDLE(TupleCreateOp, Unhandled);
134 HANDLE(TupleExtractOp, Unhandled);
135 HANDLE(CommentOp, Unhandled);
136 HANDLE(ConstraintOp, Unhandled);
137 HANDLE(LabelUniqueDeclOp, Unhandled);
138 HANDLE(LabelOp, Unhandled);
139 HANDLE(TestOp, Unhandled);
140 HANDLE(TargetOp, Unhandled);
141 HANDLE(YieldOp, Unhandled);
142 HANDLE(ValidateOp, Unhandled);
143 HANDLE(TestSuccessOp, Unhandled);
144 HANDLE(TestFailureOp, Unhandled);
145 HANDLE(VirtualRegisterOp, Unhandled);
146 HANDLE(IntToImmediateOp, Unhandled);
147 HANDLE(ConcatImmediateOp, Unhandled);
148 HANDLE(SliceImmediateOp, Unhandled);
149 HANDLE(MemoryBlockDeclareOp, Unhandled);
150 HANDLE(MemoryAllocOp, Unhandled);
151 HANDLE(MemoryBaseAddressOp, Unhandled);
152 HANDLE(MemorySizeOp, Unhandled);
153 HANDLE(SpaceOp, Unhandled);
154 HANDLE(StringDataOp, Unhandled);
155 HANDLE(SegmentOp, Unhandled);
156 HANDLE(StringConcatOp, Unhandled);
157 HANDLE(IntFormatOp, Unhandled);
158 HANDLE(ImmediateFormatOp, Unhandled);
159 HANDLE(RegisterFormatOp, Unhandled);
160 HANDLE(StringToLabelOp, Unhandled);
161 HANDLE(RandomScopeOp, Unhandled);
162#undef HANDLE
163};
164
165/// This helps visit TypeOp nodes.
166template <typename ConcreteType, typename ResultType = void,
167 typename... ExtraArgs>
169public:
170 ResultType dispatchTypeVisitor(Type type, ExtraArgs... args) {
171 auto *thisCast = static_cast<ConcreteType *>(this);
172 return TypeSwitch<Type, ResultType>(type)
173 .template Case<ImmediateType, SequenceType, SetType, BagType, DictType,
174 MapType, LabelType, IndexType, IntegerType>(
175 [&](auto expr) -> ResultType {
176 return thisCast->visitType(expr, args...);
177 })
178 .template Case<ContextResourceTypeInterface>(
179 [&](auto expr) -> ResultType {
180 return thisCast->visitContextResourceType(expr, args...);
181 })
182 .Default([&](auto expr) -> ResultType {
183 if (&type.getDialect() ==
184 type.getContext()->getLoadedDialect<RTGDialect>())
185 return visitInvalidType(type, args...);
186
187 return thisCast->visitExternalType(type, args...);
188 });
189 }
190
191 /// This callback is invoked on any RTG types not handled properly by the
192 /// TypeSwitch.
193 ResultType visitInvalidType(Type type, ExtraArgs... args) {
194 llvm::errs() << "Unknown RTG type: " << type << "\n";
195 abort();
196 }
197
198 /// This callback is invoked on any types that are not
199 /// handled by the concrete visitor.
200 ResultType visitUnhandledType(Type type, ExtraArgs... args);
201
202 ResultType visitContextResourceType(ContextResourceTypeInterface type,
203 ExtraArgs... args) {
204 return static_cast<ConcreteType *>(this)->visitUnhandledType(type, args...);
205 }
206
207 ResultType visitExternalType(Type type, ExtraArgs... args) {
208 return ResultType();
209 }
210
211#define HANDLE(TYPETYPE, TYPEKIND) \
212 ResultType visitType(TYPETYPE type, ExtraArgs... args) { \
213 return static_cast<ConcreteType *>(this)->visit##TYPEKIND##Type(type, \
214 args...); \
215 }
216
217 HANDLE(ImmediateType, Unhandled);
218 HANDLE(SequenceType, Unhandled);
219 HANDLE(SetType, Unhandled);
220 HANDLE(BagType, Unhandled);
221 HANDLE(DictType, Unhandled);
222 HANDLE(IndexType, Unhandled);
223 HANDLE(IntegerType, Unhandled);
224 HANDLE(LabelType, Unhandled);
225#undef HANDLE
226};
227
228} // namespace rtg
229} // namespace circt
230
231#endif // CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
This helps visit TypeOp nodes.
Definition RTGVisitors.h:29
HANDLE(ConcatImmediateOp, Unhandled)
HANDLE(SegmentOp, Unhandled)
HANDLE(ValidateOp, Unhandled)
HANDLE(MemoryAllocOp, Unhandled)
HANDLE(YieldOp, Unhandled)
HANDLE(IntFormatOp, Unhandled)
HANDLE(ConstraintOp, Unhandled)
ResultType visitExternalOp(Operation *op, ExtraArgs... args)
Definition RTGVisitors.h:96
HANDLE(TupleCreateOp, Unhandled)
HANDLE(MemorySizeOp, Unhandled)
HANDLE(MemoryBaseAddressOp, Unhandled)
HANDLE(TestOp, Unhandled)
HANDLE(ArrayInjectOp, Unhandled)
ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args)
This callback is invoked on any RTG operations not handled properly by the TypeSwitch.
Definition RTGVisitors.h:87
HANDLE(BagUniqueSizeOp, Unhandled)
HANDLE(EmbedSequenceOp, Unhandled)
HANDLE(OnContextOp, Unhandled)
HANDLE(BagCreateOp, Unhandled)
HANDLE(LabelUniqueDeclOp, Unhandled)
HANDLE(TestSuccessOp, Unhandled)
HANDLE(ConstantOp, Unhandled)
HANDLE(SpaceOp, Unhandled)
HANDLE(ArrayAppendOp, Unhandled)
HANDLE(TestFailureOp, Unhandled)
HANDLE(StringConcatOp, Unhandled)
HANDLE(SetUnionOp, Unhandled)
HANDLE(SliceImmediateOp, Unhandled)
HANDLE(ContextSwitchOp, Unhandled)
HANDLE(RandomizeSequenceOp, Unhandled)
HANDLE(IntToImmediateOp, Unhandled)
HANDLE(BagConvertToSetOp, Unhandled)
HANDLE(VirtualRegisterOp, Unhandled)
HANDLE(SetConvertToBagOp, Unhandled)
HANDLE(BagDifferenceOp, Unhandled)
HANDLE(InterleaveSequencesOp, Unhandled)
HANDLE(StringToLabelOp, Unhandled)
HANDLE(ImmediateFormatOp, Unhandled)
HANDLE(RandomNumberInRangeOp, Unhandled)
HANDLE(BagUnionOp, Unhandled)
HANDLE(StringDataOp, Unhandled)
HANDLE(SetCartesianProductOp, Unhandled)
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(RandomScopeOp, Unhandled)
HANDLE(CommentOp, Unhandled)
HANDLE(SubstituteSequenceOp, 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(MemoryBlockDeclareOp, Unhandled)
HANDLE(ArrayExtractOp, Unhandled)
HANDLE(ArrayCreateOp, Unhandled)
HANDLE(RegisterFormatOp, Unhandled)
HANDLE(SequenceOp, Unhandled)
HANDLE(TupleExtractOp, Unhandled)
HANDLE(ArraySizeOp, Unhandled)
HANDLE(GetSequenceOp, 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)
HANDLE(ImmediateType, Unhandled)
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