llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-webassembly

Author: Aiden Grossman (boomanaiden154)

<details>
<summary>Changes</summary>

Standard pass porting.


---
Full diff: https://github.com/llvm/llvm-project/pull/208985.diff


6 Files Affected:

- (modified) llvm/lib/Target/WebAssembly/WebAssembly.h (+11-2) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp 
(+21-7) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp 
(+2-2) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def (+6) 
- (modified) llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp (+2-2) 
- (modified) llvm/test/CodeGen/WebAssembly/add-prototypes.ll (+1) 


``````````diff
diff --git a/llvm/lib/Target/WebAssembly/WebAssembly.h 
b/llvm/lib/Target/WebAssembly/WebAssembly.h
index 9b54f49a2dcb6..cf5ff90d635f4 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.h
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.h
@@ -19,6 +19,8 @@
 #include "WebAssemblySubtarget.h"
 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
 #include "llvm/CodeGen/SelectionDAGISel.h"
+#include "llvm/IR/Analysis.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/PassRegistry.h"
 #include "llvm/Support/CodeGen.h"
 
@@ -30,7 +32,14 @@ class FunctionPass;
 
 // LLVM IR passes.
 ModulePass *createWebAssemblyLowerEmscriptenEHSjLj();
-ModulePass *createWebAssemblyAddMissingPrototypes();
+
+class WebAssemblyAddMissingPrototypesPass
+    : public RequiredPassInfoMixin<WebAssemblyAddMissingPrototypesPass> {
+public:
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
+};
+
+ModulePass *createWebAssemblyAddMissingPrototypesLegacyPass();
 ModulePass *createWebAssemblyFixFunctionBitcasts();
 FunctionPass *createWebAssemblyOptimizeReturned();
 FunctionPass *createWebAssemblyRefTypeMem2Local();
@@ -85,7 +94,7 @@ ModulePass *createWebAssemblyMCLowerPrePass();
 void initializeFixFunctionBitcastsPass(PassRegistry &);
 void initializeOptimizeReturnedPass(PassRegistry &);
 void initializeWebAssemblyRefTypeMem2LocalPass(PassRegistry &);
-void initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &);
+void initializeWebAssemblyAddMissingPrototypesLegacyPass(PassRegistry &);
 void initializeWebAssemblyArgumentMovePass(PassRegistry &);
 void initializeWebAssemblyAsmPrinterPass(PassRegistry &);
 void initializeWebAssemblyCleanCodeAfterTrapPass(PassRegistry &);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
index 344a3636b431b..6c607fb9236d7 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAddMissingPrototypes.cpp
@@ -19,9 +19,11 @@
 
//===----------------------------------------------------------------------===//
 
 #include "WebAssembly.h"
+#include "llvm/IR/Analysis.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Operator.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Transforms/Utils/Local.h"
@@ -31,7 +33,7 @@ using namespace llvm;
 #define DEBUG_TYPE "wasm-add-missing-prototypes"
 
 namespace {
-class WebAssemblyAddMissingPrototypes final : public ModulePass {
+class WebAssemblyAddMissingPrototypesLegacy final : public ModulePass {
   StringRef getPassName() const override {
     return "Add prototypes to prototypes-less functions";
   }
@@ -45,19 +47,19 @@ class WebAssemblyAddMissingPrototypes final : public 
ModulePass {
 
 public:
   static char ID;
-  WebAssemblyAddMissingPrototypes() : ModulePass(ID) {}
+  WebAssemblyAddMissingPrototypesLegacy() : ModulePass(ID) {}
 };
 } // End anonymous namespace
 
-char WebAssemblyAddMissingPrototypes::ID = 0;
-INITIALIZE_PASS(WebAssemblyAddMissingPrototypes, DEBUG_TYPE,
+char WebAssemblyAddMissingPrototypesLegacy::ID = 0;
+INITIALIZE_PASS(WebAssemblyAddMissingPrototypesLegacy, DEBUG_TYPE,
                 "Add prototypes to prototypes-less functions", false, false)
 
-ModulePass *llvm::createWebAssemblyAddMissingPrototypes() {
-  return new WebAssemblyAddMissingPrototypes();
+ModulePass *llvm::createWebAssemblyAddMissingPrototypesLegacyPass() {
+  return new WebAssemblyAddMissingPrototypesLegacy();
 }
 
-bool WebAssemblyAddMissingPrototypes::runOnModule(Module &M) {
+static bool addMissingPrototypes(Module &M) {
   LLVM_DEBUG(dbgs() << "********** Add Missing Prototypes **********\n");
 
   std::vector<std::pair<Function *, Function *>> Replacements;
@@ -151,3 +153,15 @@ bool WebAssemblyAddMissingPrototypes::runOnModule(Module 
&M) {
 
   return !Replacements.empty();
 }
+
+bool WebAssemblyAddMissingPrototypesLegacy::runOnModule(Module &M) {
+  return addMissingPrototypes(M);
+}
+
+PreservedAnalyses
+WebAssemblyAddMissingPrototypesPass::run(Module &M,
+                                         ModuleAnalysisManager &MAM) {
+  return addMissingPrototypes(M)
+             ? PreservedAnalyses::none().preserveSet<CFGAnalyses>()
+             : PreservedAnalyses::all();
+}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
index e872cb1a2e328..fc8feb173ee68 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
@@ -72,10 +72,10 @@ class WebAssemblyCodeGenPassBuilder
 
 void WebAssemblyCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) const 
{
   // Add signatures to prototype-less function declarations
-  // TODO(boomanaiden154): WebAssemblyAddMissingPrototypes
+  flushFPMsToMPM(PMW);
+  addModulePass(WebAssemblyAddMissingPrototypesPass(), PMW);
 
   // Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
-  flushFPMsToMPM(PMW);
   addModulePass(LowerGlobalDtorsPass(), PMW);
 
   // Fix function bitcasts, as WebAssembly requires caller and callee 
signatures
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def 
b/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
index b4a5760148c04..60f902cbfb77e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
@@ -11,6 +11,12 @@
 //
 
//===----------------------------------------------------------------------===//
 
+#ifndef MODULE_PASS
+#define MODULE_PASS(NAME, CREATE_PASS)
+#endif
+MODULE_PASS("wasm-add-missing-prototypes", 
WebAssemblyAddMissingPrototypesPass())
+#undef MODULE_PASS
+
 #ifndef MACHINE_FUNCTION_PASS
 #define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
 #endif
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 8ac6708b4fdae..d71cd7c1ca6d0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -93,7 +93,7 @@ LLVMInitializeWebAssemblyTarget() {
   initializeGlobalISel(PR);
   initializeWebAssemblyPreLegalizerCombinerPass(PR);
   initializeWebAssemblyPostLegalizerCombinerPass(PR);
-  initializeWebAssemblyAddMissingPrototypesPass(PR);
+  initializeWebAssemblyAddMissingPrototypesLegacyPass(PR);
   initializeWebAssemblyLowerEmscriptenEHSjLjPass(PR);
   initializeLowerGlobalDtorsLegacyPassPass(PR);
   initializeFixFunctionBitcastsPass(PR);
@@ -487,7 +487,7 @@ FunctionPass 
*WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
 
 void WebAssemblyPassConfig::addIRPasses() {
   // Add signatures to prototype-less function declarations
-  addPass(createWebAssemblyAddMissingPrototypes());
+  addPass(createWebAssemblyAddMissingPrototypesLegacyPass());
 
   // Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
   addPass(createLowerGlobalDtorsLegacyPass());
diff --git a/llvm/test/CodeGen/WebAssembly/add-prototypes.ll 
b/llvm/test/CodeGen/WebAssembly/add-prototypes.ll
index 2bbc402dd1b6d..853bbfab078c2 100644
--- a/llvm/test/CodeGen/WebAssembly/add-prototypes.ll
+++ b/llvm/test/CodeGen/WebAssembly/add-prototypes.ll
@@ -1,4 +1,5 @@
 ; RUN: opt -S -wasm-add-missing-prototypes %s | FileCheck %s
+; RUN: opt -S -passes=wasm-add-missing-prototypes %s | FileCheck %s
 
 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
 target triple = "wasm32-unknown-unknown"

``````````

</details>


https://github.com/llvm/llvm-project/pull/208985
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to