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) {
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 if (
F.getFunctionType()->getNumParams() != 0)
84 "Functions with 'no-prototype' attribute should not have params: " +
91 for (
Use &U :
F.uses()) {
93 if (
auto *BC = dyn_cast<BitCastOperator>(U.getUser())) {
94 if (
auto *DestType = dyn_cast<FunctionType>(
95 BC->getDestTy()->getPointerElementType())) {
103 if (NewType != DestType) {
105 "conflicting signatures: " +
115 dbgs() <<
"could not derive a function prototype from usage: " +
122 for (
Use &US :
F.uses()) {
123 User *U = US.getUser();
124 if (
auto *BC = dyn_cast<BitCastOperator>(U)) {
125 if (
auto *Inst = dyn_cast<BitCastInst>(U)) {
131 }
else if (
auto *Const = dyn_cast<ConstantExpr>(U)) {
134 Const->replaceAllUsesWith(NewConst);
146 for (
auto I : DeadInsts)
147 I->eraseFromParent();
148 Replacements.emplace_back(&
F, NewF);
153 for (
auto &Pair : Replacements) {
157 M.getFunctionList().push_back(New);
160 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.
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module. ...
void push_back(const T &Elt)
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...
void dump() const
Support for debugging, callable in GDB: V->dump()
A Use represents the edge between a Value definition and its users.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
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...
Type * getType() const
All values are typed, get the type of this value.
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 is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Represent the analysis usage information of a pass.
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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.
Value * CreatePointerCast(Value *V, Type *DestTy, const Twine &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.
LLVM Value Representation.
StringRef - Represent a constant reference to a string, i.e.