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