CIRCT  19.0.0git
FieldRefCache.h
Go to the documentation of this file.
1 //===- FieldRefCache.h - FieldRef cache -------------------------*- 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 FieldRefCache, a caching getFieldRefFromValue that
10 // caching FieldRef's for each queried value and all indexing operations
11 // visited during the walk.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef CIRCT_DIALECT_FIRRTL_FIELDREFCACHE_H
16 #define CIRCT_DIALECT_FIRRTL_FIELDREFCACHE_H
17 
18 #include "circt/Support/FieldRef.h"
19 #include "circt/Support/LLVM.h"
20 
21 namespace circt {
22 namespace firrtl {
23 
24 /// Caching version of getFieldRefFromValue. Computes the requested FieldRef
25 /// and for all operations visited along the way. Tracks some stats in debug.
27  using Key = llvm::PointerIntPair<Value, 1, bool>;
28  DenseMap<Key, FieldRef> refs;
29 #ifndef NDEBUG
30  size_t computed = 0;
31  size_t hits = 0;
32  size_t queries = 0;
33 #endif
34 
35 public:
36  /// Caching version of getFieldRefFromValue.
37  FieldRef getFieldRefFromValue(Value value, bool lookThroughCasts = false);
38 
39  /// Drop all cached entries.
40  void clear() { refs.clear(); }
41 
42 #ifndef NDEBUG
43  void printStats(llvm::raw_ostream &os) const;
44  void addToTotals(size_t &totalHits, size_t &totalComputed,
45  size_t &totalQueries) const;
46  void verifyImpl() const;
47 #endif // NDEBUG
48 
49  /// Verify cached fieldRefs against firrtl::getFieldRefFromValue.
50  /// No-op in release builds.
51  void verify() const {
52 #ifndef NDEBUG
53  verifyImpl();
54 #endif // NDEBUG
55  }
56 };
57 
58 } // namespace firrtl
59 } // namespace circt
60 
61 #endif // CIRCT_DIALECT_FIRRTL_FIELDREFCACHE_H
This class represents a reference to a specific field or element of an aggregate value.
Definition: FieldRef.h:28
Caching version of getFieldRefFromValue.
Definition: FieldRefCache.h:26
llvm::PointerIntPair< Value, 1, bool > Key
Definition: FieldRefCache.h:27
void clear()
Drop all cached entries.
Definition: FieldRefCache.h:40
void addToTotals(size_t &totalHits, size_t &totalComputed, size_t &totalQueries) const
void printStats(llvm::raw_ostream &os) const
void verify() const
Verify cached fieldRefs against firrtl::getFieldRefFromValue.
Definition: FieldRefCache.h:51
FieldRef getFieldRefFromValue(Value value, bool lookThroughCasts=false)
Caching version of getFieldRefFromValue.
DenseMap< Key, FieldRef > refs
Definition: FieldRefCache.h:28
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21