1//===- LoongArchSubtarget.h - Define Subtarget for the LoongArch -*- 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// This file declares the LoongArch specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHSUBTARGET_H
14#define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHSUBTARGET_H
15
16#include "LoongArchFrameLowering.h"
17#include "LoongArchISelLowering.h"
18#include "LoongArchInstrInfo.h"
19#include "LoongArchRegisterInfo.h"
20#include "MCTargetDesc/LoongArchBaseInfo.h"
21#include "llvm/CodeGen/SelectionDAGTargetInfo.h"
22#include "llvm/CodeGen/TargetSubtargetInfo.h"
23#include "llvm/IR/DataLayout.h"
24#include "llvm/Target/TargetMachine.h"
25
26#define GET_SUBTARGETINFO_HEADER
27#include "LoongArchGenSubtargetInfo.inc"
28
29namespace llvm {
30class StringRef;
31
32class LoongArchSubtarget : public LoongArchGenSubtargetInfo {
33  virtual void anchor();
34  bool HasLA32 = false;
35  bool HasLA64 = false;
36  bool HasBasicF = false;
37  bool HasBasicD = false;
38  bool HasExtLSX = false;
39  bool HasExtLASX = false;
40  bool HasExtLVZ = false;
41  bool HasExtLBT = false;
42  bool HasLaGlobalWithPcrel = false;
43  bool HasLaGlobalWithAbs = false;
44  bool HasLaLocalWithAbs = false;
45  bool HasUAL = false;
46  bool HasLinkerRelax = false;
47  bool HasExpAutoVec = false;
48  bool HasFrecipe = false;
49  unsigned GRLen = 32;
50  MVT GRLenVT = MVT::i32;
51  LoongArchABI::ABI TargetABI = LoongArchABI::ABI_Unknown;
52  LoongArchFrameLowering FrameLowering;
53  LoongArchInstrInfo InstrInfo;
54  LoongArchRegisterInfo RegInfo;
55  LoongArchTargetLowering TLInfo;
56  SelectionDAGTargetInfo TSInfo;
57
58  Align PrefFunctionAlignment;
59  Align PrefLoopAlignment;
60  unsigned MaxBytesForAlignment;
61
62  /// Initializes using the passed in CPU and feature strings so that we can
63  /// use initializer lists for subtarget initialization.
64  LoongArchSubtarget &initializeSubtargetDependencies(const Triple &TT,
65                                                      StringRef CPU,
66                                                      StringRef TuneCPU,
67                                                      StringRef FS,
68                                                      StringRef ABIName);
69
70  /// Initialize properties based on the selected processor family.
71  void initializeProperties(StringRef TuneCPU);
72
73public:
74  // Initializes the data members to match that of the specified triple.
75  LoongArchSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
76                     StringRef FS, StringRef ABIName, const TargetMachine &TM);
77
78  // Parses features string setting specified subtarget options. The
79  // definition of this function is auto-generated by tblgen.
80  void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
81
82  const LoongArchFrameLowering *getFrameLowering() const override {
83    return &FrameLowering;
84  }
85  const LoongArchInstrInfo *getInstrInfo() const override { return &InstrInfo; }
86  const LoongArchRegisterInfo *getRegisterInfo() const override {
87    return &RegInfo;
88  }
89  const LoongArchTargetLowering *getTargetLowering() const override {
90    return &TLInfo;
91  }
92  const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
93    return &TSInfo;
94  }
95  bool is64Bit() const { return HasLA64; }
96  bool hasBasicF() const { return HasBasicF; }
97  bool hasBasicD() const { return HasBasicD; }
98  bool hasExtLSX() const { return HasExtLSX; }
99  bool hasExtLASX() const { return HasExtLASX; }
100  bool hasExtLVZ() const { return HasExtLVZ; }
101  bool hasExtLBT() const { return HasExtLBT; }
102  bool hasLaGlobalWithPcrel() const { return HasLaGlobalWithPcrel; }
103  bool hasLaGlobalWithAbs() const { return HasLaGlobalWithAbs; }
104  bool hasLaLocalWithAbs() const { return HasLaLocalWithAbs; }
105  bool hasUAL() const { return HasUAL; }
106  bool hasLinkerRelax() const { return HasLinkerRelax; }
107  bool hasExpAutoVec() const { return HasExpAutoVec; }
108  bool hasFrecipe() const { return HasFrecipe; }
109  MVT getGRLenVT() const { return GRLenVT; }
110  unsigned getGRLen() const { return GRLen; }
111  LoongArchABI::ABI getTargetABI() const { return TargetABI; }
112  bool isXRaySupported() const override { return is64Bit(); }
113  Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
114  Align getPrefLoopAlignment() const { return PrefLoopAlignment; }
115  unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; }
116};
117} // end namespace llvm
118
119#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHSUBTARGET_H
120