Loading [MathJax]/extensions/tex2jax.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, ValidateOp,
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,
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(FixedRegisterOp, Unhandled);
137 HANDLE(VirtualRegisterOp, Unhandled);
138 HANDLE(IntToImmediateOp, Unhandled);
139 HANDLE(MemoryBlockDeclareOp, Unhandled);
140 HANDLE(MemoryAllocOp, Unhandled);
141 HANDLE(MemoryBaseAddressOp, Unhandled);
142 HANDLE(MemorySizeOp, Unhandled);
143#undef HANDLE
144};
145
146/// This helps visit TypeOp nodes.
147template <typename ConcreteType, typename ResultType = void,
148 typename... ExtraArgs>
150public:
151 ResultType dispatchTypeVisitor(Type type, ExtraArgs... args) {
152 auto *thisCast = static_cast<ConcreteType *>(this);
153 return TypeSwitch<Type, ResultType>(type)
154 .template Case<ImmediateType, SequenceType, SetType, BagType, DictType,
155 LabelType, IndexType, IntegerType>(
156 [&](auto expr) -> ResultType {
157 return thisCast->visitType(expr, args...);
158 })
159 .template Case<ContextResourceTypeInterface>(
160 [&](auto expr) -> ResultType {
161 return thisCast->visitContextResourceType(expr, args...);
162 })
163 .Default([&](auto expr) -> ResultType {
164 if (&type.getDialect() ==
165 type.getContext()->getLoadedDialect<RTGDialect>())
166 return visitInvalidType(type, args...);
167
168 return thisCast->visitExternalType(type, args...);
169 });
170 }
171
172 /// This callback is invoked on any RTG types not handled properly by the
173 /// TypeSwitch.
174 ResultType visitInvalidType(Type type, ExtraArgs... args) {
175 llvm::errs() << "Unknown RTG type: " << type << "\n";
176 abort();
177 }
178
179 /// This callback is invoked on any types that are not
180 /// handled by the concrete visitor.
181 ResultType visitUnhandledType(Type type, ExtraArgs... args);
182
183 ResultType visitContextResourceType(ContextResourceTypeInterface type,
184 ExtraArgs... args) {
185 return static_cast<ConcreteType *>(this)->visitUnhandledType(type, args...);
186 }
187
188 ResultType visitExternalType(Type type, ExtraArgs... args) {
189 return ResultType();
190 }
191
192#define HANDLE(TYPETYPE, TYPEKIND) \
193 ResultType visitType(TYPETYPE type, ExtraArgs... args) { \
194 return static_cast<ConcreteType *>(this)->visit##TYPEKIND##Type(type, \
195 args...); \
196 }
197
198 HANDLE(ImmediateType, Unhandled);
199 HANDLE(SequenceType, Unhandled);
200 HANDLE(SetType, Unhandled);
201 HANDLE(BagType, Unhandled);
202 HANDLE(DictType, Unhandled);
203 HANDLE(IndexType, Unhandled);
204 HANDLE(IntegerType, Unhandled);
205 HANDLE(LabelType, Unhandled);
206#undef HANDLE
207};
208
209} // namespace rtg
210} // namespace circt
211
212#endif // CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
This helps visit TypeOp nodes.
Definition RTGVisitors.h:29
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(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(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