2009-07-02 22:18:33 +00:00
|
|
|
//===- Thumb2InstrInfo.cpp - Thumb-2 Instruction Information --------*- C++ -*-===//
|
2009-06-26 21:28:53 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-07-02 22:18:33 +00:00
|
|
|
// This file contains the Thumb-2 implementation of the TargetInstrInfo class.
|
2009-06-26 21:28:53 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMInstrInfo.h"
|
|
|
|
#include "ARM.h"
|
|
|
|
#include "ARMGenInstrInfo.inc"
|
|
|
|
#include "ARMMachineFunctionInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-07-02 22:18:33 +00:00
|
|
|
#include "Thumb2InstrInfo.h"
|
2009-06-26 21:28:53 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-07-02 22:18:33 +00:00
|
|
|
Thumb2InstrInfo::Thumb2InstrInfo(const ARMSubtarget &STI)
|
2009-06-27 12:16:40 +00:00
|
|
|
: ARMBaseInstrInfo(STI), RI(*this, STI) {
|
2009-06-26 21:28:53 +00:00
|
|
|
}
|
|
|
|
|
2009-07-11 06:43:01 +00:00
|
|
|
unsigned Thumb2InstrInfo::getUnindexedOpcode(unsigned Opc) const {
|
2009-07-08 16:09:28 +00:00
|
|
|
// FIXME
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-11 06:43:01 +00:00
|
|
|
unsigned Thumb2InstrInfo::getOpcode(ARMII::Op Op) const {
|
2009-07-08 16:09:28 +00:00
|
|
|
switch (Op) {
|
|
|
|
case ARMII::ADDri: return ARM::t2ADDri;
|
|
|
|
case ARMII::MOVr: return ARM::t2MOVr;
|
|
|
|
case ARMII::SUBri: return ARM::t2SUBri;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Thumb2InstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
|
|
|
|
if (MBB.empty()) return false;
|
|
|
|
|
|
|
|
switch (MBB.back().getOpcode()) {
|
2009-07-10 15:33:46 +00:00
|
|
|
case ARM::t2LDM_RET:
|
2009-07-08 16:09:28 +00:00
|
|
|
case ARM::t2B: // Uncond branch.
|
Change Thumb2 jumptable codegen to one that uses two level jumps:
Before:
adr r12, #LJTI3_0_0
ldr pc, [r12, +r0, lsl #2]
LJTI3_0_0:
.long LBB3_24
.long LBB3_30
.long LBB3_31
.long LBB3_32
After:
adr r12, #LJTI3_0_0
add pc, r12, +r0, lsl #2
LJTI3_0_0:
b.w LBB3_24
b.w LBB3_30
b.w LBB3_31
b.w LBB3_32
This has several advantages.
1. This will make it easier to optimize this to a TBB / TBH instruction +
(smaller) table.
2. This eliminate the need for ugly asm printer hack to force the address
into thumb addresses (bit 0 is one).
3. Same codegen for pic and non-pic.
4. This eliminate the need to align the table so constantpool island pass
won't have to over-estimate the size.
Based on my calculation, the later is probably slightly faster as well since
ldr pc with shifter address is very slow. That is, it should be a win as long
as the HW implementation can do a reasonable job of branch predict the second
branch.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77024 91177308-0d34-0410-b5e6-96231b3b80d8
2009-07-25 00:33:29 +00:00
|
|
|
case ARM::t2BR_JT: // Jumptable branch.
|
2009-07-24 18:20:16 +00:00
|
|
|
case ARM::tBR_JTr: // Jumptable branch (16-bit version).
|
2009-07-08 16:09:28 +00:00
|
|
|
case ARM::tBX_RET:
|
|
|
|
case ARM::tBX_RET_vararg:
|
|
|
|
case ARM::tPOP_RET:
|
|
|
|
case ARM::tB:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-16 23:26:06 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
Thumb2InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const {
|
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2009-07-27 00:33:08 +00:00
|
|
|
if (DestRC == ARM::GPRRegisterClass &&
|
|
|
|
SrcRC == ARM::GPRRegisterClass) {
|
2009-07-25 01:25:08 +00:00
|
|
|
AddDefaultCC(AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::t2MOVr),
|
2009-07-16 23:26:06 +00:00
|
|
|
DestReg).addReg(SrcReg)));
|
|
|
|
return true;
|
2009-07-27 00:33:08 +00:00
|
|
|
} else if (DestRC == ARM::GPRRegisterClass &&
|
|
|
|
SrcRC == ARM::tGPRRegisterClass) {
|
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVtgpr2gpr), DestReg).addReg(SrcReg);
|
|
|
|
return true;
|
|
|
|
} else if (DestRC == ARM::tGPRRegisterClass &&
|
|
|
|
SrcRC == ARM::GPRRegisterClass) {
|
|
|
|
BuildMI(MBB, I, DL, get(ARM::tMOVgpr2tgpr), DestReg).addReg(SrcReg);
|
|
|
|
return true;
|
2009-07-16 23:26:06 +00:00
|
|
|
}
|
|
|
|
|
2009-07-27 00:33:08 +00:00
|
|
|
// Handle SPR, DPR, and QPR copies.
|
2009-07-16 23:26:06 +00:00
|
|
|
return ARMBaseInstrInfo::copyRegToReg(MBB, I, DestReg, SrcReg, DestRC, SrcRC);
|
|
|
|
}
|
2009-07-27 03:14:20 +00:00
|
|
|
|
|
|
|
void Thumb2InstrInfo::
|
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, bool isKill, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
|
|
|
if (RC == ARM::GPRRegisterClass) {
|
|
|
|
AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::t2STRi12))
|
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
|
|
|
.addFrameIndex(FI).addImm(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ARMBaseInstrInfo::storeRegToStackSlot(MBB, I, SrcReg, isKill, FI, RC);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Thumb2InstrInfo::
|
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
|
|
|
if (RC == ARM::GPRRegisterClass) {
|
|
|
|
AddDefaultPred(BuildMI(MBB, I, DL, get(ARM::t2LDRi12), DestReg)
|
|
|
|
.addFrameIndex(FI).addImm(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ARMBaseInstrInfo::loadRegFromStackSlot(MBB, I, DestReg, FI, RC);
|
|
|
|
}
|