2006-02-05 13:50:24 +08:00
|
|
|
//===- SparcInstrInfo.cpp - Sparc Instruction Information -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-02-05 13:50:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the Sparc implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SparcInstrInfo.h"
|
2007-12-31 14:32:00 +08:00
|
|
|
#include "SparcSubtarget.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
#include "Sparc.h"
|
2007-09-07 12:06:50 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2006-02-05 13:50:24 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "SparcGenInstrInfo.inc"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
SparcInstrInfo::SparcInstrInfo(SparcSubtarget &ST)
|
2007-09-07 12:06:50 +08:00
|
|
|
: TargetInstrInfo(SparcInsts, array_lengthof(SparcInsts)),
|
2007-12-31 14:32:00 +08:00
|
|
|
RI(ST, *this), Subtarget(ST) {
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool isZeroImm(const MachineOperand &op) {
|
2007-12-31 04:49:49 +08:00
|
|
|
return op.isImmediate() && op.getImm() == 0;
|
2006-02-05 13:50:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if the instruction is a register to register move and
|
|
|
|
/// leave the source and dest operands in the passed parameters.
|
|
|
|
///
|
|
|
|
bool SparcInstrInfo::isMoveInstr(const MachineInstr &MI,
|
|
|
|
unsigned &SrcReg, unsigned &DstReg) const {
|
|
|
|
// We look for 3 kinds of patterns here:
|
|
|
|
// or with G0 or 0
|
|
|
|
// add with G0 or 0
|
|
|
|
// fmovs or FpMOVD (pseudo double move).
|
|
|
|
if (MI.getOpcode() == SP::ORrr || MI.getOpcode() == SP::ADDrr) {
|
|
|
|
if (MI.getOperand(1).getReg() == SP::G0) {
|
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(2).getReg();
|
|
|
|
return true;
|
|
|
|
} else if (MI.getOperand(2).getReg() == SP::G0) {
|
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if ((MI.getOpcode() == SP::ORri || MI.getOpcode() == SP::ADDri) &&
|
|
|
|
isZeroImm(MI.getOperand(2)) && MI.getOperand(1).isRegister()) {
|
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
return true;
|
|
|
|
} else if (MI.getOpcode() == SP::FMOVS || MI.getOpcode() == SP::FpMOVD ||
|
|
|
|
MI.getOpcode() == SP::FMOVD) {
|
|
|
|
SrcReg = MI.getOperand(1).getReg();
|
|
|
|
DstReg = MI.getOperand(0).getReg();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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.
|
|
|
|
unsigned SparcInstrInfo::isLoadFromStackSlot(MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == SP::LDri ||
|
|
|
|
MI->getOpcode() == SP::LDFri ||
|
|
|
|
MI->getOpcode() == SP::LDDFri) {
|
|
|
|
if (MI->getOperand(1).isFrameIndex() && MI->getOperand(2).isImmediate() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(2).getImm() == 0) {
|
2007-12-31 07:10:15 +08:00
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2006-02-05 13:50:24 +08: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.
|
|
|
|
unsigned SparcInstrInfo::isStoreToStackSlot(MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
|
|
|
if (MI->getOpcode() == SP::STri ||
|
|
|
|
MI->getOpcode() == SP::STFri ||
|
|
|
|
MI->getOpcode() == SP::STDFri) {
|
|
|
|
if (MI->getOperand(0).isFrameIndex() && MI->getOperand(1).isImmediate() &&
|
2007-12-31 04:49:49 +08:00
|
|
|
MI->getOperand(1).getImm() == 0) {
|
2007-12-31 07:10:15 +08:00
|
|
|
FrameIndex = MI->getOperand(0).getIndex();
|
2006-02-05 13:50:24 +08:00
|
|
|
return MI->getOperand(2).getReg();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2006-10-25 00:39:19 +08:00
|
|
|
|
2007-05-18 08:18:17 +08:00
|
|
|
unsigned
|
|
|
|
SparcInstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
|
|
|
const std::vector<MachineOperand> &Cond)const{
|
2006-10-25 00:39:19 +08:00
|
|
|
// Can only insert uncond branches so far.
|
|
|
|
assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
|
2006-11-28 07:37:22 +08:00
|
|
|
BuildMI(&MBB, get(SP::BA)).addMBB(TBB);
|
2007-05-18 08:18:17 +08:00
|
|
|
return 1;
|
2006-10-25 01:07:11 +08:00
|
|
|
}
|
2007-12-31 14:32:00 +08:00
|
|
|
|
|
|
|
void SparcInstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const {
|
|
|
|
if (DestRC != SrcRC) {
|
|
|
|
cerr << "Not yet supported!";
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DestRC == SP::IntRegsRegisterClass)
|
|
|
|
BuildMI(MBB, I, get(SP::ORrr), DestReg).addReg(SP::G0).addReg(SrcReg);
|
|
|
|
else if (DestRC == SP::FPRegsRegisterClass)
|
|
|
|
BuildMI(MBB, I, get(SP::FMOVS), DestReg).addReg(SrcReg);
|
|
|
|
else if (DestRC == SP::DFPRegsRegisterClass)
|
|
|
|
BuildMI(MBB, I, get(Subtarget.isV9() ? SP::FMOVD : SP::FpMOVD),DestReg)
|
|
|
|
.addReg(SrcReg);
|
|
|
|
else
|
|
|
|
assert (0 && "Can't copy this register");
|
|
|
|
}
|