Exemplo n.º 1
0
        private void RenameLocals()
        {
            HashBasedPropMap <int, int> indexMap = new HashBasedPropMap <int, int>();
            int nextIndex = 0;

            for (int localIndex = 0; localIndex < _numLocals; localIndex++)
            {
                HashSet <int> storePoints = _storePoints[localIndex];
                foreach (int storePoint in storePoints)
                {
                    if (!indexMap.ContainsKey(storePoint))
                    {
                        indexMap[storePoint] = nextIndex++;
                    }
                    HashSet <int> uses = _varUses.Get(storePoint);
                    foreach (int usePoint in uses)
                    {
                        if (!indexMap.ContainsKey(usePoint))
                        {
                            indexMap[usePoint] = nextIndex++;
                        }
                    }
                }
            }

            ISetAdapter <int> a           = new SetAdapter(indexMap);
            IEnumerable <int> orderedKeys = indexMap.Keys.OrderBy(key => indexMap[key]);
            UnionFind <int>   uf          = new UnionFind <int>(a, orderedKeys.ToList());

            for (int localIndex = 0; localIndex < _numLocals; localIndex++)
            {
                HashSet <int> storePoints = _storePoints[localIndex];
                foreach (int storePoint in storePoints)
                {
                    HashSet <int> uses = _varUses.Get(storePoint);
                    foreach (int usePoint in uses)
                    {
                        uf.Union(storePoint, usePoint);
                    }
                }
            }

            _renamings = new Dictionary <Tuple <int, int>, int>();
            for (int localIndex = 0; localIndex < _numLocals; localIndex++)
            {
                HashSet <int> storePoints = _storePoints[localIndex];
                nextIndex = 0;
                foreach (int storePoint in storePoints)
                {
                    int repr = uf.Find(storePoint);
                    int index;
                    if (!_renamings.TryGetValue(Tuple.Create(localIndex, repr), out index))
                    {
                        index = nextIndex++;
                        _renamings[Tuple.Create(localIndex, repr)] = index;
                    }
                    _renamings[Tuple.Create(localIndex, storePoint)] = index;
                    HashSet <int> uses = _varUses.Get(storePoint);
                    foreach (int usePoint in uses)
                    {
                        _renamings[Tuple.Create(localIndex, usePoint)] = index;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public TypePaths(Type rootType)
 {
     RootType = rootType;
     Preds    = new HashBasedPropMap <Type, Type>();
     RootDist = new HashBasedPropMap <Type, int>();
 }