31#define DEBUG_TYPE "wasm-add-missing-prototypes"
34class WebAssemblyAddMissingPrototypes final :
public ModulePass {
36 return "Add prototypes to prototypes-less functions";
44 bool runOnModule(
Module &M)
override;
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;
66 for (Function &
F : M) {
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()) {
98 if (CB->getCalledOperand() == V)
104 FunctionType *NewType =
nullptr;
105 for (CallBase *CB : Calls) {
106 LLVM_DEBUG(
dbgs() <<
"prototype-less call of " <<
F.getName() <<
":\n");
108 FunctionType *DestType = CB->getFunctionType();
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);
138 Replacements.emplace_back(&
F, NewF);
141 for (
auto &Pair : Replacements) {
145 M.getFunctionList().push_back(NewF);
152 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.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
static LLVM_ABI 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)
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...
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
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.
LLVM_ABI 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.
FunctionAddr VTableAddr Value
ModulePass * createWebAssemblyAddMissingPrototypes()
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)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.