LLVM 20.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"
16
17using namespace llvm;
18
19#define DEBUG_TYPE "loongarch-subtarget"
20
21#define GET_SUBTARGETINFO_TARGET_DESC
22#define GET_SUBTARGETINFO_CTOR
23#include "LoongArchGenSubtargetInfo.inc"
24
25static cl::opt<bool> UseAA("loongarch-use-aa", cl::init(true),
26 cl::desc("Enable the use of AA during codegen."));
27
28void LoongArchSubtarget::anchor() {}
29
30// Enable use of alias analysis during code generation (during MI scheduling,
31// DAGCombine, etc.).
32bool LoongArchSubtarget::useAA() const { return UseAA; }
33
34LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
35 const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
36 StringRef ABIName) {
37 bool Is64Bit = TT.isArch64Bit();
38 if (CPU.empty() || CPU == "generic")
39 CPU = Is64Bit ? "generic-la64" : "generic-la32";
40
41 if (TuneCPU.empty())
42 TuneCPU = CPU;
43
44 ParseSubtargetFeatures(CPU, TuneCPU, FS);
45 initializeProperties(TuneCPU);
46 if (Is64Bit) {
47 GRLenVT = MVT::i64;
48 GRLen = 64;
49 }
50
51 if (HasLA32 == HasLA64)
52 report_fatal_error("Please use one feature of 32bit and 64bit.");
53
54 if (Is64Bit && HasLA32)
55 report_fatal_error("Feature 32bit should be used for loongarch32 target.");
56
57 if (!Is64Bit && HasLA64)
58 report_fatal_error("Feature 64bit should be used for loongarch64 target.");
59
60 TargetABI = LoongArchABI::computeTargetABI(TT, getFeatureBits(), ABIName);
61
62 return *this;
63}
64
65void LoongArchSubtarget::initializeProperties(StringRef TuneCPU) {
66 // Initialize CPU specific properties. We should add a tablegen feature for
67 // this in the future so we can specify it together with the subtarget
68 // features.
69
70 // TODO: Check TuneCPU and override defaults (that are for LA464) once we
71 // support optimizing for more uarchs.
72
73 // Default to the alignment settings empirically confirmed to perform best
74 // on LA464, with 4-wide instruction fetch and decode stages. These settings
75 // can also be overridden in initializeProperties.
76 //
77 // We default to such higher-than-minimum alignments because we assume that:
78 //
79 // * these settings should benefit most existing uarchs/users,
80 // * future general-purpose LoongArch cores are likely to have issue widths
81 // equal to or wider than 4,
82 // * instruction sequences best for LA464 should not pessimize other future
83 // uarchs, and
84 // * narrower cores would not suffer much (aside from slightly increased
85 // ICache footprint maybe), compared to the gains everywhere else.
86 PrefFunctionAlignment = Align(32);
87 PrefLoopAlignment = Align(16);
88 MaxBytesForAlignment = 16;
89}
90
92 StringRef TuneCPU, StringRef FS,
93 StringRef ABIName,
94 const TargetMachine &TM)
95 : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
96 FrameLowering(
97 initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
98 InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}
static cl::opt< bool > UseAA("aarch64-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
static cl::opt< bool > UseAA("loongarch-use-aa", cl::init(true), cl::desc("Enable the use of AA during codegen."))
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)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:77
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ABI computeTargetABI(const Triple &TT, const FeatureBitset &FeatureBits, StringRef ABIName)
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:443
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:167
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39