forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reapply: [IRGen] Emit lifetime intrinsics around temporary aggregate …
…argument allocas This reverts commit e26c24b. These temporaries are only used in the callee, and their memory can be reused after the call is complete. rdar://58552124 Link: llvm#38157 Link: llvm#41896 Link: llvm#43598 Link: ClangBuiltLinux/linux#39 Link: https://reviews.llvm.org/rGfafc6e4fdf3673dcf557d6c8ae0c0a4bb3184402 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D74094
- Loading branch information
Showing
6 changed files
with
149 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// RUN: %clang -cc1 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime | ||
// RUN: %clang -cc1 -xc++ -std=c++17 -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - -Wno-return-type-c-linkage | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=CXX | ||
// RUN: %clang -cc1 -xobjective-c -triple x86_64-apple-macos -O1 -disable-llvm-passes %s -S -emit-llvm -o - | FileCheck %s --implicit-check-not=llvm.lifetime --check-prefix=CHECK --check-prefix=OBJC | ||
|
||
typedef struct { int x[100]; } aggregate; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
void takes_aggregate(aggregate); | ||
aggregate gives_aggregate(); | ||
|
||
// CHECK-LABEL: define void @t1 | ||
void t1() { | ||
takes_aggregate(gives_aggregate()); | ||
|
||
// CHECK: [[AGGTMP:%.*]] = alloca %struct.aggregate, align 8 | ||
// CHECK: call void @llvm.lifetime.start.p0(i64 400, ptr [[AGGTMP]]) | ||
// CHECK: call void{{.*}} @gives_aggregate(ptr sret(%struct.aggregate) align 4 [[AGGTMP]]) | ||
// CHECK: call void @takes_aggregate(ptr noundef byval(%struct.aggregate) align 8 [[AGGTMP]]) | ||
// CHECK: call void @llvm.lifetime.end.p0(i64 400, ptr [[AGGTMP]]) | ||
} | ||
|
||
// CHECK: declare {{.*}}llvm.lifetime.start | ||
// CHECK: declare {{.*}}llvm.lifetime.end | ||
|
||
#ifdef __cplusplus | ||
// CXX: define void @t2 | ||
void t2() { | ||
struct S { | ||
S(aggregate) {} | ||
}; | ||
S{gives_aggregate()}; | ||
|
||
// CXX: [[AGG:%.*]] = alloca %struct.aggregate | ||
// CXX: call void @llvm.lifetime.start.p0(i64 400, ptr | ||
// CXX: call void @gives_aggregate(ptr sret(%struct.aggregate) align 4 [[AGG]]) | ||
// CXX: call void @_ZZ2t2EN1SC1E9aggregate(ptr {{.*}}, ptr {{.*}} byval(%struct.aggregate) align 8 [[AGG]]) | ||
// CXX: call void @llvm.lifetime.end.p0(i64 400, ptr | ||
} | ||
|
||
struct Dtor { | ||
~Dtor(); | ||
}; | ||
|
||
void takes_dtor(Dtor); | ||
Dtor gives_dtor(); | ||
|
||
// CXX: define void @t3 | ||
void t3() { | ||
takes_dtor(gives_dtor()); | ||
|
||
// CXX-NOT @llvm.lifetime | ||
// CXX: ret void | ||
} | ||
|
||
#endif | ||
|
||
#ifdef __OBJC__ | ||
|
||
@interface X | ||
-m:(aggregate)x; | ||
@end | ||
|
||
// OBJC: define void @t4 | ||
void t4(X *x) { | ||
[x m: gives_aggregate()]; | ||
|
||
// OBJC: [[AGG:%.*]] = alloca %struct.aggregate | ||
// OBJC: call void @llvm.lifetime.start.p0(i64 400, ptr | ||
// OBJC: call void{{.*}} @gives_aggregate(ptr sret(%struct.aggregate) align 4 [[AGGTMP]]) | ||
// OBJC: call {{.*}}@objc_msgSend | ||
// OBJC: call void @llvm.lifetime.end.p0(i64 400, ptr | ||
} | ||
|
||
#endif | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
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,19 @@ | ||
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -emit-llvm -O3 -disable-llvm-passes -o - %s | FileCheck %s | ||
|
||
struct A { | ||
float x, y, z, w; | ||
}; | ||
|
||
void foo(A a); | ||
|
||
// CHECK-LABEL: @_Z4testv | ||
// CHECK: [[A:%.*]] = alloca [[STRUCT_A:%.*]], align 4, addrspace(5) | ||
// CHECK-NEXT: [[AGG_TMP:%.*]] = alloca [[STRUCT_A]], align 4, addrspace(5) | ||
// CHECK-NEXT: [[A_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[A]] to ptr | ||
// CHECK-NEXT: [[AGG_TMP_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[AGG_TMP]] to ptr | ||
// CHECK-NEXT: call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) [[A]]) #[[ATTR4:[0-9]+]] | ||
// CHECK-NEXT: call void @llvm.lifetime.start.p5(i64 16, ptr addrspace(5) [[AGG_TMP]]) #[[ATTR4]] | ||
void test() { | ||
A a; | ||
foo(a); | ||
} |
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