13 #ifndef CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
14 #define CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Support/PointerLikeTypeTraits.h"
23 struct InnerSymbolNamespace;
27 class AnnotationSetIterator;
60 void setDict(DictionaryAttr dict);
73 template <
typename... Args>
79 template <
typename AttrClass = Attribute>
81 return getDict().getAs<AttrClass>(name);
83 template <
typename AttrClass = Attribute>
85 return getDict().getAs<AttrClass>(name);
100 using iterator = llvm::ArrayRef<NamedAttribute>::iterator;
106 explicit operator bool()
const {
return bool(
attr); }
119 template <
typename T,
typename... Rest>
121 return compare(name) || (*this)(rest...);
126 bool compare(StringRef name)
const {
return cls &&
cls.getValue() == name; }
145 MLIRContext *context);
180 bool applyToPort(FModuleLike op,
size_t portNo)
const;
266 static bool setDontTouch(Operation *op,
bool dontTouch);
278 return !(*
this == other);
305 template <
typename... Args>
317 llvm::function_ref<
bool(
Annotation)> predicate);
327 llvm::function_ref<
bool(
unsigned,
Annotation)> predicate);
340 :
public llvm::indexed_accessor_iterator<AnnotationSetIterator,
341 AnnotationSet, Annotation,
342 Annotation, Annotation> {
374 operator bool()
const {
return getOp(); }
379 return !(*
this == other);
402 template <
typename U>
404 assert(*
this &&
"isa<> used on a null type.");
405 return U::classof(*
this);
407 template <
typename U>
409 return isa<U>() ? U(
impl) : U(
nullptr);
411 template <
typename U>
413 return (*
this && isa<U>()) ? U(
impl) : U(
nullptr);
415 template <
typename U>
421 operator bool()
const {
return impl; }
498 LogicalResult
extractDUT(FModuleOp mod, FModuleOp &dut);
515 return const_cast<void *
>(v.
getAttr().getAsOpaquePointer());
518 return Annotation(mlir::DictionaryAttr::getFromOpaquePointer(p));
524 struct DenseMapInfo<
circt::firrtl::Annotation> {
528 mlir::DictionaryAttr(
static_cast<mlir::Attribute::ImplType *
>(
529 DenseMapInfo<void *>::getEmptyKey())));
533 mlir::DictionaryAttr(
static_cast<mlir::Attribute::ImplType *
>(
534 llvm::DenseMapInfo<void *>::getTombstoneKey())));
544 struct DenseMapInfo<
circt::firrtl::AnnoTarget> {
548 auto *o = DenseMapInfo<mlir::Operation *>::getEmptyKey();
549 auto i = DenseMapInfo<unsigned>::getEmptyKey();
553 auto *o = DenseMapInfo<mlir::Operation *>::getTombstoneKey();
554 auto i = DenseMapInfo<unsigned>::getTombstoneKey();
559 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.
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.
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.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
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)