2012-02-18 20:03:15 +08:00
|
|
|
//===-- Thumb1InstrInfo.cpp - Thumb-1 Instruction Information -------------===//
|
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"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "ARMSubtarget.h"
|
2009-06-27 05:28:53 +08:00
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2009-11-02 06:04:35 +08:00
|
|
|
#include "llvm/CodeGen/MachineMemOperand.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2012-02-29 07:53:30 +08:00
|
|
|
#include "llvm/MC/MCInst.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)
|
2015-03-12 13:12:31 +08:00
|
|
|
: ARMBaseInstrInfo(STI), RI() {}
|
2009-06-27 05:28:53 +08:00
|
|
|
|
2017-04-22 05:48:41 +08:00
|
|
|
/// Return the noop instruction to use for a noop.
|
|
|
|
void Thumb1InstrInfo::getNoop(MCInst &NopInst) const {
|
2012-02-29 07:53:30 +08:00
|
|
|
NopInst.setOpcode(ARM::tMOVr);
|
2015-05-14 02:37:00 +08:00
|
|
|
NopInst.addOperand(MCOperand::createReg(ARM::R8));
|
|
|
|
NopInst.addOperand(MCOperand::createReg(ARM::R8));
|
|
|
|
NopInst.addOperand(MCOperand::createImm(ARMCC::AL));
|
|
|
|
NopInst.addOperand(MCOperand::createReg(0));
|
2012-02-29 07:53:30 +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;
|
|
|
|
}
|
|
|
|
|
2010-07-11 14:33:54 +08:00
|
|
|
void Thumb1InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
|
2016-06-12 23:39:02 +08:00
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
const DebugLoc &DL, unsigned DestReg,
|
|
|
|
unsigned SrcReg, bool KillSrc) const {
|
2014-08-21 07:38:50 +08:00
|
|
|
// Need to check the arch.
|
|
|
|
MachineFunction &MF = *MBB.getParent();
|
2015-02-20 16:24:37 +08:00
|
|
|
const ARMSubtarget &st = MF.getSubtarget<ARMSubtarget>();
|
2014-08-21 07:38:50 +08:00
|
|
|
|
2010-07-11 14:33:54 +08:00
|
|
|
assert(ARM::GPRRegClass.contains(DestReg, SrcReg) &&
|
|
|
|
"Thumb1 can only copy GPR registers");
|
2014-08-21 07:38:50 +08:00
|
|
|
|
|
|
|
if (st.hasV6Ops() || ARM::hGPRRegClass.contains(SrcReg)
|
|
|
|
|| !ARM::tGPRRegClass.contains(DestReg))
|
2017-01-13 17:37:56 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVr), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc))
|
|
|
|
.add(predOps(ARMCC::AL));
|
2014-08-21 07:38:50 +08:00
|
|
|
else {
|
2017-03-07 17:38:16 +08:00
|
|
|
// FIXME: Can also use 'mov hi, $src; mov $dst, hi',
|
|
|
|
// with hi as either r10 or r11.
|
|
|
|
|
|
|
|
const TargetRegisterInfo *RegInfo = st.getRegisterInfo();
|
|
|
|
if (MBB.computeRegisterLiveness(RegInfo, ARM::CPSR, I)
|
|
|
|
== MachineBasicBlock::LQR_Dead) {
|
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVSr), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc))
|
|
|
|
->addRegisterDead(ARM::CPSR, RegInfo);
|
|
|
|
return;
|
|
|
|
}
|
2014-08-21 07:38:50 +08:00
|
|
|
|
|
|
|
// 'MOV lo, lo' is unpredictable on < v6, so use the stack to do it
|
2017-01-13 17:37:56 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tPUSH))
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
BuildMI(MBB, I, DL, get(ARM::tPOP))
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.addReg(DestReg, getDefRegState(true));
|
2014-08-21 07:38:50 +08:00
|
|
|
}
|
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
|
|
|
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 {
|
2012-04-20 15:30:17 +08:00
|
|
|
assert((RC == &ARM::tGPRRegClass ||
|
2009-08-13 13:40:51 +08:00
|
|
|
(TargetRegisterInfo::isPhysicalRegister(SrcReg) &&
|
|
|
|
isARMLowRegister(SrcReg))) && "Unknown regclass!");
|
2009-06-27 05:28:53 +08:00
|
|
|
|
2012-04-20 15:30:17 +08:00
|
|
|
if (RC == &ARM::tGPRRegClass ||
|
2010-01-16 06:21:03 +08:00
|
|
|
(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();
|
2016-07-29 02:40:00 +08:00
|
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
2015-08-12 07:09:45 +08:00
|
|
|
MachineMemOperand *MMO = MF.getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOStore,
|
|
|
|
MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
|
2017-01-13 17:37:56 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tSTRspi))
|
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
|
|
|
.addFrameIndex(FI)
|
|
|
|
.addImm(0)
|
|
|
|
.addMemOperand(MMO)
|
|
|
|
.add(predOps(ARMCC::AL));
|
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 {
|
2012-04-20 15:30:17 +08:00
|
|
|
assert((RC == &ARM::tGPRRegClass ||
|
2009-08-13 13:40:51 +08:00
|
|
|
(TargetRegisterInfo::isPhysicalRegister(DestReg) &&
|
|
|
|
isARMLowRegister(DestReg))) && "Unknown regclass!");
|
2009-06-27 05:28:53 +08:00
|
|
|
|
2012-04-20 15:30:17 +08:00
|
|
|
if (RC == &ARM::tGPRRegClass ||
|
2010-01-16 06:21:03 +08:00
|
|
|
(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();
|
2016-07-29 02:40:00 +08:00
|
|
|
MachineFrameInfo &MFI = MF.getFrameInfo();
|
2015-08-12 07:09:45 +08:00
|
|
|
MachineMemOperand *MMO = MF.getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getFixedStack(MF, FI), MachineMemOperand::MOLoad,
|
|
|
|
MFI.getObjectSize(FI), MFI.getObjectAlignment(FI));
|
2017-01-13 17:37:56 +08:00
|
|
|
BuildMI(MBB, I, DL, get(ARM::tLDRspi), DestReg)
|
|
|
|
.addFrameIndex(FI)
|
|
|
|
.addImm(0)
|
|
|
|
.addMemOperand(MMO)
|
|
|
|
.add(predOps(ARMCC::AL));
|
2009-06-27 05:28:53 +08:00
|
|
|
}
|
|
|
|
}
|
2014-07-26 03:31:34 +08:00
|
|
|
|
2016-06-28 23:18:26 +08:00
|
|
|
void Thumb1InstrInfo::expandLoadStackGuard(
|
|
|
|
MachineBasicBlock::iterator MI) const {
|
|
|
|
MachineFunction &MF = *MI->getParent()->getParent();
|
|
|
|
const TargetMachine &TM = MF.getTarget();
|
|
|
|
if (TM.isPositionIndependent())
|
|
|
|
expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_pcrel, ARM::tLDRi);
|
2014-08-02 13:40:40 +08:00
|
|
|
else
|
2016-06-28 23:18:26 +08:00
|
|
|
expandLoadStackGuardBase(MI, ARM::tLDRLIT_ga_abs, ARM::tLDRi);
|
2014-07-26 03:31:34 +08:00
|
|
|
}
|