Index: docs/AMDGPUUsage.rst =================================================================== --- docs/AMDGPUUsage.rst +++ docs/AMDGPUUsage.rst @@ -33,6 +33,31 @@ The terminology in the table, aside from the region memory space, is from the OpenCL standard. +Trap Handler ABI +---------------- +The OS element of the target triple controls the trap handler behavior. + +HSA OS +^^^^^^ +For the HSA OS, the AMDGPU back-end emits s_trap for llvm.trap/llvm.debugtrap. +Runtime trap handler supports the s_trap instruction with the following codes. +Currently the compiler only generates two of the codes, but the trap handler +ABI nevertheless defines all 4 codes. + + ===================== ============= ============================================ + Name Trap Code Trap Handler Inputs + ===================== ============= ============================================ + TrapCodeBreakPoint 0 Used for debugger breakpoint. If debugger is not installed causes dispatch to be terminated and its associated queue put into the error state. + TrapCodeLLVMTrap 1 Used for llvm.trap..queue_ptr is in SGPR0-1. Causes dispatch to be terminated and its associated queue put into the error state. + TrapCodeLLVMDebugTrap 2 Used for llvm.debugtrap. queue_ptr is in SGPR0-1. If debugger not installed handled same as llvm.trap. + TrapCodeHSADebugTrap 3 Used for HSA DEBUGTRAP. queue_ptr is in SGPR0-1, the user code is in VGPR0. + ===================== ============= ============================================ + +Non-HSA OS +^^^^^^^^^^ +For Graphics, S_ENDPGM is generated for llvm.trap. S_NOP is generated for +llvm.debugtrap together with a warning that there is no trap handler installed. + Assembler ========= @@ -261,47 +286,6 @@ For full list of supported instructions, refer to "Vector ALU instructions". -Trap Handler ABI ----------------- -The Trap Handler suppored is implemented differently based on the host OS. OS -is obtained from the appropriate element of the target triple HSA OS: - -.. code-block:: c++ - - enum TrapHandlerAbi { - TrapHandlerAbiNone = 0, - TrapHandlerAbiHsa = 1 - }; - - TrapHandlerAbi getTrapHandlerAbi() const { - return isAmdHsaOS() ? TrapHandlerAbiHsa : TrapHandlerAbiNone; - } - -For HSA OS, a trap handler is always enabled and that the following S_TRAP immediate -operand codes are supported: - -.. code-block:: c++ - - enum TrapCode { - TrapCodeBreakPoint = 0, - TrapCodeLLVMTrap = 1, - TrapCodeLLVMDebugTrap = 2, - TrapCodeHSADebugTrap = 3 - }; - -- 0: Used for debugger breakpoint. If debugger is not installed causes dispatch - to be terminated and its associated queue put into the error state. -- 1: Used for llvm.trap..queue_ptr is in SGPR0-1. Causes dispatch to be - terminated and its associated queue put into the error state. -- 2: Used for llvm.debugtrap. queue_ptr is in SGPR0-1. If debugger not installed - handled same as llvm.trap. -- 3: Used for HSA DEBUGTRAP. queue_ptr is in SGPR0-1, the user code is in VGPR0. - -Graphics -^^^^^^^^ -For Graphics, S_ENDPGM is generated for llvm.trap. S_NOP is generated for -llvm.debugtrap together with a warning that there is no trap handler installed. - HSA Code Object Directives --------------------------