aboutsummaryrefslogtreecommitdiff
path: root/Tools/CodeGen/Schedule.m
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2012-12-10 12:13:55 -0500
committerErik Schnetter <schnetter@gmail.com>2012-12-10 13:01:29 -0500
commitb05c71e2b9610cbc3b46e9dbecb6394d5308bd4b (patch)
tree2c867dbdd749fa53dfc62c56535fe11d1d48993c /Tools/CodeGen/Schedule.m
parent0cfc6c8c4aefe1e666f59d96fbeac5e0edfcff75 (diff)
Determine READS groups/variables more accurately
If a local variable is read from a grid function, but later overwritten before its value is used, don't count them as READS groups.
Diffstat (limited to 'Tools/CodeGen/Schedule.m')
-rw-r--r--Tools/CodeGen/Schedule.m30
1 files changed, 13 insertions, 17 deletions
diff --git a/Tools/CodeGen/Schedule.m b/Tools/CodeGen/Schedule.m
index 2688314..bfbb54b 100644
--- a/Tools/CodeGen/Schedule.m
+++ b/Tools/CodeGen/Schedule.m
@@ -35,24 +35,16 @@ storageStructure[groupName_, timelevels_] :=
};
groupsSetInCalc[calc_, groups_] :=
- Module[{gfs, eqs, lhss, gfsInLHS, lhsGroupNames},
- gfs = allGroupVariables[groups];
- eqs = lookup[calc, Equations];
- lhss = Map[First, eqs];
- gfsInLHS = Union[Cases[lhss, _ ? (MemberQ[gfs,#] &), Infinity]];
+ Module[{gfsInLHS, lhsGroupNames},
+ gfsInLHS = variablesSetInCalc[calc, groups];
lhsGroupNames = containingGroups[gfsInLHS, groups];
Return[lhsGroupNames]
];
groupsReadInCalc[calc_, groups_] :=
- Module[{gfs, eqs, lhss, gfsInLHS, rhsGroupNames},
- gfs = allGroupVariables[groups];
- eqs = lookup[calc, Equations];
- rhss = Map[Last, eqs];
- gfsInRHS = Union[Cases[rhss, _ ? (MemberQ[gfs,#] &), Infinity]];
+ Module[{gfsInRHS, rhsGroupNames},
+ gfsInRHS = variablesReadInCalc[calc, groups];
rhsGroupNames = containingGroups[gfsInRHS, groups];
- (* TODO: eliminate variables from this list that have been set in
- this calculation before they were used *)
Return[rhsGroupNames]
];
@@ -66,13 +58,17 @@ variablesSetInCalc[calc_, groups_] :=
];
variablesReadInCalc[calc_, groups_] :=
- Module[{gfs, eqs, lhss, gfsInLHS},
+ Module[{eqsHaveVar, firstEqWithVar, eqHasVarInRHS,
+ gfs, eqs, gfsInEqs, gfsInRHS},
+ (* Look for the first equation in which the variable occurs in the
+ calculation. If it is a RHS, then the variable is read. *)
+ eqsHaveVar[eqs_, gf_] := MemberQ[eqs, gf, Infinity];
+ firstEqWithVar[eqs_, gf_] := First[Select[eqs, MemberQ[#, gf, Infinity]&]];
+ eqHasVarInRHS[eq_, gf_] := MemberQ[{Last[eq]}, gf, Infinity];
gfs = allGroupVariables[groups];
eqs = lookup[calc, Equations];
- rhss = Map[Last, eqs];
- gfsInRHS = Union[Cases[rhss, _ ? (MemberQ[gfs,#] &), Infinity]];
- (* TODO: eliminate variables from this list that have been set in
- this calculation before they were used *)
+ gfsInEqs = Select[gfs, eqsHaveVar[eqs, #]&];
+ gfsInRHS = Select[gfsInEqs, eqHasVarInRHS[firstEqWithVar[eqs, #], #]&];
Return[gfsInRHS]
];