CIRCT  19.0.0git
SVAttributes.h
Go to the documentation of this file.
1 //===- SVAttributes.h - Declare SV dialect attributes ------------*- 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 #ifndef CIRCT_DIALECT_SV_SVATTRIBUTES_H
10 #define CIRCT_DIALECT_SV_SVATTRIBUTES_H
11 
12 #include "mlir/IR/Attributes.h"
13 #include "mlir/IR/BuiltinAttributes.h"
14 #include "llvm/ADT/ArrayRef.h"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/SmallVector.h"
17 
18 #include "circt/Dialect/SV/SVEnums.h.inc"
19 #define GET_ATTRDEF_CLASSES
20 #include "circt/Dialect/SV/SVAttributes.h.inc"
21 
22 namespace circt {
23 namespace sv {
24 
25 /// Helper functions to handle SV attributes.
26 bool hasSVAttributes(mlir::Operation *op);
27 
28 /// Return all the SV attributes of an operation, or null if there are none. All
29 /// array elements are `SVAttributeAttr`.
30 mlir::ArrayAttr getSVAttributes(mlir::Operation *op);
31 
32 /// Set the SV attributes of an operation. If `attrs` is null or contains no
33 /// attributes, the attribute is removed from the op.
34 void setSVAttributes(mlir::Operation *op, mlir::ArrayAttr attrs);
35 
36 /// Set the SV attributes of an operation. If `attrs` is empty the attribute is
37 /// removed from the op. The attributes are deduplicated such that only one copy
38 /// of each attribute is kept on the operation.
39 void setSVAttributes(mlir::Operation *op,
40  mlir::ArrayRef<SVAttributeAttr> attrs);
41 
42 /// Check if an op contains a specific SV attribute.
43 inline bool hasSVAttribute(mlir::Operation *op, SVAttributeAttr attr) {
44  return llvm::is_contained(getSVAttributes(op), attr);
45 }
46 
47 /// Modify the list of SV attributes of an operation. This function offers a
48 /// read-modify-write interface where the callback can modify the list of
49 /// attributes how it sees fit. Returns true if any modifications occurred.
51  mlir::Operation *op,
52  llvm::function_ref<void(llvm::SmallVectorImpl<SVAttributeAttr> &)>
53  modifyCallback);
54 
55 /// Add a list of SV attributes to an operation. The attributes are deduplicated
56 /// such that only one copy of each attribute is kept on the operation. Returns
57 /// the number of attributes that were added.
58 unsigned addSVAttributes(mlir::Operation *op,
59  llvm::ArrayRef<SVAttributeAttr> attrs);
60 
61 /// Remove the SV attributes from an operation for which `removeCallback`
62 /// returns true. Returns the number of attributes actually removed.
63 unsigned
64 removeSVAttributes(mlir::Operation *op,
65  llvm::function_ref<bool(SVAttributeAttr)> removeCallback);
66 
67 /// Remove a list of SV attributes from an operation. Returns the number of
68 /// attributes actually removed.
69 unsigned removeSVAttributes(mlir::Operation *op,
70  llvm::ArrayRef<SVAttributeAttr> attrs);
71 
72 } // namespace sv
73 } // namespace circt
74 
75 #endif // CIRCT_DIALECT_SV_SVATTRIBUTES_H
mlir::ArrayAttr getSVAttributes(mlir::Operation *op)
Return all the SV attributes of an operation, or null if there are none.
unsigned removeSVAttributes(mlir::Operation *op, llvm::function_ref< bool(SVAttributeAttr)> removeCallback)
Remove the SV attributes from an operation for which removeCallback returns true.
bool modifySVAttributes(mlir::Operation *op, llvm::function_ref< void(llvm::SmallVectorImpl< SVAttributeAttr > &)> modifyCallback)
Modify the list of SV attributes of an operation.
bool hasSVAttributes(mlir::Operation *op)
Helper functions to handle SV attributes.
unsigned addSVAttributes(mlir::Operation *op, llvm::ArrayRef< SVAttributeAttr > attrs)
Add a list of SV attributes to an operation.
bool hasSVAttribute(mlir::Operation *op, SVAttributeAttr attr)
Check if an op contains a specific SV attribute.
Definition: SVAttributes.h:43
void setSVAttributes(mlir::Operation *op, mlir::ArrayAttr attrs)
Set the SV attributes of an operation.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21
Definition: sv.py:1