brintos

brintos / llvm-project-archived public Read only

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