1 //=- WebAssemblySubtarget.h - Define Subtarget for the WebAssembly -*- C++ -*-//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file declares the WebAssembly-specific subclass of
12 /// TargetSubtarget.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H
18 
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 class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
32   bool HasSIMD128;
33   bool HasAtomics;
34   bool HasNontrappingFPToInt;
35   bool HasSignExt;
36 
37   /// String name of used CPU.
38   std::string CPUString;
39 
40   /// What processor and OS we're targeting.
41   Triple TargetTriple;
42 
43   WebAssemblyFrameLowering FrameLowering;
44   WebAssemblyInstrInfo InstrInfo;
45   WebAssemblySelectionDAGInfo TSInfo;
46   WebAssemblyTargetLowering TLInfo;
47 
48   /// Initializes using CPUString and the passed in feature string so that we
49   /// can use initializer lists for subtarget initialization.
50   WebAssemblySubtarget &initializeSubtargetDependencies(StringRef FS);
51 
52 public:
53   /// This constructor initializes the data members to match that
54   /// of the specified triple.
55   WebAssemblySubtarget(const Triple &TT, const std::string &CPU,
56                        const std::string &FS, const TargetMachine &TM);
57 
58   const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
59     return &TSInfo;
60   }
61   const WebAssemblyFrameLowering *getFrameLowering() const override {
62     return &FrameLowering;
63   }
64   const WebAssemblyTargetLowering *getTargetLowering() const override {
65     return &TLInfo;
66   }
67   const WebAssemblyInstrInfo *getInstrInfo() const override {
68     return &InstrInfo;
69   }
70   const WebAssemblyRegisterInfo *getRegisterInfo() const override {
71     return &getInstrInfo()->getRegisterInfo();
72   }
73   const Triple &getTargetTriple() const { return TargetTriple; }
74   bool enableMachineScheduler() const override;
75   bool useAA() const override;
76 
77   // Predicates used by WebAssemblyInstrInfo.td.
78   bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
79   bool hasSIMD128() const { return HasSIMD128; }
80   bool hasAtomics() const { return HasAtomics; }
81   bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
82   bool hasSignExt() const { return HasSignExt; }
83 
84   /// Parses features string setting specified subtarget options. Definition of
85   /// function is auto generated by tblgen.
86   void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
87 };
88 
89 } // end namespace llvm
90 
91 #endif
92