LLVM 24.0.0git
WebAssemblySubtarget.cpp
Go to the documentation of this file.
1//===-- WebAssemblySubtarget.cpp - WebAssembly Subtarget Information ------===//
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 implements the WebAssembly-specific subclass of
11/// TargetSubtarget.
12///
13//===----------------------------------------------------------------------===//
14
20#include "WebAssembly.h"
23#include "llvm/IR/LLVMContext.h"
24#include "llvm/IR/Module.h"
27using namespace llvm;
28
29#define DEBUG_TYPE "wasm-subtarget"
30
31#define GET_SUBTARGETINFO_CTOR
32#define GET_SUBTARGETINFO_TARGET_DESC
33#include "WebAssemblyGenSubtargetInfo.inc"
34
35#define OPTIONS_STRUCT_DEFS
36#include "WebAssemblyOptions.inc"
37
38const WebAssemblyOptions &llvm::getWebAssemblyOptions(const LLVMContext &C) {
39 return C.getLibraryOptions().get<WebAssemblyOptions>();
40}
41
42const WebAssemblyOptions &llvm::getWebAssemblyOptions(const Module &M) {
43 return getWebAssemblyOptions(M.getContext());
44}
45
47WebAssemblySubtarget::initializeSubtargetDependencies(StringRef CPU,
48 StringRef FS) {
49 // Determine default and user-specified characteristics
50 LLVM_DEBUG(llvm::dbgs() << "initializeSubtargetDependencies\n");
51
52 if (CPU.empty())
53 CPU = "generic";
54
55 ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
56
57 // WASIP3 uses cooperative multithreading, which implies using libcall
58 // thread context.
59 if (TargetTriple.getOS() == Triple::WASIp3) {
60 HasCooperativeMultithreading = true;
61 HasLibcallThreadContext = true;
62 }
63
64 return *this;
65}
66
68 StringRef FS,
70 StringRef ABIName)
71 : WebAssemblyGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
72 CLOpts(TM.getCLOpts()), TargetTriple(TT),
73 TargetABI(WebAssembly::getABI(ABIName)),
74 InstrInfo(initializeSubtargetDependencies(CPU, FS)), TLInfo(TM, *this) {
75 CallLoweringInfo.reset(new WebAssemblyCallLowering(*getTargetLowering()));
76 Legalizer.reset(new WebAssemblyLegalizerInfo(*this));
78 RegBankInfo.reset(RBI);
79
80 InstSelector.reset(createWebAssemblyInstructionSelector(
81 *static_cast<const WebAssemblyTargetMachine *>(&TM), *this, *RBI));
82}
83
85 // If atomics are disabled, atomic ops are lowered instead of expanded
86 return hasAtomics();
87}
88
90 // Disable the MachineScheduler for now. Even with ShouldTrackPressure set and
91 // enableMachineSchedDefaultSched overridden, it appears to have an overall
92 // negative effect for the kinds of register optimizations we're doing.
93 return false;
94}
95
96bool WebAssemblySubtarget::useAA() const { return true; }
97
99 return CallLoweringInfo.get();
100}
101
103 return InstSelector.get();
104}
105
107 return Legalizer.get();
108}
109
111 return RegBankInfo.get();
112}
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
Module.h This file contains the declarations for the Module class.
#define LLVM_DEBUG(...)
Definition Debug.h:119
This file describes how to lower LLVM calls to machine code calls.
This file contains the WebAssembly implementation of the TargetInstrInfo class.
This file declares the targeting of the Machinelegalizer class for WebAssembly.
This file provides WebAssembly-specific target descriptions.
This file declares the targeting of the RegisterBankInfo class for WebAssembly.
This file declares the WebAssembly-specific subclass of TargetSubtarget.
This file declares the WebAssembly-specific subclass of TargetMachine.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:76
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
Holds all the information related to register banks.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
OSType getOS() const
Get the parsed operating system type of this triple.
Definition Triple.h:526
This class provides the information for the WebAssembly target legalizer for GlobalISel.
This class provides the information for the target register banks.
WebAssemblySubtarget(const Triple &TT, StringRef CPU, StringRef FS, const WebAssemblyTargetMachine &TM, StringRef ABIName)
This constructor initializes the data members to match that of the specified triple.
bool enableAtomicExpand() const override
const WebAssemblyOptions & getCLOpts() const
const CallLowering * getCallLowering() const override
const WebAssemblyTargetLowering * getTargetLowering() const override
const WebAssemblyRegisterInfo * getRegisterInfo() const override
const RegisterBankInfo * getRegBankInfo() const override
bool enableMachineScheduler() const override
InstructionSelector * getInstructionSelector() const override
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
Parses features string setting specified subtarget options.
const LegalizerInfo * getLegalizerInfo() const override
This is an optimization pass for GlobalISel generic memory operations.
const WebAssemblyOptions & getWebAssemblyOptions(const LLVMContext &C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
InstructionSelector * createWebAssemblyInstructionSelector(const WebAssemblyTargetMachine &TM, const WebAssemblySubtarget &Subtarget, const WebAssemblyRegisterBankInfo &RBI)