Exemplo n.º 1
0
 /// <summary>
 /// Get the index of the statement that prevents loop merging, or -1 if none
 /// </summary>
 /// <param name="stmts"></param>
 /// <param name="stmtIndex"></param>
 /// <param name="loopVar"></param>
 /// <param name="isForwardLoop"></param>
 /// <returns></returns>
 public int GetConflictingStmt(Set <int> stmts, int stmtIndex, IVariableDeclaration loopVar, bool isForwardLoop)
 {
     foreach (EdgeIndex edge in graph.EdgesInto(stmtIndex))
     {
         int source = graph.SourceOf(edge);
         if (stmts.Contains(source) && IsProhibited(edge, loopVar, isForwardLoop, true))
         {
             return(source);
         }
     }
     foreach (EdgeIndex edge in graph.EdgesOutOf(stmtIndex))
     {
         int target = graph.TargetOf(edge);
         if (stmts.Contains(target) && IsProhibited(edge, loopVar, isForwardLoop, false))
         {
             return(target);
         }
     }
     return(-1);
 }
Exemplo n.º 2
0
        public void IndexedGraphTest()
        {
            IndexedGraph g   = new IndexedGraph();
            int          a   = g.AddNode();
            int          b   = g.AddNode();
            int          c   = g.AddNode();
            int          ab  = g.AddEdge(a, b);
            int          bb  = g.AddEdge(b, b); // self loop
            int          bc  = g.AddEdge(b, c);
            int          bc2 = g.AddEdge(b, c); // double edge

            Assert.Equal(c, g.TargetOf(bc));
            Assert.Equal(bb, g.GetEdge(b, b));
            Assert.Equal(0, g.EdgeCount(a, c));
            Assert.Equal(2, g.EdgeCount(b, c));
            Assert.Equal(4, g.EdgeCount());
            Assert.Equal(1, g.NeighborCount(a));
            Assert.Equal(2, g.NeighborCount(c));
            Assert.Equal(1, g.TargetCount(a));
            Assert.Equal(0, g.SourceCount(a));

            Console.Write("EdgesOf(b):");
            foreach (int edge in g.EdgesOf(b))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
            Console.Write("EdgesInto(b):");
            foreach (int edge in g.EdgesInto(b))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
            Console.Write("EdgesOutOf(b):");
            foreach (int edge in g.EdgesOutOf(b))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
            Console.Write("EdgesLinking(b,c):");
            foreach (int edge in g.EdgesLinking(b, c))
            {
                Console.Write(" {0}", edge);
            }
            Console.WriteLine();
        }