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