32#define DEBUG_TYPE "wasm-add-missing-prototypes"
35class WebAssemblyAddMissingPrototypes final :
public ModulePass {
37 return "Add prototypes to prototypes-less functions";
53char WebAssemblyAddMissingPrototypes::ID = 0;
55 "Add prototypes to prototypes-less functions",
false,
false)
58 return new WebAssemblyAddMissingPrototypes();
61bool WebAssemblyAddMissingPrototypes::runOnModule(
Module &M) {
62 LLVM_DEBUG(
dbgs() <<
"********** Add Missing Prototypes **********\n");
64 std::vector<std::pair<Function *, Function *>> Replacements;
68 if (!
F.isDeclaration() || !
F.hasFnAttribute(
"no-prototype"))
79 "Functions with 'no-prototype' attribute must take varargs: " +
81 unsigned NumParams =
F.getFunctionType()->getNumParams();
83 if (!(NumParams == 1 &&
F.arg_begin()->hasStructRetAttr()))
93 while (!Worklist.
empty()) {
95 for (
User *U :
V->users()) {
96 if (
auto *BC = dyn_cast<BitCastOperator>(U))
98 else if (
auto *CB = dyn_cast<CallBase>(U))
99 if (CB->getCalledOperand() == V)
107 LLVM_DEBUG(
dbgs() <<
"prototype-less call of " <<
F.getName() <<
":\n");
113 LLVM_DEBUG(
dbgs() <<
"found function type: " << *NewType <<
"\n");
114 }
else if (NewType != DestType) {
115 errs() <<
"warning: prototype-less function used with "
116 "conflicting signatures: "
117 <<
F.getName() <<
"\n";
125 dbgs() <<
"could not derive a function prototype from usage: " +
132 NewType = FunctionType::get(
F.getFunctionType()->getReturnType(),
false);
140 Replacements.emplace_back(&
F, NewF);
143 for (
auto &Pair : Replacements) {
147 M.getFunctionList().push_back(NewF);
154 return !Replacements.empty();
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represent the analysis usage information of a pass.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
bool IsNewDbgInfoFormat
Is this function using intrinsics to record the position of debugging information,...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
PointerType * getType() const
Global values are always pointers.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
virtual bool runOnModule(Module &M)=0
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
A Module instance is used to store all the information related to an LLVM module.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
void setName(const Twine &Name)
Change the name of the value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
StringRef getName() const
Return a constant reference to the value's name.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
ModulePass * createWebAssemblyAddMissingPrototypes()
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.