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