xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchSubtarget.h (revision 1db9f3b21e39176dd5b67cf8ac378633b172463e)
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 
29 namespace llvm {
30 class StringRef;
31 
32 class 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   unsigned GRLen = 32;
48   MVT GRLenVT = MVT::i32;
49   LoongArchABI::ABI TargetABI = LoongArchABI::ABI_Unknown;
50   LoongArchFrameLowering FrameLowering;
51   LoongArchInstrInfo InstrInfo;
52   LoongArchRegisterInfo RegInfo;
53   LoongArchTargetLowering TLInfo;
54   SelectionDAGTargetInfo TSInfo;
55 
56   Align PrefFunctionAlignment;
57   Align PrefLoopAlignment;
58   unsigned MaxBytesForAlignment;
59 
60   /// Initializes using the passed in CPU and feature strings so that we can
61   /// use initializer lists for subtarget initialization.
62   LoongArchSubtarget &initializeSubtargetDependencies(const Triple &TT,
63                                                       StringRef CPU,
64                                                       StringRef TuneCPU,
65                                                       StringRef FS,
66                                                       StringRef ABIName);
67 
68   /// Initialize properties based on the selected processor family.
69   void initializeProperties(StringRef TuneCPU);
70 
71 public:
72   // Initializes the data members to match that of the specified triple.
73   LoongArchSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
74                      StringRef FS, StringRef ABIName, const TargetMachine &TM);
75 
76   // Parses features string setting specified subtarget options. The
77   // definition of this function is auto-generated by tblgen.
78   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
79 
80   const LoongArchFrameLowering *getFrameLowering() const override {
81     return &FrameLowering;
82   }
83   const LoongArchInstrInfo *getInstrInfo() const override { return &InstrInfo; }
84   const LoongArchRegisterInfo *getRegisterInfo() const override {
85     return &RegInfo;
86   }
87   const LoongArchTargetLowering *getTargetLowering() const override {
88     return &TLInfo;
89   }
90   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
91     return &TSInfo;
92   }
93   bool is64Bit() const { return HasLA64; }
94   bool hasBasicF() const { return HasBasicF; }
95   bool hasBasicD() const { return HasBasicD; }
96   bool hasExtLSX() const { return HasExtLSX; }
97   bool hasExtLASX() const { return HasExtLASX; }
98   bool hasExtLVZ() const { return HasExtLVZ; }
99   bool hasExtLBT() const { return HasExtLBT; }
100   bool hasLaGlobalWithPcrel() const { return HasLaGlobalWithPcrel; }
101   bool hasLaGlobalWithAbs() const { return HasLaGlobalWithAbs; }
102   bool hasLaLocalWithAbs() const { return HasLaLocalWithAbs; }
103   bool hasUAL() const { return HasUAL; }
104   bool hasLinkerRelax() const { return HasLinkerRelax; }
105   MVT getGRLenVT() const { return GRLenVT; }
106   unsigned getGRLen() const { return GRLen; }
107   LoongArchABI::ABI getTargetABI() const { return TargetABI; }
108   bool isXRaySupported() const override { return is64Bit(); }
109   Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
110   Align getPrefLoopAlignment() const { return PrefLoopAlignment; }
111   unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; }
112 };
113 } // end namespace llvm
114 
115 #endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHSUBTARGET_H
116