@@ -440,9 +440,13 @@ static std::string getSignature(FunctionType *FTy) {
440440 return Sig;
441441}
442442
443+ static Function *getFunction (FunctionType *Ty, const Twine &Name, Module *M) {
444+ return Function::Create (Ty, GlobalValue::ExternalLinkage, Name, M);
445+ }
446+
443447static Function *getEmscriptenFunction (FunctionType *Ty, const Twine &Name,
444448 Module *M) {
445- Function* F = Function::Create (Ty, GlobalValue::ExternalLinkage , Name, M);
449+ Function * F = getFunction (Ty, Name, M);
446450 // Tell the linker that this function is expected to be imported from the
447451 // 'env' module.
448452 if (!F->hasFnAttribute (" wasm-import-module" )) {
@@ -927,11 +931,11 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
927931 // exception handling and setjmp/longjmp handling
928932 ThrewGV = getGlobalVariable (M, getAddrIntType (&M), TM, " __THREW__" );
929933 ThrewValueGV = getGlobalVariable (M, IRB.getInt32Ty (), TM, " __threwValue" );
930- GetTempRet0F = getEmscriptenFunction (
931- FunctionType::get (IRB. getInt32Ty (), false ), " getTempRet0" , &M);
932- SetTempRet0F = getEmscriptenFunction (
933- FunctionType::get (IRB.getVoidTy (), IRB.getInt32Ty (), false ),
934- " setTempRet0" , &M);
934+ GetTempRet0F = getFunction ( FunctionType::get (IRB. getInt32Ty (), false ),
935+ " getTempRet0" , &M);
936+ SetTempRet0F =
937+ getFunction ( FunctionType::get (IRB.getVoidTy (), IRB.getInt32Ty (), false ),
938+ " setTempRet0" , &M);
935939 GetTempRet0F->setDoesNotThrow ();
936940 SetTempRet0F->setDoesNotThrow ();
937941
@@ -942,13 +946,13 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
942946 // Register __resumeException function
943947 FunctionType *ResumeFTy =
944948 FunctionType::get (IRB.getVoidTy (), IRB.getPtrTy (), false );
945- ResumeF = getEmscriptenFunction (ResumeFTy, " __resumeException" , &M);
949+ ResumeF = getFunction (ResumeFTy, " __resumeException" , &M);
946950 ResumeF->addFnAttr (Attribute::NoReturn);
947951
948952 // Register llvm_eh_typeid_for function
949953 FunctionType *EHTypeIDTy =
950954 FunctionType::get (IRB.getInt32Ty (), IRB.getPtrTy (), false );
951- EHTypeIDF = getEmscriptenFunction (EHTypeIDTy, " llvm_eh_typeid_for" , &M);
955+ EHTypeIDF = getFunction (EHTypeIDTy, " llvm_eh_typeid_for" , &M);
952956 }
953957
954958 // Functions that contains calls to setjmp but don't have other longjmpable
@@ -988,14 +992,14 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
988992 // Register emscripten_longjmp function
989993 FunctionType *FTy = FunctionType::get (
990994 IRB.getVoidTy (), {getAddrIntType (&M), IRB.getInt32Ty ()}, false );
991- EmLongjmpF = getEmscriptenFunction (FTy, " emscripten_longjmp" , &M);
995+ EmLongjmpF = getFunction (FTy, " emscripten_longjmp" , &M);
992996 EmLongjmpF->addFnAttr (Attribute::NoReturn);
993997 } else { // EnableWasmSjLj
994998 Type *Int8PtrTy = IRB.getPtrTy ();
995999 // Register __wasm_longjmp function, which calls __builtin_wasm_longjmp.
9961000 FunctionType *FTy = FunctionType::get (
9971001 IRB.getVoidTy (), {Int8PtrTy, IRB.getInt32Ty ()}, false );
998- WasmLongjmpF = getEmscriptenFunction (FTy, " __wasm_longjmp" , &M);
1002+ WasmLongjmpF = getFunction (FTy, " __wasm_longjmp" , &M);
9991003 WasmLongjmpF->addFnAttr (Attribute::NoReturn);
10001004 }
10011005
@@ -1009,11 +1013,11 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runOnModule(Module &M) {
10091013 FunctionType *FTy = FunctionType::get (
10101014 IRB.getVoidTy (), {SetjmpFTy->getParamType (0 ), Int32Ty, Int32PtrTy},
10111015 false );
1012- WasmSetjmpF = getEmscriptenFunction (FTy, " __wasm_setjmp" , &M);
1016+ WasmSetjmpF = getFunction (FTy, " __wasm_setjmp" , &M);
10131017
10141018 // Register __wasm_setjmp_test function
10151019 FTy = FunctionType::get (Int32Ty, {Int32PtrTy, Int32PtrTy}, false );
1016- WasmSetjmpTestF = getEmscriptenFunction (FTy, " __wasm_setjmp_test" , &M);
1020+ WasmSetjmpTestF = getFunction (FTy, " __wasm_setjmp_test" , &M);
10171021
10181022 // wasm.catch() will be lowered down to wasm 'catch' instruction in
10191023 // instruction selection.
0 commit comments