LLVM  10.0.0
RISCVBaseInfo.cpp
Go to the documentation of this file.
1 #include "RISCVBaseInfo.h"
2 #include "llvm/ADT/ArrayRef.h"
3 #include "llvm/ADT/Triple.h"
5 
6 namespace llvm {
7 namespace RISCVSysReg {
8 #define GET_SysRegsList_IMPL
9 #include "RISCVGenSystemOperands.inc"
10 } // namespace RISCVSysReg
11 
12 namespace RISCVABI {
14  StringRef ABIName) {
15  auto TargetABI = getTargetABI(ABIName);
16  bool IsRV64 = TT.isArch64Bit();
17  bool IsRV32E = FeatureBits[RISCV::FeatureRV32E];
18 
19  if (!ABIName.empty() && TargetABI == ABI_Unknown) {
20  errs()
21  << "'" << ABIName
22  << "' is not a recognized ABI for this target (ignoring target-abi)\n";
23  } else if (ABIName.startswith("ilp32") && IsRV64) {
24  errs() << "32-bit ABIs are not supported for 64-bit targets (ignoring "
25  "target-abi)\n";
26  TargetABI = ABI_Unknown;
27  } else if (ABIName.startswith("lp64") && !IsRV64) {
28  errs() << "64-bit ABIs are not supported for 32-bit targets (ignoring "
29  "target-abi)\n";
30  TargetABI = ABI_Unknown;
31  } else if (IsRV32E && TargetABI != ABI_ILP32E && TargetABI != ABI_Unknown) {
32  // TODO: move this checking to RISCVTargetLowering and RISCVAsmParser
33  errs()
34  << "Only the ilp32e ABI is supported for RV32E (ignoring target-abi)\n";
35  TargetABI = ABI_Unknown;
36  }
37 
38  if (TargetABI != ABI_Unknown)
39  return TargetABI;
40 
41  // For now, default to the ilp32/ilp32e/lp64 ABI if no explicit ABI is given
42  // or an invalid/unrecognised string is given. In the future, it might be
43  // worth changing this to default to ilp32f/lp64f and ilp32d/lp64d when
44  // hardware support for floating point is present.
45  if (IsRV32E)
46  return ABI_ILP32E;
47  if (IsRV64)
48  return ABI_LP64;
49  return ABI_ILP32;
50 }
51 
53  auto TargetABI = StringSwitch<ABI>(ABIName)
54  .Case("ilp32", ABI_ILP32)
55  .Case("ilp32f", ABI_ILP32F)
56  .Case("ilp32d", ABI_ILP32D)
57  .Case("ilp32e", ABI_ILP32E)
58  .Case("lp64", ABI_LP64)
59  .Case("lp64f", ABI_LP64F)
60  .Case("lp64d", ABI_LP64D)
62  return TargetABI;
63 }
64 
65 // To avoid the BP value clobbered by a function call, we need to choose a
66 // callee saved register to save the value. RV32E only has X8 and X9 as callee
67 // saved registers and X8 will be used as fp. So we choose X9 as bp.
68 Register getBPReg() { return RISCV::X9; }
69 
70 } // namespace RISCVABI
71 
72 namespace RISCVFeatures {
73 
74 void validate(const Triple &TT, const FeatureBitset &FeatureBits) {
75  if (TT.isArch64Bit() && FeatureBits[RISCV::FeatureRV32E])
76  report_fatal_error("RV32E can't be enabled for an RV64 target");
77 }
78 
79 } // namespace RISCVFeatures
80 
81 } // namespace llvm
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:140
This class represents lattice values for constants.
Definition: AllocatorList.h:23
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:277
StringSwitch & Case(StringLiteral S, T Value)
Definition: StringSwitch.h:67
LLVM_NODISCARD R Default(T Value)
Definition: StringSwitch.h:181
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:147
A switch()-like statement whose cases are string literals.
Definition: StringSwitch.h:42
Container class for subtarget features.
ABI getTargetABI(StringRef ABIName)
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
Register getBPReg()
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1298
ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits, StringRef ABIName)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
Wrapper class representing virtual and physical registers.
Definition: Register.h:19