Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow sret on the second parameter as well as the first
MSVC always places the implicit sret parameter after the implicit this parameter of instance methods. We used to handle this for x86_thiscallcc by allocating the sret parameter on the stack and leaving the this pointer in ecx, but that doesn't handle alternative calling conventions like cdecl, stdcall, fastcall, or the win64 convention. Instead, change the verifier to allow sret on the second parameter. This also requires changing the Mips and X86 backends to return the argument with the sret parameter, instead of assuming that the sret parameter comes first. The Sparc backend also returns sret parameters in a register, but I wasn't able to update it to handle secondary sret parameters. It currently calls report_fatal_error if you feed it an sret in the second parameter. Reviewers: rafael.espindola, majnemer Differential Revision: http://reviews.llvm.org/D3617 llvm-svn: 208453
- Loading branch information
Showing
10 changed files
with
138 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
; RUN: llc -march=mips64el -mcpu=mips64r2 -mattr=n64 -O3 < %s | FileCheck %s | ||
; RUN: llc -march=mips64el -mcpu=mips64r2 -mattr=n64 < %s | FileCheck %s | ||
|
||
%struct.S = type { [8 x i32] } | ||
define void @foo(i32* noalias sret %agg.result) nounwind { | ||
entry: | ||
; CHECK-LABEL: foo: | ||
; CHECK: sw {{.*}}, 0($4) | ||
; CHECK: jr $ra | ||
; CHECK-NEXT: move $2, $4 | ||
|
||
@g = common global %struct.S zeroinitializer, align 4 | ||
store i32 42, i32* %agg.result | ||
ret void | ||
} | ||
|
||
define void @f(%struct.S* noalias sret %agg.result) nounwind { | ||
define void @bar(i32 %v, i32* noalias sret %agg.result) nounwind { | ||
entry: | ||
; CHECK: move $2, $4 | ||
; CHECK-LABEL: bar: | ||
; CHECK: sw $4, 0($5) | ||
; CHECK: jr $ra | ||
; CHECK-NEXT: move $2, $5 | ||
|
||
%0 = bitcast %struct.S* %agg.result to i8* | ||
call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* bitcast (%struct.S* @g to i8*), i64 32, i32 4, i1 false) | ||
store i32 %v, i32* %agg.result | ||
ret void | ||
} | ||
|
||
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
; RUN: not llc -march=sparc < %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
; CHECK: sparc only supports sret on the first parameter | ||
|
||
define void @foo(i32 %a, i32* sret %out) { | ||
store i32 %a, i32* %out | ||
ret void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; RUN: not llvm-as %s -o /dev/null 2>&1 | FileCheck %s | ||
|
||
declare void @a(i32* sret %a, i32* sret %b) | ||
; CHECK: Cannot have multiple 'sret' parameters! | ||
|
||
declare void @b(i32* %a, i32* %b, i32* sret %c) | ||
; CHECK: Attribute 'sret' is not on first or second parameter! |