[llvm] [Target] Change `no-trap-after-noreturn` to `trap-after-noreturn` (PR #67925)
Christian Sigg via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 1 09:22:08 PDT 2023
https://github.com/chsigg updated https://github.com/llvm/llvm-project/pull/67925
>From 5fc6397e8d7f4f0eb8621a55b306e93d9a32c61e Mon Sep 17 00:00:00 2001
From: Christian Sigg <csigg at google.com>
Date: Sun, 1 Oct 2023 18:12:04 +0200
Subject: [PATCH 1/2] [Target] Change `no-trap-after-noreturn` to
`trap-after-noreturn`
---
llvm/include/llvm/Target/TargetOptions.h | 4 ++--
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 2 +-
llvm/lib/CodeGen/LLVMTargetMachine.cpp | 8 ++++----
.../CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 2 +-
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp | 2 +-
llvm/lib/Target/ARM/ARMTargetMachine.cpp | 2 +-
llvm/lib/Target/NVPTX/NVPTX.h | 2 +-
llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp | 14 +++++++-------
llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp | 2 +-
llvm/lib/Target/X86/X86TargetMachine.cpp | 2 +-
llvm/test/CodeGen/ARM/trap-unreachable.ll | 2 +-
llvm/test/CodeGen/NVPTX/unreachable.ll | 4 ++++
12 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index d6d767f3d22c73e..60152bcb9501d6e 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -134,7 +134,7 @@ namespace llvm {
FunctionSections(false), DataSections(false),
IgnoreXCOFFVisibility(false), XCOFFTracebackTable(true),
UniqueSectionNames(true), UniqueBasicBlockSectionNames(false),
- TrapUnreachable(false), NoTrapAfterNoreturn(false), TLSSize(0),
+ TrapUnreachable(false), TrapAfterNoreturn(true), TLSSize(0),
EmulatedTLS(false), EnableIPRA(false), EmitStackSizeSection(false),
EnableMachineOutliner(false), EnableMachineFunctionSplitter(false),
SupportsDefaultOutlining(false), EmitAddrsig(false),
@@ -276,7 +276,7 @@ namespace llvm {
/// Do not emit a trap instruction for 'unreachable' IR instructions behind
/// noreturn calls, even if TrapUnreachable is true.
- unsigned NoTrapAfterNoreturn : 1;
+ unsigned TrapAfterNoreturn : 1;
/// Bit size of immediate TLS offsets (0 == use the default).
unsigned TLSSize : 8;
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index 764567ac7baada6..f1a2f9538a58c4d 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2881,7 +2881,7 @@ bool IRTranslator::translateUnreachable(const User &U, MachineIRBuilder &MIRBuil
auto &UI = cast<UnreachableInst>(U);
// We may be able to ignore unreachable behind a noreturn call.
- if (MF->getTarget().Options.NoTrapAfterNoreturn) {
+ if (!MF->getTarget().Options.NoTrapAfterNoreturn) {
const BasicBlock &BB = *UI.getParent();
if (&UI != &BB.front()) {
BasicBlock::const_iterator PredI =
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 87a17b88db12433..0fbc06c6dffe18f 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -37,8 +37,8 @@ static cl::opt<bool>
EnableTrapUnreachable("trap-unreachable", cl::Hidden,
cl::desc("Enable generating trap for unreachable"));
-static cl::opt<bool> EnableNoTrapAfterNoreturn(
- "no-trap-after-noreturn", cl::Hidden,
+static cl::opt<bool> EnableTrapAfterNoreturn(
+ "trap-after-noreturn", cl::Hidden, cl::init(true),
cl::desc("Do not emit a trap instruction for 'unreachable' IR instructions "
"after noreturn calls, even if --trap-unreachable is set."));
@@ -100,8 +100,8 @@ LLVMTargetMachine::LLVMTargetMachine(const Target &T,
if (EnableTrapUnreachable)
this->Options.TrapUnreachable = true;
- if (EnableNoTrapAfterNoreturn)
- this->Options.NoTrapAfterNoreturn = true;
+ if (!EnableTrapAfterNoreturn)
+ this->Options.TrapAfterNoreturn = false;
}
TargetTransformInfo
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index c5fd56795a5201a..920a4d3458bd9ce 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3225,7 +3225,7 @@ void SelectionDAGBuilder::visitUnreachable(const UnreachableInst &I) {
return;
// We may be able to ignore unreachable behind a noreturn call.
- if (DAG.getTarget().Options.NoTrapAfterNoreturn) {
+ if (!DAG.getTarget().Options.TrapAfterNoreturn) {
if (const CallInst *Call = dyn_cast_or_null<CallInst>(I.getPrevNode())) {
if (Call->doesNotReturn())
return;
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index 3d818c76bd4b7d7..4d8db443e5acacf 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -338,7 +338,7 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
if (TT.isOSBinFormatMachO()) {
this->Options.TrapUnreachable = true;
- this->Options.NoTrapAfterNoreturn = true;
+ this->Options.TrapAfterNoreturn = false;
}
if (getMCAsmInfo()->usesWindowsCFI()) {
diff --git a/llvm/lib/Target/ARM/ARMTargetMachine.cpp b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
index a80d485e750beba..8a8b5b5f1846d0f 100644
--- a/llvm/lib/Target/ARM/ARMTargetMachine.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetMachine.cpp
@@ -252,7 +252,7 @@ ARMBaseTargetMachine::ARMBaseTargetMachine(const Target &T, const Triple &TT,
if (TT.isOSBinFormatMachO()) {
this->Options.TrapUnreachable = true;
- this->Options.NoTrapAfterNoreturn = true;
+ this->Options.TrapAfterNoreturn = false;
}
// ARM supports the debug entry values.
diff --git a/llvm/lib/Target/NVPTX/NVPTX.h b/llvm/lib/Target/NVPTX/NVPTX.h
index 8dc68911fff0c05..0b920101699567d 100644
--- a/llvm/lib/Target/NVPTX/NVPTX.h
+++ b/llvm/lib/Target/NVPTX/NVPTX.h
@@ -48,7 +48,7 @@ FunctionPass *createNVPTXImageOptimizerPass();
FunctionPass *createNVPTXLowerArgsPass();
FunctionPass *createNVPTXLowerAllocaPass();
FunctionPass *createNVPTXLowerUnreachablePass(bool TrapUnreachable,
- bool NoTrapAfterNoreturn);
+ bool TrapAfterNoreturn);
MachineFunctionPass *createNVPTXPeephole();
MachineFunctionPass *createNVPTXProxyRegErasurePass();
diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp
index 34f06b548db260d..b52b7562ede9f3c 100644
--- a/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp
@@ -90,13 +90,13 @@ class NVPTXLowerUnreachable : public FunctionPass {
public:
static char ID; // Pass identification, replacement for typeid
- NVPTXLowerUnreachable(bool TrapUnreachable, bool NoTrapAfterNoreturn)
+ NVPTXLowerUnreachable(bool TrapUnreachable, bool TrapAfterNoreturn)
: FunctionPass(ID), TrapUnreachable(TrapUnreachable),
- NoTrapAfterNoreturn(NoTrapAfterNoreturn) {}
+ TrapAfterNoreturn(TrapAfterNoreturn) {}
private:
bool TrapUnreachable;
- bool NoTrapAfterNoreturn;
+ bool TrapAfterNoreturn;
};
} // namespace
@@ -117,7 +117,7 @@ StringRef NVPTXLowerUnreachable::getPassName() const {
bool NVPTXLowerUnreachable::isLoweredToTrap(const UnreachableInst &I) const {
if (!TrapUnreachable)
return false;
- if (!NoTrapAfterNoreturn)
+ if (NoTrapAfterNoreturn)
return true;
const CallInst *Call = dyn_cast_or_null<CallInst>(I.getPrevNode());
return Call && Call->doesNotReturn();
@@ -130,7 +130,7 @@ bool NVPTXLowerUnreachable::runOnFunction(Function &F) {
if (skipFunction(F))
return false;
// Early out iff isLoweredToTrap() always returns true.
- if (TrapUnreachable && !NoTrapAfterNoreturn)
+ if (TrapUnreachable && TrapAfterNoreturn)
return false;
LLVMContext &C = F.getContext();
@@ -151,6 +151,6 @@ bool NVPTXLowerUnreachable::runOnFunction(Function &F) {
}
FunctionPass *llvm::createNVPTXLowerUnreachablePass(bool TrapUnreachable,
- bool NoTrapAfterNoreturn) {
- return new NVPTXLowerUnreachable(TrapUnreachable, NoTrapAfterNoreturn);
+ bool TrapAfterNoreturn) {
+ return new NVPTXLowerUnreachable(TrapUnreachable, TrapAfterNoreturn);
}
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
index 8d895762fbe1d9d..50ba638307bb822 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
@@ -405,7 +405,7 @@ void NVPTXPassConfig::addIRPasses() {
const auto &Options = getNVPTXTargetMachine().Options;
addPass(createNVPTXLowerUnreachablePass(Options.TrapUnreachable,
- Options.NoTrapAfterNoreturn));
+ Options.TrapAfterNoreturn));
}
bool NVPTXPassConfig::addInstSelector() {
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index c0d3b8aa93e6cec..74869d56cd5d693 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -235,7 +235,7 @@ X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT,
// the calling function, and TrapUnreachable is an easy way to get that.
if (TT.isPS() || TT.isOSBinFormatMachO()) {
this->Options.TrapUnreachable = true;
- this->Options.NoTrapAfterNoreturn = TT.isOSBinFormatMachO();
+ this->Options.NoTrapAfterNoreturn = !TT.isOSBinFormatMachO();
}
setMachineOutliner(true);
diff --git a/llvm/test/CodeGen/ARM/trap-unreachable.ll b/llvm/test/CodeGen/ARM/trap-unreachable.ll
index 84dbb04c462b450..b109fe9b01764ce 100644
--- a/llvm/test/CodeGen/ARM/trap-unreachable.ll
+++ b/llvm/test/CodeGen/ARM/trap-unreachable.ll
@@ -1,5 +1,5 @@
; RUN: llc -mtriple=thumbv7 -trap-unreachable < %s | FileCheck %s --check-prefixes CHECK,TRAP_UNREACHABLE
-; RUN: llc -mtriple=thumbv7 -trap-unreachable -no-trap-after-noreturn < %s | FileCheck %s --check-prefixes CHECK,NTANR
+; RUN: llc -mtriple=thumbv7 -trap-unreachable -trap-after-noreturn=false < %s | FileCheck %s --check-prefixes CHECK,NTANR
define void @test_trap_unreachable() #0 {
; CHECK-LABEL: test_trap_unreachable:
diff --git a/llvm/test/CodeGen/NVPTX/unreachable.ll b/llvm/test/CodeGen/NVPTX/unreachable.ll
index 011497c4e23401a..5542f21d7ecee0e 100644
--- a/llvm/test/CodeGen/NVPTX/unreachable.ll
+++ b/llvm/test/CodeGen/NVPTX/unreachable.ll
@@ -6,6 +6,10 @@
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-TRAP
; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs -trap-unreachable \
; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-TRAP
+; RUN: llc < %s -march=nvptx -mcpu=sm_20 -verify-machineinstrs -trap-unreachable -trap-after-noreturn=false \
+; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOTRAP
+; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs -trap-unreachable -trap-after-noreturn=false \
+; RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOTRAP
; RUN: %if ptxas && !ptxas-12.0 %{ llc < %s -march=nvptx -mcpu=sm_20 -verify-machineinstrs | %ptxas-verify %}
; RUN: %if ptxas %{ llc < %s -march=nvptx64 -mcpu=sm_20 -verify-machineinstrs | %ptxas-verify %}
>From 779c6349557f446d2e890b60acae3c325595e268 Mon Sep 17 00:00:00 2001
From: Christian Sigg <csigg at google.com>
Date: Sun, 1 Oct 2023 18:21:48 +0200
Subject: [PATCH 2/2] Rename remaining references to NoTrapAfterNoreturn.
---
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp | 2 +-
llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp | 2 +-
llvm/lib/Target/X86/X86TargetMachine.cpp | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index f1a2f9538a58c4d..8b4e0b532c58fd8 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -2881,7 +2881,7 @@ bool IRTranslator::translateUnreachable(const User &U, MachineIRBuilder &MIRBuil
auto &UI = cast<UnreachableInst>(U);
// We may be able to ignore unreachable behind a noreturn call.
- if (!MF->getTarget().Options.NoTrapAfterNoreturn) {
+ if (!MF->getTarget().Options.TrapAfterNoreturn) {
const BasicBlock &BB = *UI.getParent();
if (&UI != &BB.front()) {
BasicBlock::const_iterator PredI =
diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp
index b52b7562ede9f3c..229b77b3b0904a4 100644
--- a/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp
@@ -117,7 +117,7 @@ StringRef NVPTXLowerUnreachable::getPassName() const {
bool NVPTXLowerUnreachable::isLoweredToTrap(const UnreachableInst &I) const {
if (!TrapUnreachable)
return false;
- if (NoTrapAfterNoreturn)
+ if (TrapAfterNoreturn)
return true;
const CallInst *Call = dyn_cast_or_null<CallInst>(I.getPrevNode());
return Call && Call->doesNotReturn();
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index 74869d56cd5d693..b5582a3b049c992 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -235,7 +235,7 @@ X86TargetMachine::X86TargetMachine(const Target &T, const Triple &TT,
// the calling function, and TrapUnreachable is an easy way to get that.
if (TT.isPS() || TT.isOSBinFormatMachO()) {
this->Options.TrapUnreachable = true;
- this->Options.NoTrapAfterNoreturn = !TT.isOSBinFormatMachO();
+ this->Options.TrapAfterNoreturn = !TT.isOSBinFormatMachO();
}
setMachineOutliner(true);
More information about the llvm-commits
mailing list