[llvm-branch-commits] [WebAssembly] Introduce CodeGenPassBuilder (PR #208983)
Heejin Ahn via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Jul 13 23:56:34 PDT 2026
================
@@ -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);
----------------
aheejin wrote:
```suggestion
flushFPMsToMPM(PMW);
// Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
```
What does `flushFPMsToMPM` do? When do we call it?
https://github.com/llvm/llvm-project/pull/208983
More information about the llvm-branch-commits
mailing list