LLVM 22.0.0git
|
This file lowers exception-related instructions and setjmp/longjmp function calls to use Emscripten's library functions. More...
#include "WebAssembly.h"
#include "WebAssemblyTargetMachine.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/CodeGen/WasmEHFuncInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/IntrinsicsWebAssembly.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include "llvm/Transforms/Utils/SSAUpdaterBulk.h"
#include <set>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "wasm-lower-em-ehsjlj" |
Functions | |
INITIALIZE_PASS (WebAssemblyLowerEmscriptenEHSjLj, DEBUG_TYPE, "WebAssembly Lower Emscripten Exceptions / Setjmp / Longjmp", false, false) ModulePass *llvm | |
static bool | canThrow (const Value *V) |
static GlobalVariable * | getGlobalVariable (Module &M, Type *Ty, WebAssemblyTargetMachine &TM, const char *Name) |
static std::string | getSignature (FunctionType *FTy) |
static Function * | getFunction (FunctionType *Ty, const Twine &Name, Module *M) |
static void | markAsImported (Function *F) |
static Type * | getAddrIntType (Module *M) |
static Type * | getAddrPtrType (Module *M) |
static Value * | getAddrSizeInt (Module *M, uint64_t C) |
static bool | canLongjmp (const Value *Callee) |
static bool | isEmAsmCall (const Value *Callee) |
static bool | containsLongjmpableCalls (const Function *F) |
static void | nullifySetjmp (Function *F) |
static DebugLoc | getOrCreateDebugLoc (const Instruction *InsertBefore, DISubprogram *SP) |
static BasicBlock * | getCleanupRetUnwindDest (const CleanupPadInst *CPI) |
Variables | |
static cl::list< std::string > | EHAllowlist ("emscripten-cxx-exceptions-allowed", cl::desc("The list of function names in which Emscripten-style " "exception handling is enabled (see emscripten " "EMSCRIPTEN_CATCHING_ALLOWED options)"), cl::CommaSeparated) |
This file lowers exception-related instructions and setjmp/longjmp function calls to use Emscripten's library functions.
The pass uses JavaScript's try and catch mechanism in case of Emscripten EH/SjLj and Wasm EH intrinsics in case of Emscripten SjLJ.
In detail, this pass does following things:
1) Assumes the existence of global variables: THREW, threwValue __THREW and threwValue are defined in compiler-rt in Emscripten. These variables are used for both exceptions and setjmp/longjmps. __THREW indicates whether an exception or a longjmp occurred or not. 0 means nothing occurred, 1 means an exception occurred, and other numbers mean a longjmp occurred. In the case of longjmp, THREW variable indicates the corresponding setjmp buffer the longjmp corresponds to. __threwValue is 0 for exceptions, and the argument to longjmp in case of longjmp.
2) We assume the existence of setThrew and setTempRet0/getTempRet0 functions at link time. setThrew exists in Emscripten's compiler-rt:
void setThrew(uintptr_t threw, int value) { if (THREW == 0) { THREW = threw; __threwValue = value; } }
Definition in file WebAssemblyLowerEmscriptenEHSjLj.cpp.
#define DEBUG_TYPE "wasm-lower-em-ehsjlj" |
Definition at line 283 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
Definition at line 599 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::dyn_cast(), llvm::isa(), and llvm::WebAssembly::WasmEnableSjLj.
Referenced by containsLongjmpableCalls().
Definition at line 388 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::dyn_cast(), and F.
Referenced by llvm::InlineAsmKeyType::InlineAsmKeyType(), and llvm::InlineAsmKeyType::InlineAsmKeyType().
Definition at line 868 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References canLongjmp(), llvm::dyn_cast(), F, and I.
Definition at line 465 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::IRBuilderBase::getIntNTy().
Definition at line 473 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::PointerType::getUnqual().
Definition at line 480 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::CallingConv::C, and llvm::IRBuilderBase::getIntN().
|
static |
Definition at line 1573 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::dyn_cast(), and llvm::Value::users().
|
static |
Definition at line 442 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::Function::Create(), and llvm::GlobalValue::ExternalLinkage.
Referenced by llvm::AArch64PrologueEmitter::AArch64PrologueEmitter(), llvm::MachineIRBuilder::buildConstant(), llvm::MachineIRBuilder::buildConstant(), llvm::MachineIRBuilder::buildStepVector(), llvm::MachineIRBuilder::buildVScale(), llvm::MachineIRBuilder::buildVScale(), llvm::SampleProfileLoaderBaseImpl< FT >::emitCoverageRemarks(), llvm::SampleProfileLoaderBaseImpl< FT >::finalizeWeightPropagation(), llvm::SampleProfileLoaderBaseImpl< FT >::getFunctionLoc(), INITIALIZE_PASS(), llvm::SampleProfileLoaderBaseImpl< FT >::initWeightPropagation(), insertLifetimeMarkersSurroundingCall(), LLVMGetBlockAddressFunction(), LLVMGetNamedFunction(), LLVMGetNamedFunctionWithLength(), llvm::MachineModuleSlotTracker::MachineModuleSlotTracker(), llvm::ScheduleDAGInstrs::ScheduleDAGInstrs(), and llvm::SMECallAttrs::SMECallAttrs().
|
static |
Definition at line 406 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::dyn_cast(), llvm::GlobalValue::GeneralDynamicTLSModel, and llvm::report_fatal_error().
Referenced by llvm::Module::getGlobalVariable(), llvm::Module::getGlobalVariable(), and llvm::Module::getNamedGlobal().
|
static |
Definition at line 1268 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References assert(), llvm::dwarf_linker::DebugLoc, llvm::MDNode::get(), llvm::Instruction::getDebugLoc(), and llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getPrevNode().
|
static |
Definition at line 426 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::erase_if(), llvm::isSpace(), llvm::replace(), and llvm::raw_string_ostream::str().
Referenced by llvm::DWARFUnitIndex::getFromHash().
INITIALIZE_PASS | ( | WebAssemblyLowerEmscriptenEHSjLj | , |
DEBUG_TYPE | , | ||
"WebAssembly Lower Emscripten Exceptions / Setjmp / Longjmp" | , | ||
false | , | ||
false | ) |
Definition at line 380 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::createWebAssemblyLowerEmscriptenEHSjLj(), and DEBUG_TYPE.
Definition at line 677 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
|
static |
Definition at line 446 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
|
static |
Definition at line 881 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.
References llvm::cast(), llvm::changeToCall(), llvm::dyn_cast(), F, llvm::Function::getFunction(), llvm::IRBuilderBase::getInt32(), llvm::BasicBlock::getParent(), I, II, llvm::make_early_inc_range(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::Value::replaceAllUsesWith(), and llvm::Value::users().
|
static |