Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 LabelDeclOp, LabelUniqueDeclOp, LabelOp,
44 // Registers
45 FixedRegisterOp, 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 // Tuples
59 TupleCreateOp, TupleExtractOp,
60 // Immediates
61 IntToImmediateOp, ConcatImmediateOp, SliceImmediateOp,
62 // Memories
63 MemoryAllocOp, MemoryBaseAddressOp, MemorySizeOp,
64 // Memory Blocks
65 MemoryBlockDeclareOp,
66 // Misc ops
67 CommentOp>([&](auto expr) -> ResultType {
68 return thisCast->visitOp(expr, args...);
69 })
70 .Default([&](auto expr) -> ResultType {
71 if (op->getDialect() ==
72 op->getContext()->getLoadedDialect<RTGDialect>())
73 return visitInvalidTypeOp(op, args...);
74
75 return thisCast->visitExternalOp(op, args...);
76 });
77 }
78
79 /// This callback is invoked on any RTG operations not handled properly by the
80 /// TypeSwitch.
81 ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) {
82 op->emitOpError("Unknown RTG operation: ") << op->getName();
83 abort();
84 }
85
86 /// This callback is invoked on any operations that are not
87 /// handled by the concrete visitor.
88 ResultType visitUnhandledOp(Operation *op, ExtraArgs... args);
89
90 ResultType visitExternalOp(Operation *op, ExtraArgs... args) {
91 return ResultType();
92 }
93
94#define HANDLE(OPTYPE, OPKIND) \
95 ResultType visitOp(OPTYPE op, ExtraArgs... args) { \
96 return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \
97 }
98
99 HANDLE(ConstantOp, Unhandled);
100 HANDLE(SequenceOp, Unhandled);
101 HANDLE(GetSequenceOp, Unhandled);
102 HANDLE(SubstituteSequenceOp, Unhandled);
103 HANDLE(RandomizeSequenceOp, Unhandled);
104 HANDLE(InterleaveSequencesOp, Unhandled);
105 HANDLE(EmbedSequenceOp, Unhandled);
106 HANDLE(RandomNumberInRangeOp, Unhandled);
107 HANDLE(OnContextOp, Unhandled);
108 HANDLE(ContextSwitchOp, Unhandled);
109 HANDLE(SetCreateOp, Unhandled);
110 HANDLE(SetSelectRandomOp, Unhandled);
111 HANDLE(SetDifferenceOp, Unhandled);
112 HANDLE(SetUnionOp, Unhandled);
113 HANDLE(SetSizeOp, Unhandled);
114 HANDLE(SetCartesianProductOp, Unhandled);
115 HANDLE(SetConvertToBagOp, Unhandled);
116 HANDLE(BagCreateOp, Unhandled);
117 HANDLE(BagSelectRandomOp, Unhandled);
118 HANDLE(BagDifferenceOp, Unhandled);
119 HANDLE(BagUnionOp, Unhandled);
120 HANDLE(BagUniqueSizeOp, Unhandled);
121 HANDLE(BagConvertToSetOp, Unhandled);
122 HANDLE(ArrayCreateOp, Unhandled);
123 HANDLE(ArrayExtractOp, Unhandled);
124 HANDLE(ArrayInjectOp, Unhandled);
125 HANDLE(ArraySizeOp, Unhandled);
126 HANDLE(TupleCreateOp, Unhandled);
127 HANDLE(TupleExtractOp, Unhandled);
128 HANDLE(CommentOp, Unhandled);
129 HANDLE(LabelDeclOp, Unhandled);
130 HANDLE(LabelUniqueDeclOp, Unhandled);
131 HANDLE(LabelOp, Unhandled);
132 HANDLE(TestOp, Unhandled);
133 HANDLE(TargetOp, Unhandled);
134 HANDLE(YieldOp, Unhandled);
135 HANDLE(ValidateOp, Unhandled);
136 HANDLE(TestSuccessOp, Unhandled);
137 HANDLE(TestFailureOp, Unhandled);
138 HANDLE(FixedRegisterOp, Unhandled);
139 HANDLE(VirtualRegisterOp, Unhandled);
140 HANDLE(IntToImmediateOp, Unhandled);
141 HANDLE(ConcatImmediateOp, Unhandled);
142 HANDLE(SliceImmediateOp, Unhandled);
143 HANDLE(MemoryBlockDeclareOp, Unhandled);
144 HANDLE(MemoryAllocOp, Unhandled);
145 HANDLE(MemoryBaseAddressOp, Unhandled);
146 HANDLE(MemorySizeOp, Unhandled);
147#undef HANDLE
148};
149
150/// This helps visit TypeOp nodes.
151template <typename ConcreteType, typename ResultType = void,
152 typename... ExtraArgs>
154public:
155 ResultType dispatchTypeVisitor(Type type, ExtraArgs... args) {
156 auto *thisCast = static_cast<ConcreteType *>(this);
157 return TypeSwitch<Type, ResultType>(type)
158 .template Case<ImmediateType, SequenceType, SetType, BagType, DictType,
159 LabelType, IndexType, IntegerType>(
160 [&](auto expr) -> ResultType {
161 return thisCast->visitType(expr, args...);
162 })
163 .template Case<ContextResourceTypeInterface>(
164 [&](auto expr) -> ResultType {
165 return thisCast->visitContextResourceType(expr, args...);
166 })
167 .Default([&](auto expr) -> ResultType {
168 if (&type.getDialect() ==
169 type.getContext()->getLoadedDialect<RTGDialect>())
170 return visitInvalidType(type, args...);
171
172 return thisCast->visitExternalType(type, args...);
173 });
174 }
175
176 /// This callback is invoked on any RTG types not handled properly by the
177 /// TypeSwitch.
178 ResultType visitInvalidType(Type type, ExtraArgs... args) {
179 llvm::errs() << "Unknown RTG type: " << type << "\n";
180 abort();
181 }
182
183 /// This callback is invoked on any types that are not
184 /// handled by the concrete visitor.
185 ResultType visitUnhandledType(Type type, ExtraArgs... args);
186
187 ResultType visitContextResourceType(ContextResourceTypeInterface type,
188 ExtraArgs... args) {
189 return static_cast<ConcreteType *>(this)->visitUnhandledType(type, args...);
190 }
191
192 ResultType visitExternalType(Type type, ExtraArgs... args) {
193 return ResultType();
194 }
195
196#define HANDLE(TYPETYPE, TYPEKIND) \
197 ResultType visitType(TYPETYPE type, ExtraArgs... args) { \
198 return static_cast<ConcreteType *>(this)->visit##TYPEKIND##Type(type, \
199 args...); \
200 }
201
202 HANDLE(ImmediateType, Unhandled);
203 HANDLE(SequenceType, Unhandled);
204 HANDLE(SetType, Unhandled);
205 HANDLE(BagType, Unhandled);
206 HANDLE(DictType, Unhandled);
207 HANDLE(IndexType, Unhandled);
208 HANDLE(IntegerType, Unhandled);
209 HANDLE(LabelType, Unhandled);
210#undef HANDLE
211};
212
213} // namespace rtg
214} // namespace circt
215
216#endif // CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
This helps visit TypeOp nodes.
Definition RTGVisitors.h:29
HANDLE(ConcatImmediateOp, Unhandled)
HANDLE(ValidateOp, Unhandled)
HANDLE(MemoryAllocOp, Unhandled)
HANDLE(YieldOp, Unhandled)
ResultType visitExternalOp(Operation *op, ExtraArgs... args)
Definition RTGVisitors.h:90
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:81
HANDLE(BagUniqueSizeOp, Unhandled)
HANDLE(EmbedSequenceOp, Unhandled)
HANDLE(OnContextOp, Unhandled)
HANDLE(BagCreateOp, Unhandled)
HANDLE(LabelUniqueDeclOp, Unhandled)
HANDLE(TestSuccessOp, Unhandled)
HANDLE(ConstantOp, Unhandled)
HANDLE(TestFailureOp, 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(FixedRegisterOp, Unhandled)
HANDLE(RandomNumberInRangeOp, Unhandled)
HANDLE(BagUnionOp, 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)
HANDLE(LabelDeclOp, 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(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