pfalcon/graph-llvm-ir — pull request #1 by dmikushin (2013-12-05 04:12:47+00:00)
Title: Quoting edges names, as dot does not like names with dots. Fixing problem with "ret void" displaying. Switched to nicer rectangular shapes.

Tried graph-llvm-ir on the llvm code below and fixed several minor issues encountered.

$ cat example.ll
; ModuleID = '/home/marcusmae/Documents/llvm-graphs/example/example.c'
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"
target triple = "x86_64-unknown-linux-gnu"

define void @vector_sum(i32 %length, float* nocapture %in1, float* nocapture %in2, float* nocapture %out) nounwind uwtable {
entry:
%cmp9 = icmp sgt i32 %length, 0
br i1 %cmp9, label %for.body, label %for.end

for.body: ; preds = %entry, %for.body
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
%arrayidx = getelementptr inbounds float* %in1, i64 %indvars.iv
%0 = load float* %arrayidx, align 4, !tbaa !0
%arrayidx2 = getelementptr inbounds float* %in2, i64 %indvars.iv
%1 = load float* %arrayidx2, align 4, !tbaa !0
%add = fadd float %0, %1
%arrayidx4 = getelementptr inbounds float* %out, i64 %indvars.iv
store float %add, float* %arrayidx4, align 4, !tbaa !0
%indvars.iv.next = add i64 %indvars.iv, 1
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
%exitcond = icmp eq i32 %lftr.wideiv, %length
br i1 %exitcond, label %for.end, label %for.body

for.end: ; preds = %for.body, %entry
ret void
}

define i32 @main(i32 %argc, i8** nocapture %argv) nounwind uwtable {
entry:
%cmp = icmp eq i32 %argc, 2
br i1 %cmp, label %if.end, label %return

if.end: ; preds = %entry
%arrayidx = getelementptr inbounds i8** %argv, i64 1
%0 = load i8** %arrayidx, align 8, !tbaa !3
%call = tail call i32 @atoi(i8* %0) nounwind readonly
%conv = sext i32 %call to i64
%mul = shl nsw i64 %conv, 2
%call1 = tail call noalias i8* @malloc(i64 %mul) nounwind
%1 = bitcast i8* %call1 to float*
%call4 = tail call noalias i8* @malloc(i64 %mul) nounwind
%2 = bitcast i8* %call4 to float*
%call7 = tail call noalias i8* @malloc(i64 %mul) nounwind
%3 = bitcast i8* %call7 to float*
%cmp826 = icmp sgt i32 %call, 0
br i1 %cmp826, label %for.body, label %for.end

for.body: ; preds = %if.end, %for.body
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %if.end ]
%call10 = tail call double @drand48() nounwind
%conv11 = fptrunc double %call10 to float
%arrayidx12 = getelementptr inbounds float* %1, i64 %indvars.iv
store float %conv11, float* %arrayidx12, align 4, !tbaa !0
%call13 = tail call double @drand48() nounwind
%conv14 = fptrunc double %call13 to float
%arrayidx16 = getelementptr inbounds float* %2, i64 %indvars.iv
store float %conv14, float* %arrayidx16, align 4, !tbaa !0
%indvars.iv.next = add i64 %indvars.iv, 1
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
%exitcond = icmp eq i32 %lftr.wideiv, %call
br i1 %exitcond, label %for.end, label %for.body

for.end: ; preds = %for.body, %if.end
tail call void @vector_sum(i32 %call, float* %1, float* %2, float* %3)
br label %return

return: ; preds = %entry, %for.end
%retval.0 = phi i32 [ 0, %for.end ], [ 1, %entry ]
ret i32 %retval.0
}

define available_externally i32 @atoi(i8* nocapture %__nptr) nounwind uwtable readonly inlinehint {
entry:
%call = tail call i64 @strtol(i8* nocapture %__nptr, i8** null, i32 10) nounwind
%conv = trunc i64 %call to i32
ret i32 %conv
}

declare noalias i8* @malloc(i64) nounwind

declare double @drand48() nounwind

declare i64 @strtol(i8*, i8** nocapture, i32) nounwind

!0 = metadata !{metadata !"float", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA"}
!3 = metadata !{metadata !"any pointer", metadata !1}