Skip to content

[NVPTX] Add builtin for 'exit' handling #79777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/include/clang/Basic/BuiltinsNVPTX.def
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ BUILTIN(__nvvm_read_ptx_sreg_pm3, "i", "n")
// MISC

BUILTIN(__nvvm_prmt, "UiUiUiUi", "")
BUILTIN(__nvvm_exit, "v", "r")
TARGET_BUILTIN(__nvvm_nanosleep, "vi", "n", AND(SM_70, PTX63))

// Min Max
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGen/builtins-nvptx.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ __device__ void activemask() {

}

__device__ void exit() {

// CHECK: call void @llvm.nvvm.exit()

__nvvm_exit();

}

// NVVM intrinsics

Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/IR/IntrinsicsNVVM.td
Original file line number Diff line number Diff line change
Expand Up @@ -4813,4 +4813,8 @@ def int_nvvm_setmaxnreg_dec_sync_aligned_u32
[IntrConvergent, IntrNoMem, IntrHasSideEffects, ImmArg<ArgIndex<0>>],
"llvm.nvvm.setmaxnreg.dec.sync.aligned.u32">;

// Exit
def int_nvvm_exit : ClangBuiltin<"__nvvm_exit">,
Intrinsic<[], [], [IntrConvergent, IntrInaccessibleMemOnly, IntrNoReturn]>;

} // let TargetPrefix = "nvvm"
3 changes: 3 additions & 0 deletions llvm/lib/Target/NVPTX/NVPTXIntrinsics.td
Original file line number Diff line number Diff line change
Expand Up @@ -6844,4 +6844,7 @@ multiclass SET_MAXNREG<string Action, Intrinsic Intr> {

defm INT_SET_MAXNREG_INC : SET_MAXNREG<"inc", int_nvvm_setmaxnreg_inc_sync_aligned_u32>;
defm INT_SET_MAXNREG_DEC : SET_MAXNREG<"dec", int_nvvm_setmaxnreg_dec_sync_aligned_u32>;

} // isConvergent

def INT_EXIT : NVPTXInst<(outs), (ins), "exit;", [(int_nvvm_exit)]>;
8 changes: 8 additions & 0 deletions llvm/test/CodeGen/NVPTX/intrinsics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ define i64 @test_clock64() {
ret i64 %ret
}

; CHECK-LABEL: test_exit
define void @test_exit() {
; CHECK: exit;
call void @llvm.nvvm.exit()
ret void
}

declare float @llvm.fabs.f32(float)
declare double @llvm.fabs.f64(double)
declare float @llvm.nvvm.sqrt.f(float)
Expand All @@ -146,3 +153,4 @@ declare i64 @llvm.ctpop.i64(i64)
declare i32 @llvm.nvvm.read.ptx.sreg.tid.x()
declare i32 @llvm.nvvm.read.ptx.sreg.clock()
declare i64 @llvm.nvvm.read.ptx.sreg.clock64()
declare void @llvm.nvvm.exit()