From 9e89ba31f16a960239a750a26a982b4c9dfe8949 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Wed, 31 Dec 2008 16:14:43 +0000 Subject: Rename AddReadAttrs to FunctionAttrs, and teach it how to work out (in a very simplistic way) which function arguments (pointer arguments only) are only dereferenced and so do not escape. Mark such arguments 'nocapture'. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@61525 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll | 11 +++++++ .../FunctionAttrs/2008-09-03-ReadNone.ll | 18 ++++++++++++ .../FunctionAttrs/2008-09-03-ReadOnly.ll | 9 ++++++ .../FunctionAttrs/2008-09-13-VolatileRead.ll | 9 ++++++ .../FunctionAttrs/2008-10-04-LocalMemory.ll | 10 +++++++ .../FunctionAttrs/2008-12-29-Constant.ll | 8 +++++ .../FunctionAttrs/2008-12-31-NoCapture.ll | 34 ++++++++++++++++++++++ test/Transforms/FunctionAttrs/dg.exp | 3 ++ 8 files changed, 102 insertions(+) create mode 100644 test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll create mode 100644 test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll create mode 100644 test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll create mode 100644 test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll create mode 100644 test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll create mode 100644 test/Transforms/FunctionAttrs/2008-12-29-Constant.ll create mode 100644 test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll create mode 100644 test/Transforms/FunctionAttrs/dg.exp (limited to 'test/Transforms/FunctionAttrs') diff --git a/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll b/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll new file mode 100644 index 0000000..5261ac4 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-03-Mutual.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone + +define i32 @a() { + %tmp = call i32 @b( ) ; [#uses=1] + ret i32 %tmp +} + +define i32 @b() { + %tmp = call i32 @a( ) ; [#uses=1] + ret i32 %tmp +} diff --git a/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll b/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll new file mode 100644 index 0000000..a17d381 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-03-ReadNone.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone | count 4 +@x = global i32 0 + +declare i32 @e() readnone + +define i32 @f() { + %tmp = call i32 @e( ) ; [#uses=1] + ret i32 %tmp +} + +define i32 @g() readonly { + ret i32 0 +} + +define i32 @h() readnone { + %tmp = load i32* @x ; [#uses=1] + ret i32 %tmp +} diff --git a/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll b/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll new file mode 100644 index 0000000..cebfdac --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-03-ReadOnly.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readonly | count 2 + +define i32 @f() { +entry: + %tmp = call i32 @e( ) ; [#uses=1] + ret i32 %tmp +} + +declare i32 @e() readonly diff --git a/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll b/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll new file mode 100644 index 0000000..b6077fd --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-09-13-VolatileRead.ll @@ -0,0 +1,9 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep read +; PR2792 + +@g = global i32 0 ; [#uses=1] + +define i32 @f() { + %t = volatile load i32* @g ; [#uses=1] + ret i32 %t +} diff --git a/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll b/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll new file mode 100644 index 0000000..50ca641 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-10-04-LocalMemory.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone | count 2 + +declare i32 @g(i32*) readnone + +define i32 @f() { + %x = alloca i32 ; [#uses=2] + store i32 0, i32* %x + %y = call i32 @g(i32* %x) ; [#uses=1] + ret i32 %y +} diff --git a/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll b/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll new file mode 100644 index 0000000..d9c0117 --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-12-29-Constant.ll @@ -0,0 +1,8 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep readnone + +@s = external constant i8 ; [#uses=1] + +define i8 @f() { + %tmp = load i8* @s ; [#uses=1] + ret i8 %tmp +} diff --git a/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll b/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll new file mode 100644 index 0000000..6d2ca1e --- /dev/null +++ b/test/Transforms/FunctionAttrs/2008-12-31-NoCapture.ll @@ -0,0 +1,34 @@ +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | not grep {@c.*nocapture} +; RUN: llvm-as < %s | opt -functionattrs | llvm-dis | grep nocapture | count 3 +@g = global i32* null ; [#uses=1] + +define i32* @c1(i32* %p) { + ret i32* %p +} + +define void @c2(i32* %p) { + store i32* %p, i32** @g + ret void +} + +define void @c3(i32* %p) { + call void @c2(i32* %p) + ret void +} + +define i32 @nc1(i32* %p) { + %tmp = bitcast i32* %p to i32* ; [#uses=2] + %val = load i32* %tmp ; [#uses=1] + store i32 0, i32* %tmp + ret i32 %val +} + +define void @nc2(i32* %p) { + %1 = call i32 @nc1(i32* %p) ; [#uses=0] + ret void +} + +define void @nc3(void ()* %f) { + call void %f() + ret void +} diff --git a/test/Transforms/FunctionAttrs/dg.exp b/test/Transforms/FunctionAttrs/dg.exp new file mode 100644 index 0000000..f200589 --- /dev/null +++ b/test/Transforms/FunctionAttrs/dg.exp @@ -0,0 +1,3 @@ +load_lib llvm.exp + +RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] -- cgit v1.1