LLVM API Documentation
00001 //===-- Thumb1InstrInfo.cpp - Thumb-1 Instruction Information -------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the Thumb-1 implementation of the TargetInstrInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "ARMSubtarget.h" 00015 #include "Thumb1InstrInfo.h" 00016 #include "llvm/CodeGen/MachineFrameInfo.h" 00017 #include "llvm/CodeGen/MachineInstrBuilder.h" 00018 #include "llvm/CodeGen/MachineMemOperand.h" 00019 #include "llvm/CodeGen/MachineRegisterInfo.h" 00020 #include "llvm/MC/MCInst.h" 00021 00022 using namespace llvm; 00023 00024 Thumb1InstrInfo::Thumb1InstrInfo(const ARMSubtarget &STI) 00025 : ARMBaseInstrInfo(STI), RI(STI) { 00026 } 00027 00028 /// getNoopForMachoTarget - Return the noop instruction to use for a noop. 00029 void Thumb1InstrInfo::getNoopForMachoTarget(MCInst &NopInst) const { 00030 NopInst.setOpcode(ARM::tMOVr); 00031 NopInst.addOperand(MCOperand::CreateReg(ARM::R8)); 00032 NopInst.addOperand(MCOperand::CreateReg(ARM::R8)); 00033 NopInst.addOperand(MCOperand::CreateImm(ARMCC::AL)); 00034 NopInst.addOperand(MCOperand::CreateReg(0)); 00035 } 00036 00037 unsigned Thumb1InstrInfo::getUnindexedOpcode(unsigned Opc) const { 00038 return 0; 00039 } 00040 00041 void Thumb1InstrInfo::copyPhysReg(MachineBasicBlock &MBB, 00042 MachineBasicBlock::iterator I, DebugLoc DL, 00043 unsigned DestReg, unsigned SrcReg, 00044 bool KillSrc) const { 00045 // Need to check the arch. 00046 MachineFunction &MF = *MBB.getParent(); 00047 const ARMSubtarget &st = MF.getTarget().getSubtarget<ARMSubtarget>(); 00048 00049 assert(ARM::GPRRegClass.contains(DestReg, SrcReg) && 00050 "Thumb1 can only copy GPR registers"); 00051 00052 if (st.hasV6Ops() || ARM::hGPRRegClass.contains(SrcReg) 00053 || !ARM::tGPRRegClass.contains(DestReg)) 00054 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tMOVr), DestReg) 00055 .addReg(SrcReg, getKillRegState(KillSrc))); 00056 else { 00057 // FIXME: The performance consequences of this are going to be atrocious. 00058 // Some things to try that should be better: 00059 // * 'mov hi, $src; mov $dst, hi', with hi as either r10 or r11 00060 // * 'movs $dst, $src' if cpsr isn't live 00061 // See: http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-August/075998.html 00062 00063 // 'MOV lo, lo' is unpredictable on < v6, so use the stack to do it 00064 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tPUSH))) 00065 .addReg(SrcReg, getKillRegState(KillSrc)); 00066 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tPOP))) 00067 .addReg(DestReg, getDefRegState(true)); 00068 } 00069 } 00070 00071 void Thumb1InstrInfo:: 00072 storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, 00073 unsigned SrcReg, bool isKill, int FI, 00074 const TargetRegisterClass *RC, 00075 const TargetRegisterInfo *TRI) const { 00076 assert((RC == &ARM::tGPRRegClass || 00077 (TargetRegisterInfo::isPhysicalRegister(SrcReg) && 00078 isARMLowRegister(SrcReg))) && "Unknown regclass!"); 00079 00080 if (RC == &ARM::tGPRRegClass || 00081 (TargetRegisterInfo::isPhysicalRegister(SrcReg) && 00082 isARMLowRegister(SrcReg))) { 00083 DebugLoc DL; 00084 if (I != MBB.end()) DL = I->getDebugLoc(); 00085 00086 MachineFunction &MF = *MBB.getParent(); 00087 MachineFrameInfo &MFI = *MF.getFrameInfo(); 00088 MachineMemOperand *MMO = 00089 MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), 00090 MachineMemOperand::MOStore, 00091 MFI.getObjectSize(FI), 00092 MFI.getObjectAlignment(FI)); 00093 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tSTRspi)) 00094 .addReg(SrcReg, getKillRegState(isKill)) 00095 .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); 00096 } 00097 } 00098 00099 void Thumb1InstrInfo:: 00100 loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, 00101 unsigned DestReg, int FI, 00102 const TargetRegisterClass *RC, 00103 const TargetRegisterInfo *TRI) const { 00104 assert((RC == &ARM::tGPRRegClass || 00105 (TargetRegisterInfo::isPhysicalRegister(DestReg) && 00106 isARMLowRegister(DestReg))) && "Unknown regclass!"); 00107 00108 if (RC == &ARM::tGPRRegClass || 00109 (TargetRegisterInfo::isPhysicalRegister(DestReg) && 00110 isARMLowRegister(DestReg))) { 00111 DebugLoc DL; 00112 if (I != MBB.end()) DL = I->getDebugLoc(); 00113 00114 MachineFunction &MF = *MBB.getParent(); 00115 MachineFrameInfo &MFI = *MF.getFrameInfo(); 00116 MachineMemOperand *MMO = 00117 MF.getMachineMemOperand(MachinePointerInfo::getFixedStack(FI), 00118 MachineMemOperand::MOLoad, 00119 MFI.getObjectSize(FI), 00120 MFI.getObjectAlignment(FI)); 00121 AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tLDRspi), DestReg) 00122 .addFrameIndex(FI).addImm(0).addMemOperand(MMO)); 00123 } 00124 } 00125 00126 void 00127 Thumb1InstrInfo::expandLoadStackGuard(MachineBasicBlock::iterator MI, 00128 Reloc::Model RM) const { 00129 if (RM == Reloc::PIC_) 00130 expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_pcrel, ARM::tLDRi, RM); 00131 else 00132 expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_abs, ARM::tLDRi, RM); 00133 }