[fpc-pascal] inlining functions

Jonas Maebe jonas at freepascal.org
Sat Jan 12 13:31:30 CET 2019


On 12/01/19 13:05, denisgolovan wrote:
> 
> 
> 12.01.2019, 14:53, "Jonas Maebe" <jonas at freepascal.org>:
>> Not at this time (unless you use the LLVM backend).
> 
> Could you give some hints on how to enable WPO/LTO under LLVM backend?
> http://wiki.freepascal.org/LLVM does not seem to mention anything on that.

It's not yet integrated in the compiler, so you have to do it manually 
right now:
a) compile everything with -al (including the RTL etc; add OPT="-a" to 
the make command)
b) go in all the unit directories, and assemble the files to bitcode 
using something like this:

for file in *.ll; do
   clang -emit-llvm -O -c $file
done

c) compile your program with -a -s and do the same as in step b) for 
your program
d) edit the generated link.res file, and replace all references to unit 
files ending in ".o" with the same files ending in ".bc"

If you used a custom clang rather than the one installed by default on 
your system, you will also have to specify the path to the libLTO that 
the linker should use. You have to do this on the ld command line in 
ppas.sh. You can find the correct parameter by compiling a test 
C-program with "clang -flto -### test.c", as this will print the ld 
invocation to use. E.g. on macOS, it will be something like

-lto_library 
/Volumes/imac/devel/clang+llvm-7.0.0-x86_64-apple-darwin/lib/libLTO.dylib"

On Linux, it's something like

-plugin 
/home/jmaebe/local/clang+llvm-7.0.0-x86_64-linux-gnu-ubuntu-16.04/bin/../lib/LLVMgold.so 
-plugin-opt=O2

(or a different optimization level)

>> However, what you actually can do, is manually recompile all units of your program
>> multiple times. While this won't help with inline functions called
>> before they are parsed in those same units, it will allow inlining of
>> function bodies in other units that were not available during the first
>> compilation due to dependency cycles.
> 
> Eh.
> It does not look too practical, right?

That's why I mentioned it's a manual process.


Jonas



More information about the fpc-pascal mailing list