33#define DEBUG_TYPE "wasm-add-missing-prototypes"
36class WebAssemblyAddMissingPrototypesLegacy final :
public ModulePass {
38 return "Add prototypes to prototypes-less functions";
46 bool runOnModule(
Module &M)
override;
50 WebAssemblyAddMissingPrototypesLegacy() :
ModulePass(
ID) {}
54char WebAssemblyAddMissingPrototypesLegacy::ID = 0;
56 "Add prototypes to prototypes-less functions",
false,
false)
59 return new WebAssemblyAddMissingPrototypesLegacy();
63 LLVM_DEBUG(
dbgs() <<
"********** Add Missing Prototypes **********\n");
65 std::vector<std::pair<Function *, Function *>> Replacements;
69 if (!
F.isDeclaration() || !
F.hasFnAttribute(
"no-prototype"))
80 "Functions with 'no-prototype' attribute must take varargs: " +
82 unsigned NumParams =
F.getFunctionType()->getNumParams();
84 if (!(NumParams == 1 &&
F.arg_begin()->hasStructRetAttr()))
94 while (!Worklist.
empty()) {
100 if (CB->getCalledOperand() == V)
108 LLVM_DEBUG(
dbgs() <<
"prototype-less call of " <<
F.getName() <<
":\n");
114 LLVM_DEBUG(
dbgs() <<
"found function type: " << *NewType <<
"\n");
115 }
else if (NewType != DestType) {
116 errs() <<
"warning: prototype-less function used with "
117 "conflicting signatures: "
118 <<
F.getName() <<
"\n";
126 dbgs() <<
"could not derive a function prototype from usage: " +
140 Replacements.emplace_back(&
F, NewF);
143 for (
auto &Pair : Replacements) {
146 std::string Name = std::string(OldF->
getName());
147 M.getFunctionList().push_back(NewF);
154 return !Replacements.empty();
157bool WebAssemblyAddMissingPrototypesLegacy::runOnModule(
Module &M) {
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.
This header defines various interfaces for pass management in LLVM.
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool addMissingPrototypes(Module &M)
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
Represent the analysis usage information of a pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
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...
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...
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
LLVM Value Representation.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Pass manager infrastructure for declaring and invalidating analyses.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
ModulePass * createWebAssemblyAddMissingPrototypesLegacyPass()
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.