I have been asked to test the LLVM environment for compiling Perl on Linux, similar to what BrowserUK did for windows. At first, I used the Debian “squeeze” Release 'apt-get' to get the LLVM package version 2.7. It installed fine, but couldn't compile Perl5.16.0.
I contacted Sylvestre Ledru who quickly responded that "Perl seems to build fine during my latest rebuild with clang 3.1." So I set out to build the LLVM environment from source. The steps are below and hopefully I used the <readmore> correctly.
Just a caution, this takes a lot of time to compile and may need as much as 3GB of space. So plan accordingly. Also notice that
you need to add '--disable-assertions' because LLVM is built in debug mode by default.../llvm/configure --enable-optimized --disable-assertions
mkdir /home/llvm/ # Home directory for LLVM versions cd /home/llvm/ # change directory to LLVM HOME mkdir llvm-3.2.src/ # make directory for version cd llvm-3.2.src/ # change directory for LLVM verson # Creates the 'llvm' directory in /home/llvm/llvm-3.2.src/ # This gives the directory structure for the build process svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm cd llvm/tools # where to install clang # Creates the 'clang' directory in /home/llvm/llvm-3.2.src/llvm/tools/ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang cd ../projects/ # where to install compiler-rt svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt cd .. mkdir build/ cd build/ ## Update: added --enable-jit to next line to always enable ../llvm/configure --enable-optimized --disable-assertions --enable-jit + ## Update: next line was missing 'make' first, then 'make check-all' t +o test make make check-all ### note: using clang: '/home/llvm/llvm-3.1.src/build/Release/bin/clan +g' make update /home/llvm/llvm-3.1.src/build# ./Release/bin/clang -v clang version 3.2 (trunk 163314) Target: i386-pc-linux-gnu Thread model: posix /home/llvm/llvm-3.1.src/build# make install make -C runtime install-bytecode make install
We now have a LLVM build including clang 3.1 compiler! We can now compile Perl with 'clang'
cd /home/pyr/PRODUCTS/perl/perllvm email7:/home/pyr/PRODUCTS/perl/perllvm# clang -v clang version 3.2 (trunk 163323) Target: i386-pc-linux-gnu Thread model: posix tar -xf./perl-5.16.0.tar cd perl-5.16.0 ./Configure -des -Dprefix=/usr/opt/perllVm -Dusethreads -Dcc=clang -D +ccflags='-O2' make make tests make install
We now have a Perl 5.16.0 built with 'clang' 3.1. 100% of the Perl tests ran correctly, which says good things about the 5.16.0 distribution. Some tests follow. I tested the Debian default 5.10.0, a 5.16.0 that I compiled with 'gcc' and finally the 5.16.0 built with 'clang'.
email7:/home/pyr/PRODUCTS/perl/perllvm# cat BrowserUK_991333.pl #!perl -sw use strict; use 5.010; use Time::HiRes qw[ time ]; no warnings 'recursion'; sub Ack { my( $M, $N ) = @_; return $N + 1 if $M == 0; return Ack( $M - 1, 1 ) if $N == 0; return Ack( $M - 1, Ack( $M, $N - 1 ) ); } my $start = time; say Ack( @ARGV ); say 'Took: ', time() - $start; email7:/home/pyr/PRODUCTS/perl/perllvm# perl5.10.0 -sw BrowserUK_99133 +3.pl 3 9 4093 Took: 15.1458311080933 email7:/home/pyr/PRODUCTS/perl/perllvm# perl5.16.0 -sw BrowserUK_99133 +3.pl 3 9 4093 Took: 15.2425358295441 email7:/home/pyr/PRODUCTS/perl/perllvm# perllvm -sw BrowserUK_991333.p +l 3 9 4093 Took: 14.7814569950104 email7:/home/pyr/Git/FB# time perl5.16.0 FBtest.plx ## Start: VSZ-8008_KB-0 RSS-5108_KB-0 BLOCK: 2048/8/2048 ( 1,000,000 +) ... ## End: VSZ-50332 RSS-47468 Diff:42324|42360_KB-0 BLOCK: 2048 real 15m5.879s user 14m24.102s sys 0m38.442s email7:/home/pyr/Git/FB# time perllvm FBtest.plx ## Start: VSZ-8008_KB-0 RSS-5108_KB-0 BLOCK: 2048/8/2048 ( 1,000,000 +) ... ## End: VSZ-50332 RSS-47468 Diff:42324|42360_KB-0 BLOCK: 2048 real 15m33.238s user 14m45.243s sys 0m41.359s
In summary it doesn't look great yet, but I didn't use the JIT LLVM. You need to modify the Perl source to take advantage of it, and that will be another post.
Thank you
"Well done is better than well said." - Benjamin Franklin
|
|---|