<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hi Justin,<br>
<br>
<span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">I think basically you have to walk the parse tree with a mutator class. The mutator class needs to have Pre and Post functions
 defined. The Pre/Post functions can be specialised for the nodes that you are interested in. And these functions get called while visiting those nodes. You can perform the transformations in these Pre/Post functions.</span><br>
<br>
-> OpenMP loop rewriting might be a good example to consult. <br>
<a href="https://github.com/llvm/llvm-project/blob/master/flang/lib/Semantics/canonicalize-omp.cpp" style="margin: 0px; font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255)" id="LPlnk187547">https://github.com/llvm/llvm-project/blob/master/flang/lib/Semantics/canonicalize-omp.cpp</a><br>
<br>
In the parse-tree representation (include/flang/Parser/parse-tree.h), the OpenMPLoopConstruct is a tuple of <span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">OmpBeginLoopDirective,
 DoConstruct and <span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">OmpEndLoopDirective. The DoConstruct and <span style="font-family: Calibri, Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255); display: inline !important">OmpEndLoopDirective
 fields are not filled during parsing. The pass in the above file fills these fields. The pass does the following rewriting transformation (copied from the source file).</span></span></span><br>
<br>
<span>// Original:<br>
</span>
<div>//   ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct<br>
</div>
<div>//     OmpBeginLoopDirective<br>
</div>
<div>//   ExecutableConstruct -> DoConstruct<br>
</div>
<div>//   ExecutableConstruct -> OmpEndLoopDirective (if available)<br>
</div>
<div><br>
</div>
<div>// After rewriting:<br>
</div>
<div>//   ExecutableConstruct -> OpenMPConstruct -> OpenMPLoopConstruct<br>
</div>
<div>//     OmpBeginLoopDirective<br>
</div>
<div>//     DoConstruct<br>
</div>
<span>//     OmpEndLoopDirective (if available)</span><br>
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
-> Another example would be lib/Semantics/rewrite-parse-tree.cpp. The pass here corrects some ambiguous parsing performed by the Flang parser.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
Thanks,<br>
Kiran</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> flang-dev <flang-dev-bounces@lists.llvm.org> on behalf of Steve Scalpone via flang-dev <flang-dev@lists.llvm.org><br>
<b>Sent:</b> 25 June 2020 17:01<br>
<b>To:</b> Szaday, Justin Josef <szaday2@illinois.edu>; Andrzej Warzynski <Andrzej.Warzynski@arm.com>; flang-dev@lists.llvm.org <flang-dev@lists.llvm.org><br>
<b>Subject:</b> Re: [flang-dev] Difficulties with In-Tree Build of Flang</font>
<div> </div>
</div>
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Verdana}
p.x_MsoNormal, li.x_MsoNormal, div.x_MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif}
a:link, span.x_MsoHyperlink
        {color:blue;
        text-decoration:underline}
span.x_EmailStyle18
        {font-family:"Calibri",sans-serif;
        color:windowtext}
.x_MsoChpDefault
        {font-size:10.0pt}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.x_WordSection1
        {}
-->
</style>
<div lang="EN-US" link="blue" vlink="purple">
<div class="x_WordSection1">
<p class="x_MsoNormal">Hi Justin,</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">You can use the flang front end (f18) to do source-to-source transformations.  Check out the -funparse option.  Sorry, I’m not familiar with the APIs to rewrite the AST.  Maybe someone else can answer that.</p>
<p class="x_MsoNormal"> </p>
<p class="x_MsoNormal">- Steve</p>
<p class="x_MsoNormal"> </p>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal" style="margin-left:.5in"><b><span style="font-size:12.0pt; color:black">From:
</span></b><span style="font-size:12.0pt; color:black">flang-dev <flang-dev-bounces@lists.llvm.org> on behalf of flang-dev <flang-dev@lists.llvm.org><br>
<b>Reply-To: </b>"Szaday, Justin Josef" <szaday2@illinois.edu><br>
<b>Date: </b>Thursday, June 25, 2020 at 8:45 AM<br>
<b>To: </b>Andrzej Warzynski <andrzej.warzynski@arm.com>, flang-dev <flang-dev@lists.llvm.org><br>
<b>Subject: </b>Re: [flang-dev] Difficulties with In-Tree Build of Flang</span></p>
</div>
<div>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
</div>
<table class="x_MsoNormalTable" border="1" cellpadding="0" style="margin-left:.5in; background:#FFEB9C">
<tbody>
<tr>
<td style="padding:.75pt .75pt .75pt .75pt">
<p class="x_MsoNormal"><b><span style="font-size:7.5pt; font-family:"Verdana",sans-serif; color:black">External email: Use caution opening links or attachments</span></b><span style="font-size:7.5pt; font-family:"Verdana",sans-serif; color:black">
</span></p>
</td>
</tr>
</tbody>
</table>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
<div>
<p class="x_MsoNormal" style="margin-left:.5in">Thanks for the replies, Andrzej and Steve,</p>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
<p class="x_MsoNormal" style="margin-left:.5in">This placeholder driver may be sufficient for my purposes for now. My goal is to use Flang to implement some high-level transformations for the Adaptive MPI project, those being converting: global variables into
 !omp threadprivate() variables, and LUNs with hardcoded values into virtualized ones. Does Flang provide a mechanism for manipulating the AST directly? If not, are there any code rewriting mechanisms (a la Clang) or should these manipulations be performed
 at the FIR-level? Any guidance on this matter would be appreciated, I scanned through the documentation and did not immediately see any discussion of code manipulation.</p>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
<p class="x_MsoNormal" style="margin-left:.5in">Thanks,</p>
<p class="x_MsoNormal" style="margin-left:.5in">Justin Szaday<br>
PhD Student in Computer Science<br>
University of Illinois at Urbana-Champaign</p>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
<div style="border:none; border-top:solid #E1E1E1 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="x_MsoNormal" style="margin-left:.5in"><b>From: </b><a href="mailto:flang-dev@lists.llvm.org">Andrzej Warzynski via flang-dev</a><br>
<b>Sent: </b>Thursday, June 25, 2020 7:45 AM<br>
<b>To: </b><a href="mailto:flang-dev@lists.llvm.org">flang-dev@lists.llvm.org</a><br>
<b>Subject: </b>Re: [flang-dev] Difficulties with In-Tree Build of Flang</p>
</div>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
<p class="x_MsoNormal" style="margin-left:.5in">Hello Justin,<br>
<br>
The new driver will take a while to implement. Internally we are aiming <br>
for LLVM 12, but that depends on many factors. First we'd like to <br>
refactor some bits of Clang's driver so that it is easy to re-use them <br>
in Flang.<br>
<br>
- Andrzej<br>
<br>
<br>
On 24/06/2020 22:50, Steve Scalpone via flang-dev wrote:<br>
> Hi Justin,<br>
> <br>
> The flang script reads from standard input if a source file is not <br>
> provided on the command line.  It appears to hang, but it’s really just <br>
> waiting for input.<br>
> <br>
> Flang isn’t hooked up to a code generator yet, so instead, by default, <br>
> flang generates another Fortran source file and tries to compile that <br>
> file with a different compiler.  The default is pgf90, but you can set <br>
> the environment variable F18_FC to be a different compiler, like gfortran.<br>
> <br>
> The flang script that you are running is just a throwaway driver until <br>
> the real driver is ready.  That work is under development right now, but <br>
> I don’t know when it will be ready.  Until then, we have this quirky <br>
> script that lets us test flang semantics.<br>
> <br>
> - Steve<br>
> <br>
> *From: *flang-dev <flang-dev-bounces@lists.llvm.org> on behalf of <br>
> flang-dev <flang-dev@lists.llvm.org><br>
> *Reply-To: *"Szaday, Justin Josef" <szaday2@illinois.edu><br>
> *Date: *Wednesday, June 24, 2020 at 2:02 PM<br>
> *To: *flang-dev <flang-dev@lists.llvm.org><br>
> *Subject: *[flang-dev] Difficulties with In-Tree Build of Flang<br>
> <br>
> *External email: Use caution opening links or attachments*<br>
> <br>
> Hello all,<br>
> <br>
> I am having a very difficult time getting in-tree builds of Flang <br>
> working. My build commands are as follows:<br>
> <br>
> cmake -G Ninja -DLLVM_ENABLE_PROJECTS="flang" <br>
> -DCMAKE_INSTALL_PREFIX=$(pwd) -DCMAKE_BUILD_TYPE=MinSizeRel ../llvm<br>
> <br>
> cmake --build . --target check-flang<br>
> <br>
> cmake --build . --target install<br>
> <br>
> The build itself completes successfully, and all the Flang tests pass <br>
> when using “check-flang”; however, “flang -v” and “flang -h” hang (it <br>
> does not produce any output and has to be killed) and, when trying to <br>
> compile a program, I get the error message “execvp(pgf90) failed: No <br>
> such file or directory” (which fails even if I set F18_FC to gfortran or <br>
> flang). I have tried building it on a few machines to no avail. I have <br>
> tested both the Debug and MinSizeRel build types, used both Ninja and <br>
> Unix Makefiles to build it, and tested a few different versions of <br>
> GCC/G++, ultimately settling on v9.1.0. I am building from master of the <br>
> llvm-project GitHub repository.<br>
> <br>
> Any insights here would be appreciated, I am at a loss about what else <br>
> to try here. Any other debugging suggestions or usage tips would be <br>
> appreciated as well.<br>
> <br>
> Thanks,<br>
> <br>
> Justin<br>
> <br>
> <br>
> _______________________________________________<br>
> flang-dev mailing list<br>
> flang-dev@lists.llvm.org<br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev</a><br>
> <br>
_______________________________________________<br>
flang-dev mailing list<br>
flang-dev@lists.llvm.org<br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev">https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev</a></p>
<p class="x_MsoNormal" style="margin-left:.5in"> </p>
</div>
</div>
</div>
</body>
</html>