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