17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Support/FormatVariadic.h"
20 using namespace circt;
21 using namespace firrtl;
24 bool lookThroughCasts) {
28 SmallVector<FieldRef> indexing;
39 auto it = refs.find(
Key(value, lookThroughCasts));
40 if (it != refs.end()) {
45 auto ref = it->second;
50 indexing.emplace_back(value, ref.getFieldID());
51 indexing.emplace_back(ref.getValue(), 0);
58 auto deltaRef =
getDeltaRef(value, lookThroughCasts);
59 indexing.emplace_back(value, deltaRef.getFieldID());
60 value = deltaRef.getValue();
64 assert(indexing.back().getFieldID() == 0);
66 auto root = indexing.back().getValue();
69 for (
auto &info : llvm::reverse(indexing)) {
70 id += info.getFieldID();
72 refs.try_emplace({info.getValue(), lookThroughCasts}, cur);
79 os << llvm::formatv(
"FieldRefCache stats:\n"
83 hits, computed, queries);
86 size_t &totalComputed,
87 size_t &totalQueries)
const {
89 totalComputed += computed;
90 totalQueries += queries;
95 for (
auto &[key, ref] : refs)
assert(baseType &&"element must be base type")
This class represents a reference to a specific field or element of an aggregate value.
llvm::PointerIntPair< Value, 1, bool > Key
void addToTotals(size_t &totalHits, size_t &totalComputed, size_t &totalQueries) const
void printStats(llvm::raw_ostream &os) const
FieldRef getFieldRefFromValue(Value value, bool lookThroughCasts=false)
Caching version of getFieldRefFromValue.
FieldRef getDeltaRef(Value value, bool lookThroughCasts=false)
Get the delta indexing from a value, as a FieldRef.
FieldRef getFieldRefFromValue(Value value, bool lookThroughCasts=false)
Get the FieldRef from a value.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.