Advertisement
lawliet89

bubble-sort.ll

May 19th, 2014
3,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LLVM 6.98 KB | None | 0 0
  1. ; ModuleID = 'bubble.ll'
  2. target datalayout = "e-p:64:64:64-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-s0:64:64-f80:128:128-n8:16:32:64-S128"
  3. target triple = "x86_64-pc-linux-gnu"
  4.  
  5. @main.a = private unnamed_addr constant [9 x i32] [i32 7, i32 12, i32 1, i32 -2, i32 0, i32 15, i32 4, i32 11, i32 9], align 16
  6. @.str = private unnamed_addr constant [23 x i8] c"\0A\0AUnsorted array is:  \00", align 1
  7. @.str1 = private unnamed_addr constant [5 x i8] c" %d \00", align 1
  8. @.str2 = private unnamed_addr constant [21 x i8] c"\0A\0ASorted array is:  \00", align 1
  9. @.str3 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1
  10.  
  11. ; Function Attrs: nounwind uwtable
  12. define i32 @main() #0 {
  13.   %a = alloca [9 x i32], align 16
  14.   %1 = bitcast [9 x i32]* %a to i8*
  15.   call void @llvm.memcpy.p0i8.p0i8.i64(i8* %1, i8* bitcast ([9 x i32]* @main.a to i8*), i64 36, i32 16, i1 false)
  16.   %2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([23 x i8]* @.str, i64 0, i64 0)) #1
  17.   %3 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 0
  18.   %4 = load i32* %3, align 16
  19.   %5 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %4) #1
  20.   %6 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 1
  21.   %7 = load i32* %6, align 4
  22.   %8 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %7) #1
  23.   %9 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 2
  24.   %10 = load i32* %9, align 8
  25.   %11 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %10) #1
  26.   %12 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 3
  27.   %13 = load i32* %12, align 4
  28.   %14 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %13) #1
  29.   %15 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 4
  30.   %16 = load i32* %15, align 16
  31.   %17 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %16) #1
  32.   %18 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 5
  33.   %19 = load i32* %18, align 4
  34.   %20 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %19) #1
  35.   %21 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 6
  36.   %22 = load i32* %21, align 8
  37.   %23 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %22) #1
  38.   %24 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 7
  39.   %25 = load i32* %24, align 4
  40.   %26 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %25) #1
  41.   %27 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 8
  42.   %28 = load i32* %27, align 16
  43.   %29 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %28) #1
  44.   %30 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 0
  45.   call void @bubbleSort(i32* %30, i32 9)
  46.   %31 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([21 x i8]* @.str2, i64 0, i64 0)) #1
  47.   %32 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 0
  48.   %33 = load i32* %32, align 16
  49.   %34 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %33) #1
  50.   %35 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 1
  51.   %36 = load i32* %35, align 4
  52.   %37 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %36) #1
  53.   %38 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 2
  54.   %39 = load i32* %38, align 8
  55.   %40 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %39) #1
  56.   %41 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 3
  57.   %42 = load i32* %41, align 4
  58.   %43 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %42) #1
  59.   %44 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 4
  60.   %45 = load i32* %44, align 16
  61.   %46 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %45) #1
  62.   %47 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 5
  63.   %48 = load i32* %47, align 4
  64.   %49 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %48) #1
  65.   %50 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 6
  66.   %51 = load i32* %50, align 8
  67.   %52 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %51) #1
  68.   %53 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 7
  69.   %54 = load i32* %53, align 4
  70.   %55 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %54) #1
  71.   %56 = getelementptr inbounds [9 x i32]* %a, i64 0, i64 8
  72.   %57 = load i32* %56, align 16
  73.   %58 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([5 x i8]* @.str1, i64 0, i64 0), i32 %57) #1
  74.   %putchar = call i32 @putchar(i32 10) #1
  75.   ret i32 0
  76. }
  77.  
  78. ; Function Attrs: nounwind
  79. declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) #1
  80.  
  81. ; Function Attrs: nounwind
  82. declare i32 @printf(i8* nocapture, ...) #2
  83.  
  84. ; Function Attrs: nounwind uwtable
  85. define void @bubbleSort(i32* nocapture %a, i32 %length) #0 {
  86.   %1 = add nsw i32 %length, -1
  87.   br label %.outer
  88.  
  89. .outer:                                           ; preds = %13, %14, %0
  90.   %i.0.ph = phi i32 [ 0, %0 ], [ 0, %14 ], [ %9, %13 ]
  91.   %swapped.0.ph = phi i8 [ 0, %0 ], [ 0, %14 ], [ 1, %13 ]
  92.   %2 = sext i32 %i.0.ph to i64
  93.   br label %3
  94.  
  95. ; <label>:3                                       ; preds = %.outer, %6
  96.   %indvars.iv = phi i64 [ %2, %.outer ], [ %indvars.iv.next, %6 ]
  97.   %i.0 = phi i32 [ %i.0.ph, %.outer ], [ %9, %6 ]
  98.   %4 = trunc i64 %indvars.iv to i32
  99.   %5 = icmp slt i32 %4, %1
  100.   br i1 %5, label %6, label %14
  101.  
  102. ; <label>:6                                       ; preds = %3
  103.   %7 = getelementptr inbounds i32* %a, i64 %indvars.iv
  104.   %8 = load i32* %7, align 4
  105.   %indvars.iv.next = add i64 %indvars.iv, 1
  106.   %9 = add nsw i32 %i.0, 1
  107.   %10 = getelementptr inbounds i32* %a, i64 %indvars.iv.next
  108.   %11 = load i32* %10, align 4
  109.   %12 = icmp sgt i32 %8, %11
  110.   br i1 %12, label %13, label %3
  111.  
  112. ; <label>:13                                      ; preds = %6
  113.   store i32 %11, i32* %7, align 4
  114.   store i32 %8, i32* %10, align 4
  115.   br label %.outer
  116.  
  117. ; <label>:14                                      ; preds = %3
  118.   %15 = icmp eq i8 %swapped.0.ph, 0
  119.   br i1 %15, label %16, label %.outer
  120.  
  121. ; <label>:16                                      ; preds = %14
  122.   ret void
  123. }
  124.  
  125. ; Function Attrs: nounwind
  126. declare i32 @putchar(i32) #1
  127.  
  128. attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
  129. attributes #1 = { nounwind }
  130. attributes #2 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement