LLVM 19.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
25void LoongArchSubtarget::anchor() {}
26
27LoongArchSubtarget &LoongArchSubtarget::initializeSubtargetDependencies(
28 const Triple &TT, StringRef CPU, StringRef TuneCPU, StringRef FS,
29 StringRef ABIName) {
30 bool Is64Bit = TT.isArch64Bit();
31 if (CPU.empty() || CPU == "generic")
32 CPU = Is64Bit ? "generic-la64" : "generic-la32";
33
34 if (TuneCPU.empty())
35 TuneCPU = CPU;
36
37 ParseSubtargetFeatures(CPU, TuneCPU, FS);
38 initializeProperties(TuneCPU);
39 if (Is64Bit) {
40 GRLenVT = MVT::i64;
41 GRLen = 64;
42 }
43
44 if (HasLA32 == HasLA64)
45 report_fatal_error("Please use one feature of 32bit and 64bit.");
46
47 if (Is64Bit && HasLA32)
48 report_fatal_error("Feature 32bit should be used for loongarch32 target.");
49
50 if (!Is64Bit && HasLA64)
51 report_fatal_error("Feature 64bit should be used for loongarch64 target.");
52
53 TargetABI = LoongArchABI::computeTargetABI(TT, ABIName);
54
55 return *this;
56}
57
58void LoongArchSubtarget::initializeProperties(StringRef TuneCPU) {
59 // Initialize CPU specific properties. We should add a tablegen feature for
60 // this in the future so we can specify it together with the subtarget
61 // features.
62
63 // TODO: Check TuneCPU and override defaults (that are for LA464) once we
64 // support optimizing for more uarchs.
65
66 // Default to the alignment settings empirically confirmed to perform best
67 // on LA464, with 4-wide instruction fetch and decode stages. These settings
68 // can also be overridden in initializeProperties.
69 //
70 // We default to such higher-than-minimum alignments because we assume that:
71 //
72 // * these settings should benefit most existing uarchs/users,
73 // * future general-purpose LoongArch cores are likely to have issue widths
74 // equal to or wider than 4,
75 // * instruction sequences best for LA464 should not pessimize other future
76 // uarchs, and
77 // * narrower cores would not suffer much (aside from slightly increased
78 // ICache footprint maybe), compared to the gains everywhere else.
79 PrefFunctionAlignment = Align(32);
80 PrefLoopAlignment = Align(16);
81 MaxBytesForAlignment = 16;
82}
83
85 StringRef TuneCPU, StringRef FS,
86 StringRef ABIName,
87 const TargetMachine &TM)
88 : LoongArchGenSubtargetInfo(TT, CPU, TuneCPU, FS),
89 FrameLowering(
90 initializeSubtargetDependencies(TT, CPU, TuneCPU, FS, ABIName)),
91 InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {}
const char LLVMTargetMachineRef TM
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:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ABI computeTargetABI(const Triple &TT, StringRef ABIName)
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:156
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39