LLVM 22.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"
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
56// Exception handling & setjmp-longjmp handling related options.
57
58// Emscripten's asm.js-style exception handling
60 "enable-emscripten-cxx-exceptions",
61 cl::desc("WebAssembly Emscripten-style exception handling"),
62 cl::init(false));
63// Emscripten's asm.js-style setjmp/longjmp handling
65 "enable-emscripten-sjlj",
66 cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
67 cl::init(false));
68// Exception handling using wasm EH instructions
70 WebAssembly::WasmEnableEH("wasm-enable-eh",
71 cl::desc("WebAssembly exception handling"));
72// setjmp/longjmp handling using wasm EH instrutions
74 "wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
75// If true, use the legacy Wasm EH proposal:
76// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md
77// And if false, use the standardized Wasm EH proposal:
78// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
79// Currently set to true by default because not all major web browsers turn on
80// the new standard proposal by default, but will later change to false.
82 "wasm-use-legacy-eh", cl::desc("WebAssembly exception handling (legacy)"),
83 cl::init(true));
84
87 // Register the target.
92
93 // Register backend passes
124}
125
126//===----------------------------------------------------------------------===//
127// WebAssembly Lowering public interface.
128//===----------------------------------------------------------------------===//
129
130static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM,
131 const Triple &TT) {
132 if (!RM) {
133 // Default to static relocation model. This should always be more optimial
134 // than PIC since the static linker can determine all global addresses and
135 // assume direct function calls.
136 return Reloc::Static;
137 }
138
139 return *RM;
140}
141
146
148
149 // You can't enable two modes of EH at the same time
150 if (WasmEnableEmEH && WasmEnableEH)
152 "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
153 // You can't enable two modes of SjLj at the same time
154 if (WasmEnableEmSjLj && WasmEnableSjLj)
156 "-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
157 // You can't mix Emscripten EH with Wasm SjLj.
158 if (WasmEnableEmEH && WasmEnableSjLj)
160 "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
161
162 if (TM->Options.ExceptionModel == ExceptionHandling::None) {
163 // FIXME: These flags should be removed in favor of directly using the
164 // generically configured ExceptionsType
166 TM->Options.ExceptionModel = ExceptionHandling::Wasm;
167 }
168
169 // Basic Correctness checking related to -exception-model
170 if (TM->Options.ExceptionModel != ExceptionHandling::None &&
171 TM->Options.ExceptionModel != ExceptionHandling::Wasm)
172 report_fatal_error("-exception-model should be either 'none' or 'wasm'");
173 if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm)
174 report_fatal_error("-exception-model=wasm not allowed with "
175 "-enable-emscripten-cxx-exceptions");
176 if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
178 "-wasm-enable-eh only allowed with -exception-model=wasm");
179 if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
181 "-wasm-enable-sjlj only allowed with -exception-model=wasm");
182 if ((!WasmEnableEH && !WasmEnableSjLj) &&
183 TM->Options.ExceptionModel == ExceptionHandling::Wasm)
185 "-exception-model=wasm only allowed with at least one of "
186 "-wasm-enable-eh or -wasm-enable-sjlj");
187
188 // Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
189 // measure, but some code will error out at compile time in this combination.
190 // See WebAssemblyLowerEmscriptenEHSjLj pass for details.
191}
192
193/// Create an WebAssembly architecture model.
194///
196 const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
197 const TargetOptions &Options, std::optional<Reloc::Model> RM,
198 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
199 : CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
201 getEffectiveCodeModel(CM, CodeModel::Large), OL),
202 TLOF(new WebAssemblyTargetObjectFile()),
203 UsesMultivalueABI(Options.MCOptions.getABIName() == "experimental-mv") {
204 // WebAssembly type-checks instructions, but a noreturn function with a return
205 // type that doesn't match the context will cause a check failure. So we lower
206 // LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
207 // 'unreachable' instructions which is meant for that case. Formerly, we also
208 // needed to add checks to SP failure emission in the instruction selection
209 // backends, but this has since been tied to TrapUnreachable and is no longer
210 // necessary.
211 this->Options.TrapUnreachable = true;
212 this->Options.NoTrapAfterNoreturn = false;
213
214 // WebAssembly treats each function as an independent unit. Force
215 // -ffunction-sections, effectively, so that we can emit them independently.
216 this->Options.FunctionSections = true;
217 this->Options.DataSections = true;
218 this->Options.UniqueSectionNames = true;
219
220 initAsmInfo();
222 // Note that we don't use setRequiresStructuredCFG(true). It disables
223 // optimizations than we're ok with, and want, such as critical edge
224 // splitting and tail merging.
225}
226
228
233
236 std::string FS) const {
237 auto &I = SubtargetMap[CPU + FS];
238 if (!I) {
239 I = std::make_unique<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this);
240 }
241 return I.get();
242}
243
246 Attribute CPUAttr = F.getFnAttribute("target-cpu");
247 Attribute FSAttr = F.getFnAttribute("target-features");
248
249 std::string CPU =
250 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
251 std::string FS =
252 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
253
254 // This needs to be done before we create a new subtarget since any
255 // creation will depend on the TM and the code generation flags on the
256 // function that reside in TargetOptions.
258
259 return getSubtargetImpl(CPU, FS);
260}
261
262namespace {
263
264class CoalesceFeaturesAndStripAtomics final : public ModulePass {
265 // Take the union of all features used in the module and use it for each
266 // function individually, since having multiple feature sets in one module
267 // currently does not make sense for WebAssembly. If atomics are not enabled,
268 // also strip atomic operations and thread local storage.
269 static char ID;
271
272public:
273 CoalesceFeaturesAndStripAtomics(WebAssemblyTargetMachine *WasmTM)
274 : ModulePass(ID), WasmTM(WasmTM) {}
275
276 bool runOnModule(Module &M) override {
277 FeatureBitset Features = coalesceFeatures(M);
278
279 std::string FeatureStr = getFeatureString(Features);
280 WasmTM->setTargetFeatureString(FeatureStr);
281 for (auto &F : M)
282 replaceFeatures(F, FeatureStr);
283
284 bool StrippedAtomics = false;
285 bool StrippedTLS = false;
286
287 if (!Features[WebAssembly::FeatureAtomics]) {
288 StrippedAtomics = stripAtomics(M);
289 StrippedTLS = stripThreadLocals(M);
290 } else if (!Features[WebAssembly::FeatureBulkMemory]) {
291 StrippedTLS |= stripThreadLocals(M);
292 }
293
294 if (StrippedAtomics && !StrippedTLS)
295 stripThreadLocals(M);
296 else if (StrippedTLS && !StrippedAtomics)
297 stripAtomics(M);
298
299 recordFeatures(M, Features, StrippedAtomics || StrippedTLS);
300
301 // Conservatively assume we have made some change
302 return true;
303 }
304
305private:
306 FeatureBitset coalesceFeatures(const Module &M) {
307 // Union the features of all defined functions. Start with an empty set, so
308 // that if a feature is disabled in every function, we'll compute it as
309 // disabled. If any function lacks a target-features attribute, it'll
310 // default to the target CPU from the `TargetMachine`.
311 FeatureBitset Features;
312 bool AnyDefinedFuncs = false;
313 for (auto &F : M) {
314 if (F.isDeclaration())
315 continue;
316
317 Features |= WasmTM->getSubtargetImpl(F)->getFeatureBits();
318 AnyDefinedFuncs = true;
319 }
320
321 // If we have no defined functions, use the target CPU from the
322 // `TargetMachine`.
323 if (!AnyDefinedFuncs) {
324 Features =
325 WasmTM
326 ->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
327 std::string(WasmTM->getTargetFeatureString()))
328 ->getFeatureBits();
329 }
330
331 return Features;
332 }
333
334 static std::string getFeatureString(const FeatureBitset &Features) {
335 std::string Ret;
336 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
337 if (Features[KV.Value])
338 Ret += (StringRef("+") + KV.Key + ",").str();
339 else
340 Ret += (StringRef("-") + KV.Key + ",").str();
341 }
342 return Ret;
343 }
344
345 void replaceFeatures(Function &F, const std::string &Features) {
346 F.removeFnAttr("target-features");
347 F.removeFnAttr("target-cpu");
348 F.addFnAttr("target-features", Features);
349 }
350
351 bool stripAtomics(Module &M) {
352 // Detect whether any atomics will be lowered, since there is no way to tell
353 // whether the LowerAtomic pass lowers e.g. stores.
354 bool Stripped = false;
355 for (auto &F : M) {
356 for (auto &B : F) {
357 for (auto &I : B) {
358 if (I.isAtomic()) {
359 Stripped = true;
360 goto done;
361 }
362 }
363 }
364 }
365
366 done:
367 if (!Stripped)
368 return false;
369
370 LowerAtomicPass Lowerer;
372 for (auto &F : M)
373 Lowerer.run(F, FAM);
374
375 return true;
376 }
377
378 bool stripThreadLocals(Module &M) {
379 bool Stripped = false;
380 for (auto &GV : M.globals()) {
381 if (GV.isThreadLocal()) {
382 // replace `@llvm.threadlocal.address.pX(GV)` with `GV`.
383 for (Use &U : make_early_inc_range(GV.uses())) {
384 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U.getUser())) {
385 if (II->getIntrinsicID() == Intrinsic::threadlocal_address &&
386 II->getArgOperand(0) == &GV) {
387 II->replaceAllUsesWith(&GV);
388 II->eraseFromParent();
389 }
390 }
391 }
392
393 Stripped = true;
394 GV.setThreadLocal(false);
395 }
396 }
397 return Stripped;
398 }
399
400 void recordFeatures(Module &M, const FeatureBitset &Features, bool Stripped) {
401 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
402 if (Features[KV.Value]) {
403 // Mark features as used
404 std::string MDKey = (StringRef("wasm-feature-") + KV.Key).str();
405 M.addModuleFlag(Module::ModFlagBehavior::Error, MDKey,
407 }
408 }
409 // Code compiled without atomics or bulk-memory may have had its atomics or
410 // thread-local data lowered to nonatomic operations or non-thread-local
411 // data. In that case, we mark the pseudo-feature "shared-mem" as disallowed
412 // to tell the linker that it would be unsafe to allow this code ot be used
413 // in a module with shared memory.
414 if (Stripped) {
415 M.addModuleFlag(Module::ModFlagBehavior::Error, "wasm-feature-shared-mem",
417 }
418 }
419};
420char CoalesceFeaturesAndStripAtomics::ID = 0;
421
422/// WebAssembly Code Generator Pass Configuration Options.
423class WebAssemblyPassConfig final : public TargetPassConfig {
424public:
425 WebAssemblyPassConfig(WebAssemblyTargetMachine &TM, PassManagerBase &PM)
426 : TargetPassConfig(TM, PM) {}
427
428 WebAssemblyTargetMachine &getWebAssemblyTargetMachine() const {
430 }
431
432 FunctionPass *createTargetRegisterAllocator(bool) override;
433
434 void addIRPasses() override;
435 void addISelPrepare() override;
436 bool addInstSelector() override;
437 void addOptimizedRegAlloc() override;
438 void addPostRegAlloc() override;
439 bool addGCPasses() override { return false; }
440 void addPreEmitPass() override;
441 bool addPreISel() override;
442
443 // No reg alloc
444 bool addRegAssignAndRewriteFast() override { return false; }
445
446 // No reg alloc
447 bool addRegAssignAndRewriteOptimized() override { return false; }
448};
449} // end anonymous namespace
450
457
460 return TargetTransformInfo(std::make_unique<WebAssemblyTTIImpl>(this, F));
461}
462
465 return new WebAssemblyPassConfig(*this, PM);
466}
467
468FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
469 return nullptr; // No reg alloc
470}
471
472//===----------------------------------------------------------------------===//
473// The following functions are called from lib/CodeGen/Passes.cpp to modify
474// the CodeGen pass sequence.
475//===----------------------------------------------------------------------===//
476
477void WebAssemblyPassConfig::addIRPasses() {
478 // Add signatures to prototype-less function declarations
480
481 // Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
483
484 // Fix function bitcasts, as WebAssembly requires caller and callee signatures
485 // to match.
487
488 // Optimize "returned" function attributes.
489 if (getOptLevel() != CodeGenOptLevel::None)
491
492 // If exception handling is not enabled and setjmp/longjmp handling is
493 // enabled, we lower invokes into calls and delete unreachable landingpad
494 // blocks. Lowering invokes when there is no EH support is done in
495 // TargetPassConfig::addPassesToHandleExceptions, but that runs after these IR
496 // passes and Emscripten SjLj handling expects all invokes to be lowered
497 // before.
498 if (!WasmEnableEmEH && !WasmEnableEH) {
499 addPass(createLowerInvokePass());
500 // The lower invoke pass may create unreachable code. Remove it in order not
501 // to process dead blocks in setjmp/longjmp handling.
503 }
504
505 // Handle exceptions and setjmp/longjmp if enabled. Unlike Wasm EH preparation
506 // done in WasmEHPrepare pass, Wasm SjLj preparation shares libraries and
507 // transformation algorithms with Emscripten SjLj, so we run
508 // LowerEmscriptenEHSjLj pass also when Wasm SjLj is enabled.
509 if (WasmEnableEmEH || WasmEnableEmSjLj || WasmEnableSjLj)
511
512 // Expand indirectbr instructions to switches.
514
516}
517
518void WebAssemblyPassConfig::addISelPrepare() {
519 // We need to move reference type allocas to WASM_ADDRESS_SPACE_VAR so that
520 // loads and stores are promoted to local.gets/local.sets.
522 // Lower atomics and TLS if necessary
523 addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
524
525 // This is a no-op if atomics are not used in the module
527
529}
530
531bool WebAssemblyPassConfig::addInstSelector() {
533 addPass(
534 createWebAssemblyISelDag(getWebAssemblyTargetMachine(), getOptLevel()));
535 // Run the argument-move pass immediately after the ScheduleDAG scheduler
536 // so that we can fix up the ARGUMENT instructions before anything else
537 // sees them in the wrong place.
539 // Set the p2align operands. This information is present during ISel, however
540 // it's inconvenient to collect. Collect it now, and update the immediate
541 // operands.
543
544 // Eliminate range checks and add default targets to br_table instructions.
546
547 // unreachable is terminator, non-terminator instruction after it is not
548 // allowed.
550
551 return false;
552}
553
554void WebAssemblyPassConfig::addOptimizedRegAlloc() {
555 // Currently RegisterCoalesce degrades wasm debug info quality by a
556 // significant margin. As a quick fix, disable this for -O1, which is often
557 // used for debugging large applications. Disabling this increases code size
558 // of Emscripten core benchmarks by ~5%, which is acceptable for -O1, which is
559 // usually not used for production builds.
560 // TODO Investigate why RegisterCoalesce degrades debug info quality and fix
561 // it properly
562 if (getOptLevel() == CodeGenOptLevel::Less)
563 disablePass(&RegisterCoalescerID);
565}
566
567void WebAssemblyPassConfig::addPostRegAlloc() {
568 // TODO: The following CodeGen passes don't currently support code containing
569 // virtual registers. Consider removing their restrictions and re-enabling
570 // them.
571
572 // These functions all require the NoVRegs property.
573 disablePass(&MachineLateInstrsCleanupID);
574 disablePass(&MachineCopyPropagationID);
575 disablePass(&PostRAMachineSinkingID);
576 disablePass(&PostRASchedulerID);
577 disablePass(&FuncletLayoutID);
578 disablePass(&StackMapLivenessID);
579 disablePass(&PatchableFunctionID);
580 disablePass(&ShrinkWrapID);
581 disablePass(&RemoveLoadsIntoFakeUsesID);
582
583 // This pass hurts code size for wasm because it can generate irreducible
584 // control flow.
585 disablePass(&MachineBlockPlacementID);
586
588}
589
590void WebAssemblyPassConfig::addPreEmitPass() {
592
593 // Nullify DBG_VALUE_LISTs that we cannot handle.
595
596 // Eliminate multiple-entry loops.
599
600 // Do various transformations for exception handling.
601 // Every CFG-changing optimizations should come before this.
602 if (TM->Options.ExceptionModel == ExceptionHandling::Wasm)
604
605 // Now that we have a prologue and epilogue and all frame indices are
606 // rewritten, eliminate SP and FP. This allows them to be stackified,
607 // colored, and numbered with the rest of the registers.
609
610 // Preparations and optimizations related to register stackification.
611 if (getOptLevel() != CodeGenOptLevel::None) {
612 // Depend on LiveIntervals and perform some optimizations on it.
614
615 // Prepare memory intrinsic calls for register stackifying.
617 }
618
619 // Mark registers as representing wasm's value stack. This is a key
620 // code-compression technique in WebAssembly. We run this pass (and
621 // MemIntrinsicResults above) very late, so that it sees as much code as
622 // possible, including code emitted by PEI and expanded by late tail
623 // duplication.
624 addPass(createWebAssemblyRegStackify(getOptLevel()));
625
626 if (getOptLevel() != CodeGenOptLevel::None) {
627 // Run the register coloring pass to reduce the total number of registers.
628 // This runs after stackification so that it doesn't consider registers
629 // that become stackified.
631 }
632
633 // Sort the blocks of the CFG into topological order, a prerequisite for
634 // BLOCK and LOOP markers.
635 addPass(createWebAssemblyCFGSort());
636
637 // Insert BLOCK and LOOP markers.
639
640 // Insert explicit local.get and local.set operators.
643
644 // Lower br_unless into br_if.
646
647 // Perform the very last peephole optimizations on the code.
648 if (getOptLevel() != CodeGenOptLevel::None)
649 addPass(createWebAssemblyPeephole());
650
651 // Create a mapping from LLVM CodeGen virtual registers to wasm registers.
653
654 // Fix debug_values whose defs have been stackified.
657
658 // Collect information to prepare for MC lowering / asm printing.
660}
661
662bool WebAssemblyPassConfig::addPreISel() {
665 return false;
666}
667
672
678
681 SMDiagnostic &Error, SMRange &SourceRange) const {
682 const auto &YamlMFI = static_cast<const yaml::WebAssemblyFunctionInfo &>(MFI);
683 MachineFunction &MF = PFS.MF;
684 MF.getInfo<WebAssemblyFunctionInfo>()->initializeBaseYamlFields(MF, YamlMFI);
685 return false;
686}
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:213
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
Machine Check Debug Module
#define T
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
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.
LLVM_ABI 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 TargetTransformInfoImplBase 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.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:69
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:223
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Container class for subtarget features.
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
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:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
static LLVM_ABI 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:282
Represents a range in source code.
Definition SMLoc.h:48
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:233
Primary interface to the complete machine description for the target machine.
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
StringRef getTargetFeatureString() const
StringRef getTargetCPU() const
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void setTargetFeatureString(StringRef FS)
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
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:47
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 > WasmUseLegacyEH
cl::opt< bool > WasmEnableEH
cl::opt< bool > WasmEnableSjLj
cl::opt< bool > WasmEnableEmEH
cl::opt< bool > WasmEnableEmSjLj
initializer< Ty > init(const Ty &Val)
@ WASM_FEATURE_PREFIX_USED
Definition Wasm.h:180
@ WASM_FEATURE_PREFIX_DISALLOWED
Definition Wasm.h:181
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI ModulePass * createLowerGlobalDtorsLegacyPass()
void initializeOptimizeReturnedPass(PassRegistry &)
LLVM_ABI FunctionPass * createIndirectBrExpandPass()
void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &)
FunctionPass * createWebAssemblyLowerRefTypesIntPtrConv()
FunctionPass * createWebAssemblyRegNumbering()
ModulePass * createWebAssemblyAddMissingPrototypes()
LLVM_ABI char & RegisterCoalescerID
RegisterCoalescer - This pass merges live ranges to eliminate copies.
FunctionPass * createWebAssemblyLateEHPrepare()
const SubtargetFeatureKV WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures]
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:649
void initializeWebAssemblyLateEHPreparePass(PassRegistry &)
@ None
No exception support.
Definition CodeGen.h:54
@ Wasm
WebAssembly Exception Handling.
Definition CodeGen.h:59
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:634
LLVM_ABI char & PatchableFunctionID
This pass implements the "patchable-function" attribute.
void initializeWebAssemblyExceptionInfoPass(PassRegistry &)
LLVM_ABI char & PostRASchedulerID
PostRAScheduler - This pass performs post register allocation scheduling.
LLVM_ABI char & RemoveLoadsIntoFakeUsesID
RemoveLoadsIntoFakeUses pass.
void initializeWebAssemblyRegNumberingPass(PassRegistry &)
void initializeWebAssemblyLowerRefTypesIntPtrConvPass(PassRegistry &)
void initializeWebAssemblyDAGToDAGISelLegacyPass(PassRegistry &)
FunctionPass * createWebAssemblyRegStackify(CodeGenOptLevel OptLevel)
FunctionPass * createWebAssemblyReplacePhysRegs()
void initializeWebAssemblyRegColoringPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
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()
LLVM_ABI char & ShrinkWrapID
ShrinkWrap pass. Look for the best place to insert save and restore.
LLVM_ABI char & MachineLateInstrsCleanupID
MachineLateInstrsCleanup - This pass removes redundant identical instructions after register allocati...
FunctionPass * createWebAssemblyDebugFixup()
LLVM_ABI FunctionPass * createLowerInvokePass()
Target & getTheWebAssemblyTarget32()
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
void initializeWebAssemblyNullifyDebugValueListsPass(PassRegistry &)
LLVM_ABI char & StackMapLivenessID
StackMapLiveness - This pass analyses the register live-out set of stackmap/patchpoint intrinsics and...
LLVM_ABI void initializeLowerGlobalDtorsLegacyPassPass(PassRegistry &)
void initializeWebAssemblyFixIrreducibleControlFlowPass(PassRegistry &)
FunctionPass * createWebAssemblyISelDag(WebAssemblyTargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a WebAssembly-specific DAG, ready for instruction scheduling.
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
void initializeWebAssemblyRegStackifyPass(PassRegistry &)
FunctionPass * createWebAssemblyCFGStackify()
FunctionPass * createWebAssemblyOptimizeLiveIntervals()
LLVM_ABI char & PostRAMachineSinkingID
This pass perform post-ra machine sink for COPY instructions.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
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 &)
LLVM_ABI char & MachineBlockPlacementID
MachineBlockPlacement - This pass places basic blocks based on branch probabilities.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
FunctionPass * createWebAssemblyCFGSort()
void initializeWebAssemblyCFGSortPass(PassRegistry &)
void initializeWebAssemblyFixBrTableDefaultsPass(PassRegistry &)
FunctionPass * createWebAssemblyNullifyDebugValueLists()
void initializeWebAssemblyAsmPrinterPass(PassRegistry &)
void initializeWebAssemblyCFGStackifyPass(PassRegistry &)
void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &)
void initializeWebAssemblyDebugFixupPass(PassRegistry &)
LLVM_ABI char & MachineCopyPropagationID
MachineCopyPropagation - This pass performs copy propagation on machine instructions.
void initializeWebAssemblyArgumentMovePass(PassRegistry &)
LLVM_ABI FunctionPass * createUnreachableBlockEliminationPass()
createUnreachableBlockEliminationPass - The LLVM code generator does not work well with unreachable b...
FunctionPass * createWebAssemblyPeephole()
void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &)
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
RegisterTargetMachine - Helper template for registering a target machine implementation,...
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.