xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //=- WebAssemblySubtarget.h - Define Subtarget for the WebAssembly -*- C++ -*-//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric ///
9*0b57cec5SDimitry Andric /// \file
10*0b57cec5SDimitry Andric /// This file declares the WebAssembly-specific subclass of
11*0b57cec5SDimitry Andric /// TargetSubtarget.
12*0b57cec5SDimitry Andric ///
13*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
14*0b57cec5SDimitry Andric 
15*0b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
16*0b57cec5SDimitry Andric #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric #include "WebAssemblyFrameLowering.h"
19*0b57cec5SDimitry Andric #include "WebAssemblyISelLowering.h"
20*0b57cec5SDimitry Andric #include "WebAssemblyInstrInfo.h"
21*0b57cec5SDimitry Andric #include "WebAssemblySelectionDAGInfo.h"
22*0b57cec5SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
23*0b57cec5SDimitry Andric #include <string>
24*0b57cec5SDimitry Andric 
25*0b57cec5SDimitry Andric #define GET_SUBTARGETINFO_ENUM
26*0b57cec5SDimitry Andric #define GET_SUBTARGETINFO_HEADER
27*0b57cec5SDimitry Andric #include "WebAssemblyGenSubtargetInfo.inc"
28*0b57cec5SDimitry Andric 
29*0b57cec5SDimitry Andric namespace llvm {
30*0b57cec5SDimitry Andric 
31*0b57cec5SDimitry Andric // Defined in WebAssemblyGenSubtargetInfo.inc.
32*0b57cec5SDimitry Andric extern const SubtargetFeatureKV
33*0b57cec5SDimitry Andric     WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures];
34*0b57cec5SDimitry Andric 
35*0b57cec5SDimitry Andric class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
36*0b57cec5SDimitry Andric   enum SIMDEnum {
37*0b57cec5SDimitry Andric     NoSIMD,
38*0b57cec5SDimitry Andric     SIMD128,
39*0b57cec5SDimitry Andric     UnimplementedSIMD128,
40*0b57cec5SDimitry Andric   } SIMDLevel = NoSIMD;
41*0b57cec5SDimitry Andric 
42*0b57cec5SDimitry Andric   bool HasAtomics = false;
43*0b57cec5SDimitry Andric   bool HasNontrappingFPToInt = false;
44*0b57cec5SDimitry Andric   bool HasSignExt = false;
45*0b57cec5SDimitry Andric   bool HasExceptionHandling = false;
46*0b57cec5SDimitry Andric   bool HasBulkMemory = false;
47*0b57cec5SDimitry Andric   bool HasMultivalue = false;
48*0b57cec5SDimitry Andric   bool HasMutableGlobals = false;
49*0b57cec5SDimitry Andric   bool HasTailCall = false;
50*0b57cec5SDimitry Andric 
51*0b57cec5SDimitry Andric   /// String name of used CPU.
52*0b57cec5SDimitry Andric   std::string CPUString;
53*0b57cec5SDimitry Andric 
54*0b57cec5SDimitry Andric   /// What processor and OS we're targeting.
55*0b57cec5SDimitry Andric   Triple TargetTriple;
56*0b57cec5SDimitry Andric 
57*0b57cec5SDimitry Andric   WebAssemblyFrameLowering FrameLowering;
58*0b57cec5SDimitry Andric   WebAssemblyInstrInfo InstrInfo;
59*0b57cec5SDimitry Andric   WebAssemblySelectionDAGInfo TSInfo;
60*0b57cec5SDimitry Andric   WebAssemblyTargetLowering TLInfo;
61*0b57cec5SDimitry Andric 
62*0b57cec5SDimitry Andric   /// Initializes using CPUString and the passed in feature string so that we
63*0b57cec5SDimitry Andric   /// can use initializer lists for subtarget initialization.
64*0b57cec5SDimitry Andric   WebAssemblySubtarget &initializeSubtargetDependencies(StringRef FS);
65*0b57cec5SDimitry Andric 
66*0b57cec5SDimitry Andric public:
67*0b57cec5SDimitry Andric   /// This constructor initializes the data members to match that
68*0b57cec5SDimitry Andric   /// of the specified triple.
69*0b57cec5SDimitry Andric   WebAssemblySubtarget(const Triple &TT, const std::string &CPU,
70*0b57cec5SDimitry Andric                        const std::string &FS, const TargetMachine &TM);
71*0b57cec5SDimitry Andric 
72*0b57cec5SDimitry Andric   const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
73*0b57cec5SDimitry Andric     return &TSInfo;
74*0b57cec5SDimitry Andric   }
75*0b57cec5SDimitry Andric   const WebAssemblyFrameLowering *getFrameLowering() const override {
76*0b57cec5SDimitry Andric     return &FrameLowering;
77*0b57cec5SDimitry Andric   }
78*0b57cec5SDimitry Andric   const WebAssemblyTargetLowering *getTargetLowering() const override {
79*0b57cec5SDimitry Andric     return &TLInfo;
80*0b57cec5SDimitry Andric   }
81*0b57cec5SDimitry Andric   const WebAssemblyInstrInfo *getInstrInfo() const override {
82*0b57cec5SDimitry Andric     return &InstrInfo;
83*0b57cec5SDimitry Andric   }
84*0b57cec5SDimitry Andric   const WebAssemblyRegisterInfo *getRegisterInfo() const override {
85*0b57cec5SDimitry Andric     return &getInstrInfo()->getRegisterInfo();
86*0b57cec5SDimitry Andric   }
87*0b57cec5SDimitry Andric   const Triple &getTargetTriple() const { return TargetTriple; }
88*0b57cec5SDimitry Andric   bool enableAtomicExpand() const override;
89*0b57cec5SDimitry Andric   bool enableIndirectBrExpand() const override { return true; }
90*0b57cec5SDimitry Andric   bool enableMachineScheduler() const override;
91*0b57cec5SDimitry Andric   bool useAA() const override;
92*0b57cec5SDimitry Andric 
93*0b57cec5SDimitry Andric   // Predicates used by WebAssemblyInstrInfo.td.
94*0b57cec5SDimitry Andric   bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
95*0b57cec5SDimitry Andric   bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
96*0b57cec5SDimitry Andric   bool hasUnimplementedSIMD128() const {
97*0b57cec5SDimitry Andric     return SIMDLevel >= UnimplementedSIMD128;
98*0b57cec5SDimitry Andric   }
99*0b57cec5SDimitry Andric   bool hasAtomics() const { return HasAtomics; }
100*0b57cec5SDimitry Andric   bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
101*0b57cec5SDimitry Andric   bool hasSignExt() const { return HasSignExt; }
102*0b57cec5SDimitry Andric   bool hasExceptionHandling() const { return HasExceptionHandling; }
103*0b57cec5SDimitry Andric   bool hasBulkMemory() const { return HasBulkMemory; }
104*0b57cec5SDimitry Andric   bool hasMultivalue() const { return HasMultivalue; }
105*0b57cec5SDimitry Andric   bool hasMutableGlobals() const { return HasMutableGlobals; }
106*0b57cec5SDimitry Andric   bool hasTailCall() const { return HasTailCall; }
107*0b57cec5SDimitry Andric 
108*0b57cec5SDimitry Andric   /// Parses features string setting specified subtarget options. Definition of
109*0b57cec5SDimitry Andric   /// function is auto generated by tblgen.
110*0b57cec5SDimitry Andric   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
111*0b57cec5SDimitry Andric };
112*0b57cec5SDimitry Andric 
113*0b57cec5SDimitry Andric } // end namespace llvm
114*0b57cec5SDimitry Andric 
115*0b57cec5SDimitry Andric #endif
116