CIRCT  19.0.0git
CHIRRTLVisitors.h
Go to the documentation of this file.
1 //===- CHIRRTLVisitors.h - CHIRRTL 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 CHIRRTL IR.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_FIRRTL_CHIRRTLVISITORS_H
14 #define CIRCT_DIALECT_FIRRTL_CHIRRTLVISITORS_H
15 
18 #include "llvm/ADT/TypeSwitch.h"
19 
20 namespace circt {
21 namespace chirrtl {
22 
23 /// CHIRRTLVisitor is a visitor for CHIRRTL operations.
24 template <typename ConcreteType, typename ResultType = void,
25  typename... ExtraArgs>
27 public:
28  ResultType dispatchCHIRRTLVisitor(Operation *op, ExtraArgs... args) {
29  auto *thisCast = static_cast<ConcreteType *>(this);
30  return TypeSwitch<Operation *, ResultType>(op)
31  .template Case<CombMemOp, MemoryPortOp, MemoryDebugPortOp,
32  MemoryPortAccessOp, SeqMemOp>(
33  [&](auto opNode) -> ResultType {
34  return thisCast->visitCHIRRTL(opNode, args...);
35  })
36  .Default([&](auto expr) -> ResultType {
37  return thisCast->visitInvalidCHIRRTL(op, args...);
38  });
39  }
40 
41  /// This callback is invoked on any non-CHIRRTL operations.
42  ResultType visitInvalidCHIRRTL(Operation *op, ExtraArgs... args) {
43  op->emitOpError("unknown chirrtl op");
44  abort();
45  }
46 
47  /// This callback is invoked on any CHIRRTL operations that are not handled
48  /// by the concrete visitor.
49  ResultType visitUnhandledCHIRRTL(Operation *op, ExtraArgs... args) {
50  return ResultType();
51  }
52 
53 #define HANDLE(OPTYPE) \
54  ResultType visitCHIRRTL(OPTYPE op, ExtraArgs... args) { \
55  return static_cast<ConcreteType *>(this)->visitUnhandledCHIRRTL(op, \
56  args...); \
57  }
58 
59  HANDLE(CombMemOp);
60  HANDLE(MemoryPortOp);
61  HANDLE(MemoryDebugPortOp);
62  HANDLE(MemoryPortAccessOp);
63  HANDLE(SeqMemOp);
64 #undef HANDLE
65 };
66 
67 } // namespace chirrtl
68 } // namespace circt
69 
70 #endif // CIRCT_DIALECT_FIRRTL_CHIRRTLVISITORS_H
CHIRRTLVisitor is a visitor for CHIRRTL operations.
ResultType visitUnhandledCHIRRTL(Operation *op, ExtraArgs... args)
This callback is invoked on any CHIRRTL operations that are not handled by the concrete visitor.
ResultType visitInvalidCHIRRTL(Operation *op, ExtraArgs... args)
This callback is invoked on any non-CHIRRTL operations.
ResultType dispatchCHIRRTLVisitor(Operation *op, ExtraArgs... args)
HANDLE(MemoryPortAccessOp)
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21