Don't get newly added Def's from RecordKeeper->getAllDerivedDefinitions

Hi everyone.
I am currently working on improving Enzyme by adding explicit Blas support via tablegen.
I’m exploring a bit to learn tg and ran in some issues which I’d like to understand better (despite being able to work around them).
Simpler, non-blas functions are already working nicely, however I ran into an inconvenience when trying to update the record-keeper, since my updates don’t always seem to be propagated.
I already worked around it by naming my defines in the .td file, but would still be interested in the issue.

The derivative of one blas function might involve another blas function, so I wanted to be able to quickly look up the dag of that other function, without iterating through all blas functions till I find the correct one.
To achieve this I added a “base” class in my .td file:

class BlasInst<dag d> : Inst<"blas"> {
  dag args = d;

and create a new Definition extending that class for every Blas instruction processed. The new definition is named based on the blas fnc and only contains the DAG patternToMatch. I managed to create definitions and add them all to the RK or pass them around. However I have not been able to get the definitions back trough the RK when asking for all derived definitions.

void emitBlasPrimals(RecordKeeper &RK, const std::vector<Record *> &blasPattern,
                     raw_ostream &os) {
  using llvm::RecTy;

  // get Blas superclass which we will populate afterwards
  Record *BlasInst = RK.getClass("BlasInst");
  const auto &foo = RK.getAllDerivedDefinitions("BlasInst");
  assert(foo.size() == 0); // no user-impl allowed

  Record *BlasClass = RK.getClass("BlasNames");
  std::vector<StringRef> blasNamesVec{};

  // Now create primal defs from all BlasPattern
  for (auto pattern : blasPattern) {
    auto name = pattern->getValueAsString("name");

    // Create a Record
    SMLoc loc{};
    ArrayRef arr(loc);
    Record r = Record(name, arr, RK);
    DagInit *d = pattern->getValueAsDag("PatternToMatch");
    // once other bugs are fixed, change to set value directly instead of templateArg?

    // Mark Record as impl BlasInst to easier find them later
    r.addSuperClass(BlasInst, SMRange());


  // next works, so dot Def is created and added to RK
  const auto dotDef = RK.getDef("dot");
  assert(dotDef->hasDirectSuperClass(BlasInst)); // passes too
  // const auto &bar = RK.getAllDerivedDefinitions(BlasInst->getName());
  const auto &bar = RK.getAllDerivedDefinitions("BlasInst"); // empty ?
  llvm::errs() << bar.size() << " "           // 0
               << blasPattern.size() << "\n"; // 9
  // next ones doesn't work since RK doesn't update itself here?
  assert(bar.size() == blasPattern.size()); // all impl generated