Skip to content

Commit

Permalink
Handle preExp and varDecls for crefs with subs. (#923)
Browse files Browse the repository at this point in the history
* Handle preExp and varDecls for crefs with subs.

  - We used to throw away any extra expressions and variable declarations
    needed for it, i.e., if it has some complicated subscript that can not
    be generated inline.

  - If you are sure you have a path (a cref with no subs) then you can use
    contextCrefNoPrevExp (e.g variable names are just paths. They are just
    represented as cref). Otherwise contextCref now needs a preEx and varDecls
    buffer passed to it.

* Fix wrong ordering of buffer arguments.

* Avoid unnecessary code generation.

  - This fixes ticket:5994.

  - The path we took for crefs with subscripts in function context
    used to create unnecessary temporaries and exps which we did
    not notice because they were were thrown away after being created.

  - Split up the function to take different paths for normal and parallel
    functions.

* Add a test case for Ticket:5994.
  • Loading branch information
mahge committed Jun 3, 2020
1 parent 85508bb commit cc6d66f
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 145 deletions.
10 changes: 5 additions & 5 deletions OMCompiler/Compiler/Template/CodegenC.tpl
Expand Up @@ -5501,7 +5501,7 @@ case SES_SIMPLE_ASSIGN_CONSTRAINTS(__) then
<<
<%modelicaLine(eqInfo(eq))%>
<%preExp%>
<%contextCref(cref, context, auxFunction)%> = <%expPart%>;
<%contextCref(cref, context, &preExp, &varDecls, auxFunction)%> = <%expPart%>;
<%postExp%>
<%endModelicaLine()%>
>>
Expand Down Expand Up @@ -5634,7 +5634,7 @@ case e as SES_LINEAR(lSystem=ls as LINEARSYSTEM(__), alternativeTearing = at) th
<%returnval2%>
}
/* write solution */
<%ls.vars |> SIMVAR(__) hasindex i0 => '<%contextCref(name, context, auxFunctions)%> = aux_x[<%i0%>];' ;separator="\n"%>
<%ls.vars |> SIMVAR(__) hasindex i0 => '<%contextCrefNoPrevExp(name, context, auxFunctions)%> = aux_x[<%i0%>];' ;separator="\n"%>
<% if profileSome() then 'SIM_PROF_ACC_EQ(modelInfoGetEquation(&data->modelData->modelDataXml,<%ls.index%>).profileBlockIndex);' %>

<%returnval%>
Expand All @@ -5660,12 +5660,12 @@ case e as SES_LINEAR(lSystem=ls as LINEARSYSTEM(__), alternativeTearing = SOME(a
<% if profileSome() then 'SIM_PROF_TICK_EQ(modelInfoGetEquation(&data->modelData->modelDataXml,<%at.index%>).profileBlockIndex);' %>
if (data->simulationInfo->linearSystemData[<%at.indexLinearSystem%>].checkConstraints(data, threadData) == 1)
{
double aux_x[<%listLength(at.vars)%>] = { <%at.vars |> SIMVAR(__) hasindex i0 => '<%contextCref(name, context, auxFunctions)%>' ;separator=","%> };
double aux_x[<%listLength(at.vars)%>] = { <%at.vars |> SIMVAR(__) hasindex i0 => '<%contextCrefNoPrevExp(name, context, auxFunctions)%>' ;separator=","%> };
retValue = solve_linear_system(data, threadData, <%at.indexLinearSystem%>, &aux_x[0]);
/* The casual tearing set found a solution */
if (retValue == 0){
/* write solution */
<%at.vars |> SIMVAR(__) hasindex i0 => '<%contextCref(name, context, auxFunctions)%> = aux_x[<%i0%>];' ;separator="\n"%>
<%at.vars |> SIMVAR(__) hasindex i0 => '<%contextCrefNoPrevExp(name, context, auxFunctions)%> = aux_x[<%i0%>];' ;separator="\n"%>
<% if profileSome() then 'SIM_PROF_ACC_EQ(modelInfoGetEquation(&data->modelData->modelDataXml,<%at.index%>).profileBlockIndex);' %>
}
}
Expand Down Expand Up @@ -5970,7 +5970,7 @@ match ty
// case T_ARRAY(__) then
// copyArrayData(var.ty, '<%tmp%>._<%var.name%>', appendStringCref(var.name,left), context, &preExp, &varDecls, &auxFunction)
// else
// let varPart = contextCref(appendStringCref(var.name,left),context, &auxFunction)
// let varPart = contextCref(appendStringCref(var.name,left), context, &preExp, &varDecls, &auxFunction)
// '<%varPart%> = <%tmp%>._<%var.name%>;'
// ; separator="\n"
// %>
Expand Down

0 comments on commit cc6d66f

Please sign in to comment.