| 1 | //===-- WebAssembly.h - Top-level interface for WebAssembly ----*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
| 10 | /// This file contains the entry points for global functions defined in |
| 11 | /// the LLVM WebAssembly back-end. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H |
| 16 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H |
| 17 | |
| 18 | #include "GISel/WebAssemblyRegisterBankInfo.h" |
| 19 | #include "WebAssemblySubtarget.h" |
| 20 | #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" |
| 21 | #include "llvm/CodeGen/MachineFunction.h" |
| 22 | #include "llvm/CodeGen/MachineFunctionAnalysisManager.h" |
| 23 | #include "llvm/CodeGen/SelectionDAGISel.h" |
| 24 | #include "llvm/IR/Analysis.h" |
| 25 | #include "llvm/IR/PassManager.h" |
| 26 | #include "llvm/PassRegistry.h" |
| 27 | #include "llvm/Support/CodeGen.h" |
| 28 | |
| 29 | namespace llvm { |
| 30 | |
| 31 | class WebAssemblyTargetMachine; |
| 32 | class ModulePass; |
| 33 | class FunctionPass; |
| 34 | |
| 35 | // LLVM IR passes. |
| 36 | class WebAssemblyLowerEmscriptenEHSjLjPass |
| 37 | : public RequiredPassInfoMixin<WebAssemblyLowerEmscriptenEHSjLjPass> { |
| 38 | public: |
| 39 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 40 | }; |
| 41 | |
| 42 | ModulePass *createWebAssemblyLowerEmscriptenEHSjLjLegacyPass(); |
| 43 | |
| 44 | class WebAssemblyAddMissingPrototypesPass |
| 45 | : public RequiredPassInfoMixin<WebAssemblyAddMissingPrototypesPass> { |
| 46 | public: |
| 47 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 48 | }; |
| 49 | |
| 50 | ModulePass *createWebAssemblyAddMissingPrototypesLegacyPass(); |
| 51 | |
| 52 | class WebAssemblyFixFunctionBitcastsPass |
| 53 | : public RequiredPassInfoMixin<WebAssemblyFixFunctionBitcastsPass> { |
| 54 | public: |
| 55 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 56 | }; |
| 57 | |
| 58 | ModulePass *createWebAssemblyFixFunctionBitcastsLegacyPass(); |
| 59 | |
| 60 | class WebAssemblyOptimizeReturnedPass |
| 61 | : public OptionalPassInfoMixin<WebAssemblyOptimizeReturnedPass> { |
| 62 | public: |
| 63 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); |
| 64 | }; |
| 65 | |
| 66 | FunctionPass *createWebAssemblyOptimizeReturnedLegacyPass(); |
| 67 | |
| 68 | class WebAssemblyRefTypeMem2LocalPass |
| 69 | : public RequiredPassInfoMixin<WebAssemblyRefTypeMem2LocalPass> { |
| 70 | public: |
| 71 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); |
| 72 | }; |
| 73 | |
| 74 | FunctionPass *createWebAssemblyRefTypeMem2LocalLegacyPass(); |
| 75 | |
| 76 | class WebAssemblyReduceToAnyAllTruePass |
| 77 | : public RequiredPassInfoMixin<WebAssemblyReduceToAnyAllTruePass> { |
| 78 | private: |
| 79 | Module *CachedModule = nullptr; |
| 80 | bool ModuleHasInterestingIntrinsics = false; |
| 81 | WebAssemblyTargetMachine &TM; |
| 82 | |
| 83 | public: |
| 84 | WebAssemblyReduceToAnyAllTruePass(WebAssemblyTargetMachine &TM) : TM(TM) {} |
| 85 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); |
| 86 | }; |
| 87 | |
| 88 | FunctionPass * |
| 89 | createWebAssemblyReduceToAnyAllTrueLegacyPass(WebAssemblyTargetMachine &TM); |
| 90 | |
| 91 | class WebAssemblyCoalesceFeaturesAndStripAtomicsPass |
| 92 | : public RequiredPassInfoMixin< |
| 93 | WebAssemblyCoalesceFeaturesAndStripAtomicsPass> { |
| 94 | WebAssemblyTargetMachine &TM; |
| 95 | |
| 96 | public: |
| 97 | WebAssemblyCoalesceFeaturesAndStripAtomicsPass(WebAssemblyTargetMachine &TM) |
| 98 | : TM(TM) {} |
| 99 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 100 | }; |
| 101 | |
| 102 | ModulePass *createWebAssemblyCoalesceFeaturesAndStripAtomicsLegacyPass( |
| 103 | WebAssemblyTargetMachine &TM); |
| 104 | |
| 105 | // GlobalISel |
| 106 | InstructionSelector * |
| 107 | createWebAssemblyInstructionSelector(const WebAssemblyTargetMachine &, |
| 108 | const WebAssemblySubtarget &, |
| 109 | const WebAssemblyRegisterBankInfo &); |
| 110 | |
| 111 | FunctionPass *createWebAssemblyPostLegalizerCombiner(); |
| 112 | void initializeWebAssemblyPostLegalizerCombinerPass(PassRegistry &); |
| 113 | |
| 114 | FunctionPass *createWebAssemblyPreLegalizerCombiner(); |
| 115 | void initializeWebAssemblyPreLegalizerCombinerPass(PassRegistry &); |
| 116 | |
| 117 | // ISel and immediate followup passes. |
| 118 | class WebAssemblyISelDAGToDAGPass : public SelectionDAGISelPass { |
| 119 | public: |
| 120 | WebAssemblyISelDAGToDAGPass(WebAssemblyTargetMachine &TM, |
| 121 | CodeGenOptLevel OptLevel); |
| 122 | }; |
| 123 | |
| 124 | FunctionPass *createWebAssemblyISelDagLegacyPass(WebAssemblyTargetMachine &TM, |
| 125 | CodeGenOptLevel OptLevel); |
| 126 | |
| 127 | class WebAssemblyArgumentMovePass |
| 128 | : public RequiredPassInfoMixin<WebAssemblyArgumentMovePass> { |
| 129 | public: |
| 130 | PreservedAnalyses run(MachineFunction &MF, |
| 131 | MachineFunctionAnalysisManager &MFAM); |
| 132 | }; |
| 133 | |
| 134 | FunctionPass *createWebAssemblyArgumentMoveLegacyPass(); |
| 135 | |
| 136 | class WebAssemblySetP2AlignOperandsPass |
| 137 | : public RequiredPassInfoMixin<WebAssemblySetP2AlignOperandsPass> { |
| 138 | public: |
| 139 | PreservedAnalyses run(MachineFunction &MF, |
| 140 | MachineFunctionAnalysisManager &MFAM); |
| 141 | }; |
| 142 | |
| 143 | FunctionPass *createWebAssemblySetP2AlignOperandsLegacyPass(); |
| 144 | |
| 145 | class WebAssemblyCleanCodeAfterTrapPass |
| 146 | : public RequiredPassInfoMixin<WebAssemblyCleanCodeAfterTrapPass> { |
| 147 | public: |
| 148 | PreservedAnalyses run(MachineFunction &MF, |
| 149 | MachineFunctionAnalysisManager &MFAM); |
| 150 | }; |
| 151 | |
| 152 | FunctionPass *createWebAssemblyCleanCodeAfterTrapLegacyPass(); |
| 153 | |
| 154 | // Late passes. |
| 155 | class WebAssemblyReplacePhysRegsPass |
| 156 | : public RequiredPassInfoMixin<WebAssemblyReplacePhysRegsPass> { |
| 157 | public: |
| 158 | PreservedAnalyses run(MachineFunction &MF, |
| 159 | MachineFunctionAnalysisManager &MFAM); |
| 160 | }; |
| 161 | |
| 162 | FunctionPass *createWebAssemblyReplacePhysRegsLegacyPass(); |
| 163 | |
| 164 | class WebAssemblyNullifyDebugValueListsPass |
| 165 | : public RequiredPassInfoMixin<WebAssemblyNullifyDebugValueListsPass> { |
| 166 | public: |
| 167 | PreservedAnalyses run(MachineFunction &MF, |
| 168 | MachineFunctionAnalysisManager &MFAM); |
| 169 | }; |
| 170 | |
| 171 | FunctionPass *createWebAssemblyNullifyDebugValueListsLegacyPass(); |
| 172 | FunctionPass *createWebAssemblyOptimizeLiveIntervals(); |
| 173 | FunctionPass *createWebAssemblyMemIntrinsicResults(); |
| 174 | FunctionPass *createWebAssemblyRegStackify(CodeGenOptLevel OptLevel); |
| 175 | FunctionPass *createWebAssemblyRegColoring(); |
| 176 | |
| 177 | class WebAssemblyFixBrTableDefaultsPass |
| 178 | : public RequiredPassInfoMixin<WebAssemblyFixBrTableDefaultsPass> { |
| 179 | public: |
| 180 | PreservedAnalyses run(MachineFunction &MF, |
| 181 | MachineFunctionAnalysisManager &MFAM); |
| 182 | }; |
| 183 | |
| 184 | FunctionPass *createWebAssemblyFixBrTableDefaultsLegacyPass(); |
| 185 | |
| 186 | class WebAssemblyFixIrreducibleControlFlowPass |
| 187 | : public RequiredPassInfoMixin<WebAssemblyFixIrreducibleControlFlowPass> { |
| 188 | public: |
| 189 | PreservedAnalyses run(MachineFunction &MF, |
| 190 | MachineFunctionAnalysisManager &MFAM); |
| 191 | }; |
| 192 | |
| 193 | FunctionPass *createWebAssemblyFixIrreducibleControlFlowLegacyPass(); |
| 194 | |
| 195 | class WebAssemblyLateEHPreparePass |
| 196 | : public RequiredPassInfoMixin<WebAssemblyLateEHPreparePass> { |
| 197 | public: |
| 198 | PreservedAnalyses run(MachineFunction &MF, |
| 199 | MachineFunctionAnalysisManager &MFAM); |
| 200 | }; |
| 201 | |
| 202 | FunctionPass *createWebAssemblyLateEHPrepareLegacyPass(); |
| 203 | FunctionPass *createWebAssemblyCFGSort(); |
| 204 | FunctionPass *createWebAssemblyCFGStackify(); |
| 205 | FunctionPass *createWebAssemblyExplicitLocals(); |
| 206 | FunctionPass *createWebAssemblyLowerBrUnless(); |
| 207 | FunctionPass *createWebAssemblyRegNumbering(); |
| 208 | FunctionPass *createWebAssemblyVecReduce(); |
| 209 | FunctionPass *createWebAssemblyDebugFixup(); |
| 210 | FunctionPass *createWebAssemblyPeephole(); |
| 211 | ModulePass *createWebAssemblyMCLowerPrePass(); |
| 212 | |
| 213 | // PassRegistry initialization declarations. |
| 214 | void initializeWebAssemblyOptimizeReturnedLegacyPass(PassRegistry &); |
| 215 | void initializeWebAssemblyRefTypeMem2LocalLegacyPass(PassRegistry &); |
| 216 | void initializeWebAssemblyAddMissingPrototypesLegacyPass(PassRegistry &); |
| 217 | void initializeWebAssemblyArgumentMoveLegacyPass(PassRegistry &); |
| 218 | void initializeWebAssemblyAsmPrinterPass(PassRegistry &); |
| 219 | void initializeWebAssemblyCleanCodeAfterTrapLegacyPass(PassRegistry &); |
| 220 | void initializeWebAssemblyCFGSortPass(PassRegistry &); |
| 221 | void initializeWebAssemblyCFGStackifyPass(PassRegistry &); |
| 222 | void initializeWebAssemblyDAGToDAGISelLegacyPass(PassRegistry &); |
| 223 | void initializeWebAssemblyDebugFixupPass(PassRegistry &); |
| 224 | void initializeWebAssemblyExceptionInfoPass(PassRegistry &); |
| 225 | void initializeWebAssemblyExplicitLocalsPass(PassRegistry &); |
| 226 | void initializeWebAssemblyFixBrTableDefaultsLegacyPass(PassRegistry &); |
| 227 | void initializeWebAssemblyFixFunctionBitcastsLegacyPass(PassRegistry &); |
| 228 | void initializeWebAssemblyFixIrreducibleControlFlowLegacyPass(PassRegistry &); |
| 229 | void initializeWebAssemblyLateEHPrepareLegacyPass(PassRegistry &); |
| 230 | void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &); |
| 231 | void initializeWebAssemblyLowerEmscriptenEHSjLjLegacyPass(PassRegistry &); |
| 232 | void initializeWebAssemblyMCLowerPrePassPass(PassRegistry &); |
| 233 | void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &); |
| 234 | void initializeWebAssemblyNullifyDebugValueListsLegacyPass(PassRegistry &); |
| 235 | void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &); |
| 236 | void initializeWebAssemblyPeepholePass(PassRegistry &); |
| 237 | void initializeWebAssemblyRegColoringPass(PassRegistry &); |
| 238 | void initializeWebAssemblyRegNumberingPass(PassRegistry &); |
| 239 | void initializeWebAssemblyRegStackifyPass(PassRegistry &); |
| 240 | void initializeWebAssemblyReplacePhysRegsLegacyPass(PassRegistry &); |
| 241 | void initializeWebAssemblySetP2AlignOperandsLegacyPass(PassRegistry &); |
| 242 | void initializeWebAssemblyCoalesceFeaturesAndStripAtomicsLegacyPass( |
| 243 | PassRegistry &); |
| 244 | |
| 245 | namespace WebAssembly { |
| 246 | enum TargetIndex { |
| 247 | // Followed by a local index (ULEB). |
| 248 | TI_LOCAL, |
| 249 | // Followed by an absolute global index (ULEB). DEPRECATED. |
| 250 | TI_GLOBAL_FIXED, |
| 251 | // Followed by the index from the bottom of the Wasm stack. |
| 252 | TI_OPERAND_STACK, |
| 253 | // Followed by a compilation unit relative global index (uint32_t) |
| 254 | // that will have an associated relocation. |
| 255 | TI_GLOBAL_RELOC, |
| 256 | // Like TI_LOCAL, but indicates an indirect value (e.g. byval arg |
| 257 | // passed by pointer). |
| 258 | TI_LOCAL_INDIRECT |
| 259 | }; |
| 260 | } // end namespace WebAssembly |
| 261 | |
| 262 | } // end namespace llvm |
| 263 | |
| 264 | #endif |
| 265 | |