LLVM  6.0.0svn
Thumb1InstrInfo.cpp
Go to the documentation of this file.
1 //===-- Thumb1InstrInfo.cpp - Thumb-1 Instruction Information -------------===//
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 Thumb-1 implementation of the TargetInstrInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "Thumb1InstrInfo.h"
15 #include "ARMSubtarget.h"
20 #include "llvm/MC/MCInst.h"
21 
22 using namespace llvm;
23 
25  : ARMBaseInstrInfo(STI), RI() {}
26 
27 /// Return the noop instruction to use for a noop.
28 void Thumb1InstrInfo::getNoop(MCInst &NopInst) const {
29  NopInst.setOpcode(ARM::tMOVr);
30  NopInst.addOperand(MCOperand::createReg(ARM::R8));
31  NopInst.addOperand(MCOperand::createReg(ARM::R8));
33  NopInst.addOperand(MCOperand::createReg(0));
34 }
35 
36 unsigned Thumb1InstrInfo::getUnindexedOpcode(unsigned Opc) const {
37  return 0;
38 }
39 
42  const DebugLoc &DL, unsigned DestReg,
43  unsigned SrcReg, bool KillSrc) const {
44  // Need to check the arch.
45  MachineFunction &MF = *MBB.getParent();
46  const ARMSubtarget &st = MF.getSubtarget<ARMSubtarget>();
47 
48  assert(ARM::GPRRegClass.contains(DestReg, SrcReg) &&
49  "Thumb1 can only copy GPR registers");
50 
51  if (st.hasV6Ops() || ARM::hGPRRegClass.contains(SrcReg)
52  || !ARM::tGPRRegClass.contains(DestReg))
53  BuildMI(MBB, I, DL, get(ARM::tMOVr), DestReg)
54  .addReg(SrcReg, getKillRegState(KillSrc))
56  else {
57  // FIXME: Can also use 'mov hi, $src; mov $dst, hi',
58  // with hi as either r10 or r11.
59 
60  const TargetRegisterInfo *RegInfo = st.getRegisterInfo();
61  if (MBB.computeRegisterLiveness(RegInfo, ARM::CPSR, I)
63  BuildMI(MBB, I, DL, get(ARM::tMOVSr), DestReg)
64  .addReg(SrcReg, getKillRegState(KillSrc))
65  ->addRegisterDead(ARM::CPSR, RegInfo);
66  return;
67  }
68 
69  // 'MOV lo, lo' is unpredictable on < v6, so use the stack to do it
70  BuildMI(MBB, I, DL, get(ARM::tPUSH))
72  .addReg(SrcReg, getKillRegState(KillSrc));
73  BuildMI(MBB, I, DL, get(ARM::tPOP))
75  .addReg(DestReg, getDefRegState(true));
76  }
77 }
78 
81  unsigned SrcReg, bool isKill, int FI,
82  const TargetRegisterClass *RC,
83  const TargetRegisterInfo *TRI) const {
84  assert((RC == &ARM::tGPRRegClass ||
86  isARMLowRegister(SrcReg))) && "Unknown regclass!");
87 
88  if (RC == &ARM::tGPRRegClass ||
90  isARMLowRegister(SrcReg))) {
91  DebugLoc DL;
92  if (I != MBB.end()) DL = I->getDebugLoc();
93 
94  MachineFunction &MF = *MBB.getParent();
95  MachineFrameInfo &MFI = MF.getFrameInfo();
98  MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
99  BuildMI(MBB, I, DL, get(ARM::tSTRspi))
100  .addReg(SrcReg, getKillRegState(isKill))
101  .addFrameIndex(FI)
102  .addImm(0)
103  .addMemOperand(MMO)
104  .add(predOps(ARMCC::AL));
105  }
106 }
107 
110  unsigned DestReg, int FI,
111  const TargetRegisterClass *RC,
112  const TargetRegisterInfo *TRI) const {
113  assert((RC == &ARM::tGPRRegClass ||
115  isARMLowRegister(DestReg))) && "Unknown regclass!");
116 
117  if (RC == &ARM::tGPRRegClass ||
119  isARMLowRegister(DestReg))) {
120  DebugLoc DL;
121  if (I != MBB.end()) DL = I->getDebugLoc();
122 
123  MachineFunction &MF = *MBB.getParent();
124  MachineFrameInfo &MFI = MF.getFrameInfo();
127  MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
128  BuildMI(MBB, I, DL, get(ARM::tLDRspi), DestReg)
129  .addFrameIndex(FI)
130  .addImm(0)
131  .addMemOperand(MMO)
132  .add(predOps(ARMCC::AL));
133  }
134 }
135 
136 void Thumb1InstrInfo::expandLoadStackGuard(
138  MachineFunction &MF = *MI->getParent()->getParent();
139  const TargetMachine &TM = MF.getTarget();
140  if (TM.isPositionIndependent())
141  expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_pcrel, ARM::tLDRi);
142  else
143  expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_abs, ARM::tLDRi);
144 }
const MachineInstrBuilder & add(const MachineOperand &MO) const
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
LivenessQueryResult computeRegisterLiveness(const TargetRegisterInfo *TRI, unsigned Reg, const_iterator Before, unsigned Neighborhood=10) const
Return whether (physical) register Reg has been <def>ined and not <kill>ed as of just before Before...
unsigned getUnindexedOpcode(unsigned Opc) const override
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
A debug info location.
Definition: DebugLoc.h:34
bool hasV6Ops() const
Definition: ARMSubtarget.h:500
return AArch64::GPR64RegClass contains(Reg)
A description of a memory reference used in the backend.
static MCOperand createReg(unsigned Reg)
Definition: MCInst.h:116
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
MachineMemOperand * getMachineMemOperand(MachinePointerInfo PtrInfo, MachineMemOperand::Flags f, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr, SyncScope::ID SSID=SyncScope::System, AtomicOrdering Ordering=AtomicOrdering::NotAtomic, AtomicOrdering FailureOrdering=AtomicOrdering::NotAtomic)
getMachineMemOperand - Allocate a new MachineMemOperand.
static std::array< MachineOperand, 2 > predOps(ARMCC::CondCodes Pred, unsigned PredReg=0)
Get the operands corresponding to the given Pred value.
int64_t getObjectSize(int ObjectIdx) const
Return the size of the specified object.
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
unsigned getKillRegState(bool B)
unsigned getDefRegState(bool B)
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void expandLoadStackGuardBase(MachineBasicBlock::iterator MI, unsigned LoadImmOpc, unsigned LoadOpc) const
Register is known to be fully dead.
const MachineInstrBuilder & addFrameIndex(int Idx) const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
The memory access writes data.
void setOpcode(unsigned Op)
Definition: MCInst.h:167
const MachineInstrBuilder & addMemOperand(MachineMemOperand *MMO) const
void copyPhysReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, const DebugLoc &DL, unsigned DestReg, unsigned SrcReg, bool KillSrc) const override
void getNoop(MCInst &NopInst) const override
Return the noop instruction to use for a noop.
The memory access reads data.
static MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
static bool isARMLowRegister(unsigned Reg)
isARMLowRegister - Returns true if the register is a low register (r0-r7).
Definition: ARMBaseInfo.h:147
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
bool isPositionIndependent() const
Thumb1InstrInfo(const ARMSubtarget &STI)
#define I(x, y, z)
Definition: MD5.cpp:58
const ARMBaseRegisterInfo * getRegisterInfo() const override
Definition: ARMSubtarget.h:467
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned SrcReg, bool isKill, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:57
IRTranslator LLVM IR MI
void addOperand(const MCOperand &Op)
Definition: MCInst.h:177
void loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, unsigned DestReg, int FrameIndex, const TargetRegisterClass *RC, const TargetRegisterInfo *TRI) const override
static MCOperand createImm(int64_t Val)
Definition: MCInst.h:123