CIRCT  19.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
circt::firrtl::AnnotationSet Class Reference

This class provides a read-only projection over the MLIR attributes that represent a set of annotations. More...

#include <FIRRTLAnnotations.h>

Collaboration diagram for circt::firrtl::AnnotationSet:
Collaboration graph
[legend]

Public Types

using ElementType = Annotation
 
using iterator = AnnotationSetIterator
 

Public Member Functions

 AnnotationSet (MLIRContext *context)
 Form an empty annotation set. More...
 
 AnnotationSet (ArrayRef< Attribute > annotations, MLIRContext *context)
 Form an annotation set from an array of annotation attributes. More...
 
 AnnotationSet (ArrayRef< Annotation > annotations, MLIRContext *context)
 Form an annotation set from an array of annotations. More...
 
 AnnotationSet (ArrayAttr annotations)
 Form an annotation set with a non-null ArrayAttr. More...
 
 AnnotationSet (ArrayAttr annotations, MLIRContext *context)
 Form an annotation set with a possibly-null ArrayAttr. More...
 
 AnnotationSet (Operation *op)
 Get an annotation set for the specified operation. More...
 
ArrayRef< Attribute > getArray () const
 Return all the raw annotations that exist. More...
 
ArrayAttr getArrayAttr () const
 Return this annotation set as an ArrayAttr. More...
 
bool applyToOperation (Operation *op) const
 Store the annotations in this set in an operation's annotations attribute, overwriting any existing annotations. More...
 
bool applyToPort (FModuleLike op, size_t portNo) const
 Store the annotations in this set in an operation's portAnnotations attribute, overwriting any existing annotations for this port. More...
 
bool applyToPort (MemOp op, size_t portNo) const
 
bool applyToAttrList (NamedAttrList &attrs) const
 Store the annotations in this set in a NamedAttrList as an array attribute with the name annotations. More...
 
bool applyToPortAttrList (NamedAttrList &attrs) const
 Store the annotations in this set in a NamedAttrList as an array attribute with the name firrtl.annotations. More...
 
DictionaryAttr applyToDictionaryAttr (DictionaryAttr attrs) const
 Insert this annotation set into a DictionaryAttr under the annotations key. More...
 
DictionaryAttr applyToDictionaryAttr (ArrayRef< NamedAttribute > attrs) const
 
DictionaryAttr applyToPortDictionaryAttr (DictionaryAttr attrs) const
 Insert this annotation set into a DictionaryAttr under the firrtl.annotations key. More...
 
DictionaryAttr applyToPortDictionaryAttr (ArrayRef< NamedAttribute > attrs) const
 
bool hasAnnotation (StringRef className) const
 Return true if we have an annotation with the specified class name. More...
 
bool hasAnnotation (StringAttr className) const
 
Annotation getAnnotation (StringRef className) const
 If this annotation set has an annotation with the specified class name, return it. More...
 
Annotation getAnnotation (StringAttr className) const
 
iterator begin () const
 
iterator end () const
 
MLIRContext * getContext () const
 Return the MLIRContext corresponding to this AnnotationSet. More...
 
bool hasDontTouch () const
 firrtl.transforms.DontTouchAnnotation More...
 
bool setDontTouch (bool dontTouch)
 
bool addDontTouch ()
 
bool removeDontTouch ()
 
bool canBeDeleted () const
 Check if every annotation can be deleted. More...
 
bool operator== (const AnnotationSet &other) const
 
bool operator!= (const AnnotationSet &other) const
 
bool empty () const
 
size_t size () const
 
void addAnnotations (ArrayRef< Annotation > annotations)
 Add more annotations to this annotation set. More...
 
void addAnnotations (ArrayRef< Attribute > annotations)
 
void addAnnotations (ArrayAttr annotations)
 
bool removeAnnotation (Annotation anno)
 Remove an annotation from this annotation set. More...
 
bool removeAnnotation (Attribute anno)
 Remove an annotation from this annotation set. More...
 
bool removeAnnotation (StringRef className)
 Remove an annotation from this annotation set. More...
 
bool removeAnnotations (llvm::function_ref< bool(Annotation)> predicate)
 Remove all annotations from this annotation set for which predicate returns true. More...
 
template<typename... Args>
bool removeAnnotationsWithClass (Args... names)
 Remove all annotations with one of the given classes from this annotation set. More...
 

Static Public Member Functions

static AnnotationSet forPort (FModuleLike op, size_t portNo)
 Get an annotation set for the specified port. More...
 
static AnnotationSet forPort (MemOp op, size_t portNo)
 
static AnnotationSet get (Value v)
 Get an annotation set for the specified value. More...
 
static bool hasDontTouch (Operation *op)
 
static bool setDontTouch (Operation *op, bool dontTouch)
 
static bool addDontTouch (Operation *op)
 
static bool removeDontTouch (Operation *op)
 
static bool canBeDeleted (Operation *op)
 
static bool removeAnnotations (Operation *op, llvm::function_ref< bool(Annotation)> predicate)
 Remove all annotations from an operation for which predicate returns true. More...
 
static bool removeAnnotations (Operation *op, StringRef className)
 
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. More...
 

Private Member Functions

bool hasAnnotationImpl (StringAttr className) const
 
bool hasAnnotationImpl (StringRef className) const
 
Annotation getAnnotationImpl (StringAttr className) const
 
Annotation getAnnotationImpl (StringRef className) const
 

Private Attributes

ArrayAttr annotations
 

Detailed Description

This class provides a read-only projection over the MLIR attributes that represent a set of annotations.

It is intended to make this work less stringly typed and fiddly for clients.

Definition at line 148 of file FIRRTLAnnotations.h.

Member Typedef Documentation

◆ ElementType

Definition at line 150 of file FIRRTLAnnotations.h.

◆ iterator

Definition at line 267 of file FIRRTLAnnotations.h.

Constructor & Destructor Documentation

◆ AnnotationSet() [1/6]

circt::firrtl::AnnotationSet::AnnotationSet ( MLIRContext *  context)
inlineexplicit

Form an empty annotation set.

Definition at line 153 of file FIRRTLAnnotations.h.

Referenced by canBeDeleted(), get(), hasDontTouch(), and removePortAnnotations().

◆ AnnotationSet() [2/6]

AnnotationSet::AnnotationSet ( ArrayRef< Attribute >  annotations,
MLIRContext *  context 
)
explicit

Form an annotation set from an array of annotation attributes.

Definition at line 46 of file FIRRTLAnnotations.cpp.

◆ AnnotationSet() [3/6]

AnnotationSet::AnnotationSet ( ArrayRef< Annotation annotations,
MLIRContext *  context 
)
explicit

Form an annotation set from an array of annotations.

Definition at line 51 of file FIRRTLAnnotations.cpp.

◆ AnnotationSet() [4/6]

circt::firrtl::AnnotationSet::AnnotationSet ( ArrayAttr  annotations)
inlineexplicit

Form an annotation set with a non-null ArrayAttr.

Definition at line 164 of file FIRRTLAnnotations.h.

References annotations, and assert().

◆ AnnotationSet() [5/6]

AnnotationSet::AnnotationSet ( ArrayAttr  annotations,
MLIRContext *  context 
)
explicit

Form an annotation set with a possibly-null ArrayAttr.

Definition at line 56 of file FIRRTLAnnotations.cpp.

◆ AnnotationSet() [6/6]

AnnotationSet::AnnotationSet ( Operation *  op)
explicit

Get an annotation set for the specified operation.

Definition at line 60 of file FIRRTLAnnotations.cpp.

Member Function Documentation

◆ addAnnotations() [1/3]

void AnnotationSet::addAnnotations ( ArrayAttr  annotations)

◆ addAnnotations() [2/3]

void AnnotationSet::addAnnotations ( ArrayRef< Annotation annotations)

Add more annotations to this annotation set.

Add more annotations to this AttributeSet.

Definition at line 297 of file FIRRTLAnnotations.cpp.

References annotations, circt::calyx::direction::get(), and getContext().

Referenced by addDontTouch(), annosForFieldIDRange(), circt::firrtl::applyGCTView(), and circt::firrtl::applyOMIR().

◆ addAnnotations() [3/3]

void AnnotationSet::addAnnotations ( ArrayRef< Attribute >  annotations)

◆ addDontTouch() [1/2]

bool AnnotationSet::addDontTouch ( )

◆ addDontTouch() [2/2]

bool AnnotationSet::addDontTouch ( Operation *  op)
static

Definition at line 270 of file FIRRTLAnnotations.cpp.

References addDontTouch(), and applyToOperation().

◆ applyToAttrList()

bool AnnotationSet::applyToAttrList ( NamedAttrList &  attrs) const

Store the annotations in this set in a NamedAttrList as an array attribute with the name annotations.

Overwrites existing annotations. Removes the annotations attribute if the set is empty. Returns true if the list was modified, false otherwise.

This function is useful if you are in the process of modifying an operation's attributes as a NamedAttrList, or you are preparing the attributes of a operation yet to be created. In that case applyToAttrList allows you to set the annotations attribute in that list to the contents of this set.

Definition at line 133 of file FIRRTLAnnotations.cpp.

References applyToAttrListImpl(), and circt::firrtl::getAnnotationAttrName().

◆ applyToDictionaryAttr() [1/2]

DictionaryAttr AnnotationSet::applyToDictionaryAttr ( ArrayRef< NamedAttribute >  attrs) const

◆ applyToDictionaryAttr() [2/2]

DictionaryAttr AnnotationSet::applyToDictionaryAttr ( DictionaryAttr  attrs) const

Insert this annotation set into a DictionaryAttr under the annotations key.

Update the attribute dictionary of an operation to contain this annotation set.

Overwrites any existing attribute stored under annotations. Removes the annotations attribute in the dictionary if the set is empty. Returns the updated dictionary.

This function is useful if you hold an operation's attributes dictionary and want to set the annotations key in the dictionary to the contents of this set.

Definition at line 187 of file FIRRTLAnnotations.cpp.

References applyToDictionaryAttrImpl(), and circt::firrtl::getAnnotationAttrName().

◆ applyToOperation()

bool AnnotationSet::applyToOperation ( Operation *  op) const

Store the annotations in this set in an operation's annotations attribute, overwriting any existing annotations.

Removes the annotations attribute if the set is empty. Returns true if the operation was modified, false otherwise.

Definition at line 90 of file FIRRTLAnnotations.cpp.

References circt::firrtl::getAnnotationAttrName(), and getArrayAttr().

Referenced by addDontTouch(), circt::firrtl::applyGCTView(), circt::firrtl::applyOMIR(), removeAnnotations(), removeDontTouch(), and circt::firrtl::OpAnnoTarget::setAnnotations().

◆ applyToPort() [1/2]

bool AnnotationSet::applyToPort ( FModuleLike  op,
size_t  portNo 
) const

Store the annotations in this set in an operation's portAnnotations attribute, overwriting any existing annotations for this port.

Returns true if the operation was modified, false otherwise.

Definition at line 113 of file FIRRTLAnnotations.cpp.

References applyToPort().

Referenced by circt::firrtl::PortAnnoTarget::setAnnotations().

◆ applyToPort() [2/2]

bool AnnotationSet::applyToPort ( MemOp  op,
size_t  portNo 
) const

Definition at line 117 of file FIRRTLAnnotations.cpp.

References applyToPort().

◆ applyToPortAttrList()

bool AnnotationSet::applyToPortAttrList ( NamedAttrList &  attrs) const

Store the annotations in this set in a NamedAttrList as an array attribute with the name firrtl.annotations.

Overwrites existing annotations. Removes the firrtl.annotations attribute if the set is empty. Returns true if the list was modified, false otherwise.

This function is useful if you are in the process of modifying a port's attributes as a NamedAttrList, or you are preparing the attributes of a port yet to be created as part of an operation. In that case applyToPortAttrList allows you to set the firrtl.annotations attribute in that list to the contents of this set.

Definition at line 139 of file FIRRTLAnnotations.cpp.

References applyToAttrListImpl(), and circt::firrtl::getDialectAnnotationAttrName().

◆ applyToPortDictionaryAttr() [1/2]

DictionaryAttr AnnotationSet::applyToPortDictionaryAttr ( ArrayRef< NamedAttribute >  attrs) const

◆ applyToPortDictionaryAttr() [2/2]

DictionaryAttr AnnotationSet::applyToPortDictionaryAttr ( DictionaryAttr  attrs) const

Insert this annotation set into a DictionaryAttr under the firrtl.annotations key.

Update the attribute dictionary of a port to contain this annotation set.

Overwrites any existing attribute stored under firrtl.annotations. Removes the firrtl.annotations attribute in the dictionary if the set is empty. Returns the updated dictionary.

This function is useful if you hold a port's attributes dictionary and want to set the firrtl.annotations key in the dictionary to the contents of this set.

Definition at line 200 of file FIRRTLAnnotations.cpp.

References applyToDictionaryAttrImpl(), and circt::firrtl::getDialectAnnotationAttrName().

◆ begin()

auto circt::firrtl::AnnotationSet::begin ( ) const
inline

Definition at line 373 of file FIRRTLAnnotations.h.

◆ canBeDeleted() [1/2]

bool AnnotationSet::canBeDeleted ( ) const

Check if every annotation can be deleted.

Definition at line 286 of file FIRRTLAnnotations.cpp.

References annotations, and circt::firrtl::Annotation::canBeDeleted().

Referenced by isDeletableDeclaration(), and isDeletableWireOrRegOrNode().

◆ canBeDeleted() [2/2]

bool AnnotationSet::canBeDeleted ( Operation *  op)
static

Definition at line 292 of file FIRRTLAnnotations.cpp.

References AnnotationSet().

◆ empty()

bool circt::firrtl::AnnotationSet::empty ( ) const
inline

◆ end()

auto circt::firrtl::AnnotationSet::end ( ) const
inline

Definition at line 376 of file FIRRTLAnnotations.h.

References annotations.

◆ forPort() [1/2]

AnnotationSet AnnotationSet::forPort ( FModuleLike  op,
size_t  portNo 
)
static

◆ forPort() [2/2]

AnnotationSet AnnotationSet::forPort ( MemOp  op,
size_t  portNo 
)
static

Definition at line 74 of file FIRRTLAnnotations.cpp.

References forPort().

◆ get()

AnnotationSet AnnotationSet::get ( Value  v)
static

Get an annotation set for the specified value.

Definition at line 79 of file FIRRTLAnnotations.cpp.

References AnnotationSet(), and forPort().

◆ getAnnotation() [1/2]

Annotation circt::firrtl::AnnotationSet::getAnnotation ( StringAttr  className) const
inline

Definition at line 261 of file FIRRTLAnnotations.h.

References annotations, and getAnnotationImpl().

◆ getAnnotation() [2/2]

Annotation circt::firrtl::AnnotationSet::getAnnotation ( StringRef  className) const
inline

If this annotation set has an annotation with the specified class name, return it.

Otherwise return a null DictionaryAttr.

Definition at line 256 of file FIRRTLAnnotations.h.

References annotations, and getAnnotationImpl().

Referenced by getPrefixInfo(), and moveVerifAnno().

◆ getAnnotationImpl() [1/2]

Annotation AnnotationSet::getAnnotationImpl ( StringAttr  className) const
private

Definition at line 211 of file FIRRTLAnnotations.cpp.

Referenced by getAnnotation(), and hasAnnotationImpl().

◆ getAnnotationImpl() [2/2]

Annotation AnnotationSet::getAnnotationImpl ( StringRef  className) const
private

Definition at line 219 of file FIRRTLAnnotations.cpp.

◆ getArray()

ArrayRef<Attribute> circt::firrtl::AnnotationSet::getArray ( ) const
inline

Return all the raw annotations that exist.

Definition at line 182 of file FIRRTLAnnotations.h.

References annotations.

◆ getArrayAttr()

ArrayAttr circt::firrtl::AnnotationSet::getArrayAttr ( ) const
inline

Return this annotation set as an ArrayAttr.

Definition at line 185 of file FIRRTLAnnotations.h.

References annotations.

Referenced by applyToAttrListImpl(), applyToDictionaryAttrImpl(), applyToOperation(), applyToPort(), removeAnnotations(), and removePortAnnotations().

◆ getContext()

MLIRContext* circt::firrtl::AnnotationSet::getContext ( ) const
inline

Return the MLIRContext corresponding to this AnnotationSet.

Definition at line 272 of file FIRRTLAnnotations.h.

References annotations.

Referenced by addAnnotations(), addDontTouch(), applyToDictionaryAttrImpl(), lowerModuleBody(), and removeAnnotations().

◆ hasAnnotation() [1/2]

bool circt::firrtl::AnnotationSet::hasAnnotation ( StringAttr  className) const
inline

Definition at line 250 of file FIRRTLAnnotations.h.

References annotations, and hasAnnotationImpl().

◆ hasAnnotation() [2/2]

bool circt::firrtl::AnnotationSet::hasAnnotation ( StringRef  className) const
inline

Return true if we have an annotation with the specified class name.

Definition at line 247 of file FIRRTLAnnotations.h.

References annotations, and hasAnnotationImpl().

Referenced by Equivalence::check(), and hasDontTouch().

◆ hasAnnotationImpl() [1/2]

bool AnnotationSet::hasAnnotationImpl ( StringAttr  className) const
private

Definition at line 227 of file FIRRTLAnnotations.cpp.

References getAnnotationImpl().

Referenced by hasAnnotation().

◆ hasAnnotationImpl() [2/2]

bool AnnotationSet::hasAnnotationImpl ( StringRef  className) const
private

Definition at line 231 of file FIRRTLAnnotations.cpp.

References getAnnotationImpl().

◆ hasDontTouch() [1/2]

bool AnnotationSet::hasDontTouch ( ) const

firrtl.transforms.DontTouchAnnotation

Definition at line 235 of file FIRRTLAnnotations.cpp.

References circt::firrtl::dontTouchAnnoClass, and hasAnnotation().

Referenced by addDontTouch(), circt::firrtl::hasDontTouch(), and hasDontTouchOrInnerSymOnResult().

◆ hasDontTouch() [2/2]

bool AnnotationSet::hasDontTouch ( Operation *  op)
static

Definition at line 259 of file FIRRTLAnnotations.cpp.

References AnnotationSet().

◆ operator!=()

bool circt::firrtl::AnnotationSet::operator!= ( const AnnotationSet other) const
inline

Definition at line 293 of file FIRRTLAnnotations.h.

◆ operator==()

bool circt::firrtl::AnnotationSet::operator== ( const AnnotationSet other) const
inline

Definition at line 290 of file FIRRTLAnnotations.h.

References annotations.

◆ removeAnnotation() [1/3]

bool AnnotationSet::removeAnnotation ( Annotation  anno)

Remove an annotation from this annotation set.

Returns true if any were removed, false otherwise.

Definition at line 343 of file FIRRTLAnnotations.cpp.

References removeAnnotations().

Referenced by removeDontTouch().

◆ removeAnnotation() [2/3]

bool AnnotationSet::removeAnnotation ( Attribute  anno)

Remove an annotation from this annotation set.

Returns true if any were removed, false otherwise.

Definition at line 349 of file FIRRTLAnnotations.cpp.

References circt::firrtl::Annotation::getDict(), and removeAnnotations().

◆ removeAnnotation() [3/3]

bool AnnotationSet::removeAnnotation ( StringRef  className)

Remove an annotation from this annotation set.

Returns true if any were removed, false otherwise.

Definition at line 356 of file FIRRTLAnnotations.cpp.

References circt::firrtl::Annotation::getClass(), and removeAnnotations().

◆ removeAnnotations() [1/3]

bool AnnotationSet::removeAnnotations ( llvm::function_ref< bool(Annotation)>  predicate)

Remove all annotations from this annotation set for which predicate returns true.

The predicate is guaranteed to be called on every annotation, such that this method can be used to partition the set by extracting and removing annotations at the same time. Returns true if any annotations were removed, false otherwise.

Definition at line 363 of file FIRRTLAnnotations.cpp.

References annotations, circt::calyx::direction::get(), getArrayAttr(), and getContext().

Referenced by removeAnnotation(), removeAnnotations(), removeAnnotationsWithClass(), removePortAnnotations(), ResolveTracesPass::runOnOperation(), and SFCCompatPass::runOnOperation().

◆ removeAnnotations() [2/3]

bool AnnotationSet::removeAnnotations ( Operation *  op,
llvm::function_ref< bool(Annotation)>  predicate 
)
static

Remove all annotations from an operation for which predicate returns true.

The predicate is guaranteed to be called on every annotation, such that this method can be used to partition the set by extracting and removing annotations at the same time. Returns true if any annotations were removed, false otherwise.

Definition at line 395 of file FIRRTLAnnotations.cpp.

References applyToOperation(), empty(), and removeAnnotations().

◆ removeAnnotations() [3/3]

bool AnnotationSet::removeAnnotations ( Operation *  op,
StringRef  className 
)
static

◆ removeAnnotationsWithClass()

template<typename... Args>
bool circt::firrtl::AnnotationSet::removeAnnotationsWithClass ( Args...  names)
inline

Remove all annotations with one of the given classes from this annotation set.

Definition at line 322 of file FIRRTLAnnotations.h.

References circt::firrtl::Annotation::isClass(), and removeAnnotations().

◆ removeDontTouch() [1/2]

bool AnnotationSet::removeDontTouch ( )

Definition at line 255 of file FIRRTLAnnotations.cpp.

References circt::firrtl::dontTouchAnnoClass, and removeAnnotation().

Referenced by removeDontTouch(), and setDontTouch().

◆ removeDontTouch() [2/2]

bool AnnotationSet::removeDontTouch ( Operation *  op)
static

Definition at line 278 of file FIRRTLAnnotations.cpp.

References applyToOperation(), and removeDontTouch().

◆ removePortAnnotations()

bool AnnotationSet::removePortAnnotations ( Operation *  module,
llvm::function_ref< bool(unsigned, Annotation)>  predicate 
)
static

Remove all port annotations from a module or extmodule for which predicate returns true.

The predicate is guaranteed to be called on every annotation, such that this method can be used to partition a module's port annotations by extracting and removing annotations at the same time. Returns true if any annotations were removed, false otherwise.

Definition at line 412 of file FIRRTLAnnotations.cpp.

References AnnotationSet(), empty(), circt::calyx::direction::get(), getArrayAttr(), and removeAnnotations().

Referenced by ResolveTracesPass::runOnOperation(), and SFCCompatPass::runOnOperation().

◆ setDontTouch() [1/2]

bool AnnotationSet::setDontTouch ( bool  dontTouch)

Definition at line 239 of file FIRRTLAnnotations.cpp.

References addDontTouch(), and removeDontTouch().

◆ setDontTouch() [2/2]

bool AnnotationSet::setDontTouch ( Operation *  op,
bool  dontTouch 
)
static

Definition at line 263 of file FIRRTLAnnotations.cpp.

References addDontTouch(), and removeDontTouch().

◆ size()

size_t circt::firrtl::AnnotationSet::size ( ) const
inline

Member Data Documentation

◆ annotations

ArrayAttr circt::firrtl::AnnotationSet::annotations
private

The documentation for this class was generated from the following files: