<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">Hi All,</span><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">This is my example function to explaining my problem:</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><div>void BM_MatrixMultiplication_var(int NVar)</div><div> {</div><div> for(int i=0; i < NConst1; i++) //MatrixARow</div>
<div> {</div><div> for(int j=0; j < NVar; j++) //MatrixBColumn<br></div><div> {</div><div> fResultMatrix[i][j] = 0.0;</div><div> for(int k = 0; k < NVar; k++) //MatrixAColumn</div>
<div> {</div><div> fResultMatrix[i][j] += fMatrixA[i][k] * fMatrixB[k][j];</div><div> }</div><div> }<br></div><div> }<br>
</div><div> }</div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">This is my function what i want to change with clang.</div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px">This is my goal:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">void BM_MatrixMultiplication_var(int NVar)</div>
<div style="font-family:arial,sans-serif;font-size:13px"> {</div><div style="font-family:arial,sans-serif;font-size:13px"> LIKWID_MARKER_START(for-loop-1-BM_MatrixMultiplication_var);</div><div style="font-family:arial,sans-serif;font-size:13px">
for(int i=0; i < NConst1; i++) //MatrixARow</div><div style="font-family:arial,sans-serif;font-size:13px"> {</div><div style="font-family:arial,sans-serif;font-size:13px"> for(int j=0; j < NVar; j++) //MatrixBColumn<br>
</div><div style="font-family:arial,sans-serif;font-size:13px"> {</div><div style="font-family:arial,sans-serif;font-size:13px"> fResultMatrix[i][j] = 0.0;</div><div style="font-family:arial,sans-serif;font-size:13px">
for(int k = 0; k < NVar; k++) //MatrixAColumn<br></div><div style="font-family:arial,sans-serif;font-size:13px"> {</div><div style="font-family:arial,sans-serif;font-size:13px">
fResultMatrix[i][j] += fMatrixA[i][k] * fMatrixB[k][j];</div><div style="font-family:arial,sans-serif;font-size:13px"> }</div><div style="font-family:arial,sans-serif;font-size:13px">
}<br></div><div style="font-family:arial,sans-serif;font-size:13px"> }<br></div><div style="font-family:arial,sans-serif;font-size:13px"> }</div><div style="font-family:arial,sans-serif;font-size:13px">
LIKWID_MARKER_STOP(for-loop-1-BM_MatrixMultiplication_var);</div><div style="font-family:arial,sans-serif;font-size:13px"> </div><div style="font-family:arial,sans-serif;font-size:13px">I tried to work with AST Matcher.</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">And I get already:</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">
<div>void BM_MatrixMultiplication_var(int NVar)</div><div> {</div><div> for(int i=0; i < NConst1; i++) //MatrixARow</div><div> {</div><div> LIKWID_MARKER_START();</div>
<div> for(int j=0; j < NVar; j++) //MatrixBColumn</div><div> {</div><div> fResultMatrix[i][j] = 0.0;</div><div> LIKWID_MARKER_START();</div>
<div> for(int k = 0; k < NVar; k++) //MatrixAColumn</div><div> {</div><div> fResultMatrix[i][j] += fMatrixA[i][k] * fMatrixB[k][j];</div><div>
}</div><div> LIKWID_MARKER_STOP();</div><div> }</div><div> LIKWID_MARKER_STOP();</div><div> }</div><div> }</div></div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">With the following statement: StatementMatcher ForLoop = forStmt(hasAncestor(forStmt())).bind( "forStmt" );</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px"><div style="font-family:arial;font-size:small"><font face="arial, sans-serif">// Finding nested Loop</font></div>
<div style="font-family:arial;font-size:small"><font face="arial, sans-serif">//for (int i= 0; i < expr(); ++i) hasAncestor(forStmt())</font></div><div style="font-family:arial;font-size:small"><font face="arial, sans-serif">//{ </font></div>
<div style="font-family:arial;font-size:small"><font face="arial, sans-serif">// for (int i= 0; i < expr(); ++i) forStmt()</font></div><div style="font-family:arial;font-size:small"><font face="arial, sans-serif">// { </font></div>
<div style="font-family:arial;font-size:small"><font face="arial, sans-serif">// Berechnung</font></div><div style="font-family:arial;font-size:small"><font face="arial, sans-serif">// }</font></div><div style="font-family:arial;font-size:small">
<font face="arial, sans-serif">//}</font></div><div style="font-family:arial;font-size:small"><font face="arial, sans-serif">//</font></div><div><font face="arial, sans-serif"><br></font></div><div><div>It is not perfect. What i have to do? </div>
<div><br></div><div>Can you tell me?</div></div><div><br></div><div><br></div></div><div style="font-family:arial,sans-serif;font-size:13px">I tried different statements and got different errors. what i am doing wrong?</div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style><div style><span style="font-family:arial,sans-serif">//StatementMatcher ForLoop = compoundStmt( hasParent( forStmt( hasAncestor( forStmt( ))))).bind( "forStmt" );</span><br>
</div><div style><font face="arial, sans-serif">//</font></div><div style><font face="arial, sans-serif">//for (int i= 0; i < expr(); ++i) hasAncestor(forStmt())</font></div><div style><font face="arial, sans-serif">//{ </font></div>
<div style><font face="arial, sans-serif">// for (int i= 0; i < expr(); ++i) hasParent(forStmt()) </font></div><div style><font face="arial, sans-serif">// { compoundStmt() </font></div><div style><font face="arial, sans-serif">// Berechnung</font></div>
<div style><font face="arial, sans-serif">// } compoundStmt()</font></div><div style><font face="arial, sans-serif">//}</font></div><div style><font face="arial, sans-serif">//</font></div><div style><font face="arial, sans-serif">//{ hasParent(compoundStmt())</font></div>
<div style><font face="arial, sans-serif">//<span class="" style="white-space:pre"> </span>for (int i= 0; i < expr(); ++i) hasAncestor(forStmt())</font></div><div style><font face="arial, sans-serif">//<span class="" style="white-space:pre"> </span>{<span class="" style="white-space:pre"> </span> </font></div>
<div style><font face="arial, sans-serif">// <span class="" style="white-space:pre"> </span>for (int i= 0; i < expr(); ++i) forStmt() </font></div><div style><font face="arial, sans-serif">// <span class="" style="white-space:pre"> </span>{ </font></div>
<div style><font face="arial, sans-serif">// <span class="" style="white-space:pre"> </span>Berechnung</font></div><div style><font face="arial, sans-serif">// <span class="" style="white-space:pre"> </span>} </font></div>
<div style><font face="arial, sans-serif">//<span class="" style="white-space:pre"> </span>}</font></div><div style><font face="arial, sans-serif">//} compoundStmt()</font></div><div style><font face="arial, sans-serif">//</font></div>
<div style><font face="arial, sans-serif">//StatementMatcher ForLoop = forStmt(hasAncestor(forStmt(hasParent(compoundStmt()).bind("outerForStmt"));</font></div><div style><font face="arial, sans-serif">//StatementMatcher ForLoop = forStmt().bind("forStmt");</font></div>
<div style><font face="arial, sans-serif">//</font></div><div style><font face="arial, sans-serif">//<span class="" style="white-space:pre"> </span>for (int i= 0; i < expr(); ++i) forStmt()</font></div><div style><font face="arial, sans-serif">//<span class="" style="white-space:pre"> </span>{</font></div>
<div style><font face="arial, sans-serif">// <span class="" style="white-space:pre"> </span>Berechnung<span class="" style="white-space:pre"> </span> </font></div><div style><font face="arial, sans-serif">//<span class="" style="white-space:pre"> </span>}</font></div>
<div style><font face="arial, sans-serif">//</font></div><div style><font face="arial, sans-serif"><br></font></div><div style><font face="arial, sans-serif"><br></font></div><div style><font face="arial, sans-serif">//for (int i= 0; i < expr(); ++i) { ... }</font></div>
<div style><font face="arial, sans-serif">StatementMatcher LoopMatcher =</font></div><div style><font face="arial, sans-serif"> forStmt( // for ([init]; [condition]; [increment])</font></div><div style><font face="arial, sans-serif"> hasLoopInit(</font></div>
<div style><font face="arial, sans-serif"> declStmt(</font></div><div style><font face="arial, sans-serif"> hasSingleDecl(varDecl(hasInitializer(integerLiteral(equals(0)))) // Die Initialisierung hat eine einzige Variable und ist mit dem Ganzzahlliteral 0 initialisiert</font></div>
<div style><font face="arial, sans-serif"> .bind("initVarName")))),</font></div><div style><font face="arial, sans-serif"> hasIncrement( // "increment" part of for-loop</font></div>
<div style><font face="arial, sans-serif"> unaryOperator( // any unary op, e.g. *, &, --</font></div><div style><font face="arial, sans-serif"> hasOperatorName("++"), // exact unary op: ++</font></div>
<div style><font face="arial, sans-serif"> hasUnaryOperand(declRefExpr(to(varDecl(hasType(isInteger())).bind("incVarName"))))</font></div><div style><font face="arial, sans-serif"> )</font></div>
<div style><font face="arial, sans-serif"> ),</font></div><div style><font face="arial, sans-serif"> hasCondition(binaryOperator(</font></div><div style><font face="arial, sans-serif"> hasOperatorName("<"),</font></div>
<div style><font face="arial, sans-serif"> hasLHS(ignoringParenImpCasts(declRefExpr(to(varDecl(hasType(isInteger())).bind("condVarName"))))),</font></div><div style><font face="arial, sans-serif"> hasRHS(expr(hasType(isInteger()))))</font></div>
<div style><font face="arial, sans-serif"> )</font></div><div style><font face="arial, sans-serif"> ).bind("forLoop");</font></div><div style="font-family:arial,sans-serif;font-size:13px">
<br></div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thank Your for Your reply</div><div style="font-family:arial,sans-serif;font-size:13px">
Anja<br></div></div>