2007-06-06 07:42:06 +00:00
|
|
|
//===- MipsInstrInfo.cpp - Mips Instruction Information ---------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains the Mips implementation of the TargetInstrInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#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"
|
2007-09-07 04:06:50 +00:00
|
|
|
#include "llvm/ADT/STLExtras.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"
|
2007-06-06 07:42:06 +00:00
|
|
|
#include "MipsGenInstrInfo.inc"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
MipsInstrInfo::MipsInstrInfo(MipsTargetMachine &tm)
|
2008-01-01 01:03:04 +00:00
|
|
|
: TargetInstrInfoImpl(MipsInsts, array_lengthof(MipsInsts)),
|
2008-07-14 14:42:54 +00:00
|
|
|
TM(tm), RI(*TM.getSubtargetImpl(), *this) {}
|
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::
|
2008-11-18 19:49:32 +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)) {
|
2008-10-03 15:45:36 +00:00
|
|
|
if ((MI->getOperand(2).isFI()) && // is a stack slot
|
|
|
|
(MI->getOperand(1).isImm()) && // the imm is zero
|
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
|
|
|
(isZeroImm(MI->getOperand(1)))) {
|
2007-12-30 23:10:15 +00:00
|
|
|
FrameIndex = MI->getOperand(2).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::
|
2008-11-18 19:49:32 +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)) {
|
2008-10-03 15:45:36 +00:00
|
|
|
if ((MI->getOperand(2).isFI()) && // is a stack slot
|
|
|
|
(MI->getOperand(1).isImm()) && // the imm is zero
|
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
|
|
|
(isZeroImm(MI->getOperand(1)))) {
|
2008-08-02 19:42:36 +00:00
|
|
|
FrameIndex = MI->getOperand(2).getIndex();
|
|
|
|
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::
|
|
|
|
insertNoop(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const
|
|
|
|
{
|
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;
|
|
|
|
}
|
2008-08-26 18:03:31 +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,
|
2009-02-12 00:02:55 +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();
|
|
|
|
|
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 (RC == Mips::CPURegsRegisterClass)
|
2009-11-25 00:36:00 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::SW)).addReg(SrcReg, getKillRegState(isKill))
|
|
|
|
.addImm(0).addFrameIndex(FI);
|
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)
|
2009-11-25 00:36:00 +00:00
|
|
|
BuildMI(MBB, I, DL, get(Mips::SWC1)).addReg(SrcReg, getKillRegState(isKill))
|
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
|
|
|
.addImm(0).addFrameIndex(FI);
|
2009-11-25 00:36:00 +00:00
|
|
|
else if (RC == Mips::AFGR64RegisterClass) {
|
|
|
|
if (!TM.getSubtarget<MipsSubtarget>().isMips1()) {
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::SDC1))
|
|
|
|
.addReg(SrcReg, getKillRegState(isKill))
|
|
|
|
.addImm(0).addFrameIndex(FI);
|
|
|
|
} else {
|
|
|
|
const TargetRegisterInfo *TRI =
|
|
|
|
MBB.getParent()->getTarget().getRegisterInfo();
|
|
|
|
const unsigned *SubSet = TRI->getSubRegisters(SrcReg);
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::SWC1))
|
|
|
|
.addReg(SubSet[0], getKillRegState(isKill))
|
|
|
|
.addImm(0).addFrameIndex(FI);
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::SWC1))
|
|
|
|
.addReg(SubSet[1], getKillRegState(isKill))
|
|
|
|
.addImm(4).addFrameIndex(FI);
|
|
|
|
}
|
|
|
|
} 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,
|
|
|
|
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
|
|
|
|
|
|
|
if (RC == Mips::CPURegsRegisterClass)
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::LW), DestReg).addImm(0).addFrameIndex(FI);
|
|
|
|
else if (RC == Mips::FGR32RegisterClass)
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::LWC1), DestReg).addImm(0).addFrameIndex(FI);
|
|
|
|
else if (RC == Mips::AFGR64RegisterClass) {
|
|
|
|
if (!TM.getSubtarget<MipsSubtarget>().isMips1()) {
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::LDC1), DestReg).addImm(0).addFrameIndex(FI);
|
|
|
|
} else {
|
|
|
|
const TargetRegisterInfo *TRI =
|
|
|
|
MBB.getParent()->getTarget().getRegisterInfo();
|
|
|
|
const unsigned *SubSet = TRI->getSubRegisters(DestReg);
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::LWC1), SubSet[0])
|
|
|
|
.addImm(0).addFrameIndex(FI);
|
|
|
|
BuildMI(MBB, I, DL, get(Mips::LWC1), SubSet[1])
|
|
|
|
.addImm(4).addFrameIndex(FI);
|
|
|
|
}
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
2007-08-18 01:56:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Branch Analysis
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// GetCondFromBranchOpc - Return the Mips CC that matches
|
|
|
|
/// the correspondent Branch instruction opcode.
|
|
|
|
static Mips::CondCode GetCondFromBranchOpc(unsigned BrOpc)
|
|
|
|
{
|
|
|
|
switch (BrOpc) {
|
|
|
|
default: return Mips::COND_INVALID;
|
2008-07-28 19:11:24 +00:00
|
|
|
case Mips::BEQ : return Mips::COND_E;
|
|
|
|
case Mips::BNE : return Mips::COND_NE;
|
|
|
|
case Mips::BGTZ : return Mips::COND_GZ;
|
|
|
|
case Mips::BGEZ : return Mips::COND_GEZ;
|
|
|
|
case Mips::BLTZ : return Mips::COND_LZ;
|
|
|
|
case Mips::BLEZ : return Mips::COND_LEZ;
|
|
|
|
|
|
|
|
// We dont do fp branch analysis yet!
|
|
|
|
case Mips::BC1T :
|
|
|
|
case Mips::BC1F : return Mips::COND_INVALID;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetCondBranchFromCond - Return the Branch instruction
|
|
|
|
/// opcode that matches the cc.
|
|
|
|
unsigned Mips::GetCondBranchFromCond(Mips::CondCode CC)
|
|
|
|
{
|
|
|
|
switch (CC) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Illegal condition code!");
|
2007-08-18 01:56:48 +00:00
|
|
|
case Mips::COND_E : return Mips::BEQ;
|
|
|
|
case Mips::COND_NE : return Mips::BNE;
|
|
|
|
case Mips::COND_GZ : return Mips::BGTZ;
|
|
|
|
case Mips::COND_GEZ : return Mips::BGEZ;
|
|
|
|
case Mips::COND_LZ : return Mips::BLTZ;
|
|
|
|
case Mips::COND_LEZ : return Mips::BLEZ;
|
2008-07-28 19:11:24 +00:00
|
|
|
|
|
|
|
case Mips::FCOND_F:
|
|
|
|
case Mips::FCOND_UN:
|
|
|
|
case Mips::FCOND_EQ:
|
|
|
|
case Mips::FCOND_UEQ:
|
|
|
|
case Mips::FCOND_OLT:
|
|
|
|
case Mips::FCOND_ULT:
|
|
|
|
case Mips::FCOND_OLE:
|
|
|
|
case Mips::FCOND_ULE:
|
|
|
|
case Mips::FCOND_SF:
|
|
|
|
case Mips::FCOND_NGLE:
|
|
|
|
case Mips::FCOND_SEQ:
|
|
|
|
case Mips::FCOND_NGL:
|
|
|
|
case Mips::FCOND_LT:
|
|
|
|
case Mips::FCOND_NGE:
|
|
|
|
case Mips::FCOND_LE:
|
|
|
|
case Mips::FCOND_NGT: return Mips::BC1T;
|
|
|
|
|
|
|
|
case Mips::FCOND_T:
|
|
|
|
case Mips::FCOND_OR:
|
|
|
|
case Mips::FCOND_NEQ:
|
|
|
|
case Mips::FCOND_OGL:
|
|
|
|
case Mips::FCOND_UGE:
|
|
|
|
case Mips::FCOND_OGE:
|
|
|
|
case Mips::FCOND_UGT:
|
|
|
|
case Mips::FCOND_OGT:
|
|
|
|
case Mips::FCOND_ST:
|
|
|
|
case Mips::FCOND_GLE:
|
|
|
|
case Mips::FCOND_SNE:
|
|
|
|
case Mips::FCOND_GL:
|
|
|
|
case Mips::FCOND_NLT:
|
|
|
|
case Mips::FCOND_GE:
|
|
|
|
case Mips::FCOND_NLE:
|
|
|
|
case Mips::FCOND_GT: return Mips::BC1F;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GetOppositeBranchCondition - Return the inverse of the specified
|
|
|
|
/// condition, e.g. turning COND_E to COND_NE.
|
|
|
|
Mips::CondCode Mips::GetOppositeBranchCondition(Mips::CondCode CC)
|
|
|
|
{
|
|
|
|
switch (CC) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Illegal condition code!");
|
2007-08-18 01:56:48 +00:00
|
|
|
case Mips::COND_E : return Mips::COND_NE;
|
|
|
|
case Mips::COND_NE : return Mips::COND_E;
|
|
|
|
case Mips::COND_GZ : return Mips::COND_LEZ;
|
|
|
|
case Mips::COND_GEZ : return Mips::COND_LZ;
|
|
|
|
case Mips::COND_LZ : return Mips::COND_GEZ;
|
|
|
|
case Mips::COND_LEZ : return Mips::COND_GZ;
|
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
|
|
|
case Mips::FCOND_F : return Mips::FCOND_T;
|
|
|
|
case Mips::FCOND_UN : return Mips::FCOND_OR;
|
|
|
|
case Mips::FCOND_EQ : return Mips::FCOND_NEQ;
|
|
|
|
case Mips::FCOND_UEQ: return Mips::FCOND_OGL;
|
|
|
|
case Mips::FCOND_OLT: return Mips::FCOND_UGE;
|
|
|
|
case Mips::FCOND_ULT: return Mips::FCOND_OGE;
|
|
|
|
case Mips::FCOND_OLE: return Mips::FCOND_UGT;
|
|
|
|
case Mips::FCOND_ULE: return Mips::FCOND_OGT;
|
|
|
|
case Mips::FCOND_SF: return Mips::FCOND_ST;
|
|
|
|
case Mips::FCOND_NGLE:return Mips::FCOND_GLE;
|
|
|
|
case Mips::FCOND_SEQ: return Mips::FCOND_SNE;
|
|
|
|
case Mips::FCOND_NGL: return Mips::FCOND_GL;
|
|
|
|
case Mips::FCOND_LT: return Mips::FCOND_NLT;
|
|
|
|
case Mips::FCOND_NGE: return Mips::FCOND_GE;
|
|
|
|
case Mips::FCOND_LE: return Mips::FCOND_NLE;
|
|
|
|
case Mips::FCOND_NGT: return Mips::FCOND_GT;
|
2007-08-18 01:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MipsInstrInfo::AnalyzeBranch(MachineBasicBlock &MBB,
|
|
|
|
MachineBasicBlock *&TBB,
|
|
|
|
MachineBasicBlock *&FBB,
|
2009-02-09 07:14:22 +00:00
|
|
|
SmallVectorImpl<MachineOperand> &Cond,
|
|
|
|
bool AllowModify) const
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
|
|
|
// If the block has no terminators, it just falls into the block after it.
|
|
|
|
MachineBasicBlock::iterator I = MBB.end();
|
2010-04-02 01:38:09 +00:00
|
|
|
if (I == MBB.begin())
|
|
|
|
return false;
|
|
|
|
--I;
|
|
|
|
while (I->isDebugValue()) {
|
|
|
|
if (I == MBB.begin())
|
|
|
|
return false;
|
|
|
|
--I;
|
|
|
|
}
|
|
|
|
if (!isUnpredicatedTerminator(I))
|
2007-08-18 01:56:48 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// Get the last instruction in the block.
|
|
|
|
MachineInstr *LastInst = I;
|
|
|
|
|
|
|
|
// If there is only one terminator instruction, process it.
|
|
|
|
unsigned LastOpc = LastInst->getOpcode();
|
|
|
|
if (I == MBB.begin() || !isUnpredicatedTerminator(--I)) {
|
2008-01-07 07:27:27 +00:00
|
|
|
if (!LastInst->getDesc().isBranch())
|
2007-08-18 01:56:48 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mips::CondCode BranchCode = GetCondFromBranchOpc(LastInst->getOpcode());
|
|
|
|
if (BranchCode == Mips::COND_INVALID)
|
|
|
|
return true; // Can't handle indirect branch.
|
|
|
|
|
|
|
|
// Conditional branch
|
|
|
|
// Block ends with fall-through condbranch.
|
|
|
|
if (LastOpc != Mips::COND_INVALID) {
|
|
|
|
int LastNumOp = LastInst->getNumOperands();
|
|
|
|
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = LastInst->getOperand(LastNumOp-1).getMBB();
|
2007-08-18 01:56:48 +00:00
|
|
|
Cond.push_back(MachineOperand::CreateImm(BranchCode));
|
|
|
|
|
|
|
|
for (int i=0; i<LastNumOp-1; i++) {
|
|
|
|
Cond.push_back(LastInst->getOperand(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the instruction before it if it is 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() && isUnpredicatedTerminator(--I))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// If the block ends with Mips::J and a Mips::BNE/Mips::BEQ, handle it.
|
|
|
|
unsigned SecondLastOpc = SecondLastInst->getOpcode();
|
|
|
|
Mips::CondCode BranchCode = GetCondFromBranchOpc(SecondLastOpc);
|
|
|
|
|
2008-08-02 19:42:36 +00:00
|
|
|
if (BranchCode != Mips::COND_INVALID && LastOpc == Mips::J) {
|
2007-08-18 01:56:48 +00:00
|
|
|
int SecondNumOp = SecondLastInst->getNumOperands();
|
|
|
|
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = SecondLastInst->getOperand(SecondNumOp-1).getMBB();
|
2007-08-18 01:56:48 +00:00
|
|
|
Cond.push_back(MachineOperand::CreateImm(BranchCode));
|
|
|
|
|
|
|
|
for (int i=0; i<SecondNumOp-1; i++) {
|
|
|
|
Cond.push_back(SecondLastInst->getOperand(i));
|
|
|
|
}
|
|
|
|
|
2007-12-30 23:10:15 +00:00
|
|
|
FBB = LastInst->getOperand(0).getMBB();
|
2007-08-18 01:56:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the block ends with two unconditional branches, handle it. The last
|
|
|
|
// one is not executed, so remove it.
|
|
|
|
if ((SecondLastOpc == Mips::J) && (LastOpc == Mips::J)) {
|
2007-12-30 23:10:15 +00:00
|
|
|
TBB = SecondLastInst->getOperand(0).getMBB();
|
2007-08-18 01:56:48 +00:00
|
|
|
I = LastInst;
|
2009-02-09 07:14:22 +00:00
|
|
|
if (AllowModify)
|
|
|
|
I->eraseFromParent();
|
2007-08-18 01:56:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, can't handle this.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-06 07:42:06 +00:00
|
|
|
unsigned MipsInstrInfo::
|
|
|
|
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");
|
|
|
|
assert((Cond.size() == 3 || Cond.size() == 2 || Cond.size() == 0) &&
|
|
|
|
"Mips branch conditions can have two|three components!");
|
|
|
|
|
|
|
|
if (FBB == 0) { // One way branch.
|
|
|
|
if (Cond.empty()) {
|
|
|
|
// Unconditional branch?
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, get(Mips::J)).addMBB(TBB);
|
2007-08-18 01:56:48 +00:00
|
|
|
} else {
|
|
|
|
// Conditional branch.
|
|
|
|
unsigned Opc = GetCondBranchFromCond((Mips::CondCode)Cond[0].getImm());
|
2008-01-07 07:27:27 +00:00
|
|
|
const TargetInstrDesc &TID = get(Opc);
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2008-01-07 03:13:06 +00:00
|
|
|
if (TID.getNumOperands() == 3)
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, TID).addReg(Cond[1].getReg())
|
2007-08-18 01:56:48 +00:00
|
|
|
.addReg(Cond[2].getReg())
|
|
|
|
.addMBB(TBB);
|
|
|
|
else
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, TID).addReg(Cond[1].getReg())
|
2007-08-18 01:56:48 +00:00
|
|
|
.addMBB(TBB);
|
|
|
|
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Two-way Conditional branch.
|
|
|
|
unsigned Opc = GetCondBranchFromCond((Mips::CondCode)Cond[0].getImm());
|
2008-01-07 07:27:27 +00:00
|
|
|
const TargetInstrDesc &TID = get(Opc);
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2008-01-07 03:13:06 +00:00
|
|
|
if (TID.getNumOperands() == 3)
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, TID).addReg(Cond[1].getReg()).addReg(Cond[2].getReg())
|
2007-08-18 01:56:48 +00:00
|
|
|
.addMBB(TBB);
|
|
|
|
else
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, TID).addReg(Cond[1].getReg()).addMBB(TBB);
|
2007-08-18 01:56:48 +00:00
|
|
|
|
2010-06-17 22:43:56 +00:00
|
|
|
BuildMI(&MBB, DL, get(Mips::J)).addMBB(FBB);
|
2007-08-18 01:56:48 +00:00
|
|
|
return 2;
|
2007-06-06 07:42:06 +00:00
|
|
|
}
|
2007-08-18 01:56:48 +00:00
|
|
|
|
|
|
|
unsigned MipsInstrInfo::
|
|
|
|
RemoveBranch(MachineBasicBlock &MBB) const
|
|
|
|
{
|
|
|
|
MachineBasicBlock::iterator I = MBB.end();
|
|
|
|
if (I == MBB.begin()) return 0;
|
|
|
|
--I;
|
2010-04-02 01:38:09 +00:00
|
|
|
while (I->isDebugValue()) {
|
|
|
|
if (I == MBB.begin())
|
|
|
|
return 0;
|
|
|
|
--I;
|
|
|
|
}
|
2007-08-18 01:56:48 +00:00
|
|
|
if (I->getOpcode() != Mips::J &&
|
|
|
|
GetCondFromBranchOpc(I->getOpcode()) == Mips::COND_INVALID)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
|
|
|
|
|
|
|
I = MBB.end();
|
|
|
|
|
|
|
|
if (I == MBB.begin()) return 1;
|
|
|
|
--I;
|
|
|
|
if (GetCondFromBranchOpc(I->getOpcode()) == Mips::COND_INVALID)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// Remove the branch.
|
|
|
|
I->eraseFromParent();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ReverseBranchCondition - Return the inverse opcode of the
|
|
|
|
/// specified Branch instruction.
|
|
|
|
bool MipsInstrInfo::
|
2008-08-14 22:49:33 +00:00
|
|
|
ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const
|
2007-08-18 01:56:48 +00:00
|
|
|
{
|
|
|
|
assert( (Cond.size() == 3 || Cond.size() == 2) &&
|
|
|
|
"Invalid Mips branch condition!");
|
|
|
|
Cond[0].setImm(GetOppositeBranchCondition((Mips::CondCode)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 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;
|
|
|
|
}
|