1//=- WebAssemblySubtarget.h - Define Subtarget for the WebAssembly -*- C++ -*-//
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 declares the WebAssembly-specific subclass of
11/// TargetSubtarget.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
17
18#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
19#include "WebAssemblyFrameLowering.h"
20#include "WebAssemblyISelLowering.h"
21#include "WebAssemblyInstrInfo.h"
22#include "WebAssemblySelectionDAGInfo.h"
23#include "WebAssemblyUtilities.h"
24#include "llvm/CodeGen/GlobalISel/CallLowering.h"
25#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
26#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
27#include "llvm/CodeGen/RegisterBankInfo.h"
28#include "llvm/CodeGen/TargetSubtargetInfo.h"
29#include <string>
30
31#define GET_SUBTARGETINFO_HEADER
32#include "WebAssemblyGenSubtargetInfo.inc"
33
34namespace llvm {
35
36class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
37 enum SIMDEnum {
38 NoSIMD,
39 SIMD128,
40 RelaxedSIMD,
41 } SIMDLevel = NoSIMD;
42
43 bool HasAtomics = false;
44 bool HasBulkMemory = false;
45 bool HasBulkMemoryOpt = false;
46 bool HasCallIndirectOverlong = false;
47 bool HasCompactImports = false;
48 bool HasExceptionHandling = false;
49 bool HasExtendedConst = false;
50 bool HasFP16 = false;
51 bool HasGC = false;
52 bool HasCooperativeMultithreading = false;
53 bool HasLibcallThreadContext = false;
54 bool HasMultiMemory = false;
55 bool HasMultivalue = false;
56 bool HasMutableGlobals = false;
57 bool HasNontrappingFPToInt = false;
58 bool HasReferenceTypes = false;
59 bool HasRelaxedAtomics = false;
60 bool HasSignExt = false;
61 bool HasTailCall = false;
62 bool HasWideArithmetic = false;
63
64 /// What processor and OS we're targeting.
65 Triple TargetTriple;
66
67 /// The ABI in use.
68 WebAssembly::WebAssemblyABI TargetABI = WebAssembly::WebAssemblyABI::MVP;
69
70 WebAssemblyFrameLowering FrameLowering;
71 WebAssemblyInstrInfo InstrInfo;
72 WebAssemblySelectionDAGInfo TSInfo;
73 WebAssemblyTargetLowering TLInfo;
74
75 std::unique_ptr<CallLowering> CallLoweringInfo;
76 std::unique_ptr<InstructionSelector> InstSelector;
77 std::unique_ptr<LegalizerInfo> Legalizer;
78 std::unique_ptr<RegisterBankInfo> RegBankInfo;
79
80 WebAssemblySubtarget &initializeSubtargetDependencies(StringRef CPU,
81 StringRef FS);
82
83public:
84 /// This constructor initializes the data members to match that
85 /// of the specified triple.
86 WebAssemblySubtarget(const Triple &TT, StringRef CPU, StringRef FS,
87 const TargetMachine &TM, StringRef ABIName);
88
89 const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
90 return &TSInfo;
91 }
92 const WebAssemblyFrameLowering *getFrameLowering() const override {
93 return &FrameLowering;
94 }
95 const WebAssemblyTargetLowering *getTargetLowering() const override {
96 return &TLInfo;
97 }
98 const WebAssemblyInstrInfo *getInstrInfo() const override {
99 return &InstrInfo;
100 }
101 const WebAssemblyRegisterInfo *getRegisterInfo() const override {
102 return &getInstrInfo()->getRegisterInfo();
103 }
104 const Triple &getTargetTriple() const { return TargetTriple; }
105 bool enableAtomicExpand() const override;
106 bool enableIndirectBrExpand() const override { return true; }
107 bool enableMachineScheduler() const override;
108 bool useAA() const override;
109
110 // Predicates used by WebAssemblyInstrInfo.td.
111 bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
112 bool hasAtomics() const { return HasAtomics; }
113 bool hasBulkMemory() const { return HasBulkMemory; }
114 bool hasBulkMemoryOpt() const { return HasBulkMemoryOpt; }
115 bool hasCallIndirectOverlong() const { return HasCallIndirectOverlong; }
116 bool hasCompactImports() const { return HasCompactImports; }
117 bool hasExceptionHandling() const { return HasExceptionHandling; }
118 bool hasExtendedConst() const { return HasExtendedConst; }
119 bool hasFP16() const { return HasFP16; }
120 bool hasGC() const { return HasGC; }
121 bool hasCooperativeMultithreading() const {
122 return HasCooperativeMultithreading;
123 }
124 bool hasLibcallThreadContext() const { return HasLibcallThreadContext; }
125 bool hasMultiMemory() const { return HasMultiMemory; }
126 bool hasMultivalue() const { return HasMultivalue; }
127 bool hasMutableGlobals() const { return HasMutableGlobals; }
128 bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
129 bool hasReferenceTypes() const { return HasReferenceTypes; }
130 bool hasRelaxedAtomics() const { return HasRelaxedAtomics; }
131 bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
132 bool hasSignExt() const { return HasSignExt; }
133 bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
134 bool hasTailCall() const { return HasTailCall; }
135 bool hasWideArithmetic() const { return HasWideArithmetic; }
136
137 bool usesMultivalueABI() const {
138 return TargetABI == WebAssembly::WebAssemblyABI::ExperimentalMV;
139 }
140
141 /// Parses features string setting specified subtarget options. Definition of
142 /// function is auto generated by tblgen.
143 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
144
145 const CallLowering *getCallLowering() const override;
146 InstructionSelector *getInstructionSelector() const override;
147 const LegalizerInfo *getLegalizerInfo() const override;
148 const RegisterBankInfo *getRegBankInfo() const override;
149};
150
151} // end namespace llvm
152
153#endif
154