File tree Expand file tree Collapse file tree 5 files changed +47
-1
lines changed
Expand file tree Collapse file tree 5 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -176,6 +176,15 @@ fn create_wrapper_function(
176176 None
177177 } ;
178178
179+ if tcx. sess . target . is_like_gpu {
180+ // Conservatively apply convergent to all functions
181+ attributes:: apply_to_llfn (
182+ llfn,
183+ llvm:: AttributePlace :: Function ,
184+ & [ llvm:: AttributeKind :: Convergent . create_attr ( cx. llcx ) ] ,
185+ ) ;
186+ }
187+
179188 let llbb = unsafe { llvm:: LLVMAppendBasicBlockInContext ( cx. llcx , llfn, c"entry" . as_ptr ( ) ) } ;
180189 let mut bx = SBuilder :: build ( & cx, llbb) ;
181190
Original file line number Diff line number Diff line change 1414use std:: borrow:: Borrow ;
1515
1616use itertools:: Itertools ;
17- use rustc_codegen_ssa:: traits:: TypeMembershipCodegenMethods ;
17+ use rustc_codegen_ssa:: traits:: { MiscCodegenMethods , TypeMembershipCodegenMethods } ;
1818use rustc_data_structures:: fx:: FxIndexSet ;
1919use rustc_middle:: ty:: { Instance , Ty } ;
2020use rustc_sanitizers:: { cfi, kcfi} ;
@@ -70,6 +70,11 @@ pub(crate) fn declare_raw_fn<'ll, 'tcx>(
7070
7171 let mut attrs = SmallVec :: < [ _ ; 4 ] > :: new ( ) ;
7272
73+ if cx. sess ( ) . target . is_like_gpu {
74+ // Conservatively apply convergent to all functions
75+ attrs. push ( llvm:: AttributeKind :: Convergent . create_attr ( cx. llcx ) ) ;
76+ }
77+
7378 if cx. tcx . sess . opts . cg . no_redzone . unwrap_or ( cx. tcx . sess . target . disable_redzone ) {
7479 attrs. push ( llvm:: AttributeKind :: NoRedZone . create_attr ( cx. llcx ) ) ;
7580 }
Original file line number Diff line number Diff line change @@ -292,6 +292,7 @@ pub(crate) enum AttributeKind {
292292 CapturesNone = 46 ,
293293 SanitizeRealtimeNonblocking = 47 ,
294294 SanitizeRealtimeBlocking = 48 ,
295+ Convergent = 49 ,
295296}
296297
297298/// LLVMIntPredicate
Original file line number Diff line number Diff line change @@ -328,6 +328,7 @@ enum class LLVMRustAttributeKind {
328328 CapturesNone = 46 ,
329329 SanitizeRealtimeNonblocking = 47 ,
330330 SanitizeRealtimeBlocking = 48 ,
331+ Convergent = 49 ,
331332};
332333
333334static Attribute::AttrKind fromRust (LLVMRustAttributeKind Kind) {
@@ -428,6 +429,8 @@ static Attribute::AttrKind fromRust(LLVMRustAttributeKind Kind) {
428429 return Attribute::SanitizeRealtime;
429430 case LLVMRustAttributeKind::SanitizeRealtimeBlocking:
430431 return Attribute::SanitizeRealtimeBlocking;
432+ case LLVMRustAttributeKind::Convergent:
433+ return Attribute::Convergent;
431434 }
432435 report_fatal_error (" bad LLVMRustAttributeKind" );
433436}
Original file line number Diff line number Diff line change 1+ // Checks that when compiling for GPU targets, the convergent attribute
2+ // is added to function declarations and definitions.
3+
4+ //@ add-minicore
5+ //@ revisions: amdgpu nvptx
6+ //@ [amdgpu] compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900
7+ //@ [amdgpu] needs-llvm-components: amdgpu
8+ //@ [nvptx] compile-flags: --crate-type=rlib --target=nvptx64-nvidia-cuda
9+ //@ [nvptx] needs-llvm-components: nvptx
10+ #![ feature( no_core, lang_items, abi_gpu_kernel) ]
11+ #![ no_core]
12+
13+ extern crate minicore;
14+ use minicore:: * ;
15+
16+ extern "C" {
17+ fn ext ( ) ;
18+ }
19+
20+ // CHECK: define {{.*}}_kernel void @fun(i32{{.*}}) unnamed_addr #[[ATTR:[0-9]+]] {
21+ // CHECK: declare void @ext() unnamed_addr #[[ATTR]]
22+ // CHECK: attributes #[[ATTR]] = {{.*}} convergent
23+ #[ no_mangle]
24+ pub extern "gpu-kernel" fn fun ( _: i32 ) {
25+ unsafe {
26+ ext ( ) ;
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments