CIRCT  20.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 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 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...
 
template<typename... Args>
static bool hasAnnotation (Operation *op, Args... args)
 Return true if we have an annotation with the specified class name. 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 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 142 of file FIRRTLAnnotations.h.

Member Typedef Documentation

◆ ElementType

Definition at line 144 of file FIRRTLAnnotations.h.

◆ iterator

Definition at line 227 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 147 of file FIRRTLAnnotations.h.

Referenced by 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 158 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 195 of file FIRRTLAnnotations.cpp.

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

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

◆ 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 178 of file FIRRTLAnnotations.cpp.

References addDontTouch(), and applyToOperation().

◆ 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::createPathRef(), 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().

◆ begin()

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

Definition at line 329 of file FIRRTLAnnotations.h.

◆ empty()

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

◆ end()

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

Definition at line 332 of file FIRRTLAnnotations.h.

References annotations.

◆ forPort() [1/2]

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

Get an annotation set for the specified port.

Definition at line 70 of file FIRRTLAnnotations.cpp.

References forPort().

Referenced by get(), circt::firrtl::PortAnnoTarget::getAnnotations(), getPortImpl(), circt::firrtl::hasDontTouch(), and Deduper::mergeAnnotations().

◆ 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 221 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 216 of file FIRRTLAnnotations.h.

References annotations, and getAnnotationImpl().

Referenced by moveVerifAnno().

◆ getAnnotationImpl() [1/2]

Annotation AnnotationSet::getAnnotationImpl ( StringAttr  className) const
private

Definition at line 121 of file FIRRTLAnnotations.cpp.

Referenced by getAnnotation(), and hasAnnotationImpl().

◆ getAnnotationImpl() [2/2]

Annotation AnnotationSet::getAnnotationImpl ( StringRef  className) const
private

Definition at line 129 of file FIRRTLAnnotations.cpp.

◆ getArray()

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

Return all the raw annotations that exist.

Definition at line 176 of file FIRRTLAnnotations.h.

References annotations.

◆ getArrayAttr()

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

Return this annotation set as an ArrayAttr.

Definition at line 179 of file FIRRTLAnnotations.h.

References annotations, and assert().

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

◆ getContext()

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

Return the MLIRContext corresponding to this AnnotationSet.

Definition at line 232 of file FIRRTLAnnotations.h.

References annotations.

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

◆ hasAnnotation() [1/3]

template<typename... Args>
static bool circt::firrtl::AnnotationSet::hasAnnotation ( Operation *  op,
Args...  args 
)
inlinestatic

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

Definition at line 206 of file FIRRTLAnnotations.h.

References annotations, and circt::firrtl::getAnnotationsIfPresent().

◆ hasAnnotation() [2/3]

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

Definition at line 200 of file FIRRTLAnnotations.h.

References annotations, and hasAnnotationImpl().

◆ hasAnnotation() [3/3]

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

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

Definition at line 197 of file FIRRTLAnnotations.h.

References annotations, and hasAnnotationImpl().

Referenced by Equivalence::check(), hasDontTouch(), and circt::firrtl::InstanceInfo::InstanceInfo().

◆ hasAnnotationImpl() [1/2]

bool AnnotationSet::hasAnnotationImpl ( StringAttr  className) const
private

Definition at line 137 of file FIRRTLAnnotations.cpp.

References getAnnotationImpl().

Referenced by hasAnnotation().

◆ hasAnnotationImpl() [2/2]

bool AnnotationSet::hasAnnotationImpl ( StringRef  className) const
private

Definition at line 141 of file FIRRTLAnnotations.cpp.

References getAnnotationImpl().

◆ hasDontTouch() [1/2]

bool AnnotationSet::hasDontTouch ( ) const

firrtl.transforms.DontTouchAnnotation

Definition at line 145 of file FIRRTLAnnotations.cpp.

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

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

◆ hasDontTouch() [2/2]

bool AnnotationSet::hasDontTouch ( Operation *  op)
static

Definition at line 168 of file FIRRTLAnnotations.cpp.

References AnnotationSet().

◆ operator!=()

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

Definition at line 249 of file FIRRTLAnnotations.h.

◆ operator==()

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

Definition at line 246 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 241 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 247 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 254 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 261 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 288 of file FIRRTLAnnotations.cpp.

References applyToOperation(), circt::firrtl::getAnnotationsIfPresent(), 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 278 of file FIRRTLAnnotations.h.

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

◆ removeDontTouch() [1/2]

bool AnnotationSet::removeDontTouch ( )

Definition at line 164 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 186 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 309 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 149 of file FIRRTLAnnotations.cpp.

References addDontTouch(), and removeDontTouch().

◆ setDontTouch() [2/2]

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

Definition at line 172 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: