Coverage Report

Created: 2024-01-17 10:31

/src/llvm-project/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
// 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
#include "MipsABIInfo.h"
10
#include "Mips.h"
11
#include "llvm/ADT/StringRef.h"
12
#include "llvm/CodeGen/LowLevelType.h"
13
#include "llvm/MC/MCTargetOptions.h"
14
#include "llvm/Support/CommandLine.h"
15
16
using namespace llvm;
17
18
// Note: this option is defined here to be visible from libLLVMMipsAsmParser
19
//       and libLLVMMipsCodeGen
20
cl::opt<bool>
21
EmitJalrReloc("mips-jalr-reloc", cl::Hidden,
22
              cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"),
23
              cl::init(true));
24
25
namespace {
26
static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
27
28
static const MCPhysReg Mips64IntRegs[8] = {
29
    Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,
30
    Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};
31
}
32
33
0
ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const {
34
0
  if (IsO32())
35
0
    return ArrayRef(O32IntRegs);
36
0
  if (IsN32() || IsN64())
37
0
    return ArrayRef(Mips64IntRegs);
38
0
  llvm_unreachable("Unhandled ABI");
39
0
}
40
41
0
ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const {
42
0
  if (IsO32())
43
0
    return ArrayRef(O32IntRegs);
44
0
  if (IsN32() || IsN64())
45
0
    return ArrayRef(Mips64IntRegs);
46
0
  llvm_unreachable("Unhandled ABI");
47
0
}
48
49
24
unsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const {
50
24
  if (IsO32())
51
0
    return CC != CallingConv::Fast ? 16 : 0;
52
24
  if (IsN32() || IsN64())
53
24
    return 0;
54
0
  llvm_unreachable("Unhandled ABI");
55
0
}
56
57
MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,
58
9
                                          const MCTargetOptions &Options) {
59
9
  if (Options.getABIName().starts_with("o32"))
60
0
    return MipsABIInfo::O32();
61
9
  if (Options.getABIName().starts_with("n32"))
62
0
    return MipsABIInfo::N32();
63
9
  if (Options.getABIName().starts_with("n64"))
64
0
    return MipsABIInfo::N64();
65
9
  if (TT.getEnvironment() == llvm::Triple::GNUABIN32)
66
0
    return MipsABIInfo::N32();
67
9
  assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
68
69
9
  if (TT.isMIPS64())
70
9
    return MipsABIInfo::N64();
71
0
  return MipsABIInfo::O32();
72
9
}
73
74
48
unsigned MipsABIInfo::GetStackPtr() const {
75
48
  return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
76
48
}
77
78
72
unsigned MipsABIInfo::GetFramePtr() const {
79
72
  return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
80
72
}
81
82
0
unsigned MipsABIInfo::GetBasePtr() const {
83
0
  return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
84
0
}
85
86
3
unsigned MipsABIInfo::GetGlobalPtr() const {
87
3
  return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
88
3
}
89
90
48
unsigned MipsABIInfo::GetNullPtr() const {
91
48
  return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
92
48
}
93
94
0
unsigned MipsABIInfo::GetZeroReg() const {
95
0
  return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
96
0
}
97
98
0
unsigned MipsABIInfo::GetPtrAdduOp() const {
99
0
  return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
100
0
}
101
102
72
unsigned MipsABIInfo::GetPtrAddiuOp() const {
103
72
  return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
104
72
}
105
106
0
unsigned MipsABIInfo::GetPtrSubuOp() const {
107
0
  return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
108
0
}
109
110
0
unsigned MipsABIInfo::GetPtrAndOp() const {
111
0
  return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
112
0
}
113
114
48
unsigned MipsABIInfo::GetGPRMoveOp() const {
115
48
  return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
116
48
}
117
118
0
unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
119
0
  static const unsigned EhDataReg[] = {
120
0
    Mips::A0, Mips::A1, Mips::A2, Mips::A3
121
0
  };
122
0
  static const unsigned EhDataReg64[] = {
123
0
    Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
124
0
  };
125
126
0
  return IsN64() ? EhDataReg64[I] : EhDataReg[I];
127
0
}
128