2005-02-05 02:24:26 +00:00
|
|
|
//===- AlphaInstrInfo.cpp - Alpha Instruction Information -------*- C++ -*-===//
|
2005-04-21 23:13:11 +00:00
|
|
|
//
|
2005-01-22 23:41:55 +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-01-22 23:41:55 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the Alpha implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Alpha.h"
|
|
|
|
#include "AlphaInstrInfo.h"
|
2009-06-03 20:30:14 +00:00
|
|
|
#include "AlphaMachineFunctionInfo.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "AlphaGenInstrInfo.inc"
|
2009-06-03 20:30:14 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.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"
|
2005-01-22 23:41:55 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2009-07-08 19:04:27 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2005-01-22 23:41:55 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
AlphaInstrInfo::AlphaInstrInfo()
|
2008-01-01 01:03:04 +00:00
|
|
|
: TargetInstrInfoImpl(AlphaInsts, array_lengthof(AlphaInsts)),
|
2006-11-13 23:36:35 +00:00
|
|
|
RI(*this) { }
|
2005-01-22 23:41:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool AlphaInstrInfo::isMoveInstr(const MachineInstr& MI,
|
2009-01-20 19:12:24 +00:00
|
|
|
unsigned& sourceReg, unsigned& destReg,
|
|
|
|
unsigned& SrcSR, unsigned& DstSR) const {
|
2008-01-07 02:48:55 +00:00
|
|
|
unsigned oc = MI.getOpcode();
|
2006-10-31 23:46:56 +00:00
|
|
|
if (oc == Alpha::BISr ||
|
2006-03-09 18:18:51 +00:00
|
|
|
oc == Alpha::CPYSS ||
|
|
|
|
oc == Alpha::CPYST ||
|
|
|
|
oc == Alpha::CPYSSt ||
|
|
|
|
oc == Alpha::CPYSTs) {
|
2005-11-09 19:17:08 +00:00
|
|
|
// or r1, r2, r2
|
|
|
|
// cpys(s|t) r1 r2 r2
|
2007-04-25 07:12:14 +00:00
|
|
|
assert(MI.getNumOperands() >= 3 &&
|
2008-10-03 15:45:36 +00:00
|
|
|
MI.getOperand(0).isReg() &&
|
|
|
|
MI.getOperand(1).isReg() &&
|
|
|
|
MI.getOperand(2).isReg() &&
|
2005-01-22 23:41:55 +00:00
|
|
|
"invalid Alpha BIS instruction!");
|
|
|
|
if (MI.getOperand(1).getReg() == MI.getOperand(2).getReg()) {
|
|
|
|
sourceReg = MI.getOperand(1).getReg();
|
|
|
|
destReg = MI.getOperand(0).getReg();
|
2009-01-20 19:12:24 +00:00
|
|
|
SrcSR = DstSR = 0;
|
2005-01-22 23:41:55 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-02 20:12:32 +00:00
|
|
|
|
|
|
|
unsigned
|
2008-11-18 19:49:32 +00:00
|
|
|
AlphaInstrInfo::isLoadFromStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
2006-02-02 20:12:32 +00:00
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
case Alpha::LDL:
|
|
|
|
case Alpha::LDQ:
|
|
|
|
case Alpha::LDBU:
|
|
|
|
case Alpha::LDWU:
|
|
|
|
case Alpha::LDS:
|
|
|
|
case Alpha::LDT:
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(1).isFI()) {
|
2007-12-30 23:10:15 +00:00
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2006-02-02 20:12:32 +00:00
|
|
|
return MI->getOperand(0).getReg();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-03 03:07:37 +00:00
|
|
|
unsigned
|
2008-11-18 19:49:32 +00:00
|
|
|
AlphaInstrInfo::isStoreToStackSlot(const MachineInstr *MI,
|
|
|
|
int &FrameIndex) const {
|
2006-02-03 03:07:37 +00:00
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
case Alpha::STL:
|
|
|
|
case Alpha::STQ:
|
|
|
|
case Alpha::STB:
|
|
|
|
case Alpha::STW:
|
|
|
|
case Alpha::STS:
|
|
|
|
case Alpha::STT:
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MI->getOperand(1).isFI()) {
|
2007-12-30 23:10:15 +00:00
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2006-02-03 03:07:37 +00:00
|
|
|
return MI->getOperand(0).getReg();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-31 16:49:55 +00:00
|
|
|
static bool isAlphaIntCondCode(unsigned Opcode) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case Alpha::BEQ:
|
|
|
|
case Alpha::BNE:
|
|
|
|
case Alpha::BGE:
|
|
|
|
case Alpha::BGT:
|
|
|
|
case Alpha::BLE:
|
|
|
|
case Alpha::BLT:
|
|
|
|
case Alpha::BLBC:
|
|
|
|
case Alpha::BLBS:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-14 22:49:33 +00:00
|
|
|
unsigned AlphaInstrInfo::InsertBranch(MachineBasicBlock &MBB,
|
2009-02-12 00:02:55 +00:00
|
|
|
MachineBasicBlock *TBB,
|
|
|
|
MachineBasicBlock *FBB,
|
2008-08-14 22:49:33 +00:00
|
|
|
const SmallVectorImpl<MachineOperand> &Cond) const {
|
2009-02-13 02:30:42 +00:00
|
|
|
// FIXME this should probably have a DebugLoc argument
|
|
|
|
DebugLoc dl = DebugLoc::getUnknownLoc();
|
2006-10-31 16:49:55 +00:00
|
|
|
assert(TBB && "InsertBranch must not be told to insert a fallthrough");
|
|
|
|
assert((Cond.size() == 2 || Cond.size() == 0) &&
|
|
|
|
"Alpha branch conditions have two components!");
|
|
|
|
|
|
|
|
// One-way branch.
|
|
|
|
if (FBB == 0) {
|
|
|
|
if (Cond.empty()) // Unconditional branch
|
2009-02-13 02:30:42 +00:00
|
|
|
BuildMI(&MBB, dl, get(Alpha::BR)).addMBB(TBB);
|
2006-10-31 16:49:55 +00:00
|
|
|
else // Conditional branch
|
|
|
|
if (isAlphaIntCondCode(Cond[0].getImm()))
|
2009-02-13 02:30:42 +00:00
|
|
|
BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_I))
|
2006-10-31 16:49:55 +00:00
|
|
|
.addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
|
|
|
|
else
|
2009-02-13 02:30:42 +00:00
|
|
|
BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_F))
|
2006-10-31 16:49:55 +00:00
|
|
|
.addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
|
2007-05-18 00:05:48 +00:00
|
|
|
return 1;
|
2006-10-31 16:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Two-way Conditional Branch.
|
|
|
|
if (isAlphaIntCondCode(Cond[0].getImm()))
|
2009-02-13 02:30:42 +00:00
|
|
|
BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_I))
|
2006-10-31 16:49:55 +00:00
|
|
|
.addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
|
|
|
|
else
|
2009-02-13 02:30:42 +00:00
|
|
|
BuildMI(&MBB, dl, get(Alpha::COND_BRANCH_F))
|
2006-10-31 16:49:55 +00:00
|
|
|
.addImm(Cond[0].getImm()).addReg(Cond[1].getReg()).addMBB(TBB);
|
2009-02-13 02:30:42 +00:00
|
|
|
BuildMI(&MBB, dl, get(Alpha::BR)).addMBB(FBB);
|
2007-05-18 00:05:48 +00:00
|
|
|
return 2;
|
2006-10-31 16:49:55 +00:00
|
|
|
}
|
|
|
|
|
2008-08-26 18:03:31 +00:00
|
|
|
bool AlphaInstrInfo::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
|
|
|
//cerr << "copyRegToReg " << DestReg << " <- " << SrcReg << "\n";
|
|
|
|
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 == Alpha::GPRCRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::BISr), DestReg)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addReg(SrcReg);
|
2007-12-31 06:32:00 +00:00
|
|
|
} else if (DestRC == Alpha::F4RCRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::CPYSS), DestReg)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addReg(SrcReg);
|
2007-12-31 06:32:00 +00:00
|
|
|
} else if (DestRC == Alpha::F8RCRegisterClass) {
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::CPYST), DestReg)
|
|
|
|
.addReg(SrcReg)
|
|
|
|
.addReg(SrcReg);
|
2007-12-31 06:32:00 +00:00
|
|
|
} else {
|
2008-08-26 18:03:31 +00:00
|
|
|
// Attempt to copy register that is not GPR or FPR
|
|
|
|
return false;
|
2007-12-31 06:32:00 +00:00
|
|
|
}
|
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
|
|
|
|
AlphaInstrInfo::storeRegToStackSlot(MachineBasicBlock &MBB,
|
2009-02-12 00:02:55 +00:00
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned SrcReg, bool isKill, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const {
|
2008-01-01 21:11:32 +00:00
|
|
|
//cerr << "Trying to store " << getPrettyName(SrcReg) << " to "
|
|
|
|
// << FrameIdx << "\n";
|
|
|
|
//BuildMI(MBB, MI, Alpha::WTF, 0).addReg(SrcReg);
|
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 == Alpha::F4RCRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::STS))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2008-01-01 21:11:32 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
else if (RC == Alpha::F8RCRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::STT))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2008-01-01 21:11:32 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
else if (RC == Alpha::GPRCRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::STQ))
|
2009-05-13 21:33:08 +00:00
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
2008-01-01 21:11:32 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
else
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unhandled register class");
|
2008-01-01 21:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaInstrInfo::storeRegToAddr(MachineFunction &MF, unsigned SrcReg,
|
|
|
|
bool isKill,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == Alpha::F4RCRegisterClass)
|
|
|
|
Opc = Alpha::STS;
|
|
|
|
else if (RC == Alpha::F8RCRegisterClass)
|
|
|
|
Opc = Alpha::STT;
|
|
|
|
else if (RC == Alpha::GPRCRegisterClass)
|
|
|
|
Opc = Alpha::STQ;
|
|
|
|
else
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unhandled register class");
|
2009-02-12 23:24:44 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
2008-01-01 21:11:32 +00:00
|
|
|
MachineInstrBuilder MIB =
|
2009-05-13 21:33:08 +00:00
|
|
|
BuildMI(MF, DL, get(Opc)).addReg(SrcReg, getKillRegState(isKill));
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AlphaInstrInfo::loadRegFromStackSlot(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI,
|
|
|
|
unsigned DestReg, int FrameIdx,
|
|
|
|
const TargetRegisterClass *RC) const {
|
|
|
|
//cerr << "Trying to load " << getPrettyName(DestReg) << " to "
|
|
|
|
// << FrameIdx << "\n";
|
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 == Alpha::F4RCRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::LDS), DestReg)
|
2008-01-01 21:11:32 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
else if (RC == Alpha::F8RCRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::LDT), DestReg)
|
2008-01-01 21:11:32 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
else if (RC == Alpha::GPRCRegisterClass)
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::LDQ), DestReg)
|
2008-01-01 21:11:32 +00:00
|
|
|
.addFrameIndex(FrameIdx).addReg(Alpha::F31);
|
|
|
|
else
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unhandled register class");
|
2008-01-01 21:11:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaInstrInfo::loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
|
|
|
|
SmallVectorImpl<MachineOperand> &Addr,
|
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
SmallVectorImpl<MachineInstr*> &NewMIs) const {
|
|
|
|
unsigned Opc = 0;
|
|
|
|
if (RC == Alpha::F4RCRegisterClass)
|
|
|
|
Opc = Alpha::LDS;
|
|
|
|
else if (RC == Alpha::F8RCRegisterClass)
|
|
|
|
Opc = Alpha::LDT;
|
|
|
|
else if (RC == Alpha::GPRCRegisterClass)
|
|
|
|
Opc = Alpha::LDQ;
|
|
|
|
else
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unhandled register class");
|
2009-02-12 23:24:44 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
2008-01-01 21:11:32 +00:00
|
|
|
MachineInstrBuilder MIB =
|
2009-02-12 23:24:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2008-12-03 18:43:12 +00:00
|
|
|
MachineInstr *AlphaInstrInfo::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 FrameIndex) const {
|
2008-01-07 01:35:02 +00:00
|
|
|
if (Ops.size() != 1) return NULL;
|
|
|
|
|
|
|
|
// Make sure this is a reg-reg copy.
|
|
|
|
unsigned Opc = MI->getOpcode();
|
|
|
|
|
|
|
|
MachineInstr *NewMI = NULL;
|
|
|
|
switch(Opc) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case Alpha::BISr:
|
|
|
|
case Alpha::CPYSS:
|
|
|
|
case Alpha::CPYST:
|
|
|
|
if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
|
|
|
|
if (Ops[0] == 0) { // move -> store
|
|
|
|
unsigned InReg = MI->getOperand(1).getReg();
|
2008-07-03 09:09:37 +00:00
|
|
|
bool isKill = MI->getOperand(1).isKill();
|
2009-07-01 01:59:31 +00:00
|
|
|
bool isUndef = MI->getOperand(1).isUndef();
|
2008-01-07 01:35:02 +00:00
|
|
|
Opc = (Opc == Alpha::BISr) ? Alpha::STQ :
|
|
|
|
((Opc == Alpha::CPYSS) ? Alpha::STS : Alpha::STT);
|
2009-02-12 00:02:55 +00:00
|
|
|
NewMI = BuildMI(MF, MI->getDebugLoc(), get(Opc))
|
2009-07-01 01:59:31 +00:00
|
|
|
.addReg(InReg, getKillRegState(isKill) | getUndefRegState(isUndef))
|
2008-07-03 09:09:37 +00:00
|
|
|
.addFrameIndex(FrameIndex)
|
2008-01-07 01:35:02 +00:00
|
|
|
.addReg(Alpha::F31);
|
|
|
|
} else { // load -> move
|
|
|
|
unsigned OutReg = MI->getOperand(0).getReg();
|
2008-07-03 09:09:37 +00:00
|
|
|
bool isDead = MI->getOperand(0).isDead();
|
2009-07-01 01:59:31 +00:00
|
|
|
bool isUndef = MI->getOperand(0).isUndef();
|
2008-01-07 01:35:02 +00:00
|
|
|
Opc = (Opc == Alpha::BISr) ? Alpha::LDQ :
|
|
|
|
((Opc == Alpha::CPYSS) ? Alpha::LDS : Alpha::LDT);
|
2009-02-12 00:02:55 +00:00
|
|
|
NewMI = BuildMI(MF, MI->getDebugLoc(), get(Opc))
|
2009-07-01 01:59:31 +00:00
|
|
|
.addReg(OutReg, RegState::Define | getDeadRegState(isDead) |
|
|
|
|
getUndefRegState(isUndef))
|
2008-07-03 09:09:37 +00:00
|
|
|
.addFrameIndex(FrameIndex)
|
2008-01-07 01:35:02 +00:00
|
|
|
.addReg(Alpha::F31);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-07-03 09:09:37 +00:00
|
|
|
return NewMI;
|
2008-01-07 01:35:02 +00:00
|
|
|
}
|
|
|
|
|
2006-10-31 16:49:55 +00:00
|
|
|
static unsigned AlphaRevCondCode(unsigned Opcode) {
|
|
|
|
switch (Opcode) {
|
|
|
|
case Alpha::BEQ: return Alpha::BNE;
|
|
|
|
case Alpha::BNE: return Alpha::BEQ;
|
|
|
|
case Alpha::BGE: return Alpha::BLT;
|
|
|
|
case Alpha::BGT: return Alpha::BLE;
|
|
|
|
case Alpha::BLE: return Alpha::BGT;
|
|
|
|
case Alpha::BLT: return Alpha::BGE;
|
|
|
|
case Alpha::BLBC: return Alpha::BLBS;
|
|
|
|
case Alpha::BLBS: return Alpha::BLBC;
|
|
|
|
case Alpha::FBEQ: return Alpha::FBNE;
|
|
|
|
case Alpha::FBNE: return Alpha::FBEQ;
|
|
|
|
case Alpha::FBGE: return Alpha::FBLT;
|
|
|
|
case Alpha::FBGT: return Alpha::FBLE;
|
|
|
|
case Alpha::FBLE: return Alpha::FBGT;
|
|
|
|
case Alpha::FBLT: return Alpha::FBGE;
|
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unknown opcode");
|
2006-10-31 16:49:55 +00:00
|
|
|
}
|
2008-03-30 18:22:13 +00:00
|
|
|
return 0; // Not reached
|
2006-10-31 16:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Branch analysis.
|
|
|
|
bool AlphaInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,MachineBasicBlock *&TBB,
|
2009-02-09 07:14:22 +00:00
|
|
|
MachineBasicBlock *&FBB,
|
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const {
|
2006-10-31 16:49:55 +00:00
|
|
|
// If the block has no terminators, it just falls into the block after it.
|
|
|
|
MachineBasicBlock::iterator I = MBB.end();
|
2007-06-08 21:59:56 +00:00
|
|
|
if (I == MBB.begin() || !isUnpredicatedTerminator(--I))
|
2006-10-31 16:49:55 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the last instruction in the block.
|
|
|
|
MachineInstr *LastInst = I;
|
|
|
|
|
|
|
|
// If there is only one terminator instruction, process it.
|
2007-06-08 21:59:56 +00:00
|
|
|
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
|
2006-10-31 16:49:55 +00:00
|
|
|
if (LastInst->getOpcode() == Alpha::BR) {
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = LastInst->getOperand(0).getMBB();
|
2006-10-31 16:49:55 +00:00
|
|
|
return false;
|
|
|
|
} else if (LastInst->getOpcode() == Alpha::COND_BRANCH_I ||
|
|
|
|
LastInst->getOpcode() == Alpha::COND_BRANCH_F) {
|
|
|
|
// Block ends with fall-through condbranch.
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = LastInst->getOperand(2).getMBB();
|
2006-10-31 16:49:55 +00:00
|
|
|
Cond.push_back(LastInst->getOperand(0));
|
|
|
|
Cond.push_back(LastInst->getOperand(1));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Otherwise, don't know what this is.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the instruction before it if it's a terminator.
|
|
|
|
MachineInstr *SecondLastInst = I;
|
|
|
|
|
|
|
|
// If there are three terminators, we don't know what sort of block this is.
|
|
|
|
if (SecondLastInst && I != MBB.begin() &&
|
2007-06-08 21:59:56 +00:00
|
|
|
isUnpredicatedTerminator(--I))
|
2006-10-31 16:49:55 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// If the block ends with Alpha::BR and Alpha::COND_BRANCH_*, handle it.
|
|
|
|
if ((SecondLastInst->getOpcode() == Alpha::COND_BRANCH_I ||
|
|
|
|
SecondLastInst->getOpcode() == Alpha::COND_BRANCH_F) &&
|
|
|
|
LastInst->getOpcode() == Alpha::BR) {
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = SecondLastInst->getOperand(2).getMBB();
|
2006-10-31 16:49:55 +00:00
|
|
|
Cond.push_back(SecondLastInst->getOperand(0));
|
|
|
|
Cond.push_back(SecondLastInst->getOperand(1));
|
2007-12-30 23:10:15 +00:00
|
|
|
FBB = LastInst->getOperand(0).getMBB();
|
2006-10-31 16:49:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-13 17:59:52 +00:00
|
|
|
// If the block ends with two Alpha::BRs, handle it. The second one is not
|
|
|
|
// executed, so remove it.
|
|
|
|
if (SecondLastInst->getOpcode() == Alpha::BR &&
|
|
|
|
LastInst->getOpcode() == Alpha::BR) {
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
2007-06-13 17:59:52 +00:00
|
|
|
I = LastInst;
|
2009-02-09 07:14:22 +00:00
|
|
|
if (AllowModify)
|
|
|
|
I->eraseFromParent();
|
2007-06-13 17:59:52 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-10-31 16:49:55 +00:00
|
|
|
// Otherwise, can't handle this.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-18 00:05:48 +00:00
|
|
|
unsigned AlphaInstrInfo::RemoveBranch(MachineBasicBlock &MBB) const {
|
2006-10-31 16:49:55 +00:00
|
|
|
MachineBasicBlock::iterator I = MBB.end();
|
2007-05-18 00:05:48 +00:00
|
|
|
if (I == MBB.begin()) return 0;
|
2006-10-31 16:49:55 +00:00
|
|
|
--I;
|
|
|
|
if (I->getOpcode() != Alpha::BR &&
|
|
|
|
I->getOpcode() != Alpha::COND_BRANCH_I &&
|
|
|
|
I->getOpcode() != Alpha::COND_BRANCH_F)
|
2007-05-18 00:05:48 +00:00
|
|
|
return 0;
|
2006-10-31 16:49:55 +00:00
|
|
|
|
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
|
|
|
|
|
|
|
I = MBB.end();
|
|
|
|
|
2007-05-18 00:05:48 +00:00
|
|
|
if (I == MBB.begin()) return 1;
|
2006-10-31 16:49:55 +00:00
|
|
|
--I;
|
|
|
|
if (I->getOpcode() != Alpha::COND_BRANCH_I &&
|
|
|
|
I->getOpcode() != Alpha::COND_BRANCH_F)
|
2007-05-18 00:05:48 +00:00
|
|
|
return 1;
|
2006-10-31 16:49:55 +00:00
|
|
|
|
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
2007-05-18 00:05:48 +00:00
|
|
|
return 2;
|
2006-10-31 16:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AlphaInstrInfo::insertNoop(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator MI) const {
|
2009-02-12 00:02:55 +00:00
|
|
|
DebugLoc DL = DebugLoc::getUnknownLoc();
|
|
|
|
if (MI != MBB.end()) DL = MI->getDebugLoc();
|
|
|
|
BuildMI(MBB, MI, DL, get(Alpha::BISr), Alpha::R31)
|
|
|
|
.addReg(Alpha::R31)
|
2006-10-31 16:49:55 +00:00
|
|
|
.addReg(Alpha::R31);
|
2006-10-24 17:07:11 +00:00
|
|
|
}
|
2006-10-31 16:49:55 +00:00
|
|
|
|
2008-10-16 01:49:15 +00:00
|
|
|
bool AlphaInstrInfo::BlockHasNoFallThrough(const MachineBasicBlock &MBB) const {
|
2006-10-31 16:49:55 +00:00
|
|
|
if (MBB.empty()) return false;
|
|
|
|
|
|
|
|
switch (MBB.back().getOpcode()) {
|
2007-05-21 18:44:17 +00:00
|
|
|
case Alpha::RETDAG: // Return.
|
|
|
|
case Alpha::RETDAGp:
|
2006-10-31 16:49:55 +00:00
|
|
|
case Alpha::BR: // Uncond branch.
|
|
|
|
case Alpha::JMP: // Indirect branch.
|
|
|
|
return true;
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool AlphaInstrInfo::
|
2008-08-14 22:49:33 +00:00
|
|
|
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const {
|
2006-10-31 16:49:55 +00:00
|
|
|
assert(Cond.size() == 2 && "Invalid Alpha branch opcode!");
|
|
|
|
Cond[0].setImm(AlphaRevCondCode(Cond[0].getImm()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-06-03 20:30:14 +00:00
|
|
|
/// getGlobalBaseReg - Return a virtual register initialized with the
|
|
|
|
/// the global base register value. Output instructions required to
|
|
|
|
/// initialize the register in the function entry block, if necessary.
|
|
|
|
///
|
|
|
|
unsigned AlphaInstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
|
|
|
|
AlphaMachineFunctionInfo *AlphaFI = MF->getInfo<AlphaMachineFunctionInfo>();
|
|
|
|
unsigned GlobalBaseReg = AlphaFI->getGlobalBaseReg();
|
|
|
|
if (GlobalBaseReg != 0)
|
|
|
|
return GlobalBaseReg;
|
|
|
|
|
|
|
|
// Insert the set of GlobalBaseReg into the first MBB of the function
|
|
|
|
MachineBasicBlock &FirstMBB = MF->front();
|
|
|
|
MachineBasicBlock::iterator MBBI = FirstMBB.begin();
|
|
|
|
MachineRegisterInfo &RegInfo = MF->getRegInfo();
|
|
|
|
const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
|
|
|
|
|
|
|
|
GlobalBaseReg = RegInfo.createVirtualRegister(&Alpha::GPRCRegClass);
|
|
|
|
bool Ok = TII->copyRegToReg(FirstMBB, MBBI, GlobalBaseReg, Alpha::R29,
|
|
|
|
&Alpha::GPRCRegClass, &Alpha::GPRCRegClass);
|
|
|
|
assert(Ok && "Couldn't assign to global base register!");
|
2009-07-03 16:03:33 +00:00
|
|
|
Ok = Ok; // Silence warning when assertions are turned off.
|
2009-06-03 20:30:14 +00:00
|
|
|
RegInfo.addLiveIn(Alpha::R29);
|
|
|
|
|
|
|
|
AlphaFI->setGlobalBaseReg(GlobalBaseReg);
|
|
|
|
return GlobalBaseReg;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getGlobalRetAddr - Return a virtual register initialized with the
|
|
|
|
/// the global base register value. Output instructions required to
|
|
|
|
/// initialize the register in the function entry block, if necessary.
|
|
|
|
///
|
|
|
|
unsigned AlphaInstrInfo::getGlobalRetAddr(MachineFunction *MF) const {
|
|
|
|
AlphaMachineFunctionInfo *AlphaFI = MF->getInfo<AlphaMachineFunctionInfo>();
|
|
|
|
unsigned GlobalRetAddr = AlphaFI->getGlobalRetAddr();
|
|
|
|
if (GlobalRetAddr != 0)
|
|
|
|
return GlobalRetAddr;
|
|
|
|
|
|
|
|
// Insert the set of GlobalRetAddr into the first MBB of the function
|
|
|
|
MachineBasicBlock &FirstMBB = MF->front();
|
|
|
|
MachineBasicBlock::iterator MBBI = FirstMBB.begin();
|
|
|
|
MachineRegisterInfo &RegInfo = MF->getRegInfo();
|
|
|
|
const TargetInstrInfo *TII = MF->getTarget().getInstrInfo();
|
|
|
|
|
|
|
|
GlobalRetAddr = RegInfo.createVirtualRegister(&Alpha::GPRCRegClass);
|
|
|
|
bool Ok = TII->copyRegToReg(FirstMBB, MBBI, GlobalRetAddr, Alpha::R26,
|
|
|
|
&Alpha::GPRCRegClass, &Alpha::GPRCRegClass);
|
|
|
|
assert(Ok && "Couldn't assign to global return address register!");
|
2009-07-03 16:03:33 +00:00
|
|
|
Ok = Ok; // Silence warning when assertions are turned off.
|
2009-06-03 20:30:14 +00:00
|
|
|
RegInfo.addLiveIn(Alpha::R26);
|
|
|
|
|
|
|
|
AlphaFI->setGlobalRetAddr(GlobalRetAddr);
|
|
|
|
return GlobalRetAddr;
|
|
|
|
}
|