Changes between Version 3 and Version 4 of LLVM_ToolDemo


Ignore:
Timestamp:
Mar 12, 2014, 1:29:18 AM (4 years ago)
Author:
cameron
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • LLVM_ToolDemo

    v3 v4  
    6464{{{
    6565cd proto/RE/output/demo1src
    66 make clang-re
     66clang++ -msse2  -O3 -std=gnu++0x -o clang-re re.cpp  -I../util -I../lib/ -I../lib/cc-lib/
    6767}}}
    6868
     
    8484
    8585Now let's try breaking it down in steps, using LLVM tools.
    86 First, we use clang to make LLVM bitcode, then compile and optimize to the
    87 current architecture with llc.  Finally use clang to generate an executable.
     86First, we use clang to make LLVM bitcode.
     87{{{
     88clang++ -msse2  -O3 -std=gnu++0x -emit-llvm -c -o llvm-re.bc re.cpp  -I../util -I../lib/ -I../lib/cc-lib/
     89}}}
     90
     91Now bitcode is not readable, but we can use {{{llvm-dis}}} to disassemble and
     92produce a corresponding llvm-re.ll file containing IR code.
     93{{{
     94llvm-dis-3.4 llvm-re.bc
     95}}}
     96
     97If we look through the generated IR file, we see all sorts of
     98interesting code sequences, like this one.
    8899
    89100{{{
    90 clang++ -msse2  -O3 -std=gnu++0x -emit-llvm -c -o llvm-re.bc re.cpp  -I../util -I../lib/ -I../lib/cc-lib/
     101  %324 = and <2 x i64> %263, <i64 71777214294589695, i64 71777214294589695>
     102  %325 = and <2 x i64> %287, <i64 71777214294589695, i64 71777214294589695>
     103  %326 = bitcast <2 x i64> %325 to <8 x i16>
     104  %327 = bitcast <2 x i64> %324 to <8 x i16>
     105  %328 = call <16 x i8> @llvm.x86.sse2.packuswb.128(<8 x i16> %326, <8 x i16> %327) #2
     106  %329 = bitcast <16 x i8> %328 to <2 x i64>
     107  %330 = bitcast <16 x i8> %328 to <8 x i16>
     108  %331 = call <8 x i16> @llvm.x86.sse2.psrli.w(<8 x i16> %330, i32 4) #2
     109}}}
     110
     111What we should recognize right away is that LLVM seems to have
     112a notion of SIMD vector types built in:  `<2 x i64>` and `<8 x i16>`
     113are used extensively.   Also note that we can directly use SSE2
     114intrinsics from LLVM.
     115
     116We can now use llc to generate object code for our
     117current machine.
     118{{{
    91119llc-3.4  -filetype=obj  llvm-re.bc  -o  opt-re.o
    92120clang++ opt-re.o -o opt-re
     
    107135
    108136This is quite a big change!   What's going on?
     137
     138We shouldn't get too excited.  In this case, the key here is that llc
     139was compiling to the current architecture including avx2 extensions, even
     140though the original command line argument was {{{-msse2}}}.
     141
     142We can prove this by using llc to generate assembly instead of object code.
     143{{{
     144llc-3.4  -filetype=asm  llvm-re.bc  -o  opt-re.s
     145}}}
     146
     147If we inspect the output, we find that, for example, pxor instructions
     148are replaced by vpxor, throughout.
     149