LLVM 23.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"
24using namespace llvm;
25
26#define DEBUG_TYPE "wasm-subtarget"
27
28#define GET_SUBTARGETINFO_CTOR
29#define GET_SUBTARGETINFO_TARGET_DESC
30#include "WebAssemblyGenSubtargetInfo.inc"
31
33WebAssemblySubtarget::initializeSubtargetDependencies(StringRef CPU,
34 StringRef FS) {
35 // Determine default and user-specified characteristics
36 LLVM_DEBUG(llvm::dbgs() << "initializeSubtargetDependencies\n");
37
38 if (CPU.empty())
39 CPU = "generic";
40
41 ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
42
43 // WASIP3 implies using the libcall thread context.
44 if (TargetTriple.getOS() == Triple::WASIp3)
45 HasLibcallThreadContext = true;
46
47 FeatureBitset Bits = getFeatureBits();
48
49 // bulk-memory implies bulk-memory-opt
50 if (HasBulkMemory) {
51 HasBulkMemoryOpt = true;
52 Bits.set(WebAssembly::FeatureBulkMemoryOpt);
53 }
54
55 // gc implies reference-types
56 if (HasGC) {
57 HasReferenceTypes = true;
58 }
59
60 // reference-types implies call-indirect-overlong
61 if (HasReferenceTypes) {
62 HasCallIndirectOverlong = true;
63 Bits.set(WebAssembly::FeatureCallIndirectOverlong);
64 }
65
66 // In case we changed any bits, update `MCSubtargetInfo`'s `FeatureBitset`.
67 setFeatureBits(Bits);
68
69 return *this;
70}
71
73 const std::string &CPU,
74 const std::string &FS,
75 const TargetMachine &TM)
76 : WebAssemblyGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
77 TargetTriple(TT), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
78 TLInfo(TM, *this) {
79 CallLoweringInfo.reset(new WebAssemblyCallLowering(*getTargetLowering()));
80 Legalizer.reset(new WebAssemblyLegalizerInfo(*this));
82 RegBankInfo.reset(RBI);
83
84 InstSelector.reset(createWebAssemblyInstructionSelector(
85 *static_cast<const WebAssemblyTargetMachine *>(&TM), *this, *RBI));
86}
87
89 // If atomics are disabled, atomic ops are lowered instead of expanded
90 return hasAtomics();
91}
92
94 // Disable the MachineScheduler for now. Even with ShouldTrackPressure set and
95 // enableMachineSchedDefaultSched overridden, it appears to have an overall
96 // negative effect for the kinds of register optimizations we're doing.
97 return false;
98}
99
100bool WebAssemblySubtarget::useAA() const { return true; }
101
103 return CallLoweringInfo.get();
104}
105
107 return InstSelector.get();
108}
109
111 return Legalizer.get();
112}
113
115 return RegBankInfo.get();
116}
#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.
Container class for subtarget features.
Holds all the information related to register banks.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
OSType getOS() const
Get the parsed operating system type of this triple.
Definition Triple.h:445
This class provides the information for the WebAssembly target legalizer for GlobalISel.
This class provides the information for the target register banks.
bool enableAtomicExpand() const override
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
WebAssemblySubtarget(const Triple &TT, const std::string &CPU, const std::string &FS, const TargetMachine &TM)
This constructor initializes the data members to match that of the specified triple.
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.
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)