Coverage Report

Created: 2025-11-16 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
Line
Count
Source
1
#include "RISCVBaseInfo.h"
2
#include "llvm/ADT/ArrayRef.h"
3
#include "llvm/ADT/Triple.h"
4
#include "llvm/Support/raw_ostream.h"
5
6
namespace llvm_ks {
7
namespace RISCVSysReg {
8
#define GET_SysRegsList_IMPL
9
#include "RISCVGenSystemOperands.inc"
10
} // namespace RISCVSysReg
11
12
namespace RISCVABI {
13
ABI computeTargetABI(const Triple &TT, FeatureBitset FeatureBits,
14
25.6k
                     StringRef ABIName) {
15
25.6k
  auto TargetABI = StringSwitch<ABI>(ABIName)
16
25.6k
                       .Case("ilp32", ABI_ILP32)
17
25.6k
                       .Case("ilp32f", ABI_ILP32F)
18
25.6k
                       .Case("ilp32d", ABI_ILP32D)
19
25.6k
                       .Case("ilp32e", ABI_ILP32E)
20
25.6k
                       .Case("lp64", ABI_LP64)
21
25.6k
                       .Case("lp64f", ABI_LP64F)
22
25.6k
                       .Case("lp64d", ABI_LP64D)
23
25.6k
                       .Default(ABI_Unknown);
24
25
25.6k
  bool IsRV64 = TT.isArch64Bit();
26
25.6k
  bool IsRV32E = FeatureBits[RISCV::FeatureRV32E];
27
28
25.6k
  if (!ABIName.empty() && TargetABI == ABI_Unknown) {
29
0
    errs()
30
0
        << "'" << ABIName
31
0
        << "' is not a recognized ABI for this target (ignoring target-abi)\n";
32
25.6k
  } else if (ABIName.startswith("ilp32") && IsRV64) {
33
0
    errs() << "32-bit ABIs are not supported for 64-bit targets (ignoring "
34
0
              "target-abi)\n";
35
0
    TargetABI = ABI_Unknown;
36
25.6k
  } else if (ABIName.startswith("lp64") && !IsRV64) {
37
0
    errs() << "64-bit ABIs are not supported for 32-bit targets (ignoring "
38
0
              "target-abi)\n";
39
0
    TargetABI = ABI_Unknown;
40
25.6k
  } else if (ABIName.endswith("f") && !FeatureBits[RISCV::FeatureStdExtF]) {
41
0
    errs() << "Hard-float 'f' ABI can't be used for a target that "
42
0
              "doesn't support the F instruction set extension (ignoring "
43
0
              "target-abi)\n";
44
0
    TargetABI = ABI_Unknown;
45
25.6k
  } else if (ABIName.endswith("d") && !FeatureBits[RISCV::FeatureStdExtD]) {
46
0
    errs() << "Hard-float 'd' ABI can't be used for a target that "
47
0
              "doesn't support the D instruction set extension (ignoring "
48
0
              "target-abi)\n";
49
0
    TargetABI = ABI_Unknown;
50
25.6k
  } else if (IsRV32E && TargetABI != ABI_ILP32E && TargetABI != ABI_Unknown) {
51
0
    errs()
52
0
        << "Only the ilp32e ABI is supported for RV32E (ignoring target-abi)\n";
53
0
    TargetABI = ABI_Unknown;
54
0
  }
55
56
25.6k
  if (TargetABI != ABI_Unknown)
57
0
    return TargetABI;
58
59
  // For now, default to the ilp32/ilp32e/lp64 ABI if no explicit ABI is given
60
  // or an invalid/unrecognised string is given. In the future, it might be
61
  // worth changing this to default to ilp32f/lp64f and ilp32d/lp64d when
62
  // hardware support for floating point is present.
63
25.6k
  if (IsRV32E)
64
0
    return ABI_ILP32E;
65
25.6k
  if (IsRV64)
66
12.5k
    return ABI_LP64;
67
13.1k
  return ABI_ILP32;
68
25.6k
}
69
} // namespace RISCVABI
70
71
namespace RISCVFeatures {
72
73
51.2k
void validate(const Triple &TT, const FeatureBitset &FeatureBits) {
74
51.2k
  if (TT.isArch64Bit() && FeatureBits[RISCV::FeatureRV32E])
75
0
    report_fatal_error("RV32E can't be enabled for an RV64 target");
76
51.2k
}
77
78
} // namespace RISCVFeatures
79
80
} // namespace llvm_ks