CIRCT 22.0.0git
Loading...
Searching...
No Matches
SVOps.h
Go to the documentation of this file.
1//===- SVOps.h - Declare SV dialect operations ------------------*- 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 classes for the SV dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_SV_OPS_H
14#define CIRCT_DIALECT_SV_OPS_H
15
23#include "mlir/IR/OpImplementation.h"
24#include "mlir/IR/SymbolTable.h"
25#include "mlir/Interfaces/CallInterfaces.h"
26#include "mlir/Interfaces/InferTypeOpInterface.h"
27#include "mlir/Interfaces/SideEffectInterfaces.h"
28
29namespace circt {
30namespace hw {
31class InstanceOp;
32class HWSymbolCache;
33class InnerRefAttr;
34} // namespace hw
35
36namespace sv {
37
38/// Return true if the specified operation is an expression.
39bool isExpression(Operation *op);
40
41/// Returns if the expression is known to be 2-state (binary)
42bool is2StateExpression(Value v);
43
44//===----------------------------------------------------------------------===//
45// CaseOp Support
46//===----------------------------------------------------------------------===//
47
48/// This describes the bit in a pattern, 0/1/x/z.
49enum class CasePatternBit { Zero = 0, One = 1, AnyX = 2, AnyZ = 3 };
50
51/// Return the letter for the specified pattern bit, e.g. "0", "1", "x" or "z".
53
54// This is provides convenient access to encode and decode a pattern.
56
57public:
60 virtual ~CasePattern() {}
61 CasePatternKind getKind() const { return kind; }
62
63 /// Return true if this pattern has an X.
64 virtual bool hasX() const { return false; }
65
66 /// Return true if this pattern has an Z.
67 virtual bool hasZ() const { return false; }
68
69 virtual Attribute attr() const = 0;
70
71private:
73};
74
76public:
77 using AttrType = mlir::UnitAttr;
78 CaseDefaultPattern(MLIRContext *ctx)
80 unitAttr = AttrType::get(ctx);
81 }
82
83 Attribute attr() const override { return unitAttr; }
84
85 static bool classof(const CasePattern *S) {
86 return S->getKind() == CPK_default;
87 }
88
89private:
90 // The default pattern is recognized by a UnitAttr. This is needed since we
91 // need to be able to determine the pattern type of a case based on an
92 // attribute attached to the sv.case op.
93 UnitAttr unitAttr;
94};
95
97public:
98 // Return the number of bits in the pattern.
99 size_t getWidth() const { return intAttr.getValue().getBitWidth() / 2; }
100
101 /// Return the specified bit, bit 0 is the least significant bit.
102 CasePatternBit getBit(size_t bitNumber) const;
103
104 bool hasX() const override;
105 bool hasZ() const override;
106
107 Attribute attr() const override { return intAttr; }
108
109 /// Get a CasePattern from a specified list of CasePatternBit. Bits are
110 /// specified in most least significant order - element zero is the least
111 /// significant bit.
112 CaseBitPattern(ArrayRef<CasePatternBit> bits, MLIRContext *context);
113
114 /// Get a CasePattern for the specified constant value.
115 CaseBitPattern(const APInt &value, MLIRContext *context);
116
117 /// Get a CasePattern with a correctly encoded attribute.
119
120 static bool classof(const CasePattern *S) { return S->getKind() == CPK_bit; }
121
122private:
123 IntegerAttr intAttr;
124};
125
127public:
128 // Get a CasePattern for the specified enum value attribute.
129 CaseEnumPattern(hw::EnumFieldAttr attr)
131
132 // Return the named value of this enumeration.
133 StringRef getFieldValue() const;
134
135 Attribute attr() const override { return enumAttr; }
136
137 static bool classof(const CasePattern *S) { return S->getKind() == CPK_enum; }
138
139private:
140 hw::EnumFieldAttr enumAttr;
141};
142
143// This provides information about one case.
144struct CaseInfo {
145 std::unique_ptr<CasePattern> pattern;
146 Block *block;
147};
148
149//===----------------------------------------------------------------------===//
150// Other Supporting Logic
151//===----------------------------------------------------------------------===//
152
153/// Return true if the specified operation is in a procedural region.
154LogicalResult verifyInProceduralRegion(Operation *op);
155/// Return true if the specified operation is not in a procedural region.
156LogicalResult verifyInNonProceduralRegion(Operation *op);
157
158/// Signals that an operations regions are procedural.
159template <typename ConcreteType>
161 : public mlir::OpTrait::TraitBase<ConcreteType, ProceduralRegion> {
162 static LogicalResult verifyTrait(Operation *op) {
163 return mlir::OpTrait::impl::verifyAtLeastNRegions(op, 1);
164 }
165};
166
167/// This class verifies that the specified op is located in a procedural region.
168template <typename ConcreteType>
170 : public mlir::OpTrait::TraitBase<ConcreteType, ProceduralOp> {
171public:
172 static LogicalResult verifyTrait(Operation *op) {
173 return verifyInProceduralRegion(op);
174 }
175};
176
177/// This class verifies that the specified op is not located in a procedural
178/// region.
179template <typename ConcreteType>
181 : public mlir::OpTrait::TraitBase<ConcreteType, NonProceduralOp> {
182public:
183 static LogicalResult verifyTrait(Operation *op) {
185 }
186};
187
188/// This class provides a verifier for ops that are expecting their parent
189/// to be one of the given parent ops
190template <typename ConcreteType>
192 : public mlir::OpTrait::TraitBase<ConcreteType, VendorExtension> {
193public:
194 static LogicalResult verifyTrait(Operation *op) { return success(); }
195};
196
197} // namespace sv
198} // namespace circt
199
200#define GET_OP_CLASSES
201#include "circt/Dialect/SV/SV.h.inc"
202
203#endif // CIRCT_DIALECT_SV_OPS_H
CaseBitPattern(IntegerAttr attr)
Get a CasePattern with a correctly encoded attribute.
Definition SVOps.h:118
IntegerAttr intAttr
Definition SVOps.h:123
CasePatternBit getBit(size_t bitNumber) const
Return the specified bit, bit 0 is the least significant bit.
Definition SVOps.cpp:785
bool hasZ() const override
Return true if this pattern has an Z.
Definition SVOps.cpp:797
static bool classof(const CasePattern *S)
Definition SVOps.h:120
Attribute attr() const override
Definition SVOps.h:107
bool hasX() const override
Return true if this pattern has an X.
Definition SVOps.cpp:790
size_t getWidth() const
Definition SVOps.h:99
static bool classof(const CasePattern *S)
Definition SVOps.h:85
Attribute attr() const override
Definition SVOps.h:83
CaseDefaultPattern(MLIRContext *ctx)
Definition SVOps.h:78
mlir::UnitAttr AttrType
Definition SVOps.h:77
static bool classof(const CasePattern *S)
Definition SVOps.h:137
CaseEnumPattern(hw::EnumFieldAttr attr)
Definition SVOps.h:129
hw::EnumFieldAttr enumAttr
Definition SVOps.h:140
StringRef getFieldValue() const
Definition SVOps.cpp:860
Attribute attr() const override
Definition SVOps.h:135
CasePatternKind getKind() const
Definition SVOps.h:61
CasePattern(CasePatternKind kind)
Definition SVOps.h:59
const CasePatternKind kind
Definition SVOps.h:72
virtual ~CasePattern()
Definition SVOps.h:60
virtual bool hasZ() const
Return true if this pattern has an Z.
Definition SVOps.h:67
virtual Attribute attr() const =0
virtual bool hasX() const
Return true if this pattern has an X.
Definition SVOps.h:64
This class verifies that the specified op is not located in a procedural region.
Definition SVOps.h:181
static LogicalResult verifyTrait(Operation *op)
Definition SVOps.h:183
This class verifies that the specified op is located in a procedural region.
Definition SVOps.h:170
static LogicalResult verifyTrait(Operation *op)
Definition SVOps.h:172
Signals that an operations regions are procedural.
Definition SVOps.h:161
static LogicalResult verifyTrait(Operation *op)
Definition SVOps.h:162
This class provides a verifier for ops that are expecting their parent to be one of the given parent ...
Definition SVOps.h:192
static LogicalResult verifyTrait(Operation *op)
Definition SVOps.h:194
LogicalResult verifyInNonProceduralRegion(Operation *op)
Return true if the specified operation is not in a procedural region.
Definition SVOps.cpp:63
CasePatternBit
This describes the bit in a pattern, 0/1/x/z.
Definition SVOps.h:49
bool isExpression(Operation *op)
Return true if the specified operation is an expression.
Definition SVOps.cpp:50
char getLetter(CasePatternBit bit)
Return the letter for the specified pattern bit, e.g. "0", "1", "x" or "z".
Definition SVOps.cpp:770
bool is2StateExpression(Value v)
Returns if the expression is known to be 2-state (binary)
Definition SVOps.cpp:40
LogicalResult verifyInProceduralRegion(Operation *op)
Return true if the specified operation is in a procedural region.
Definition SVOps.cpp:56
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition hw.py:1
Definition sv.py:1
std::unique_ptr< CasePattern > pattern
Definition SVOps.h:145