LLVM  9.0.0svn
Macros | Functions | Variables
WebAssemblyLowerEmscriptenEHSjLj.cpp File Reference

This file lowers exception-related instructions and setjmp/longjmp function calls in order to use Emscripten's JavaScript try and catch mechanism. More...

#include "WebAssembly.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/SSAUpdater.h"
Include dependency graph for WebAssemblyLowerEmscriptenEHSjLj.cpp:

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 GlobalVariablegetGlobalVariableI32 (Module &M, IRBuilder<> &IRB, const char *Name)
 
static std::string getSignature (FunctionType *FTy)
 

Variables

static cl::list< std::string > EHWhitelist ("emscripten-cxx-exceptions-whitelist", cl::desc("The list of function names in which Emscripten-style " "exception handling is enabled (see emscripten " "EMSCRIPTEN_CATCHING_WHITELIST options)"), cl::CommaSeparated)
 

Detailed Description

This file lowers exception-related instructions and setjmp/longjmp function calls in order to use Emscripten's JavaScript try and catch mechanism.

To handle exceptions and setjmp/longjmps, this scheme relies on JavaScript's try and catch syntax and relevant exception-related libraries implemented in JavaScript glue code that will be produced by Emscripten. This is similar to the current Emscripten asm.js exception handling in fastcomp. For fastcomp's EH / SjLj scheme, see these files in fastcomp LLVM branch: (Location: https://github.com/kripken/emscripten-fastcomp) lib/Target/JSBackend/NaCl/LowerEmExceptionsPass.cpp lib/Target/JSBackend/NaCl/LowerEmSetjmp.cpp lib/Target/JSBackend/JSBackend.cpp lib/Target/JSBackend/CallHandlers.h

In detail, this pass does following things:

1) Assumes the existence of global variables: THREW, threwValue __THREW and threwValue will be set in invoke wrappers in JS glue code. For what invoke wrappers are, refer to 3). 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, __threwValue variable indicates the corresponding setjmp buffer the longjmp corresponds to.

2) We assume the existence of setThrew and setTempRet0/getTempRet0 functions at link time. The global variables in 1) will exist in wasm address space, but their values should be set in JS code, so these functions as interfaces to JS glue code. These functions are equivalent to the following JS functions, which actually exist in asm.js version of JS library.

function setThrew(threw, value) { if (THREW == 0) { THREW = threw; __threwValue = value; } }

Definition in file WebAssemblyLowerEmscriptenEHSjLj.cpp.

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "wasm-lower-em-ehsjlj"

Definition at line 219 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.

Function Documentation

◆ canThrow()

static bool canThrow ( const Value V)
static

Definition at line 322 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.

References F(), and Name.

Referenced by getSignature().

◆ getGlobalVariableI32()

static GlobalVariable* getGlobalVariableI32 ( Module M,
IRBuilder<> &  IRB,
const char Name 
)
static

◆ getSignature()

static std::string getSignature ( FunctionType FTy)
static

Definition at line 353 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.

References llvm::MCID::Add, llvm::SSAUpdater::AddAvailableValue(), llvm::SwitchInst::addCase(), llvm::PHINode::addIncoming(), llvm::SmallVectorImpl< T >::append(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), C, Callee, canThrow(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::BasicBlock::Create(), llvm::BinaryOperator::Create(), llvm::Function::Create(), llvm::IRBuilder< T, Inserter >::CreateAnd(), llvm::IRBuilder< T, Inserter >::CreateBr(), llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::IRBuilder< T, Inserter >::CreateCondBr(), llvm::IRBuilder< T, Inserter >::CreateExtractValue(), llvm::CallInst::CreateFree(), llvm::IRBuilder< T, Inserter >::CreateICmpEQ(), llvm::IRBuilder< T, Inserter >::CreateICmpNE(), llvm::IRBuilder< T, Inserter >::CreateInsertValue(), llvm::IRBuilder< T, Inserter >::CreateIntToPtr(), llvm::IRBuilder< T, Inserter >::CreateLoad(), llvm::CallInst::CreateMalloc(), llvm::IRBuilder< T, Inserter >::CreatePHI(), llvm::IRBuilder< T, Inserter >::CreateStore(), llvm::IRBuilder< T, Inserter >::CreateSwitch(), llvm::IRBuilder< T, Inserter >::CreateUnreachable(), llvm::dbgs(), llvm::DominatorTree::dominates(), llvm::dyn_cast(), llvm::StringMap< ValueTy, AllocatorTy >::end(), llvm::Function::eraseFromParent(), llvm::GlobalValue::ExternalLinkage, F(), llvm::StringMap< ValueTy, AllocatorTy >::find(), llvm::AttributeList::FunctionIndex, llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::AttributeList::getAttributes(), llvm::Function::getContext(), llvm::Module::getContext(), llvm::Function::getEntryBlock(), llvm::BasicBlock::getFirstInsertionPt(), llvm::BasicBlock::getFirstNonPHI(), llvm::AttributeList::getFnAttributes(), llvm::Module::getFunction(), llvm::Function::getFunctionType(), getGlobalVariableI32(), llvm::IRBuilderBase::getInt32(), llvm::Type::getInt32PtrTy(), llvm::IRBuilderBase::getInt32Ty(), llvm::Type::getInt32Ty(), llvm::IRBuilderBase::getInt8PtrTy(), llvm::Type::getInt8PtrTy(), llvm::Function::getIntrinsicID(), llvm::Instruction::getModule(), llvm::BasicBlock::getModule(), llvm::Value::getName(), llvm::ilist_node_with_parent< NodeTy, ParentTy, Options >::getNextNode(), llvm::AttributeList::getParamAttributes(), llvm::FunctionType::getParamType(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::AttributeList::getRetAttributes(), llvm::FunctionType::getReturnType(), llvm::BasicBlock::getTerminator(), llvm::Value::getType(), llvm::PointerType::getUnqual(), llvm::Use::getUser(), llvm::IRBuilderBase::getVoidTy(), I, llvm::ARM_PROC::IE, llvm::SSAUpdater::Initialize(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::GlobalValue::isDeclaration(), llvm::FunctionType::isVarArg(), LLVM_DEBUG, llvm::makeArrayRef(), llvm::None, llvm::FunctionType::param_begin(), llvm::FunctionType::param_end(), llvm::FunctionType::params(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::DominatorTreeBase< NodeT, IsPostDom >::recalculate(), llvm::remove_if(), replace(), llvm::Value::replaceAllUsesWith(), llvm::report_fatal_error(), llvm::SSAUpdater::RewriteUse(), llvm::SSAUpdater::RewriteUseAfterInsertions(), llvm::CallBase::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Instruction::setDebugLoc(), llvm::Function::setDoesNotThrow(), llvm::IRBuilderBase::SetInsertPoint(), SI, llvm::SmallVectorBase::size(), llvm::BasicBlock::size(), llvm::SplitBlock(), SSA, llvm::StringRef::startswith(), llvm::raw_string_ostream::str(), llvm::Value::takeName(), llvm::RegState::Undef, llvm::Value::use_begin(), llvm::Value::use_empty(), llvm::Value::use_end(), and llvm::Value::users().

Referenced by llvm::DWARFUnitIndex::getFromHash().

◆ INITIALIZE_PASS()

INITIALIZE_PASS ( WebAssemblyLowerEmscriptenEHSjLj  ,
DEBUG_TYPE  ,
"WebAssembly Lower Emscripten Exceptions / Setjmp / Longjmp"  ,
false  ,
false   
)

Definition at line 313 of file WebAssemblyLowerEmscriptenEHSjLj.cpp.

Variable Documentation

◆ EHWhitelist

cl::list<std::string> EHWhitelist("emscripten-cxx-exceptions-whitelist", cl::desc("The list of function names in which Emscripten-style " "exception handling is enabled (see emscripten " "EMSCRIPTEN_CATCHING_WHITELIST options)"), cl::CommaSeparated)
static