summaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp')
-rw-r--r--contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp57
1 files changed, 18 insertions, 39 deletions
diff --git a/contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index f0b6a3e35dba..e9cb7c10113b 100644
--- a/contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/contrib/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
///
/// \file
-/// \brief This file lowers exception-related instructions and setjmp/longjmp
+/// This file lowers exception-related instructions and setjmp/longjmp
/// function calls in order to use Emscripten's JavaScript try and catch
/// mechanism.
///
@@ -225,13 +225,8 @@ static cl::list<std::string>
namespace {
class WebAssemblyLowerEmscriptenEHSjLj final : public ModulePass {
- static const char *ThrewGVName;
- static const char *ThrewValueGVName;
- static const char *TempRet0GVName;
static const char *ResumeFName;
static const char *EHTypeIDFName;
- static const char *SetThrewFName;
- static const char *SetTempRet0FName;
static const char *EmLongjmpFName;
static const char *EmLongjmpJmpbufFName;
static const char *SaveSetjmpFName;
@@ -300,14 +295,9 @@ public:
};
} // End anonymous namespace
-const char *WebAssemblyLowerEmscriptenEHSjLj::ThrewGVName = "__THREW__";
-const char *WebAssemblyLowerEmscriptenEHSjLj::ThrewValueGVName = "__threwValue";
-const char *WebAssemblyLowerEmscriptenEHSjLj::TempRet0GVName = "__tempRet0";
const char *WebAssemblyLowerEmscriptenEHSjLj::ResumeFName = "__resumeException";
const char *WebAssemblyLowerEmscriptenEHSjLj::EHTypeIDFName =
"llvm_eh_typeid_for";
-const char *WebAssemblyLowerEmscriptenEHSjLj::SetThrewFName = "setThrew";
-const char *WebAssemblyLowerEmscriptenEHSjLj::SetTempRet0FName = "setTempRet0";
const char *WebAssemblyLowerEmscriptenEHSjLj::EmLongjmpFName =
"emscripten_longjmp";
const char *WebAssemblyLowerEmscriptenEHSjLj::EmLongjmpJmpbufFName =
@@ -343,15 +333,13 @@ static bool canThrow(const Value *V) {
return true;
}
-// Returns an available name for a global value.
-// If the proposed name already exists in the module, adds '_' at the end of
-// the name until the name is available.
-static inline std::string createGlobalValueName(const Module &M,
- const std::string &Propose) {
- std::string Name = Propose;
- while (M.getNamedGlobal(Name))
- Name += "_";
- return Name;
+static GlobalVariable *createGlobalVariableI32(Module &M, IRBuilder<> &IRB,
+ const char *Name) {
+ if (M.getNamedGlobal(Name))
+ report_fatal_error(Twine("variable name is reserved: ") + Name);
+
+ return new GlobalVariable(M, IRB.getInt32Ty(), false,
+ GlobalValue::WeakODRLinkage, IRB.getInt32(0), Name);
}
// Simple function name mangler.
@@ -613,11 +601,13 @@ void WebAssemblyLowerEmscriptenEHSjLj::createSetThrewFunction(Module &M) {
LLVMContext &C = M.getContext();
IRBuilder<> IRB(C);
- assert(!M.getNamedGlobal(SetThrewFName) && "setThrew already exists");
+ if (M.getNamedGlobal("setThrew"))
+ report_fatal_error("setThrew already exists");
+
Type *Params[] = {IRB.getInt32Ty(), IRB.getInt32Ty()};
FunctionType *FTy = FunctionType::get(IRB.getVoidTy(), Params, false);
Function *F =
- Function::Create(FTy, GlobalValue::ExternalLinkage, SetThrewFName, &M);
+ Function::Create(FTy, GlobalValue::WeakODRLinkage, "setThrew", &M);
Argument *Arg1 = &*(F->arg_begin());
Argument *Arg2 = &*std::next(F->arg_begin());
Arg1->setName("threw");
@@ -648,11 +638,12 @@ void WebAssemblyLowerEmscriptenEHSjLj::createSetTempRet0Function(Module &M) {
LLVMContext &C = M.getContext();
IRBuilder<> IRB(C);
- assert(!M.getNamedGlobal(SetTempRet0FName) && "setTempRet0 already exists");
+ if (M.getNamedGlobal("setTempRet0"))
+ report_fatal_error("setTempRet0 already exists");
Type *Params[] = {IRB.getInt32Ty()};
FunctionType *FTy = FunctionType::get(IRB.getVoidTy(), Params, false);
Function *F =
- Function::Create(FTy, GlobalValue::ExternalLinkage, SetTempRet0FName, &M);
+ Function::Create(FTy, GlobalValue::WeakODRLinkage, "setTempRet0", &M);
F->arg_begin()->setName("value");
BasicBlock *EntryBB = BasicBlock::Create(C, "entry", F);
IRB.SetInsertPoint(EntryBB);
@@ -699,15 +690,9 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
// Create global variables __THREW__, threwValue, and __tempRet0, which are
// used in common for both exception handling and setjmp/longjmp handling
- ThrewGV = new GlobalVariable(M, IRB.getInt32Ty(), false,
- GlobalValue::ExternalLinkage, IRB.getInt32(0),
- createGlobalValueName(M, ThrewGVName));
- ThrewValueGV = new GlobalVariable(
- M, IRB.getInt32Ty(), false, GlobalValue::ExternalLinkage, IRB.getInt32(0),
- createGlobalValueName(M, ThrewValueGVName));
- TempRet0GV = new GlobalVariable(M, IRB.getInt32Ty(), false,
- GlobalValue::ExternalLinkage, IRB.getInt32(0),
- createGlobalValueName(M, TempRet0GVName));
+ ThrewGV = createGlobalVariableI32(M, IRB, "__THREW__");
+ ThrewValueGV = createGlobalVariableI32(M, IRB, "__threwValue");
+ TempRet0GV = createGlobalVariableI32(M, IRB, "__tempRet0");
bool Changed = false;
@@ -736,12 +721,6 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
if (DoSjLj) {
Changed = true; // We have setjmp or longjmp somewhere
- Function *MallocF = M.getFunction("malloc");
- Function *FreeF = M.getFunction("free");
- if (!MallocF || !FreeF)
- report_fatal_error(
- "malloc and free must be linked into the module if setjmp is used");
-
// Register saveSetjmp function
FunctionType *SetjmpFTy = SetjmpF->getFunctionType();
SmallVector<Type *, 4> Params = {SetjmpFTy->getParamType(0),