|
LLVM 24.0.0git
|
Fix bitcasted functions. More...
#include "WebAssembly.h"#include "llvm/IR/Analysis.h"#include "llvm/IR/Constants.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/Module.h"#include "llvm/IR/Operator.h"#include "llvm/IR/PassManager.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 (WebAssemblyFixFunctionBitcastsLegacy, DEBUG_TYPE, "Fix mismatching bitcasts for WebAssembly", false, false) ModulePass *llvm | |
| static void | findUses (Value *V, Function &F, SmallVectorImpl< std::pair< CallBase *, Function * > > &Uses) |
| static Function * | createWrapper (Function *F, FunctionType *Ty) |
| static bool | shouldFixMainFunction (FunctionType *FuncTy, FunctionType *MainTy) |
| static bool | fixFunctionBitcasts (Module &M) |
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 38 of file WebAssemblyFixFunctionBitcasts.cpp.
|
static |
Definition at line 112 of file WebAssemblyFixFunctionBitcasts.cpp.
References Call, llvm::BasicBlock::Create(), llvm::Function::Create(), llvm::dbgs(), DL, F, llvm::PoisonValue::get(), llvm::BasicBlock::getDataLayout(), llvm::Value::getType(), llvm::CastInst::isBitOrNoopPointerCastable(), llvm::Type::isStructTy(), llvm::Type::isVoidTy(), LLVM_DEBUG, llvm::GlobalValue::PrivateLinkage, and Wrapper.
Referenced by fixFunctionBitcasts().
|
static |
Definition at line 69 of file WebAssemblyFixFunctionBitcasts.cpp.
References A(), llvm::dyn_cast(), F, findUses(), llvm::Value::users(), and Uses.
Referenced by findUses(), and fixFunctionBitcasts().
Definition at line 225 of file WebAssemblyFixFunctionBitcasts.cpp.
References C(), llvm::cast(), llvm::CallInst::Create(), createWrapper(), llvm::dbgs(), F, findUses(), llvm::FunctionType::get(), llvm::PointerType::get(), llvm::PoisonValue::get(), llvm::CallBase::getCalledOperand(), llvm::CallBase::getFunctionType(), llvm::Type::getInt32Ty(), llvm::GlobalValue::getLinkage(), llvm::GlobalValue::getVisibility(), llvm::GlobalValue::isDeclaration(), LLVM_DEBUG, llvm::CallBase::setCalledOperand(), llvm::Value::setName(), shouldFixMainFunction(), llvm::Value::stripPointerCasts(), llvm::CallingConv::Swift, llvm::CallingConv::SwiftTail, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), Uses, and Wrapper.
Referenced by llvm::WebAssemblyFixFunctionBitcastsPass::run().
| INITIALIZE_PASS | ( | WebAssemblyFixFunctionBitcastsLegacy | , |
| DEBUG_TYPE | , | ||
| "Fix mismatching bitcasts for WebAssembly" | , | ||
| false | , | ||
| false | ) |
Definition at line 60 of file WebAssemblyFixFunctionBitcasts.cpp.
References llvm::createWebAssemblyFixFunctionBitcastsLegacyPass(), and DEBUG_TYPE.
|
static |
Definition at line 216 of file WebAssemblyFixFunctionBitcasts.cpp.
Referenced by fixFunctionBitcasts().