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