Skip to content

Commit cc6d66f

Browse files
authored
Handle preExp and varDecls for crefs with subs. (#923)
* 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.
1 parent 85508bb commit cc6d66f

File tree

5 files changed

+220
-145
lines changed

5 files changed

+220
-145
lines changed

OMCompiler/Compiler/Template/CodegenC.tpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,7 +5501,7 @@ case SES_SIMPLE_ASSIGN_CONSTRAINTS(__) then
55015501
<<
55025502
<%modelicaLine(eqInfo(eq))%>
55035503
<%preExp%>
5504-
<%contextCref(cref, context, auxFunction)%> = <%expPart%>;
5504+
<%contextCref(cref, context, &preExp, &varDecls, auxFunction)%> = <%expPart%>;
55055505
<%postExp%>
55065506
<%endModelicaLine()%>
55075507
>>
@@ -5634,7 +5634,7 @@ case e as SES_LINEAR(lSystem=ls as LINEARSYSTEM(__), alternativeTearing = at) th
56345634
<%returnval2%>
56355635
}
56365636
/* write solution */
5637-
<%ls.vars |> SIMVAR(__) hasindex i0 => '<%contextCref(name, context, auxFunctions)%> = aux_x[<%i0%>];' ;separator="\n"%>
5637+
<%ls.vars |> SIMVAR(__) hasindex i0 => '<%contextCrefNoPrevExp(name, context, auxFunctions)%> = aux_x[<%i0%>];' ;separator="\n"%>
56385638
<% if profileSome() then 'SIM_PROF_ACC_EQ(modelInfoGetEquation(&data->modelData->modelDataXml,<%ls.index%>).profileBlockIndex);' %>
56395639

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

0 commit comments

Comments
 (0)