2011-04-16 05:51:11 +08:00
|
|
|
//===-- MipsISelDAGToDAG.cpp - A dag to dag inst selector for Mips --------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
//
|
|
|
|
// This file defines an instruction selector for the MIPS target.
|
|
|
|
//
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
#define DEBUG_TYPE "mips-isel"
|
|
|
|
#include "Mips.h"
|
2007-11-05 11:02:32 +08:00
|
|
|
#include "MipsMachineFunction.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "MipsRegisterInfo.h"
|
|
|
|
#include "MipsSubtarget.h"
|
|
|
|
#include "MipsTargetMachine.h"
|
|
|
|
#include "llvm/GlobalValue.h"
|
|
|
|
#include "llvm/Instructions.h"
|
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
#include "llvm/Support/CFG.h"
|
|
|
|
#include "llvm/Type.h"
|
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2007-12-31 12:13:23 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-09 04:53:28 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-06-06 15:42:06 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
// Instruction Selector Implementation
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
// MipsDAGToDAGISel - MIPS specific code to select MIPS machine
|
|
|
|
// instructions for SelectionDAG operations.
|
2011-04-16 05:51:11 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2007-06-06 15:42:06 +08:00
|
|
|
namespace {
|
|
|
|
|
2009-10-25 14:33:48 +08:00
|
|
|
class MipsDAGToDAGISel : public SelectionDAGISel {
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
/// TM - Keep a reference to MipsTargetMachine.
|
|
|
|
MipsTargetMachine &TM;
|
|
|
|
|
|
|
|
/// Subtarget - Keep a pointer to the MipsSubtarget around so that we can
|
|
|
|
/// make the right decision when generating code for different targets.
|
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.
llvm-svn: 53146
2008-07-06 03:05:21 +08:00
|
|
|
const MipsSubtarget &Subtarget;
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
public:
|
2008-07-08 02:00:37 +08:00
|
|
|
explicit MipsDAGToDAGISel(MipsTargetMachine &tm) :
|
2009-01-16 03:20:50 +08:00
|
|
|
SelectionDAGISel(tm),
|
2008-10-04 00:55:19 +08:00
|
|
|
TM(tm), Subtarget(tm.getSubtarget<MipsSubtarget>()) {}
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
// Pass Name
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "MIPS DAG->DAG Pattern Instruction Selection";
|
2011-03-05 01:51:39 +08:00
|
|
|
}
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
|
|
|
|
private:
|
2007-06-06 15:42:06 +08:00
|
|
|
// Include the pieces autogenerated from the target description.
|
|
|
|
#include "MipsGenDAGISel.inc"
|
|
|
|
|
2009-06-04 04:30:14 +08:00
|
|
|
/// getTargetMachine - Return a reference to the TargetMachine, casted
|
|
|
|
/// to the target-specific type.
|
|
|
|
const MipsTargetMachine &getTargetMachine() {
|
|
|
|
return static_cast<const MipsTargetMachine &>(TM);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// getInstrInfo - Return a reference to the TargetInstrInfo, casted
|
|
|
|
/// to the target-specific type.
|
|
|
|
const MipsInstrInfo *getInstrInfo() {
|
|
|
|
return getTargetMachine().getInstrInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *getGlobalBaseReg();
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode *Select(SDNode *N);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
// Complex Pattern.
|
2010-09-22 04:31:19 +08:00
|
|
|
bool SelectAddr(SDValue N, SDValue &Base, SDValue &Offset);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode *SelectLoadFp64(SDNode *N);
|
|
|
|
SDNode *SelectStoreFp64(SDNode *N);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
// getI32Imm - Return a target constant with the specified
|
|
|
|
// value, of type i32.
|
2008-07-28 05:46:04 +08:00
|
|
|
inline SDValue getI32Imm(unsigned Imm) {
|
2009-08-12 04:47:22 +08:00
|
|
|
return CurDAG->getTargetConstant(Imm, MVT::i32);
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
2011-06-21 08:40:49 +08:00
|
|
|
|
|
|
|
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
|
|
|
|
char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps);
|
2007-06-06 15:42:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-13 03:49:57 +08:00
|
|
|
/// getGlobalBaseReg - Output the instructions required to put the
|
|
|
|
/// GOT address into a register.
|
2009-06-04 04:30:14 +08:00
|
|
|
SDNode *MipsDAGToDAGISel::getGlobalBaseReg() {
|
|
|
|
unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
|
|
|
|
return CurDAG->getRegister(GlobalBaseReg, TLI.getPointerTy()).getNode();
|
2007-11-13 03:49:57 +08:00
|
|
|
}
|
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
/// ComplexPattern used on MipsInstrInfo
|
|
|
|
/// Used on Mips Load/Store instructions
|
|
|
|
bool MipsDAGToDAGISel::
|
2011-07-08 02:57:00 +08:00
|
|
|
SelectAddr(SDValue Addr, SDValue &Base, SDValue &Offset) {
|
2007-06-06 15:42:06 +08:00
|
|
|
// if Address is FI, get the TargetFrameIndex.
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
|
2009-08-12 04:47:22 +08:00
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
2007-06-06 15:42:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
2011-03-05 01:51:39 +08:00
|
|
|
|
2007-11-05 11:02:32 +08:00
|
|
|
// on PIC code Load GA
|
|
|
|
if (TM.getRelocationModel() == Reloc::PIC_) {
|
2011-05-28 09:07:07 +08:00
|
|
|
if (Addr.getOpcode() == MipsISD::WrapperPIC) {
|
2009-08-12 04:47:22 +08:00
|
|
|
Base = CurDAG->getRegister(Mips::GP, MVT::i32);
|
2011-05-28 09:07:07 +08:00
|
|
|
Offset = Addr.getOperand(0);
|
2007-11-05 11:02:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
2008-09-17 05:48:12 +08:00
|
|
|
if ((Addr.getOpcode() == ISD::TargetExternalSymbol ||
|
2007-11-05 11:02:32 +08:00
|
|
|
Addr.getOpcode() == ISD::TargetGlobalAddress))
|
|
|
|
return false;
|
2011-05-31 10:53:58 +08:00
|
|
|
else if (Addr.getOpcode() == ISD::TargetGlobalTLSAddress) {
|
|
|
|
Base = CurDAG->getRegister(Mips::GP, MVT::i32);
|
|
|
|
Offset = Addr;
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-05 01:51:39 +08:00
|
|
|
}
|
|
|
|
|
2011-06-02 09:03:14 +08:00
|
|
|
// Addresses of the form FI+const or FI|const
|
|
|
|
if (CurDAG->isBaseWithConstantOffset(Addr)) {
|
|
|
|
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1));
|
|
|
|
if (isInt<16>(CN->getSExtValue())) {
|
|
|
|
|
|
|
|
// If the first operand is a FI, get the TargetFI Node
|
|
|
|
if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>
|
|
|
|
(Addr.getOperand(0)))
|
|
|
|
Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
|
|
|
|
else
|
|
|
|
Base = Addr.getOperand(0);
|
|
|
|
|
|
|
|
Offset = CurDAG->getTargetConstant(CN->getZExtValue(), MVT::i32);
|
|
|
|
return true;
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
2011-06-02 09:03:14 +08:00
|
|
|
}
|
2009-11-16 12:33:42 +08:00
|
|
|
|
2011-06-02 09:03:14 +08:00
|
|
|
// Operand is a result from an ADD.
|
|
|
|
if (Addr.getOpcode() == ISD::ADD) {
|
2009-11-16 12:33:42 +08:00
|
|
|
// When loading from constant pools, load the lower address part in
|
2009-11-25 20:17:58 +08:00
|
|
|
// the instruction itself. Example, instead of:
|
2009-11-16 12:33:42 +08:00
|
|
|
// lui $2, %hi($CPI1_0)
|
|
|
|
// addiu $2, $2, %lo($CPI1_0)
|
|
|
|
// lwc1 $f0, 0($2)
|
|
|
|
// Generate:
|
|
|
|
// lui $2, %hi($CPI1_0)
|
|
|
|
// lwc1 $f0, %lo($CPI1_0)($2)
|
2011-03-05 01:51:39 +08:00
|
|
|
if ((Addr.getOperand(0).getOpcode() == MipsISD::Hi ||
|
2009-11-25 20:17:58 +08:00
|
|
|
Addr.getOperand(0).getOpcode() == ISD::LOAD) &&
|
2009-11-16 12:33:42 +08:00
|
|
|
Addr.getOperand(1).getOpcode() == MipsISD::Lo) {
|
2011-03-05 01:51:39 +08:00
|
|
|
SDValue LoVal = Addr.getOperand(1);
|
2011-06-25 01:55:19 +08:00
|
|
|
if (isa<ConstantPoolSDNode>(LoVal.getOperand(0)) ||
|
|
|
|
isa<GlobalAddressSDNode>(LoVal.getOperand(0))) {
|
2009-11-25 20:17:58 +08:00
|
|
|
Base = Addr.getOperand(0);
|
|
|
|
Offset = LoVal.getOperand(0);
|
|
|
|
return true;
|
2009-11-16 12:33:42 +08:00
|
|
|
}
|
|
|
|
}
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
2007-07-12 07:24:41 +08:00
|
|
|
Base = Addr;
|
2009-08-12 04:47:22 +08:00
|
|
|
Offset = CurDAG->getTargetConstant(0, MVT::i32);
|
2007-06-06 15:42:06 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode *MipsDAGToDAGISel::SelectLoadFp64(SDNode *N) {
|
2011-03-05 01:51:39 +08:00
|
|
|
MVT::SimpleValueType NVT =
|
2010-01-05 09:24:18 +08:00
|
|
|
N->getValueType(0).getSimpleVT().SimpleTy;
|
2009-11-19 14:06:13 +08:00
|
|
|
|
|
|
|
if (!Subtarget.isMips1() || NVT != MVT::f64)
|
|
|
|
return NULL;
|
|
|
|
|
2010-09-03 08:35:13 +08:00
|
|
|
LoadSDNode *LN = cast<LoadSDNode>(N);
|
|
|
|
if (LN->getExtensionType() != ISD::NON_EXTLOAD ||
|
|
|
|
LN->getAddressingMode() != ISD::UNINDEXED)
|
2009-11-19 14:06:13 +08:00
|
|
|
return NULL;
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
SDValue Chain = N->getOperand(0);
|
|
|
|
SDValue N1 = N->getOperand(1);
|
2009-11-19 14:06:13 +08:00
|
|
|
SDValue Offset0, Offset1, Base;
|
|
|
|
|
2011-07-08 02:57:00 +08:00
|
|
|
if (!SelectAddr(N1, Base, Offset0) ||
|
2009-11-19 14:06:13 +08:00
|
|
|
N1.getValueType() != MVT::i32)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MachineSDNode::mmo_iterator MemRefs0 = MF->allocateMemRefsArray(1);
|
|
|
|
MemRefs0[0] = cast<MemSDNode>(N)->getMemOperand();
|
2010-01-05 09:24:18 +08:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2009-11-19 14:06:13 +08:00
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
// The second load should start after for 4 bytes.
|
2009-11-19 14:06:13 +08:00
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Offset0))
|
|
|
|
Offset1 = CurDAG->getTargetConstant(C->getSExtValue()+4, MVT::i32);
|
|
|
|
else if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Offset0))
|
2011-03-05 01:51:39 +08:00
|
|
|
Offset1 = CurDAG->getTargetConstantPool(CP->getConstVal(),
|
|
|
|
MVT::i32,
|
|
|
|
CP->getAlignment(),
|
|
|
|
CP->getOffset()+4,
|
2009-11-19 14:06:13 +08:00
|
|
|
CP->getTargetFlags());
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
2009-11-25 09:05:25 +08:00
|
|
|
// Choose the offsets depending on the endianess
|
|
|
|
if (TM.getTargetData()->isBigEndian())
|
|
|
|
std::swap(Offset0, Offset1);
|
|
|
|
|
2009-11-19 14:06:13 +08:00
|
|
|
// Instead of:
|
|
|
|
// ldc $f0, X($3)
|
|
|
|
// Generate:
|
|
|
|
// lwc $f0, X($3)
|
|
|
|
// lwc $f1, X+4($3)
|
2011-03-05 01:51:39 +08:00
|
|
|
SDNode *LD0 = CurDAG->getMachineNode(Mips::LWC1, dl, MVT::f32,
|
2011-07-08 02:57:00 +08:00
|
|
|
MVT::Other, Base, Offset0, Chain);
|
2010-02-10 03:54:29 +08:00
|
|
|
SDValue Undef = SDValue(CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
|
2009-11-19 14:06:13 +08:00
|
|
|
dl, NVT), 0);
|
2011-03-05 01:51:39 +08:00
|
|
|
SDValue I0 = CurDAG->getTargetInsertSubreg(Mips::sub_fpeven, dl,
|
2009-11-19 14:06:13 +08:00
|
|
|
MVT::f64, Undef, SDValue(LD0, 0));
|
|
|
|
|
|
|
|
SDNode *LD1 = CurDAG->getMachineNode(Mips::LWC1, dl, MVT::f32,
|
2011-07-08 02:57:00 +08:00
|
|
|
MVT::Other, Base, Offset1, SDValue(LD0, 1));
|
2011-03-05 01:51:39 +08:00
|
|
|
SDValue I1 = CurDAG->getTargetInsertSubreg(Mips::sub_fpodd, dl,
|
2009-11-19 14:06:13 +08:00
|
|
|
MVT::f64, I0, SDValue(LD1, 0));
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
ReplaceUses(SDValue(N, 0), I1);
|
|
|
|
ReplaceUses(SDValue(N, 1), Chain);
|
2009-11-19 14:06:13 +08:00
|
|
|
cast<MachineSDNode>(LD0)->setMemRefs(MemRefs0, MemRefs0 + 1);
|
|
|
|
cast<MachineSDNode>(LD1)->setMemRefs(MemRefs0, MemRefs0 + 1);
|
|
|
|
return I1.getNode();
|
|
|
|
}
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode *MipsDAGToDAGISel::SelectStoreFp64(SDNode *N) {
|
2009-11-19 14:06:13 +08:00
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
if (!Subtarget.isMips1() ||
|
2010-01-05 09:24:18 +08:00
|
|
|
N->getOperand(1).getValueType() != MVT::f64)
|
2009-11-19 14:06:13 +08:00
|
|
|
return NULL;
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
SDValue Chain = N->getOperand(0);
|
2009-11-19 14:06:13 +08:00
|
|
|
|
2010-08-19 07:56:46 +08:00
|
|
|
StoreSDNode *SN = cast<StoreSDNode>(N);
|
|
|
|
if (SN->isTruncatingStore() || SN->getAddressingMode() != ISD::UNINDEXED)
|
2009-11-19 14:06:13 +08:00
|
|
|
return NULL;
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
SDValue N1 = N->getOperand(1);
|
|
|
|
SDValue N2 = N->getOperand(2);
|
2009-11-19 14:06:13 +08:00
|
|
|
SDValue Offset0, Offset1, Base;
|
|
|
|
|
2011-07-08 02:57:00 +08:00
|
|
|
if (!SelectAddr(N2, Base, Offset0) ||
|
2009-11-19 14:06:13 +08:00
|
|
|
N1.getValueType() != MVT::f64 ||
|
|
|
|
N2.getValueType() != MVT::i32)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
MachineSDNode::mmo_iterator MemRefs0 = MF->allocateMemRefsArray(1);
|
|
|
|
MemRefs0[0] = cast<MemSDNode>(N)->getMemOperand();
|
2010-01-05 09:24:18 +08:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2009-11-19 14:06:13 +08:00
|
|
|
|
|
|
|
// Get the even and odd part from the f64 register
|
2011-03-05 01:51:39 +08:00
|
|
|
SDValue FPOdd = CurDAG->getTargetExtractSubreg(Mips::sub_fpodd,
|
2009-11-19 14:06:13 +08:00
|
|
|
dl, MVT::f32, N1);
|
2010-05-25 01:42:58 +08:00
|
|
|
SDValue FPEven = CurDAG->getTargetExtractSubreg(Mips::sub_fpeven,
|
2009-11-19 14:06:13 +08:00
|
|
|
dl, MVT::f32, N1);
|
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
// The second store should start after for 4 bytes.
|
2009-11-19 14:06:13 +08:00
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Offset0))
|
|
|
|
Offset1 = CurDAG->getTargetConstant(C->getSExtValue()+4, MVT::i32);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
|
2009-11-25 09:05:25 +08:00
|
|
|
// Choose the offsets depending on the endianess
|
|
|
|
if (TM.getTargetData()->isBigEndian())
|
|
|
|
std::swap(Offset0, Offset1);
|
|
|
|
|
2009-11-19 14:06:13 +08:00
|
|
|
// Instead of:
|
|
|
|
// sdc $f0, X($3)
|
|
|
|
// Generate:
|
|
|
|
// swc $f0, X($3)
|
|
|
|
// swc $f1, X+4($3)
|
2011-07-08 02:57:00 +08:00
|
|
|
SDValue Ops0[] = { FPEven, Base, Offset0, Chain };
|
2009-11-19 14:06:13 +08:00
|
|
|
Chain = SDValue(CurDAG->getMachineNode(Mips::SWC1, dl,
|
|
|
|
MVT::Other, Ops0, 4), 0);
|
|
|
|
cast<MachineSDNode>(Chain.getNode())->setMemRefs(MemRefs0, MemRefs0 + 1);
|
|
|
|
|
2011-07-08 02:57:00 +08:00
|
|
|
SDValue Ops1[] = { FPOdd, Base, Offset1, Chain };
|
2009-11-19 14:06:13 +08:00
|
|
|
Chain = SDValue(CurDAG->getMachineNode(Mips::SWC1, dl,
|
|
|
|
MVT::Other, Ops1, 4), 0);
|
|
|
|
cast<MachineSDNode>(Chain.getNode())->setMemRefs(MemRefs0, MemRefs0 + 1);
|
|
|
|
|
2010-01-05 09:24:18 +08:00
|
|
|
ReplaceUses(SDValue(N, 0), Chain);
|
2009-11-19 14:06:13 +08:00
|
|
|
return Chain.getNode();
|
|
|
|
}
|
|
|
|
|
2007-06-06 15:42:06 +08:00
|
|
|
/// Select instructions not customized! Used for
|
|
|
|
/// expanded, promoted and normal instructions
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode* MipsDAGToDAGISel::Select(SDNode *Node) {
|
2007-06-06 15:42:06 +08:00
|
|
|
unsigned Opcode = Node->getOpcode();
|
2009-02-05 07:02:30 +08:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
// Dump information about the Node being selected
|
2010-03-02 14:34:30 +08:00
|
|
|
DEBUG(errs() << "Selecting: "; Node->dump(CurDAG); errs() << "\n");
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
// If we have a custom node, we already have selected!
|
2008-07-18 03:10:17 +08:00
|
|
|
if (Node->isMachineOpcode()) {
|
2010-03-02 14:34:30 +08:00
|
|
|
DEBUG(errs() << "== "; Node->dump(CurDAG); errs() << "\n");
|
2007-06-06 15:42:06 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2011-03-05 01:51:39 +08:00
|
|
|
// Instruction Selection not handled by the auto-generated
|
2007-09-25 04:15:11 +08:00
|
|
|
// tablegen selection should be handled here.
|
2011-03-05 01:51:39 +08:00
|
|
|
///
|
2007-06-06 15:42:06 +08:00
|
|
|
switch(Opcode) {
|
|
|
|
default: break;
|
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
case ISD::SUBE:
|
2008-06-06 08:58:26 +08:00
|
|
|
case ISD::ADDE: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue InFlag = Node->getOperand(2), CmpLHS;
|
2010-12-23 08:58:24 +08:00
|
|
|
unsigned Opc = InFlag.getOpcode(); (void)Opc;
|
2011-03-05 01:51:39 +08:00
|
|
|
assert(((Opc == ISD::ADDC || Opc == ISD::ADDE) ||
|
|
|
|
(Opc == ISD::SUBC || Opc == ISD::SUBE)) &&
|
2008-06-06 14:37:31 +08:00
|
|
|
"(ADD|SUB)E flag operand must come from (ADD|SUB)C/E insn");
|
|
|
|
|
2008-12-15 05:38:24 +08:00
|
|
|
unsigned MOp;
|
2008-06-06 14:37:31 +08:00
|
|
|
if (Opcode == ISD::ADDE) {
|
|
|
|
CmpLHS = InFlag.getValue(0);
|
|
|
|
MOp = Mips::ADDu;
|
2011-03-05 01:51:39 +08:00
|
|
|
} else {
|
2008-06-06 14:37:31 +08:00
|
|
|
CmpLHS = InFlag.getOperand(0);
|
|
|
|
MOp = Mips::SUBu;
|
|
|
|
}
|
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Ops[] = { CmpLHS, InFlag.getOperand(1) };
|
2008-06-06 08:58:26 +08:00
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue LHS = Node->getOperand(0);
|
|
|
|
SDValue RHS = Node->getOperand(1);
|
2008-06-06 08:58:26 +08:00
|
|
|
|
2009-08-11 06:56:29 +08:00
|
|
|
EVT VT = LHS.getValueType();
|
2009-09-26 02:54:59 +08:00
|
|
|
SDNode *Carry = CurDAG->getMachineNode(Mips::SLTu, dl, VT, Ops, 2);
|
2011-03-05 01:51:39 +08:00
|
|
|
SDNode *AddCarry = CurDAG->getMachineNode(Mips::ADDu, dl, VT,
|
2009-09-26 02:54:59 +08:00
|
|
|
SDValue(Carry,0), RHS);
|
2008-06-06 08:58:26 +08:00
|
|
|
|
2010-12-21 10:38:05 +08:00
|
|
|
return CurDAG->SelectNodeTo(Node, MOp, VT, MVT::Glue,
|
2008-07-28 05:46:04 +08:00
|
|
|
LHS, SDValue(AddCarry,0));
|
2008-06-06 08:58:26 +08:00
|
|
|
}
|
|
|
|
|
2011-06-08 03:03:14 +08:00
|
|
|
/// Mul with two results
|
2008-06-06 14:37:31 +08:00
|
|
|
case ISD::SMUL_LOHI:
|
|
|
|
case ISD::UMUL_LOHI: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue Op1 = Node->getOperand(0);
|
|
|
|
SDValue Op2 = Node->getOperand(1);
|
2008-06-06 08:58:26 +08:00
|
|
|
|
2008-06-06 14:37:31 +08:00
|
|
|
unsigned Op;
|
2011-03-05 05:03:24 +08:00
|
|
|
Op = (Opcode == ISD::UMUL_LOHI ? Mips::MULTu : Mips::MULT);
|
2008-06-06 08:58:26 +08:00
|
|
|
|
2011-03-05 05:03:24 +08:00
|
|
|
SDNode *Mul = CurDAG->getMachineNode(Op, dl, MVT::Glue, Op1, Op2);
|
2008-06-06 08:58:26 +08:00
|
|
|
|
2011-03-05 05:03:24 +08:00
|
|
|
SDValue InFlag = SDValue(Mul, 0);
|
2011-03-05 01:51:39 +08:00
|
|
|
SDNode *Lo = CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32,
|
2010-12-21 10:38:05 +08:00
|
|
|
MVT::Glue, InFlag);
|
2008-07-28 05:46:04 +08:00
|
|
|
InFlag = SDValue(Lo,1);
|
2009-09-26 02:54:59 +08:00
|
|
|
SDNode *Hi = CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
|
2008-06-06 14:37:31 +08:00
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
if (!SDValue(Node, 0).use_empty())
|
2010-01-05 09:24:18 +08:00
|
|
|
ReplaceUses(SDValue(Node, 0), SDValue(Lo,0));
|
2008-06-06 14:37:31 +08:00
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
if (!SDValue(Node, 1).use_empty())
|
2010-01-05 09:24:18 +08:00
|
|
|
ReplaceUses(SDValue(Node, 1), SDValue(Hi,0));
|
2008-06-06 14:37:31 +08:00
|
|
|
|
|
|
|
return NULL;
|
2008-06-06 08:58:26 +08:00
|
|
|
}
|
|
|
|
|
2008-06-06 14:37:31 +08:00
|
|
|
/// Special Muls
|
2011-03-05 01:51:39 +08:00
|
|
|
case ISD::MUL:
|
2010-11-12 08:38:32 +08:00
|
|
|
if (Subtarget.isMips32())
|
|
|
|
break;
|
2007-06-06 15:42:06 +08:00
|
|
|
case ISD::MULHS:
|
|
|
|
case ISD::MULHU: {
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue MulOp1 = Node->getOperand(0);
|
|
|
|
SDValue MulOp2 = Node->getOperand(1);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
|
|
|
unsigned MulOp = (Opcode == ISD::MULHU ? Mips::MULTu : Mips::MULT);
|
2011-03-05 01:51:39 +08:00
|
|
|
SDNode *MulNode = CurDAG->getMachineNode(MulOp, dl,
|
2010-12-21 10:38:05 +08:00
|
|
|
MVT::Glue, MulOp1, MulOp2);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2008-07-28 05:46:04 +08:00
|
|
|
SDValue InFlag = SDValue(MulNode, 0);
|
2008-06-06 14:37:31 +08:00
|
|
|
|
2010-02-01 20:16:39 +08:00
|
|
|
if (Opcode == ISD::MUL)
|
2009-09-26 02:54:59 +08:00
|
|
|
return CurDAG->getMachineNode(Mips::MFLO, dl, MVT::i32, InFlag);
|
2008-06-06 14:37:31 +08:00
|
|
|
else
|
2009-09-26 02:54:59 +08:00
|
|
|
return CurDAG->getMachineNode(Mips::MFHI, dl, MVT::i32, InFlag);
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
2007-11-13 03:49:57 +08:00
|
|
|
// Get target GOT address.
|
2009-06-04 04:30:14 +08:00
|
|
|
case ISD::GLOBAL_OFFSET_TABLE:
|
|
|
|
return getGlobalBaseReg();
|
2007-11-13 03:49:57 +08:00
|
|
|
|
2009-11-14 02:49:59 +08:00
|
|
|
case ISD::ConstantFP: {
|
2010-01-05 09:24:18 +08:00
|
|
|
ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(Node);
|
2011-03-05 01:51:39 +08:00
|
|
|
if (Node->getValueType(0) == MVT::f64 && CN->isExactlyValue(+0.0)) {
|
|
|
|
SDValue Zero = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
|
2010-01-19 20:53:04 +08:00
|
|
|
Mips::ZERO, MVT::i32);
|
|
|
|
SDValue Undef = SDValue(
|
2010-02-10 03:54:29 +08:00
|
|
|
CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, dl, MVT::f64), 0);
|
2010-01-19 20:53:04 +08:00
|
|
|
SDNode *MTC = CurDAG->getMachineNode(Mips::MTC1, dl, MVT::f32, Zero);
|
2011-03-05 01:51:39 +08:00
|
|
|
SDValue I0 = CurDAG->getTargetInsertSubreg(Mips::sub_fpeven, dl,
|
2010-01-19 20:53:04 +08:00
|
|
|
MVT::f64, Undef, SDValue(MTC, 0));
|
2011-03-05 01:51:39 +08:00
|
|
|
SDValue I1 = CurDAG->getTargetInsertSubreg(Mips::sub_fpodd, dl,
|
2010-01-19 20:53:04 +08:00
|
|
|
MVT::f64, I0, SDValue(MTC, 0));
|
|
|
|
ReplaceUses(SDValue(Node, 0), I1);
|
|
|
|
return I1.getNode();
|
2009-11-14 02:49:59 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-19 14:06:13 +08:00
|
|
|
case ISD::LOAD:
|
2010-01-05 09:24:18 +08:00
|
|
|
if (SDNode *ResNode = SelectLoadFp64(Node))
|
2009-11-19 14:06:13 +08:00
|
|
|
return ResNode;
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ISD::STORE:
|
2010-01-05 09:24:18 +08:00
|
|
|
if (SDNode *ResNode = SelectStoreFp64(Node))
|
2009-11-19 14:06:13 +08:00
|
|
|
return ResNode;
|
|
|
|
// Other cases are autogenerated.
|
|
|
|
break;
|
2011-05-31 10:53:58 +08:00
|
|
|
|
|
|
|
case MipsISD::ThreadPointer: {
|
|
|
|
unsigned SrcReg = Mips::HWR29;
|
|
|
|
unsigned DestReg = Mips::V1;
|
|
|
|
SDNode *Rdhwr = CurDAG->getMachineNode(Mips::RDHWR, Node->getDebugLoc(),
|
|
|
|
Node->getValueType(0), CurDAG->getRegister(SrcReg, MVT::i32));
|
|
|
|
SDValue Chain = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, DestReg,
|
|
|
|
SDValue(Rdhwr, 0));
|
|
|
|
SDValue ResNode = CurDAG->getCopyFromReg(Chain, dl, DestReg, MVT::i32);
|
|
|
|
ReplaceUses(SDValue(Node, 0), ResNode);
|
|
|
|
return ResNode.getNode();
|
|
|
|
}
|
2007-06-06 15:42:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Select the default instruction
|
2010-01-05 09:24:18 +08:00
|
|
|
SDNode *ResNode = SelectCode(Node);
|
2007-06-06 15:42:06 +08:00
|
|
|
|
2010-03-02 14:34:30 +08:00
|
|
|
DEBUG(errs() << "=> ");
|
2010-01-05 09:24:18 +08:00
|
|
|
if (ResNode == NULL || ResNode == Node)
|
|
|
|
DEBUG(Node->dump(CurDAG));
|
2007-06-06 15:42:06 +08:00
|
|
|
else
|
|
|
|
DEBUG(ResNode->dump(CurDAG));
|
2009-08-23 14:49:22 +08:00
|
|
|
DEBUG(errs() << "\n");
|
2007-06-06 15:42:06 +08:00
|
|
|
return ResNode;
|
|
|
|
}
|
|
|
|
|
2011-06-21 08:40:49 +08:00
|
|
|
bool MipsDAGToDAGISel::
|
|
|
|
SelectInlineAsmMemoryOperand(const SDValue &Op, char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
assert(ConstraintCode == 'm' && "unexpected asm memory constraint");
|
|
|
|
OutOps.push_back(Op);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-05 01:51:39 +08:00
|
|
|
/// createMipsISelDag - This pass converts a legalized DAG into a
|
2007-06-06 15:42:06 +08:00
|
|
|
/// MIPS-specific DAG, ready for instruction scheduling.
|
|
|
|
FunctionPass *llvm::createMipsISelDag(MipsTargetMachine &TM) {
|
|
|
|
return new MipsDAGToDAGISel(TM);
|
|
|
|
}
|