CIRCT  19.0.0git
CombVisitors.h
Go to the documentation of this file.
1 //===- CombVisitors.h - Comb 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 the Comb IR.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_COMB_COMBVISITORS_H
14 #define CIRCT_DIALECT_COMB_COMBVISITORS_H
15 
17 #include "llvm/ADT/TypeSwitch.h"
18 
19 namespace circt {
20 namespace comb {
21 
22 /// This helps visit Combinational nodes.
23 template <typename ConcreteType, typename ResultType = void,
24  typename... ExtraArgs>
26 public:
27  ResultType dispatchCombinationalVisitor(Operation *op, ExtraArgs... args) {
28  auto *thisCast = static_cast<ConcreteType *>(this);
29  return TypeSwitch<Operation *, ResultType>(op)
30  .template Case<
31  // Arithmetic and Logical Binary Operations.
32  AddOp, SubOp, MulOp, DivUOp, DivSOp, ModUOp, ModSOp, ShlOp, ShrUOp,
33  ShrSOp,
34  // Bitwise operations
35  AndOp, OrOp, XorOp,
36  // Comparison operations
37  ICmpOp,
38  // Reduction Operators
39  ParityOp,
40  // Other operations.
41  ConcatOp, ReplicateOp, ExtractOp, MuxOp>(
42  [&](auto expr) -> ResultType {
43  return thisCast->visitComb(expr, args...);
44  })
45  .Default([&](auto expr) -> ResultType {
46  return thisCast->visitInvalidComb(op, args...);
47  });
48  }
49 
50  /// This callback is invoked on any non-expression operations.
51  ResultType visitInvalidComb(Operation *op, ExtraArgs... args) {
52  op->emitOpError("unknown combinational node");
53  abort();
54  }
55 
56  /// This callback is invoked on any combinational operations that are not
57  /// handled by the concrete visitor.
58  ResultType visitUnhandledComb(Operation *op, ExtraArgs... args) {
59  return ResultType();
60  }
61 
62  /// This fallback is invoked on any binary node that isn't explicitly handled.
63  /// The default implementation delegates to the 'unhandled' fallback.
64  ResultType visitBinaryComb(Operation *op, ExtraArgs... args) {
65  return static_cast<ConcreteType *>(this)->visitUnhandledComb(op, args...);
66  }
67 
68  ResultType visitUnaryComb(Operation *op, ExtraArgs... args) {
69  return static_cast<ConcreteType *>(this)->visitUnhandledComb(op, args...);
70  }
71 
72  ResultType visitVariadicComb(Operation *op, ExtraArgs... args) {
73  return static_cast<ConcreteType *>(this)->visitUnhandledComb(op, args...);
74  }
75 
76 #define HANDLE(OPTYPE, OPKIND) \
77  ResultType visitComb(OPTYPE op, ExtraArgs... args) { \
78  return static_cast<ConcreteType *>(this)->visit##OPKIND##Comb(op, \
79  args...); \
80  }
81 
82  // Arithmetic and Logical Binary Operations.
83  HANDLE(AddOp, Binary);
84  HANDLE(SubOp, Binary);
85  HANDLE(MulOp, Binary);
86  HANDLE(DivUOp, Binary);
87  HANDLE(DivSOp, Binary);
88  HANDLE(ModUOp, Binary);
89  HANDLE(ModSOp, Binary);
90  HANDLE(ShlOp, Binary);
91  HANDLE(ShrUOp, Binary);
92  HANDLE(ShrSOp, Binary);
93 
94  HANDLE(AndOp, Variadic);
95  HANDLE(OrOp, Variadic);
96  HANDLE(XorOp, Variadic);
97 
98  HANDLE(ParityOp, Unary);
99 
100  HANDLE(ICmpOp, Binary);
101 
102  // Other operations.
103  HANDLE(ConcatOp, Unhandled);
104  HANDLE(ReplicateOp, Unhandled);
105  HANDLE(ExtractOp, Unhandled);
106  HANDLE(MuxOp, Unhandled);
107 #undef HANDLE
108 };
109 
110 } // namespace comb
111 } // namespace circt
112 
113 #endif // CIRCT_DIALECT_COMB_COMBVISITORS_H
This helps visit Combinational nodes.
Definition: CombVisitors.h:25
HANDLE(ReplicateOp, Unhandled)
HANDLE(ExtractOp, Unhandled)
ResultType visitUnaryComb(Operation *op, ExtraArgs... args)
Definition: CombVisitors.h:68
ResultType visitVariadicComb(Operation *op, ExtraArgs... args)
Definition: CombVisitors.h:72
ResultType visitBinaryComb(Operation *op, ExtraArgs... args)
This fallback is invoked on any binary node that isn't explicitly handled.
Definition: CombVisitors.h:64
ResultType visitInvalidComb(Operation *op, ExtraArgs... args)
This callback is invoked on any non-expression operations.
Definition: CombVisitors.h:51
ResultType visitUnhandledComb(Operation *op, ExtraArgs... args)
This callback is invoked on any combinational operations that are not handled by the concrete visitor...
Definition: CombVisitors.h:58
ResultType dispatchCombinationalVisitor(Operation *op, ExtraArgs... args)
Definition: CombVisitors.h:27
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: comb.py:1