Coverage Report

Created: 2025-07-14 06:17

/src/keystone/llvm/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp
Line
Count
Source (jump to first uncovered line)
1
//===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "MipsABIInfo.h"
11
#include "MCTargetDesc/MipsMCTargetDesc.h"
12
#include "llvm/ADT/StringRef.h"
13
#include "llvm/ADT/StringSwitch.h"
14
#include "llvm/MC/MCTargetOptions.h"
15
16
using namespace llvm_ks;
17
18
namespace {
19
static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
20
21
static const MCPhysReg Mips64IntRegs[8] = {
22
    Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,
23
    Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};
24
}
25
26
0
ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const {
27
0
  if (IsO32())
28
0
    return makeArrayRef(O32IntRegs);
29
0
  if (IsN32() || IsN64())
30
0
    return makeArrayRef(Mips64IntRegs);
31
0
  llvm_unreachable("Unhandled ABI");
32
0
}
33
34
0
ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const {
35
0
  if (IsO32())
36
0
    return makeArrayRef(O32IntRegs);
37
0
  if (IsN32() || IsN64())
38
0
    return makeArrayRef(Mips64IntRegs);
39
0
  llvm_unreachable("Unhandled ABI");
40
0
}
41
42
MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,
43
5.46k
                                          const MCTargetOptions &Options) {
44
5.46k
  if (Options.getABIName().startswith("o32"))
45
0
    return MipsABIInfo::O32();
46
5.46k
  else if (Options.getABIName().startswith("n32"))
47
0
    return MipsABIInfo::N32();
48
5.46k
  else if (Options.getABIName().startswith("n64"))
49
0
    return MipsABIInfo::N64();
50
5.46k
  else if (Options.getABIName().startswith("eabi"))
51
0
    return MipsABIInfo::EABI();
52
5.46k
  else if (!Options.getABIName().empty())
53
0
    llvm_unreachable("Unknown ABI option for MIPS");
54
55
  // FIXME: This shares code with the selectMipsCPU routine that's
56
  // used and not shared in a couple of other places. This needs unifying
57
  // at some level.
58
5.46k
  if (CPU.empty() || CPU == "generic") {
59
0
    if (TT.getArch() == Triple::mips || TT.getArch() == Triple::mipsel)
60
0
      CPU = "mips32";
61
0
    else
62
0
      CPU = "mips64";
63
0
  }
64
65
5.46k
  return StringSwitch<MipsABIInfo>(CPU)
66
5.46k
      .Case("mips1", MipsABIInfo::O32())
67
5.46k
      .Case("mips2", MipsABIInfo::O32())
68
5.46k
      .Case("mips32", MipsABIInfo::O32())
69
5.46k
      .Case("mips32r2", MipsABIInfo::O32())
70
5.46k
      .Case("mips32r3", MipsABIInfo::O32())
71
5.46k
      .Case("mips32r5", MipsABIInfo::O32())
72
5.46k
      .Case("mips32r6", MipsABIInfo::O32())
73
5.46k
      .Case("mips3", MipsABIInfo::N64())
74
5.46k
      .Case("mips4", MipsABIInfo::N64())
75
5.46k
      .Case("mips5", MipsABIInfo::N64())
76
5.46k
      .Case("mips64", MipsABIInfo::N64())
77
5.46k
      .Case("mips64r2", MipsABIInfo::N64())
78
5.46k
      .Case("mips64r3", MipsABIInfo::N64())
79
5.46k
      .Case("mips64r5", MipsABIInfo::N64())
80
5.46k
      .Case("mips64r6", MipsABIInfo::N64())
81
5.46k
      .Case("octeon", MipsABIInfo::N64())
82
5.46k
      .Default(MipsABIInfo::Unknown());
83
5.46k
}
84
85
0
unsigned MipsABIInfo::GetStackPtr() const {
86
0
  return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
87
0
}
88
89
0
unsigned MipsABIInfo::GetFramePtr() const {
90
0
  return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
91
0
}
92
93
0
unsigned MipsABIInfo::GetBasePtr() const {
94
0
  return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
95
0
}
96
97
12
unsigned MipsABIInfo::GetNullPtr() const {
98
12
  return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
99
12
}
100
101
544
unsigned MipsABIInfo::GetZeroReg() const {
102
544
  return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
103
544
}
104
105
0
unsigned MipsABIInfo::GetPtrAdduOp() const {
106
0
  return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
107
0
}
108
109
0
unsigned MipsABIInfo::GetPtrAddiuOp() const {
110
0
  return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
111
0
}
112
113
0
unsigned MipsABIInfo::GetGPRMoveOp() const {
114
0
  return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
115
0
}
116
117
0
unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
118
0
  static const unsigned EhDataReg[] = {
119
0
    Mips::A0, Mips::A1, Mips::A2, Mips::A3
120
0
  };
121
0
  static const unsigned EhDataReg64[] = {
122
0
    Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
123
0
  };
124
125
0
  return IsN64() ? EhDataReg64[I] : EhDataReg[I];
126
0
}
127