private void PutIntoCache(Node stmt, double execOrder) { _execOrders.Add(stmt, execOrder); // todo. use Family instead of ChildrenRecursive and make this not crash var usages = stmt.ChildrenRecursive().Where(n => n.IsAtom()).ToReadOnly(); foreach (Expression u in usages) { _atoms.Add(u); var cache = _usages.GetOrCreate(u, () => new List<Expression>()); var ins = cache.TakeWhile((u2, i) => _execOrders[u2.Stmt()] <= execOrder).Count(); var isAssignToAtom = u.Parent is Assign && ((Assign)u.Parent).Lhs == u; cache.Insert(ins, isAssignToAtom ? u.Parent.AssertCast<Assign>() : u); } }
private void EvictFromCache(Node stmt) { _execOrders.Remove(stmt); // todo. use Family instead of ChildrenRecursive and make this not crash var atoms = stmt.ChildrenRecursive().Where(n => n.IsAtom()).Distinct(Node.EquivComparer()).ToReadOnly(); foreach (Expression atom in atoms) { _usages[atom].RemoveElements(e => e.Stmt() == stmt); if (_usages[atom].IsEmpty()) _atoms.Remove(atom); } }