LLVM 20.0.0git
WebAssemblyTargetMachine.cpp
Go to the documentation of this file.
1//===- WebAssemblyTargetMachine.cpp - Define TargetMachine for WebAssembly -==//
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 defines the WebAssembly-specific subclass of TargetMachine.
11///
12//===----------------------------------------------------------------------===//
13
17#include "WebAssembly.h"
24#include "llvm/CodeGen/Passes.h"
27#include "llvm/IR/Function.h"
29#include "llvm/MC/MCAsmInfo.h"
35#include <optional>
36using namespace llvm;
37
38#define DEBUG_TYPE "wasm"
39
40// A command-line option to keep implicit locals
41// for the purpose of testing with lit/llc ONLY.
42// This produces output which is not valid WebAssembly, and is not supported
43// by assemblers/disassemblers and other MC based tools.
45 "wasm-disable-explicit-locals", cl::Hidden,
46 cl::desc("WebAssembly: output implicit locals in"
47 " instruction output for test purposes only."),
48 cl::init(false));
49
51 "wasm-disable-fix-irreducible-control-flow-pass", cl::Hidden,
52 cl::desc("webassembly: disables the fix "
53 " irreducible control flow optimization pass"),
54 cl::init(false));
55
57 // Register the target.
62
63 // Register backend passes
93}
94
95//===----------------------------------------------------------------------===//
96// WebAssembly Lowering public interface.
97//===----------------------------------------------------------------------===//
98
99static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM,
100 const Triple &TT) {
101 if (!RM) {
102 // Default to static relocation model. This should always be more optimial
103 // than PIC since the static linker can determine all global addresses and
104 // assume direct function calls.
105 return Reloc::Static;
106 }
107
108 return *RM;
109}
110
111/// Create an WebAssembly architecture model.
112///
114 const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
115 const TargetOptions &Options, std::optional<Reloc::Model> RM,
116 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
118 T,
119 TT.isArch64Bit()
120 ? (TT.isOSEmscripten() ? "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-"
121 "i128:128-f128:64-n32:64-S128-ni:1:10:20"
122 : "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-"
123 "i128:128-n32:64-S128-ni:1:10:20")
124 : (TT.isOSEmscripten() ? "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-"
125 "i128:128-f128:64-n32:64-S128-ni:1:10:20"
126 : "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-"
127 "i128:128-n32:64-S128-ni:1:10:20"),
128 TT, CPU, FS, Options, getEffectiveRelocModel(RM, TT),
129 getEffectiveCodeModel(CM, CodeModel::Large), OL),
130 TLOF(new WebAssemblyTargetObjectFile()),
131 UsesMultivalueABI(Options.MCOptions.getABIName() == "experimental-mv") {
132 // WebAssembly type-checks instructions, but a noreturn function with a return
133 // type that doesn't match the context will cause a check failure. So we lower
134 // LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
135 // 'unreachable' instructions which is meant for that case. Formerly, we also
136 // needed to add checks to SP failure emission in the instruction selection
137 // backends, but this has since been tied to TrapUnreachable and is no longer
138 // necessary.
139 this->Options.TrapUnreachable = true;
140 this->Options.NoTrapAfterNoreturn = false;
141
142 // WebAssembly treats each function as an independent unit. Force
143 // -ffunction-sections, effectively, so that we can emit them independently.
144 this->Options.FunctionSections = true;
145 this->Options.DataSections = true;
146 this->Options.UniqueSectionNames = true;
147
148 initAsmInfo();
149
150 // Note that we don't use setRequiresStructuredCFG(true). It disables
151 // optimizations than we're ok with, and want, such as critical edge
152 // splitting and tail merging.
153}
154
156
158 return getSubtargetImpl(std::string(getTargetCPU()),
159 std::string(getTargetFeatureString()));
160}
161
164 std::string FS) const {
165 auto &I = SubtargetMap[CPU + FS];
166 if (!I) {
167 I = std::make_unique<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this);
168 }
169 return I.get();
170}
171
174 Attribute CPUAttr = F.getFnAttribute("target-cpu");
175 Attribute FSAttr = F.getFnAttribute("target-features");
176
177 std::string CPU =
178 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
179 std::string FS =
180 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
181
182 // This needs to be done before we create a new subtarget since any
183 // creation will depend on the TM and the code generation flags on the
184 // function that reside in TargetOptions.
186
187 return getSubtargetImpl(CPU, FS);
188}
189
190namespace {
191
192class CoalesceFeaturesAndStripAtomics final : public ModulePass {
193 // Take the union of all features used in the module and use it for each
194 // function individually, since having multiple feature sets in one module
195 // currently does not make sense for WebAssembly. If atomics are not enabled,
196 // also strip atomic operations and thread local storage.
197 static char ID;
199
200public:
201 CoalesceFeaturesAndStripAtomics(WebAssemblyTargetMachine *WasmTM)
202 : ModulePass(ID), WasmTM(WasmTM) {}
203
204 bool runOnModule(Module &M) override {
205 FeatureBitset Features = coalesceFeatures(M);
206
207 std::string FeatureStr = getFeatureString(Features);
208 WasmTM->setTargetFeatureString(FeatureStr);
209 for (auto &F : M)
210 replaceFeatures(F, FeatureStr);
211
212 bool StrippedAtomics = false;
213 bool StrippedTLS = false;
214
215 if (!Features[WebAssembly::FeatureAtomics]) {
216 StrippedAtomics = stripAtomics(M);
217 StrippedTLS = stripThreadLocals(M);
218 } else if (!Features[WebAssembly::FeatureBulkMemory]) {
219 StrippedTLS |= stripThreadLocals(M);
220 }
221
222 if (StrippedAtomics && !StrippedTLS)
223 stripThreadLocals(M);
224 else if (StrippedTLS && !StrippedAtomics)
225 stripAtomics(M);
226
227 recordFeatures(M, Features, StrippedAtomics || StrippedTLS);
228
229 // Conservatively assume we have made some change
230 return true;
231 }
232
233private:
234 FeatureBitset coalesceFeatures(const Module &M) {
235 // Union the features of all defined functions. Start with an empty set, so
236 // that if a feature is disabled in every function, we'll compute it as
237 // disabled. If any function lacks a target-features attribute, it'll
238 // default to the target CPU from the `TargetMachine`.
239 FeatureBitset Features;
240 bool AnyDefinedFuncs = false;
241 for (auto &F : M) {
242 if (F.isDeclaration())
243 continue;
244
245 Features |= WasmTM->getSubtargetImpl(F)->getFeatureBits();
246 AnyDefinedFuncs = true;
247 }
248
249 // If we have no defined functions, use the target CPU from the
250 // `TargetMachine`.
251 if (!AnyDefinedFuncs) {
252 Features =
253 WasmTM
254 ->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
255 std::string(WasmTM->getTargetFeatureString()))
256 ->getFeatureBits();
257 }
258
259 return Features;
260 }
261
262 static std::string getFeatureString(const FeatureBitset &Features) {
263 std::string Ret;
264 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
265 if (Features[KV.Value])
266 Ret += (StringRef("+") + KV.Key + ",").str();
267 else
268 Ret += (StringRef("-") + KV.Key + ",").str();
269 }
270 return Ret;
271 }
272
273 void replaceFeatures(Function &F, const std::string &Features) {
274 F.removeFnAttr("target-features");
275 F.removeFnAttr("target-cpu");
276 F.addFnAttr("target-features", Features);
277 }
278
279 bool stripAtomics(Module &M) {
280 // Detect whether any atomics will be lowered, since there is no way to tell
281 // whether the LowerAtomic pass lowers e.g. stores.
282 bool Stripped = false;
283 for (auto &F : M) {
284 for (auto &B : F) {
285 for (auto &I : B) {
286 if (I.isAtomic()) {
287 Stripped = true;
288 goto done;
289 }
290 }
291 }
292 }
293
294 done:
295 if (!Stripped)
296 return false;
297
298 LowerAtomicPass Lowerer;
300 for (auto &F : M)
301 Lowerer.run(F, FAM);
302
303 return true;
304 }
305
306 bool stripThreadLocals(Module &M) {
307 bool Stripped = false;
308 for (auto &GV : M.globals()) {
309 if (GV.isThreadLocal()) {
310 // replace `@llvm.threadlocal.address.pX(GV)` with `GV`.
311 for (Use &U : make_early_inc_range(GV.uses())) {
312 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U.getUser())) {
313 if (II->getIntrinsicID() == Intrinsic::threadlocal_address &&
314 II->getArgOperand(0) == &GV) {
315 II->replaceAllUsesWith(&GV);
316 II->eraseFromParent();
317 }
318 }
319 }
320
321 Stripped = true;
322 GV.setThreadLocal(false);
323 }
324 }
325 return Stripped;
326 }
327
328 void recordFeatures(Module &M, const FeatureBitset &Features, bool Stripped) {
329 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
330 if (Features[KV.Value]) {
331 // Mark features as used
332 std::string MDKey = (StringRef("wasm-feature-") + KV.Key).str();
333 M.addModuleFlag(Module::ModFlagBehavior::Error, MDKey,
335 }
336 }
337 // Code compiled without atomics or bulk-memory may have had its atomics or
338 // thread-local data lowered to nonatomic operations or non-thread-local
339 // data. In that case, we mark the pseudo-feature "shared-mem" as disallowed
340 // to tell the linker that it would be unsafe to allow this code ot be used
341 // in a module with shared memory.
342 if (Stripped) {
343 M.addModuleFlag(Module::ModFlagBehavior::Error, "wasm-feature-shared-mem",
345 }
346 }
347};
348char CoalesceFeaturesAndStripAtomics::ID = 0;
349
350/// WebAssembly Code Generator Pass Configuration Options.
351class WebAssemblyPassConfig final : public TargetPassConfig {
352public:
353 WebAssemblyPassConfig(WebAssemblyTargetMachine &TM, PassManagerBase &PM)
354 : TargetPassConfig(TM, PM) {}
355
356 WebAssemblyTargetMachine &getWebAssemblyTargetMachine() const {
357 return getTM<WebAssemblyTargetMachine>();
358 }
359
360 FunctionPass *createTargetRegisterAllocator(bool) override;
361
362 void addIRPasses() override;
363 void addISelPrepare() override;
364 bool addInstSelector() override;
365 void addOptimizedRegAlloc() override;
366 void addPostRegAlloc() override;
367 bool addGCPasses() override { return false; }
368 void addPreEmitPass() override;
369 bool addPreISel() override;
370
371 // No reg alloc
372 bool addRegAssignAndRewriteFast() override { return false; }
373
374 // No reg alloc
375 bool addRegAssignAndRewriteOptimized() override { return false; }
376};
377} // end anonymous namespace
378
380 BumpPtrAllocator &Allocator, const Function &F,
381 const TargetSubtargetInfo *STI) const {
382 return WebAssemblyFunctionInfo::create<WebAssemblyFunctionInfo>(Allocator, F,
383 STI);
384}
385
389}
390
393 return new WebAssemblyPassConfig(*this, PM);
394}
395
396FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
397 return nullptr; // No reg alloc
398}
399
405
407
408 // You can't enable two modes of EH at the same time
409 if (WasmEnableEmEH && WasmEnableEH)
411 "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
412 // You can't enable two modes of SjLj at the same time
413 if (WasmEnableEmSjLj && WasmEnableSjLj)
415 "-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
416 // You can't mix Emscripten EH with Wasm SjLj.
417 if (WasmEnableEmEH && WasmEnableSjLj)
419 "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
420 if (WasmEnableExnref && !WasmEnableEH)
422 "-wasm-enable-exnref should be used with -wasm-enable-eh");
423
424 // Here we make sure TargetOptions.ExceptionModel is the same as
425 // MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
426 // stores the exception model info in LangOptions, which is later transferred
427 // to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
428 // clang's LangOptions is not used and thus the exception model info is not
429 // correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
430 // have the correct exception model in WebAssemblyMCAsmInfo constructor. But
431 // in this case TargetOptions is still not updated, so we make sure they are
432 // the same.
433 TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
434
435 // Basic Correctness checking related to -exception-model
436 if (TM->Options.ExceptionModel != ExceptionHandling::None &&
437 TM->Options.ExceptionModel != ExceptionHandling::Wasm)
438 report_fatal_error("-exception-model should be either 'none' or 'wasm'");
439 if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm)
440 report_fatal_error("-exception-model=wasm not allowed with "
441 "-enable-emscripten-cxx-exceptions");
442 if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
444 "-wasm-enable-eh only allowed with -exception-model=wasm");
445 if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
447 "-wasm-enable-sjlj only allowed with -exception-model=wasm");
448 if ((!WasmEnableEH && !WasmEnableSjLj) &&
449 TM->Options.ExceptionModel == ExceptionHandling::Wasm)
451 "-exception-model=wasm only allowed with at least one of "
452 "-wasm-enable-eh or -wasm-enable-sjlj");
453
454 // Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
455 // measure, but some code will error out at compile time in this combination.
456 // See WebAssemblyLowerEmscriptenEHSjLj pass for details.
457}
458
459//===----------------------------------------------------------------------===//
460// The following functions are called from lib/CodeGen/Passes.cpp to modify
461// the CodeGen pass sequence.
462//===----------------------------------------------------------------------===//
463
464void WebAssemblyPassConfig::addIRPasses() {
465 // Add signatures to prototype-less function declarations
467
468 // Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
470
471 // Fix function bitcasts, as WebAssembly requires caller and callee signatures
472 // to match.
474
475 // Optimize "returned" function attributes.
476 if (getOptLevel() != CodeGenOptLevel::None)
478
480
481 // If exception handling is not enabled and setjmp/longjmp handling is
482 // enabled, we lower invokes into calls and delete unreachable landingpad
483 // blocks. Lowering invokes when there is no EH support is done in
484 // TargetPassConfig::addPassesToHandleExceptions, but that runs after these IR
485 // passes and Emscripten SjLj handling expects all invokes to be lowered
486 // before.
487 if (!WasmEnableEmEH && !WasmEnableEH) {
488 addPass(createLowerInvokePass());
489 // The lower invoke pass may create unreachable code. Remove it in order not
490 // to process dead blocks in setjmp/longjmp handling.
492 }
493
494 // Handle exceptions and setjmp/longjmp if enabled. Unlike Wasm EH preparation
495 // done in WasmEHPrepare pass, Wasm SjLj preparation shares libraries and
496 // transformation algorithms with Emscripten SjLj, so we run
497 // LowerEmscriptenEHSjLj pass also when Wasm SjLj is enabled.
498 if (WasmEnableEmEH || WasmEnableEmSjLj || WasmEnableSjLj)
500
501 // Expand indirectbr instructions to switches.
503
505}
506
507void WebAssemblyPassConfig::addISelPrepare() {
508 // We need to move reference type allocas to WASM_ADDRESS_SPACE_VAR so that
509 // loads and stores are promoted to local.gets/local.sets.
511 // Lower atomics and TLS if necessary
512 addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
513
514 // This is a no-op if atomics are not used in the module
516
518}
519
520bool WebAssemblyPassConfig::addInstSelector() {
522 addPass(
523 createWebAssemblyISelDag(getWebAssemblyTargetMachine(), getOptLevel()));
524 // Run the argument-move pass immediately after the ScheduleDAG scheduler
525 // so that we can fix up the ARGUMENT instructions before anything else
526 // sees them in the wrong place.
528 // Set the p2align operands. This information is present during ISel, however
529 // it's inconvenient to collect. Collect it now, and update the immediate
530 // operands.
532
533 // Eliminate range checks and add default targets to br_table instructions.
535
536 // unreachable is terminator, non-terminator instruction after it is not
537 // allowed.
539
540 return false;
541}
542
543void WebAssemblyPassConfig::addOptimizedRegAlloc() {
544 // Currently RegisterCoalesce degrades wasm debug info quality by a
545 // significant margin. As a quick fix, disable this for -O1, which is often
546 // used for debugging large applications. Disabling this increases code size
547 // of Emscripten core benchmarks by ~5%, which is acceptable for -O1, which is
548 // usually not used for production builds.
549 // TODO Investigate why RegisterCoalesce degrades debug info quality and fix
550 // it properly
551 if (getOptLevel() == CodeGenOptLevel::Less)
552 disablePass(&RegisterCoalescerID);
554}
555
556void WebAssemblyPassConfig::addPostRegAlloc() {
557 // TODO: The following CodeGen passes don't currently support code containing
558 // virtual registers. Consider removing their restrictions and re-enabling
559 // them.
560
561 // These functions all require the NoVRegs property.
562 disablePass(&MachineLateInstrsCleanupID);
563 disablePass(&MachineCopyPropagationID);
564 disablePass(&PostRAMachineSinkingID);
565 disablePass(&PostRASchedulerID);
566 disablePass(&FuncletLayoutID);
567 disablePass(&StackMapLivenessID);
568 disablePass(&PatchableFunctionID);
569 disablePass(&ShrinkWrapID);
570 disablePass(&RemoveLoadsIntoFakeUsesID);
571
572 // This pass hurts code size for wasm because it can generate irreducible
573 // control flow.
574 disablePass(&MachineBlockPlacementID);
575
577}
578
579void WebAssemblyPassConfig::addPreEmitPass() {
581
582 // Nullify DBG_VALUE_LISTs that we cannot handle.
584
585 // Eliminate multiple-entry loops.
588
589 // Do various transformations for exception handling.
590 // Every CFG-changing optimizations should come before this.
591 if (TM->Options.ExceptionModel == ExceptionHandling::Wasm)
593
594 // Now that we have a prologue and epilogue and all frame indices are
595 // rewritten, eliminate SP and FP. This allows them to be stackified,
596 // colored, and numbered with the rest of the registers.
598
599 // Preparations and optimizations related to register stackification.
600 if (getOptLevel() != CodeGenOptLevel::None) {
601 // Depend on LiveIntervals and perform some optimizations on it.
603
604 // Prepare memory intrinsic calls for register stackifying.
606
607 // Mark registers as representing wasm's value stack. This is a key
608 // code-compression technique in WebAssembly. We run this pass (and
609 // MemIntrinsicResults above) very late, so that it sees as much code as
610 // possible, including code emitted by PEI and expanded by late tail
611 // duplication.
613
614 // Run the register coloring pass to reduce the total number of registers.
615 // This runs after stackification so that it doesn't consider registers
616 // that become stackified.
618 }
619
620 // Sort the blocks of the CFG into topological order, a prerequisite for
621 // BLOCK and LOOP markers.
622 addPass(createWebAssemblyCFGSort());
623
624 // Insert BLOCK and LOOP markers.
626
627 // Insert explicit local.get and local.set operators.
630
631 // Lower br_unless into br_if.
633
634 // Perform the very last peephole optimizations on the code.
635 if (getOptLevel() != CodeGenOptLevel::None)
636 addPass(createWebAssemblyPeephole());
637
638 // Create a mapping from LLVM CodeGen virtual registers to wasm registers.
640
641 // Fix debug_values whose defs have been stackified.
644
645 // Collect information to prepare for MC lowering / asm printing.
647}
648
649bool WebAssemblyPassConfig::addPreISel() {
652 return false;
653}
654
658}
659
661 const MachineFunction &MF) const {
662 const auto *MFI = MF.getInfo<WebAssemblyFunctionInfo>();
663 return new yaml::WebAssemblyFunctionInfo(MF, *MFI);
664}
665
668 SMDiagnostic &Error, SMRange &SourceRange) const {
669 const auto &YamlMFI = static_cast<const yaml::WebAssemblyFunctionInfo &>(MFI);
670 MachineFunction &MF = PFS.MF;
671 MF.getInfo<WebAssemblyFunctionInfo>()->initializeBaseYamlFields(MF, YamlMFI);
672 return false;
673}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
FunctionAnalysisManager FAM
Basic Register Allocator
Target-Independent Code Generator Pass Configuration Options pass.
This file defines the interfaces that WebAssembly uses to lower LLVM code into a selection DAG.
This file provides WebAssembly-specific target descriptions.
This file declares WebAssembly-specific per-machine-function information.
This file registers the WebAssembly target.
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM, const Triple &TT)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyTarget()
static void basicCheckForEHAndSjLj(TargetMachine *TM)
static cl::opt< bool > WasmDisableExplicitLocals("wasm-disable-explicit-locals", cl::Hidden, cl::desc("WebAssembly: output implicit locals in" " instruction output for test purposes only."), cl::init(false))
static cl::opt< bool > WasmDisableFixIrreducibleControlFlowPass("wasm-disable-fix-irreducible-control-flow-pass", cl::Hidden, cl::desc("webassembly: disables the fix " " irreducible control flow optimization pass"), cl::init(false))
This file declares the WebAssembly-specific subclass of TargetMachine.
This file declares the WebAssembly-specific subclass of TargetLoweringObjectFile.
This file a TargetTransformInfo::Concept conforming object specific to the WebAssembly target machine...
This file contains the declaration of the WebAssembly-specific utility functions.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:253
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:392
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:208
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Container class for subtarget features.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:310
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:48
A pass that lowers atomic intrinsic into non-atomic intrinsics.
PreservedAnalyses run(Function &F, FunctionAnalysisManager &)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition: Pass.h:251
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:281
Represents a range in source code.
Definition: SMLoc.h:48
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:229
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
Definition: TargetMachine.h:96
std::string TargetFS
Definition: TargetMachine.h:98
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
std::string TargetCPU
Definition: TargetMachine.h:97
std::unique_ptr< const MCSubtargetInfo > STI
void setTargetFeatureString(StringRef FS)
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
unsigned UniqueSectionNames
unsigned FunctionSections
Emit functions into separate sections.
unsigned NoTrapAfterNoreturn
Do not emit a trap instruction for 'unreachable' IR instructions behind noreturn calls,...
unsigned DataSections
Emit data into separate sections.
unsigned TrapUnreachable
Emit target-specific trap instruction for 'unreachable' IR instructions.
Target-Independent Code Generator Pass Configuration Options.
virtual void addPostRegAlloc()
This method may be implemented by targets that want to run passes after register allocation pass pipe...
virtual bool addInstSelector()
addInstSelector - This method should install an instruction selector pass, which converts from LLVM c...
virtual bool addPreISel()
Methods with trivial inline returns are convenient points in the common codegen pass pipeline where t...
virtual void addOptimizedRegAlloc()
addOptimizedRegAlloc - Add passes related to register allocation.
virtual void addPreEmitPass()
This pass may be implemented by targets that want to run passes immediately before machine code is em...
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
virtual void addISelPrepare()
Add common passes that perform LLVM IR to IR transforms in preparation for instruction selection.
TargetSubtargetInfo - Generic base class for all target subtargets.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
yaml::MachineFunctionInfo * createDefaultFuncInfoYAML() const override
Allocate and return a default initialized instance of the YAML representation for the MachineFunction...
bool parseMachineFunctionInfo(const yaml::MachineFunctionInfo &, PerFunctionMIParsingState &PFS, SMDiagnostic &Error, SMRange &SourceRange) const override
Parse out the target's MachineFunctionInfo from the YAML reprsentation.
WebAssemblyTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
Create an WebAssembly architecture model.
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
const WebAssemblySubtarget * getSubtargetImpl() const
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
yaml::MachineFunctionInfo * convertFuncInfoToYAML(const MachineFunction &MF) const override
Allocate and initialize an instance of the YAML representation of the MachineFunctionInfo.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
cl::opt< bool > WasmEnableEH
cl::opt< bool > WasmEnableSjLj
cl::opt< bool > WasmEnableExnref
cl::opt< bool > WasmEnableEmEH
cl::opt< bool > WasmEnableEmSjLj
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
@ WASM_FEATURE_PREFIX_USED
Definition: Wasm.h:177
@ WASM_FEATURE_PREFIX_DISALLOWED
Definition: Wasm.h:178
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void initializeOptimizeReturnedPass(PassRegistry &)
FunctionPass * createIndirectBrExpandPass()
void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &)
FunctionPass * createWebAssemblyLowerRefTypesIntPtrConv()
FunctionPass * createWebAssemblyRegNumbering()
FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...
ModulePass * createWebAssemblyAddMissingPrototypes()
char & RegisterCoalescerID
RegisterCoalescer - This pass merges live ranges to eliminate copies.
FunctionPass * createWebAssemblyLateEHPrepare()
const SubtargetFeatureKV WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures]
void initializeWebAssemblyLateEHPreparePass(PassRegistry &)
@ None
No exception support.
@ Wasm
WebAssembly Exception Handling.
FunctionPass * createWebAssemblyFixBrTableDefaults()
void initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &)
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Definition: STLExtras.h:657
char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
void initializeWebAssemblyExceptionInfoPass(PassRegistry &)
char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
char & RemoveLoadsIntoFakeUsesID
RemoveLoadsIntoFakeUses pass.
void initializeWebAssemblyRegNumberingPass(PassRegistry &)
void initializeWebAssemblyLowerRefTypesIntPtrConvPass(PassRegistry &)
void initializeWebAssemblyDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createWebAssemblyReplacePhysRegs()
void initializeWebAssemblyRegColoringPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
FunctionPass * createWebAssemblyMemIntrinsicResults()
char & ShrinkWrapID
ShrinkWrap pass. Look for the best place to insert save and restore.
Definition: ShrinkWrap.cpp:287
char & MachineLateInstrsCleanupID
MachineLateInstrsCleanup - This pass removes redundant identical instructions after register allocati...
FunctionPass * createWebAssemblyDebugFixup()
ModulePass * createLowerGlobalDtorsLegacyPass()
FunctionPass * createLowerInvokePass()
Definition: LowerInvoke.cpp:85
void initializeLowerGlobalDtorsLegacyPassPass(PassRegistry &)
Target & getTheWebAssemblyTarget32()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
void initializeWebAssemblyNullifyDebugValueListsPass(PassRegistry &)
char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
void initializeWebAssemblyFixIrreducibleControlFlowPass(PassRegistry &)
FunctionPass * createWebAssemblyISelDag(WebAssemblyTargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a WebAssembly-specific DAG, ready for instruction scheduling.
char & FuncletLayoutID
This pass lays out funclets contiguously.
void initializeWebAssemblyRegStackifyPass(PassRegistry &)
FunctionPass * createWebAssemblyCFGStackify()
FunctionPass * createWebAssemblyOptimizeLiveIntervals()
char & PostRAMachineSinkingID
This pass perform post-ra machine sink for COPY instructions.
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
FunctionPass * createWebAssemblyOptimizeReturned()
FunctionPass * createWebAssemblyRefTypeMem2Local()
FunctionPass * createWebAssemblyCleanCodeAfterTrap()
void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &)
FunctionPass * createWebAssemblySetP2AlignOperands()
ModulePass * createWebAssemblyLowerEmscriptenEHSjLj()
void initializeWebAssemblyLowerEmscriptenEHSjLjPass(PassRegistry &)
FunctionPass * createWebAssemblyArgumentMove()
FunctionPass * createWebAssemblyExplicitLocals()
Target & getTheWebAssemblyTarget64()
void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &)
void initializeWebAssemblyMCLowerPrePassPass(PassRegistry &)
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &)
FunctionPass * createWebAssemblyFixIrreducibleControlFlow()
ModulePass * createWebAssemblyFixFunctionBitcasts()
FunctionPass * createWebAssemblyLowerBrUnless()
void initializeFixFunctionBitcastsPass(PassRegistry &)
FunctionPass * createWebAssemblyRegColoring()
void initializeWebAssemblyPeepholePass(PassRegistry &)
ModulePass * createWebAssemblyMCLowerPrePass()
void initializeWebAssemblyRefTypeMem2LocalPass(PassRegistry &)
char & MachineBlockPlacementID
MachineBlockPlacement - This pass places basic blocks based on branch probabilities.
FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
FunctionPass * createWebAssemblyRegStackify()
FunctionPass * createWebAssemblyCFGSort()
void initializeWebAssemblyCFGSortPass(PassRegistry &)
void initializeWebAssemblyFixBrTableDefaultsPass(PassRegistry &)
FunctionPass * createWebAssemblyNullifyDebugValueLists()
void initializeWebAssemblyCFGStackifyPass(PassRegistry &)
void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &)
void initializeWebAssemblyDebugFixupPass(PassRegistry &)
char & MachineCopyPropagationID
MachineCopyPropagation - This pass performs copy propagation on machine instructions.
void initializeWebAssemblyArgumentMovePass(PassRegistry &)
FunctionPass * createWebAssemblyPeephole()
void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &)
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
RegisterTargetMachine - Helper template for registering a target machine implementation,...
Used to provide key value pairs for feature and CPU bit flags.
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.