[flang-dev] flang test questions

Kiran Chandramohan via flang-dev flang-dev at lists.llvm.org
Wed Jul 14 00:46:20 PDT 2021


Hello Damian,

If you intend to use the fir-dev branch. You may find the following instructions helpful.


1) You can build Flang on the fir-dev branch by enabling the flang project along with clang, mlir and openmp.
Note: Please change TARGETS_TO_BUILD to your platform (X86, PowerPC).

git clone https://github.com/flang-compiler/f18-llvm-project.git
cd f18-llvm-project

git checkout fir-dev

mkdir build

cd build

cmake -G Ninja ../llvm -DLLVM_ENABLE_PROJECTS="flang;clang;mlir;openmp" -DLLVM_TARGETS_TO_BUILD=AArch64 -DCMAKE_BUILD_TYPE=Release

nice -n 10 ninja


2) Currently there is no driver support for end-to-end codegen. You must use two developer tools (bbc and tco) to generate llvm IR and then use clang or gcc to link and generate the executable. Two sample example invocations are given below. A few tests are also end-to-end and you may also use those as a reference. (https://github.com/flang-compiler/f18-llvm-project/blob/fir-dev/flang/test/Lower/end-to-end-always-exec-loopbody.f90).
Note: Ryuta Suzuki created a script that might help here. (https://flang-compiler.slack.com/archives/C5C58TT32/p1625041964086400?thread_ts=1624955427.084800&cid=C5C58TT32)

input="fraction.f90"

bbc $input -o - | tco | llc --relocation-model=pic --filetype=obj -o $input.o

gcc $input.o -L/…/f18-llvm-project/install/lib -lFortran_main -lFortranRuntime -lFortranDecimal -lm -o $input.out

./bin/bbc -emit-fir array.f90 -o - | ./bin/tco &> array.ll
./bin/clang++ array.ll -lFortran_main -lFortranRuntime -lFortranDecimal

LD_LIBRARY_PATH=$HOME/f18-llvm-project/build/lib ./a.out


3) It is possible that the linking process might complain about some math symbols. If so, you must download classic flang and place the library libpgmath.so somewhere and point to it in the link step.

git clone https://github.com/flang-compiler/flang.git

cd flang/runtime/libpgmath

mkdir build

cd build

cmake ../

make

And then you can find lipgmath.* in the lib directory in build.

(There might be an option to build pgmath automatically if you set an environment variable. There might also be an option to use mlir/libm math functions instead of pgmath. But I have not explored these options.)

Thanks,
Kiran
________________________________
From: flang-dev <flang-dev-bounces at lists.llvm.org> on behalf of Andrzej Warzynski via flang-dev <flang-dev at lists.llvm.org>
Sent: 13 July 2021 21:55
To: flang-dev at lists.llvm.org <flang-dev at lists.llvm.org>
Subject: Re: [flang-dev] flang test questions

Hi Damian,

On 13/07/2021 20:06, Damian Rouson via flang-dev wrote:
> Second, I was informed in April that the f18-llvm-project fork's fir-dev
> branch is able to produce executable files from Fortran 77 source.
> Could someone explain how to use this capability and whether this
> capability has been merged upstream to the llvm-project repository?

Merging this upstream is an ongoing process. I am not active in this
area so can't comment on timescales, but it is one of our main
challenges right now.

As for compiling with the fir-dev branch on f18-llvm-project, we have
been recently discussing this on flang-compiler.slack.com. Are you
active there? I can send you an invite.

> Do I need to pass a flag
> to tell flang to produce an executable program without invoking gfortran?

`flang` that you are referring to is just a bash wrapper script [1] that
was added for experimenting. It will only use LLVM Flang to
parse-unparse the input source, and then will call e.g. `gfortran` for
code-generation. You can replace `gfortran` with some other Fortran
compiler. The name is rather confusing. We should rename it as
`flang-to-gnu` or something similar.

Welcome aboard! :)

-Andrzej

[1] https://github.com/llvm/llvm-project/blob/main/flang/tools/f18/flang.in
_______________________________________________
flang-dev mailing list
flang-dev at lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/flang-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/flang-dev/attachments/20210714/0252a33a/attachment-0001.html>


More information about the flang-dev mailing list