2011-04-15 21:51:11 +00:00
|
|
|
//===- MipsInstrInfo.cpp - Mips Instruction Information ---------*- C++ -*-===//
|
2007-06-06 07:42:06 +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.
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
//
|
|
|
|
// This file contains the Mips implementation of the TargetInstrInfo class.
|
|
|
|
//
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 07:42:06 +00:00
|
|
|
|
|
|
|
#include "MipsInstrInfo.h"
|
2008-07-14 14:42:54 +00:00
|
|
|
#include "MipsTargetMachine.h"
|
2009-06-03 20:30:14 +00:00
|
|
|
#include "MipsMachineFunction.h"
|
2011-07-07 23:56:50 +00:00
|
|
|
#include "InstPrinter/MipsInstPrinter.h"
|
2007-06-06 07:42:06 +00:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2009-06-03 20:30:14 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2009-07-11 20:10:48 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2011-08-24 18:08:43 +00:00
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
2011-07-11 03:57:24 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2011-06-28 20:07:07 +00:00
|
|
|
|
2011-07-01 17:57:27 +00:00
|
|
|
#define GET_INSTRINFO_CTOR
|
2007-06-06 07:42:06 +00:00
|
|
|
#include "MipsGenInstrInfo.inc"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
|
2011-07-01 17:57:27 +00:00
|
|
|
: MipsGenInstrInfo(Mips::ADJCALLSTACKDOWN, Mips::ADJCALLSTACKUP),
|
2008-07-14 14:42:54 +00:00
|
|
|
TM(tm), RI(*TM.getSubtargetImpl(), *this) {}
|
2007-06-06 07:42:06 +00:00
|
|
|
|
2011-07-07 23:56:50 +00:00
|
|
|
|
|
|
|
const MipsRegisterInfo &MipsInstrInfo::getRegisterInfo() const {
|
|
|
|
return RI;
|
|
|
|
}
|
|
|
|
|
2007-06-06 07:42:06 +00:00
|
|
|
static bool isZeroImm(const MachineOperand &op) {
|
2008-10-03 15:45:36 +00:00
|
|
|
return op.isImm() && op.getImm() == 0;
|
2007-06-06 07:42:06 +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.
|
|
|
|
unsigned MipsInstrInfo::
|
2011-03-04 17:51:39 +00:00
|
|
|
isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const
|
2007-06-06 07:42:06 +00:00
|
|
|
{
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
if ((MI->getOpcode() == Mips::LW) || (MI->getOpcode() == Mips::LWC1) ||
|
2009-03-21 00:05:07 +00:00
|
|
|
(MI->getOpcode() == Mips::LDC1)) {
|
2011-07-07 18:57:00 +00:00
|
|
|
if ((MI->getOperand(1).isFI()) && // is a stack slot
|
|
|
|
(MI->getOperand(2).isImm()) && // the imm is zero
|
|
|
|
(isZeroImm(MI->getOperand(2)))) {
|
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2007-06-06 07:42:06 +00: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 MipsInstrInfo::
|
2011-03-04 17:51:39 +00:00
|
|
|
isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const
|
2007-06-06 07:42:06 +00:00
|
|
|
{
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
if ((MI->getOpcode() == Mips::SW) || (MI->getOpcode() == Mips::SWC1) ||
|
2009-03-21 00:05:07 +00:00
|
|
|
(MI->getOpcode() == Mips::SDC1)) {
|
2011-07-07 18:57:00 +00:00
|
|
|
if ((MI->getOperand(1).isFI()) && // is a stack slot
|
|
|
|
(MI->getOperand(2).isImm()) && // the imm is zero
|
|
|
|
(isZeroImm(MI->getOperand(2)))) {
|
|
|
|
FrameIndex = MI->getOperand(1).getIndex();
|
2008-08-02 19:42:36 +00:00
|
|
|
return MI->getOperand(0).getReg();
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-18 01:56:48 +00:00
|
|
|
/// insertNoop - If data hazard condition is found insert the target nop
|
|
|
|
/// instruction.
|
|
|
|
void MipsInstrInfo::
|
2011-03-04 17:51:39 +00:00
|
|
|
insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
2010-04-02 20:16:16 +00:00
|
|
|
DebugLoc DL;
|
2009-02-12 00:02:55 +00:00
|
|
|
BuildMI(MBB, MI, DL, get(Mips::NOP));
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 01:08:31 +00:00
|
|
|
void MipsInstrInfo::
|
|
|
|
copyPhysReg(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock::iterator I, DebugLoc DL,
|
|
|
|
unsigned DestReg, unsigned SrcReg,
|
|
|
|
bool KillSrc) const {
|
|
|
|
bool DestCPU = Mips::CPURegsRegClass.contains(DestReg);
|
|
|
|
bool SrcCPU = Mips::CPURegsRegClass.contains(SrcReg);
|
|
|
|
|
|
|
|
// CPU-CPU is the most common.
|
|
|
|
if (DestCPU && SrcCPU) {
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::ADDu), DestReg).addReg(Mips::ZERO)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
return;
|
|
|
|
}
|
2008-08-02 19:42:36 +00:00
|
|
|
|
2010-07-11 01:08:31 +00:00
|
|
|
// Copy to CPU from other registers.
|
|
|
|
if (DestCPU) {
|
|
|
|
if (Mips::CCRRegClass.contains(SrcReg))
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::CFC1), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
else if (Mips::FGR32RegClass.contains(SrcReg))
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MFC1), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
else if (SrcReg == Mips::HI)
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MFHI), DestReg);
|
|
|
|
else if (SrcReg == Mips::LO)
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MFLO), DestReg);
|
|
|
|
else
|
|
|
|
llvm_unreachable("Copy to CPU from invalid register");
|
|
|
|
return;
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-11 01:08:31 +00:00
|
|
|
// Copy to other registers from CPU.
|
|
|
|
if (SrcCPU) {
|
|
|
|
if (Mips::CCRRegClass.contains(DestReg))
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::CTC1), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
else if (Mips::FGR32RegClass.contains(DestReg))
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MTC1), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
else if (DestReg == Mips::HI)
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MTHI))
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
else if (DestReg == Mips::LO)
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MTLO))
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
else
|
|
|
|
llvm_unreachable("Copy from CPU to invalid register");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Mips::FGR32RegClass.contains(DestReg, SrcReg)) {
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::FMOV_S32), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
return;
|
|
|
|
}
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2010-07-11 01:08:31 +00:00
|
|
|
if (Mips::AFGR64RegClass.contains(DestReg, SrcReg)) {
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::FMOV_D32), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Mips::CCRRegClass.contains(DestReg, SrcReg)) {
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::MOVCCRToCCR), DestReg)
|
|
|
|
.addReg(SrcReg, getKillRegState(KillSrc));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
llvm_unreachable("Cannot copy registers");
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsInstrInfo::
|
|
|
|
storeRegToStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
2011-03-04 17:51:39 +00:00
|
|
|
unsigned SrcReg, bool isKill, int FI,
|
2010-05-06 19:06:44 +00:00
|
|
|
const TargetRegisterClass *RC,
|
|
|
|
const TargetRegisterInfo *TRI) const {
|
2010-04-02 20:16:16 +00:00
|
|
|
DebugLoc DL;
|
2009-02-12 00:02:55 +00:00
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
|
|
|
|
2011-03-04 17:51:39 +00:00
|
|
|
if (RC == Mips::CPURegsRegisterClass)
|
2009-11-25 00:36:00 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::SW)).addReg(SrcReg, getKillRegState(isKill))
|
2011-07-07 18:57:00 +00:00
|
|
|
.addFrameIndex(FI).addImm(0);
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
else if (RC == Mips::FGR32RegisterClass)
|
2011-04-15 21:51:11 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::SWC1)).addReg(SrcReg, getKillRegState(isKill))
|
2011-07-07 18:57:00 +00:00
|
|
|
.addFrameIndex(FI).addImm(0);
|
2009-11-25 00:36:00 +00:00
|
|
|
else if (RC == Mips::AFGR64RegisterClass) {
|
2011-08-16 03:51:51 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::SDC1))
|
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
|
|
|
.addFrameIndex(FI).addImm(0);
|
2009-11-25 00:36:00 +00:00
|
|
|
} else
|
|
|
|
llvm_unreachable("Register class not handled!");
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MipsInstrInfo::
|
|
|
|
loadRegFromStackSlot(MachineBasicBlock &MBB, MachineBasicBlock::iterator I,
|
|
|
|
unsigned DestReg, int FI,
|
2010-05-06 19:06:44 +00:00
|
|
|
const TargetRegisterClass *RC,
|
2011-03-04 17:51:39 +00:00
|
|
|
const TargetRegisterInfo *TRI) const
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
{
|
2010-04-02 20:16:16 +00:00
|
|
|
DebugLoc DL;
|
2009-02-12 00:02:55 +00:00
|
|
|
if (I != MBB.end()) DL = I->getDebugLoc();
|
2009-11-25 00:36:00 +00:00
|
|
|
|
2011-03-04 17:51:39 +00:00
|
|
|
if (RC == Mips::CPURegsRegisterClass)
|
2011-07-07 18:57:00 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::LW), DestReg).addFrameIndex(FI).addImm(0);
|
2009-11-25 00:36:00 +00:00
|
|
|
else if (RC == Mips::FGR32RegisterClass)
|
2011-07-07 18:57:00 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::LWC1), DestReg).addFrameIndex(FI).addImm(0);
|
2009-11-25 00:36:00 +00:00
|
|
|
else if (RC == Mips::AFGR64RegisterClass) {
|
2011-08-16 03:51:51 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::LDC1), DestReg).addFrameIndex(FI).addImm(0);
|
2009-11-25 00:36:00 +00:00
|
|
|
} else
|
|
|
|
llvm_unreachable("Register class not handled!");
|
Several changes to Mips backend, experimental fp support being the most
important.
- Cleanup in the Subtarget info with addition of new features, not all support
yet, but they allow the future inclusion of features easier. Among new features,
we have : Arch family info (mips1, mips2, ...), ABI info (o32, eabi), 64-bit
integer
and float registers, allegrex vector FPU (VFPU), single float only support.
- TargetMachine now detects allegrex core.
- Added allegrex (Mips32r2) sext_inreg instructions.
- *Added Float Point Instructions*, handling single float only, and
aliased accesses for 32-bit FPUs.
- Some cleanup in FP instruction formats and FP register classes.
- Calling conventions improved to support mips 32-bit EABI.
- Added Asm Printer support for fp cond codes.
- Added support for sret copy to a return register.
- EABI support added into LowerCALL and FORMAL_ARGS.
- MipsFunctionInfo now keeps a virtual register per function to track the
sret on function entry until function ret.
- MipsInstrInfo FP support into methods (isMoveInstr, isLoadFromStackSlot, ...),
FP cond codes mapping and initial FP Branch Analysis.
- Two new Mips SDNode to handle fp branch and compare instructions : FPBrcond,
FPCmp
- MipsTargetLowering : handling different FP classes, Allegrex support, sret
return copy, no homing location within EABI, non 32-bit stack objects
arguments, and asm constraint for float.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53146 91177308-0d34-0410-b5e6-96231b3b80d8
2008-07-05 19:05:21 +00:00
|
|
|
}
|
|
|
|
|
2011-07-01 01:04:43 +00:00
|
|
|
MachineInstr*
|
|
|
|
MipsInstrInfo::emitFrameIndexDebugValue(MachineFunction &MF, int FrameIx,
|
|
|
|
uint64_t Offset, const MDNode *MDPtr,
|
|
|
|
DebugLoc DL) const {
|
|
|
|
MachineInstrBuilder MIB = BuildMI(MF, DL, get(Mips::DBG_VALUE))
|
|
|
|
.addFrameIndex(FrameIx).addImm(0).addImm(Offset).addMetadata(MDPtr);
|
|
|
|
return &*MIB;
|
|
|
|
}
|
|
|
|
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-08-18 01:56:48 +00:00
|
|
|
// Branch Analysis
|
2011-04-15 21:51:11 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
static unsigned GetAnalyzableBrOpc(unsigned Opc) {
|
|
|
|
return (Opc == Mips::BEQ || Opc == Mips::BNE || Opc == Mips::BGTZ ||
|
|
|
|
Opc == Mips::BGEZ || Opc == Mips::BLTZ || Opc == Mips::BLEZ ||
|
|
|
|
Opc == Mips::BC1T || Opc == Mips::BC1F || Opc == Mips::J) ? Opc : 0;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
/// GetOppositeBranchOpc - Return the inverse of the specified
|
|
|
|
/// opcode, e.g. turning BEQ to BNE.
|
|
|
|
unsigned Mips::GetOppositeBranchOpc(unsigned Opc)
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
2011-04-01 17:39:08 +00:00
|
|
|
switch (Opc) {
|
|
|
|
default: llvm_unreachable("Illegal opcode!");
|
|
|
|
case Mips::BEQ : return Mips::BNE;
|
|
|
|
case Mips::BNE : return Mips::BEQ;
|
|
|
|
case Mips::BGTZ : return Mips::BLEZ;
|
|
|
|
case Mips::BGEZ : return Mips::BLTZ;
|
|
|
|
case Mips::BLTZ : return Mips::BGEZ;
|
|
|
|
case Mips::BLEZ : return Mips::BGTZ;
|
|
|
|
case Mips::BC1T : return Mips::BC1F;
|
|
|
|
case Mips::BC1F : return Mips::BC1T;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
static void AnalyzeCondBr(const MachineInstr* Inst, unsigned Opc,
|
|
|
|
MachineBasicBlock *&BB,
|
|
|
|
SmallVectorImpl<MachineOperand>& Cond) {
|
|
|
|
assert(GetAnalyzableBrOpc(Opc) && "Not an analyzable branch");
|
|
|
|
int NumOp = Inst->getNumExplicitOperands();
|
|
|
|
|
|
|
|
// for both int and fp branches, the last explicit operand is the
|
|
|
|
// MBB.
|
|
|
|
BB = Inst->getOperand(NumOp-1).getMBB();
|
|
|
|
Cond.push_back(MachineOperand::CreateImm(Opc));
|
|
|
|
|
|
|
|
for (int i=0; i<NumOp-1; i++)
|
|
|
|
Cond.push_back(Inst->getOperand(i));
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-04 17:51:39 +00:00
|
|
|
bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
2007-08-18 01:56:48 +00:00
|
|
|
MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
2009-02-09 07:14:22 +00:00
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
2011-03-04 17:51:39 +00:00
|
|
|
bool AllowModify) const
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
2011-04-01 17:39:08 +00:00
|
|
|
MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
|
|
|
|
|
|
|
|
// Skip all the debug instructions.
|
|
|
|
while (I != REnd && I->isDebugValue())
|
|
|
|
++I;
|
|
|
|
|
|
|
|
if (I == REnd || !isUnpredicatedTerminator(&*I)) {
|
|
|
|
// If this block ends with no branches (it just falls through to its succ)
|
|
|
|
// just return false, leaving TBB/FBB null.
|
|
|
|
TBB = FBB = NULL;
|
2010-04-02 01:38:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
MachineInstr *LastInst = &*I;
|
2007-08-18 01:56:48 +00:00
|
|
|
unsigned LastOpc = LastInst->getOpcode();
|
2011-04-01 17:39:08 +00:00
|
|
|
|
|
|
|
// Not an analyzable branch (must be an indirect jump).
|
|
|
|
if (!GetAnalyzableBrOpc(LastOpc))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// Get the second to last instruction in the block.
|
|
|
|
unsigned SecondLastOpc = 0;
|
|
|
|
MachineInstr *SecondLastInst = NULL;
|
|
|
|
|
|
|
|
if (++I != REnd) {
|
|
|
|
SecondLastInst = &*I;
|
|
|
|
SecondLastOpc = GetAnalyzableBrOpc(SecondLastInst->getOpcode());
|
|
|
|
|
|
|
|
// Not an analyzable branch (must be an indirect jump).
|
|
|
|
if (isUnpredicatedTerminator(SecondLastInst) && !SecondLastOpc)
|
2007-08-18 01:56:48 +00:00
|
|
|
return true;
|
2011-04-01 17:39:08 +00:00
|
|
|
}
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// If there is only one terminator instruction, process it.
|
|
|
|
if (!SecondLastOpc) {
|
2007-08-18 01:56:48 +00:00
|
|
|
// Unconditional branch
|
|
|
|
if (LastOpc == Mips::J) {
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = LastInst->getOperand(0).getMBB();
|
2007-08-18 01:56:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Conditional branch
|
2011-04-01 17:39:08 +00:00
|
|
|
AnalyzeCondBr(LastInst, LastOpc, TBB, Cond);
|
|
|
|
return false;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// If we reached here, there are two branches.
|
2007-08-18 01:56:48 +00:00
|
|
|
// If there are three terminators, we don't know what sort of block this is.
|
2011-04-01 17:39:08 +00:00
|
|
|
if (++I != REnd && isUnpredicatedTerminator(&*I))
|
2007-08-18 01:56:48 +00:00
|
|
|
return true;
|
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// If second to last instruction is an unconditional branch,
|
|
|
|
// analyze it and remove the last instruction.
|
|
|
|
if (SecondLastOpc == Mips::J) {
|
|
|
|
// Return if the last instruction cannot be removed.
|
|
|
|
if (!AllowModify)
|
|
|
|
return true;
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
|
|
|
LastInst->eraseFromParent();
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// Conditional branch followed by an unconditional branch.
|
|
|
|
// The last one must be unconditional.
|
|
|
|
if (LastOpc != Mips::J)
|
|
|
|
return true;
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
AnalyzeCondBr(SecondLastInst, SecondLastOpc, TBB, Cond);
|
|
|
|
FBB = LastInst->getOperand(0).getMBB();
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MipsInstrInfo::BuildCondBr(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock *TBB, DebugLoc DL,
|
|
|
|
const SmallVectorImpl<MachineOperand>& Cond)
|
|
|
|
const {
|
|
|
|
unsigned Opc = Cond[0].getImm();
|
2011-06-28 19:10:37 +00:00
|
|
|
const MCInstrDesc &MCID = get(Opc);
|
|
|
|
MachineInstrBuilder MIB = BuildMI(&MBB, DL, MCID);
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
for (unsigned i = 1; i < Cond.size(); ++i)
|
|
|
|
MIB.addReg(Cond[i].getReg());
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
MIB.addMBB(TBB);
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2007-06-06 07:42:06 +00:00
|
|
|
unsigned MipsInstrInfo::
|
2011-03-04 17:51:39 +00:00
|
|
|
InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
|
2008-08-14 22:49:33 +00:00
|
|
|
MachineBasicBlock *FBB,
|
2010-06-17 22:43:56 +00:00
|
|
|
const SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
DebugLoc DL) const {
|
2007-08-18 01:56:48 +00:00
|
|
|
// Shouldn't be a fall through.
|
|
|
|
assert(TBB && "InsertBranch must not be told to insert a fallthrough");
|
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// # of condition operands:
|
|
|
|
// Unconditional branches: 0
|
|
|
|
// Floating point branches: 1 (opc)
|
|
|
|
// Int BranchZero: 2 (opc, reg)
|
|
|
|
// Int Branch: 3 (opc, reg0, reg1)
|
|
|
|
assert((Cond.size() <= 3) &&
|
|
|
|
"# of Mips branch conditions must be <= 3!");
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2007-08-18 01:56:48 +00:00
|
|
|
// Two-way Conditional branch.
|
2011-04-01 17:39:08 +00:00
|
|
|
if (FBB) {
|
|
|
|
BuildCondBr(MBB, TBB, DL, Cond);
|
|
|
|
BuildMI(&MBB, DL, get(Mips::J)).addMBB(FBB);
|
|
|
|
return 2;
|
|
|
|
}
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// One way branch.
|
|
|
|
// Unconditional branch.
|
|
|
|
if (Cond.empty())
|
|
|
|
BuildMI(&MBB, DL, get(Mips::J)).addMBB(TBB);
|
|
|
|
else // Conditional branch.
|
|
|
|
BuildCondBr(MBB, TBB, DL, Cond);
|
|
|
|
return 1;
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|
2007-08-18 01:56:48 +00:00
|
|
|
|
|
|
|
unsigned MipsInstrInfo::
|
2011-03-04 17:51:39 +00:00
|
|
|
RemoveBranch(MachineBasicBlock &MBB) const
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
2011-04-01 17:39:08 +00:00
|
|
|
MachineBasicBlock::reverse_iterator I = MBB.rbegin(), REnd = MBB.rend();
|
|
|
|
MachineBasicBlock::reverse_iterator FirstBr;
|
|
|
|
unsigned removed;
|
|
|
|
|
|
|
|
// Skip all the debug instructions.
|
|
|
|
while (I != REnd && I->isDebugValue())
|
|
|
|
++I;
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
FirstBr = I;
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
// Up to 2 branches are removed.
|
|
|
|
// Note that indirect branches are not removed.
|
|
|
|
for(removed = 0; I != REnd && removed < 2; ++I, ++removed)
|
|
|
|
if (!GetAnalyzableBrOpc(I->getOpcode()))
|
|
|
|
break;
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
MBB.erase(I.base(), FirstBr.base());
|
2011-03-04 17:51:39 +00:00
|
|
|
|
2011-04-01 17:39:08 +00:00
|
|
|
return removed;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
|
2011-03-04 17:51:39 +00:00
|
|
|
/// ReverseBranchCondition - Return the inverse opcode of the
|
2007-08-18 01:56:48 +00:00
|
|
|
/// specified Branch instruction.
|
|
|
|
bool MipsInstrInfo::
|
2011-03-04 17:51:39 +00:00
|
|
|
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
2011-04-01 17:39:08 +00:00
|
|
|
assert( (Cond.size() && Cond.size() <= 3) &&
|
2007-08-18 01:56:48 +00:00
|
|
|
"Invalid Mips branch condition!");
|
2011-04-01 17:39:08 +00:00
|
|
|
Cond[0].setImm(Mips::GetOppositeBranchOpc(Cond[0].getImm()));
|
2007-08-18 01:56:48 +00:00
|
|
|
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 MipsInstrInfo::getGlobalBaseReg(MachineFunction *MF) const {
|
|
|
|
MipsFunctionInfo *MipsFI = MF->getInfo<MipsFunctionInfo>();
|
|
|
|
unsigned GlobalBaseReg = MipsFI->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(Mips::CPURegsRegisterClass);
|
2010-07-10 22:43:03 +00:00
|
|
|
BuildMI(FirstMBB, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY),
|
|
|
|
GlobalBaseReg).addReg(Mips::GP);
|
2009-06-03 20:30:14 +00:00
|
|
|
RegInfo.addLiveIn(Mips::GP);
|
|
|
|
|
|
|
|
MipsFI->setGlobalBaseReg(GlobalBaseReg);
|
|
|
|
return GlobalBaseReg;
|
|
|
|
}
|