]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Construct sorted and fused loop hierarchy.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 3 Feb 2012 17:47:53 +0000 (17:47 +0000)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Fri, 3 Feb 2012 17:47:53 +0000 (17:47 +0000)
src/ofc/generators/onetep/LoopTree.scala
src/ofc/generators/onetep/Tree.scala

index 8ef209462b91e91f56e497dd7f9f8b3883389930..a7eee751bba416b6b1e785d171a8d8d553b118a6 100644 (file)
@@ -148,7 +148,7 @@ class LoopTree private[onetep](localIndex: Option[Index]) {
 
     for (item <- subItems)
       item match {
-        case Left(space) => dependencies ++= IterationSpace.flattenPostorder(space)
+        case Left(space) => dependencies ++= space.getDependencies
         case Right(tree) => dependencies ++= tree.getDependencies
       }
 
@@ -167,7 +167,6 @@ class LoopTree private[onetep](localIndex: Option[Index]) {
     spaces.toSet
   }
 
-
   def addIterationSpace(indices: List[Index], space: IterationSpace) {
     indices match {
       case Nil => subItems += Left(space)
@@ -207,7 +206,15 @@ class LoopTree private[onetep](localIndex: Option[Index]) {
   }
 
   def sort() {
-    //TODO: Implement me!
+    def compareItems(before: Either[IterationSpace, LoopTree], after: Either[IterationSpace, LoopTree]) : Boolean =
+      (before, after) match {
+        case (Left(space1), Left(space2)) => space2.getDependencies.contains(space1)
+        case (Right(tree1), Right(tree2)) => (tree2.getDependencies & tree1.getSpaces).nonEmpty
+        case (Left(space),  Right(tree))  => tree.getDependencies.contains(space)
+        case (Right(tree),  Left(space))  => (space.getDependencies & tree.getSpaces).nonEmpty 
+      }
+
+    subItems = subItems.sortWith(compareItems(_, _))
   }
 
   def getLocalIndex = localIndex
index 0b7d3abf13fdf0515d5d0a940d6dc449d4663a10..218fc6688f3faf0c2159f9cff8ce66e5c97a8de7 100644 (file)
@@ -54,6 +54,10 @@ trait IterationSpace {
   def getExternalIndices : Set[Index]
   def getInternalIndices : Set[Index] = (getSpatialIndices ++ getDiscreteIndices).toSet
   def getIndices : Set[Index] = getInternalIndices ++ getExternalIndices
+  def getDependencies : Set[IterationSpace] = {
+    val operands = getOperands
+    operands.toSet ++ operands.flatMap(_.getDependencies)
+  }
 }
 
 trait DataSpace extends IterationSpace {