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 // Bags
36 BagCreateOp, BagSelectRandomOp, BagDifferenceOp, BagUnionOp,
37 BagUniqueSizeOp,
38 // Contexts
39 OnContextOp, ContextSwitchOp,
40 // Labels
41 LabelDeclOp, LabelUniqueDeclOp, LabelOp,
42 // Registers
43 FixedRegisterOp, VirtualRegisterOp,
44 // RTG tests
45 TestOp, TargetOp, YieldOp,
46 // Integers
47 RandomNumberInRangeOp,
48 // Sequences
49 SequenceOp, GetSequenceOp, SubstituteSequenceOp,
50 RandomizeSequenceOp, EmbedSequenceOp, InterleaveSequencesOp,
51 // Sets
52 SetCreateOp, SetSelectRandomOp, SetDifferenceOp, SetUnionOp,
53 SetSizeOp>([&](auto expr) -> ResultType {
54 return thisCast->visitOp(expr, args...);
55 })
56 .Default([&](auto expr) -> ResultType {
57 if (op->getDialect() ==
58 op->getContext()->getLoadedDialect<RTGDialect>())
59 return visitInvalidTypeOp(op, args...);
60
61 return thisCast->visitExternalOp(op, args...);
62 });
63 }
64
65 /// This callback is invoked on any RTG operations not handled properly by the
66 /// TypeSwitch.
67 ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) {
68 op->emitOpError("Unknown RTG operation: ") << op->getName();
69 abort();
70 }
71
72 /// This callback is invoked on any operations that are not
73 /// handled by the concrete visitor.
74 ResultType visitUnhandledOp(Operation *op, ExtraArgs... args);
75
76 ResultType visitExternalOp(Operation *op, ExtraArgs... args) {
77 return ResultType();
78 }
79
80#define HANDLE(OPTYPE, OPKIND) \
81 ResultType visitOp(OPTYPE op, ExtraArgs... args) { \
82 return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \
83 }
84
85 HANDLE(SequenceOp, Unhandled);
86 HANDLE(GetSequenceOp, Unhandled);
87 HANDLE(SubstituteSequenceOp, Unhandled);
88 HANDLE(RandomizeSequenceOp, Unhandled);
89 HANDLE(InterleaveSequencesOp, Unhandled);
90 HANDLE(EmbedSequenceOp, Unhandled);
91 HANDLE(RandomNumberInRangeOp, Unhandled);
92 HANDLE(OnContextOp, Unhandled);
93 HANDLE(ContextSwitchOp, Unhandled);
94 HANDLE(SetCreateOp, Unhandled);
95 HANDLE(SetSelectRandomOp, Unhandled);
96 HANDLE(SetDifferenceOp, Unhandled);
97 HANDLE(SetUnionOp, Unhandled);
98 HANDLE(SetSizeOp, Unhandled);
99 HANDLE(BagCreateOp, Unhandled);
100 HANDLE(BagSelectRandomOp, Unhandled);
101 HANDLE(BagDifferenceOp, Unhandled);
102 HANDLE(BagUnionOp, Unhandled);
103 HANDLE(BagUniqueSizeOp, Unhandled);
104 HANDLE(LabelDeclOp, Unhandled);
105 HANDLE(LabelUniqueDeclOp, Unhandled);
106 HANDLE(LabelOp, Unhandled);
107 HANDLE(TestOp, Unhandled);
108 HANDLE(TargetOp, Unhandled);
109 HANDLE(YieldOp, Unhandled);
110 HANDLE(FixedRegisterOp, Unhandled);
111 HANDLE(VirtualRegisterOp, Unhandled);
112#undef HANDLE
113};
114
115/// This helps visit TypeOp nodes.
116template <typename ConcreteType, typename ResultType = void,
117 typename... ExtraArgs>
119public:
120 ResultType dispatchTypeVisitor(Type type, ExtraArgs... args) {
121 auto *thisCast = static_cast<ConcreteType *>(this);
122 return TypeSwitch<Type, ResultType>(type)
123 .template Case<SequenceType, SetType, BagType, DictType, LabelType,
124 IndexType, IntegerType>([&](auto expr) -> ResultType {
125 return thisCast->visitType(expr, args...);
126 })
127 .template Case<ContextResourceTypeInterface>(
128 [&](auto expr) -> ResultType {
129 return thisCast->visitContextResourceType(expr, args...);
130 })
131 .Default([&](auto expr) -> ResultType {
132 if (&type.getDialect() ==
133 type.getContext()->getLoadedDialect<RTGDialect>())
134 return visitInvalidType(type, args...);
135
136 return thisCast->visitExternalType(type, args...);
137 });
138 }
139
140 /// This callback is invoked on any RTG types not handled properly by the
141 /// TypeSwitch.
142 ResultType visitInvalidType(Type type, ExtraArgs... args) {
143 llvm::errs() << "Unknown RTG type: " << type << "\n";
144 abort();
145 }
146
147 /// This callback is invoked on any types that are not
148 /// handled by the concrete visitor.
149 ResultType visitUnhandledType(Type type, ExtraArgs... args);
150
151 ResultType visitContextResourceType(ContextResourceTypeInterface type,
152 ExtraArgs... args) {
153 return static_cast<ConcreteType *>(this)->visitUnhandledType(type, args...);
154 }
155
156 ResultType visitExternalType(Type type, ExtraArgs... args) {
157 return ResultType();
158 }
159
160#define HANDLE(TYPETYPE, TYPEKIND) \
161 ResultType visitType(TYPETYPE type, ExtraArgs... args) { \
162 return static_cast<ConcreteType *>(this)->visit##TYPEKIND##Type(type, \
163 args...); \
164 }
165
166 HANDLE(SequenceType, Unhandled);
167 HANDLE(SetType, Unhandled);
168 HANDLE(BagType, Unhandled);
169 HANDLE(DictType, Unhandled);
170 HANDLE(IndexType, Unhandled);
171 HANDLE(IntegerType, Unhandled);
172 HANDLE(LabelType, Unhandled);
173#undef HANDLE
174};
175
176} // namespace rtg
177} // namespace circt
178
179#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:76
HANDLE(TestOp, Unhandled)
ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args)
This callback is invoked on any RTG operations not handled properly by the TypeSwitch.
Definition RTGVisitors.h:67
HANDLE(BagUniqueSizeOp, Unhandled)
HANDLE(EmbedSequenceOp, Unhandled)
HANDLE(OnContextOp, Unhandled)
HANDLE(BagCreateOp, Unhandled)
HANDLE(LabelUniqueDeclOp, Unhandled)
HANDLE(SetUnionOp, Unhandled)
HANDLE(ContextSwitchOp, Unhandled)
HANDLE(RandomizeSequenceOp, Unhandled)
HANDLE(VirtualRegisterOp, Unhandled)
HANDLE(BagDifferenceOp, Unhandled)
HANDLE(InterleaveSequencesOp, Unhandled)
HANDLE(FixedRegisterOp, Unhandled)
HANDLE(RandomNumberInRangeOp, Unhandled)
HANDLE(BagUnionOp, 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(SequenceOp, 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)
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