CIRCT  19.0.0git
FIRRTLOpInterfaces.h
Go to the documentation of this file.
1 //===- FIRRTLOpInterfaces.h - Declare FIRRTL op interfaces ------*- 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 declares the operation interfaces for the FIRRTL IR and supporting
10 // types.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef CIRCT_DIALECT_FIRRTL_OP_INTERFACES_H
15 #define CIRCT_DIALECT_FIRRTL_OP_INTERFACES_H
16 
22 #include "mlir/IR/Attributes.h"
23 #include "mlir/IR/BuiltinTypes.h"
24 #include "mlir/IR/OpDefinition.h"
25 #include "mlir/IR/SymbolTable.h"
26 #include "llvm/ADT/TypeSwitch.h"
27 
28 namespace mlir {
29 class PatternRewriter;
30 } // end namespace mlir
31 
32 namespace circt {
33 namespace firrtl {
34 
35 class FIRRTLType;
36 class Forceable;
37 class ClassLike;
38 class ClassType;
39 
40 /// This holds the name and type that describes the module's ports.
41 struct PortInfo {
42  StringAttr name;
43  Type type;
45  hw::InnerSymAttr sym = {};
46  Location loc = UnknownLoc::get(type.getContext());
48 
49  StringRef getName() const { return name ? name.getValue() : ""; }
50 
51  /// Return true if this is a simple output-only port. If you want the
52  /// direction of the port, use the \p direction parameter.
53  bool isOutput() const { return direction == Direction::Out && !isInOut(); }
54 
55  /// Return true if this is a simple input-only port. If you want the
56  /// direction of the port, use the \p direction parameter.
57  bool isInput() const { return direction == Direction::In && !isInOut(); }
58 
59  /// Return true if this is an inout port. This will be true if the port
60  /// contains either bi-directional signals or analog types.
61  /// Non-HW types (e.g., ref types) are never considered InOut.
62  bool isInOut() const { return isTypeInOut(type); }
63 
64  /// Default constructors
65  PortInfo(StringAttr name, Type type, Direction dir, StringAttr symName = {},
66  std::optional<Location> location = {},
67  std::optional<AnnotationSet> annos = {})
68  : name(name), type(type), direction(dir) {
69  if (symName)
70  sym = hw::InnerSymAttr::get(symName);
71  if (location)
72  loc = *location;
73  if (annos)
74  annotations = *annos;
75  };
76  PortInfo(StringAttr name, Type type, Direction dir, hw::InnerSymAttr sym,
77  Location loc, AnnotationSet annos)
78  : name(name), type(type), direction(dir), sym(sym), loc(loc),
79  annotations(annos) {}
80 };
81 
82 enum class ConnectBehaviorKind {
83  /// Classic FIRRTL connections: last connect 'wins' across paths;
84  /// conditionally applied under 'when'.
86  /// Exclusive connection to the destination, unconditional.
88 };
89 
90 /// Verification hook for verifying module like operations.
91 LogicalResult verifyModuleLikeOpInterface(FModuleLike module);
92 
93 namespace detail {
94 /// Return null or forceable reference result type.
95 RefType getForceableResultType(bool forceable, Type type);
96 /// Verify a Forceable op.
97 LogicalResult verifyForceableOp(Forceable op);
98 /// Replace a Forceable op with equivalent, changing whether forceable.
99 /// No-op if already has specified forceability.
100 Forceable
101 replaceWithNewForceability(Forceable op, bool forceable,
102  ::mlir::PatternRewriter *rewriter = nullptr);
103 } // end namespace detail
104 
105 //===----------------------------------------------------------------------===//
106 // ClassLike Helpers
107 //===----------------------------------------------------------------------===//
108 
109 namespace detail {
110 ClassType getInstanceTypeForClassLike(ClassLike classOp);
111 
112 /// Assuming that the classOp is the source of truth, verify that the type
113 /// accurately matches the signature of the class.
114 LogicalResult
115 verifyTypeAgainstClassLike(ClassLike classOp, ClassType type,
116  function_ref<InFlightDiagnostic()> emitError);
117 } // namespace detail
118 
119 } // namespace firrtl
120 } // namespace circt
121 
122 #include "circt/Dialect/FIRRTL/FIRRTLOpInterfaces.h.inc"
123 #endif // CIRCT_DIALECT_FIRRTL_OP_INTERFACES_H
This class provides a read-only projection over the MLIR attributes that represent a set of annotatio...
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
ClassType getInstanceTypeForClassLike(ClassLike classOp)
Definition: FIRRTLOps.cpp:1776
LogicalResult verifyForceableOp(Forceable op)
Verify a Forceable op.
LogicalResult verifyTypeAgainstClassLike(ClassLike classOp, ClassType type, function_ref< InFlightDiagnostic()> emitError)
Assuming that the classOp is the source of truth, verify that the type accurately matches the signatu...
Definition: FIRRTLOps.cpp:1729
Forceable replaceWithNewForceability(Forceable op, bool forceable, ::mlir::PatternRewriter *rewriter=nullptr)
Replace a Forceable op with equivalent, changing whether forceable.
RefType getForceableResultType(bool forceable, Type type)
Return null or forceable reference result type.
Direction
This represents the direction of a single port.
LogicalResult verifyModuleLikeOpInterface(FModuleLike module)
Verification hook for verifying module like operations.
@ LastConnect
Classic FIRRTL connections: last connect 'wins' across paths; conditionally applied under 'when'.
@ StaticSingleConnect
Exclusive connection to the destination, unconditional.
bool isTypeInOut(mlir::Type type)
Returns true if the given type has some flipped (aka unaligned) dataflow.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
This holds the name and type that describes the module's ports.
bool isOutput() const
Return true if this is a simple output-only port.
PortInfo(StringAttr name, Type type, Direction dir, hw::InnerSymAttr sym, Location loc, AnnotationSet annos)
PortInfo(StringAttr name, Type type, Direction dir, StringAttr symName={}, std::optional< Location > location={}, std::optional< AnnotationSet > annos={})
Default constructors.
StringRef getName() const
bool isInput() const
Return true if this is a simple input-only port.
bool isInOut() const
Return true if this is an inout port.