blob: 394ec33a85dd3463b1a12e26b06d6cde4cf7ce64 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//=- WebAssemblySubtarget.h - Define Subtarget for the WebAssembly -*- C++ -*-//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Dan Gohman10e730a2015-06-29 23:51:55 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This file declares the WebAssembly-specific subclass of
Dan Gohman10e730a2015-06-29 23:51:55 +000011/// 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"
David Blaikieb3bde2e2017-11-17 01:07:10 +000022#include "llvm/CodeGen/TargetSubtargetInfo.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000023#include <string>
24
Thomas Lively3f34e1b82019-03-29 00:14:01 +000025#define GET_SUBTARGETINFO_ENUM
Dan Gohman10e730a2015-06-29 23:51:55 +000026#define GET_SUBTARGETINFO_HEADER
27#include "WebAssemblyGenSubtargetInfo.inc"
28
29namespace llvm {
30
Thomas Lively3f34e1b82019-03-29 00:14:01 +000031// Defined in WebAssemblyGenSubtargetInfo.inc.
32extern const SubtargetFeatureKV
33 WebAssemblyFeatureKV[WebAssembly::NumSubtargetFeatures];
34
Dan Gohman10e730a2015-06-29 23:51:55 +000035class WebAssemblySubtarget final : public WebAssemblyGenSubtargetInfo {
Thomas Lively64a39a12019-01-10 22:32:11 +000036 enum SIMDEnum {
37 NoSIMD,
38 SIMD128,
39 UnimplementedSIMD128,
40 } SIMDLevel = NoSIMD;
41
42 bool HasAtomics = false;
43 bool HasNontrappingFPToInt = false;
44 bool HasSignExt = false;
45 bool HasExceptionHandling = false;
Thomas Lively88058d42019-01-31 21:02:19 +000046 bool HasBulkMemory = false;
Thomas Livelyeafe8ef2019-05-23 17:26:47 +000047 bool HasMultivalue = false;
Thomas Lively5f0c4c62019-03-29 22:00:18 +000048 bool HasMutableGlobals = false;
Thomas Livelyeafe8ef2019-05-23 17:26:47 +000049 bool HasTailCall = false;
Heejin Ahn764f4082020-01-23 19:22:51 -080050 bool HasReferenceTypes = false;
Dan Gohman10e730a2015-06-29 23:51:55 +000051
52 /// String name of used CPU.
53 std::string CPUString;
54
55 /// What processor and OS we're targeting.
56 Triple TargetTriple;
57
58 WebAssemblyFrameLowering FrameLowering;
59 WebAssemblyInstrInfo InstrInfo;
60 WebAssemblySelectionDAGInfo TSInfo;
61 WebAssemblyTargetLowering TLInfo;
62
63 /// Initializes using CPUString and the passed in feature string so that we
64 /// can use initializer lists for subtarget initialization.
65 WebAssemblySubtarget &initializeSubtargetDependencies(StringRef FS);
66
67public:
68 /// This constructor initializes the data members to match that
69 /// of the specified triple.
70 WebAssemblySubtarget(const Triple &TT, const std::string &CPU,
71 const std::string &FS, const TargetMachine &TM);
72
73 const WebAssemblySelectionDAGInfo *getSelectionDAGInfo() const override {
74 return &TSInfo;
75 }
76 const WebAssemblyFrameLowering *getFrameLowering() const override {
77 return &FrameLowering;
78 }
79 const WebAssemblyTargetLowering *getTargetLowering() const override {
80 return &TLInfo;
81 }
JF Bastienb9073fb2015-07-22 21:28:15 +000082 const WebAssemblyInstrInfo *getInstrInfo() const override {
83 return &InstrInfo;
84 }
85 const WebAssemblyRegisterInfo *getRegisterInfo() const override {
86 return &getInstrInfo()->getRegisterInfo();
87 }
Dan Gohman10e730a2015-06-29 23:51:55 +000088 const Triple &getTargetTriple() const { return TargetTriple; }
Thomas Lively3f34e1b82019-03-29 00:14:01 +000089 bool enableAtomicExpand() const override;
Derek Schuffec4be572019-07-03 23:54:06 +000090 bool enableIndirectBrExpand() const override { return true; }
Dan Gohman10e730a2015-06-29 23:51:55 +000091 bool enableMachineScheduler() const override;
Dan Gohman7615e462015-12-05 19:27:18 +000092 bool useAA() const override;
Dan Gohman10e730a2015-06-29 23:51:55 +000093
94 // Predicates used by WebAssemblyInstrInfo.td.
JF Bastien03855df2015-07-01 23:41:25 +000095 bool hasAddr64() const { return TargetTriple.isArch64Bit(); }
Thomas Lively64a39a12019-01-10 22:32:11 +000096 bool hasSIMD128() const { return SIMDLevel >= SIMD128; }
97 bool hasUnimplementedSIMD128() const {
98 return SIMDLevel >= UnimplementedSIMD128;
99 }
Derek Schuff18ba1922017-08-30 18:07:45 +0000100 bool hasAtomics() const { return HasAtomics; }
Dan Gohmancdd48b82017-11-28 01:13:40 +0000101 bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; }
Dan Gohman5d2b9352018-01-19 17:16:24 +0000102 bool hasSignExt() const { return HasSignExt; }
Heejin Ahn9386bde2018-02-24 00:40:50 +0000103 bool hasExceptionHandling() const { return HasExceptionHandling; }
Thomas Lively88058d42019-01-31 21:02:19 +0000104 bool hasBulkMemory() const { return HasBulkMemory; }
Thomas Livelyeafe8ef2019-05-23 17:26:47 +0000105 bool hasMultivalue() const { return HasMultivalue; }
Thomas Lively5f0c4c62019-03-29 22:00:18 +0000106 bool hasMutableGlobals() const { return HasMutableGlobals; }
Thomas Livelyeafe8ef2019-05-23 17:26:47 +0000107 bool hasTailCall() const { return HasTailCall; }
Heejin Ahn764f4082020-01-23 19:22:51 -0800108 bool hasReferenceTypes() const { return HasReferenceTypes; }
Dan Gohman10e730a2015-06-29 23:51:55 +0000109
110 /// Parses features string setting specified subtarget options. Definition of
111 /// function is auto generated by tblgen.
112 void ParseSubtargetFeatures(StringRef CPU, StringRef FS);
113};
114
115} // end namespace llvm
116
117#endif