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