LLVM  14.0.0git
MSP430RegisterInfo.cpp
Go to the documentation of this file.
1 //===-- MSP430RegisterInfo.cpp - MSP430 Register Information --------------===//
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 MSP430 implementation of the TargetRegisterInfo class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "MSP430RegisterInfo.h"
14 #include "MSP430.h"
16 #include "MSP430TargetMachine.h"
17 #include "llvm/ADT/BitVector.h"
21 #include "llvm/IR/Function.h"
25 
26 using namespace llvm;
27 
28 #define DEBUG_TYPE "msp430-reg-info"
29 
30 #define GET_REGINFO_TARGET_DESC
31 #include "MSP430GenRegisterInfo.inc"
32 
33 // FIXME: Provide proper call frame setup / destroy opcodes.
35  : MSP430GenRegisterInfo(MSP430::PC) {}
36 
37 const MCPhysReg*
39  const MSP430FrameLowering *TFI = getFrameLowering(*MF);
40  const Function* F = &MF->getFunction();
41  static const MCPhysReg CalleeSavedRegs[] = {
42  MSP430::R4, MSP430::R5, MSP430::R6, MSP430::R7,
43  MSP430::R8, MSP430::R9, MSP430::R10,
44  0
45  };
46  static const MCPhysReg CalleeSavedRegsFP[] = {
47  MSP430::R5, MSP430::R6, MSP430::R7,
48  MSP430::R8, MSP430::R9, MSP430::R10,
49  0
50  };
51  static const MCPhysReg CalleeSavedRegsIntr[] = {
52  MSP430::R4, MSP430::R5, MSP430::R6, MSP430::R7,
53  MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
54  MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15,
55  0
56  };
57  static const MCPhysReg CalleeSavedRegsIntrFP[] = {
58  MSP430::R5, MSP430::R6, MSP430::R7,
59  MSP430::R8, MSP430::R9, MSP430::R10, MSP430::R11,
60  MSP430::R12, MSP430::R13, MSP430::R14, MSP430::R15,
61  0
62  };
63 
64  if (TFI->hasFP(*MF))
65  return (F->getCallingConv() == CallingConv::MSP430_INTR ?
66  CalleeSavedRegsIntrFP : CalleeSavedRegsFP);
67  else
68  return (F->getCallingConv() == CallingConv::MSP430_INTR ?
69  CalleeSavedRegsIntr : CalleeSavedRegs);
70 
71 }
72 
74  BitVector Reserved(getNumRegs());
75  const MSP430FrameLowering *TFI = getFrameLowering(MF);
76 
77  // Mark 4 special registers with subregisters as reserved.
78  Reserved.set(MSP430::PCB);
79  Reserved.set(MSP430::SPB);
80  Reserved.set(MSP430::SRB);
81  Reserved.set(MSP430::CGB);
82  Reserved.set(MSP430::PC);
83  Reserved.set(MSP430::SP);
84  Reserved.set(MSP430::SR);
85  Reserved.set(MSP430::CG);
86 
87  // Mark frame pointer as reserved if needed.
88  if (TFI->hasFP(MF)) {
89  Reserved.set(MSP430::R4B);
90  Reserved.set(MSP430::R4);
91  }
92 
93  return Reserved;
94 }
95 
96 const TargetRegisterClass *
98  const {
99  return &MSP430::GR16RegClass;
100 }
101 
102 void
104  int SPAdj, unsigned FIOperandNum,
105  RegScavenger *RS) const {
106  assert(SPAdj == 0 && "Unexpected");
107 
108  MachineInstr &MI = *II;
109  MachineBasicBlock &MBB = *MI.getParent();
110  MachineFunction &MF = *MBB.getParent();
111  const MSP430FrameLowering *TFI = getFrameLowering(MF);
112  DebugLoc dl = MI.getDebugLoc();
113  int FrameIndex = MI.getOperand(FIOperandNum).getIndex();
114 
115  unsigned BasePtr = (TFI->hasFP(MF) ? MSP430::R4 : MSP430::SP);
117 
118  // Skip the saved PC
119  Offset += 2;
120 
121  if (!TFI->hasFP(MF))
122  Offset += MF.getFrameInfo().getStackSize();
123  else
124  Offset += 2; // Skip the saved FP
125 
126  // Fold imm into offset
127  Offset += MI.getOperand(FIOperandNum + 1).getImm();
128 
129  if (MI.getOpcode() == MSP430::ADDframe) {
130  // This is actually "load effective address" of the stack slot
131  // instruction. We have only two-address instructions, thus we need to
132  // expand it into mov + add
133  const TargetInstrInfo &TII = *MF.getSubtarget().getInstrInfo();
134 
135  MI.setDesc(TII.get(MSP430::MOV16rr));
136  MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
137 
138  if (Offset == 0)
139  return;
140 
141  // We need to materialize the offset via add instruction.
142  Register DstReg = MI.getOperand(0).getReg();
143  if (Offset < 0)
144  BuildMI(MBB, std::next(II), dl, TII.get(MSP430::SUB16ri), DstReg)
145  .addReg(DstReg).addImm(-Offset);
146  else
147  BuildMI(MBB, std::next(II), dl, TII.get(MSP430::ADD16ri), DstReg)
148  .addReg(DstReg).addImm(Offset);
149 
150  return;
151  }
152 
153  MI.getOperand(FIOperandNum).ChangeToRegister(BasePtr, false);
154  MI.getOperand(FIOperandNum + 1).ChangeToImmediate(Offset);
155 }
156 
158  const MSP430FrameLowering *TFI = getFrameLowering(MF);
159  return TFI->hasFP(MF) ? MSP430::R4 : MSP430::SP;
160 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm::MachineInstrBuilder::addImm
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
Definition: MachineInstrBuilder.h:131
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MSP430FrameLowering
Definition: MSP430FrameLowering.h:20
llvm::CallingConv::MSP430_INTR
@ MSP430_INTR
MSP430_INTR - Calling convention used for MSP430 interrupt routines.
Definition: CallingConv.h:121
MSP430TargetMachine.h
llvm::Function
Definition: Function.h:62
llvm::BitVector::set
BitVector & set()
Definition: BitVector.h:343
llvm::TargetSubtargetInfo::getInstrInfo
virtual const TargetInstrInfo * getInstrInfo() const
Definition: TargetSubtargetInfo.h:92
ErrorHandling.h
MSP430GenRegisterInfo
R4
#define R4(n)
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::TargetInstrInfo
TargetInstrInfo - Interface to description of machine instruction set.
Definition: TargetInstrInfo.h:97
TargetMachine.h
llvm::MSP430RegisterInfo::eliminateFrameIndex
void eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
Definition: MSP430RegisterInfo.cpp:103
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::MSP430RegisterInfo::MSP430RegisterInfo
MSP430RegisterInfo()
Definition: MSP430RegisterInfo.cpp:34
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
BitVector.h
llvm::MachineFrameInfo::getStackSize
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
Definition: MachineFrameInfo.h:553
llvm::MachineFrameInfo::getObjectOffset
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Definition: MachineFrameInfo.h:494
llvm::BitVector
Definition: BitVector.h:74
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:634
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MSP430RegisterInfo::getCalleeSavedRegs
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
Code Generation virtual methods...
Definition: MSP430RegisterInfo.cpp:38
llvm::RegScavenger
Definition: RegisterScavenging.h:34
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:650
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:225
llvm::MachineInstrBuilder::addReg
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Definition: MachineInstrBuilder.h:97
R6
#define R6(n)
llvm::MachineFunction
Definition: MachineFunction.h:234
TargetOptions.h
MSP430.h
llvm::MSP430RegisterInfo::getReservedRegs
BitVector getReservedRegs(const MachineFunction &MF) const override
Definition: MSP430RegisterInfo.cpp:73
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::MSP430RegisterInfo::getPointerRegClass
const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override
Definition: MSP430RegisterInfo.cpp:97
llvm::ISD::FrameIndex
@ FrameIndex
Definition: ISDOpcodes.h:80
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::MSP430FrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: MSP430FrameLowering.cpp:28
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:600
uint16_t
MachineFrameInfo.h
Function.h
MSP430MachineFunctionInfo.h
MachineInstrBuilder.h
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
MSP430RegisterInfo.h
MachineFunction.h
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::MSP430RegisterInfo::getFrameRegister
Register getFrameRegister(const MachineFunction &MF) const override
Definition: MSP430RegisterInfo.cpp:157