[LLVMdev] LLVM IR is a compiler IR

Jin Gu Kang jaykang10 at imrc.kist.re.kr
Wed Oct 5 00:04:42 PDT 2011


Hi David,

I have been also trying to make one bitcode representation that
can be lowered to efficient ABIs on all target platforms.

I made new compilation strategy to achieve this goal as follows,

C/C++ source code
------------------------------------------ using front-end complier
Target Independent Bitcode
------------------------------------------ using translator
Traget Dependent Bitcode
------------------------------------------ using opt with optimization passes
Optimized Target Dependent Bitcode
------------------------------------------ using LLC
Target Assembly code

I can show you simple example with this strategy.

C/C++ source code
  1 #include <stdio.h>
  2
  3 int main(void) {
  4   long double a = 3.14;
  5   long double b = 2.2;
  6   long double c;
  7
  8   c = a + b;
  9
 10   printf("c=%Lf\n", c);
 11   return 0;
 12 }
------------------------------------------------------------------------------------------
Target Independent Bitcode
  1 ; ModuleID = 'long_double.c'
  2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64
 -v64:64:64-v128:128:128-a0:0:64-f192:32:32"
  3 target triple = "ovm-none-linux"
  4
  5 @.str = private constant [7 x i8(char)] [i8(char) 99, i8(char) 61, i8(char) 37, i8(char) 76, i8(c
    har) 102, i8(char) 10, i8(char) 0], align 1 ; <[7 x i8(char)]*> [#uses=1]
  6
  7 define i32(int) @main() nounwind {
  8 entry:
  9   %retval = alloca i32(int)                       ; <i32(int)*> [#uses=2]
 10   %c = alloca long_double                         ; <long_double*> [#uses=2]
 11   %b = alloca long_double                         ; <long_double*> [#uses=2]
 12   %a = alloca long_double                         ; <long_double*> [#uses=2]
 13   %0 = alloca i32(int)                            ; <i32(int)*> [#uses=2]
 14   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
 15   store long_double 0xL00000000000000810000000000000000C8F5C28F5C28F800, long_double* %a, align 8
 16   store long_double 0xL000000000000008100000000000000008CCCCCCCCCCCD000, long_double* %b, align 8
 17   %1 = load long_double* %a, align 8              ; <long_double> [#uses=1]
 18   %2 = load long_double* %b, align 8              ; <long_double> [#uses=1]
 19   %3 = fadd long_double %1, %2                    ; <long_double> [#uses=1]
 20   store long_double %3, long_double* %c, align 8
 21   %4 = load long_double* %c, align 8              ; <long_double> [#uses=1]
 22   %5 = call i32(int) (i8(char)*, ...)* @printf(i8(char)* noalias getelementptr inbounds ([7 x i8(
    char)]* @.str, i32(int) 0, i32(int) 0), long_double %4) nounwind ; <i32(int)> [#uses=0]
 23   store i32(int) 0, i32(int)* %0, align 4
 24   %6 = load i32(int)* %0, align 4                 ; <i32(int)> [#uses=1]
 25   store i32(int) %6, i32(int)* %retval, align 4
 26   br label %return
 27
 28 return:                                           ; preds = %entry
 29   %retval1 = load i32(int)* %retval               ; <i32(int)> [#uses=1]
 30   ret i32(int) %retval1
 31 }
 32
 33 declare i32(int) @printf(i8(char)* noalias, ...) nounwind
------------------------------------------------------------------------------------------
Target Dependent Bitcode
ARM
  1 ; ModuleID = 'long_double.mod.opt.arm.bc'
  2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64
 -v64:64:64-v128:128:128-a0:0:64"
  3 target triple = "armv5-none-linux-gnueabi"
  4
  5 @.str = private constant [7 x i8] c"c=%Lf\0A\00", align 1 ; <[7 x i8]*> [#uses=1]
  6
  7 define i32 @main() nounwind {
  8 entry:
  9   %retval = alloca i32                            ; <i32*> [#uses=2]
 10   %c = alloca double                              ; <double*> [#uses=2]
 11   %b = alloca double                              ; <double*> [#uses=2]
 12   %a = alloca double                              ; <double*> [#uses=2]
 13   %0 = alloca i32                                 ; <i32*> [#uses=2]
 14   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
 15   store double 3.140000e+00, double* %a, align 8
 16   store double 2.200000e+00, double* %b, align 8
 17   %1 = load double* %a, align 8                   ; <double> [#uses=1]
 18   %2 = load double* %b, align 8                   ; <double> [#uses=1]
 19   %3 = fadd double %1, %2                         ; <double> [#uses=1]
 20   store double %3, double* %c, align 8
 21   %4 = load double* %c, align 8                   ; <double> [#uses=1]
 22   %5 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([7 x i8]* @.str, i32 0, i
   32 0), double %4) nounwind ; <i32> [#uses=0]
 23   store i32 0, i32* %0, align 4
 24   %6 = load i32* %0, align 4                      ; <i32> [#uses=1]
 25   store i32 %6, i32* %retval, align 4
 26   br label %return
 27
 28 return:                                           ; preds = %entry
 29   %retval1 = load i32* %retval, align 4           ; <i32> [#uses=1]
 30   ret i32 %retval1
 31 }
 32
 33 declare i32 @printf(i8* noalias, ...) nounwind
X86
  1 ; ModuleID = 'long_double.mod.opt.x86.bc'
  2 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64
    -v64:64:64-v128:128:128-a0:0:64-f80:32:32"
  3 target triple = "i386-pc-linux-gnu"
  4
  5 @.str = private constant [7 x i8] c"c=%Lf\0A\00", align 1 ; <[7 x i8]*> [#uses=1]
  6
  7 define i32 @main() nounwind {
  8 entry:
  9   %retval = alloca i32                            ; <i32*> [#uses=2]
 10   %c = alloca x86_fp80                            ; <x86_fp80*> [#uses=2]
 11   %b = alloca x86_fp80                            ; <x86_fp80*> [#uses=2]
 12   %a = alloca x86_fp80                            ; <x86_fp80*> [#uses=2]
 13   %0 = alloca i32                                 ; <i32*> [#uses=2]
 14   %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
 15   store x86_fp80 0xK4000C8F5C28F5C28F800, x86_fp80* %a, align 4
 16   store x86_fp80 0xK40008CCCCCCCCCCCD000, x86_fp80* %b, align 4
 17   %1 = load x86_fp80* %a, align 4                 ; <x86_fp80> [#uses=1]
 18   %2 = load x86_fp80* %b, align 4                 ; <x86_fp80> [#uses=1]
 19   %3 = fadd x86_fp80 %1, %2                       ; <x86_fp80> [#uses=1]
 20   store x86_fp80 %3, x86_fp80* %c, align 4
 21   %4 = load x86_fp80* %c, align 4                 ; <x86_fp80> [#uses=1]
 22   %5 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([7 x i8]* @.str, i32 0, i
   32 0), x86_fp80 %4) nounwind ; <i32> [#uses=0]
 23   store i32 0, i32* %0, align 4
 24   %6 = load i32* %0, align 4                      ; <i32> [#uses=1]
 25   store i32 %6, i32* %retval, align 4
 26   br label %return
 27
 28 return:                                           ; preds = %entry
 29   %retval1 = load i32* %retval, align 4           ; <i32> [#uses=1]
 30   ret i32 %retval1
 31 }
 32
 33 declare i32 @printf(i8* noalias, ...) nounwind
I made new common long double type and inserted it into bitcode.

As Talin mentioned,

I am interested in having conversation about achieving the goals of the "near miss" users

of LLVM collaboratively. :)



Thanks,

Jin-Gu Kang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20111005/b3213d2a/attachment.html>


More information about the llvm-dev mailing list