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