Path: blob/main/contrib/llvm-project/llvm/lib/Target/Mips/MCTargetDesc/MipsABIInfo.cpp
35294 views
//===---- MipsABIInfo.cpp - Information about MIPS ABI's ------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "MipsABIInfo.h"9#include "Mips.h"10#include "llvm/ADT/StringRef.h"11#include "llvm/CodeGenTypes/LowLevelType.h"12#include "llvm/MC/MCTargetOptions.h"13#include "llvm/Support/CommandLine.h"1415using namespace llvm;1617// Note: this option is defined here to be visible from libLLVMMipsAsmParser18// and libLLVMMipsCodeGen19cl::opt<bool>20EmitJalrReloc("mips-jalr-reloc", cl::Hidden,21cl::desc("MIPS: Emit R_{MICRO}MIPS_JALR relocation with jalr"),22cl::init(true));2324namespace {25static const MCPhysReg O32IntRegs[4] = {Mips::A0, Mips::A1, Mips::A2, Mips::A3};2627static const MCPhysReg Mips64IntRegs[8] = {28Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64,29Mips::T0_64, Mips::T1_64, Mips::T2_64, Mips::T3_64};30}3132ArrayRef<MCPhysReg> MipsABIInfo::GetByValArgRegs() const {33if (IsO32())34return ArrayRef(O32IntRegs);35if (IsN32() || IsN64())36return ArrayRef(Mips64IntRegs);37llvm_unreachable("Unhandled ABI");38}3940ArrayRef<MCPhysReg> MipsABIInfo::GetVarArgRegs() const {41if (IsO32())42return ArrayRef(O32IntRegs);43if (IsN32() || IsN64())44return ArrayRef(Mips64IntRegs);45llvm_unreachable("Unhandled ABI");46}4748unsigned MipsABIInfo::GetCalleeAllocdArgSizeInBytes(CallingConv::ID CC) const {49if (IsO32())50return CC != CallingConv::Fast ? 16 : 0;51if (IsN32() || IsN64())52return 0;53llvm_unreachable("Unhandled ABI");54}5556MipsABIInfo MipsABIInfo::computeTargetABI(const Triple &TT, StringRef CPU,57const MCTargetOptions &Options) {58if (Options.getABIName().starts_with("o32"))59return MipsABIInfo::O32();60if (Options.getABIName().starts_with("n32"))61return MipsABIInfo::N32();62if (Options.getABIName().starts_with("n64"))63return MipsABIInfo::N64();64if (TT.getEnvironment() == llvm::Triple::GNUABIN32)65return MipsABIInfo::N32();66assert(Options.getABIName().empty() && "Unknown ABI option for MIPS");6768if (TT.isMIPS64())69return MipsABIInfo::N64();70return MipsABIInfo::O32();71}7273unsigned MipsABIInfo::GetStackPtr() const {74return ArePtrs64bit() ? Mips::SP_64 : Mips::SP;75}7677unsigned MipsABIInfo::GetFramePtr() const {78return ArePtrs64bit() ? Mips::FP_64 : Mips::FP;79}8081unsigned MipsABIInfo::GetBasePtr() const {82return ArePtrs64bit() ? Mips::S7_64 : Mips::S7;83}8485unsigned MipsABIInfo::GetGlobalPtr() const {86return ArePtrs64bit() ? Mips::GP_64 : Mips::GP;87}8889unsigned MipsABIInfo::GetNullPtr() const {90return ArePtrs64bit() ? Mips::ZERO_64 : Mips::ZERO;91}9293unsigned MipsABIInfo::GetZeroReg() const {94return AreGprs64bit() ? Mips::ZERO_64 : Mips::ZERO;95}9697unsigned MipsABIInfo::GetPtrAdduOp() const {98return ArePtrs64bit() ? Mips::DADDu : Mips::ADDu;99}100101unsigned MipsABIInfo::GetPtrAddiuOp() const {102return ArePtrs64bit() ? Mips::DADDiu : Mips::ADDiu;103}104105unsigned MipsABIInfo::GetPtrSubuOp() const {106return ArePtrs64bit() ? Mips::DSUBu : Mips::SUBu;107}108109unsigned MipsABIInfo::GetPtrAndOp() const {110return ArePtrs64bit() ? Mips::AND64 : Mips::AND;111}112113unsigned MipsABIInfo::GetGPRMoveOp() const {114return ArePtrs64bit() ? Mips::OR64 : Mips::OR;115}116117unsigned MipsABIInfo::GetEhDataReg(unsigned I) const {118static const unsigned EhDataReg[] = {119Mips::A0, Mips::A1, Mips::A2, Mips::A3120};121static const unsigned EhDataReg64[] = {122Mips::A0_64, Mips::A1_64, Mips::A2_64, Mips::A3_64123};124125return IsN64() ? EhDataReg64[I] : EhDataReg[I];126}127128129130