13 #ifndef CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
14 #define CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "mlir/IR/BuiltinTypes.h"
19 #include "llvm/ADT/STLExtras.h"
20 #include "llvm/Support/PointerLikeTypeTraits.h"
24 struct InnerSymbolNamespace;
28 class AnnotationSetIterator;
59 auto oldFieldID = anno.
getMember<IntegerAttr>(
"circt.fieldID");
60 if (oldFieldID && !fieldID) {
74 void setDict(DictionaryAttr dict);
87 template <
typename... Args>
93 template <
typename AttrClass = Attribute>
95 return getDict().getAs<AttrClass>(name);
97 template <
typename AttrClass = Attribute>
99 return getDict().getAs<AttrClass>(name);
103 void setMember(StringAttr name, Attribute value);
104 void setMember(StringRef name, Attribute value);
114 using iterator = llvm::ArrayRef<NamedAttribute>::iterator;
120 explicit operator bool()
const {
return bool(
attr); }
133 template <
typename T,
typename... Rest>
135 return compare(name) || (*this)(rest...);
140 bool compare(StringRef name)
const {
return cls &&
cls.getValue() == name; }
161 MLIRContext *context);
196 bool applyToPort(FModuleLike op,
size_t portNo)
const;
282 static bool setDontTouch(Operation *op,
bool dontTouch);
294 return !(*
this == other);
321 template <
typename... Args>
333 llvm::function_ref<
bool(
Annotation)> predicate);
343 llvm::function_ref<
bool(
unsigned,
Annotation)> predicate);
356 :
public llvm::indexed_accessor_iterator<AnnotationSetIterator,
357 AnnotationSet, Annotation,
358 Annotation, Annotation> {
390 operator bool()
const {
return getOp(); }
395 return !(*
this == other);
418 template <
typename U>
420 assert(*
this &&
"isa<> used on a null type.");
421 return U::classof(*
this);
423 template <
typename U>
425 return isa<U>() ? U(
impl) : U(
nullptr);
427 template <
typename U>
429 return (*
this && isa<U>()) ? U(
impl) : U(
nullptr);
431 template <
typename U>
437 operator bool()
const {
return impl; }
514 LogicalResult
extractDUT(FModuleOp mod, FModuleOp &dut);
531 return const_cast<void *
>(v.
getAttr().getAsOpaquePointer());
534 return Annotation(mlir::DictionaryAttr::getFromOpaquePointer(p));
540 struct DenseMapInfo<
circt::firrtl::Annotation> {
544 mlir::DictionaryAttr(
static_cast<mlir::Attribute::ImplType *
>(
545 DenseMapInfo<void *>::getEmptyKey())));
549 mlir::DictionaryAttr(
static_cast<mlir::Attribute::ImplType *
>(
550 llvm::DenseMapInfo<void *>::getTombstoneKey())));
560 struct DenseMapInfo<
circt::firrtl::AnnoTarget> {
564 auto *o = DenseMapInfo<mlir::Operation *>::getEmptyKey();
565 auto i = DenseMapInfo<unsigned>::getEmptyKey();
569 auto *o = DenseMapInfo<mlir::Operation *>::getTombstoneKey();
570 auto i = DenseMapInfo<unsigned>::getTombstoneKey();
575 return hash_combine(impl.getOp(), impl.getPortNo());
assert(baseType &&"element must be base type")
friend class AnnotationSet
AnnotationSetIterator(AnnotationSet owner, ptrdiff_t curIndex)
Annotation operator*() const
This class provides a read-only projection over the MLIR attributes that represent a set of annotatio...
bool hasDontTouch() const
firrtl.transforms.DontTouchAnnotation
bool hasAnnotationImpl(StringAttr className) const
bool removeAnnotations(llvm::function_ref< bool(Annotation)> predicate)
Remove all annotations from this annotation set for which predicate returns true.
bool applyToPortAttrList(NamedAttrList &attrs) const
Store the annotations in this set in a NamedAttrList as an array attribute with the name firrtl....
Annotation getAnnotationImpl(StringAttr className) const
bool applyToPort(FModuleLike op, size_t portNo) const
Store the annotations in this set in an operation's portAnnotations attribute, overwriting any existi...
ArrayAttr getArrayAttr() const
Return this annotation set as an ArrayAttr.
AnnotationSet(ArrayAttr annotations)
Form an annotation set with a non-null ArrayAttr.
bool removeAnnotation(Annotation anno)
Remove an annotation from this annotation set.
bool removeAnnotationsWithClass(Args... names)
Remove all annotations with one of the given classes from this annotation set.
static AnnotationSet get(Value v)
Get an annotation set for the specified value.
bool applyToAttrList(NamedAttrList &attrs) const
Store the annotations in this set in a NamedAttrList as an array attribute with the name annotations.
DictionaryAttr applyToDictionaryAttr(DictionaryAttr attrs) const
Insert this annotation set into a DictionaryAttr under the annotations key.
Annotation getAnnotation(StringAttr className) const
bool hasAnnotation(StringAttr className) const
bool operator!=(const AnnotationSet &other) const
bool applyToOperation(Operation *op) const
Store the annotations in this set in an operation's annotations attribute, overwriting any existing a...
void addAnnotations(ArrayRef< Annotation > annotations)
Add more annotations to this annotation set.
bool hasAnnotation(StringRef className) const
Return true if we have an annotation with the specified class name.
AnnotationSet(MLIRContext *context)
Form an empty annotation set.
static bool removePortAnnotations(Operation *module, llvm::function_ref< bool(unsigned, Annotation)> predicate)
Remove all port annotations from a module or extmodule for which predicate returns true.
static AnnotationSet forPort(FModuleLike op, size_t portNo)
Get an annotation set for the specified port.
Annotation getAnnotation(StringRef className) const
If this annotation set has an annotation with the specified class name, return it.
bool canBeDeleted() const
Check if every annotation can be deleted.
bool operator==(const AnnotationSet &other) const
bool setDontTouch(bool dontTouch)
ArrayRef< Attribute > getArray() const
Return all the raw annotations that exist.
AnnotationSetIterator iterator
MLIRContext * getContext() const
Return the MLIRContext corresponding to this AnnotationSet.
DictionaryAttr applyToPortDictionaryAttr(DictionaryAttr attrs) const
Insert this annotation set into a DictionaryAttr under the firrtl.annotations key.
This class provides a read-only projection of an annotation.
Attribute getAttr() const
Get the underlying attribute.
DictionaryAttr getDict() const
Get the data dictionary of this attribute.
void setDict(DictionaryAttr dict)
Set the data dictionary of this attribute.
bool operator==(const Annotation &other) const
unsigned getFieldID() const
Get the field id this attribute targets.
AttrClass getMember(StringAttr name) const
Return a member of the annotation.
void setMember(StringAttr name, Attribute value)
Add or set a member of the annotation to a value.
Annotation(Annotation anno, uint64_t fieldID)
bool canBeDeleted()
Returns true if this is an annotation which can be safely deleted without consequence.
void removeMember(StringAttr name)
Remove a member of the annotation.
bool operator!=(const Annotation &other) const
AttrClass getMember(StringRef name) const
StringRef getClass() const
Return the 'class' that this annotation is representing.
Annotation(Attribute attr)
StringAttr getClassAttr() const
Return the 'class' that this annotation is representing.
llvm::ArrayRef< NamedAttribute >::iterator iterator
bool isClass(Args... names) const
Return true if this annotation matches any of the specified class names.
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
StringRef getAnnotationAttrName()
Return the name of the attribute used for annotations on FIRRTL ops.
LogicalResult extractDUT(FModuleOp mod, FModuleOp &dut)
Utility that searches for a MarkDUTAnnotation on a specific module, mod, and tries to update a design...
bool isOMIRStringEncodedPassthrough(StringRef type)
Check if an OMIR type is a string-encoded value that the FIRRTL dialect simply passes through as a st...
StringRef getDialectAnnotationAttrName()
Return the name of the dialect-prefixed attribute used for annotations.
StringRef getPortAnnotationAttrName()
Return the name of the attribute used for port annotations on FIRRTL ops.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
llvm::hash_code hash_value(const T &e)
An annotation target is used to keep track of something that is targeted by an Annotation.
void setOp(Operation *op)
FIRRTLType getType() const
Get the type of the target.
U dyn_cast_or_null() const
bool operator!=(const AnnoTarget &other) const
Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const
Get a reference to this target suitable for use in an NLA.
detail::AnnoTargetImpl getImpl() const
detail::AnnoTargetImpl impl
Operation * getOp() const
FModuleLike getModule() const
Get the parent module of the target.
AnnotationSet getAnnotations() const
Get the annotations associated with the target.
void setAnnotations(AnnotationSet annotations) const
Set the annotations associated with the target.
bool operator==(const AnnoTarget &other) const
AnnoTarget(detail::AnnoTargetImpl impl=nullptr)
Helper struct to perform variadic class equality check.
bool compare(StringRef name) const
bool compare(StringAttr name) const
bool operator()(T name, Rest... rest) const
This represents an annotation targeting a specific operation.
Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const
OpAnnoTarget(Operation *op)
void setAnnotations(AnnotationSet annotations) const
FIRRTLType getType() const
static bool classof(const AnnoTarget &annoTarget)
AnnotationSet getAnnotations() const
This represents an annotation targeting a specific port of a module, memory, or instance.
static bool classof(const AnnoTarget &annoTarget)
FIRRTLType getType() const
void setPortNo(unsigned portNo)
AnnotationSet getAnnotations() const
void setAnnotations(AnnotationSet annotations) const
Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const
unsigned getPortNo() const
PortAnnoTarget(FModuleLike op, unsigned portNo)
Operation * getOp() const
bool operator!=(const AnnoTargetImpl &other) const
void setOp(Operation *op)
bool operator==(const AnnoTargetImpl &other) const
unsigned getPortNo() const
AnnoTargetImpl(Operation *op)
AnnoTargetImpl(Operation *op, unsigned portNo)
void setPortNo(unsigned portNo)
static bool isEqual(AnnoTarget lhs, AnnoTarget rhs)
static AnnoTarget getTombstoneKey()
static unsigned getHashValue(AnnoTarget val)
static AnnoTarget getEmptyKey()
static unsigned getHashValue(Annotation val)
static bool isEqual(Annotation LHS, Annotation RHS)
static Annotation getEmptyKey()
static Annotation getTombstoneKey()
static Annotation getFromVoidPointer(void *p)
static void * getAsVoidPointer(Annotation v)