-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AMDGPU] Handled G_UBSANTRAP GlobalIsel #134492
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
515510f
b92d165
626119a
3445c01
7835b11
8322f92
3e4b6dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2103,7 +2103,7 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_, | |
| getActionDefinitionsBuilder({G_MEMCPY, G_MEMCPY_INLINE, G_MEMMOVE, G_MEMSET}) | ||
| .lower(); | ||
|
|
||
| getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP}).custom(); | ||
| getActionDefinitionsBuilder({G_TRAP, G_DEBUGTRAP, G_UBSANTRAP}).custom(); | ||
|
|
||
| getActionDefinitionsBuilder({G_VASTART, G_VAARG, G_BRJT, G_JUMP_TABLE, | ||
| G_INDEXED_LOAD, G_INDEXED_SEXTLOAD, | ||
|
|
@@ -2221,7 +2221,9 @@ bool AMDGPULegalizerInfo::legalizeCustom( | |
| case TargetOpcode::G_TRAP: | ||
| return legalizeTrap(MI, MRI, B); | ||
| case TargetOpcode::G_DEBUGTRAP: | ||
| return legalizeDebugTrap(MI, MRI, B); | ||
| return legalizeDebugUbsanTrap(MI, MRI, B, TargetOpcode::G_DEBUGTRAP); | ||
| case TargetOpcode::G_UBSANTRAP: | ||
| return legalizeDebugUbsanTrap(MI, MRI, B, TargetOpcode::G_UBSANTRAP); | ||
| default: | ||
| return false; | ||
| } | ||
|
|
@@ -7023,22 +7025,25 @@ bool AMDGPULegalizerInfo::legalizeTrapHsa(MachineInstr &MI, | |
| return true; | ||
| } | ||
|
|
||
| bool AMDGPULegalizerInfo::legalizeDebugTrap(MachineInstr &MI, | ||
| bool AMDGPULegalizerInfo::legalizeDebugUbsanTrap(MachineInstr &MI, | ||
| MachineRegisterInfo &MRI, | ||
| MachineIRBuilder &B) const { | ||
| MachineIRBuilder &B, unsigned int Opcode) const { | ||
| // Is non-HSA path or trap-handler disabled? Then, report a warning | ||
| // accordingly | ||
| if (!ST.isTrapHandlerEnabled() || | ||
| ST.getTrapHandlerAbi() != GCNSubtarget::TrapHandlerAbi::AMDHSA) { | ||
| DiagnosticInfoUnsupported NoTrap(B.getMF().getFunction(), | ||
| "debugtrap handler not supported", | ||
| "debugtrap/ubsantrap handler not supported", | ||
|
||
| MI.getDebugLoc(), DS_Warning); | ||
| LLVMContext &Ctx = B.getMF().getFunction().getContext(); | ||
| Ctx.diagnose(NoTrap); | ||
| } else { | ||
| } else if (Opcode == TargetOpcode::G_DEBUGTRAP){ | ||
| // Insert debug-trap instruction | ||
| B.buildInstr(AMDGPU::S_TRAP) | ||
| .addImm(static_cast<unsigned>(GCNSubtarget::TrapID::LLVMAMDHSADebugTrap)); | ||
| } else if (Opcode == TargetOpcode::G_UBSANTRAP){ | ||
| B.buildInstr(AMDGPU::S_TRAP) | ||
| .addImm(static_cast<unsigned>(GCNSubtarget::TrapID::LLVMAMDHSATrap)); | ||
| } | ||
|
|
||
| MI.eraseFromParent(); | ||
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,29 +5,31 @@ | |
| ; RUN: llc -global-isel=1 -mtriple=amdgcn--amdhsa -mattr=+trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=HSA-TRAP %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn--amdhsa -mattr=-trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=NO-HSA-TRAP %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn--amdhsa -mattr=-trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=NO-HSA-TRAP %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn--amdhsa -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn--amdhsa -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn--amdhsa -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-1 %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn--amdhsa -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-2 %s | ||
|
|
||
| ; enable trap handler feature | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn-unknown-mesa3d -mattr=+trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=NO-MESA-TRAP -check-prefix=TRAP-BIT -check-prefix=MESA-TRAP %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn-unknown-mesa3d -mattr=+trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=NO-MESA-TRAP -check-prefix=TRAP-BIT -check-prefix=MESA-TRAP %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn-unknown-mesa3d -mattr=+trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING -check-prefix=TRAP-BIT %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn-unknown-mesa3d -mattr=+trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING -check-prefix=TRAP-BIT %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn-unknown-mesa3d -mattr=+trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-1 -check-prefix=TRAP-BIT %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn-unknown-mesa3d -mattr=+trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-2 -check-prefix=TRAP-BIT %s | ||
|
|
||
| ; disable trap handler feature | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn-unknown-mesa3d -mattr=-trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=NO-MESA-TRAP -check-prefix=NO-TRAP-BIT -check-prefix=NOMESA-TRAP %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn-unknown-mesa3d -mattr=-trap-handler -verify-machineinstrs < %s | FileCheck -check-prefix=GCN -check-prefix=NO-MESA-TRAP -check-prefix=NO-TRAP-BIT -check-prefix=NOMESA-TRAP %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn-unknown-mesa3d -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING -check-prefix=NO-TRAP-BIT %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn-unknown-mesa3d -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING -check-prefix=NO-TRAP-BIT %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn-unknown-mesa3d -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-1 -check-prefix=NO-TRAP-BIT %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn-unknown-mesa3d -mattr=-trap-handler -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-2 -check-prefix=NO-TRAP-BIT %s | ||
|
|
||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING %s | ||
| ; RUN: llc -global-isel=0 -mtriple=amdgcn -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-1 %s | ||
| ; RUN: llc -global-isel=1 -mtriple=amdgcn -verify-machineinstrs < %s 2>&1 | FileCheck -check-prefix=GCN -check-prefix=GCN-WARNING-2 %s | ||
|
|
||
| ; GCN-WARNING: warning: <unknown>:0:0: in function hsa_debugtrap void (ptr addrspace(1)): debugtrap handler not supported | ||
| ; GCN-WARNING-1: warning: <unknown>:0:0: in function hsa_debugtrap void (ptr addrspace(1)): debugtrap handler not supported | ||
| ; GCN-WARNING-2: warning: <unknown>:0:0: in function hsa_debugtrap void (ptr addrspace(1)): debugtrap/ubsantrap handler not supported | ||
|
||
|
|
||
|
|
||
| declare void @llvm.trap() #0 | ||
| declare void @llvm.debugtrap() #1 | ||
| declare void @llvm.ubsantrap(i8) #2 | ||
|
|
||
| ; MESA-TRAP: .section .AMDGPU.config | ||
| ; MESA-TRAP: .long 47180 | ||
|
|
@@ -83,6 +85,13 @@ define amdgpu_kernel void @hsa_debugtrap(ptr addrspace(1) nocapture readonly %ar | |
| ret void | ||
| } | ||
|
|
||
| ;define amdgpu_kernel void @ubsantrap(ptr addrspace(1) nocapture readonly %arg0) { | ||
| ; store volatile i32 1, ptr addrspace(1) %arg0 | ||
| ; call void @llvm.ubsantrap(i8 0) | ||
| ; store volatile i32 2, ptr addrspace(1) %arg0 | ||
| ; ret void | ||
| ;} | ||
|
||
|
|
||
| ; For non-HSA path | ||
| ; GCN-LABEL: {{^}}trap: | ||
| ; TRAP-BIT: enable_trap_handler = 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should add the default lower() action to LegalizerHelper for G_DEBUGTRAP and G_UBSANTRAP, which just replace the opcode with G_TRAP (this is what LegalizeDAG does as the default action)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So should we replace the custom() call to lower() or add lower() as a fallback option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly. G_TRAP would still be custom, G_DEBUGTRAP and G_UBSANTRAP would lower. The default lowering would just replace those with regular G_TRAP