LLVM  3.7.0
BPFRegisterInfo.cpp
Go to the documentation of this file.
1 //===-- BPFRegisterInfo.cpp - BPF Register Information ----------*- C++ -*-===//
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 // This file contains the BPF implementation of the TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "BPF.h"
15 #include "BPFRegisterInfo.h"
16 #include "BPFSubtarget.h"
24 
25 #define GET_REGINFO_TARGET_DESC
26 #include "BPFGenRegisterInfo.inc"
27 using namespace llvm;
28 
30  : BPFGenRegisterInfo(BPF::R0) {}
31 
32 const MCPhysReg *
34  return CSR_SaveList;
35 }
36 
38  BitVector Reserved(getNumRegs());
39  Reserved.set(BPF::R10); // R10 is read only frame pointer
40  Reserved.set(BPF::R11); // R11 is pseudo stack pointer
41  return Reserved;
42 }
43 
45  int SPAdj, unsigned FIOperandNum,
46  RegScavenger *RS) const {
47  assert(SPAdj == 0 && "Unexpected");
48 
49  unsigned i = 0;
50  MachineInstr &MI = *II;
51  MachineFunction &MF = *MI.getParent()->getParent();
52  DebugLoc DL = MI.getDebugLoc();
53 
54  while (!MI.getOperand(i).isFI()) {
55  ++i;
56  assert(i < MI.getNumOperands() && "Instr doesn't have FrameIndex operand!");
57  }
58 
59  unsigned FrameReg = getFrameRegister(MF);
60  int FrameIndex = MI.getOperand(i).getIndex();
61 
62  if (MI.getOpcode() == BPF::MOV_rr) {
64  int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex);
65 
66  MI.getOperand(i).ChangeToRegister(FrameReg, false);
67 
68  MachineBasicBlock &MBB = *MI.getParent();
69  unsigned reg = MI.getOperand(i - 1).getReg();
70  BuildMI(MBB, ++II, DL, TII.get(BPF::ADD_ri), reg)
71  .addReg(reg)
72  .addImm(Offset);
73  return;
74  }
75 
76  int Offset = MF.getFrameInfo()->getObjectOffset(FrameIndex) +
77  MI.getOperand(i + 1).getImm();
78 
79  if (!isInt<32>(Offset))
80  llvm_unreachable("bug in frame offset");
81 
82  MI.getOperand(i).ChangeToRegister(FrameReg, false);
83  MI.getOperand(i + 1).ChangeToImmediate(Offset);
84 }
85 
87  return BPF::R10;
88 }
bool isInt< 32 >(int64_t x)
Definition: MathExtras.h:276
const MachineFunction * getParent() const
getParent - Return the MachineFunction containing this basic block.
BitVector & set()
Definition: BitVector.h:218
unsigned getFrameRegister(const MachineFunction &MF) const override
void ChangeToRegister(unsigned Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isDebug=false)
ChangeToRegister - Replace this operand with a new register operand of the specified value...
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
A debug info location.
Definition: DebugLoc.h:34
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const HexagonInstrInfo * TII
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:98
const MachineInstrBuilder & addImm(int64_t Val) const
addImm - Add a new immediate operand.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:271
bool isFI() const
isFI - Tests if this is a MO_FrameIndex operand.
int64_t getImm() const
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:267
void ChangeToImmediate(int64_t ImmVal)
ChangeToImmediate - Replace this operand with a new immediate operand of the specified value...
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:120
TargetInstrInfo - Interface to description of machine instruction set.
bundle_iterator< MachineInstr, instr_iterator > iterator
void eliminateFrameIndex(MachineBasicBlock::iterator MI, int SPAdj, unsigned FIOperandNum, RegScavenger *RS=nullptr) const override
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:273
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
BuildMI - Builder interface.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
Definition: MCInstrInfo.h:45
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
Definition: MachineInstr.h:238
Representation of each machine instruction.
Definition: MachineInstr.h:51
unsigned getReg() const
getReg - Returns the register number.
virtual const TargetInstrInfo * getInstrInfo() const
const MCPhysReg * getCalleeSavedRegs(const MachineFunction *MF) const override
BitVector getReservedRegs(const MachineFunction &MF) const override