CIRCT 24.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
17#include "llvm/ADT/TypeSwitch.h"
18
19namespace circt {
20namespace rtg {
21
22/// This helps visit TypeOp nodes.
23template <typename ConcreteType, typename ResultType = void,
24 typename... ExtraArgs>
26public:
27 ResultType dispatchOpVisitor(Operation *op, ExtraArgs... args) {
28 auto *thisCast = static_cast<ConcreteType *>(this);
29 return TypeSwitch<Operation *, ResultType>(op)
30 .template Case<
31 // Constants
32 ConstantOp, StructDeclOp, VariantDeclOp,
33 // Bags
34 BagCreateOp, BagSelectRandomOp, BagDifferenceOp, BagUnionOp,
35 BagUniqueSizeOp, BagConvertToSetOp,
36 // Contexts
37 OnContextOp, ContextSwitchOp,
38 // Labels
39 StringToLabelOp, LabelUniqueDeclOp, LabelOp,
40 // Registers
41 VirtualRegisterOp, RegisterToIndexOp, IndexToRegisterOp,
42 // RTG tests
43 TestOp, TargetOp, YieldOp, ValidateOp, TestSuccessOp, TestFailureOp,
44 // Integers
45 RandomNumberInRangeOp,
46 // Sequences
47 SequenceOp, GetSequenceOp, SubstituteSequenceOp,
48 RandomizeSequenceOp, EmbedSequenceOp, InterleaveSequencesOp,
49 // Sets
50 SetCreateOp, SetSelectRandomOp, SetDifferenceOp, SetUnionOp,
51 SetSizeOp, SetCartesianProductOp, SetConvertToBagOp,
52 // Arrays
53 ArrayCreateOp, ArrayExtractOp, ArrayInjectOp, ArraySizeOp,
54 ArrayAppendOp,
55 // Tuples
56 TupleCreateOp, TupleExtractOp,
57 // Structs
58 StructCreateOp, StructExtractOp,
59 // Variants
60 VariantCreateOp, VariantMatchOp,
61 // Immediates
62 IntToImmediateOp, ConcatImmediateOp, SliceImmediateOp,
63 // Memories
64 MemoryAllocOp, MemoryBaseAddressOp, MemorySizeOp,
65 // Memory Blocks
66 MemoryBlockDeclareOp,
67 // Data segment ops
68 SpaceOp, StringDataOp, SegmentOp,
69 // String ops
70 StringConcatOp, IntFormatOp, ImmediateFormatOp, RegisterFormatOp,
71 StringToASCIIArrayOp,
72 // Misc ops
73 CommentOp, ConstraintOp, RandomScopeOp,
74 // Mut ops
75 MutCreateOp, MutReadOp, MutWriteOp,
76 // Effect handler ops
77 EffectOp, WithHandlersOp, PerformOp, ResumeOp>(
78 [&](auto expr) -> ResultType {
79 return thisCast->visitOp(expr, args...);
80 })
81 .Default([&](auto expr) -> ResultType {
82 if (op->getDialect() ==
83 op->getContext()->getLoadedDialect<RTGDialect>())
84 return visitInvalidTypeOp(op, args...);
85
86 return thisCast->visitExternalOp(op, args...);
87 });
88 }
89
90 /// This callback is invoked on any RTG operations not handled properly by the
91 /// TypeSwitch.
92 ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) {
93 op->emitOpError("Unknown RTG operation: ") << op->getName();
94 abort();
95 }
96
97 /// This callback is invoked on any operations that are not
98 /// handled by the concrete visitor.
99 ResultType visitUnhandledOp(Operation *op, ExtraArgs... args);
100
101 ResultType visitExternalOp(Operation *op, ExtraArgs... args) {
102 return ResultType();
103 }
104
105#define HANDLE(OPTYPE, OPKIND) \
106 ResultType visitOp(OPTYPE op, ExtraArgs... args) { \
107 return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \
108 }
109
110 HANDLE(ConstantOp, Unhandled);
111 HANDLE(StructDeclOp, Unhandled);
112 HANDLE(VariantDeclOp, Unhandled);
113 HANDLE(SequenceOp, Unhandled);
114 HANDLE(GetSequenceOp, Unhandled);
115 HANDLE(SubstituteSequenceOp, Unhandled);
116 HANDLE(RandomizeSequenceOp, Unhandled);
117 HANDLE(InterleaveSequencesOp, Unhandled);
118 HANDLE(EmbedSequenceOp, Unhandled);
119 HANDLE(RandomNumberInRangeOp, Unhandled);
120 HANDLE(OnContextOp, Unhandled);
121 HANDLE(ContextSwitchOp, Unhandled);
122 HANDLE(SetCreateOp, Unhandled);
123 HANDLE(SetSelectRandomOp, Unhandled);
124 HANDLE(SetDifferenceOp, Unhandled);
125 HANDLE(SetUnionOp, Unhandled);
126 HANDLE(SetSizeOp, Unhandled);
127 HANDLE(SetCartesianProductOp, Unhandled);
128 HANDLE(SetConvertToBagOp, Unhandled);
129 HANDLE(BagCreateOp, Unhandled);
130 HANDLE(BagSelectRandomOp, Unhandled);
131 HANDLE(BagDifferenceOp, Unhandled);
132 HANDLE(BagUnionOp, Unhandled);
133 HANDLE(BagUniqueSizeOp, Unhandled);
134 HANDLE(BagConvertToSetOp, Unhandled);
135 HANDLE(ArrayCreateOp, Unhandled);
136 HANDLE(ArrayExtractOp, Unhandled);
137 HANDLE(ArrayInjectOp, Unhandled);
138 HANDLE(ArraySizeOp, Unhandled);
139 HANDLE(ArrayAppendOp, Unhandled);
140 HANDLE(TupleCreateOp, Unhandled);
141 HANDLE(TupleExtractOp, Unhandled);
142 HANDLE(StructCreateOp, Unhandled);
143 HANDLE(StructExtractOp, Unhandled);
144 HANDLE(VariantCreateOp, Unhandled);
145 HANDLE(VariantMatchOp, Unhandled);
146 HANDLE(CommentOp, Unhandled);
147 HANDLE(ConstraintOp, Unhandled);
148 HANDLE(LabelUniqueDeclOp, Unhandled);
149 HANDLE(LabelOp, Unhandled);
150 HANDLE(TestOp, Unhandled);
151 HANDLE(TargetOp, Unhandled);
152 HANDLE(YieldOp, Unhandled);
153 HANDLE(ValidateOp, Unhandled);
154 HANDLE(TestSuccessOp, Unhandled);
155 HANDLE(TestFailureOp, Unhandled);
156 HANDLE(VirtualRegisterOp, Unhandled);
157 HANDLE(RegisterToIndexOp, Unhandled);
158 HANDLE(IndexToRegisterOp, Unhandled);
159 HANDLE(IntToImmediateOp, Unhandled);
160 HANDLE(ConcatImmediateOp, Unhandled);
161 HANDLE(SliceImmediateOp, Unhandled);
162 HANDLE(MemoryBlockDeclareOp, Unhandled);
163 HANDLE(MemoryAllocOp, Unhandled);
164 HANDLE(MemoryBaseAddressOp, Unhandled);
165 HANDLE(MemorySizeOp, Unhandled);
166 HANDLE(SpaceOp, Unhandled);
167 HANDLE(StringDataOp, Unhandled);
168 HANDLE(SegmentOp, Unhandled);
169 HANDLE(StringConcatOp, Unhandled);
170 HANDLE(IntFormatOp, Unhandled);
171 HANDLE(ImmediateFormatOp, Unhandled);
172 HANDLE(RegisterFormatOp, Unhandled);
173 HANDLE(StringToLabelOp, Unhandled);
174 HANDLE(StringToASCIIArrayOp, Unhandled);
175 HANDLE(RandomScopeOp, Unhandled);
176 HANDLE(MutCreateOp, Unhandled);
177 HANDLE(MutReadOp, Unhandled);
178 HANDLE(MutWriteOp, Unhandled);
179 HANDLE(EffectOp, Unhandled);
180 HANDLE(WithHandlersOp, Unhandled);
181 HANDLE(PerformOp, Unhandled);
182 HANDLE(ResumeOp, Unhandled);
183#undef HANDLE
184};
185
186} // namespace rtg
187} // namespace circt
188
189#endif // CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
This helps visit TypeOp nodes.
Definition RTGVisitors.h:25
HANDLE(ConcatImmediateOp, Unhandled)
HANDLE(SegmentOp, Unhandled)
HANDLE(EffectOp, Unhandled)
HANDLE(ValidateOp, Unhandled)
HANDLE(MemoryAllocOp, Unhandled)
HANDLE(YieldOp, Unhandled)
HANDLE(IntFormatOp, Unhandled)
HANDLE(ConstraintOp, Unhandled)
ResultType visitExternalOp(Operation *op, ExtraArgs... args)
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:92
HANDLE(BagUniqueSizeOp, Unhandled)
HANDLE(EmbedSequenceOp, Unhandled)
HANDLE(OnContextOp, Unhandled)
HANDLE(BagCreateOp, Unhandled)
HANDLE(LabelUniqueDeclOp, Unhandled)
HANDLE(ResumeOp, Unhandled)
HANDLE(TestSuccessOp, Unhandled)
HANDLE(ConstantOp, Unhandled)
HANDLE(SpaceOp, Unhandled)
HANDLE(ArrayAppendOp, Unhandled)
HANDLE(TestFailureOp, Unhandled)
HANDLE(StringConcatOp, Unhandled)
HANDLE(SetUnionOp, Unhandled)
HANDLE(SliceImmediateOp, Unhandled)
HANDLE(ContextSwitchOp, Unhandled)
HANDLE(StructExtractOp, Unhandled)
HANDLE(RandomizeSequenceOp, Unhandled)
HANDLE(IntToImmediateOp, Unhandled)
HANDLE(StructDeclOp, Unhandled)
HANDLE(BagConvertToSetOp, Unhandled)
HANDLE(VirtualRegisterOp, Unhandled)
HANDLE(SetConvertToBagOp, Unhandled)
HANDLE(BagDifferenceOp, Unhandled)
HANDLE(InterleaveSequencesOp, Unhandled)
HANDLE(StringToLabelOp, Unhandled)
HANDLE(VariantMatchOp, Unhandled)
HANDLE(ImmediateFormatOp, Unhandled)
HANDLE(MutReadOp, Unhandled)
HANDLE(RandomNumberInRangeOp, Unhandled)
HANDLE(BagUnionOp, Unhandled)
HANDLE(StringDataOp, Unhandled)
HANDLE(SetCartesianProductOp, Unhandled)
HANDLE(WithHandlersOp, 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:27
HANDLE(MutCreateOp, Unhandled)
HANDLE(VariantDeclOp, Unhandled)
HANDLE(PerformOp, Unhandled)
HANDLE(RandomScopeOp, Unhandled)
HANDLE(CommentOp, Unhandled)
HANDLE(SubstituteSequenceOp, Unhandled)
HANDLE(MutWriteOp, Unhandled)
HANDLE(RegisterToIndexOp, 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(StructCreateOp, Unhandled)
HANDLE(IndexToRegisterOp, Unhandled)
HANDLE(StringToASCIIArrayOp, Unhandled)
HANDLE(MemoryBlockDeclareOp, Unhandled)
HANDLE(ArrayExtractOp, Unhandled)
HANDLE(VariantCreateOp, Unhandled)
HANDLE(ArrayCreateOp, Unhandled)
HANDLE(RegisterFormatOp, Unhandled)
HANDLE(SequenceOp, Unhandled)
HANDLE(TupleExtractOp, Unhandled)
HANDLE(ArraySizeOp, Unhandled)
HANDLE(GetSequenceOp, Unhandled)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.