37 #define DEBUG_TYPE "wasm-fix-function-bitcasts" 40 "wasm-temporary-workarounds",
41 cl::desc(
"Apply certain temporary workarounds"),
45 class FixFunctionBitcasts final :
public ModulePass {
47 return "WebAssembly Fix Function Bitcasts";
55 bool runOnModule(
Module &M)
override;
65 "Fix mismatching bitcasts for WebAssembly",
false,
false)
68 return new FixFunctionBitcasts();
79 else if (U.get()->getType() != F.
getType()) {
88 if (isa<Constant>(U.get())) {
90 auto c = ConstantBCs.
insert(cast<Constant>(U.get()));
94 Uses.push_back(std::make_pair(&U, &F));
121 for (; AI != AE && PI != PE; ++AI, ++PI) {
126 Args.push_back(&*AI);
128 for (; PI != PE; ++PI)
131 for (; AI != AE; ++AI)
132 Args.push_back(&*AI);
152 bool FixFunctionBitcasts::runOnModule(
Module &M) {
169 Type *MainArgTys[] = {
175 if (
F.getFunctionType() != MainTy) {
191 for (
auto &UseFunc : Uses) {
192 Use *U = UseFunc.first;
208 auto Pair = Wrappers.
insert(std::make_pair(std::make_pair(F, Ty),
nullptr));
216 if (isa<Constant>(U->get()))
225 Main->
setName(
"__original_main");
void setVisibility(VisibilityTypes V)
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
void push_back(const T &Elt)
iterator_range< use_iterator > uses()
This class represents an incoming formal argument to a Function.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
This class represents a function call, abstracting a target machine's calling convention.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Like Internal, but omit from symbol table.
LLVMContext & getContext() const
All values hold a context through their type.
const Use & getOperandUse(unsigned i) const
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
param_iterator param_end() const
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
LLVMContext & getContext() const
Get the global data context.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void setName(const Twine &Name)
Change the name of the value.
Class to represent function types.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Type * getType() const
All values are typed, get the type of this value.
INITIALIZE_PASS(FixFunctionBitcasts, DEBUG_TYPE, "Fix mismatching bitcasts for WebAssembly", false, false) ModulePass *llvm
static cl::opt< bool > TemporaryWorkarounds("wasm-temporary-workarounds", cl::desc("Apply certain temporary workarounds"), cl::init(true), cl::Hidden)
LinkageTypes getLinkage() const
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
amdgpu Simplify well known AMD library false Value * Callee
Class to represent pointers.
static Function * CreateWrapper(Function *F, FunctionType *Ty)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isVoidTy() const
Return true if this is 'void'.
initializer< Ty > init(const Ty &Val)
VisibilityTypes getVisibility() const
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
param_iterator param_begin() const
Represent the analysis usage information of a pass.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
ModulePass * createWebAssemblyFixFunctionBitcasts()
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type::subtype_iterator param_iterator
Type * getReturnType() const
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void setLinkage(LinkageTypes LT)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
static IntegerType * getInt32Ty(LLVMContext &C)
static void FindUses(Value *V, Function &F, SmallVectorImpl< std::pair< Use *, Function *>> &Uses, SmallPtrSetImpl< Constant *> &ConstantBCs)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
StringRef - Represent a constant reference to a string, i.e.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
PointerType * getType() const
Global values are always pointers.