I cannot do compilation without going through temp files if I attach -save-temps
flag, because the Flang compiler driver creates different compiler jobs for -save-temps
flag.
For -save-temps
flag Flang compiler driver process each file separately.
- User command:
flang-new test.f95 -v -c -save-temps
- Fortran compilation jobs:
flang-new -fc1 -triple x86_64-unknown-linux-gnu -E -fcolor-diagnostics -mrelocation-model static -target-cpu x86-64 -o test.i -save-temps=cwd -x f95-cpp-input test.f95
flang-new -fc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -fcolor-diagnostics -mrelocation-model static -target-cpu x86-64 -o test.bc -save-temps=cwd -x f95 test.i
Other compilation steps which converts *.bc file to *.s and then to *.o file
- Fortran compilation jobs:
Whereas without -save-temps
Flang generates the object file directly from the source file:
- User command:
flang-new test.f95 -v -c
- Fortran compilation job:
flang-new -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model static -target-cpu x86-64 -o test.o -x f95-cpp-input test.f95
- Fortran compilation job:
IMO the -save-temps
flag is useful for compiler debugging. I can extract the code (MLIR / LLVM IR / assembly) and I can easily verify if given compilation phase is correct.
I cannot do it for -save-temps
flag because the set of compilation jobs is managed by Flang driver which uses Clang’s driver library. I was convinced that I should not modify the Flang driver (see this post)