CIRCT 23.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,
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 // Immediates
58 IntToImmediateOp, ConcatImmediateOp, SliceImmediateOp,
59 // Memories
60 MemoryAllocOp, MemoryBaseAddressOp, MemorySizeOp,
61 // Memory Blocks
62 MemoryBlockDeclareOp,
63 // Data segment ops
64 SpaceOp, StringDataOp, SegmentOp,
65 // String ops
66 StringConcatOp, IntFormatOp, ImmediateFormatOp, RegisterFormatOp,
67 // Misc ops
68 CommentOp, ConstraintOp, RandomScopeOp>(
69 [&](auto expr) -> ResultType {
70 return thisCast->visitOp(expr, args...);
71 })
72 .Default([&](auto expr) -> ResultType {
73 if (op->getDialect() ==
74 op->getContext()->getLoadedDialect<RTGDialect>())
75 return visitInvalidTypeOp(op, args...);
76
77 return thisCast->visitExternalOp(op, args...);
78 });
79 }
80
81 /// This callback is invoked on any RTG operations not handled properly by the
82 /// TypeSwitch.
83 ResultType visitInvalidTypeOp(Operation *op, ExtraArgs... args) {
84 op->emitOpError("Unknown RTG operation: ") << op->getName();
85 abort();
86 }
87
88 /// This callback is invoked on any operations that are not
89 /// handled by the concrete visitor.
90 ResultType visitUnhandledOp(Operation *op, ExtraArgs... args);
91
92 ResultType visitExternalOp(Operation *op, ExtraArgs... args) {
93 return ResultType();
94 }
95
96#define HANDLE(OPTYPE, OPKIND) \
97 ResultType visitOp(OPTYPE op, ExtraArgs... args) { \
98 return static_cast<ConcreteType *>(this)->visit##OPKIND##Op(op, args...); \
99 }
100
101 HANDLE(ConstantOp, Unhandled);
102 HANDLE(SequenceOp, Unhandled);
103 HANDLE(GetSequenceOp, Unhandled);
104 HANDLE(SubstituteSequenceOp, Unhandled);
105 HANDLE(RandomizeSequenceOp, Unhandled);
106 HANDLE(InterleaveSequencesOp, Unhandled);
107 HANDLE(EmbedSequenceOp, Unhandled);
108 HANDLE(RandomNumberInRangeOp, Unhandled);
109 HANDLE(OnContextOp, Unhandled);
110 HANDLE(ContextSwitchOp, Unhandled);
111 HANDLE(SetCreateOp, Unhandled);
112 HANDLE(SetSelectRandomOp, Unhandled);
113 HANDLE(SetDifferenceOp, Unhandled);
114 HANDLE(SetUnionOp, Unhandled);
115 HANDLE(SetSizeOp, Unhandled);
116 HANDLE(SetCartesianProductOp, Unhandled);
117 HANDLE(SetConvertToBagOp, Unhandled);
118 HANDLE(BagCreateOp, Unhandled);
119 HANDLE(BagSelectRandomOp, Unhandled);
120 HANDLE(BagDifferenceOp, Unhandled);
121 HANDLE(BagUnionOp, Unhandled);
122 HANDLE(BagUniqueSizeOp, Unhandled);
123 HANDLE(BagConvertToSetOp, Unhandled);
124 HANDLE(ArrayCreateOp, Unhandled);
125 HANDLE(ArrayExtractOp, Unhandled);
126 HANDLE(ArrayInjectOp, Unhandled);
127 HANDLE(ArraySizeOp, Unhandled);
128 HANDLE(ArrayAppendOp, Unhandled);
129 HANDLE(TupleCreateOp, Unhandled);
130 HANDLE(TupleExtractOp, Unhandled);
131 HANDLE(CommentOp, Unhandled);
132 HANDLE(ConstraintOp, Unhandled);
133 HANDLE(LabelUniqueDeclOp, Unhandled);
134 HANDLE(LabelOp, Unhandled);
135 HANDLE(TestOp, Unhandled);
136 HANDLE(TargetOp, Unhandled);
137 HANDLE(YieldOp, Unhandled);
138 HANDLE(ValidateOp, Unhandled);
139 HANDLE(TestSuccessOp, Unhandled);
140 HANDLE(TestFailureOp, Unhandled);
141 HANDLE(VirtualRegisterOp, Unhandled);
142 HANDLE(RegisterToIndexOp, Unhandled);
143 HANDLE(IndexToRegisterOp, Unhandled);
144 HANDLE(IntToImmediateOp, Unhandled);
145 HANDLE(ConcatImmediateOp, Unhandled);
146 HANDLE(SliceImmediateOp, Unhandled);
147 HANDLE(MemoryBlockDeclareOp, Unhandled);
148 HANDLE(MemoryAllocOp, Unhandled);
149 HANDLE(MemoryBaseAddressOp, Unhandled);
150 HANDLE(MemorySizeOp, Unhandled);
151 HANDLE(SpaceOp, Unhandled);
152 HANDLE(StringDataOp, Unhandled);
153 HANDLE(SegmentOp, Unhandled);
154 HANDLE(StringConcatOp, Unhandled);
155 HANDLE(IntFormatOp, Unhandled);
156 HANDLE(ImmediateFormatOp, Unhandled);
157 HANDLE(RegisterFormatOp, Unhandled);
158 HANDLE(StringToLabelOp, Unhandled);
159 HANDLE(RandomScopeOp, Unhandled);
160#undef HANDLE
161};
162
163} // namespace rtg
164} // namespace circt
165
166#endif // CIRCT_DIALECT_RTG_IR_RTGVISITORS_H
This helps visit TypeOp nodes.
Definition RTGVisitors.h:25
HANDLE(ConcatImmediateOp, Unhandled)
HANDLE(SegmentOp, Unhandled)
HANDLE(ValidateOp, Unhandled)
HANDLE(MemoryAllocOp, Unhandled)
HANDLE(YieldOp, Unhandled)
HANDLE(IntFormatOp, Unhandled)
HANDLE(ConstraintOp, Unhandled)
ResultType visitExternalOp(Operation *op, ExtraArgs... args)
Definition RTGVisitors.h:92
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:83
HANDLE(BagUniqueSizeOp, Unhandled)
HANDLE(EmbedSequenceOp, Unhandled)
HANDLE(OnContextOp, Unhandled)
HANDLE(BagCreateOp, Unhandled)
HANDLE(LabelUniqueDeclOp, 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(RandomizeSequenceOp, Unhandled)
HANDLE(IntToImmediateOp, Unhandled)
HANDLE(BagConvertToSetOp, Unhandled)
HANDLE(VirtualRegisterOp, Unhandled)
HANDLE(SetConvertToBagOp, Unhandled)
HANDLE(BagDifferenceOp, Unhandled)
HANDLE(InterleaveSequencesOp, Unhandled)
HANDLE(StringToLabelOp, Unhandled)
HANDLE(ImmediateFormatOp, Unhandled)
HANDLE(RandomNumberInRangeOp, Unhandled)
HANDLE(BagUnionOp, Unhandled)
HANDLE(StringDataOp, 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:27
HANDLE(RandomScopeOp, Unhandled)
HANDLE(CommentOp, Unhandled)
HANDLE(SubstituteSequenceOp, 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(IndexToRegisterOp, Unhandled)
HANDLE(MemoryBlockDeclareOp, Unhandled)
HANDLE(ArrayExtractOp, 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.
Definition rtg.py:1