[LLVMdev] LLVM and OpenMP

Chris Lattner sabre at nondot.org
Thu Nov 29 16:21:18 PST 2007


On Fri, 30 Nov 2007, Anton Korobeynikov wrote:
> I've just commited a patch to llvm-gcc 4.2, which moves openmp lowering
> stuff to be run little bit earlier, so llvm-convert will catch its
> result. It looks now gcc atomic & sync builtins should be introduced to
> llvm as a remaining ingredient.
>
> Example program from Diego's paper now compiles to:

Very nice Anton!!

-Chris

> @.str = internal constant [10 x i8] c"sum = %d\0A\00"           ; <[10 x
> i8]*> [#uses=1]
>
> define i32 @main() {
> entry:
>        %sum = alloca i32               ; <i32*> [#uses=3]
>        %.omp_data_o.3 = alloca %struct..omp_data_s.1           ; <%
> struct..omp_data_s.1*> [#uses=2]
>        store i32 0, i32* %sum, align 4
>        %tmp = getelementptr %struct..omp_data_s.1* %.omp_data_o.3, i32
> 0, i32 0                ; <i32**> [#uses=1]
>        store i32* %sum, i32** %tmp, align 8
>        %.omp_data_o.31 = bitcast %struct..omp_data_s.1* %.omp_data_o.3
> to i8*          ; <i8*> [#uses=2]
>        call void @GOMP_parallel_start( void (i8*)* @main.omp_fn.0, i8*
> %.omp_data_o.31, i32 0 ) nounwind
>        call void @main.omp_fn.0( i8* %.omp_data_o.31 )
>        call void @GOMP_parallel_end( ) nounwind
>        %tmp3 = load i32* %sum, align 4         ; <i32> [#uses=1]
>        %tmp5 = call i32 (i8*, ...)* @printf( i8* getelementptr ([10 x
> i8]* @.str, i32 0, i32 0), i32 %tmp3 ) nounwind      $
>        ret i32 undef
> }
>
> define internal void @main.omp_fn.0(i8* %.omp_data_i) {
> entry:
>        %tmp1 = tail call i32 (...)*
> @omp_get_thread_num( )             ; <i32> [#uses=1]
>        %tmp3 = bitcast i8* %.omp_data_i to i32**               ;
> <i32**> [#uses=1]
>        %tmp4 = load i32** %tmp3, align 4               ; <i32*>
> [#uses=1]
>        %tmp45 = bitcast i32* %tmp4 to i8*              ; <i8*>
> [#uses=1]
>        %tmp6 = tail call i32 @__sync_fetch_and_add_4( i8* %tmp45, i32 %
> tmp1 ) nounwind                 ; <i32> [#uses=0]
>        ret void
> }
>
>

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list