diff options
author | Chris Lattner <sabre@nondot.org> | 2010-07-29 04:46:19 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-07-29 04:46:19 +0000 |
commit | 3a44c7e55df3cadfddefda988450fe8e5fe5169e (patch) | |
tree | 5455774de0b048fd5f072490f00b88f4642bc75f /llvm/tools/llvm-diff/DifferenceEngine.cpp | |
parent | 029c0f168112ed0949b7aad8e7cfabc8a0d0059b (diff) | |
download | llvm-3a44c7e55df3cadfddefda988450fe8e5fe5169e.zip llvm-3a44c7e55df3cadfddefda988450fe8e5fe5169e.tar.gz llvm-3a44c7e55df3cadfddefda988450fe8e5fe5169e.tar.bz2 |
now that we have CGT around, we can start using preferred types
for return values too. Instead of compiling something like:
struct foo {
int *X;
float *Y;
};
struct foo test(struct foo *P) { return *P; }
to:
%1 = type { i64, i64 }
define %1 @test(%struct.foo* %P) nounwind {
entry:
%retval = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
%P.addr = alloca %struct.foo*, align 8 ; <%struct.foo**> [#uses=2]
store %struct.foo* %P, %struct.foo** %P.addr
%tmp = load %struct.foo** %P.addr ; <%struct.foo*> [#uses=1]
%tmp1 = bitcast %struct.foo* %retval to i8* ; <i8*> [#uses=1]
%tmp2 = bitcast %struct.foo* %tmp to i8* ; <i8*> [#uses=1]
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 16, i32 8, i1 false)
%0 = bitcast %struct.foo* %retval to %1* ; <%1*> [#uses=1]
%1 = load %1* %0, align 1 ; <%1> [#uses=1]
ret %1 %1
}
We now get the result more type safe, with:
define %struct.foo @test(%struct.foo* %P) nounwind {
entry:
%retval = alloca %struct.foo, align 8 ; <%struct.foo*> [#uses=2]
%P.addr = alloca %struct.foo*, align 8 ; <%struct.foo**> [#uses=2]
store %struct.foo* %P, %struct.foo** %P.addr
%tmp = load %struct.foo** %P.addr ; <%struct.foo*> [#uses=1]
%tmp1 = bitcast %struct.foo* %retval to i8* ; <i8*> [#uses=1]
%tmp2 = bitcast %struct.foo* %tmp to i8* ; <i8*> [#uses=1]
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp1, i8* %tmp2, i64 16, i32 8, i1 false)
%0 = load %struct.foo* %retval ; <%struct.foo> [#uses=1]
ret %struct.foo %0
}
That memcpy is completely terrible, but I don't know how to fix it.
llvm-svn: 109729
Diffstat (limited to 'llvm/tools/llvm-diff/DifferenceEngine.cpp')
0 files changed, 0 insertions, 0 deletions