Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

perllVm: A start.

by BrowserUk (Pope)
on Sep 02, 2012 at 22:26 UTC ( #991333=perlmeditation: print w/ replies, xml ) Need Help??

Or, how to build a working perl with 4 commands.

Start with a fresh distribution of perl 5.16. Shove it somewhere out of the way and build & test it.

Now create another, simpler directory structure:

llperl \- dll \-src

Copy the 44 .c files required to build the perl516.dll into dll. Copy perlmain.c, 68 perlish header files and couple of other oddballs perly.act perly.tab. Copy 5 files with .c extensions that are use as include files and rename them .cinc. Modified the /includes appropriately. Rename perllib.c to perllib.cpp (it contains c++ code).

Now build the DLL (2 commmands):

C:\test\llperl\dll>cl /MT -c -DWIN32 -DWIN64 -DPERLDLL -DPERL_CORE -DP +ERL_IMPLICIT_SYS -I ..\src *.c *.cpp Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64 Copyright (C) Microsoft Corporation. All rights reserved. av.c deb.c doio.c doop.c dump.c DynaLoader.c fcrypt.c globals.c gv.c h +v.c keywords.c locale.c mathoms.c mg.c mro.c numeric.c op.c op.c(10621) : warning C4028: formal paramete +r 2 different from declaration pad.c perl.c perlapi.c Generating Code... Compiling... perlio.c perly. +c pp.c pp_ctl.c pp_hot.c pp_pack.c pp_sort.c pp_sys.c reentr.c regcomp.c regexec.c run.c scope.c sv.c tai +nt.c toke.c universal.c utf8.c util.c win32.c Generating Code... Compiling... Win32CORE.c win32io.c w +in32sck.c win32thread.c Generating Code... Compiling... perllib.cpp Generating Code... C:\test\llperl\dll>link /dll /out:..\perl516.dll -def:..\perldll.def * +.obj ws2_32.lib user32.lib ComCtl32.Lib AdvAPI32.Lib Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. perlio.obj : warning LNK4197: export 'PerlIO_perlio' specified multipl +e times; using first specification perlio.obj : warning LNK4197: export 'PerlIO_pending' specified multip +le times; using first specification Creating library ..\perl516.lib and object ..\perl516.exp C:\test\llperl>dir 02/09/2012 09:53 <DIR> dll 02/09/2012 22:52 2,587,136 perl516.dll 02/09/2012 22:52 153,839 perl516.exp 02/09/2012 22:52 253,364 perl516.lib 02/09/2012 03:46 <DIR> src

Now build perl.exe with 2 more commands:

C:\test\llperl>cl /MT -c -DWIN32 -DWIN64 -DPERL_CORE -DPERL_IMPLICIT_ +SYS -I src src\*.c Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64 Copyright (C) Microsoft Corporation. All rights reserved. perlmain.c C:\test\llperl>link /OUT:perllVm.exe *.obj perl516.lib ws2_32.lib user +32.lib ComCtl32.Lib AdvAPI32.Lib Microsoft (R) Incremental Linker Version 9.00.21022.08 Copyright (C) Microsoft Corporation. All rights reserved. C:\test\llperl>dir 02/09/2012 09:53 <DIR> dll 02/09/2012 22:52 2,587,136 perl516.dll 02/09/2012 22:52 153,839 perl516.exp 02/09/2012 22:52 253,364 perl516.lib 02/09/2012 03:29 23,359 perldll.def 02/09/2012 22:56 38,400 perllVm.exe 02/09/2012 22:56 1,015 perlmain.obj 02/09/2012 03:46 <DIR> src

And try it:

C:\test\llperl>perllVm -v This is perl 5, version 16, subversion 1 (v5.16.1) built for MSWin32-x +64-multi-thread Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. C:\test\llperl>perllVm -E"say 'Hello, world!'" Hello, world! C:\test\llperl>type Ack.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; C:\test\llperl>perllVm Ack.pl 3 9 4093 Took: 15.6298589706421

How's that compare with the standard build:

C:\test\llperl>\test\perl-5.16.1\perl.exe Ack.pl 3 9 4093 Took: 9.76109409332275

Slow, but then I never enabled any optimisation, but it did run the XS module TIme::HiRes without incident. Which is cool and a good sign.

So what's the point? Well now I copy the same start structure and files to another directory and do this:

C:\test\perllVm>dir 02/09/2012 04:04 331 Ack.pl 02/09/2012 22:10 1,863 build.cmd 02/09/2012 23:12 <DIR> dll 02/09/2012 03:29 23,359 perldll.def 02/09/2012 05:01 <DIR> src C:\test\perllVm>cd dll C:\test\perllVm\dll>set opts=-c -fno-caret-diagnostics -fno-color-diag +nostics C:\test\perllVm\dll>set warn=-Wno-unused-value -Wno-deprecated-declara +tions -Wno-parentheses -Wno-deprecated-writable-strings C:\test\perllVm\dll>set defs=-DWIN32 -DWIN64 -DPERLDLL -DPERL_CORE -DP +ERL_IMPLICIT_SYS C:\test\perllVm\dll>set srcs=av.c deb.c doio.c doop.c dump.c DynaLoade +r.c fcrypt.c globals.c gv.c hv.c keywords.c locale .c mathoms.c mg.c mro.c numeric.c op.c pad.c perl.c perlapi.c perlio.c + perllib.cpp perly.c pp.c pp_ctl.c pp_hot.c pp_pac k.c pp_sort.c pp_sys.c reentr.c regcomp.c regexec.c run.c scope.c sv.c + taint.c toke.c universal.c utf8.c util.c win32.c Win32CORE.c win32io.c win32sck.c win32thread.c C:\test\perllVm\dll>set libs=ws2_32.lib user32.lib ComCtl32.Lib AdvAPI +32.Lib C:\test\perllVm\dll>\llvm\clang.exe -m64 -I ..\src %opts% %warn% %defs +% %srcs% In file included from sv.c:41: ./stdint.h:197:9: warning: 'INT64_C' macro redefined ..\src/handy.h:204:28: note: previous definition is here In file included from sv.c:41: ./stdint.h:202:9: warning: 'UINT64_C' macro redefined ..\src/handy.h:205:28: note: previous definition is here win32.c:1925:30: warning: format specifies type 'int' but the argument + has type 'DWORD' (aka 'unsigned long') [-Wformat] win32.c:1925:33: warning: format specifies type 'int' but the argument + has type 'DWORD' (aka 'unsigned long') [-Wformat] win32.c:1929:36: warning: format specifies type 'int' but the argument + has type 'DWORD' (aka 'unsigned long') [-Wformat] win32.c:1977:41: warning: format specifies type 'unsigned int' but the + argument has type 'DWORD' (aka 'unsigned long') [-Wformat] C:\test\perllVm\dll>dir /b *.o av.o deb.o doio.o doop.o dump.o DynaLoader.o fcrypt.o globals.o gv.o h +v.o keywords.o locale.o mathoms.o mg.o mro.o numeric.o op.o pad.o perl.o perlapi.o perlio.o perllib.o perly.o pp.o +pp_ctl.o pp_hot.o pp_pack.o pp_sort.o pp_sys.o reentr.o regcomp.o regexec.o run.o scope.o sv.o taint.o toke.o univers +al.o utf8.o util.o win32.o Win32CORE.o win32io.o win32sck.o win32thread.o C:\test\perllVm\dll>link /verbose:lib /dll /noentry /out:..\perl516.dl +l -def:..\perldll.def *.obj /libpath %libs% | wc -l 1796

No surprise it didn't quite link yet -- still a lot to learn about the clang/llvm, toolset -- but now I've got a nice simple environment in which to play. (I like simple!)

Of course, I would have got there a lot sooner with some expert assistance.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

RIP Neil Armstrong

Social

Comment on perllVm: A start.
Select or Download Code
Re: perllVm: A start.
by flexvault (Parson) on Sep 03, 2012 at 16:11 UTC

    BrowserUk,

    Congratulations!

    I'm not too familiar with windows, but it looks like you didn't use any of CPAN LLVM modules. Is that correct?

    How did you get/compile 'clang.exe'? The LLVM documentation implies(to me) that 'clang' is much faster than 'gcc', but it looks like you use 'gcc' to compile 'clang.exe'. Or maybe once you have 'clang.exe' you can get a faster version by compiling 'clang.exe' with 'clang'. Completely guessing :-)

    Keep up the good work...Ed

    "Well done is better than well said." - Benjamin Franklin

      flexvault:

      I installed clang from cygwin a couple of days ago. It'll make windows EXEs, so you might give that a shot for a simple installation if you don't find something else.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.

        roboticus,

        Thanks for the heads up!

        What I was referring to is that I don't work on windows much, but I have some Debian Linux machines that I could check out. Looks like favorable results with Debian on compiling the entire distribution with clang.

        Thanks...Ed

        "Well done is better than well said." - Benjamin Franklin

      Thanks.

      • it looks like you didn't use any of CPAN LLVM modules.

        Correct. Those modules are for use from an existing Perl installation to compile C code to speed up small functions. Much in the vain of using XS or Inline::C.

        The exercise here is to (first) build Perl itself using LLVM.

      • How did you get/compile 'clang.exe'?

        You pull the source code and then build it :) see http://clang.llvm.org/get_started.html.

        It can be built with gcc (mingw on win), or MSVC.

        Once built (on *nix) clang 'claims' (or perhaps just 'aims') to be a "drop-in replacement for gcc".

        (I'm not in a position to verify that, but superficially from the docs and examples I can find, it looks fairly true.

      • Or maybe once you have 'clang.exe' you can get a faster version by compiling 'clang.exe' with 'clang'. Completely guessing :-)

        I've no idea if you can bootstrap clang using clang.

        Update: it can and does on *nix. (Apparently their build bots re-build themselves regularly.)

      For now, my target is to work out how to build (a) working perl -- that is compatible with modules built for that perl using the normal mechanisms -- using clang.

      A simple, standalone sandbox in which to play.

      Then I can compare that to the standard build and see what if any improvements are available using LLVM as just another C compiler.

      Then I can explore what differences/improvements are bought about by which of LLVMs many optimisation passes. Ie. which give the best bang for the buck.

      Then move on to exploring the possibility of bolting LLVM JIT into the mix at runtime.

      But baby steps. The clang docs are sparse and despite that they are targeting windows compatibility -- and have already added lots of support -- there are few windows people involved from who to curry expertise.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        BrowserUk,

        I just checked if Debian had clang/LLVM, and interestingly: http://clang.debian.net/

        It included a link with actual compile times: http://gcc.gnu.org/ml/gcc/2012-02/msg00134.html

        See the full report for explanation, but the following looks good.

        These are the average compile times for compiling a file in a set of 100 randomly selected files: (time values in seconds) gcc 4.4 gcc 4.6 gcc 4.7 clang 3.0 clang 3.1 -fs-o -O0 0.450 0.458 0.501 0.449 0.439 -O0 0.624 0.631 0.684 0.504 0.494 -O0 -g 0.722 0.727 0.781 0.661 0.653 -O2 0.811 0.803 0.874 0.603 0.597 -O2 -g 0.916 0.979 1.06 0.809 0.809 These are the average compile times for compiling a file in the set of the 10 files that are slowest (as when compiled with gcc 4.4 using -O2) to compile: gcc 4.4 gcc 4.6 gcc 4.7 clang 3.0 clang 3.1 -fs-o -O0 2.18 1.70 1.86 1.70 1.66 -O0 5.87 5.33 5.71 2.90 2.85 -O0 -g 6.71 6.19 6.61 4.00 4.08 -O2 11.9 10.8 12.0 6.72 6.80 -O2 -g 13.2 13.6 15.1 9.57 9.78
        I usually compile with '-O2' which looks very good.

        Regards...Ed

        "Well done is better than well said." - Benjamin Franklin

        BrowserUK: Please see https://www.socialtext.net/perl5/LLVM

        Yuval has no time and tuits to follow his proposal, but I might do so.

        I'm also trying to target nqp to LLVM (vmkit, really) to get away from parrot's performance problems.

Re: perllVm: A start.
by Will_the_Chill (Pilgrim) on Sep 04, 2012 at 02:59 UTC
    BrowserUK,

    Look at you, starting work toward Perl5-on-LLVM already!

    *high five*

    ~ Will

      Just a quick exploration for now... someone had to get their hands muddy.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      RIP Neil Armstrong

        Quite!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://991333]
Approved by ww
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2014-12-22 23:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (133 votes), past polls