[LLVMdev] DSA - LocalDataStructures pass does not create DSGraphs

sebald.ziegler.maillist at ikolus.de sebald.ziegler.maillist at ikolus.de
Wed Aug 7 09:57:16 PDT 2013


Hallo.

I wanted to use the DSA from the poolalloc project as a starting point for 
static C code analysis (for me it has some benefits to work on LLVM-IR 
(generated by clang) instead of C code).

Currently there is no poolalloc version 3.3. Therefore I wrote a quick patch 
to make poolalloc 3.2 compile with llvm 3.3 (mostly adaptions to file 
relocations were necessary). The patch is attached as it is quite small.

With the foundations working a simple test before getting serious seemed to be 
a good idea. So I tried to perform the LocalAnalysis (LocalDataStructures pass 
in poolalloc) on the running example (LLVM-IR obtained by clang) of Chris 
Lattner's PHD thesis (p. 44) (code attached).

When this pass(LocalDataStructures) is run I can call dumpCallGraph() on it 
and get the correct result. But calls to hasDSGraph(const Function &F) all 
return false although they should not. DSGraphs should have been built.

Does anyone see what I am doing wrong? Or is this a bug?

Thank you for any help and comments!

Sebald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: initialPortTo33.diff
Type: text/x-patch
Size: 61218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130807/a4eb35a2/attachment.bin>
-------------- next part --------------
; ModuleID = '../tests/lattnersRunningExample.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"

%struct.list = type { %struct.list*, i32 }

@Global = global i32 10, align 4

; Function Attrs: nounwind uwtable
define void @do_all(%struct.list* %L, void (i32*)* %FP) #0 {
entry:
  %L.addr = alloca %struct.list*, align 8
  %FP.addr = alloca void (i32*)*, align 8
  store %struct.list* %L, %struct.list** %L.addr, align 8
  store void (i32*)* %FP, void (i32*)** %FP.addr, align 8
  br label %do.body

do.body:                                          ; preds = %do.cond, %entry
  %0 = load void (i32*)** %FP.addr, align 8
  %1 = load %struct.list** %L.addr, align 8
  %Data = getelementptr inbounds %struct.list* %1, i32 0, i32 1
  call void %0(i32* %Data)
  %2 = load %struct.list** %L.addr, align 8
  %Next = getelementptr inbounds %struct.list* %2, i32 0, i32 0
  %3 = load %struct.list** %Next, align 8
  store %struct.list* %3, %struct.list** %L.addr, align 8
  br label %do.cond

do.cond:                                          ; preds = %do.body
  %4 = load %struct.list** %L.addr, align 8
  %tobool = icmp ne %struct.list* %4, null
  br i1 %tobool, label %do.body, label %do.end

do.end:                                           ; preds = %do.cond
  ret void
}

; Function Attrs: nounwind uwtable
define void @addG(i32* %X) #0 {
entry:
  %X.addr = alloca i32*, align 8
  store i32* %X, i32** %X.addr, align 8
  %0 = load i32* @Global, align 4
  %1 = load i32** %X.addr, align 8
  %2 = load i32* %1, align 4
  %add = add nsw i32 %2, %0
  store i32 %add, i32* %1, align 4
  ret void
}

; Function Attrs: nounwind uwtable
define void @addGToList(%struct.list* %L) #0 {
entry:
  %L.addr = alloca %struct.list*, align 8
  store %struct.list* %L, %struct.list** %L.addr, align 8
  %0 = load %struct.list** %L.addr, align 8
  call void @do_all(%struct.list* %0, void (i32*)* @addG)
  ret void
}

; Function Attrs: nounwind uwtable
define %struct.list* @makeList(i32 %Num) #0 {
entry:
  %Num.addr = alloca i32, align 4
  %New = alloca %struct.list*, align 8
  store i32 %Num, i32* %Num.addr, align 4
  %call = call noalias i8* @malloc(i64 16) #2
  %0 = bitcast i8* %call to %struct.list*
  store %struct.list* %0, %struct.list** %New, align 8
  %1 = load i32* %Num.addr, align 4
  %tobool = icmp ne i32 %1, 0
  br i1 %tobool, label %cond.true, label %cond.false

cond.true:                                        ; preds = %entry
  %2 = load i32* %Num.addr, align 4
  %sub = sub nsw i32 %2, 1
  %call1 = call %struct.list* @makeList(i32 %sub)
  br label %cond.end

cond.false:                                       ; preds = %entry
  br label %cond.end

cond.end:                                         ; preds = %cond.false, %cond.true
  %cond = phi %struct.list* [ %call1, %cond.true ], [ null, %cond.false ]
  %3 = load %struct.list** %New, align 8
  %Next = getelementptr inbounds %struct.list* %3, i32 0, i32 0
  store %struct.list* %cond, %struct.list** %Next, align 8
  %4 = load i32* %Num.addr, align 4
  %5 = load %struct.list** %New, align 8
  %Data = getelementptr inbounds %struct.list* %5, i32 0, i32 1
  store i32 %4, i32* %Data, align 4
  %6 = load %struct.list** %New, align 8
  ret %struct.list* %6
}

; Function Attrs: nounwind
declare noalias i8* @malloc(i64) #1

; Function Attrs: nounwind uwtable
define i32 @main() #0 {
entry:
  %retval = alloca i32, align 4
  %X = alloca %struct.list*, align 8
  %Y = alloca %struct.list*, align 8
  store i32 0, i32* %retval
  %call = call %struct.list* @makeList(i32 10)
  store %struct.list* %call, %struct.list** %X, align 8
  %call1 = call %struct.list* @makeList(i32 100)
  store %struct.list* %call1, %struct.list** %Y, align 8
  %0 = load %struct.list** %X, align 8
  call void @addGToList(%struct.list* %0)
  store i32 20, i32* @Global, align 4
  %1 = load %struct.list** %Y, align 8
  call void @addGToList(%struct.list* %1)
  ret i32 0
}

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" }
attributes #1 = { 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" }
attributes #2 = { nounwind }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 1298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130807/a4eb35a2/attachment.cpp>


More information about the llvm-dev mailing list