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