33 #define DEBUG_TYPE "wasm-add-missing-prototypes" 36 class WebAssemblyAddMissingPrototypes final :
public ModulePass {
38 return "Add prototypes to prototypes-less functions";
46 bool runOnModule(
Module &M)
override;
50 WebAssemblyAddMissingPrototypes() :
ModulePass(ID) {}
56 "Add prototypes to prototypes-less functions",
false,
false)
59 return new WebAssemblyAddMissingPrototypes();
62 bool WebAssemblyAddMissingPrototypes::runOnModule(
Module &M) {
65 std::vector<std::pair<Function*, Function*>> Replacements;
69 if (!
F.isDeclaration() || !
F.hasFnAttribute(
"no-prototype"))
72 LLVM_DEBUG(
dbgs() <<
"Found no-prototype function: " <<
F.getName() <<
"\n");
79 "Functions with 'no-prototype' attribute must take varargs: " +
81 if (
F.getFunctionType()->getNumParams() != 0)
83 "Functions with 'no-prototype' attribute should not have params: " +
91 for (
Use &U :
F.uses()) {
95 cast<FunctionType>(BC->getDestTy()->getPointerElementType());
108 dbgs() <<
"could not derive a function prototype from usage: " +
113 for (
Use &U :
F.uses()) {
116 cast<FunctionType>(BC->getDestTy()->getPointerElementType());
117 if (NewType != DestType) {
119 "Prototypeless function used with conflicting signatures: " +
122 BC->replaceAllUsesWith(NewF);
123 Replacements.emplace_back(&
F, NewF);
125 dbgs() << *U.getUser()->getType() <<
"\n";
130 "unexpected use of prototypeless function: " +
F.getName() +
"\n");
136 for (
auto &Pair : Replacements) {
140 M.getFunctionList().push_back(New);
143 return !Replacements.empty();
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
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.
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...
ModulePass * createWebAssemblyAddMissingPrototypes()
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.
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.
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.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, const Twine &N="", Module *M=nullptr)