LLVM 24.0.0git
LoongArchSubtarget.cpp
Go to the documentation of this file.
1//===-- LoongArchSubtarget.cpp - LoongArch Subtarget Information -*- 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 implements the LoongArch specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "LoongArchSubtarget.h"
18
19using namespace llvm;
20
21#define DEBUG_TYPE "loongarch-subtarget"
22
23#define GET_SUBTARGETINFO_TARGET_DESC
24#define GET_SUBTARGETINFO_CTOR
25#include "LoongArchGenSubtargetInfo.inc"
26
27static cl::opt<bool> UseAA("loongarch-use-aa", cl::init(true),
28 cl::desc("Enable the use of AA during codegen."));
29
30void LoongArchSubtarget::anchor() {}
31
32// Enable use of alias analysis during code generation (during MI scheduling,
33// DAGCombine, etc.).
34bool LoongArchSubtarget::useAA() const { return UseAA; }
35
36LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
37 const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
38 StringRef ABIName) {
39 bool Is64Bit = TT.isArch64Bit();
40 if (CPU.empty() || CPU == "generic")
41 CPU = Is64Bit ? "generic-la64" : "generic-la32";
42
43 if (TuneCPU.empty())
44 TuneCPU = CPU;
45
46 ParseSubtargetFeatures(CPU, TuneCPU, FS);
47 initializeProperties(TuneCPU);
48 if (Is64Bit) {
49 GRLenVT = MVT::i64;
50 GRLen = 64;
51 }
52
53 if (HasLA32 == HasLA64)
54 report_fatal_error("Please use one feature of 32bit and 64bit.");
55
56 if (Is64Bit && HasLA32)
57 report_fatal_error("Feature 32bit should be used for loongarch32 target.");
58
59 if (!Is64Bit && HasLA64)
60 report_fatal_error("Feature 64bit should be used for loongarch64 target.");
61
62 TargetABI = LoongArchABI::computeTargetABI(TT, getFeatureBits(), ABIName);
63
64 return *this;
65}
66
67void LoongArchSubtarget::initializeProperties(StringRef TuneCPU) {
68 // Initialize CPU specific properties. We should add a tablegen feature for
69 // this in the future so we can specify it together with the subtarget
70 // features.
71
72 // TODO: Check TuneCPU and override defaults (that are for LA464) once we
73 // support optimizing for more uarchs.
74
75 // Default to the alignment settings empirically confirmed to perform best
76 // on LA464, with 4-wide instruction fetch and decode stages. These settings
77 // can also be overridden in initializeProperties.
78 //
79 // We default to such higher-than-minimum alignments because we assume that:
80 //
81 // * these settings should benefit most existing uarchs/users,
82 // * future general-purpose LoongArch cores are likely to have issue widths
83 // equal to or wider than 4,
84 // * instruction sequences best for LA464 should not pessimize other future
85 // uarchs, and
86 // * narrower cores would not suffer much (aside from slightly increased
87 // ICache footprint maybe), compared to the gains everywhere else.
88 PrefFunctionAlignment = Align(32);
89 PrefLoopAlignment = Align(16);
90 MaxBytesForAlignment = 16;
91
92 // Software prefetching is only enabled for uarches it has been tuned for.
93 PrefetchDistance = 0;
94 MinPrefetchStride = 1;
95 MaxPrefetchIterationsAhead = UINT_MAX;
96
97 if (TuneCPU == "la464" || TuneCPU == "la664") {
98 // The LA464/LA664 hardware prefetchers cover strides of up to 1 KiB, but
99 // stop tracking streams with a stride of 2 KiB or more. Only prefetch
100 // those, as software prefetches for smaller strides just add instructions.
101 PrefetchDistance = 200;
102 MinPrefetchStride = 2048;
103 }
104}
105
107 StringRef TuneCPU, StringRef FS,
108 StringRef ABIName,
109 const TargetMachine &TM)
110 : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
111 FrameLowering(
112 initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
113 InstrInfo(*this), TLInfo(TM, *this) {
114 TSInfo = std::make_unique<LoongArchSelectionDAGInfo>();
115}
116
118
120 return TSInfo.get();
121}
122
124 // We usually compute max call frame size after ISel. Do the computation now
125 // if the .mir file didn't specify it. Note that this will probably give you
126 // bogus values after PEI has eliminated the callframe setup/destroy pseudo
127 // instructions, specify explicitly if you need it to be correct.
128 MachineFrameInfo &MFI = MF.getFrameInfo();
131}
static cl::opt< bool > UseAA("loongarch-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
void mirFileLoaded(MachineFunction &MF) const override
const SelectionDAGTargetInfo * getSelectionDAGInfo() const override
bool useAA() const override
LoongArchSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS, StringRef ABIName, const TargetMachine &TM)
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS)
~LoongArchSubtarget() override
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
LLVM_ABI void computeMaxCallFrameSize(MachineFunction &MF, std::vector< MachineBasicBlock::iterator > *FrameSDOps=nullptr)
Computes the maximum size of a callframe.
bool isMaxCallFrameSizeComputed() const
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Targets can subclass this to parameterize the SelectionDAG lowering and instruction selection process...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
Primary interface to the complete machine description for the target machine.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163