2005-03-17 18:17:03 +00:00
|
|
|
//===- IA64InstrInfo.cpp - IA64 Instruction Information -----------*- C++ -*-===//
|
2005-04-21 23:13:11 +00:00
|
|
|
//
|
2005-03-17 18:17:03 +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:13:11 +00:00
|
|
|
//
|
2005-03-17 18:17:03 +00: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-05 17:59:02 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2005-03-17 18:17:03 +00:00
|
|
|
#include "IA64GenInstrInfo.inc"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
IA64InstrInfo::IA64InstrInfo()
|
2008-01-01 01:03:04 +00:00
|
|
|
: TargetInstrInfoImpl(IA64Insts, sizeof(IA64Insts)/sizeof(IA64Insts[0])),
|
2006-11-27 23:37:22 +00:00
|
|
|
RI(*this) {
|
2005-03-17 18:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool IA64InstrInfo::isMoveInstr(const MachineInstr& MI,
|
2009-01-20 19:12:24 +00:00
|
|
|
unsigned& sourceReg,
|
|
|
|
unsigned& destReg,
|
|
|
|
unsigned& SrcSR, unsigned& DstSR) const {
|
|
|
|
SrcSR = DstSR = 0; // No sub-registers.
|
|
|
|
|
2008-01-07 02:48:55 +00:00
|
|
|
unsigned oc = MI.getOpcode();
|
2005-03-17 18:17:03 +00:00
|
|
|
if (oc == IA64::MOV || oc == IA64::FMOV) {
|
2006-01-25 02:23:38 +00:00
|
|
|
// TODO: this doesn't detect predicate moves
|
2007-04-25 07:12:14 +00:00
|
|
|
assert(MI.getNumOperands() >= 2 &&
|
2008-10-03 15:45:36 +00:00
|
|
|
/* MI.getOperand(0).isReg() &&
|
|
|
|
MI.getOperand(1).isReg() && */
|
2005-03-17 18:17:03 +00:00
|
|
|
"invalid register-register move instruction");
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI.getOperand(0).isReg() &&
|
|
|
|
MI.getOperand(1).isReg()) {
|
2005-03-17 18:17:03 +00: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 00:05:48 +00:00
|
|
|
unsigned
|
|
|
|
IA64InstrInfo::InsertBranch(MachineBasicBlock &MBB,MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
2008-08-14 22:49:33 +00:00
|
|
|
const SmallVectorImpl<MachineOperand> &Cond)const {
|
2009-02-13 02:34:39 +00:00
|
|
|
// FIXME this should probably have a DebugLoc argument
|
|
|
|
DebugLoc dl = DebugLoc::getUnknownLoc();
|
2006-10-24 16:44:55 +00:00
|
|
|
// Can only insert uncond branches so far.
|
|
|
|
assert(Cond.empty() && !FBB && TBB && "Can only handle uncond branches!");
|
2009-02-13 02:34:39 +00:00
|
|
|
BuildMI(&MBB, dl, get(IA64::BRL_NOTCALL)).addMBB(TBB);
|
2007-05-18 00:05:48 +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 IA64InstrInfo::copyRegToReg(MachineBasicBlock &MBB,
|
2009-02-12 00:02:55 +00:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
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 (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
|
2007-12-31 06:32:00 +00:00
|
|
|
if(DestRC == IA64::PRRegisterClass ) // if a bool, we use pseudocode
|
|
|
|
// (SrcReg) DestReg = cmp.eq.unc(r0, r0)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::PCMPEQUNC), DestReg)
|
2007-12-31 06:32:00 +00:00
|
|
|
.addReg(IA64::r0).addReg(IA64::r0).addReg(SrcReg);
|
|
|
|
else // otherwise, MOV works (for both gen. regs and FP regs)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::MOV), DestReg).addReg(SrcReg);
|
2008-08-26 18:03:31 +00:00
|
|
|
|
|
|
|
return true;
|
2007-12-31 06:32:00 +00:00
|
|
|
}
|
2008-01-01 21:11:32 +00:00
|
|
|
|
|
|
|
void IA64InstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned SrcReg, bool isKill,
|
|
|
|
int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const{
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
2008-01-01 21:11:32 +00:00
|
|
|
|
|
|
|
if (RC == IA64::FPRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::STF_SPILL)).addFrameIndex(FrameIdx)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill));
|
2008-01-01 21:11:32 +00:00
|
|
|
} else if (RC == IA64::GRRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::ST8)).addFrameIndex(FrameIdx)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill));
|
2008-01-01 21:11:32 +00:00
|
|
|
} else if (RC == IA64::PRRegisterClass) {
|
|
|
|
/* we use IA64::r2 as a temporary register for doing this hackery. */
|
|
|
|
// first we load 0:
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::MOV), IA64::r2).addReg(IA64::r0);
|
2008-01-01 21:11:32 +00:00
|
|
|
// then conditionally add 1:
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::CADDIMM22), IA64::r2).addReg(IA64::r2)
|
2009-05-13 21:33:08 +00:00
|
|
|
.addImm(1).addReg(SrcReg, getKillRegState(isKill));
|
2008-01-01 21:11:32 +00:00
|
|
|
// and then store it to the stack
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::ST8))
|
|
|
|
.addFrameIndex(FrameIdx)
|
|
|
|
.addReg(IA64::r2);
|
2008-01-01 21:11:32 +00: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 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;
|
|
|
|
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-12 23:08:38 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc));
|
2009-02-18 05:45:50 +00:00
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
|
|
|
MIB.addOperand(Addr[i]);
|
2009-05-13 21:33:08 +00:00
|
|
|
MIB.addReg(SrcReg, getKillRegState(isKill));
|
2008-01-01 21:11:32 +00:00
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void IA64InstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
2009-02-12 00:02:55 +00: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-01 21:11:32 +00:00
|
|
|
|
|
|
|
if (RC == IA64::FPRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(IA64::LDF_FILL), DestReg).addFrameIndex(FrameIdx);
|
2008-01-01 21:11:32 +00:00
|
|
|
} else if (RC == IA64::GRRegisterClass) {
|
2009-02-12 00:02:55 +00: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-01 21:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IA64InstrInfo::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 == 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-12 23:08:38 +00:00
|
|
|
"sorry, I don't know how to load this sort of reg\n");
|
2008-01-01 21:11:32 +00:00
|
|
|
}
|
|
|
|
|
2009-02-12 23:08:38 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Opc), DestReg);
|
2009-02-18 05:45:50 +00:00
|
|
|
for (unsigned i = 0, e = Addr.size(); i != e; ++i)
|
|
|
|
MIB.addOperand(Addr[i]);
|
2008-01-01 21:11:32 +00:00
|
|
|
NewMIs.push_back(MIB);
|
|
|
|
return;
|
|
|
|
}
|