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 "WebAssemblyFrameLowering.h"
19 #include "WebAssemblyISelLowering.h"
20 #include "WebAssemblyInstrInfo.h"
21 #include "WebAssemblySelectionDAGInfo.h"
22 #include "llvm/CodeGen/TargetSubtargetInfo.h"
23 #include <string>
24 
25 #define GET_SUBTARGETINFO_ENUM
26 #define GET_SUBTARGETINFO_HEADER
27 #include "WebAssemblyGenSubtargetInfo.inc"
28 
29 namespace llvm {
30 
31 // Defined in WebAssemblyGenSubtargetInfo.inc.
32 extern const SubtargetFeatureKV
33     WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures];
34 
35 class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
36   enum SIMDEnum {
37     NoSIMD,
38     SIMD128,
39     RelaxedSIMD,
40   } SIMDLevel = NoSIMD;
41 
42   bool HasAtomics = false;
43   bool HasNontrappingFPToInt = false;
44   bool HasSignExt = false;
45   bool HasExceptionHandling = false;
46   bool HasBulkMemory = false;
47   bool HasMultivalue = false;
48   bool HasMutableGlobals = false;
49   bool HasTailCall = false;
50   bool HasReferenceTypes = false;
51   bool HasExtendedConst = false;
52 
53   /// What processor and OS we're targeting.
54   Triple TargetTriple;
55 
56   WebAssemblyFrameLowering FrameLowering;
57   WebAssemblyInstrInfo InstrInfo;
58   WebAssemblySelectionDAGInfo TSInfo;
59   WebAssemblyTargetLowering TLInfo;
60 
61   WebAssemblySubtarget &initializeSubtargetDependencies(StringRef CPU,
62                                                         StringRef FS);
63 
64 public:
65   /// This constructor initializes the data members to match that
66   /// of the specified triple.
67   WebAssemblySubtarget(const Triple &TT, const std::string &CPU,
68                        const std::string &FS, const TargetMachine &TM);
69 
70   const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
71     return &TSInfo;
72   }
73   const WebAssemblyFrameLowering *getFrameLowering() const override {
74     return &FrameLowering;
75   }
76   const WebAssemblyTargetLowering *getTargetLowering() const override {
77     return &TLInfo;
78   }
79   const WebAssemblyInstrInfo *getInstrInfo() const override {
80     return &InstrInfo;
81   }
82   const WebAssemblyRegisterInfo *getRegisterInfo() const override {
83     return &getInstrInfo()->getRegisterInfo();
84   }
85   const Triple &getTargetTriple() const { return TargetTriple; }
86   bool enableAtomicExpand() const override;
87   bool enableIndirectBrExpand() const override { return true; }
88   bool enableMachineScheduler() const override;
89   bool useAA() const override;
90 
91   // Predicates used by WebAssemblyInstrInfo.td.
92   bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
93   bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
94   bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
95   bool hasAtomics() const { return HasAtomics; }
96   bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
97   bool hasSignExt() const { return HasSignExt; }
98   bool hasExceptionHandling() const { return HasExceptionHandling; }
99   bool hasBulkMemory() const { return HasBulkMemory; }
100   bool hasMultivalue() const { return HasMultivalue; }
101   bool hasMutableGlobals() const { return HasMutableGlobals; }
102   bool hasTailCall() const { return HasTailCall; }
103   bool hasReferenceTypes() const { return HasReferenceTypes; }
104 
105   /// Parses features string setting specified subtarget options. Definition of
106   /// function is auto generated by tblgen.
107   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
108 };
109 
110 } // end namespace llvm
111 
112 #endif
113