32 #define DEBUG_TYPE "wasm-add-missing-prototypes" 35 class WebAssemblyAddMissingPrototypes final :
public ModulePass {
37 return "Add prototypes to prototypes-less functions";
45 bool runOnModule(
Module &M)
override;
55 "Add prototypes to prototypes-less functions",
false,
false)
58 return new WebAssemblyAddMissingPrototypes();
61 bool 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()))
92 for (
Use &U :
F.uses()) {
95 if (
auto *BC = dyn_cast<BitCastOperator>(U.getUser())) {
96 if (
auto *DestType = dyn_cast<FunctionType>(
97 BC->getDestTy()->getPointerElementType())) {
101 LLVM_DEBUG(
dbgs() <<
"found function type: " << *NewType <<
"\n");
102 }
else if (NewType != DestType) {
103 errs() <<
"warning: prototype-less function used with " 104 "conflicting signatures: " 105 <<
F.getName() <<
"\n";
115 dbgs() <<
"could not derive a function prototype from usage: " +
129 Replacements.emplace_back(&
F, NewF);
132 for (
auto &Pair : Replacements) {
136 M.getFunctionList().push_back(NewF);
143 return !Replacements.empty();
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
A Use represents the edge between a Value definition and its users.
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...
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
ModulePass * createWebAssemblyAddMissingPrototypes()
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
INITIALIZE_PASS(WebAssemblyAddMissingPrototypes, DEBUG_TYPE, "Add prototypes to prototypes-less functions", false, false) ModulePass *llvm
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Module.h This file contains the declarations for the Module class.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
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.
StringRef - Represent a constant reference to a string, i.e.
PointerType * getType() const
Global values are always pointers.