Exemplo n.º 1
0
        private static Dictionary <int, HashSet <VarVersionPair> > GetAllVarVersions(VarVersionPair
                                                                                     leftvar, Exprent exprent, SSAUConstructorSparseEx ssau)
        {
            Dictionary <int, HashSet <VarVersionPair> > map = new Dictionary <int, HashSet <VarVersionPair
                                                                                            > >();
            SFormsFastMapDirect mapLiveVars = ssau.GetLiveVarVersionsMap(leftvar);
            List <Exprent>      lst         = exprent.GetAllExprents(true);

            lst.Add(exprent);
            foreach (Exprent expr in lst)
            {
                if (expr.type == Exprent.Exprent_Var)
                {
                    int varindex = ((VarExprent)expr).GetIndex();
                    if (leftvar.var != varindex)
                    {
                        if (mapLiveVars.ContainsKey(varindex))
                        {
                            HashSet <VarVersionPair> verset = new HashSet <VarVersionPair>();
                            foreach (int vers in mapLiveVars.Get(varindex))
                            {
                                verset.Add(new VarVersionPair(varindex, vers));
                            }
                            Sharpen.Collections.Put(map, varindex, verset);
                        }
                        else
                        {
                            throw new Exception("inkonsistent live map!");
                        }
                    }
                    else
                    {
                        Sharpen.Collections.Put(map, varindex, null);
                    }
                }
                else if (expr.type == Exprent.Exprent_Field)
                {
                    if (ssau.GetMapFieldVars().ContainsKey(expr.id))
                    {
                        int?varindex = ssau.GetMapFieldVars().GetOrNullable(expr.id);
                        if (mapLiveVars.ContainsKey(varindex.Value))
                        {
                            HashSet <VarVersionPair> verset = new HashSet <VarVersionPair>();
                            foreach (int vers in mapLiveVars.Get(varindex.Value))
                            {
                                verset.Add(new VarVersionPair(varindex.Value, vers));
                            }
                            Sharpen.Collections.Put(map, varindex.Value, verset);
                        }
                    }
                }
            }
            return(map);
        }
Exemplo n.º 2
0
        private static void ReplaceSingleVar(Exprent parent, VarExprent var, Exprent dest
                                             , SSAUConstructorSparseEx ssau)
        {
            parent.ReplaceExprent(var, dest);
            // live sets
            SFormsFastMapDirect      livemap = ssau.GetLiveVarVersionsMap(new VarVersionPair(var));
            HashSet <VarVersionPair> setVars = GetAllVersions(dest);

            foreach (VarVersionPair varpaar in setVars)
            {
                VarVersionNode node      = ssau.GetSsuversions().nodes.GetWithKey(varpaar);
                var            toRemove  = new List <KeyValuePair <int, FastSparseSetFactory <int> .FastSparseSet <int> > >();
                var            entryList = node.live.EntryList();
                for (var index = 0; index < entryList.Count; index++)
                {
                    var itent = entryList[index];
                    KeyValuePair <int, FastSparseSetFactory <int> .FastSparseSet <int> > ent =
                        entryList.ElementAtOrDefault(index + 1);
                    if (ent.Value == null)
                    {
                        break;
                    }

                    int key = ent.Key;
                    if (!livemap.ContainsKey(key))
                    {
                        toRemove.Add(itent);
                    }
                    else
                    {
                        FastSparseSetFactory <int> .FastSparseSet <int> set = ent.Value;
                        set.Complement(livemap.Get(key));
                        if (set.IsEmpty())
                        {
                            toRemove.Add(itent);
                        }
                    }
                }

                foreach (var keyValuePair in toRemove)
                {
                    node.live.PutInternal(keyValuePair.Key, keyValuePair.Value, true);
                    // entryList.RemoveAll(c => c.Key == keyValuePair.Key);
                }
            }
        }