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/TargetSubtargetInfo.h"
22#include "llvm/IR/DataLayout.h"
23#include "llvm/Target/TargetMachine.h"
24
25#define GET_SUBTARGETINFO_HEADER
26#include "LoongArchGenSubtargetInfo.inc"
27
28namespace llvm {
29class StringRef;
30
31class LoongArchSubtarget : public LoongArchGenSubtargetInfo {
32 virtual void anchor();
33
34#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
35 bool ATTRIBUTE = DEFAULT;
36#include "LoongArchGenSubtargetInfo.inc"
37
38 unsigned GRLen = 32;
39 // TODO: The default value is empirical and conservative. Override the
40 // default in initializeProperties once we support optimizing for more
41 // uarches.
42 uint8_t MaxInterleaveFactor = 2;
43 MVT GRLenVT = MVT::i32;
44 LoongArchABI::ABI TargetABI = LoongArchABI::ABI_Unknown;
45 LoongArchFrameLowering FrameLowering;
46 LoongArchInstrInfo InstrInfo;
47 LoongArchTargetLowering TLInfo;
48 std::unique_ptr<const SelectionDAGTargetInfo> TSInfo;
49
50 Align PrefFunctionAlignment;
51 Align PrefLoopAlignment;
52 unsigned MaxBytesForAlignment;
53
54 // Software prefetch settings for LoopDataPrefetch, set in
55 // initializeProperties. A PrefetchDistance of 0 disables the pass.
56 unsigned PrefetchDistance;
57 unsigned MinPrefetchStride;
58 unsigned MaxPrefetchIterationsAhead;
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
71public:
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 ~LoongArchSubtarget() override;
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 &InstrInfo.getRegisterInfo();
88 }
89 const LoongArchTargetLowering *getTargetLowering() const override {
90 return &TLInfo;
91 }
92
93 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override;
94
95#define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
96 bool GETTER() const { return ATTRIBUTE; }
97#include "LoongArchGenSubtargetInfo.inc"
98
99 bool is64Bit() const { return HasLA64; }
100 MVT getGRLenVT() const { return GRLenVT; }
101 unsigned getGRLen() const { return GRLen; }
102 LoongArchABI::ABI getTargetABI() const { return TargetABI; }
103 bool isSoftFPABI() const {
104 return TargetABI == LoongArchABI::ABI_LP64S ||
105 TargetABI == LoongArchABI::ABI_ILP32S;
106 }
107 bool isXRaySupported() const override { return is64Bit(); }
108 Align getPrefFunctionAlignment() const { return PrefFunctionAlignment; }
109 Align getPrefLoopAlignment() const { return PrefLoopAlignment; }
110 unsigned getMaxBytesForAlignment() const { return MaxBytesForAlignment; }
111 unsigned getMaxInterleaveFactor() const { return MaxInterleaveFactor; }
112 unsigned getPrefetchDistance() const override { return PrefetchDistance; }
113 unsigned getMinPrefetchStride(unsigned NumMemAccesses,
114 unsigned NumStridedMemAccesses,
115 unsigned NumPrefetches,
116 bool HasCall) const override {
117 return MinPrefetchStride;
118 }
119 unsigned getMaxPrefetchIterationsAhead() const override {
120 return MaxPrefetchIterationsAhead;
121 }
122 bool enableWritePrefetching() const override { return true; }
123 bool enableMachineScheduler() const override { return true; }
124 bool useAA() const override;
125};
126} // end namespace llvm
127
128#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHSUBTARGET_H
129