2006-02-05 05:50:24 +00:00
|
|
|
//===- SparcInstrInfo.cpp - Sparc Instruction Information -------*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-02-25 19:28:19 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2006-02-05 05:50:24 +00:00
|
|
|
// This file contains the Sparc implementation of the TargetInstrInfo class.
|
2004-02-25 19:28:19 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "SparcInstrInfo.h"
|
2007-12-31 06:32:00 +00:00
|
|
|
#include "SparcSubtarget.h"
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "Sparc.h"
|
2007-09-07 04:06:50 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2009-01-05 17:59:02 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2004-02-25 19:28:19 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "SparcGenInstrInfo.inc"
|
2004-02-29 05:59:33 +00:00
|
|
|
using namespace llvm;
|
2004-02-25 19:28:19 +00:00
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST)
|
2008-01-01 01:03:04 +00:00
|
|
|
: TargetInstrInfoImpl(SparcInsts, array_lengthof(SparcInsts)),
|
2007-12-31 06:32:00 +00:00
|
|
|
RI(ST, *this), Subtarget(ST) {
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-04 06:58:46 +00:00
|
|
|
static bool isZeroImm(const MachineOperand &op) {
|
2008-10-03 15:45:36 +00:00
|
|
|
return op.isImm() && op.getImm() == 0;
|
2004-12-11 05:19:03 +00:00
|
|
|
}
|
|
|
|
|
2004-07-25 06:19:04 +00:00
|
|
|
/// Return true if the instruction is a register to register move and
|
|
|
|
/// leave the source and dest operands in the passed parameters.
|
|
|
|
///
|
2006-02-05 05:50:24 +00:00
|
|
|
bool SparcInstrInfo::isMoveInstr(const MachineInstr &MI,
|
2009-01-20 19:12:24 +00:00
|
|
|
unsigned &SrcReg, unsigned &DstReg,
|
|
|
|
unsigned &SrcSR, unsigned &DstSR) const {
|
|
|
|
SrcSR = DstSR = 0; // No sub-registers.
|
|
|
|
|
2004-12-11 05:19:03 +00:00
|
|
|
// We look for 3 kinds of patterns here:
|
|
|
|
// or with G0 or 0
|
|
|
|
// add with G0 or 0
|
|
|
|
// fmovs or FpMOVD (pseudo double move).
|
2006-02-05 05:50:24 +00:00
|
|
|
if (MI.getOpcode() == SP::ORrr || MI.getOpcode() == SP::ADDrr) {
|
|
|
|
if (MI.getOperand(1).getReg() == SP::G0) {
|
2004-12-11 05:19:03 +00:00
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(2).getReg();
|
|
|
|
return true;
|
2006-02-05 05:50:24 +00:00
|
|
|
} else if (MI.getOperand(2).getReg() == SP::G0) {
|
2004-12-11 05:19:03 +00:00
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
return true;
|
|
|
|
}
|
2006-02-05 05:50:24 +00:00
|
|
|
} else if ((MI.getOpcode() == SP::ORri || MI.getOpcode() == SP::ADDri) &&
|
2008-10-03 15:45:36 +00:00
|
|
|
isZeroImm(MI.getOperand(2)) && MI.getOperand(1).isReg()) {
|
2006-02-04 06:58:46 +00:00
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
return true;
|
2006-02-05 05:50:24 +00:00
|
|
|
} else if (MI.getOpcode() == SP::FMOVS || MI.getOpcode() == SP::FpMOVD ||
|
|
|
|
MI.getOpcode() == SP::FMOVD) {
|
2004-07-25 06:19:04 +00:00
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-03 06:44:54 +00:00
|
|
|
|
|
|
|
/// isLoadFromStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// load from a stack slot, return the virtual or physical register number of
|
|
|
|
/// the destination along with the FrameIndex of the loaded stack slot. If
|
|
|
|
/// not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than loading from the stack slot.
|
2008-11-18 19:49:32 +00:00
|
|
|
unsigned SparcInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
|
2006-02-05 05:50:24 +00:00
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == SP::LDri ||
|
|
|
|
MI->getOpcode() == SP::LDFri ||
|
|
|
|
MI->getOpcode() == SP::LDDFri) {
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(1).isFI() && MI->getOperand(2).isImm() &&
|
2007-12-30 20:49:49 +00:00
|
|
|
MI->getOperand(2).getImm() == 0) {
|
2007-12-30 23:10:15 +00:00
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2006-02-03 06:44:54 +00:00
|
|
|
return MI->getOperand(0).getReg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isStoreToStackSlot - If the specified machine instruction is a direct
|
|
|
|
/// store to a stack slot, return the virtual or physical register number of
|
|
|
|
/// the source reg along with the FrameIndex of the loaded stack slot. If
|
|
|
|
/// not, return 0. This predicate must return 0 if the instruction has
|
|
|
|
/// any side effects other than storing to the stack slot.
|
2008-11-18 19:49:32 +00:00
|
|
|
unsigned SparcInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
|
2006-02-05 05:50:24 +00:00
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == SP::STri ||
|
|
|
|
MI->getOpcode() == SP::STFri ||
|
|
|
|
MI->getOpcode() == SP::STDFri) {
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(0).isFI() && MI->getOperand(1).isImm() &&
|
2007-12-30 20:49:49 +00:00
|
|
|
MI->getOperand(1).getImm() == 0) {
|
2007-12-30 23:10:15 +00:00
|
|
|
FrameIndex = MI->getOperand(0).getIndex();
|
2006-02-03 06:44:54 +00:00
|
|
|
return MI->getOperand(2).getReg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-10-24 16:39:19 +00:00
|
|
|
|
2007-05-18 00:18:17 +00:00
|
|
|
unsigned
|
|
|
|
SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
2008-08-14 22:49:33 +00:00
|
|
|
const SmallVectorImpl<MachineOperand> &Cond)const{
|
2009-02-13 02:31:35 +00:00
|
|
|
// FIXME this should probably take a DebugLoc argument
|
|
|
|
DebugLoc dl = DebugLoc::getUnknownLoc();
|
2006-10-24 16:39:19 +00:00
|
|
|
// Can only insert uncond branches so far.
|
|
|
|
assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
|
2009-02-13 02:31:35 +00:00
|
|
|
BuildMI(&MBB, dl, get(SP::BA)).addMBB(TBB);
|
2007-05-18 00:18:17 +00:00
|
|
|
return 1;
|
2006-10-24 17:07:11 +00:00
|
|
|
}
|
2007-12-31 06:32:00 +00:00
|
|
|
|
2008-08-26 18:03:31 +00:00
|
|
|
bool SparcInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
2009-02-12 00:02:55 +00:00
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const {
|
2007-12-31 06:32:00 +00:00
|
|
|
if (DestRC != SrcRC) {
|
2008-08-26 18:03:31 +00:00
|
|
|
// Not yet supported!
|
|
|
|
return false;
|
2007-12-31 06:32:00 +00:00
|
|
|
}
|
|
|
|
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2007-12-31 06:32:00 +00:00
|
|
|
if (DestRC == SP::IntRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::ORrr), DestReg).addReg(SP::G0).addReg(SrcReg);
|
2007-12-31 06:32:00 +00:00
|
|
|
else if (DestRC == SP::FPRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::FMOVS), DestReg).addReg(SrcReg);
|
2007-12-31 06:32:00 +00:00
|
|
|
else if (DestRC == SP::DFPRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Subtarget.isV9() ? SP::FMOVD : SP::FpMOVD),DestReg)
|
2007-12-31 06:32:00 +00:00
|
|
|
.addReg(SrcReg);
|
|
|
|
else
|
2008-08-26 18:03:31 +00:00
|
|
|
// Can't copy this register
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2007-12-31 06:32:00 +00:00
|
|
|
}
|
2008-01-01 21:11:32 +00:00
|
|
|
|
|
|
|
void SparcInstrInfo::
|
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned SrcReg, bool isKill, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2008-01-01 21:11:32 +00:00
|
|
|
// On the order of operands here: think "[FrameIdx + 0] = SrcReg".
|
|
|
|
if (RC == SP::IntRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::STri)).addFrameIndex(FI).addImm(0)
|
2008-01-01 21:11:32 +00:00
|
|
|
.addReg(SrcReg, false, false, isKill);
|
|
|
|
else if (RC == SP::FPRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::STFri)).addFrameIndex(FI).addImm(0)
|
2008-01-01 21:11:32 +00:00
|
|
|
.addReg(SrcReg, false, false, isKill);
|
|
|
|
else if (RC == SP::DFPRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::STDFri)).addFrameIndex(FI).addImm(0)
|
2008-01-01 21:11:32 +00:00
|
|
|
.addReg(SrcReg, false, false, isKill);
|
|
|
|
else
|
|
|
|
assert(0 && "Can't store this register to stack slot");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparcInstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
|
2009-02-12 00:02:55 +00:00
|
|
|
bool isKill,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
2008-01-01 21:11:32 +00:00
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = 0;
|
2009-02-12 23:08:38 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
2008-01-01 21:11:32 +00:00
|
|
|
if (RC == SP::IntRegsRegisterClass)
|
|
|
|
Opc = SP::STri;
|
|
|
|
else if (RC == SP::FPRegsRegisterClass)
|
|
|
|
Opc = SP::STFri;
|
|
|
|
else if (RC == SP::DFPRegsRegisterClass)
|
|
|
|
Opc = SP::STDFri;
|
|
|
|
else
|
|
|
|
assert(0 && "Can't load this register");
|
2009-02-12 23:08:38 +00:00
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc));
|
2008-01-01 21:11:32 +00:00
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = Addr[i];
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MO.isReg())
|
2008-01-01 21:11:32 +00:00
|
|
|
MIB.addReg(MO.getReg());
|
2008-10-03 15:45:36 +00:00
|
|
|
else if (MO.isImm())
|
2008-01-01 21:11:32 +00:00
|
|
|
MIB.addImm(MO.getImm());
|
|
|
|
else {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(MO.isFI());
|
2008-01-01 21:11:32 +00:00
|
|
|
MIB.addFrameIndex(MO.getIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MIB.addReg(SrcReg, false, false, isKill);
|
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparcInstrInfo::
|
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2008-01-01 21:11:32 +00:00
|
|
|
if (RC == SP::IntRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::LDri), DestReg).addFrameIndex(FI).addImm(0);
|
2008-01-01 21:11:32 +00:00
|
|
|
else if (RC == SP::FPRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::LDFri), DestReg).addFrameIndex(FI).addImm(0);
|
2008-01-01 21:11:32 +00:00
|
|
|
else if (RC == SP::DFPRegsRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, I, DL, get(SP::LDDFri), DestReg).addFrameIndex(FI).addImm(0);
|
2008-01-01 21:11:32 +00:00
|
|
|
else
|
|
|
|
assert(0 && "Can't load this register from stack slot");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SparcInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
2009-02-12 00:02:55 +00:00
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
2008-01-01 21:11:32 +00:00
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == SP::IntRegsRegisterClass)
|
|
|
|
Opc = SP::LDri;
|
|
|
|
else if (RC == SP::FPRegsRegisterClass)
|
|
|
|
Opc = SP::LDFri;
|
|
|
|
else if (RC == SP::DFPRegsRegisterClass)
|
|
|
|
Opc = SP::LDDFri;
|
|
|
|
else
|
|
|
|
assert(0 && "Can't load this register");
|
2009-02-12 23:08:38 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg);
|
2008-01-01 21:11:32 +00:00
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i) {
|
|
|
|
MachineOperand &MO = Addr[i];
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MO.isReg())
|
2008-01-01 21:11:32 +00:00
|
|
|
MIB.addReg(MO.getReg());
|
2008-10-03 15:45:36 +00:00
|
|
|
else if (MO.isImm())
|
2008-01-01 21:11:32 +00:00
|
|
|
MIB.addImm(MO.getImm());
|
|
|
|
else {
|
2008-10-03 15:45:36 +00:00
|
|
|
assert(MO.isFI());
|
2008-01-01 21:11:32 +00:00
|
|
|
MIB.addFrameIndex(MO.getIndex());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
return;
|
|
|
|
}
|
2008-01-07 01:35:02 +00:00
|
|
|
|
2008-12-03 18:43:12 +00:00
|
|
|
MachineInstr *SparcInstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
|
|
|
|
MachineInstr* MI,
|
2008-10-16 01:49:15 +00:00
|
|
|
const SmallVectorImpl<unsigned> &Ops,
|
2008-12-03 18:43:12 +00:00
|
|
|
int FI) const {
|
2008-01-07 01:35:02 +00:00
|
|
|
if (Ops.size() != 1) return NULL;
|
|
|
|
|
|
|
|
unsigned OpNum = Ops[0];
|
|
|
|
bool isFloat = false;
|
|
|
|
MachineInstr *NewMI = NULL;
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
case SP::ORrr:
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(1).isReg() && MI->getOperand(1).getReg() == SP::G0&&
|
|
|
|
MI->getOperand(0).isReg() && MI->getOperand(2).isReg()) {
|
2008-01-07 01:35:02 +00:00
|
|
|
if (OpNum == 0) // COPY -> STORE
|
2009-02-12 00:02:55 +00:00
|
|
|
NewMI = BuildMI(MF, MI->getDebugLoc(), get(SP::STri))
|
|
|
|
.addFrameIndex(FI)
|
|
|
|
.addImm(0)
|
|
|
|
.addReg(MI->getOperand(2).getReg());
|
2008-01-07 01:35:02 +00:00
|
|
|
else // COPY -> LOAD
|
2009-02-12 00:02:55 +00:00
|
|
|
NewMI = BuildMI(MF, MI->getDebugLoc(), get(SP::LDri),
|
|
|
|
MI->getOperand(0).getReg())
|
|
|
|
.addFrameIndex(FI)
|
|
|
|
.addImm(0);
|
2008-01-07 01:35:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SP::FMOVS:
|
|
|
|
isFloat = true;
|
|
|
|
// FALLTHROUGH
|
|
|
|
case SP::FMOVD:
|
2008-07-03 09:09:37 +00:00
|
|
|
if (OpNum == 0) { // COPY -> STORE
|
|
|
|
unsigned SrcReg = MI->getOperand(1).getReg();
|
|
|
|
bool isKill = MI->getOperand(1).isKill();
|
2009-02-12 00:02:55 +00:00
|
|
|
NewMI = BuildMI(MF, MI->getDebugLoc(),
|
|
|
|
get(isFloat ? SP::STFri : SP::STDFri))
|
|
|
|
.addFrameIndex(FI)
|
|
|
|
.addImm(0)
|
|
|
|
.addReg(SrcReg, false, false, isKill);
|
2008-07-03 09:09:37 +00:00
|
|
|
} else { // COPY -> LOAD
|
|
|
|
unsigned DstReg = MI->getOperand(0).getReg();
|
|
|
|
bool isDead = MI->getOperand(0).isDead();
|
2009-02-12 00:02:55 +00:00
|
|
|
NewMI = BuildMI(MF, MI->getDebugLoc(),
|
|
|
|
get(isFloat ? SP::LDFri : SP::LDDFri))
|
|
|
|
.addReg(DstReg, true, false, false, isDead)
|
|
|
|
.addFrameIndex(FI)
|
|
|
|
.addImm(0);
|
2008-07-03 09:09:37 +00:00
|
|
|
}
|
2008-01-07 01:35:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewMI;
|
2008-01-07 19:13:36 +00:00
|
|
|
}
|