LLVM 19.0.0git
LoongArchBaseInfo.cpp
Go to the documentation of this file.
1//= LoongArchBaseInfo.cpp - Top level definitions for LoongArch MC -*- 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 helper functions for the LoongArch target useful for the
10// compiler back-end and the MC libraries.
11//
12//===----------------------------------------------------------------------===//
13
14#include "LoongArchBaseInfo.h"
15#include "llvm/ADT/ArrayRef.h"
19
20namespace llvm {
21
22namespace LoongArchABI {
23
24ABI computeTargetABI(const Triple &TT, StringRef ABIName) {
25 ABI ArgProvidedABI = getTargetABI(ABIName);
26 bool Is64Bit = TT.isArch64Bit();
27 ABI TripleABI;
28
29 // Figure out the ABI explicitly requested via the triple's environment type.
30 switch (TT.getEnvironment()) {
33 break;
36 break;
37
38 // Let the fallback case behave like {ILP32,LP64}D.
40 default:
42 break;
43 }
44
45 switch (ArgProvidedABI) {
47 // Fallback to the triple-implied ABI if ABI name is not specified or
48 // invalid.
49 if (!ABIName.empty())
50 errs() << "'" << ABIName
51 << "' is not a recognized ABI for this target, ignoring and using "
52 "triple-implied ABI\n";
53 return TripleABI;
54
58 if (Is64Bit) {
59 errs() << "32-bit ABIs are not supported for 64-bit targets, ignoring "
60 "target-abi and using triple-implied ABI\n";
61 return TripleABI;
62 }
63 break;
64
68 if (!Is64Bit) {
69 errs() << "64-bit ABIs are not supported for 32-bit targets, ignoring "
70 "target-abi and using triple-implied ABI\n";
71 return TripleABI;
72 }
73 break;
74 }
75
76 if (!ABIName.empty() && TT.hasEnvironment() && ArgProvidedABI != TripleABI)
77 errs() << "warning: triple-implied ABI conflicts with provided target-abi '"
78 << ABIName << "', using target-abi\n";
79
80 return ArgProvidedABI;
81}
82
84 auto TargetABI = StringSwitch<ABI>(ABIName)
85 .Case("ilp32s", ABI_ILP32S)
86 .Case("ilp32f", ABI_ILP32F)
87 .Case("ilp32d", ABI_ILP32D)
88 .Case("lp64s", ABI_LP64S)
89 .Case("lp64f", ABI_LP64F)
90 .Case("lp64d", ABI_LP64D)
92 return TargetABI;
93}
94
95// To avoid the BP value clobbered by a function call, we need to choose a
96// callee saved register to save the value. The `last` `S` register (s9) is
97// used for FP. So we choose the previous (s8) as BP.
98MCRegister getBPReg() { return LoongArch::R31; }
99
100} // end namespace LoongArchABI
101
102} // end namespace llvm
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:33
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
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:44
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:69
R Default(T Value)
Definition: StringSwitch.h:182
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
ABI computeTargetABI(const Triple &TT, StringRef ABIName)
ABI getTargetABI(StringRef ABIName)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.