Repository navigation
[CodeGen][WebAssembly] Reserve a personality for the D language - #224883
Conversation
|
@llvm/pr-subscribers-llvm-transforms @llvm/pr-subscribers-llvm-ir Author: Demetrius Kanios (QuantumSegfault) ChangesNow that #209282 is merged, languages/code may choose to create and use personality functions other than This reserves a 7 Files Affected:
diff --git a/llvm/include/llvm/IR/EHPersonalities.h b/llvm/include/llvm/IR/EHPersonalities.h
index 39f6817b3dc38..9715f63eb6491 100644
--- a/llvm/include/llvm/IR/EHPersonalities.h
+++ b/llvm/include/llvm/IR/EHPersonalities.h
@@ -35,6 +35,7 @@ enum class EHPersonality {
Wasm_CXX,
XL_CXX,
ZOS_CXX,
+ Wasm_D
};
/// See if the given exception handling personality function is one
@@ -85,6 +86,7 @@ inline bool isScopedEHPersonality(EHPersonality Pers) {
case EHPersonality::MSVC_TableSEH:
case EHPersonality::CoreCLR:
case EHPersonality::Wasm_CXX:
+ case EHPersonality::Wasm_D:
return true;
default:
return false;
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index f4d46e3cad48d..e6c0e9fe6fb7f 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -3748,9 +3748,10 @@ bool IRTranslatorImpl::findUnwindDestinations(
bool IsMSVCCXX = Personality == EHPersonality::MSVC_CXX;
bool IsCoreCLR = Personality == EHPersonality::CoreCLR;
bool IsWasmCXX = Personality == EHPersonality::Wasm_CXX;
+ bool IsWasmD = Personality == EHPersonality::Wasm_D;
bool IsSEH = isAsynchronousEHPersonality(Personality);
- if (IsWasmCXX) {
+ if (IsWasmCXX || IsWasmD) {
// Ignore this for now.
return false;
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
index 6ca0592644a08..30e84d321a2b3 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
@@ -28,6 +28,7 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/EHPersonalities.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -264,7 +265,8 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
continue;
}
if (isa<FuncletPadInst>(PadInst) &&
- Personality != EHPersonality::Wasm_CXX)
+ Personality != EHPersonality::Wasm_CXX &&
+ Personality != EHPersonality::Wasm_D)
assert(BB.begin() == PadInst && "WinEHPrepare failed to demote PHIs");
}
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 794a4e6e1b537..71bfcb2549fd6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -2118,7 +2118,7 @@ void SelectionDAGBuilder::visitCleanupPad(const CleanupPadInst &CPI) {
// the start of an EH scope/funclet.
FuncInfo.MBB->setIsEHScopeEntry();
auto Pers = classifyEHPersonality(FuncInfo.Fn->getPersonalityFn());
- if (Pers != EHPersonality::Wasm_CXX) {
+ if (Pers != EHPersonality::Wasm_CXX && Pers != EHPersonality::Wasm_D) {
FuncInfo.MBB->setIsEHFuncletEntry();
FuncInfo.MBB->setIsCleanupFuncletEntry();
}
@@ -2142,6 +2142,7 @@ static void findUnwindDestinations(
bool IsMSVCCXX = Personality == EHPersonality::MSVC_CXX;
bool IsCoreCLR = Personality == EHPersonality::CoreCLR;
bool IsWasmCXX = Personality == EHPersonality::Wasm_CXX;
+ bool IsWasmD = Personality == EHPersonality::Wasm_D;
bool IsSEH = isAsynchronousEHPersonality(Personality);
while (EHPadBB) {
@@ -2158,7 +2159,7 @@ static void findUnwindDestinations(
UnwindDests.emplace_back(FuncInfo.getMBB(EHPadBB), Prob);
UnwindDests.back().first->setIsEHScopeEntry();
// In Wasm, EH scopes are not funclets
- if (!IsWasmCXX)
+ if (!IsWasmCXX && !IsWasmD)
UnwindDests.back().first->setIsEHFuncletEntry();
break;
} else if (const auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Pad)) {
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 6233cf8d0d668..9ac061cbefc9c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -1475,7 +1475,7 @@ bool SelectionDAGISel::PrepareEHLandingPad() {
if (auto *RegMask = TRI.getCustomEHPadPreservedMask(*MF))
MF->getRegInfo().addPhysRegsUsedFromRegMask(RegMask);
- if (Pers == EHPersonality::Wasm_CXX) {
+ if (Pers == EHPersonality::Wasm_CXX || Pers == EHPersonality::Wasm_D) {
if (const auto *CPI = dyn_cast<CatchPadInst>(LLVMBB->getFirstNonPHIIt()))
mapWasmLandingPadIndex(MBB, CPI);
} else {
diff --git a/llvm/lib/IR/EHPersonalities.cpp b/llvm/lib/IR/EHPersonalities.cpp
index 12ae4748e1f4a..a7d0740dc8533 100644
--- a/llvm/lib/IR/EHPersonalities.cpp
+++ b/llvm/lib/IR/EHPersonalities.cpp
@@ -52,6 +52,7 @@ EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
.Case("__gxx_wasm_personality_v0", EHPersonality::Wasm_CXX)
.Case("__xlcxx_personality_v1", EHPersonality::XL_CXX)
.Case("__zos_cxx_personality_v2", EHPersonality::ZOS_CXX)
+ .Case("_d_eh_personality_wasm", EHPersonality::Wasm_D)
.Default(EHPersonality::Unknown);
}
@@ -86,6 +87,8 @@ StringRef llvm::getEHPersonalityName(EHPersonality Pers) {
return "__xlcxx_personality_v1";
case EHPersonality::ZOS_CXX:
return "__zos_cxx_personality_v2";
+ case EHPersonality::Wasm_D:
+ return "_d_eh_personality_wasm";
case EHPersonality::Unknown:
llvm_unreachable("Unknown EHPersonality!");
}
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 4b09510933d0c..180b10fe08270 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4868,6 +4868,7 @@ static bool isCatchAll(EHPersonality Personality, Constant *TypeInfo) {
case EHPersonality::Wasm_CXX:
case EHPersonality::XL_CXX:
case EHPersonality::ZOS_CXX:
+ case EHPersonality::Wasm_D:
return isa<ConstantPointerNull>(TypeInfo);
}
llvm_unreachable("invalid enum");
|
|
If you have any opinions on the symbol name. I chose |
|
I guess this is fine given how things are currently implemented. Though we should really avoid the need for this hardcoded list of personalities and encode the properties of the personality in IR, so that frontends can use custom personality functions without having to teach LLVM about them. Some options here would be either a first class way to declare personalities, or to have an attribute on the personality function declaration. (See e.g. how we switched allocator optimizations to be encoded via attributes instead of adding Rust's allocator functions to the hardcoded list in LLVM.) |
aheejin
left a comment
There was a problem hiding this comment.
Maybe it's nice to have something like isWasmFunctionality in EHPersonalities.h given that the pattern is repeated many times, but not sure what others would feel about adding a target-specific function in there.. Anyway, this LGTM, but if we ever get to add more Wasm personalities, maybe it'd be good to think that or what @nikic said
|
Yeah, I agree. Eventually we should probably find a way to decentralize the entire personality system. However that's out of scope for this immediate change. And if we get anybody else wanting more personalities before this proposed rework, we can refactor as |
|
Ping. Any opinions on this? (name particularly) |
|
All good from my side. |
…#224883) Now that llvm#209282 is merged, languages/code may choose to create and use personality functions other than `__gxx_wasm_personality_v0` on WebAssembly. However said personality must still be `isScopedEHPersonality` and recognized as a Wasm personality for everything to function correctly. This reserves a `EHPersonality::Wasm_D` (symbol `_d_eh_personality_wasm`) for future use by the D programming language.
Now that #209282 is merged, languages/code may choose to create and use personality functions other than
__gxx_wasm_personality_v0on WebAssembly. However said personality must still beisScopedEHPersonalityand recognized as a Wasm personality for everything to function correctly.This reserves a
EHPersonality::Wasm_D(symbol_d_eh_personality_wasm) for future use by the D programming language.