예제 #1
0
 private bool IsStageDependence(SCC <string> Src, SCC <string> Dst)
 {
     foreach (var c in Src)
     {
         foreach (var d in AnnotationDependences.Successors(c))
         {
             if (Dst.Contains(d))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #2
0
 private bool FindInDAG(Graph <SCC <string> > DAG, SCC <string> toFind, SCC <string> start)
 {
     if (toFind == start)
     {
         return(true);
     }
     foreach (var n in DAG.Successors(start))
     {
         if (FindInDAG(DAG, toFind, n))
         {
             return(true);
         }
     }
     return(false);
 }
        public HashSet <VariableDescriptor> DependsOn(VariableDescriptor v)
        {
            if (DependsOnSCCsDAG == null)
            {
                if (CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Variable dependence: computing SCCs");
                }

                Adjacency <VariableDescriptor> next = new Adjacency <VariableDescriptor>(dependsOnNonTransitive.Successors);
                Adjacency <VariableDescriptor> prev = new Adjacency <VariableDescriptor>(dependsOnNonTransitive.Predecessors);
                StronglyConnectedComponents <VariableDescriptor> DependsOnSCCs =
                    new StronglyConnectedComponents <VariableDescriptor>(
                        dependsOnNonTransitive.Nodes, next, prev);
                DependsOnSCCs.Compute();

                VariableDescriptorToSCC = new Dictionary <VariableDescriptor, SCC <VariableDescriptor> >();
                foreach (var scc in DependsOnSCCs)
                {
                    foreach (var s in scc)
                    {
                        VariableDescriptorToSCC[s] = scc;
                    }
                }

                DependsOnSCCsDAG = new Graph <SCC <VariableDescriptor> >();
                foreach (var edge in dependsOnNonTransitive.Edges)
                {
                    if (VariableDescriptorToSCC[edge.Item1] != VariableDescriptorToSCC[edge.Item2])
                    {
                        DependsOnSCCsDAG.AddEdge(VariableDescriptorToSCC[edge.Item1], VariableDescriptorToSCC[edge.Item2]);
                    }
                }

                SCC <VariableDescriptor> dummy = new SCC <VariableDescriptor>();
                foreach (var n in dependsOnNonTransitive.Nodes)
                {
                    DependsOnSCCsDAG.AddEdge(VariableDescriptorToSCC[n], dummy);
                }

                if (CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Variable dependence: SCCs computed!");
                }
            }

            return(DependsOn(VariableDescriptorToSCC[v]));
        }
예제 #4
0
        public bool MayReach(Block src, Block dst)
        {
            if (ReachabilityGraphSCCsDAG == null)
            {
                if (CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Interprocedural reachability: computing SCCs");
                }

                Adjacency <Block> next = new Adjacency <Block>(reachabilityGraph.Successors);
                Adjacency <Block> prev = new Adjacency <Block>(reachabilityGraph.Predecessors);
                StronglyConnectedComponents <Block> ReachabilitySCCs = new StronglyConnectedComponents <Block>(
                    reachabilityGraph.Nodes, next, prev);
                ReachabilitySCCs.Compute();

                BlockToSCC = new Dictionary <Block, SCC <Block> >();
                foreach (var scc in ReachabilitySCCs)
                {
                    foreach (var s in scc)
                    {
                        BlockToSCC[s] = scc;
                    }
                }

                ReachabilityGraphSCCsDAG = new Graph <SCC <Block> >();
                foreach (var edge in reachabilityGraph.Edges)
                {
                    if (BlockToSCC[edge.Item1] != BlockToSCC[edge.Item2])
                    {
                        ReachabilityGraphSCCsDAG.AddEdge(BlockToSCC[edge.Item1], BlockToSCC[edge.Item2]);
                    }
                }

                SCC <Block> dummy = new SCC <Block>();
                foreach (var n in reachabilityGraph.Nodes)
                {
                    ReachabilityGraphSCCsDAG.AddEdge(BlockToSCC[n], dummy);
                }

                if (CommandLineOptions.Clo.Trace)
                {
                    Console.WriteLine("Interprocedural reachability: SCCs computed!");
                }
            }

            return(ReachableFrom(BlockToSCC[src]).Contains(dst));
        }
        private void ConstructStagesDAG()
        {
            if (CommandLineOptions.Clo.Trace)
            {
                Console.WriteLine("Annotation dependence analysis: Computing SCCs");
            }

            Adjacency <string> next = new Adjacency <string>(AnnotationDependences.Successors);
            Adjacency <string> prev = new Adjacency <string>(AnnotationDependences.Predecessors);

            SCCs = new StronglyConnectedComponents <string>(
                AnnotationDependences.Nodes, next, prev);
            SCCs.Compute();

            if (CommandLineOptions.Clo.Trace)
            {
                Console.WriteLine("Annotation dependence analysis: Building stages DAG");
            }

            Dictionary <string, SCC <string> > rep = new Dictionary <string, SCC <string> >();

            foreach (var scc in SCCs)
            {
                foreach (var s in scc)
                {
                    rep[s] = scc;
                }
            }

            StagesDAG = new Graph <SCC <string> >();

            foreach (var edge in AnnotationDependences.Edges)
            {
                if (rep[edge.Item1] != rep[edge.Item2])
                {
                    StagesDAG.AddEdge(rep[edge.Item1], rep[edge.Item2]);
                }
            }

            SCC <string> dummy = new SCC <string>();

            foreach (var scc in SCCs)
            {
                StagesDAG.AddEdge(scc, dummy);
            }
        }
 private HashSet <Block> ReachableFrom(SCC <Block> scc)
 {
     if (!MayReachCache.ContainsKey(scc))
     {
         HashSet <Block> result = new HashSet <Block>();
         if (scc.Count() > 0)
         {
             result.UnionWith(scc);
             foreach (var nextSCC in ReachabilityGraphSCCsDAG.Successors(scc))
             {
                 result.UnionWith(ReachableFrom(nextSCC));
             }
         }
         MayReachCache[scc] = result;
     }
     return(MayReachCache[scc]);
 }
예제 #7
0
 public HashSet <VariableDescriptor> DependsOn(SCC <VariableDescriptor> vSCC)
 {
     if (!DependsOnCache.ContainsKey(vSCC))
     {
         HashSet <VariableDescriptor> result = new HashSet <VariableDescriptor>();
         if (vSCC.Count() > 0)
         {
             result.UnionWith(vSCC);
             foreach (var wSCC in DependsOnSCCsDAG.Successors(vSCC))
             {
                 result.UnionWith(DependsOn(wSCC));
             }
         }
         DependsOnCache[vSCC] = result;
     }
     return(DependsOnCache[vSCC]);
 }
예제 #8
0
        private static void DumpSCC(SCC <string> component)
        {
            var sortedComponent = component.ToList();

            sortedComponent.Sort();
            Console.Write("{ ");
            bool first = true;

            foreach (var s in sortedComponent)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    Console.Write(", ");
                }
                Console.Write(s);
            }
            Console.Write(" }");
        }
 private bool IsStageDependence(SCC<string> Src, SCC<string> Dst)
 {
     foreach (var c in Src) {
     foreach (var d in CandidateDependences.Successors(c)) {
       if (Dst.Contains(d)) {
     return true;
       }
     }
       }
       return false;
 }
예제 #10
0
        private void  InitBlock()
        {
            if (!Head.containsKey(g.toString()))
            {
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                H = new TreeSet <Integer>();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_g_it.hasNext())
                {
                    Arc arc_g = arc_g_it.next();
                    if (arc_g.From == init)
                    {
                        H.add(arc_g.To);
                    }
                }
                Head.put(g.toString(), H);
            }

            if (!Tail.containsKey(h.toString()))
            {
                FiniteAutomaton fa = new FiniteAutomaton();
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                OneToOneTreeMap <Integer, FAState> st = new OneToOneTreeMap <Integer, FAState>();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_h_it.hasNext())
                {
                    Arc arc_h = arc_h_it.next();
                    if (!st.containsKey(arc_h.From))
                    {
                        st.put(arc_h.From, fa.createState());
                    }
                    if (!st.containsKey(arc_h.To))
                    {
                        st.put(arc_h.To, fa.createState());
                    }
                    fa.addTransition(st.getValue(arc_h.From), st.getValue(arc_h.To), arc_h.Label?"1":"0");
                }
                SCC s = new SCC(fa);
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                T = new TreeSet <Integer>();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (s_it.hasNext())
                {
                    T.add(st.getKey(s_it.next()));
                }
                int TailSize = 0;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (TailSize != T.size())
                {
                    TailSize = T.size();
                    //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                    TreeSet <Arc> isolatedArcsTemp = new TreeSet <Arc>();
                    //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                    while (arc_it.hasNext())
                    {
                        Arc arc = arc_it.next();
                        if (!T.contains(arc.To))
                        {
                            isolatedArcsTemp.add(arc);
                        }
                        else
                        {
                            T.add(arc.From);
                        }
                    }
                    isolatedArcs = isolatedArcsTemp;
                }
                Tail.put(h.toString(), T);
            }
            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            TreeSet <Integer> intersection = new TreeSet <Integer>();

            intersection.addAll(Head.get_Renamed(g.toString()));
            intersection.retainAll(Tail.get_Renamed(h.toString()));
            if (debug_Renamed_Field)
            {
                if (intersection.isEmpty())
                {
                    debug("g:" + g + ", Head: " + Head.get_Renamed(g.toString()));
                    debug("h:" + h + ", Tail: " + Tail.get_Renamed(h.toString()));
                }
            }
            return(!intersection.isEmpty());

            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            ArrayList <TreeSet <Arc> > graphs = new ArrayList <TreeSet <Arc> >();

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (symbol_it.hasNext())
            {
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                TreeSet <Arc> graph = new TreeSet <Arc>();

                System.String sym = symbol_it.next();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (from_it.hasNext())
                {
                    cav2010.automata.FAState from = from_it.next();
                    if (from.getNext(sym) != null)
                    {
                        //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                        while (to_it.hasNext())
                        {
                            cav2010.automata.FAState to = to_it.next();
                            if (input.F.contains(from) || input.F.contains(to))
                            {
                                graph.add(new Arc(from.id, true, to.id));
                            }
                            else
                            {
                                graph.add(new Arc(from.id, false, to.id));
                            }
                        }
                    }
                }
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                ArrayList <TreeSet <Arc> > toRemove = new ArrayList <TreeSet <Arc> >();
                bool canAdd = true;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (old_it.hasNext())
                {
                    //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                    if (smallerThan(old, graph))
                    {
                        canAdd = false;
                        break;
                    }
                    else if (smallerThan(graph, old))
                    {
                        toRemove.add(old);
                    }
                }
                if (canAdd)
                {
                    graphs.add(graph);
                    graphs.removeAll(toRemove);
                }
            }
            return(graphs);

            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            TreeSet <Arc> f = new TreeSet <Arc>();

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (arc_g_it.hasNext())
            {
                Arc arc_g = arc_g_it.next();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_h_it.hasNext())
                {
                    Arc arc_h = arc_h_it.next();
                    if (arc_g.To == arc_h.From)
                    {
                        if (arc_g.Label || arc_h.Label)
                        {
                            f.add(new Arc(arc_g.From, true, arc_h.To));
                            f.remove(new Arc(arc_g.From, false, arc_h.To));
                        }
                        else
                        {
                            if (!f.contains(new Arc(arc_g.From, true, arc_h.To)))
                            {
                                f.add(new Arc(arc_g.From, false, arc_h.To));
                            }
                        }
                    }
                }
            }
            return(f);

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (arc_g_it.hasNext())
            {
                Arc  arc_g      = arc_g_it.next();
                bool has_larger = false;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_h_it.hasNext())
                {
                    Arc arc_h = arc_h_it.next();
                    if (arc_g.From == arc_h.From)
                    {
                        if (!arc_g.Label || arc_h.Label)
                        {
                            if (arc_g.To == arc_h.To)
                            {
                                has_larger = true;
                                break;
                            }
                        }
                    }
                }
                if (!has_larger)
                {
                    return(false);
                }
            }
            return(true);
        }
예제 #11
0
	private bool lasso_finding_test(HashSet<Arc> g, HashSet<Arc> h, int init){
		if(!Head.ContainsKey(g.ToString())){
			HashSet<int> H=new HashSet<int>();

		    foreach (Arc arc_g in g)
		    {
		        if(arc_g.From==init){
					H.Add(arc_g.To);
				}
			}
			Head.Add(g.ToString(), H);
		}
		if(!Tail.ContainsKey(h.ToString())){
			Automata fa=new Automata();
			OneToOneTreeMap<int,cav2010.automata.FAState> st=new OneToOneTreeMap<int,FAState>();
		    foreach (Arc arc_h in h)
		    {
		        if(!st.containsKey(arc_h.From))
					st.put(arc_h.From, fa.createState());
				if(!st.containsKey(arc_h.To))
					st.put(arc_h.To, fa.createState());
				fa.addTransition(st.getValue(arc_h.From), st.getValue(arc_h.To), arc_h.Label?"1":"0");
			}
			SCC s=new SCC(fa);
			HashSet<int> T=new HashSet<int>();
            foreach (FAState state in s.getResult())
		    {
		        T.Add(st.getKey(state));
			}

			int TailSize=0;
			HashSet<Arc> isolatedArcs=h;
			while(TailSize!=T.Count){
                TailSize = T.Count;

				HashSet<Arc> isolatedArcsTemp=new HashSet<Arc>();

			    foreach (Arc arc in isolatedArcs)
			    {
			        if(!T.Contains(arc.To)){
						isolatedArcsTemp.Add(arc);
					}else{
						T.Add(arc.From);
					}
				}
				isolatedArcs=isolatedArcsTemp;
			}
			Tail.Add(h.ToString(), T);
		}
        HashSet<int> intersection = new HashSet<int>(Head[g.ToString()]);
		//intersection.retainAll(Tail[h.ToString()]);

        intersection.IntersectWith(Tail[h.ToString()]);
		
        //if(debug){
        //    if(intersection.isEmpty()){
        //        //debug("g_graph:"+g+", Head: "+Head.get(g.ToString()));
        //        //debug("h_graph:"+h+", Tail: "+Tail.get(h.ToString()));
        //    }
        //}
		
		return intersection.Count > 0;
	}
        public HashSet<VariableDescriptor> DependsOn(VariableDescriptor v)
        {
            if (DependsOnSCCsDAG == null) {
            if (CommandLineOptions.Clo.Trace) {
              Console.WriteLine("Variable dependence: computing SCCs");
            }
            Adjacency<VariableDescriptor> next = new Adjacency<VariableDescriptor>(dependsOnNonTransitive.Successors);
            Adjacency<VariableDescriptor> prev = new Adjacency<VariableDescriptor>(dependsOnNonTransitive.Predecessors);
            StronglyConnectedComponents<VariableDescriptor> DependsOnSCCs = new StronglyConnectedComponents<VariableDescriptor>(
              dependsOnNonTransitive.Nodes, next, prev);
            DependsOnSCCs.Compute();

            VariableDescriptorToSCC = new Dictionary<VariableDescriptor, SCC<VariableDescriptor>>();
            foreach (var scc in DependsOnSCCs) {
              foreach (var s in scc) {
            VariableDescriptorToSCC[s] = scc;
              }
            }

            DependsOnSCCsDAG = new Graph<SCC<VariableDescriptor>>();
            foreach (var edge in dependsOnNonTransitive.Edges) {
              if (VariableDescriptorToSCC[edge.Item1] != VariableDescriptorToSCC[edge.Item2]) {
            DependsOnSCCsDAG.AddEdge(VariableDescriptorToSCC[edge.Item1], VariableDescriptorToSCC[edge.Item2]);
              }
            }

            SCC<VariableDescriptor> dummy = new SCC<VariableDescriptor>();
            foreach (var n in dependsOnNonTransitive.Nodes) {
              DependsOnSCCsDAG.AddEdge(VariableDescriptorToSCC[n], dummy);
            }

            if (CommandLineOptions.Clo.Trace) {
              Console.WriteLine("Variable dependence: SCCs computed!");
            }
              }
              return DependsOn(VariableDescriptorToSCC[v]);
        }
예제 #13
0
 /// <summary>
 /// Returns true if the other SCC refers to the same SCC.
 /// </summary>
 /// <param name="other">The other SCC.</param>
 /// <returns>True, if the other SCC refers to the same SCC.</returns>
 public bool Equals(SCC other) =>
 other.Parent == Parent && other.Index == Index;
예제 #14
0
        private void  InitBlock()
        {
            if (!Head.containsKey(g.toString()))
            {
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                TreeSet <Integer> H = new TreeSet <Integer>();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_g_it.hasNext())
                {
                    Arc arc_g = arc_g_it.next();
                    if (arc_g.From == init)
                    {
                        H.add(arc_g.To);
                    }
                }
                Head.put(g.toString(), H);
            }
            if (!Tail.containsKey(h.toString()))
            {
                FiniteAutomaton fa = new FiniteAutomaton();
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                OneToOneTreeMap <Integer, cav2010.automata.FAState> st = new OneToOneTreeMap <Integer, cav2010.automata.FAState>();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_h_it.hasNext())
                {
                    Arc arc_h = arc_h_it.next();
                    if (!st.containsKey(arc_h.From))
                    {
                        st.put(arc_h.From, fa.createState());
                    }
                    if (!st.containsKey(arc_h.To))
                    {
                        st.put(arc_h.To, fa.createState());
                    }
                    fa.addTransition(st.getValue(arc_h.From), st.getValue(arc_h.To), arc_h.Label?"1":"0");
                }
                SCC s = new SCC(fa);
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                TreeSet <Integer> T = new TreeSet <Integer>();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (s_it.hasNext())
                {
                    T.add(st.getKey(s_it.next()));
                }
                int TailSize = 0;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (TailSize != T.size())
                {
                    TailSize = T.size();
                    //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                    TreeSet <Arc> isolatedArcsTemp = new TreeSet <Arc>();
                    //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                    while (arc_it.hasNext())
                    {
                        Arc arc = arc_it.next();
                        if (!T.contains(arc.To))
                        {
                            isolatedArcsTemp.add(arc);
                        }
                        else
                        {
                            T.add(arc.From);
                        }
                    }
                    isolatedArcs = isolatedArcsTemp;
                }
                Tail.put(h.toString(), T);
            }
            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            TreeSet <Integer> intersection = new TreeSet <Integer>();

            intersection.addAll(Head.get_Renamed(g.toString()));
            intersection.retainAll(Tail.get_Renamed(h.toString()));

            if (debug_Renamed_Field)
            {
                if (intersection.isEmpty())
                {
                    debug("g:" + g + ", Head: " + Head.get_Renamed(g.toString()));
                    debug("h:" + h + ", Tail: " + Tail.get_Renamed(h.toString()));
                }
            }

            return(!intersection.isEmpty());

            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            TreeSet <Arc> result = new TreeSet <Arc>();

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (arc_it1.hasNext())
            {
                Arc  cur    = arc_it1.next();
                bool canAdd = true;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_it2.hasNext())
                {
                    Arc other = arc_it2.next();
                    if (cur.From == other.From)
                    {
                        if (!cur.Label || other.Label)
                        {
                            if (cur.To != other.To)
                            {
                                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                                if (rel.contains(new Pair <FAState, FAState>(new FAState(cur.getTo()), new FAState(other.getTo()))) &&
                                    result.contains(other))
                                {
                                    canAdd = false;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (canAdd)
                {
                    result.add(cur);
                }
            }
            return(result);

            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            ArrayList <TreeSet <Arc> > graphs = new ArrayList <TreeSet <Arc> >();

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (symbol_it.hasNext())
            {
                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                TreeSet <Arc> graph = new TreeSet <Arc>();

                System.String sym = symbol_it.next();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (from_it.hasNext())
                {
                    FAState from = from_it.next();
                    if (from.getNext(sym) != null)
                    {
                        //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                        while (to_it.hasNext())
                        {
                            FAState to = to_it.next();
                            if (input.F.contains(from) || input.F.contains(to))
                            {
                                graph.add(new Arc(from.id, true, to.id));
                            }
                            else
                            {
                                graph.add(new Arc(from.id, false, to.id));
                            }
                        }
                    }
                }

                //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                ArrayList <TreeSet <Arc> > toRemove = new ArrayList <TreeSet <Arc> >();
                bool canAdd = true;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (old_it.hasNext())
                {
                    //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                    if (smallerThan(old, graph, rel))
                    {
                        canAdd = false;
                        break;
                    }
                    else if (smallerThan(graph, old, rel))
                    {
                        toRemove.add(old);
                    }
                }
                if (canAdd)
                {
                    if (opt2)
                    {
                        graphs.add(min(graph));
                    }
                    else
                    {
                        graphs.add(graph);
                    }
                    graphs.removeAll(toRemove);
                }
            }
            return(graphs);

            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            TreeSet <Arc> f = new TreeSet <Arc>();

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (arc_g_it.hasNext())
            {
                Arc arc_g = arc_g_it.next();
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_h_it.hasNext())
                {
                    Arc arc_h = arc_h_it.next();
                    if (arc_g.To == arc_h.From)
                    {
                        if (arc_g.Label || arc_h.Label)
                        {
                            f.add(new Arc(arc_g.From, true, arc_h.To));
                            f.remove(new Arc(arc_g.From, false, arc_h.To));
                        }
                        else
                        {
                            if (!f.contains(new Arc(arc_g.From, true, arc_h.To)))
                            {
                                f.add(new Arc(arc_g.From, false, arc_h.To));
                            }
                        }
                    }
                }
            }
            return(f);

            //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
            while (arc_g_it.hasNext())
            {
                Arc  arc_g      = arc_g_it.next();
                bool has_larger = false;
                //UPGRADE_NOTE: There is an untranslated Statement.  Please refer to original code. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1153'"
                while (arc_h_it.hasNext())
                {
                    Arc arc_h = arc_h_it.next();
                    if (arc_g.From == arc_h.From)
                    {
                        if (!arc_g.Label || arc_h.Label)
                        {
                            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
                            if (rel.contains(new Pair <FAState, FAState>(new FAState(arc_g.getTo()), new FAState(arc_h.getTo()))))
                            {
                                has_larger = true;
                                break;
                            }
                        }
                    }
                }
                if (!has_larger)
                {
                    return(false);
                }
            }
            return(true);

            FAState[] states  = input.states.toArray(new FAState[0]);
            bool[]    isFinal = new bool[states.Length];
            bool[][]  fsim    = new bool[states.Length][];
            for (int i = 0; i < states.Length; i++)
            {
                fsim[i] = new bool[states.Length];
            }
            // sim[u][v]=true iff v in sim(u) iff v simulates u

            for (int i = 0; i < states.Length; i++)
            {
                isFinal[i] = input.F.contains(states[i]);
            }
            for (int i = 0; i < states.Length; i++)
            {
                for (int j = i; j < states.Length; j++)
                {
                    fsim[i][j] = (!isFinal[i] || isFinal[j]) && states[j].covers(states[i]);
                    fsim[j][i] = (isFinal[i] || !isFinal[j]) && states[i].covers(states[j]);
                }
            }
            Simulation sim = new Simulation();
            //UPGRADE_ISSUE: The following fragment of code could not be parsed and was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1156'"
            Set <Pair <FAState, FAState> > FSim = sim.FastFSimRelNBW(input, fsim);

            return(FSim);
        }
예제 #15
0
 internal PhiValueEnumerator(SCC parent)
 {
     Parent     = parent;
     enumerator = parent.GetValueEnumerator();
 }
 public HashSet<VariableDescriptor> DependsOn(SCC<VariableDescriptor> vSCC)
 {
     if (!DependsOnCache.ContainsKey(vSCC)) {
     HashSet<VariableDescriptor> result = new HashSet<VariableDescriptor>();
     if (vSCC.Count() > 0) {
       result.UnionWith(vSCC);
       foreach (var wSCC in DependsOnSCCsDAG.Successors(vSCC)) {
     result.UnionWith(DependsOn(wSCC));
       }
     }
     DependsOnCache[vSCC] = result;
       }
       return DependsOnCache[vSCC];
 }
예제 #17
0
파일: 2337070.cs 프로젝트: qifanyyy/CLCDSA
    public void Solve()
    {
        List <int>[] E  = new List <int> [N];
        List <int>[] XE = new List <int> [N];
        for (int i = 0; i < N; i++)
        {
            E[i]  = new List <int>();
            XE[i] = new List <int>();
        }
        for (int i = 0; i < N; i++)
        {
            E[P[i]].Add(i);
            XE[i].Add(P[i]);
        }



        var scc = new SCC();

        scc.Init(N, E, XE);
        scc.CalcCompo();
        if (scc.Compo == N)
        {
            Console.WriteLine("POSSIBLE");
            return;
        }

        if (scc.Compo == 1)
        {
            Console.WriteLine(N % 2 == 0 ? "POSSIBLE" : "IMPOSSIBLE");
            return;
        }

        int M = scc.Compo;

        List <int>[] sc = new List <int> [M];
        for (int i = 0; i < M; i++)
        {
            sc[i] = new List <int>();
        }

        int cyc = -1;

        for (int i = 0; i < N; i++)
        {
            sc[scc.Mem[i]].Add(i);
            if (sc[scc.Mem[i]].Count > 1)
            {
                cyc = scc.Mem[i];
            }
        }

        Pair[] ar = new Pair[N];
        for (int i = 0; i < N; i++)
        {
            ar[i] = new Pair(i, scc.Mem[i]);
        }

        Array.Sort(ar, (p, q) => p.Order.CompareTo(q.Order));
        Array.Reverse(ar);

//Console.WriteLine(String.Join(" ",ar.Select(p => String.Format("[{0},{1}]",p.Idx,p.Order))));

        int[] gr = new int[N];
        for (int i = 0; i < N; i++)
        {
            gr[i] = -1;
        }

        foreach (var p in ar)
        {
            if (p.Order == cyc)
            {
                break;
            }
            int now = p.Idx;
            var hs  = new HashSet <int>();
            foreach (var nxt in E[now])
            {
                hs.Add(gr[nxt]);
            }
            int g = 0;
            while (hs.Contains(g))
            {
                g++;
            }
            gr[now] = g;
        }

        int p0  = sc[cyc][0];
        var hss = new HashSet <int>();

        foreach (var nxt in E[p0])
        {
            hss.Add(gr[nxt]);
        }
        List <int> gg = new List <int>();
        int        g0 = 0;

        while (hss.Contains(g0))
        {
            g0++;
        }
        gg.Add(g0);
        hss.Add(g0);
        while (hss.Contains(g0))
        {
            g0++;
        }
        gg.Add(g0);

        // cycle ?List??????
        List <int> loop = new List <int>();

        loop.Add(p0);
        while (true)
        {
            int now = loop[loop.Count - 1];
            foreach (var nxt in E[now])
            {
                if (scc.Mem[nxt] == cyc)
                {
                    loop.Add(nxt);
                    break;
                }
            }
            if (loop[loop.Count - 1] == p0)
            {
                loop.RemoveAt(loop.Count - 1);
                break;
            }
        }

//Console.WriteLine(String.Join(" -> ",loop));


        // p0 ? min?????
        int[] gr0 = new int[N];
        for (int i = 0; i < N; i++)
        {
            gr0[i] = gr[i];
        }
        gr0[p0] = gg[0];
        for (int i = loop.Count - 1; i >= 0; i--)
        {
            int now = loop[i];
            var hs  = new HashSet <int>();
            foreach (var nxt in E[now])
            {
                hs.Add(gr0[nxt]);
            }
            int g = 0;
            while (hs.Contains(g))
            {
                g++;
            }
            if (i > 0)
            {
                gr0[now] = g;
                continue;
            }
            if (i == 0)
            {
                if (g == gg[0])
                {
                    Console.WriteLine("POSSIBLE");
                    return;
                }
            }
        }

        // p0 ? gg[1] ??????nxt?gg[0]??????

        int[] gr1 = new int[N];
        for (int i = 0; i < N; i++)
        {
            gr1[i] = gr[i];
        }
        gr1[p0]      = gg[1];
        gr1[loop[1]] = gg[0];
        for (int i = loop.Count - 1; i >= 1; i--)
        {
            int now = loop[i];
            var hs  = new HashSet <int>();
            foreach (var nxt in E[now])
            {
                hs.Add(gr1[nxt]);
            }
            int g = 0;
            while (hs.Contains(g))
            {
                g++;
            }
            if (i > 1)
            {
                gr1[now] = g;
                continue;
            }
            if (i == 1)
            {
                if (g == gg[0])
                {
                    Console.WriteLine("POSSIBLE");
                    return;
                }
            }
        }

        Console.WriteLine("IMPOSSIBLE");
    }
 private bool FindInDAG(Graph<SCC<string>> DAG, SCC<string> toFind, SCC<string> start)
 {
     if (toFind == start) {
     return true;
       }
       foreach (var n in DAG.Successors(start)) {
     if (FindInDAG(DAG, toFind, n)) {
       return true;
     }
       }
       return false;
 }
        private void ConstructStagesDAG()
        {
            if (CommandLineOptions.Clo.Trace)
              {
            Console.WriteLine("Candidate dependence analysis: Computing SCCs");
              }

              Adjacency<string> next = new Adjacency<string>(CandidateDependences.Successors);
              Adjacency<string> prev = new Adjacency<string>(CandidateDependences.Predecessors);
              SCCs = new StronglyConnectedComponents<string>(
            CandidateDependences.Nodes, next, prev);
              SCCs.Compute();

              if (CommandLineOptions.Clo.Trace)
              {
            Console.WriteLine("Candidate dependence analysis: Building stages DAG");
              }

              Dictionary<string, SCC<string>> rep = new Dictionary<string, SCC<string>>();
              foreach (var scc in SCCs)
              {
            foreach (var s in scc)
            {
              rep[s] = scc;
            }
              }

              StagesDAG = new Graph<SCC<string>>();

              foreach (var edge in CandidateDependences.Edges)
              {
            if (rep[edge.Item1] != rep[edge.Item2])
            {
              StagesDAG.AddEdge(rep[edge.Item1], rep[edge.Item2]);
            }
              }

              SCC<string> dummy = new SCC<string>();
              foreach (var scc in SCCs)
              {
            StagesDAG.AddEdge(scc, dummy);
              }
        }
 private static void DumpSCC(SCC<string> component)
 {
     var sortedComponent = component.ToList();
       sortedComponent.Sort();
       Console.Write("{ ");
       bool first = true;
       foreach (var s in sortedComponent) {
     if (first) {
       first = false;
     }
     else {
       Console.Write(", ");
     }
     Console.Write(s);
       }
       Console.Write(" }");
 }
        public bool MayReach(Block src, Block dst)
        {
            if (ReachabilityGraphSCCsDAG == null) {
            if (CommandLineOptions.Clo.Trace) {
              Console.WriteLine("Interprocedural reachability: computing SCCs");
            }
            Adjacency<Block> next = new Adjacency<Block>(reachabilityGraph.Successors);
            Adjacency<Block> prev = new Adjacency<Block>(reachabilityGraph.Predecessors);
            StronglyConnectedComponents<Block> ReachabilitySCCs = new StronglyConnectedComponents<Block>(
              reachabilityGraph.Nodes, next, prev);
            ReachabilitySCCs.Compute();

            BlockToSCC = new Dictionary<Block, SCC<Block>>();
            foreach (var scc in ReachabilitySCCs) {
              foreach (var s in scc) {
            BlockToSCC[s] = scc;
              }
            }

            ReachabilityGraphSCCsDAG = new Graph<SCC<Block>>();
            foreach (var edge in reachabilityGraph.Edges) {
              if (BlockToSCC[edge.Item1] != BlockToSCC[edge.Item2]) {
            ReachabilityGraphSCCsDAG.AddEdge(BlockToSCC[edge.Item1], BlockToSCC[edge.Item2]);
              }
            }

            SCC<Block> dummy = new SCC<Block>();
            foreach (var n in reachabilityGraph.Nodes) {
              ReachabilityGraphSCCsDAG.AddEdge(BlockToSCC[n], dummy);
            }

            if (CommandLineOptions.Clo.Trace) {
              Console.WriteLine("Interprocedural reachability: SCCs computed!");
            }
              }
              return ReachableFrom(BlockToSCC[src]).Contains(dst);
        }
 private HashSet<Block> ReachableFrom(SCC<Block> scc)
 {
     if (!MayReachCache.ContainsKey(scc)) {
     HashSet<Block> result = new HashSet<Block>();
     if (scc.Count() > 0) {
       result.UnionWith(scc);
       foreach (var nextSCC in ReachabilityGraphSCCsDAG.Successors(scc)) {
     result.UnionWith(ReachableFrom(nextSCC));
       }
     }
     MayReachCache[scc] = result;
       }
       return MayReachCache[scc];
 }