[llvm] [NVPTX] Fix code generation for `trap-unreachable`. (PR #67478)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 28 10:29:46 PDT 2023
================
@@ -99,12 +105,33 @@ char NVPTXLowerUnreachable::ID = 1;
INITIALIZE_PASS(NVPTXLowerUnreachable, "nvptx-lower-unreachable",
"Lower Unreachable", false, false)
+StringRef NVPTXLowerUnreachable::getPassName() const {
+ return "add an exit instruction before every unreachable";
+}
+
+// =============================================================================
+// Returns whether a `trap` intrinsic should be emitted before I.
+//
+// This is a copy of the logic in SelectionDAGBuilder::visitUnreachable().
+// =============================================================================
+bool NVPTXLowerUnreachable::isLoweredToTrap(const UnreachableInst &I) const {
+ if (!TrapUnreachable)
+ return false;
+ if (!NoTrapAfterNoreturn)
+ return true;
+ const CallInst *Call = dyn_cast_or_null<CallInst>(I.getPrevNode());
+ return Call && Call->doesNotReturn();
+}
+
// =============================================================================
// Main function for this pass.
// =============================================================================
bool NVPTXLowerUnreachable::runOnFunction(Function &F) {
if (skipFunction(F))
return false;
+ // Early out iff isLoweredToTrap() always returns true.
+ if (TrapUnreachable && !NoTrapAfterNoreturn)
----------------
Artem-B wrote:
Nit: `!NoTrapAfterNoReturn` has disturbingly high concentration of negations. :-/
Can we rename it into `TrapAfterNoReturn` ?
https://github.com/llvm/llvm-project/pull/67478
More information about the llvm-commits
mailing list