CIRCT  18.0.0git
FIRRTLAnnotations.h
Go to the documentation of this file.
1 //===- FIRRTLAnnotations.h - Code for working with Annotations --*- 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 // This file declares helpers for working with FIRRTL annotations.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
14 #define CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
15 
16 #include "circt/Support/LLVM.h"
17 #include "mlir/IR/BuiltinAttributes.h"
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/Support/PointerLikeTypeTraits.h"
20 
21 namespace circt {
22 namespace hw {
23 struct InnerSymbolNamespace;
24 } // namespace hw
25 namespace firrtl {
26 
27 class AnnotationSetIterator;
28 class FModuleOp;
29 class FModuleLike;
30 class MemOp;
31 class InstanceOp;
32 class FIRRTLType;
33 
34 /// Return the name of the attribute used for annotations on FIRRTL ops.
35 inline StringRef getAnnotationAttrName() { return "annotations"; }
36 
37 /// Return the name of the attribute used for port annotations on FIRRTL ops.
38 inline StringRef getPortAnnotationAttrName() { return "portAnnotations"; }
39 
40 /// Return the name of the dialect-prefixed attribute used for annotations.
41 inline StringRef getDialectAnnotationAttrName() { return "firrtl.annotations"; }
42 
43 /// Check if an OMIR type is a string-encoded value that the FIRRTL dialect
44 /// simply passes through as a string without any decoding.
45 bool isOMIRStringEncodedPassthrough(StringRef type);
46 
47 /// This class provides a read-only projection of an annotation.
48 class Annotation {
49 public:
51 
52  explicit Annotation(Attribute attr) : attr(attr) {
53  assert(attr && "null attributes not allowed");
54  }
55 
56  /// Get the data dictionary of this attribute.
57  DictionaryAttr getDict() const;
58 
59  /// Set the data dictionary of this attribute.
60  void setDict(DictionaryAttr dict);
61 
62  /// Get the field id this attribute targets.
63  unsigned getFieldID() const;
64 
65  /// Get the underlying attribute.
66  Attribute getAttr() const { return attr; }
67 
68  /// Return the 'class' that this annotation is representing.
69  StringAttr getClassAttr() const;
70  StringRef getClass() const;
71 
72  /// Return true if this annotation matches any of the specified class names.
73  template <typename... Args>
74  bool isClass(Args... names) const {
75  return ClassIsa{getClassAttr()}(names...);
76  }
77 
78  /// Return a member of the annotation.
79  template <typename AttrClass = Attribute>
80  AttrClass getMember(StringAttr name) const {
81  return getDict().getAs<AttrClass>(name);
82  }
83  template <typename AttrClass = Attribute>
84  AttrClass getMember(StringRef name) const {
85  return getDict().getAs<AttrClass>(name);
86  }
87 
88  /// Add or set a member of the annotation to a value.
89  void setMember(StringAttr name, Attribute value);
90  void setMember(StringRef name, Attribute value);
91 
92  /// Remove a member of the annotation.
93  void removeMember(StringAttr name);
94  void removeMember(StringRef name);
95 
96  /// Returns true if this is an annotation which can be safely deleted without
97  /// consequence.
98  bool canBeDeleted();
99 
100  using iterator = llvm::ArrayRef<NamedAttribute>::iterator;
101  iterator begin() const { return getDict().begin(); }
102  iterator end() const { return getDict().end(); }
103 
104  bool operator==(const Annotation &other) const { return attr == other.attr; }
105  bool operator!=(const Annotation &other) const { return !(*this == other); }
106  explicit operator bool() const { return bool(attr); }
107  bool operator!() const { return attr == nullptr; }
108 
109  void dump();
110 
111 private:
112  Attribute attr;
113 
114  /// Helper struct to perform variadic class equality check.
115  struct ClassIsa {
116  StringAttr cls;
117 
118  bool operator()() const { return false; }
119  template <typename T, typename... Rest>
120  bool operator()(T name, Rest... rest) const {
121  return compare(name) || (*this)(rest...);
122  }
123 
124  private:
125  bool compare(StringAttr name) const { return cls == name; }
126  bool compare(StringRef name) const { return cls && cls.getValue() == name; }
127  };
128 };
129 
130 /// This class provides a read-only projection over the MLIR attributes that
131 /// represent a set of annotations. It is intended to make this work less
132 /// stringly typed and fiddly for clients.
133 ///
135 public:
136  /// Form an empty annotation set.
137  explicit AnnotationSet(MLIRContext *context)
138  : annotations(ArrayAttr::get(context, {})) {}
139 
140  /// Form an annotation set from an array of annotation attributes.
141  explicit AnnotationSet(ArrayRef<Attribute> annotations, MLIRContext *context);
142 
143  /// Form an annotation set from an array of annotations.
144  explicit AnnotationSet(ArrayRef<Annotation> annotations,
145  MLIRContext *context);
146 
147  /// Form an annotation set with a non-null ArrayAttr.
149  assert(annotations && "Cannot use null attribute set");
150  }
151 
152  /// Form an annotation set with a possibly-null ArrayAttr.
153  explicit AnnotationSet(ArrayAttr annotations, MLIRContext *context);
154 
155  /// Get an annotation set for the specified operation.
156  explicit AnnotationSet(Operation *op);
157 
158  /// Get an annotation set for the specified port.
159  static AnnotationSet forPort(FModuleLike op, size_t portNo);
160  static AnnotationSet forPort(MemOp op, size_t portNo);
161 
162  /// Get an annotation set for the specified value.
163  static AnnotationSet get(Value v);
164 
165  /// Return all the raw annotations that exist.
166  ArrayRef<Attribute> getArray() const { return annotations.getValue(); }
167 
168  /// Return this annotation set as an ArrayAttr.
169  ArrayAttr getArrayAttr() const { return annotations; }
170 
171  /// Store the annotations in this set in an operation's `annotations`
172  /// attribute, overwriting any existing annotations. Removes the `annotations`
173  /// attribute if the set is empty. Returns true if the operation was modified,
174  /// false otherwise.
175  bool applyToOperation(Operation *op) const;
176 
177  /// Store the annotations in this set in an operation's `portAnnotations`
178  /// attribute, overwriting any existing annotations for this port. Returns
179  /// true if the operation was modified, false otherwise.
180  bool applyToPort(FModuleLike op, size_t portNo) const;
181  bool applyToPort(MemOp op, size_t portNo) const;
182 
183  /// Store the annotations in this set in a `NamedAttrList` as an array
184  /// attribute with the name `annotations`. Overwrites existing annotations.
185  /// Removes the `annotations` attribute if the set is empty. Returns true if
186  /// the list was modified, false otherwise.
187  ///
188  /// This function is useful if you are in the process of modifying an
189  /// operation's attributes as a `NamedAttrList`, or you are preparing the
190  /// attributes of a operation yet to be created. In that case
191  /// `applyToAttrList` allows you to set the `annotations` attribute in that
192  /// list to the contents of this set.
193  bool applyToAttrList(NamedAttrList &attrs) const;
194 
195  /// Store the annotations in this set in a `NamedAttrList` as an array
196  /// attribute with the name `firrtl.annotations`. Overwrites existing
197  /// annotations. Removes the `firrtl.annotations` attribute if the set is
198  /// empty. Returns true if the list was modified, false otherwise.
199  ///
200  /// This function is useful if you are in the process of modifying a port's
201  /// attributes as a `NamedAttrList`, or you are preparing the attributes of a
202  /// port yet to be created as part of an operation. In that case
203  /// `applyToPortAttrList` allows you to set the `firrtl.annotations` attribute
204  /// in that list to the contents of this set.
205  bool applyToPortAttrList(NamedAttrList &attrs) const;
206 
207  /// Insert this annotation set into a `DictionaryAttr` under the `annotations`
208  /// key. Overwrites any existing attribute stored under `annotations`. Removes
209  /// the `annotations` attribute in the dictionary if the set is empty. Returns
210  /// the updated dictionary.
211  ///
212  /// This function is useful if you hold an operation's attributes dictionary
213  /// and want to set the `annotations` key in the dictionary to the contents of
214  /// this set.
215  DictionaryAttr applyToDictionaryAttr(DictionaryAttr attrs) const;
216  DictionaryAttr applyToDictionaryAttr(ArrayRef<NamedAttribute> attrs) const;
217 
218  /// Insert this annotation set into a `DictionaryAttr` under the
219  /// `firrtl.annotations` key. Overwrites any existing attribute stored under
220  /// `firrtl.annotations`. Removes the `firrtl.annotations` attribute in the
221  /// dictionary if the set is empty. Returns the updated dictionary.
222  ///
223  /// This function is useful if you hold a port's attributes dictionary and
224  /// want to set the `firrtl.annotations` key in the dictionary to the contents
225  /// of this set.
226  DictionaryAttr applyToPortDictionaryAttr(DictionaryAttr attrs) const;
227  DictionaryAttr
228  applyToPortDictionaryAttr(ArrayRef<NamedAttribute> attrs) const;
229 
230  /// Return true if we have an annotation with the specified class name.
231  bool hasAnnotation(StringRef className) const {
232  return !annotations.empty() && hasAnnotationImpl(className);
233  }
234  bool hasAnnotation(StringAttr className) const {
235  return !annotations.empty() && hasAnnotationImpl(className);
236  }
237 
238  /// If this annotation set has an annotation with the specified class name,
239  /// return it. Otherwise return a null DictionaryAttr.
240  Annotation getAnnotation(StringRef className) const {
241  if (annotations.empty())
242  return {};
243  return getAnnotationImpl(className);
244  }
245  Annotation getAnnotation(StringAttr className) const {
246  if (annotations.empty())
247  return {};
248  return getAnnotationImpl(className);
249  }
250 
252  iterator begin() const;
253  iterator end() const;
254 
255  /// Return the MLIRContext corresponding to this AnnotationSet.
256  MLIRContext *getContext() const { return annotations.getContext(); }
257 
258  // Support for widely used annotations.
259 
260  /// firrtl.transforms.DontTouchAnnotation
261  bool hasDontTouch() const;
262  bool setDontTouch(bool dontTouch);
263  bool addDontTouch();
264  bool removeDontTouch();
265  static bool hasDontTouch(Operation *op);
266  static bool setDontTouch(Operation *op, bool dontTouch);
267  static bool addDontTouch(Operation *op);
268  static bool removeDontTouch(Operation *op);
269 
270  /// Check if every annotation can be deleted.
271  bool canBeDeleted() const;
272  static bool canBeDeleted(Operation *op);
273 
274  bool operator==(const AnnotationSet &other) const {
275  return annotations == other.annotations;
276  }
277  bool operator!=(const AnnotationSet &other) const {
278  return !(*this == other);
279  }
280 
281  bool empty() const { return annotations.empty(); }
282 
283  size_t size() const { return annotations.size(); }
284 
285  /// Add more annotations to this annotation set.
286  void addAnnotations(ArrayRef<Annotation> annotations);
287  void addAnnotations(ArrayRef<Attribute> annotations);
288  void addAnnotations(ArrayAttr annotations);
289 
290  /// Remove an annotation from this annotation set. Returns true if any were
291  /// removed, false otherwise.
292  bool removeAnnotation(Annotation anno);
293  bool removeAnnotation(Attribute anno);
294  bool removeAnnotation(StringRef className);
295 
296  /// Remove all annotations from this annotation set for which `predicate`
297  /// returns true. The predicate is guaranteed to be called on every
298  /// annotation, such that this method can be used to partition the set by
299  /// extracting and removing annotations at the same time. Returns true if any
300  /// annotations were removed, false otherwise.
301  bool removeAnnotations(llvm::function_ref<bool(Annotation)> predicate);
302 
303  /// Remove all annotations with one of the given classes from this annotation
304  /// set.
305  template <typename... Args>
306  bool removeAnnotationsWithClass(Args... names) {
307  return removeAnnotations(
308  [&](Annotation anno) { return anno.isClass(names...); });
309  }
310 
311  /// Remove all annotations from an operation for which `predicate` returns
312  /// true. The predicate is guaranteed to be called on every annotation, such
313  /// that this method can be used to partition the set by extracting and
314  /// removing annotations at the same time. Returns true if any annotations
315  /// were removed, false otherwise.
316  static bool removeAnnotations(Operation *op,
317  llvm::function_ref<bool(Annotation)> predicate);
318  static bool removeAnnotations(Operation *op, StringRef className);
319 
320  /// Remove all port annotations from a module or extmodule for which
321  /// `predicate` returns true. The predicate is guaranteed to be called on
322  /// every annotation, such that this method can be used to partition a
323  /// module's port annotations by extracting and removing annotations at the
324  /// same time. Returns true if any annotations were removed, false otherwise.
325  static bool removePortAnnotations(
326  Operation *module,
327  llvm::function_ref<bool(unsigned, Annotation)> predicate);
328 
329 private:
330  bool hasAnnotationImpl(StringAttr className) const;
331  bool hasAnnotationImpl(StringRef className) const;
332  Annotation getAnnotationImpl(StringAttr className) const;
333  Annotation getAnnotationImpl(StringRef className) const;
334 
335  ArrayAttr annotations;
336 };
337 
338 // Iteration over the annotation set.
340  : public llvm::indexed_accessor_iterator<AnnotationSetIterator,
341  AnnotationSet, Annotation,
342  Annotation, Annotation> {
343 public:
344  // Index into this iterator.
345  Annotation operator*() const;
346 
347 private:
348  AnnotationSetIterator(AnnotationSet owner, ptrdiff_t curIndex)
349  : llvm::indexed_accessor_iterator<AnnotationSetIterator, AnnotationSet,
351  owner, curIndex) {}
352  friend llvm::indexed_accessor_iterator<AnnotationSetIterator, AnnotationSet,
354  friend class AnnotationSet;
355 };
356 
357 inline auto AnnotationSet::begin() const -> iterator {
358  return AnnotationSetIterator(*this, 0);
359 }
360 inline auto AnnotationSet::end() const -> iterator {
361  return iterator(*this, annotations.size());
362 }
363 
364 //===----------------------------------------------------------------------===//
365 // AnnoTarget
366 //===----------------------------------------------------------------------===//
367 
368 namespace detail {
370  /* implicit */ AnnoTargetImpl(Operation *op) : op(op), portNo(~0UL) {}
371 
372  AnnoTargetImpl(Operation *op, unsigned portNo) : op(op), portNo(portNo) {}
373 
374  operator bool() const { return getOp(); }
375  bool operator==(const AnnoTargetImpl &other) const {
376  return op == other.op && portNo == other.portNo;
377  }
378  bool operator!=(const AnnoTargetImpl &other) const {
379  return !(*this == other);
380  }
381 
382  bool isPort() const { return op && portNo != ~0UL; }
383  bool isOp() const { return op && portNo == ~0UL; }
384 
385  Operation *getOp() const { return op; }
386  void setOp(Operation *op) { this->op = op; }
387 
388  unsigned getPortNo() const { return portNo; }
389  void setPortNo(unsigned portNo) { this->portNo = portNo; }
390 
391 protected:
392  Operation *op;
393  size_t portNo;
394 };
395 } // namespace detail
396 
397 /// An annotation target is used to keep track of something that is targeted by
398 /// an Annotation.
399 struct AnnoTarget {
401 
402  template <typename U>
403  bool isa() const { // NOLINT(readability-identifier-naming)
404  assert(*this && "isa<> used on a null type.");
405  return U::classof(*this);
406  }
407  template <typename U>
408  U dyn_cast() const { // NOLINT(readability-identifier-naming)
409  return isa<U>() ? U(impl) : U(nullptr);
410  }
411  template <typename U>
412  U dyn_cast_or_null() const { // NOLINT(readability-identifier-naming)
413  return (*this && isa<U>()) ? U(impl) : U(nullptr);
414  }
415  template <typename U>
416  U cast() const {
417  assert(isa<U>());
418  return U(impl);
419  }
420 
421  operator bool() const { return impl; }
422  bool operator==(const AnnoTarget &other) const { return impl == other.impl; }
423  bool operator!=(const AnnoTarget &other) const { return !(*this == other); }
424 
425  Operation *getOp() const { return getImpl().getOp(); }
426  void setOp(Operation *op) { getImpl().setOp(op); }
427 
428  /// Get the annotations associated with the target.
430 
431  /// Set the annotations associated with the target.
432  void setAnnotations(AnnotationSet annotations) const;
433 
434  /// Get the parent module of the target.
435  FModuleLike getModule() const;
436 
437  /// Get a reference to this target suitable for use in an NLA.
438  Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const;
439 
440  /// Get the type of the target.
441  FIRRTLType getType() const;
442 
443  detail::AnnoTargetImpl getImpl() const { return impl; }
444 
445 protected:
447 };
448 
449 /// This represents an annotation targeting a specific operation.
450 struct OpAnnoTarget : public AnnoTarget {
452 
453  OpAnnoTarget(Operation *op) : AnnoTarget(op) {}
454 
456  void setAnnotations(AnnotationSet annotations) const;
457  Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const;
458  FIRRTLType getType() const;
459 
460  static bool classof(const AnnoTarget &annoTarget) {
461  return annoTarget.getImpl().isOp();
462  }
463 };
464 
465 /// This represents an annotation targeting a specific port of a module, memory,
466 /// or instance.
467 struct PortAnnoTarget : public AnnoTarget {
469 
470  PortAnnoTarget(FModuleLike op, unsigned portNo);
471  PortAnnoTarget(MemOp op, unsigned portNo);
472 
473  unsigned getPortNo() const { return getImpl().getPortNo(); }
474  void setPortNo(unsigned portNo) { getImpl().setPortNo(portNo); }
475 
477  void setAnnotations(AnnotationSet annotations) const;
478  Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const;
479  FIRRTLType getType() const;
480 
481  static bool classof(const AnnoTarget &annoTarget) {
482  return annoTarget.getImpl().isPort();
483  }
484 };
485 
486 //===----------------------------------------------------------------------===//
487 // Utilities for Specific Annotations
488 //
489 // TODO: Remove these in favor of first-class annotations.
490 //===----------------------------------------------------------------------===//
491 
492 /// Utility that searches for a MarkDUTAnnotation on a specific module, `mod`,
493 /// and tries to update a design-under-test (DUT), `dut`, with this module if
494 /// the module is the DUT. This function returns success if either no DUT was
495 /// found or if the DUT was found and a previous DUT was not set (if `dut` is
496 /// null). This returns failure if a DUT was found and a previous DUT was set.
497 /// This function generates an error message in the failure case.
498 LogicalResult extractDUT(FModuleOp mod, FModuleOp &dut);
499 
500 } // namespace firrtl
501 } // namespace circt
502 
503 //===----------------------------------------------------------------------===//
504 // Traits
505 //===----------------------------------------------------------------------===//
506 
507 namespace llvm {
508 
509 /// Make `Annotation` behave like a `Attribute` in terms of pointer-likeness.
510 template <>
511 struct PointerLikeTypeTraits<circt::firrtl::Annotation>
512  : PointerLikeTypeTraits<mlir::Attribute> {
514  static inline void *getAsVoidPointer(Annotation v) {
515  return const_cast<void *>(v.getAttr().getAsOpaquePointer());
516  }
517  static inline Annotation getFromVoidPointer(void *p) {
518  return Annotation(mlir::DictionaryAttr::getFromOpaquePointer(p));
519  }
520 };
521 
522 /// Make `Annotation` hash just like `Attribute`.
523 template <>
524 struct DenseMapInfo<circt::firrtl::Annotation> {
527  return Annotation(
528  mlir::DictionaryAttr(static_cast<mlir::Attribute::ImplType *>(
529  DenseMapInfo<void *>::getEmptyKey())));
530  }
532  return Annotation(
533  mlir::DictionaryAttr(static_cast<mlir::Attribute::ImplType *>(
534  llvm::DenseMapInfo<void *>::getTombstoneKey())));
535  }
536  static unsigned getHashValue(Annotation val) {
537  return mlir::hash_value(val.getAttr());
538  }
539  static bool isEqual(Annotation LHS, Annotation RHS) { return LHS == RHS; }
540 };
541 
542 /// Make `AnnoTarget` hash.
543 template <>
544 struct DenseMapInfo<circt::firrtl::AnnoTarget> {
548  auto *o = DenseMapInfo<mlir::Operation *>::getEmptyKey();
549  auto i = DenseMapInfo<unsigned>::getEmptyKey();
550  return AnnoTarget(AnnoTargetImpl(o, i));
551  }
553  auto *o = DenseMapInfo<mlir::Operation *>::getTombstoneKey();
554  auto i = DenseMapInfo<unsigned>::getTombstoneKey();
555  return AnnoTarget(AnnoTargetImpl(o, i));
556  }
557  static unsigned getHashValue(AnnoTarget val) {
558  auto impl = val.getImpl();
559  return hash_combine(impl.getOp(), impl.getPortNo());
560  }
561  static bool isEqual(AnnoTarget lhs, AnnoTarget rhs) { return lhs == rhs; }
562 };
563 
564 } // namespace llvm
565 
566 #endif // CIRCT_DIALECT_FIRRTL_ANNOTATIONS_H
lowerAnnotationsNoRefTypePorts FirtoolPreserveValuesMode value
Definition: Firtool.cpp:95
assert(baseType &&"element must be base type")
AnnotationSetIterator(AnnotationSet owner, ptrdiff_t curIndex)
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.
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...
Definition: DebugAnalysis.h:21
Definition: hw.py:1
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.
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
void setAnnotations(AnnotationSet annotations) 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)
void setPortNo(unsigned portNo)
AnnotationSet getAnnotations() const
void setAnnotations(AnnotationSet annotations) const
Attribute getNLAReference(hw::InnerSymbolNamespace &moduleNamespace) const
PortAnnoTarget(FModuleLike op, unsigned portNo)
bool operator!=(const AnnoTargetImpl &other) const
bool operator==(const AnnoTargetImpl &other) const
AnnoTargetImpl(Operation *op, unsigned portNo)
static bool isEqual(AnnoTarget lhs, AnnoTarget rhs)
static unsigned getHashValue(AnnoTarget val)
static unsigned getHashValue(Annotation val)
static bool isEqual(Annotation LHS, Annotation RHS)