2005-03-18 02:17:03 +08:00
|
|
|
//===- IA64InstrInfo.cpp - IA64 Instruction Information -----------*- C++ -*-===//
|
2005-04-22 07:13:11 +08:00
|
|
|
//
|
2005-03-18 02:17:03 +08:00
|
|
|
// 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.
|
2005-04-22 07:13:11 +08:00
|
|
|
//
|
2005-03-18 02:17:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the IA64 implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "IA64InstrInfo.h"
|
|
|
|
#include "IA64.h"
|
|
|
|
#include "IA64InstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2009-01-06 01:59:02 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2005-03-18 02:17:03 +08:00
|
|
|
#include "IA64GenInstrInfo.inc"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
IA64InstrInfo::IA64InstrInfo()
|
2008-01-01 09:03:04 +08:00
|
|
|
: TargetInstrInfoImpl(IA64Insts, sizeof(IA64Insts)/sizeof(IA64Insts[0])),
|
2006-11-28 07:37:22 +08:00
|
|
|
RI(*this) {
|
2005-03-18 02:17:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IA64InstrInfo::isMoveInstr(const MachineInstr& MI,
|
2009-01-21 03:12:24 +08:00
|
|
|
unsigned& sourceReg,
|
|
|
|
unsigned& destReg,
|
|
|
|
unsigned& SrcSR, unsigned& DstSR) const {
|
|
|
|
SrcSR = DstSR = 0; // No sub-registers.
|
|
|
|
|
2008-01-07 10:48:55 +08:00
|
|
|
unsigned oc = MI.getOpcode();
|
2005-03-18 02:17:03 +08:00
|
|
|
if (oc == IA64::MOV || oc == IA64::FMOV) {
|
2006-01-25 10:23:38 +08:00
|
|
|
// TODO: this doesn't detect predicate moves
|
2007-04-25 15:12:14 +08:00
|
|
|
assert(MI.getNumOperands() >= 2 &&
|
2008-10-03 23:45:36 +08:00
|
|
|
/* MI.getOperand(0).isReg() &&
|
|
|
|
MI.getOperand(1).isReg() && */
|
2005-03-18 02:17:03 +08:00
|
|
|
"invalid register-register move instruction");
|
2008-10-03 23:45:36 +08:00
|
|
|
if (MI.getOperand(0).isReg() &&
|
|
|
|
MI.getOperand(1).isReg()) {
|
2005-03-18 02:17:03 +08:00
|
|
|
// if both operands of the MOV/FMOV are registers, then
|
|
|
|
// yes, this is a move instruction
|
|
|
|
sourceReg = MI.getOperand(1).getReg();
|
|
|
|
destReg = MI.getOperand(0).getReg();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; // we don't consider e.g. %regN = MOV <FrameIndex #x> a
|
|
|
|
// move instruction
|
|
|
|
}
|
|
|
|
|
2007-05-18 08:05:48 +08:00
|
|
|
unsigned
|
|
|
|
IA64InstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
2008-08-15 06:49:33 +08:00
|
|
|
const SmallVectorImpl<MachineOperand> &Cond)const {
|
2009-02-13 10:34:39 +08:00
|
|
|
// FIXME this should probably have a DebugLoc argument
|
|
|
|
DebugLoc dl = DebugLoc::getUnknownLoc();
|
2006-10-25 00:44:55 +08:00
|
|
|
// Can only insert uncond branches so far.
|
|
|
|
assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
|
2009-02-13 10:34:39 +08:00
|
|
|
BuildMI(&MBB, dl, get(IA64::BRL_NOTCALL)).addMBB(TBB);
|
2007-05-18 08:05:48 +08:00
|
|
|
return 1;
|
2006-10-25 01:07:11 +08:00
|
|
|
}
|
2007-12-31 14:32:00 +08:00
|
|
|
|
2008-08-27 02:03:31 +08:00
|
|
|
bool IA64InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
2009-02-12 08:02:55 +08:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
const TargetRegisterClass *DestRC,
|
|
|
|
const TargetRegisterClass *SrcRC) const {
|
2007-12-31 14:32:00 +08:00
|
|
|
if (DestRC != SrcRC) {
|
2008-08-27 02:03:31 +08:00
|
|
|
// Not yet supported!
|
|
|
|
return false;
|
2007-12-31 14:32:00 +08:00
|
|
|
}
|
|
|
|
|
2009-02-12 08:02:55 +08:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
2007-12-31 14:32:00 +08:00
|
|
|
if(DestRC == IA64::PRRegisterClass ) // if a bool, we use pseudocode
|
|
|
|
// (SrcReg) DestReg = cmp.eq.unc(r0, r0)
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::PCMPEQUNC), DestReg)
|
2007-12-31 14:32:00 +08:00
|
|
|
.addReg(IA64::r0).addReg(IA64::r0).addReg(SrcReg);
|
|
|
|
else // otherwise, MOV works (for both gen. regs and FP regs)
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::MOV), DestReg).addReg(SrcReg);
|
2008-08-27 02:03:31 +08:00
|
|
|
|
|
|
|
return true;
|
2007-12-31 14:32:00 +08:00
|
|
|
}
|
2008-01-02 05:11:32 +08:00
|
|
|
|
|
|
|
void IA64InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned SrcReg, bool isKill,
|
|
|
|
int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const{
|
2009-02-12 08:02:55 +08:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
2008-01-02 05:11:32 +08:00
|
|
|
|
|
|
|
if (RC == IA64::FPRegisterClass) {
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::STF_SPILL)).addFrameIndex(FrameIdx)
|
2008-01-02 05:11:32 +08:00
|
|
|
.addReg(SrcReg, false, false, isKill);
|
|
|
|
} else if (RC == IA64::GRRegisterClass) {
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::ST8)).addFrameIndex(FrameIdx)
|
2008-01-02 05:11:32 +08:00
|
|
|
.addReg(SrcReg, false, false, isKill);
|
|
|
|
} else if (RC == IA64::PRRegisterClass) {
|
|
|
|
/* we use IA64::r2 as a temporary register for doing this hackery. */
|
|
|
|
// first we load 0:
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::MOV), IA64::r2).addReg(IA64::r0);
|
2008-01-02 05:11:32 +08:00
|
|
|
// then conditionally add 1:
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::CADDIMM22), IA64::r2).addReg(IA64::r2)
|
2008-01-02 05:11:32 +08:00
|
|
|
.addImm(1).addReg(SrcReg, false, false, isKill);
|
|
|
|
// and then store it to the stack
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::ST8))
|
|
|
|
.addFrameIndex(FrameIdx)
|
|
|
|
.addReg(IA64::r2);
|
2008-01-02 05:11:32 +08:00
|
|
|
} else assert(0 &&
|
|
|
|
"sorry, I don't know how to store this sort of reg in the stack\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void IA64InstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
|
2009-02-12 08:02:55 +08:00
|
|
|
bool isKill,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
2008-01-02 05:11:32 +08:00
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == IA64::FPRegisterClass) {
|
|
|
|
Opc = IA64::STF8;
|
|
|
|
} else if (RC == IA64::GRRegisterClass) {
|
|
|
|
Opc = IA64::ST8;
|
|
|
|
} else if (RC == IA64::PRRegisterClass) {
|
|
|
|
Opc = IA64::ST1;
|
|
|
|
} else {
|
|
|
|
assert(0 &&
|
|
|
|
"sorry, I don't know how to store this sort of reg\n");
|
|
|
|
}
|
|
|
|
|
2009-02-13 07:08:38 +08:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc));
|
2009-02-18 13:45:50 +08:00
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
|
|
|
MIB.addOperand(Addr[i]);
|
2008-01-02 05:11:32 +08:00
|
|
|
MIB.addReg(SrcReg, false, false, isKill);
|
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void IA64InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
2009-02-12 08:02:55 +08:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC)const{
|
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
2008-01-02 05:11:32 +08:00
|
|
|
|
|
|
|
if (RC == IA64::FPRegisterClass) {
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::LDF_FILL), DestReg).addFrameIndex(FrameIdx);
|
2008-01-02 05:11:32 +08:00
|
|
|
} else if (RC == IA64::GRRegisterClass) {
|
2009-02-12 08:02:55 +08:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::LD8), DestReg).addFrameIndex(FrameIdx);
|
|
|
|
} else if (RC == IA64::PRRegisterClass) {
|
|
|
|
// first we load a byte from the stack into r2, our 'predicate hackery'
|
|
|
|
// scratch reg
|
|
|
|
BuildMI(MBB, MI, DL, get(IA64::LD8), IA64::r2).addFrameIndex(FrameIdx);
|
|
|
|
// then we compare it to zero. If it _is_ zero, compare-not-equal to
|
|
|
|
// r0 gives us 0, which is what we want, so that's nice.
|
|
|
|
BuildMI(MBB, MI, DL, get(IA64::CMPNE), DestReg)
|
|
|
|
.addReg(IA64::r2)
|
|
|
|
.addReg(IA64::r0);
|
|
|
|
} else {
|
|
|
|
assert(0 &&
|
|
|
|
"sorry, I don't know how to load this sort of reg from the stack\n");
|
|
|
|
}
|
2008-01-02 05:11:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IA64InstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
2009-02-12 08:02:55 +08:00
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
2008-01-02 05:11:32 +08:00
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == IA64::FPRegisterClass) {
|
|
|
|
Opc = IA64::LDF8;
|
|
|
|
} else if (RC == IA64::GRRegisterClass) {
|
|
|
|
Opc = IA64::LD8;
|
|
|
|
} else if (RC == IA64::PRRegisterClass) {
|
|
|
|
Opc = IA64::LD1;
|
|
|
|
} else {
|
|
|
|
assert(0 &&
|
2009-02-13 07:08:38 +08:00
|
|
|
"sorry, I don't know how to load this sort of reg\n");
|
2008-01-02 05:11:32 +08:00
|
|
|
}
|
|
|
|
|
2009-02-13 07:08:38 +08:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg);
|
2009-02-18 13:45:50 +08:00
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
|
|
|
MIB.addOperand(Addr[i]);
|
2008-01-02 05:11:32 +08:00
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
return;
|
|
|
|
}
|