-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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 1 commit
515510f
b92d165
626119a
3445c01
7835b11
8322f92
3e4b6dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
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, | ||
|
@@ -2222,6 +2222,8 @@ bool AMDGPULegalizerInfo::legalizeCustom( | |
return legalizeTrap(MI, MRI, B); | ||
case TargetOpcode::G_DEBUGTRAP: | ||
return legalizeDebugTrap(MI, MRI, B); | ||
case TargetOpcode::G_UBSANTRAP: | ||
return legalizeUbsanTrap(MI, MRI, B); | ||
default: | ||
return false; | ||
} | ||
|
@@ -7045,6 +7047,29 @@ bool AMDGPULegalizerInfo::legalizeDebugTrap(MachineInstr &MI, | |
return true; | ||
} | ||
|
||
|
||
bool AMDGPULegalizerInfo::legalizeUbsanTrap(MachineInstr &MI, | ||
MachineRegisterInfo &MRI, | ||
MachineIRBuilder &B) const { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code is identical to legalizeDebugTrap above, they should just use the same implementation function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The trap ID differs in these functions. Is it still required to merge the definitions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you can just rename that function above to "legalizeDebugUbsanTrap" and select the TrapID based on the opcode. The warning can also just say "debugtrap/ubsantrap handler not supported". |
||
// 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(), | ||
"ubsantrap handler not supported", | ||
MI.getDebugLoc(), DS_Warning); | ||
LLVMContext &Ctx = B.getMF().getFunction().getContext(); | ||
tgymnich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Ctx.diagnose(NoTrap); | ||
} else { | ||
// Insert trap instruction | ||
B.buildInstr(AMDGPU::S_TRAP) | ||
.addImm(static_cast<unsigned>(GCNSubtarget::TrapID::LLVMAMDHSATrap)); | ||
} | ||
|
||
MI.eraseFromParent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want it to be removed even trap handler is disabled? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has to be modified or erased otherwise it will be a legalization loop |
||
return true; | ||
} | ||
|
||
bool AMDGPULegalizerInfo::legalizeBVHIntersectRayIntrinsic( | ||
MachineInstr &MI, MachineIRBuilder &B) const { | ||
MachineRegisterInfo &MRI = *B.getMRI(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
; RUN: llc -mtriple=amdgcn-amd-amdhsa -global-isel < %s | ||
; LLVM ERROR: cannot select: G_UBSANTRAP 0 (in function: ubsan_trap) | ||
|
||
define void @ubsan_trap() { | ||
call void @llvm.ubsantrap(i8 0) | ||
ret void | ||
} | ||
tgymnich marked this conversation as resolved.
Show resolved
Hide resolved
|
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?