31#define DEBUG_TYPE "wasm-add-missing-prototypes"
34class WebAssemblyAddMissingPrototypes final :
public ModulePass {
36 return "Add prototypes to prototypes-less functions";
52char WebAssemblyAddMissingPrototypes::ID = 0;
54 "Add prototypes to prototypes-less functions",
false,
false)
57 return new WebAssemblyAddMissingPrototypes();
60bool WebAssemblyAddMissingPrototypes::runOnModule(
Module &M) {
61 LLVM_DEBUG(
dbgs() <<
"********** Add Missing Prototypes **********\n");
63 std::vector<std::pair<Function *, Function *>> Replacements;
67 if (!
F.isDeclaration() || !
F.hasFnAttribute(
"no-prototype"))
78 "Functions with 'no-prototype' attribute must take varargs: " +
80 unsigned NumParams =
F.getFunctionType()->getNumParams();
82 if (!(NumParams == 1 &&
F.arg_begin()->hasStructRetAttr()))
92 while (!Worklist.
empty()) {
94 for (
User *U :
V->users()) {
95 if (
auto *BC = dyn_cast<BitCastOperator>(U))
97 else if (
auto *CB = dyn_cast<CallBase>(U))
98 if (CB->getCalledOperand() == V)
106 LLVM_DEBUG(
dbgs() <<
"prototype-less call of " <<
F.getName() <<
":\n");
112 LLVM_DEBUG(
dbgs() <<
"found function type: " << *NewType <<
"\n");
113 }
else if (NewType != DestType) {
114 errs() <<
"warning: prototype-less function used with "
115 "conflicting signatures: "
116 <<
F.getName() <<
"\n";
124 dbgs() <<
"could not derive a function prototype from usage: " +
131 NewType = FunctionType::get(
F.getFunctionType()->getReturnType(),
false);
139 Replacements.emplace_back(&
F, NewF);
142 for (
auto &Pair : Replacements) {
146 M.getFunctionList().push_back(NewF);
153 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.