LLVM 13.0 released with Flang

The official release notes say: Flang is now included in the binary packages released by LLVM.

https://releases.llvm.org/13.0.0/docs/ReleaseNotes.html

Does it mean LLVM Flang can now produce an executable without calling an external compiler?

Flang as the Fortran front-end is now included in the official LLVM binary packages.

4 Likes

LLVM 13.0 is available in Fedora 35. I have made some tests in a Fedora Rawhide virtual machine. There is flang-new, which can’t produce yet an executable:

$ flang-new --version
flang-new version 13.0.0 (Fedora 13.0.0~rc1-1.fc35)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ flang-new hello.f90
error: code-generation is not available yet

and the flang script:

$ flang --version
flang version 13.0.0
$ flang hello.f90
$ ./a.out
 Hello World!
1 Like

Trying to add a use iso_c_binding statement in an hello world example, I am quite confused:

$ flang hello.f90
./hello.f90:2:9: error: Cannot read module file for module 'iso_c_binding': Source file 'iso_c_binding.f18.mod' was not found
      use iso_c_binding
          ^^^^^^^^^^^^^
error: Semantic errors in hello.f90
flang: in /home/osboxes, flang-new failed with exit status 1: /usr/bin/flang-new -fc1 -module-suffix .f18.mod -fdebug-unparse -fno-analyzed-objects-for-unparse hello.f90

I used flang but the error message says flang-new failed. And why the iso_c_binding module is not available?

Classic Flang (GitHub - flang-compiler/flang: Flang is a Fortran language front-end designed for integration with LLVM.) is a separate compiler and not shipped along with llvm.

flang-new is the driver of the Fortran frontend shipped along with llvm. flang is a shell script that can parse, perform semantics, and unparse and call an external compiler to do the codegen. flang basically calls flang-new internally. When codegen becomes available then the flang script will be removed/renamed and flang-new will be renamed as flang.

I don’t know why the iso_c_binding usage is not working. I expected it to work. Maybe you can file a bug (Bug List).

1 Like

Thanks for clarifying things about flang / flang-new.
I will make more tests about iso_c_binding and see if everything is correctly installed in my Fedora Rawhide.

EnzymeAD seems to be a good plugin for Flang.

2 Likes

I fully agree, and we are actively working on making it work (and work nicer at that), but the actual plugin interface for flang-new is only just landing right now[1], so I would deem it too early to use for now.

An alternative way to use Enzyme with Fortran is by writing the compilation pipeline out manually in the Makefile:

  1. Obtain .fir with the bbc compiler
  2. Run first round of optimizations with opt
  3. Combine the IR with llvm-link
  4. Apply Enzyme with opt
  5. 2nd optimization pass, and compile executable with clang++

Let me know if I can be of any help!

[1] ⚙ D129156 Add -fpass-plugin option to Flang