126 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file declares the WebAssembly-specific subclass of11/// TargetSubtarget.12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H16#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYSUBTARGET_H17 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_HEADER27#include "WebAssemblyGenSubtargetInfo.inc"28 29namespace llvm {30 31// Defined in WebAssemblyGenSubtargetInfo.inc.32extern const SubtargetFeatureKV33 WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures];34 35class 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 HasGC = false;50 bool HasMultiMemory = false;51 bool HasMultivalue = false;52 bool HasMutableGlobals = false;53 bool HasNontrappingFPToInt = false;54 bool HasReferenceTypes = false;55 bool HasSignExt = false;56 bool HasTailCall = false;57 bool HasWideArithmetic = false;58 59 /// What processor and OS we're targeting.60 Triple TargetTriple;61 62 WebAssemblyFrameLowering FrameLowering;63 WebAssemblyInstrInfo InstrInfo;64 WebAssemblySelectionDAGInfo TSInfo;65 WebAssemblyTargetLowering TLInfo;66 67 WebAssemblySubtarget &initializeSubtargetDependencies(StringRef CPU,68 StringRef FS);69 70public:71 /// This constructor initializes the data members to match that72 /// of the specified triple.73 WebAssemblySubtarget(const Triple &TT, const std::string &CPU,74 const std::string &FS, const TargetMachine &TM);75 76 const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {77 return &TSInfo;78 }79 const WebAssemblyFrameLowering *getFrameLowering() const override {80 return &FrameLowering;81 }82 const WebAssemblyTargetLowering *getTargetLowering() const override {83 return &TLInfo;84 }85 const WebAssemblyInstrInfo *getInstrInfo() const override {86 return &InstrInfo;87 }88 const WebAssemblyRegisterInfo *getRegisterInfo() const override {89 return &getInstrInfo()->getRegisterInfo();90 }91 const Triple &getTargetTriple() const { return TargetTriple; }92 bool enableAtomicExpand() const override;93 bool enableIndirectBrExpand() const override { return true; }94 bool enableMachineScheduler() const override;95 bool useAA() const override;96 97 // Predicates used by WebAssemblyInstrInfo.td.98 bool hasAddr64() const { return TargetTriple.isArch64Bit(); }99 bool hasAtomics() const { return HasAtomics; }100 bool hasBulkMemory() const { return HasBulkMemory; }101 bool hasBulkMemoryOpt() const { return HasBulkMemoryOpt; }102 bool hasCallIndirectOverlong() const { return HasCallIndirectOverlong; }103 bool hasExceptionHandling() const { return HasExceptionHandling; }104 bool hasExtendedConst() const { return HasExtendedConst; }105 bool hasFP16() const { return HasFP16; }106 bool hasMultiMemory() const { return HasMultiMemory; }107 bool hasMultivalue() const { return HasMultivalue; }108 bool hasMutableGlobals() const { return HasMutableGlobals; }109 bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }110 bool hasReferenceTypes() const { return HasReferenceTypes; }111 bool hasGC() const { return HasGC; }112 bool hasRelaxedSIMD() const { return SIMDLevel >= RelaxedSIMD; }113 bool hasSignExt() const { return HasSignExt; }114 bool hasSIMD128() const { return SIMDLevel >= SIMD128; }115 bool hasTailCall() const { return HasTailCall; }116 bool hasWideArithmetic() const { return HasWideArithmetic; }117 118 /// Parses features string setting specified subtarget options. Definition of119 /// function is auto generated by tblgen.120 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);121};122 123} // end namespace llvm124 125#endif126