for (item <- subItems)
item match {
- case Left(space) => dependencies ++= IterationSpace.flattenPostorder(space)
+ case Left(space) => dependencies ++= space.getDependencies
case Right(tree) => dependencies ++= tree.getDependencies
}
spaces.toSet
}
-
def addIterationSpace(indices: List[Index], space: IterationSpace) {
indices match {
case Nil => subItems += Left(space)
}
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
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 {