Пример #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);
        }
Пример #2
0
        private static bool IsVersionToBeReplaced(VarVersionPair usedvar, Dictionary <int
                                                                                      , HashSet <VarVersionPair> > mapVars, SSAUConstructorSparseEx ssau, VarVersionPair
                                                  leftpaar)
        {
            VarVersionsGraph    ssuversions = ssau.GetSsuversions();
            SFormsFastMapDirect mapLiveVars = ssau.GetLiveVarVersionsMap(usedvar);

            if (mapLiveVars == null)
            {
                // dummy version, predecessor of a phi node
                return(false);
            }
            // compare protected ranges
            if (!InterpreterUtil.EqualObjects(ssau.GetMapVersionFirstRange().GetOrNullable(leftpaar
                                                                                           ), ssau.GetMapVersionFirstRange().GetOrNullable(usedvar)))
            {
                return(false);
            }
            foreach (KeyValuePair <int, HashSet <VarVersionPair> > ent in mapVars)
            {
                FastSparseSetFactory <int> .FastSparseSet <int> liveverset = mapLiveVars.Get(ent.Key);
                if (liveverset == null)
                {
                    return(false);
                }
                HashSet <VarVersionNode> domset = new HashSet <VarVersionNode>();
                foreach (VarVersionPair verpaar in ent.Value)
                {
                    domset.Add(ssuversions.nodes.GetWithKey(verpaar));
                }
                bool isdom = false;
                foreach (int livever in liveverset)
                {
                    VarVersionNode node = ssuversions.nodes.GetWithKey(new VarVersionPair(ent.Key, livever
                                                                                          ));
                    if (ssuversions.IsDominatorSet(node, domset))
                    {
                        isdom = true;
                        break;
                    }
                }
                if (!isdom)
                {
                    return(false);
                }
            }
            return(true);
        }
Пример #3
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);
                }
            }
        }