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/TargetSubtargetInfo.h"
24 #include <string>
25 
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   bool HasMultiMemory = false;
53 
54   /// What processor and OS we're targeting.
55   Triple TargetTriple;
56 
57   WebAssemblyFrameLowering FrameLowering;
58   WebAssemblyInstrInfo InstrInfo;
59   WebAssemblySelectionDAGInfo TSInfo;
60   WebAssemblyTargetLowering TLInfo;
61 
62   WebAssemblySubtarget &initializeSubtargetDependencies(StringRef CPU,
63                                                         StringRef FS);
64 
65 public:
66   /// This constructor initializes the data members to match that
67   /// of the specified triple.
68   WebAssemblySubtarget(const Triple &TT, const std::string &CPU,
69                        const std::string &FS, const TargetMachine &TM);
70 
getSelectionDAGInfo()71   const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
72     return &TSInfo;
73   }
getFrameLowering()74   const WebAssemblyFrameLowering *getFrameLowering() const override {
75     return &FrameLowering;
76   }
getTargetLowering()77   const WebAssemblyTargetLowering *getTargetLowering() const override {
78     return &TLInfo;
79   }
getInstrInfo()80   const WebAssemblyInstrInfo *getInstrInfo() const override {
81     return &InstrInfo;
82   }
getRegisterInfo()83   const WebAssemblyRegisterInfo *getRegisterInfo() const override {
84     return &getInstrInfo()->getRegisterInfo();
85   }
getTargetTriple()86   const Triple &getTargetTriple() const { return TargetTriple; }
87   bool enableAtomicExpand() const override;
enableIndirectBrExpand()88   bool enableIndirectBrExpand() const override { return true; }
89   bool enableMachineScheduler() const override;
90   bool useAA() const override;
91 
92   // Predicates used by WebAssemblyInstrInfo.td.
hasAddr64()93   bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
hasSIMD128()94   bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
hasRelaxedSIMD()95   bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }
hasAtomics()96   bool hasAtomics() const { return HasAtomics; }
hasNontrappingFPToInt()97   bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
hasSignExt()98   bool hasSignExt() const { return HasSignExt; }
hasExceptionHandling()99   bool hasExceptionHandling() const { return HasExceptionHandling; }
hasBulkMemory()100   bool hasBulkMemory() const { return HasBulkMemory; }
hasMultivalue()101   bool hasMultivalue() const { return HasMultivalue; }
hasMutableGlobals()102   bool hasMutableGlobals() const { return HasMutableGlobals; }
hasTailCall()103   bool hasTailCall() const { return HasTailCall; }
hasReferenceTypes()104   bool hasReferenceTypes() const { return HasReferenceTypes; }
hasMultiMemory()105   bool hasMultiMemory() const { return HasMultiMemory; }
106 
107   /// Parses features string setting specified subtarget options. Definition of
108   /// function is auto generated by tblgen.
109   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
110 };
111 
112 } // end namespace llvm
113 
114 #endif
115