Skip to content

Commit

Permalink
Improve clock propagation in synchronous models
Browse files Browse the repository at this point in the history
  • Loading branch information
rfranke committed Feb 21, 2016
1 parent c37fa36 commit 2c5439f
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 37 deletions.
40 changes: 27 additions & 13 deletions Compiler/BackEnd/BackendDump.mo
Expand Up @@ -295,25 +295,39 @@ end printBasePartitions;
public function printSubPartitions
input array<BackendDAE.SubPartition> subPartitions;
protected
String factorStr, shiftStr, solverStr, eventStr;
BackendDAE.SubClock clk;
String subClockStr, eventStr;
algorithm
for i in 1:arrayLength(subPartitions) loop
clk := subPartitions[i].clock;
factorStr := "factor(" + MMath.rationalString(clk.factor) + ")";
shiftStr := "shift(" + MMath.rationalString(clk.shift) + ")";
solverStr := match clk.solver
local
String s;
case NONE() then "";
case SOME(s) then "solver(" + s + ")";
end match;
subClockStr := subClockString(subPartitions[i].clock);
eventStr := "event(" + boolString(subPartitions[i].holdEvents) + ")";
print( intString(i) + ": " + factorStr + " " + shiftStr + " " +
solverStr + " " + eventStr + "\n");
print(intString(i) + ": " + subClockStr + " " + eventStr + "\n");
end for;
end printSubPartitions;

public function subClockString
input BackendDAE.SubClock subClock;
output String subClockString;
protected
String factorStr, shiftStr, solverStr;
algorithm
factorStr := "factor(" + MMath.rationalString(subClock.factor) + ")";
shiftStr := "shift(" + MMath.rationalString(subClock.shift) + ")";
solverStr := "solver(" + optionString(subClock.solver) + ")";
subClockString := factorStr + " " + shiftStr + " " + solverStr;
end subClockString;

public function optionString
input Option<String> option;
output String optionString;
algorithm
optionString := match option
local
String s;
case SOME(s) then s;
else "";
end match;
end optionString;

public function printBackendDAEType "This is a helper for printShared."
input BackendDAE.BackendDAEType btp;
algorithm
Expand Down
61 changes: 39 additions & 22 deletions Compiler/BackEnd/SynchronousFeatures.mo
Expand Up @@ -455,7 +455,7 @@ algorithm
end makeClockedSyst;

protected function resolveClocks
"Get from clock equation system array sub-clocks[varIdx] and base clock."
"Get array of subClocks[varIdx] and common base from clock equation system."
input BackendDAE.Variables inVars;
input BackendDAE.EquationArray inEqs;
input BackendDAE.StrongComponents inComps;
Expand All @@ -465,10 +465,14 @@ protected
BackendDAE.Equation eq;
DAE.Exp exp;
DAE.ClockKind clockKind;
tuple<BackendDAE.SubClock, Integer> subClock;
BackendDAE.SubClock subClock;
BackendDAE.StrongComponent comp;
Integer eqIdx, varIdx;
Integer eqIdx, varIdx, parentIdx;
algorithm
if Flags.isSet(Flags.DUMP_SYNCHRONOUS) then
print("\n" + BackendDump.BORDER +
"\nClock propagation\n" + BackendDump.BORDER + "\n\n");
end if;
outSubClocks := arrayCreate(BackendVariable.varsSize(inVars), (BackendDAE.DEFAULT_SUBCLOCK, 0));
for comp in inComps loop
outClockKind := matchcontinue comp
Expand All @@ -481,8 +485,28 @@ algorithm
case BackendDAE.EQUATION(scalar = e) then e;
case BackendDAE.SOLVED_EQUATION(exp = e) then e;
end match;
(clockKind, subClock) := getSubClock(exp, inVars, outSubClocks);
arrayUpdate(outSubClocks, varIdx, subClock);
(clockKind, (subClock, parentIdx)) := getSubClock(exp, inVars, outSubClocks);
if parentIdx <> varIdx then
arrayUpdate(outSubClocks, varIdx, (subClock, parentIdx));
else
// can't determine clock from var itself;
// use alternative exp of unsolved equation instead
exp := match eq
local
DAE.Exp e;
case BackendDAE.EQUATION(exp = e) then e;
else exp;
end match;
(clockKind, (subClock, parentIdx)) := getSubClock(exp, inVars, outSubClocks);
arrayUpdate(outSubClocks, varIdx, (subClock, parentIdx));
end if;
if Flags.isSet(Flags.DUMP_SYNCHRONOUS) then
print("var " + intString(varIdx) + ": " +
BackendDump.equationString(eq) + " ->\n " +
ExpressionDump.printExpStr(exp) + ": " +
BackendDump.subClockString(subClock) +
" with parent " + intString(parentIdx) + ".\n");
end if;
then setClockKind(outClockKind, clockKind);
else
algorithm
Expand Down Expand Up @@ -559,7 +583,7 @@ algorithm
case DAE.CREF(cr, _)
algorithm
i1 := getVarIdx(cr, inVars);
(subClock, _) := arrayGet(inSubClocks, i1);
(subClock, _) := arrayGet(inSubClocks, i1);
then
(DAE.INFERRED_CLOCK(), (subClock, i1));

Expand All @@ -573,24 +597,25 @@ algorithm
end getSubClock;

protected function getSubClock1
"Helper for recursion in getSubClock"
input DAE.Exp inExp;
input BackendDAE.Variables inVars;
input array<tuple<BackendDAE.SubClock, Integer>> inSubClocks;
output DAE.ClockKind outClockKind;
output tuple<BackendDAE.SubClock, Integer> outSubClock;
protected
BackendDAE.SubClock subClk;
Integer parent;
BackendDAE.SubClock subClock;
Integer parentIdx;
algorithm
(outClockKind, (subClk, parent)) := getSubClock(inExp, inVars, inSubClocks);
parent := match inExp
(outClockKind, (subClock, parentIdx)) := getSubClock(inExp, inVars, inSubClocks);
parentIdx := match inExp
local
DAE.ComponentRef cr;
case DAE.CREF(cr, _)
then getVarIdx(cr, inVars);
else parent;
else parentIdx;
end match;
outSubClock := (subClk, parent);
outSubClock := (subClock, parentIdx);
end getSubClock1;

protected function setClockKind
Expand Down Expand Up @@ -757,16 +782,8 @@ algorithm
then oldSolverMethod;
else
algorithm
oldMethod := match oldSolverMethod
local String s;
case SOME(s) then s;
case NONE() then "";
end match;
newMethod := match newSolverMethod
local String s;
case SOME(s) then s;
case NONE() then "";
end match;
oldMethod := BackendDump.optionString(oldSolverMethod);
newMethod := BackendDump.optionString(newSolverMethod);
Error.addMessage(Error.SUBCLOCK_CONFLICT, {"solver", oldMethod, newMethod});
then fail();
end match;
Expand Down
4 changes: 2 additions & 2 deletions Compiler/Util/Error.mo
Expand Up @@ -828,9 +828,9 @@ public constant Message CLOCKED_DSICRETE_CONT_CONFLICT = MESSAGE(568, TRANSLATIO
public constant Message INVALID_CLOCK_EQUATION = MESSAGE(569, TRANSLATION(), ERROR(),
Util.gettext("Invalid form of clock equation"));
public constant Message SUBCLOCK_CONFLICT = MESSAGE(570, TRANSLATION(), ERROR(),
Util.gettext("Partitions have different sub-clock %ss (%s) and (%s)."));
Util.gettext("Partition has different sub-clock %ss (%s) and (%s)."));
public constant Message CLOCK_CONFLICT = MESSAGE(571, TRANSLATION(), ERROR(),
Util.gettext("Partitions have different base clocks."));
Util.gettext("Partition has different base clocks."));
public constant Message EXEC_STAT = MESSAGE(572, TRANSLATION(), NOTIFICATION(),
Util.gettext("Performance of %s: time %s/%s"));
public constant Message EXEC_STAT_GC = MESSAGE(573, TRANSLATION(), NOTIFICATION(),
Expand Down

0 comments on commit 2c5439f

Please sign in to comment.