Skip to content

Instantly share code, notes, and snippets.

@nachivpn
Created May 14, 2017 22:28
Show Gist options
  • Save nachivpn/5de0d1fee48ece0a72ba1061e51b94f3 to your computer and use it in GitHub Desktop.
Save nachivpn/5de0d1fee48ece0a72ba1061e51b94f3 to your computer and use it in GitHub Desktop.
llvm-arrays-2.ll
; int n = 25;
; int[] a = new int[n];
; return a.length;
; Generates this:
; ......
entry0:
;;; int n = 25;
%"$0_n" = alloca i32
store i32 25, i32* %"$0_n"
;;; int[] a = new int[n];
;;; "new int[n]" returns a struct at r_astruct_10
%r0 = load i32, i32* %"$0_n"
%r_size_1 = getelementptr i32, i32* null, i32 1
%r_sizeof_2 = ptrtoint i32* %r_size_1 to i32
%r_len_3 = sext i32 %r0 to i64
%r_size_4 = sext i32 %r_sizeof_2 to i64
%r5 = call i8* @calloc(i64 %r_len_3, i64 %r_size_4)
%r_addr_6 = bitcast i8* %r5 to i32*
%r_astructptr_7 = alloca { i32, i32* }
%r_alenptr_8 = getelementptr { i32, i32* }, { i32, i32* }* %r_astructptr_7, i32 0, i32 0
store i32 %r0, i32* %r_alenptr_8
%r_aptr_9 = getelementptr { i32, i32* }, { i32, i32* }* %r_astructptr_7, i32 0, i32 1
store i32* %r_addr_6, i32** %r_aptr_9
%r_astruct_10 = load { i32, i32* }, { i32, i32* }* %r_astructptr_7
;;; "int[] a =" stores the struct %r_astruct_10 in %"$1_a"
%"$1_a" = alloca { i32, i32* }
store { i32, i32* } %r_astruct_10, { i32, i32* }* %"$1_a"
;;; return a.length;
%r_alenptr_11 = getelementptr { i32, i32* }, { i32, i32* }* %"$1_a", i32 0, i32 0
%r_alen_12 = load i32, i32* %r_alenptr_11
ret i32 %r_alen_12
; .....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment