LLVM 23.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"
28#include "llvm/CodeGen/Passes.h"
31#include "llvm/IR/Function.h"
39#include <optional>
40using namespace llvm;
41
42#define DEBUG_TYPE "wasm"
43
44// A command-line option to keep implicit locals
45// for the purpose of testing with lit/llc ONLY.
46// This produces output which is not valid WebAssembly, and is not supported
47// by assemblers/disassemblers and other MC based tools.
49 "wasm-disable-explicit-locals", cl::Hidden,
50 cl::desc("WebAssembly: output implicit locals in"
51 " instruction output for test purposes only."),
52 cl::init(false));
53
54// Exception handling & setjmp-longjmp handling related options.
55
56// Emscripten's asm.js-style exception handling
58 "enable-emscripten-cxx-exceptions",
59 cl::desc("WebAssembly Emscripten-style exception handling"),
60 cl::init(false));
61// Emscripten's asm.js-style setjmp/longjmp handling
63 "enable-emscripten-sjlj",
64 cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
65 cl::init(false));
66// Exception handling using wasm EH instructions
68 WebAssembly::WasmEnableEH("wasm-enable-eh",
69 cl::desc("WebAssembly exception handling"));
70// setjmp/longjmp handling using wasm EH instrutions
72 "wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
73// If true, use the legacy Wasm EH proposal:
74// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md
75// And if false, use the standardized Wasm EH proposal:
76// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
77// Currently set to true by default because not all major web browsers turn on
78// the new standard proposal by default, but will later change to false.
80 "wasm-use-legacy-eh", cl::desc("WebAssembly exception handling (legacy)"),
81 cl::init(true));
82
85 // Register the target.
90
91 // Register backend passes
125}
126
127//===----------------------------------------------------------------------===//
128// WebAssembly Lowering public interface.
129//===----------------------------------------------------------------------===//
130
131static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
132 // Default to static relocation model. This should always be more optimial
133 // than PIC since the static linker can determine all global addresses and
134 // assume direct function calls.
135 return RM.value_or(Reloc::Static);
136}
137
142
144
145 // You can't enable two modes of EH at the same time
146 if (WasmEnableEmEH && WasmEnableEH)
148 "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
149 // You can't enable two modes of SjLj at the same time
150 if (WasmEnableEmSjLj && WasmEnableSjLj)
152 "-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
153 // You can't mix Emscripten EH with Wasm SjLj.
154 if (WasmEnableEmEH && WasmEnableSjLj)
156 "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
157
159 // FIXME: These flags should be removed in favor of directly using the
160 // generically configured ExceptionsType
163 }
164
165 // Basic Correctness checking related to -exception-model
168 report_fatal_error("-exception-model should be either 'none' or 'wasm'");
169 if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm)
170 report_fatal_error("-exception-model=wasm not allowed with "
171 "-enable-emscripten-cxx-exceptions");
172 if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
174 "-wasm-enable-eh only allowed with -exception-model=wasm");
175 if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
177 "-wasm-enable-sjlj only allowed with -exception-model=wasm");
178 if ((!WasmEnableEH && !WasmEnableSjLj) &&
181 "-exception-model=wasm only allowed with at least one of "
182 "-wasm-enable-eh or -wasm-enable-sjlj");
183
184 // Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
185 // measure, but some code will error out at compile time in this combination.
186 // See WebAssemblyLowerEmscriptenEHSjLj pass for details.
187}
188
189/// Create an WebAssembly architecture model.
190///
192 const Target &T, const Triple &TT, StringRef CPU, StringRef FS,
193 const TargetOptions &Options, std::optional<Reloc::Model> RM,
194 std::optional<CodeModel::Model> CM, CodeGenOptLevel OL, bool JIT)
195 : CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
197 getEffectiveCodeModel(CM, CodeModel::Large), OL),
198 TLOF(new WebAssemblyTargetObjectFile()),
199 UsesMultivalueABI(Options.MCOptions.getABIName() == "experimental-mv") {
200 // WebAssembly type-checks instructions, but a noreturn function with a return
201 // type that doesn't match the context will cause a check failure. So we lower
202 // LLVM 'unreachable' to ISD::TRAP and then lower that to WebAssembly's
203 // 'unreachable' instructions which is meant for that case. Formerly, we also
204 // needed to add checks to SP failure emission in the instruction selection
205 // backends, but this has since been tied to TrapUnreachable and is no longer
206 // necessary.
207 this->Options.TrapUnreachable = true;
208 this->Options.NoTrapAfterNoreturn = false;
209
210 // WebAssembly treats each function as an independent unit. Force
211 // -ffunction-sections, effectively, so that we can emit them independently.
212 this->Options.FunctionSections = true;
213 this->Options.DataSections = true;
214 this->Options.UniqueSectionNames = true;
215
217 initAsmInfo();
218
220
221 // Note that we don't use setRequiresStructuredCFG(true). It disables
222 // optimizations than we're ok with, and want, such as critical edge
223 // splitting and tail merging.
224}
225
227
232
235 std::string FS) const {
236 auto &I = SubtargetMap[CPU + FS];
237 if (!I) {
238 I = std::make_unique<WebAssemblySubtarget>(TargetTriple, CPU, FS, *this);
239 }
240 return I.get();
241}
242
245 Attribute CPUAttr = F.getFnAttribute("target-cpu");
246 Attribute FSAttr = F.getFnAttribute("target-features");
247
248 std::string CPU =
249 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
250 std::string FS =
251 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
252
253 // This needs to be done before we create a new subtarget since any
254 // creation will depend on the TM and the code generation flags on the
255 // function that reside in TargetOptions.
257
258 return getSubtargetImpl(CPU, FS);
259}
260
261namespace {
262
263class CoalesceFeaturesAndStripAtomics final : public ModulePass {
264 // Take the union of all features used in the module and use it for each
265 // function individually, since having multiple feature sets in one module
266 // currently does not make sense for WebAssembly. If atomics are not enabled,
267 // also strip atomic operations and thread local storage.
268 static char ID;
270
271public:
272 CoalesceFeaturesAndStripAtomics(WebAssemblyTargetMachine *WasmTM)
273 : ModulePass(ID), WasmTM(WasmTM) {}
274
275 bool runOnModule(Module &M) override {
276 FeatureBitset Features = coalesceFeatures(M);
277
278 std::string FeatureStr = getFeatureString(Features);
279 WasmTM->setTargetFeatureString(FeatureStr);
280 for (auto &F : M)
281 replaceFeatures(F, FeatureStr);
282
283 bool StrippedAtomics = false;
284 bool StrippedTLS = false;
285
286 if (!Features[WebAssembly::FeatureAtomics]) {
287 StrippedAtomics = stripAtomics(M);
288 StrippedTLS = stripThreadLocals(M);
289 } else if (!Features[WebAssembly::FeatureBulkMemory]) {
290 StrippedTLS |= stripThreadLocals(M);
291 }
292
293 if (StrippedAtomics && !StrippedTLS)
294 stripThreadLocals(M);
295 else if (StrippedTLS && !StrippedAtomics)
296 stripAtomics(M);
297
298 recordFeatures(M, Features, StrippedAtomics || StrippedTLS);
299
300 // Conservatively assume we have made some change
301 return true;
302 }
303
304private:
305 FeatureBitset coalesceFeatures(const Module &M) {
306 // Union the features of all defined functions. Start with an empty set, so
307 // that if a feature is disabled in every function, we'll compute it as
308 // disabled. If any function lacks a target-features attribute, it'll
309 // default to the target CPU from the `TargetMachine`.
310 FeatureBitset Features;
311 bool AnyDefinedFuncs = false;
312 for (auto &F : M) {
313 if (F.isDeclaration())
314 continue;
315
316 Features |= WasmTM->getSubtargetImpl(F)->getFeatureBits();
317 AnyDefinedFuncs = true;
318 }
319
320 // If we have no defined functions, use the target CPU from the
321 // `TargetMachine`.
322 if (!AnyDefinedFuncs) {
323 Features =
324 WasmTM
325 ->getSubtargetImpl(std::string(WasmTM->getTargetCPU()),
326 std::string(WasmTM->getTargetFeatureString()))
327 ->getFeatureBits();
328 }
329
330 return Features;
331 }
332
333 static std::string getFeatureString(const FeatureBitset &Features) {
334 std::string Ret;
335 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
336 if (Features[KV.Value])
337 Ret += (StringRef("+") + KV.Key + ",").str();
338 else
339 Ret += (StringRef("-") + KV.Key + ",").str();
340 }
341 // remove trailing ','
342 Ret.pop_back();
343 return Ret;
344 }
345
346 void replaceFeatures(Function &F, const std::string &Features) {
347 F.removeFnAttr("target-features");
348 F.removeFnAttr("target-cpu");
349 F.addFnAttr("target-features", Features);
350 }
351
352 bool stripAtomics(Module &M) {
353 // Detect whether any atomics will be lowered, since there is no way to tell
354 // whether the LowerAtomic pass lowers e.g. stores.
355 bool Stripped = false;
356 for (auto &F : M) {
357 for (auto &B : F) {
358 for (auto &I : B) {
359 if (I.isAtomic()) {
360 Stripped = true;
361 goto done;
362 }
363 }
364 }
365 }
366
367 done:
368 if (!Stripped)
369 return false;
370
371 LowerAtomicPass Lowerer;
373 for (auto &F : M)
374 Lowerer.run(F, FAM);
375
376 return true;
377 }
378
379 bool stripThreadLocals(Module &M) {
380 bool Stripped = false;
381 for (auto &GV : M.globals()) {
382 if (GV.isThreadLocal()) {
383 // replace `@llvm.threadlocal.address.pX(GV)` with `GV`.
384 for (Use &U : make_early_inc_range(GV.uses())) {
385 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(U.getUser())) {
386 if (II->getIntrinsicID() == Intrinsic::threadlocal_address &&
387 II->getArgOperand(0) == &GV) {
388 II->replaceAllUsesWith(&GV);
389 II->eraseFromParent();
390 }
391 }
392 }
393
394 Stripped = true;
395 GV.setThreadLocal(false);
396 }
397 }
398 return Stripped;
399 }
400
401 void recordFeatures(Module &M, const FeatureBitset &Features, bool Stripped) {
402 for (const SubtargetFeatureKV &KV : WebAssemblyFeatureKV) {
403 if (Features[KV.Value]) {
404 // Mark features as used
405 std::string MDKey = (StringRef("wasm-feature-") + KV.Key).str();
406 M.addModuleFlag(Module::ModFlagBehavior::Error, MDKey,
408 }
409 }
410 // Code compiled without atomics or bulk-memory may have had its atomics or
411 // thread-local data lowered to nonatomic operations or non-thread-local
412 // data. In that case, we mark the pseudo-feature "shared-mem" as disallowed
413 // to tell the linker that it would be unsafe to allow this code ot be used
414 // in a module with shared memory.
415 if (Stripped) {
416 M.addModuleFlag(Module::ModFlagBehavior::Error, "wasm-feature-shared-mem",
418 }
419 }
420};
421char CoalesceFeaturesAndStripAtomics::ID = 0;
422
423/// WebAssembly Code Generator Pass Configuration Options.
424class WebAssemblyPassConfig final : public TargetPassConfig {
425public:
426 WebAssemblyPassConfig(WebAssemblyTargetMachine &TM, PassManagerBase &PM)
427 : TargetPassConfig(TM, PM) {}
428
429 WebAssemblyTargetMachine &getWebAssemblyTargetMachine() const {
431 }
432
433 FunctionPass *createTargetRegisterAllocator(bool) override;
434
435 void addIRPasses() override;
436 void addISelPrepare() override;
437 bool addInstSelector() override;
438 void addOptimizedRegAlloc() override;
439 void addPostRegAlloc() override;
440 bool addGCPasses() override { return false; }
441 void addPreEmitPass() override;
442 bool addPreISel() override;
443
444 // No reg alloc
445 bool addRegAssignAndRewriteFast() override { return false; }
446
447 // No reg alloc
448 bool addRegAssignAndRewriteOptimized() override { return false; }
449
450 bool addIRTranslator() override;
451 void addPreLegalizeMachineIR() override;
452 bool addLegalizeMachineIR() override;
453 void addPreRegBankSelect() override;
454 bool addRegBankSelect() override;
455 bool addGlobalInstructionSelect() override;
456};
457} // end anonymous namespace
458
465
468 return TargetTransformInfo(std::make_unique<WebAssemblyTTIImpl>(this, F));
469}
470
473 return new WebAssemblyPassConfig(*this, PM);
474}
475
476FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
477 return nullptr; // No reg alloc
478}
479
480//===----------------------------------------------------------------------===//
481// The following functions are called from lib/CodeGen/Passes.cpp to modify
482// the CodeGen pass sequence.
483//===----------------------------------------------------------------------===//
484
485void WebAssemblyPassConfig::addIRPasses() {
486 // Add signatures to prototype-less function declarations
488
489 // Lower .llvm.global_dtors into .llvm.global_ctors with __cxa_atexit calls.
491
492 // Fix function bitcasts, as WebAssembly requires caller and callee signatures
493 // to match.
495
496 // Optimize "returned" function attributes.
497 if (getOptLevel() != CodeGenOptLevel::None)
499
500 // If exception handling is not enabled and setjmp/longjmp handling is
501 // enabled, we lower invokes into calls and delete unreachable landingpad
502 // blocks. Lowering invokes when there is no EH support is done in
503 // TargetPassConfig::addPassesToHandleExceptions, but that runs after these IR
504 // passes and Emscripten SjLj handling expects all invokes to be lowered
505 // before.
506 if (!WasmEnableEmEH && !WasmEnableEH) {
507 addPass(createLowerInvokePass());
508 // The lower invoke pass may create unreachable code. Remove it in order not
509 // to process dead blocks in setjmp/longjmp handling.
511 }
512
513 // Handle exceptions and setjmp/longjmp if enabled. Unlike Wasm EH preparation
514 // done in WasmEHPrepare pass, Wasm SjLj preparation shares libraries and
515 // transformation algorithms with Emscripten SjLj, so we run
516 // LowerEmscriptenEHSjLj pass also when Wasm SjLj is enabled.
517 if (WasmEnableEmEH || WasmEnableEmSjLj || WasmEnableSjLj)
519
520 // Expand indirectbr instructions to switches.
522
523 // Try to expand `vecreduce_{and, or}` into `{any, all}_true`.
524 addPass(createWebAssemblyReduceToAnyAllTrue(getWebAssemblyTargetMachine()));
525
527}
528
529void WebAssemblyPassConfig::addISelPrepare() {
530 // We need to move reference type allocas to WASM_ADDRESS_SPACE_VAR so that
531 // loads and stores are promoted to local.gets/local.sets.
533 // Lower atomics and TLS if necessary
534 addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine()));
535
536 // This is a no-op if atomics are not used in the module
538
540}
541
542bool WebAssemblyPassConfig::addInstSelector() {
544 addPass(
545 createWebAssemblyISelDag(getWebAssemblyTargetMachine(), getOptLevel()));
546 // Run the argument-move pass immediately after the ScheduleDAG scheduler
547 // so that we can fix up the ARGUMENT instructions before anything else
548 // sees them in the wrong place.
550 // Set the p2align operands. This information is present during ISel, however
551 // it's inconvenient to collect. Collect it now, and update the immediate
552 // operands.
554
555 // Eliminate range checks and add default targets to br_table instructions.
557
558 // unreachable is terminator, non-terminator instruction after it is not
559 // allowed.
561
562 return false;
563}
564
565void WebAssemblyPassConfig::addOptimizedRegAlloc() {
566 // Currently RegisterCoalesce degrades wasm debug info quality by a
567 // significant margin. As a quick fix, disable this for -O1, which is often
568 // used for debugging large applications. Disabling this increases code size
569 // of Emscripten core benchmarks by ~5%, which is acceptable for -O1, which is
570 // usually not used for production builds.
571 // TODO Investigate why RegisterCoalesce degrades debug info quality and fix
572 // it properly
573 if (getOptLevel() == CodeGenOptLevel::Less)
574 disablePass(&RegisterCoalescerID);
576}
577
578void WebAssemblyPassConfig::addPostRegAlloc() {
579 // TODO: The following CodeGen passes don't currently support code containing
580 // virtual registers. Consider removing their restrictions and re-enabling
581 // them.
582
583 // These functions all require the NoVRegs property.
584 disablePass(&MachineLateInstrsCleanupID);
585 disablePass(&MachineCopyPropagationID);
586 disablePass(&PostRAMachineSinkingID);
587 disablePass(&PostRASchedulerID);
588 disablePass(&FuncletLayoutID);
589 disablePass(&StackMapLivenessID);
590 disablePass(&PatchableFunctionID);
591 disablePass(&ShrinkWrapID);
592 disablePass(&RemoveLoadsIntoFakeUsesID);
593
594 // This pass hurts code size for wasm because it can generate irreducible
595 // control flow.
596 disablePass(&MachineBlockPlacementID);
597
599}
600
601void WebAssemblyPassConfig::addPreEmitPass() {
603
604 // Nullify DBG_VALUE_LISTs that we cannot handle.
606
607 // Remove any unreachable blocks that may be left floating around.
608 // Rare, but possible. Needed for WebAssemblyFixIrreducibleControlFlow.
610
611 // Eliminate multiple-entry loops.
613
614 // Do various transformations for exception handling.
615 // Every CFG-changing optimizations should come before this.
616 if (TM->Options.ExceptionModel == ExceptionHandling::Wasm)
618
619 // Now that we have a prologue and epilogue and all frame indices are
620 // rewritten, eliminate SP and FP. This allows them to be stackified,
621 // colored, and numbered with the rest of the registers.
623
624 // Preparations and optimizations related to register stackification.
625 if (getOptLevel() != CodeGenOptLevel::None) {
626 // Depend on LiveIntervals and perform some optimizations on it.
628
629 // Prepare memory intrinsic calls for register stackifying.
631 }
632
633 // Mark registers as representing wasm's value stack. This is a key
634 // code-compression technique in WebAssembly. We run this pass (and
635 // MemIntrinsicResults above) very late, so that it sees as much code as
636 // possible, including code emitted by PEI and expanded by late tail
637 // duplication.
638 addPass(createWebAssemblyRegStackify(getOptLevel()));
639
640 if (getOptLevel() != CodeGenOptLevel::None) {
641 // Run the register coloring pass to reduce the total number of registers.
642 // This runs after stackification so that it doesn't consider registers
643 // that become stackified.
645 }
646
647 // Sort the blocks of the CFG into topological order, a prerequisite for
648 // BLOCK and LOOP markers.
649 addPass(createWebAssemblyCFGSort());
650
651 // Insert BLOCK and LOOP markers.
653
654 // Insert explicit local.get and local.set operators.
657
658 // Lower br_unless into br_if.
660
661 // Perform the very last peephole optimizations on the code.
662 if (getOptLevel() != CodeGenOptLevel::None)
663 addPass(createWebAssemblyPeephole());
664
665 // Create a mapping from LLVM CodeGen virtual registers to wasm registers.
667
668 // Fix debug_values whose defs have been stackified.
671
672 // Collect information to prepare for MC lowering / asm printing.
674}
675
676bool WebAssemblyPassConfig::addPreISel() {
679 return false;
680}
681
682bool WebAssemblyPassConfig::addIRTranslator() {
683 addPass(new IRTranslator());
684 return false;
685}
686
687void WebAssemblyPassConfig::addPreLegalizeMachineIR() {
688 if (getOptLevel() != CodeGenOptLevel::None) {
690 }
691}
692bool WebAssemblyPassConfig::addLegalizeMachineIR() {
693 addPass(new Legalizer());
694 return false;
695}
696
697void WebAssemblyPassConfig::addPreRegBankSelect() {
698 if (getOptLevel() != CodeGenOptLevel::None) {
700 }
701}
702
703bool WebAssemblyPassConfig::addRegBankSelect() {
704 addPass(new RegBankSelect());
705 return false;
706}
707
708bool WebAssemblyPassConfig::addGlobalInstructionSelect() {
709 addPass(new InstructionSelect(getOptLevel()));
710
711 // We insert only if ISelDAG won't insert these at a later point.
712 if (isGlobalISelAbortEnabled()) {
717 }
718
719 return false;
720}
721
726
732
735 SMDiagnostic &Error, SMRange &SourceRange) const {
736 const auto &YamlMFI = static_cast<const yaml::WebAssemblyFunctionInfo &>(MFI);
737 MachineFunction &MF = PFS.MF;
738 MF.getInfo<WebAssemblyFunctionInfo>()->initializeBaseYamlFields(MF, YamlMFI);
739 return false;
740}
static Reloc::Model getEffectiveRelocModel()
#define X(NUM, ENUM, NAME)
Definition ELF.h:851
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
DXIL Legalizer
This file declares the IRTranslator pass.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
#define T
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
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))
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:105
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:261
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
This pass is responsible for selecting generic machine instructions to target-specific instructions.
static void setUseExtended(bool Enable)
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...
This pass implements the reg bank selector pass used in the GlobalISel pipeline.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:297
Represents a range in source code.
Definition SMLoc.h:47
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:222
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.
ExceptionHandling ExceptionModel
What exception model to use.
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:189
@ WASM_FEATURE_PREFIX_DISALLOWED
Definition Wasm.h:190
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:643
void initializeWebAssemblyPostLegalizerCombinerPass(PassRegistry &)
void initializeWebAssemblyLateEHPreparePass(PassRegistry &)
@ None
No exception support.
Definition CodeGen.h:54
@ Wasm
WebAssembly Exception Handling.
Definition CodeGen.h:59
FunctionPass * createWebAssemblyFixBrTableDefaults()
void initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &)
FunctionPass * createWebAssemblyReduceToAnyAllTrue(WebAssemblyTargetMachine &TM)
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:633
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 char & UnreachableMachineBlockElimID
UnreachableMachineBlockElimination - This pass removes unreachable machine basic blocks.
LLVM_ABI FunctionPass * createLowerInvokePass()
Target & getTheWebAssemblyTarget32()
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
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.
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 &)
LLVM_ABI void initializeGlobalISel(PassRegistry &)
Initialize all passes linked into the GlobalISel library.
void initializeWebAssemblyPreLegalizerCombinerPass(PassRegistry &)
FunctionPass * createWebAssemblyArgumentMove()
FunctionPass * createWebAssemblyExplicitLocals()
Target & getTheWebAssemblyTarget64()
void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &)
void initializeWebAssemblyMCLowerPrePassPass(PassRegistry &)
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &)
FunctionPass * createWebAssemblyPreLegalizerCombiner()
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()
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
void initializeWebAssemblyCFGSortPass(PassRegistry &)
void initializeWebAssemblyFixBrTableDefaultsPass(PassRegistry &)
FunctionPass * createWebAssemblyPostLegalizerCombiner()
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.