================
@@ -0,0 +1,255 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "WebAssembly.h"
+#include "WebAssemblyTargetMachine.h"
+#include "llvm/CodeGen/AtomicExpand.h"
+#include "llvm/CodeGen/IndirectBrExpand.h"
+#include "llvm/CodeGen/MachineBlockPlacement.h"
+#include "llvm/CodeGen/MachineCopyPropagation.h"
+#include "llvm/CodeGen/MachineLateInstrsCleanup.h"
+#include "llvm/CodeGen/PatchableFunction.h"
+#include "llvm/CodeGen/PostRAMachineSink.h"
+#include "llvm/CodeGen/PostRASchedulerList.h"
+#include "llvm/CodeGen/RegisterCoalescerPass.h"
+#include "llvm/CodeGen/RemoveLoadsIntoFakeUses.h"
+#include "llvm/CodeGen/ShrinkWrap.h"
+#include "llvm/CodeGen/UnreachableBlockElim.h"
+#include "llvm/IR/PassInstrumentation.h"
+#include "llvm/MC/MCStreamer.h"
+#include "llvm/Passes/CodeGenPassBuilder.h"
+#include "llvm/Passes/PassBuilder.h"
+#include "llvm/Support/CodeGen.h"
+#include "llvm/Target/CGPassBuilderOption.h"
+#include "llvm/Transforms/Utils/LowerGlobalDtors.h"
+#include "llvm/Transforms/Utils/LowerInvoke.h"
+
+using namespace llvm;
+
+namespace WebAssembly {
+extern cl::opt<bool> WasmDisableExplicitLocals;
+extern cl::opt<bool> WasmEnableEH;
+extern cl::opt<bool> WasmEnableEmEH;
+extern cl::opt<bool> WasmEnableEmSjLj;
+extern cl::opt<bool> WasmEnableSjLj;
+} // namespace WebAssembly
+
+using llvm::WebAssembly::WasmDisableExplicitLocals;
+using llvm::WebAssembly::WasmEnableEH;
+using llvm::WebAssembly::WasmEnableEmEH;
+using llvm::WebAssembly::WasmEnableEmSjLj;
+using llvm::WebAssembly::WasmEnableSjLj;
+
+namespace {
+
+class WebAssemblyCodeGenPassBuilder
+    : public CodeGenPassBuilder<WebAssemblyCodeGenPassBuilder,
+                                WebAssemblyTargetMachine> {
+  using Base = CodeGenPassBuilder<WebAssemblyCodeGenPassBuilder,
+                                  WebAssemblyTargetMachine>;
+
+public:
+  explicit WebAssemblyCodeGenPassBuilder(WebAssemblyTargetMachine &TM,
+                                         const CGPassBuilderOption &Opts,
+                                         PassInstrumentationCallbacks *PIC)
+      : CodeGenPassBuilder(TM, Opts, PIC) {
+    disablePass<MachineLateInstrsCleanupPass, MachineCopyPropagationPass,
+                PostRAMachineSinkingPass, PostRASchedulerPass,
+                FuncletLayoutPass, StackMapLivenessPass, PatchableFunctionPass,
+                ShrinkWrapPass, RemoveLoadsIntoFakeUsesPass,
+                MachineBlockPlacementPass>();
+    if (getOptLevel() == CodeGenOptLevel::Less)
+      disablePass<RegisterCoalescerPass>();
+  }
+
+  void addIRPasses(PassManagerWrapper &PMW) const;
+  void addISelPrepare(PassManagerWrapper &PMW) const;
+  Error addInstSelector(PassManagerWrapper &PMW) const;
+  void addPreEmitPass(PassManagerWrapper &PMW) const;
+};
+
+void WebAssemblyCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) const 
{
+  // Add signatures to prototype-less function declarations
+  // TODO(boomanaiden154): WebAssemblyAddMissingPrototypes
+
+  // Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
+  flushFPMsToMPM(PMW);
----------------
boomanaiden154 wrote:

You need to call it when the previous pass is a 
MachineFunctionPass/FunctionPass and the next pass is a ModulePass.

The NewPM explicitly nests pass managers (eg, a function pass manager has to be 
nested under a module pass manager). In the middle-end, this is explicit with 
the types that get passed to the various functions to build parts of the 
pipelines. In the backend each target needs flexibility on where to add module 
passes, so we ended up with this compromise where rather than explicitly 
creating FPMs, we have a pass manager wrapper that handles the nesting and you 
need to explicitly call `flushFPMsToMPM` when adding a module pass.

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

Reply via email to