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
35#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
36 bool ATTRIBUTE = DEFAULT;
37#include "LoongArchGenSubtargetInfo.inc"
38
39 unsigned GRLen = 32;
40 // TODO: The default value is empirical and conservative. Override the
41 // default in initializeProperties once we support optimizing for more
42 // uarches.
43 uint8_t MaxInterleaveFactor = 2;
44 MVT GRLenVT = MVT::i32;
45 LoongArchABI::ABI TargetABI = LoongArchABI::ABI_Unknown;
46 LoongArchFrameLowering FrameLowering;
47 LoongArchInstrInfo InstrInfo;
48 LoongArchRegisterInfo RegInfo;
49 LoongArchTargetLowering TLInfo;
50 SelectionDAGTargetInfo TSInfo;
51
52 Align PrefFunctionAlignment;
53 Align PrefLoopAlignment;
54 unsigned MaxBytesForAlignment;
55
56 /// Initializes using the passed in CPU and feature strings so that we can
57 /// use initializer lists for subtarget initialization.
58 LoongArchSubtarget &initializeSubtargetDependencies(const Triple &TT,
59 StringRef CPU,
60 StringRef TuneCPU,
61 StringRef FS,
62 StringRef ABIName);
63
64 /// Initialize properties based on the selected processor family.
65 void initializeProperties(StringRef TuneCPU);
66
67public:
68 // Initializes the data members to match that of the specified triple.
69 LoongArchSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
70 StringRef FS, StringRef ABIName, const TargetMachine &TM);
71
72 // Parses features string setting specified subtarget options. The
73 // definition of this function is auto-generated by tblgen.
74 void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
75
76 const LoongArchFrameLowering *getFrameLowering() const override {
77 return &FrameLowering;
78 }
79 const LoongArchInstrInfo *getInstrInfo() const override { return &InstrInfo; }
80 const LoongArchRegisterInfo *getRegisterInfo() const override {
81 return &RegInfo;
82 }
83 const LoongArchTargetLowering *getTargetLowering() const override {
84 return &TLInfo;
85 }
86 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
87 return &TSInfo;
88 }
89
90#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
91 bool GETTER() const { return ATTRIBUTE; }
92#include "LoongArchGenSubtargetInfo.inc"
93
94 bool is64Bit() const { return HasLA64; }
95 MVT getGRLenVT() const { return GRLenVT; }
96 unsigned getGRLen() const { return GRLen; }
97 LoongArchABI::ABI getTargetABI() const { return TargetABI; }
98 bool isSoftFPABI() const {
99 return TargetABI == LoongArchABI::ABI_LP64S ||
100 TargetABI == LoongArchABI::ABI_ILP32S;
101 }
102 bool isXRaySupported() const override { return is64Bit(); }
103 Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
104 Align getPrefLoopAlignment() const { return PrefLoopAlignment; }
105 unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; }
106 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; }
107 bool enableMachineScheduler() const override { return true; }
108};
109} // end namespace llvm
110
111#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHSUBTARGET_H
112