2009-11-08 06:00:39 +08:00
|
|
|
//===- Thumb1InstrInfo.cpp - Thumb-1 Instruction Information ----*- C++ -*-===//
|
2009-06-27 05:28:53 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-07-03 06:18:33 +08:00
|
|
|
// This file contains the Thumb-1 implementation of the TargetInstrInfo class.
|
2009-06-27 05:28:53 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-07 07:52:48 +08:00
|
|
|
#include "Thumb1InstrInfo.h"
|
2009-06-27 05:28:53 +08:00
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMGenInstrInfo.inc"
|
|
|
|
#include "ARMMachineFunctionInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2010-05-22 09:47:14 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2009-11-02 06:04:35 +08:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
|
|
|
#include "llvm/CodeGen/PseudoSourceValue.h"
|
2009-06-27 05:28:53 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-07-03 06:18:33 +08:00
|
|
|
#include "Thumb1InstrInfo.h"
|
2009-06-27 05:28:53 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-11-02 08:10:38 +08:00
|
|
|
Thumb1InstrInfo::Thumb1InstrInfo(const ARMSubtarget &STI)
|
|
|
|
: ARMBaseInstrInfo(STI), RI(*this, STI) {
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
|
2009-07-11 14:43:01 +08:00
|
|
|
unsigned Thumb1InstrInfo::getUnindexedOpcode(unsigned Opc) const {
|
2009-07-09 00:09:28 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
bool Thumb1InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
2010-05-07 04:33:48 +08:00
|
|
|
const TargetRegisterClass *SrcRC,
|
|
|
|
DebugLoc DL) const {
|
2010-06-16 06:08:33 +08:00
|
|
|
if (DestRC == ARM::GPRRegisterClass || DestRC == ARM::tcGPRRegisterClass) {
|
|
|
|
if (SrcRC == ARM::GPRRegisterClass || SrcRC == ARM::tcGPRRegisterClass) {
|
2009-07-27 07:59:01 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVgpr2gpr), DestReg).addReg(SrcReg);
|
2009-06-27 05:28:53 +08:00
|
|
|
return true;
|
|
|
|
} else if (SrcRC == ARM::tGPRRegisterClass) {
|
2009-07-27 07:59:01 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVtgpr2gpr), DestReg).addReg(SrcReg);
|
2009-06-27 05:28:53 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (DestRC == ARM::tGPRRegisterClass) {
|
2010-06-16 06:08:33 +08:00
|
|
|
if (SrcRC == ARM::GPRRegisterClass || SrcRC == ARM::tcGPRRegisterClass) {
|
2009-07-27 07:59:01 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVgpr2tgpr), DestReg).addReg(SrcReg);
|
2009-06-27 05:28:53 +08:00
|
|
|
return true;
|
|
|
|
} else if (SrcRC == ARM::tGPRRegisterClass) {
|
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVr), DestReg).addReg(SrcReg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
bool Thumb1InstrInfo::
|
2009-06-27 20:16:40 +08:00
|
|
|
canFoldMemoryOperand(const MachineInstr *MI,
|
|
|
|
const SmallVectorImpl<unsigned> &Ops) const {
|
|
|
|
if (Ops.size() != 1) return false;
|
|
|
|
|
|
|
|
unsigned OpNum = Ops[0];
|
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
switch (Opc) {
|
|
|
|
default: break;
|
|
|
|
case ARM::tMOVr:
|
2009-07-27 07:59:01 +08:00
|
|
|
case ARM::tMOVtgpr2gpr:
|
|
|
|
case ARM::tMOVgpr2tgpr:
|
|
|
|
case ARM::tMOVgpr2gpr: {
|
2009-06-27 20:16:40 +08:00
|
|
|
if (OpNum == 0) { // move -> store
|
|
|
|
unsigned SrcReg = MI->getOperand(1).getReg();
|
2009-08-13 13:40:51 +08:00
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
|
|
|
|
!isARMLowRegister(SrcReg))
|
2009-06-27 20:16:40 +08:00
|
|
|
// tSpill cannot take a high register operand.
|
|
|
|
return false;
|
|
|
|
} else { // move -> load
|
|
|
|
unsigned DstReg = MI->getOperand(0).getReg();
|
2009-08-13 13:40:51 +08:00
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(DstReg) &&
|
|
|
|
!isARMLowRegister(DstReg))
|
2009-06-27 20:16:40 +08:00
|
|
|
// tRestore cannot target a high register operand.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
void Thumb1InstrInfo::
|
2009-06-27 05:28:53 +08:00
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, bool isKill, int FI,
|
2010-05-07 03:06:44 +08:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2009-08-13 13:40:51 +08:00
|
|
|
assert((RC == ARM::tGPRRegisterClass ||
|
|
|
|
(TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
|
|
|
|
isARMLowRegister(SrcReg))) && "Unknown regclass!");
|
2009-06-27 05:28:53 +08:00
|
|
|
|
2010-01-16 06:21:03 +08:00
|
|
|
if (RC == ARM::tGPRRegisterClass ||
|
|
|
|
(TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
|
|
|
|
isARMLowRegister(SrcReg))) {
|
2010-05-07 03:06:44 +08:00
|
|
|
DebugLoc DL;
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2009-11-02 06:04:35 +08:00
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
MachineFrameInfo &MFI = *MF.getFrameInfo();
|
|
|
|
MachineMemOperand *MMO =
|
|
|
|
MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI),
|
|
|
|
MachineMemOperand::MOStore, 0,
|
|
|
|
MFI.getObjectSize(FI),
|
|
|
|
MFI.getObjectAlignment(FI));
|
2009-07-11 14:43:01 +08:00
|
|
|
AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tSpill))
|
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2009-11-02 06:04:35 +08:00
|
|
|
.addFrameIndex(FI).addImm(0).addMemOperand(MMO));
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
void Thumb1InstrInfo::
|
2009-06-27 05:28:53 +08:00
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
2010-05-07 03:06:44 +08:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2009-08-13 13:40:51 +08:00
|
|
|
assert((RC == ARM::tGPRRegisterClass ||
|
|
|
|
(TargetRegisterInfo::isPhysicalRegister(DestReg) &&
|
|
|
|
isARMLowRegister(DestReg))) && "Unknown regclass!");
|
2009-06-27 05:28:53 +08:00
|
|
|
|
2010-01-16 06:21:03 +08:00
|
|
|
if (RC == ARM::tGPRRegisterClass ||
|
|
|
|
(TargetRegisterInfo::isPhysicalRegister(DestReg) &&
|
|
|
|
isARMLowRegister(DestReg))) {
|
2010-05-07 03:06:44 +08:00
|
|
|
DebugLoc DL;
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2009-11-02 06:04:35 +08:00
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
MachineFrameInfo &MFI = *MF.getFrameInfo();
|
|
|
|
MachineMemOperand *MMO =
|
|
|
|
MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI),
|
|
|
|
MachineMemOperand::MOLoad, 0,
|
|
|
|
MFI.getObjectSize(FI),
|
|
|
|
MFI.getObjectAlignment(FI));
|
2009-07-11 14:43:01 +08:00
|
|
|
AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::tRestore), DestReg)
|
2009-11-02 06:04:35 +08:00
|
|
|
.addFrameIndex(FI).addImm(0).addMemOperand(MMO));
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
bool Thumb1InstrInfo::
|
2009-06-27 05:28:53 +08:00
|
|
|
spillCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
2010-05-22 09:47:14 +08:00
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2009-06-27 05:28:53 +08:00
|
|
|
if (CSI.empty())
|
|
|
|
return false;
|
|
|
|
|
2010-04-03 04:16:16 +08:00
|
|
|
DebugLoc DL;
|
2009-06-27 05:28:53 +08:00
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MBB, MI, DL, get(ARM::tPUSH));
|
2009-08-12 05:11:32 +08:00
|
|
|
AddDefaultPred(MIB);
|
2009-06-27 05:28:53 +08:00
|
|
|
for (unsigned i = CSI.size(); i != 0; --i) {
|
|
|
|
unsigned Reg = CSI[i-1].getReg();
|
2010-05-22 09:47:14 +08:00
|
|
|
bool isKill = true;
|
|
|
|
|
|
|
|
// Add the callee-saved register as live-in unless it's LR and
|
|
|
|
// @llvm.returnaddress is called. If LR is returned for @llvm.returnaddress
|
|
|
|
// then it's already added to the function and entry block live-in sets.
|
|
|
|
if (Reg == ARM::LR) {
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
if (MF.getFrameInfo()->isReturnAddressTaken() &&
|
|
|
|
MF.getRegInfo().isLiveIn(Reg))
|
|
|
|
isKill = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isKill) {
|
|
|
|
MBB.addLiveIn(Reg);
|
|
|
|
MIB.addReg(Reg, RegState::Kill);
|
|
|
|
}
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
bool Thumb1InstrInfo::
|
2009-06-27 05:28:53 +08:00
|
|
|
restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
2010-05-22 09:47:14 +08:00
|
|
|
const std::vector<CalleeSavedInfo> &CSI,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2009-06-27 05:28:53 +08:00
|
|
|
MachineFunction &MF = *MBB.getParent();
|
|
|
|
ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
|
|
|
|
if (CSI.empty())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool isVarArg = AFI->getVarArgsRegSaveSize() > 0;
|
2009-08-12 05:11:32 +08:00
|
|
|
DebugLoc DL = MI->getDebugLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(ARM::tPOP));
|
|
|
|
AddDefaultPred(MIB);
|
|
|
|
|
2009-12-17 04:31:50 +08:00
|
|
|
bool NumRegs = false;
|
2009-06-27 05:28:53 +08:00
|
|
|
for (unsigned i = CSI.size(); i != 0; --i) {
|
|
|
|
unsigned Reg = CSI[i-1].getReg();
|
|
|
|
if (Reg == ARM::LR) {
|
|
|
|
// Special epilogue for vararg functions. See emitEpilogue
|
|
|
|
if (isVarArg)
|
|
|
|
continue;
|
|
|
|
Reg = ARM::PC;
|
2009-08-12 05:11:32 +08:00
|
|
|
(*MIB).setDesc(get(ARM::tPOP_RET));
|
2009-06-27 05:28:53 +08:00
|
|
|
MI = MBB.erase(MI);
|
|
|
|
}
|
2009-08-12 05:11:32 +08:00
|
|
|
MIB.addReg(Reg, getDefRegState(true));
|
2009-12-17 04:31:50 +08:00
|
|
|
NumRegs = true;
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// It's illegal to emit pop instruction without operands.
|
2009-08-12 05:11:32 +08:00
|
|
|
if (NumRegs)
|
|
|
|
MBB.insert(MI, &*MIB);
|
2010-03-23 00:13:21 +08:00
|
|
|
else
|
|
|
|
MF.DeleteMachineInstr(MIB);
|
2009-06-27 05:28:53 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-07-03 06:18:33 +08:00
|
|
|
MachineInstr *Thumb1InstrInfo::
|
2009-06-27 05:28:53 +08:00
|
|
|
foldMemoryOperandImpl(MachineFunction &MF, MachineInstr *MI,
|
|
|
|
const SmallVectorImpl<unsigned> &Ops, int FI) const {
|
|
|
|
if (Ops.size() != 1) return NULL;
|
|
|
|
|
|
|
|
unsigned OpNum = Ops[0];
|
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
MachineInstr *NewMI = NULL;
|
|
|
|
switch (Opc) {
|
|
|
|
default: break;
|
|
|
|
case ARM::tMOVr:
|
2009-07-27 07:59:01 +08:00
|
|
|
case ARM::tMOVtgpr2gpr:
|
|
|
|
case ARM::tMOVgpr2tgpr:
|
|
|
|
case ARM::tMOVgpr2gpr: {
|
2009-06-27 05:28:53 +08:00
|
|
|
if (OpNum == 0) { // move -> store
|
|
|
|
unsigned SrcReg = MI->getOperand(1).getReg();
|
|
|
|
bool isKill = MI->getOperand(1).isKill();
|
2009-08-13 13:40:51 +08:00
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
|
|
|
|
!isARMLowRegister(SrcReg))
|
2009-06-27 05:28:53 +08:00
|
|
|
// tSpill cannot take a high register operand.
|
|
|
|
break;
|
2009-07-11 14:43:01 +08:00
|
|
|
NewMI = AddDefaultPred(BuildMI(MF, MI->getDebugLoc(), get(ARM::tSpill))
|
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
|
|
|
.addFrameIndex(FI).addImm(0));
|
2009-06-27 05:28:53 +08:00
|
|
|
} else { // move -> load
|
|
|
|
unsigned DstReg = MI->getOperand(0).getReg();
|
2009-08-13 13:40:51 +08:00
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(DstReg) &&
|
|
|
|
!isARMLowRegister(DstReg))
|
2009-06-27 05:28:53 +08:00
|
|
|
// tRestore cannot target a high register operand.
|
|
|
|
break;
|
|
|
|
bool isDead = MI->getOperand(0).isDead();
|
2009-07-11 14:43:01 +08:00
|
|
|
NewMI = AddDefaultPred(BuildMI(MF, MI->getDebugLoc(), get(ARM::tRestore))
|
|
|
|
.addReg(DstReg,
|
|
|
|
RegState::Define | getDeadRegState(isDead))
|
|
|
|
.addFrameIndex(FI).addImm(0));
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewMI;
|
|
|
|
}
|