Changes between Version 2 and Version 3 of LLVM_ToolDemo


Ignore:
Timestamp:
Mar 12, 2014, 12:31:33 AM (4 years ago)
Author:
cameron
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LLVM_ToolDemo

    v2 v3  
    1515}}}
    1616
    17 Now let's compile code for matching the regular expression: {{{([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)}}}.
     17Now let's compile code for matching the regular expression: {{{([^ @]+)@([^ @]+)}}}.
    1818It should be in the file {{{RE/data/test/test1.re}}}, modify as needed.   Now run the regular
    1919compilation chain with gcc.
     
    3333{{{
    3434perf stat -e cycles:u,instructions:u ./re ../../performance/data/howto -c
    35 Matching Lines:32539
     35Matching Lines:15057
    3636
    3737 Performance counter stats for './re ../../performance/data/howto -c':
    3838
    39         95,090,095 cycles:u                  #    0.000 GHz                   
    40        216,535,343 instructions:u            #    2.28  insns per cycle       
     39        62,431,920 cycles:u                  #    0.000 GHz                   
     40       145,810,959 instructions:u            #    2.34  insns per cycle       
    4141
    42        0.034277223 seconds time elapsed
     42       0.030353954 seconds time elapsed
    4343
    4444}}}
     
    4747For interest, let's compare with egrep.
    4848{{{
    49 perf stat -e cycles:u,instructions:u egrep '([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+)' ../../performance/data/howto -c
    50 32539
     49perf stat -e cycles:u,instructions:u egrep '([^ @]+)@([^ @]+)' ../../performance/data/howto -c
     5015057
    5151
    52  Performance counter stats for 'egrep ([a-zA-Z][a-zA-Z0-9]*)://([^ /]+)(/[^ ]*)?|([^ @]+)@([^ @]+) ../../performance/data/howto -c':
     52 Performance counter stats for 'egrep ([^ @]+)@([^ @]+) ../../performance/data/howto -c':
    5353
    54     43,229,901,018 cycles:u                  #    0.000 GHz                   
    55    109,259,361,636 instructions:u            #    2.53  insns per cycle       
     54       595,201,507 cycles:u                  #    0.000 GHz                   
     55     1,500,703,136 instructions:u            #    2.52  insns per cycle       
    5656
    57       11.437203814 seconds time elapsed
     57       0.168963462 seconds time elapsed
    5858}}}
    5959
    60 Well egrep found the same number of matches, but about 300X slower!
     60Well egrep found the same number of matches, but a lot slower!
     61
     62Now let's look at using the LLVM tools.
     63
     64{{{
     65cd proto/RE/output/demo1src
     66make clang-re
     67}}}
     68
     69This just uses clang as a compiler instead of gcc.
     70
     71{{{
     72perf stat -e cycles:u,instructions:u ./clang-re ../../performance/data/howto -c
     73Matching Lines:15057
     74
     75 Performance counter stats for './clang-re ../../performance/data/howto -c':
     76
     77        58,330,370 cycles:u                  #    0.000 GHz                   
     78       136,538,756 instructions:u            #    2.34  insns per cycle       
     79
     80       0.029585823 seconds time elapsed
     81}}}
     82
     83Even better than gcc!
     84
     85Now let's try breaking it down in steps, using LLVM tools.
     86First, we use clang to make LLVM bitcode, then compile and optimize to the
     87current architecture with llc.  Finally use clang to generate an executable.
     88
     89{{{
     90clang++ -msse2  -O3 -std=gnu++0x -emit-llvm -c -o llvm-re.bc re.cpp  -I../util -I../lib/ -I../lib/cc-lib/
     91llc-3.4  -filetype=obj  llvm-re.bc  -o  opt-re.o
     92clang++ opt-re.o -o opt-re
     93}}}
     94
     95Now check out the performance.
     96{{{
     97cameron@cs-osl-06:~/proto/RE/output/demo1src$ perf stat -e cycles:u,instructions:u ./opt-re ../../performance/data/howto -c
     98Matching Lines:15057
     99
     100 Performance counter stats for './opt-re ../../performance/data/howto -c':
     101
     102        49,439,793 cycles:u                  #    0.000 GHz                   
     103       113,650,693 instructions:u            #    2.30  insns per cycle       
     104
     105       0.021609171 seconds time elapsed
     106}}}
     107
     108This is quite a big change!   What's going on?