|
LLVM
10.0.0
|
Fix bitcasted functions. More...
#include "WebAssembly.h"#include "llvm/IR/CallSite.h"#include "llvm/IR/Constants.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/Module.h"#include "llvm/IR/Operator.h"#include "llvm/Pass.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "wasm-fix-function-bitcasts" |
Functions | |
| INITIALIZE_PASS (FixFunctionBitcasts, DEBUG_TYPE, "Fix mismatching bitcasts for WebAssembly", false, false) ModulePass *llvm | |
| static void | findUses (Value *V, Function &F, SmallVectorImpl< std::pair< Use *, Function *>> &Uses, SmallPtrSetImpl< Constant *> &ConstantBCs) |
| static Function * | createWrapper (Function *F, FunctionType *Ty) |
| static bool | shouldFixMainFunction (FunctionType *FuncTy, FunctionType *MainTy) |
Fix bitcasted functions.
WebAssembly requires caller and callee signatures to match, however in LLVM, some amount of slop is vaguely permitted. Detect mismatch by looking for bitcasts of functions and rewrite them to use wrapper functions instead.
This doesn't catch all cases, such as when a function's address is taken in one place and casted in another, but it works for many common cases.
Note that LLVM already optimizes away function bitcasts in common cases by dropping arguments as needed, so this pass only ends up getting used in less common cases.
Definition in file WebAssemblyFixFunctionBitcasts.cpp.
Definition at line 36 of file WebAssemblyFixFunctionBitcasts.cpp.
|
static |
Definition at line 118 of file WebAssemblyFixFunctionBitcasts.cpp.
References llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, llvm::BasicBlock::Create(), llvm::Function::Create(), llvm::CallInst::Create(), llvm::ReturnInst::Create(), llvm::CastInst::CreateBitOrPointerCast(), llvm::dbgs(), llvm::Function::eraseFromParent(), llvm::UndefValue::get(), llvm::Module::getContext(), llvm::Function::getFunctionType(), llvm::Value::getName(), llvm::FunctionType::getNumParams(), llvm::GlobalValue::getParent(), llvm::FunctionType::getReturnType(), llvm::Value::getType(), llvm::CastInst::isBitOrNoopPointerCastable(), llvm::Type::isStructTy(), llvm::FunctionType::isVarArg(), llvm::Function::isVarArg(), llvm::Type::isVoidTy(), LLVM_DEBUG, llvm::FunctionType::param_begin(), llvm::FunctionType::param_end(), llvm::GlobalValue::PrivateLinkage, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Value::setName(), llvm::SmallVectorBase::size(), and Wrapper.
Referenced by shouldFixMainFunction().
|
static |
Definition at line 67 of file WebAssemblyFixFunctionBitcasts.cpp.
References C, Callee, llvm::GlobalValue::getType(), llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::Value::uses().
Referenced by shouldFixMainFunction().
| INITIALIZE_PASS | ( | FixFunctionBitcasts | , |
| DEBUG_TYPE | , | ||
| "Fix mismatching bitcasts for WebAssembly" | , | ||
| false | , | ||
| false | |||
| ) |
Definition at line 58 of file WebAssemblyFixFunctionBitcasts.cpp.
|
static |
Definition at line 228 of file WebAssemblyFixFunctionBitcasts.cpp.
References llvm::AMDGPU::HSAMD::Kernel::Key::Args, C, llvm::CallInst::Create(), createWrapper(), llvm::dbgs(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), F(), findUses(), llvm::FunctionType::get(), llvm::PointerType::get(), llvm::UndefValue::get(), llvm::ConstantExpr::getBitCast(), llvm::CallBase::getCalledValue(), llvm::Value::getContext(), llvm::Type::getInt32Ty(), llvm::Type::getInt8PtrTy(), llvm::GlobalValue::getLinkage(), llvm::FunctionType::getNumParams(), llvm::User::getOperandUse(), llvm::FunctionType::getReturnType(), llvm::Value::getType(), llvm::GlobalValue::getVisibility(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::GlobalValue::isDeclaration(), llvm::FunctionType::isVarArg(), LLVM_DEBUG, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Value::setName(), llvm::Value::stripPointerCasts(), and Wrapper.
1.8.13