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
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and 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"
|
|
|
|
#include "Sparc.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)
|
|
|
|
: TargetInstrInfo(SparcInsts, sizeof(SparcInsts)/sizeof(SparcInsts[0])),
|
2006-11-13 23:36:35 +00:00
|
|
|
RI(ST, *this) {
|
2004-02-25 19:28:19 +00:00
|
|
|
}
|
|
|
|
|
2006-02-04 06:58:46 +00:00
|
|
|
static bool isZeroImm(const MachineOperand &op) {
|
|
|
|
return op.isImmediate() && op.getImmedValue() == 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,
|
|
|
|
unsigned &SrcReg, unsigned &DstReg) const {
|
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) &&
|
2006-02-04 06:58:46 +00:00
|
|
|
isZeroImm(MI.getOperand(2)) && MI.getOperand(1).isRegister()) {
|
|
|
|
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.
|
2006-02-05 05:50:24 +00:00
|
|
|
unsigned SparcInstrInfo::isLoadFromStackSlot(MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == SP::LDri ||
|
|
|
|
MI->getOpcode() == SP::LDFri ||
|
|
|
|
MI->getOpcode() == SP::LDDFri) {
|
2006-02-03 06:44:54 +00:00
|
|
|
if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
|
|
|
|
MI->getOperand(2).getImmedValue() == 0) {
|
|
|
|
FrameIndex = MI->getOperand(1).getFrameIndex();
|
|
|
|
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.
|
2006-02-05 05:50:24 +00:00
|
|
|
unsigned SparcInstrInfo::isStoreToStackSlot(MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == SP::STri ||
|
|
|
|
MI->getOpcode() == SP::STFri ||
|
|
|
|
MI->getOpcode() == SP::STDFri) {
|
2006-02-03 06:44:54 +00:00
|
|
|
if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
|
|
|
|
MI->getOperand(1).getImmedValue() == 0) {
|
|
|
|
FrameIndex = MI->getOperand(0).getFrameIndex();
|
|
|
|
return MI->getOperand(2).getReg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-10-24 16:39:19 +00:00
|
|
|
|
|
|
|
void SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
const std::vector<MachineOperand> &Cond)const{
|
|
|
|
// Can only insert uncond branches so far.
|
|
|
|
assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
|
2006-11-27 23:37:22 +00:00
|
|
|
BuildMI(&MBB, get(SP::BA)).addMBB(TBB);
|
2006-10-24 17:07:11 +00:00
|
|
|
}
|