blob: 498ea6fda4b3b965b4558cee74723c4b21ee9b3d [file] [log] [blame]
Daniel Sanders23e98772014-11-02 16:09:29 +00001//===---- 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 "MipsRegisterInfo.h"
Eric Christophera5762812015-01-26 17:33:46 +000012#include "llvm/ADT/StringRef.h"
13#include "llvm/ADT/StringSwitch.h"
14#include "llvm/MC/MCTargetOptions.h"
Daniel Sanders23e98772014-11-02 16:09:29 +000015
16using namespace llvm;
17
18namespace {
19static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};
20
21static 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
Craig Topper862d5d82015-09-28 00:15:34 +000026ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const {
Daniel Sanders23e98772014-11-02 16:09:29 +000027 if (IsO32())
28 return makeArrayRef(O32IntRegs);
29 if (IsN32() || IsN64())
30 return makeArrayRef(Mips64IntRegs);
31 llvm_unreachable("Unhandled ABI");
32}
Daniel Sandersd7eba312014-11-07 12:21:37 +000033
Craig Topper862d5d82015-09-28 00:15:34 +000034ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const {
Daniel Sandersd7eba312014-11-07 12:21:37 +000035 if (IsO32())
36 return makeArrayRef(O32IntRegs);
37 if (IsN32() || IsN64())
38 return makeArrayRef(Mips64IntRegs);
39 llvm_unreachable("Unhandled ABI");
40}
Daniel Sanders2c6f4b42014-11-07 15:03:53 +000041
42unsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const {
43 if (IsO32())
44 return CC != CallingConv::Fast ? 16 : 0;
Daniel Sanders43750eab2016-06-03 10:38:09 +000045 if (IsN32() || IsN64())
Daniel Sanders2c6f4b42014-11-07 15:03:53 +000046 return 0;
47 llvm_unreachable("Unhandled ABI");
48}
Eric Christophera5762812015-01-26 17:33:46 +000049
Daniel Sanders50f17232015-09-15 16:17:27 +000050MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,
Eric Christophera5762812015-01-26 17:33:46 +000051 const MCTargetOptions &Options) {
52 if (Options.getABIName().startswith("o32"))
53 return MipsABIInfo::O32();
Simon Atanasyanedd7a7b2016-12-10 17:30:09 +000054 if (Options.getABIName().startswith("n32"))
Eric Christophera5762812015-01-26 17:33:46 +000055 return MipsABIInfo::N32();
Simon Atanasyanedd7a7b2016-12-10 17:30:09 +000056 if (Options.getABIName().startswith("n64"))
Eric Christophera5762812015-01-26 17:33:46 +000057 return MipsABIInfo::N64();
Simon Atanasyanedd7a7b2016-12-10 17:30:09 +000058 assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");
Eric Christophera5762812015-01-26 17:33:46 +000059
Daniel Sandersde393322016-06-23 12:42:53 +000060 if (TT.getArch() == Triple::mips64 || TT.getArch() == Triple::mips64el)
61 return MipsABIInfo::N64();
62 return MipsABIInfo::O32();
Eric Christophera5762812015-01-26 17:33:46 +000063}
Daniel Sanders81eb66c2015-04-17 09:50:21 +000064
65unsigned MipsABIInfo::GetStackPtr() const {
66 return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;
67}
68
69unsigned MipsABIInfo::GetFramePtr() const {
70 return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;
71}
72
Vasileios Kalintirisbb698c72015-06-02 13:14:46 +000073unsigned MipsABIInfo::GetBasePtr() const {
74 return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;
75}
76
Daniel Sanders6ba3dd62016-06-03 09:53:06 +000077unsigned MipsABIInfo::GetGlobalPtr() const {
78 return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;
79}
80
Daniel Sanders81eb66c2015-04-17 09:50:21 +000081unsigned MipsABIInfo::GetNullPtr() const {
82 return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;
83}
84
Daniel Sandersa39ef1c2015-08-17 10:11:55 +000085unsigned MipsABIInfo::GetZeroReg() const {
86 return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;
87}
88
Daniel Sanders81eb66c2015-04-17 09:50:21 +000089unsigned MipsABIInfo::GetPtrAdduOp() const {
90 return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;
91}
92
93unsigned MipsABIInfo::GetPtrAddiuOp() const {
94 return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;
95}
96
Simon Dardis878c0b12016-06-14 13:39:43 +000097unsigned MipsABIInfo::GetPtrSubuOp() const {
98 return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;
99}
100
Simon Dardisa2d8cc32016-04-28 16:26:43 +0000101unsigned MipsABIInfo::GetPtrAndOp() const {
102 return ArePtrs64bit() ? Mips::AND64 : Mips::AND;
103}
104
Vasileios Kalintiris1c78ca62015-08-11 08:56:25 +0000105unsigned MipsABIInfo::GetGPRMoveOp() const {
106 return ArePtrs64bit() ? Mips::OR64 : Mips::OR;
107}
108
Daniel Sanders81eb66c2015-04-17 09:50:21 +0000109unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {
110 static const unsigned EhDataReg[] = {
111 Mips::A0, Mips::A1, Mips::A2, Mips::A3
112 };
113 static const unsigned EhDataReg64[] = {
114 Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64
115 };
116
117 return IsN64() ? EhDataReg64[I] : EhDataReg[I];
118}
119