LLVM  15.0.0git
LoongArchRegisterInfo.cpp
Go to the documentation of this file.
1 //===- LoongArchRegisterInfo.cpp - LoongArch Register Information -*- C++ -*-=//
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 // This file contains the LoongArch implementation of the TargetRegisterInfo
10 // class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "LoongArchRegisterInfo.h"
15 #include "LoongArch.h"
16 #include "LoongArchSubtarget.h"
24 
25 using namespace llvm;
26 
27 #define GET_REGINFO_TARGET_DESC
28 #include "LoongArchGenRegisterInfo.inc"
29 
31  : LoongArchGenRegisterInfo(LoongArch::R1, /*DwarfFlavour*/ 0,
32  /*EHFlavor*/ 0,
33  /*PC*/ 0, HwMode) {}
34 
35 const MCPhysReg *
37  auto &Subtarget = MF->getSubtarget<LoongArchSubtarget>();
38 
39  switch (Subtarget.getTargetABI()) {
40  default:
41  llvm_unreachable("Unrecognized ABI");
44  return CSR_ILP32S_LP64S_SaveList;
47  return CSR_ILP32F_LP64F_SaveList;
50  return CSR_ILP32D_LP64D_SaveList;
51  }
52 }
53 
54 const uint32_t *
56  CallingConv::ID CC) const {
57  auto &Subtarget = MF.getSubtarget<LoongArchSubtarget>();
58 
59  switch (Subtarget.getTargetABI()) {
60  default:
61  llvm_unreachable("Unrecognized ABI");
64  return CSR_ILP32S_LP64S_RegMask;
67  return CSR_ILP32F_LP64F_RegMask;
70  return CSR_ILP32D_LP64D_RegMask;
71  }
72 }
73 
75  return CSR_NoRegs_RegMask;
76 }
77 
80  const LoongArchFrameLowering *TFI = getFrameLowering(MF);
81  BitVector Reserved(getNumRegs());
82 
83  // Use markSuperRegs to ensure any register aliases are also reserved
84  markSuperRegs(Reserved, LoongArch::R0); // zero
85  markSuperRegs(Reserved, LoongArch::R2); // tp
86  markSuperRegs(Reserved, LoongArch::R3); // sp
87  markSuperRegs(Reserved, LoongArch::R21); // non-allocatable
88  if (TFI->hasFP(MF))
89  markSuperRegs(Reserved, LoongArch::R22); // fp
90  // Reserve the base register if we need to realign the stack and allocate
91  // variable-sized objects at runtime.
92  if (TFI->hasBP(MF))
93  markSuperRegs(Reserved, LoongArchABI::getBPReg()); // bp
94 
95  assert(checkAllSuperRegsMarked(Reserved));
96  return Reserved;
97 }
98 
100  return PhysReg == LoongArch::R0;
101 }
102 
103 Register
105  const TargetFrameLowering *TFI = getFrameLowering(MF);
106  return TFI->hasFP(MF) ? LoongArch::R22 : LoongArch::R3;
107 }
108 
110  int SPAdj,
111  unsigned FIOperandNum,
112  RegScavenger *RS) const {
113  assert(SPAdj == 0 && "Unexpected non-zero SPAdj value");
114  // TODO: Implement this when we have function calls
115 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::LoongArchABI::ABI_LP64S
@ ABI_LP64S
Definition: LoongArchBaseInfo.h:30
TargetFrameLowering.h
llvm::LoongArchRegisterInfo::getCalleeSavedRegs
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Definition: LoongArchRegisterInfo.cpp:36
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
LoongArchRegisterInfo.h
llvm::LoongArchABI::ABI_ILP32D
@ ABI_ILP32D
Definition: LoongArchBaseInfo.h:29
ErrorHandling.h
llvm::LoongArchABI::ABI_LP64F
@ ABI_LP64F
Definition: LoongArchBaseInfo.h:31
TargetInstrInfo.h
llvm::LoongArchABI::ABI_ILP32F
@ ABI_ILP32F
Definition: LoongArchBaseInfo.h:28
LoongArchSubtarget.h
llvm::LoongArchRegisterInfo::getCallPreservedMask
const uint32_t * getCallPreservedMask(const MachineFunction &MF, CallingConv::ID) const override
Definition: LoongArchRegisterInfo.cpp:55
llvm::LoongArchRegisterInfo::getNoPreservedMask
const uint32_t * getNoPreservedMask() const override
Definition: LoongArchRegisterInfo.cpp:74
R2
#define R2(n)
llvm::LoongArchFrameLowering
Definition: LoongArchFrameLowering.h:21
llvm::TargetFrameLowering::hasFP
virtual bool hasFP(const MachineFunction &MF) const =0
hasFP - Return true if the specified function should have a dedicated frame pointer register.
llvm::BitVector
Definition: BitVector.h:75
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
LoongArchGenRegisterInfo
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:656
llvm::LoongArchRegisterInfo::isConstantPhysReg
bool isConstantPhysReg(MCRegister PhysReg) const override
Definition: LoongArchRegisterInfo.cpp:99
llvm::LoongArchRegisterInfo::getFrameRegister
Register getFrameRegister(const MachineFunction &MF) const override
Definition: LoongArchRegisterInfo.cpp:104
llvm::LoongArchRegisterInfo::eliminateFrameIndex
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
Definition: LoongArchRegisterInfo.cpp:109
llvm::LoongArchSubtarget
Definition: LoongArchSubtarget.h:32
llvm::RegScavenger
Definition: RegisterScavenging.h:34
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::LoongArchFrameLowering::hasBP
bool hasBP(const MachineFunction &MF) const
Definition: LoongArchFrameLowering.cpp:40
llvm::LoongArchRegisterInfo::LoongArchRegisterInfo
LoongArchRegisterInfo(unsigned HwMode)
Definition: LoongArchRegisterInfo.cpp:30
llvm::MachineFunction
Definition: MachineFunction.h:257
LoongArch.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
uint32_t
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::LoongArchABI::ABI_ILP32S
@ ABI_ILP32S
Definition: LoongArchBaseInfo.h:27
uint16_t
MachineFrameInfo.h
llvm::LoongArchABI::ABI_LP64D
@ ABI_LP64D
Definition: LoongArchBaseInfo.h:32
llvm::LoongArchABI::getBPReg
MCRegister getBPReg()
Definition: LoongArchBaseInfo.cpp:36
MachineInstrBuilder.h
llvm::LoongArchRegisterInfo::getReservedRegs
BitVector getReservedRegs(const MachineFunction &MF) const override
Definition: LoongArchRegisterInfo.cpp:79
RegisterScavenging.h
MachineFunction.h
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::LoongArchFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: LoongArchFrameLowering.cpp:31
llvm::MCRegister
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:24