2007-12-29 20:36:04 +00:00
|
|
|
//===-- SPUISelDAGToDAG.cpp - CellSPU pattern matching inst selector ------===//
|
2007-12-04 22:23:35 +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-12-04 22:23:35 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines a pattern matching instruction selector for the Cell SPU,
|
|
|
|
// converting from a legalized dag to a SPU-target dag.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SPU.h"
|
|
|
|
#include "SPUTargetMachine.h"
|
|
|
|
#include "SPUHazardRecognizers.h"
|
2011-01-10 12:39:04 +00:00
|
|
|
#include "SPUFrameLowering.h"
|
2009-01-15 04:41:47 +00:00
|
|
|
#include "SPUTargetMachine.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/GlobalValue.h"
|
|
|
|
#include "llvm/Intrinsics.h"
|
2009-07-15 21:51:10 +00:00
|
|
|
#include "llvm/LLVMContext.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
//! ConstantSDNode predicate for i32 sign-extended, 10-bit immediates
|
|
|
|
bool
|
|
|
|
isI32IntS10Immediate(ConstantSDNode *CN)
|
|
|
|
{
|
2010-03-29 19:07:58 +00:00
|
|
|
return isInt<10>(CN->getSExtValue());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 22:32:34 +00:00
|
|
|
//! ConstantSDNode predicate for i32 unsigned 10-bit immediate values
|
|
|
|
bool
|
|
|
|
isI32IntU10Immediate(ConstantSDNode *CN)
|
|
|
|
{
|
2010-03-29 21:13:41 +00:00
|
|
|
return isUInt<10>(CN->getSExtValue());
|
2007-12-17 22:32:34 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
//! ConstantSDNode predicate for i16 sign-extended, 10-bit immediate values
|
|
|
|
bool
|
|
|
|
isI16IntS10Immediate(ConstantSDNode *CN)
|
|
|
|
{
|
2010-03-29 19:07:58 +00:00
|
|
|
return isInt<10>(CN->getSExtValue());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2007-12-15 00:38:50 +00:00
|
|
|
//! ConstantSDNode predicate for i16 unsigned 10-bit immediate values
|
|
|
|
bool
|
|
|
|
isI16IntU10Immediate(ConstantSDNode *CN)
|
|
|
|
{
|
2010-03-29 21:13:41 +00:00
|
|
|
return isUInt<10>((short) CN->getZExtValue());
|
2007-12-15 00:38:50 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
//! ConstantSDNode predicate for signed 16-bit values
|
|
|
|
/*!
|
|
|
|
\arg CN The constant SelectionDAG node holding the value
|
|
|
|
\arg Imm The returned 16-bit value, if returning true
|
|
|
|
|
|
|
|
This predicate tests the value in \a CN to see whether it can be
|
|
|
|
represented as a 16-bit, sign-extended quantity. Returns true if
|
|
|
|
this is the case.
|
|
|
|
*/
|
|
|
|
bool
|
|
|
|
isIntS16Immediate(ConstantSDNode *CN, short &Imm)
|
|
|
|
{
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT vt = CN->getValueType(0);
|
2008-09-12 16:56:44 +00:00
|
|
|
Imm = (short) CN->getZExtValue();
|
2009-08-11 20:47:22 +00:00
|
|
|
if (vt.getSimpleVT() >= MVT::i1 && vt.getSimpleVT() <= MVT::i16) {
|
2007-12-04 22:23:35 +00:00
|
|
|
return true;
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (vt == MVT::i32) {
|
2008-09-12 16:56:44 +00:00
|
|
|
int32_t i_val = (int32_t) CN->getZExtValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
short s_val = (short) i_val;
|
|
|
|
return i_val == s_val;
|
|
|
|
} else {
|
2008-09-12 16:56:44 +00:00
|
|
|
int64_t i_val = (int64_t) CN->getZExtValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
short s_val = (short) i_val;
|
|
|
|
return i_val == s_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! ConstantFPSDNode predicate for representing floats as 16-bit sign ext.
|
|
|
|
static bool
|
|
|
|
isFPS16Immediate(ConstantFPSDNode *FPN, short &Imm)
|
|
|
|
{
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT vt = FPN->getValueType(0);
|
2009-08-11 20:47:22 +00:00
|
|
|
if (vt == MVT::f32) {
|
2007-12-22 22:45:38 +00:00
|
|
|
int val = FloatToBits(FPN->getValueAPF().convertToFloat());
|
2007-12-04 22:23:35 +00:00
|
|
|
int sval = (int) ((val << 16) >> 16);
|
|
|
|
Imm = (short) val;
|
|
|
|
return val == sval;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
//! Generate the carry-generate shuffle mask.
|
|
|
|
SDValue getCarryGenerateShufMask(SelectionDAG &DAG, DebugLoc dl) {
|
|
|
|
SmallVector<SDValue, 16 > ShufBytes;
|
2008-05-13 00:00:25 +00:00
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
// Create the shuffle mask for "rotating" the borrow up one register slot
|
|
|
|
// once the borrow is generated.
|
2009-08-11 20:47:22 +00:00
|
|
|
ShufBytes.push_back(DAG.getConstant(0x04050607, MVT::i32));
|
|
|
|
ShufBytes.push_back(DAG.getConstant(0x80808080, MVT::i32));
|
|
|
|
ShufBytes.push_back(DAG.getConstant(0x0c0d0e0f, MVT::i32));
|
|
|
|
ShufBytes.push_back(DAG.getConstant(0x80808080, MVT::i32));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32,
|
2009-03-17 01:15:45 +00:00
|
|
|
&ShufBytes[0], ShufBytes.size());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
//! Generate the borrow-generate shuffle mask
|
|
|
|
SDValue getBorrowGenerateShufMask(SelectionDAG &DAG, DebugLoc dl) {
|
|
|
|
SmallVector<SDValue, 16 > ShufBytes;
|
|
|
|
|
|
|
|
// Create the shuffle mask for "rotating" the borrow up one register slot
|
|
|
|
// once the borrow is generated.
|
2009-08-11 20:47:22 +00:00
|
|
|
ShufBytes.push_back(DAG.getConstant(0x04050607, MVT::i32));
|
|
|
|
ShufBytes.push_back(DAG.getConstant(0xc0c0c0c0, MVT::i32));
|
|
|
|
ShufBytes.push_back(DAG.getConstant(0x0c0d0e0f, MVT::i32));
|
|
|
|
ShufBytes.push_back(DAG.getConstant(0xc0c0c0c0, MVT::i32));
|
2009-03-17 01:15:45 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32,
|
2009-03-17 01:15:45 +00:00
|
|
|
&ShufBytes[0], ShufBytes.size());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
//===------------------------------------------------------------------===//
|
|
|
|
/// SPUDAGToDAGISel - Cell SPU-specific code to select SPU machine
|
|
|
|
/// instructions for SelectionDAG operations.
|
|
|
|
///
|
|
|
|
class SPUDAGToDAGISel :
|
|
|
|
public SelectionDAGISel
|
|
|
|
{
|
2010-04-17 15:26:15 +00:00
|
|
|
const SPUTargetMachine &TM;
|
|
|
|
const SPUTargetLowering &SPUtli;
|
2009-03-17 01:15:45 +00:00
|
|
|
unsigned GlobalBaseReg;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit SPUDAGToDAGISel(SPUTargetMachine &tm) :
|
|
|
|
SelectionDAGISel(tm),
|
|
|
|
TM(tm),
|
|
|
|
SPUtli(*tm.getTargetLowering())
|
|
|
|
{ }
|
|
|
|
|
2009-07-31 18:16:33 +00:00
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF) {
|
2009-03-17 01:15:45 +00:00
|
|
|
// Make sure we re-emit a set of the global base reg if necessary
|
|
|
|
GlobalBaseReg = 0;
|
2009-07-31 18:16:33 +00:00
|
|
|
SelectionDAGISel::runOnMachineFunction(MF);
|
2009-03-17 01:15:45 +00:00
|
|
|
return true;
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
/// getI32Imm - Return a target constant with the specified value, of type
|
|
|
|
/// i32.
|
|
|
|
inline SDValue getI32Imm(uint32_t Imm) {
|
2009-08-11 20:47:22 +00:00
|
|
|
return CurDAG->getTargetConstant(Imm, MVT::i32);
|
2009-01-15 04:41:47 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
/// getSmallIPtrImm - Return a target constant of pointer type.
|
|
|
|
inline SDValue getSmallIPtrImm(unsigned Imm) {
|
|
|
|
return CurDAG->getTargetConstant(Imm, SPUtli.getPointerTy());
|
2010-09-04 18:12:00 +00:00
|
|
|
}
|
2009-03-17 01:15:45 +00:00
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *emitBuildVector(SDNode *bvNode) {
|
|
|
|
EVT vecVT = bvNode->getValueType(0);
|
2009-03-17 01:15:45 +00:00
|
|
|
DebugLoc dl = bvNode->getDebugLoc();
|
|
|
|
|
|
|
|
// Check to see if this vector can be represented as a CellSPU immediate
|
|
|
|
// constant by invoking all of the instruction selection predicates:
|
2009-08-11 20:47:22 +00:00
|
|
|
if (((vecVT == MVT::v8i16) &&
|
|
|
|
(SPU::get_vec_i16imm(bvNode, *CurDAG, MVT::i16).getNode() != 0)) ||
|
|
|
|
((vecVT == MVT::v4i32) &&
|
|
|
|
((SPU::get_vec_i16imm(bvNode, *CurDAG, MVT::i32).getNode() != 0) ||
|
|
|
|
(SPU::get_ILHUvec_imm(bvNode, *CurDAG, MVT::i32).getNode() != 0) ||
|
|
|
|
(SPU::get_vec_u18imm(bvNode, *CurDAG, MVT::i32).getNode() != 0) ||
|
2009-03-17 01:15:45 +00:00
|
|
|
(SPU::get_v4i32_imm(bvNode, *CurDAG).getNode() != 0))) ||
|
2009-08-11 20:47:22 +00:00
|
|
|
((vecVT == MVT::v2i64) &&
|
|
|
|
((SPU::get_vec_i16imm(bvNode, *CurDAG, MVT::i64).getNode() != 0) ||
|
|
|
|
(SPU::get_ILHUvec_imm(bvNode, *CurDAG, MVT::i64).getNode() != 0) ||
|
2010-02-23 05:30:43 +00:00
|
|
|
(SPU::get_vec_u18imm(bvNode, *CurDAG, MVT::i64).getNode() != 0)))) {
|
|
|
|
HandleSDNode Dummy(SDValue(bvNode, 0));
|
|
|
|
if (SDNode *N = Select(bvNode))
|
|
|
|
return N;
|
|
|
|
return Dummy.getValue().getNode();
|
|
|
|
}
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
// No, need to emit a constant pool spill:
|
|
|
|
std::vector<Constant*> CV;
|
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
for (size_t i = 0; i < bvNode->getNumOperands(); ++i) {
|
2010-04-17 15:31:16 +00:00
|
|
|
ConstantSDNode *V = cast<ConstantSDNode > (bvNode->getOperand(i));
|
2010-02-23 05:30:43 +00:00
|
|
|
CV.push_back(const_cast<ConstantInt *>(V->getConstantIntValue()));
|
2009-03-17 01:15:45 +00:00
|
|
|
}
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const Constant *CP = ConstantVector::get(CV);
|
2009-03-17 01:15:45 +00:00
|
|
|
SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy());
|
|
|
|
unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
|
|
|
|
SDValue CGPoolOffset =
|
2010-04-17 15:26:15 +00:00
|
|
|
SPU::LowerConstantPool(CPIdx, *CurDAG, TM);
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
HandleSDNode Dummy(CurDAG->getLoad(vecVT, dl,
|
|
|
|
CurDAG->getEntryNode(), CGPoolOffset,
|
2010-09-21 06:22:23 +00:00
|
|
|
MachinePointerInfo::getConstantPool(),
|
2011-11-08 18:42:53 +00:00
|
|
|
false, false, false, Alignment));
|
2010-02-23 05:30:43 +00:00
|
|
|
CurDAG->ReplaceAllUsesWith(SDValue(bvNode, 0), Dummy.getValue());
|
|
|
|
if (SDNode *N = SelectCode(Dummy.getValue().getNode()))
|
|
|
|
return N;
|
|
|
|
return Dummy.getValue().getNode();
|
2009-03-17 01:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Select - Convert the specified operand from a target-independent to a
|
|
|
|
/// target-specific node if it hasn't already been changed.
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *Select(SDNode *N);
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
//! Emit the instruction sequence for i64 shl
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *SelectSHLi64(SDNode *N, EVT OpVT);
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
//! Emit the instruction sequence for i64 srl
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *SelectSRLi64(SDNode *N, EVT OpVT);
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
//! Emit the instruction sequence for i64 sra
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *SelectSRAi64(SDNode *N, EVT OpVT);
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
//! Emit the necessary sequence for loading i64 constants:
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *SelectI64Constant(SDNode *N, EVT OpVT, DebugLoc dl);
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
//! Alternate instruction emit sequence for loading i64 constants
|
2009-08-10 22:56:29 +00:00
|
|
|
SDNode *SelectI64Constant(uint64_t i64const, EVT OpVT, DebugLoc dl);
|
2009-03-17 01:15:45 +00:00
|
|
|
|
|
|
|
//! Returns true if the address N is an A-form (local store) address
|
2010-01-05 01:24:18 +00:00
|
|
|
bool SelectAFormAddr(SDNode *Op, SDValue N, SDValue &Base,
|
2009-03-17 01:15:45 +00:00
|
|
|
SDValue &Index);
|
|
|
|
|
|
|
|
//! D-form address predicate
|
2010-01-05 01:24:18 +00:00
|
|
|
bool SelectDFormAddr(SDNode *Op, SDValue N, SDValue &Base,
|
2009-03-17 01:15:45 +00:00
|
|
|
SDValue &Index);
|
|
|
|
|
|
|
|
/// Alternate D-form address using i7 offset predicate
|
2010-01-05 01:24:18 +00:00
|
|
|
bool SelectDForm2Addr(SDNode *Op, SDValue N, SDValue &Disp,
|
2009-03-17 01:15:45 +00:00
|
|
|
SDValue &Base);
|
|
|
|
|
|
|
|
/// D-form address selection workhorse
|
2010-01-05 01:24:18 +00:00
|
|
|
bool DFormAddressPredicate(SDNode *Op, SDValue N, SDValue &Disp,
|
2009-03-17 01:15:45 +00:00
|
|
|
SDValue &Base, int minOffset, int maxOffset);
|
|
|
|
|
|
|
|
//! Address predicate if N can be expressed as an indexed [r+r] operation.
|
2010-01-05 01:24:18 +00:00
|
|
|
bool SelectXFormAddr(SDNode *Op, SDValue N, SDValue &Base,
|
2009-03-17 01:15:45 +00:00
|
|
|
SDValue &Index);
|
|
|
|
|
|
|
|
/// SelectInlineAsmMemoryOperand - Implement addressing mode selection for
|
|
|
|
/// inline asm expressions.
|
|
|
|
virtual bool SelectInlineAsmMemoryOperand(const SDValue &Op,
|
|
|
|
char ConstraintCode,
|
|
|
|
std::vector<SDValue> &OutOps) {
|
|
|
|
SDValue Op0, Op1;
|
|
|
|
switch (ConstraintCode) {
|
|
|
|
default: return true;
|
|
|
|
case 'm': // memory
|
2010-01-05 01:24:18 +00:00
|
|
|
if (!SelectDFormAddr(Op.getNode(), Op, Op0, Op1)
|
|
|
|
&& !SelectAFormAddr(Op.getNode(), Op, Op0, Op1))
|
|
|
|
SelectXFormAddr(Op.getNode(), Op, Op0, Op1);
|
2009-03-17 01:15:45 +00:00
|
|
|
break;
|
|
|
|
case 'o': // offsetable
|
2010-01-05 01:24:18 +00:00
|
|
|
if (!SelectDFormAddr(Op.getNode(), Op, Op0, Op1)
|
|
|
|
&& !SelectAFormAddr(Op.getNode(), Op, Op0, Op1)) {
|
2009-03-17 01:15:45 +00:00
|
|
|
Op0 = Op;
|
|
|
|
Op1 = getSmallIPtrImm(0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'v': // not offsetable
|
2007-12-04 22:23:35 +00:00
|
|
|
#if 1
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("InlineAsmMemoryOperand 'v' constraint not handled.");
|
2007-12-04 22:23:35 +00:00
|
|
|
#else
|
2009-03-17 01:15:45 +00:00
|
|
|
SelectAddrIdxOnly(Op, Op, Op0, Op1);
|
2007-12-04 22:23:35 +00:00
|
|
|
#endif
|
2009-03-17 01:15:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
OutOps.push_back(Op0);
|
|
|
|
OutOps.push_back(Op1);
|
|
|
|
return false;
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Cell SPU DAG->DAG Pattern Instruction Selection";
|
|
|
|
}
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2010-09-16 12:29:33 +00:00
|
|
|
private:
|
2010-11-23 03:31:01 +00:00
|
|
|
SDValue getRC( MVT );
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-03-17 01:15:45 +00:00
|
|
|
// Include the pieces autogenerated from the target description.
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "SPUGenDAGISel.inc"
|
2009-03-17 01:15:45 +00:00
|
|
|
};
|
2008-05-13 00:00:25 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
/*!
|
2009-01-26 22:33:37 +00:00
|
|
|
\arg Op The ISD instruction operand
|
2007-12-04 22:23:35 +00:00
|
|
|
\arg N The address to be tested
|
|
|
|
\arg Base The base address
|
|
|
|
\arg Index The base address index
|
|
|
|
*/
|
|
|
|
bool
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectAFormAddr(SDNode *Op, SDValue N, SDValue &Base,
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue &Index) {
|
2007-12-04 22:23:35 +00:00
|
|
|
// These match the addr256k operand type:
|
2009-08-11 20:47:22 +00:00
|
|
|
EVT OffsVT = MVT::i16;
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Zero = CurDAG->getTargetConstant(0, OffsVT);
|
2011-03-04 12:00:11 +00:00
|
|
|
int64_t val;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
switch (N.getOpcode()) {
|
|
|
|
case ISD::Constant:
|
2011-03-04 12:00:11 +00:00
|
|
|
val = dyn_cast<ConstantSDNode>(N.getNode())->getSExtValue();
|
|
|
|
Base = CurDAG->getTargetConstant( val , MVT::i32);
|
|
|
|
Index = Zero;
|
|
|
|
return true; break;
|
2008-01-11 02:53:15 +00:00
|
|
|
case ISD::ConstantPool:
|
|
|
|
case ISD::GlobalAddress:
|
2011-03-04 12:00:11 +00:00
|
|
|
report_fatal_error("SPU SelectAFormAddr: Pool/Global not lowered.");
|
2008-01-11 02:53:15 +00:00
|
|
|
/*NOTREACHED*/
|
|
|
|
|
2008-01-29 02:16:57 +00:00
|
|
|
case ISD::TargetConstant:
|
2008-01-11 02:53:15 +00:00
|
|
|
case ISD::TargetGlobalAddress:
|
2008-01-29 02:16:57 +00:00
|
|
|
case ISD::TargetJumpTable:
|
2010-04-07 22:58:41 +00:00
|
|
|
report_fatal_error("SPUSelectAFormAddr: Target Constant/Pool/Global "
|
2009-07-08 20:53:28 +00:00
|
|
|
"not wrapped as A-form address.");
|
2008-01-29 02:16:57 +00:00
|
|
|
/*NOTREACHED*/
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
case SPUISD::AFormAddr:
|
2008-01-29 02:16:57 +00:00
|
|
|
// Just load from memory if there's only a single use of the location,
|
|
|
|
// otherwise, this will get handled below with D-form offset addresses
|
|
|
|
if (N.hasOneUse()) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op0 = N.getOperand(0);
|
2008-01-29 02:16:57 +00:00
|
|
|
switch (Op0.getOpcode()) {
|
|
|
|
case ISD::TargetConstantPool:
|
|
|
|
case ISD::TargetJumpTable:
|
|
|
|
Base = Op0;
|
|
|
|
Index = Zero;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case ISD::TargetGlobalAddress: {
|
|
|
|
GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op0);
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalValue *GV = GSDN->getGlobal();
|
2008-01-29 02:16:57 +00:00
|
|
|
if (GV->getAlignment() == 16) {
|
|
|
|
Base = Op0;
|
|
|
|
Index = Zero;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
bool
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectDForm2Addr(SDNode *Op, SDValue N, SDValue &Disp,
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue &Base) {
|
2008-04-30 00:30:08 +00:00
|
|
|
const int minDForm2Offset = -(1 << 7);
|
|
|
|
const int maxDForm2Offset = (1 << 7) - 1;
|
|
|
|
return DFormAddressPredicate(Op, N, Disp, Base, minDForm2Offset,
|
|
|
|
maxDForm2Offset);
|
2008-01-30 02:55:46 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
/*!
|
|
|
|
\arg Op The ISD instruction (ignored)
|
|
|
|
\arg N The address to be tested
|
|
|
|
\arg Base Base address register/pointer
|
|
|
|
\arg Index Base address index
|
|
|
|
|
|
|
|
Examine the input address by a base register plus a signed 10-bit
|
|
|
|
displacement, [r+I10] (D-form address).
|
|
|
|
|
|
|
|
\return true if \a N is a D-form address with \a Base and \a Index set
|
2008-07-27 21:46:04 +00:00
|
|
|
to non-empty SDValue instances.
|
2007-12-04 22:23:35 +00:00
|
|
|
*/
|
|
|
|
bool
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectDFormAddr(SDNode *Op, SDValue N, SDValue &Base,
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue &Index) {
|
2008-01-30 02:55:46 +00:00
|
|
|
return DFormAddressPredicate(Op, N, Base, Index,
|
2011-01-10 12:39:04 +00:00
|
|
|
SPUFrameLowering::minFrameOffset(),
|
|
|
|
SPUFrameLowering::maxFrameOffset());
|
2008-01-30 02:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::DFormAddressPredicate(SDNode *Op, SDValue N, SDValue &Base,
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue &Index, int minOffset,
|
2008-01-30 02:55:46 +00:00
|
|
|
int maxOffset) {
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned Opc = N.getOpcode();
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT PtrTy = SPUtli.getPointerTy();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-01-29 02:16:57 +00:00
|
|
|
if (Opc == ISD::FrameIndex) {
|
|
|
|
// Stack frame index must be less than 512 (divided by 16):
|
2010-04-17 15:31:16 +00:00
|
|
|
FrameIndexSDNode *FIN = cast<FrameIndexSDNode>(N);
|
2008-04-30 00:30:08 +00:00
|
|
|
int FI = int(FIN->getIndex());
|
2009-08-23 07:05:07 +00:00
|
|
|
DEBUG(errs() << "SelectDFormAddr: ISD::FrameIndex = "
|
2008-04-30 00:30:08 +00:00
|
|
|
<< FI << "\n");
|
2011-01-10 12:39:04 +00:00
|
|
|
if (SPUFrameLowering::FItoStackOffset(FI) < maxOffset) {
|
2007-12-04 22:23:35 +00:00
|
|
|
Base = CurDAG->getTargetConstant(0, PtrTy);
|
2008-04-30 00:30:08 +00:00
|
|
|
Index = CurDAG->getTargetFrameIndex(FI, PtrTy);
|
2007-12-04 22:23:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (Opc == ISD::ADD) {
|
|
|
|
// Generated by getelementptr
|
2008-07-27 21:46:04 +00:00
|
|
|
const SDValue Op0 = N.getOperand(0);
|
|
|
|
const SDValue Op1 = N.getOperand(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-01-29 02:16:57 +00:00
|
|
|
if ((Op0.getOpcode() == SPUISD::Hi && Op1.getOpcode() == SPUISD::Lo)
|
|
|
|
|| (Op1.getOpcode() == SPUISD::Hi && Op0.getOpcode() == SPUISD::Lo)) {
|
|
|
|
Base = CurDAG->getTargetConstant(0, PtrTy);
|
|
|
|
Index = N;
|
|
|
|
return true;
|
|
|
|
} else if (Op1.getOpcode() == ISD::Constant
|
|
|
|
|| Op1.getOpcode() == ISD::TargetConstant) {
|
2010-04-17 15:31:16 +00:00
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Op1);
|
2008-09-26 21:54:37 +00:00
|
|
|
int32_t offset = int32_t(CN->getSExtValue());
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-01-29 02:16:57 +00:00
|
|
|
if (Op0.getOpcode() == ISD::FrameIndex) {
|
2010-04-17 15:31:16 +00:00
|
|
|
FrameIndexSDNode *FIN = cast<FrameIndexSDNode>(Op0);
|
2008-04-30 00:30:08 +00:00
|
|
|
int FI = int(FIN->getIndex());
|
2009-08-23 07:05:07 +00:00
|
|
|
DEBUG(errs() << "SelectDFormAddr: ISD::ADD offset = " << offset
|
2008-04-30 00:30:08 +00:00
|
|
|
<< " frame index = " << FI << "\n");
|
2008-01-11 02:53:15 +00:00
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
if (SPUFrameLowering::FItoStackOffset(FI) < maxOffset) {
|
2008-01-11 02:53:15 +00:00
|
|
|
Base = CurDAG->getTargetConstant(offset, PtrTy);
|
2008-04-30 00:30:08 +00:00
|
|
|
Index = CurDAG->getTargetFrameIndex(FI, PtrTy);
|
2008-01-11 02:53:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-01-30 02:55:46 +00:00
|
|
|
} else if (offset > minOffset && offset < maxOffset) {
|
2008-01-11 02:53:15 +00:00
|
|
|
Base = CurDAG->getTargetConstant(offset, PtrTy);
|
2008-01-29 02:16:57 +00:00
|
|
|
Index = Op0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else if (Op0.getOpcode() == ISD::Constant
|
|
|
|
|| Op0.getOpcode() == ISD::TargetConstant) {
|
2010-04-17 15:31:16 +00:00
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Op0);
|
2008-09-26 21:54:37 +00:00
|
|
|
int32_t offset = int32_t(CN->getSExtValue());
|
2008-01-29 02:16:57 +00:00
|
|
|
|
|
|
|
if (Op1.getOpcode() == ISD::FrameIndex) {
|
2010-04-17 15:31:16 +00:00
|
|
|
FrameIndexSDNode *FIN = cast<FrameIndexSDNode>(Op1);
|
2008-04-30 00:30:08 +00:00
|
|
|
int FI = int(FIN->getIndex());
|
2009-08-23 07:05:07 +00:00
|
|
|
DEBUG(errs() << "SelectDFormAddr: ISD::ADD offset = " << offset
|
2008-04-30 00:30:08 +00:00
|
|
|
<< " frame index = " << FI << "\n");
|
2008-01-29 02:16:57 +00:00
|
|
|
|
2011-01-10 12:39:04 +00:00
|
|
|
if (SPUFrameLowering::FItoStackOffset(FI) < maxOffset) {
|
2008-01-29 02:16:57 +00:00
|
|
|
Base = CurDAG->getTargetConstant(offset, PtrTy);
|
2008-04-30 00:30:08 +00:00
|
|
|
Index = CurDAG->getTargetFrameIndex(FI, PtrTy);
|
2008-01-11 02:53:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-01-30 02:55:46 +00:00
|
|
|
} else if (offset > minOffset && offset < maxOffset) {
|
2008-01-29 02:16:57 +00:00
|
|
|
Base = CurDAG->getTargetConstant(offset, PtrTy);
|
|
|
|
Index = Op1;
|
|
|
|
return true;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-01-11 21:01:19 +00:00
|
|
|
}
|
2008-01-29 02:16:57 +00:00
|
|
|
} else if (Opc == SPUISD::IndirectAddr) {
|
|
|
|
// Indirect with constant offset -> D-Form address
|
2008-07-27 21:46:04 +00:00
|
|
|
const SDValue Op0 = N.getOperand(0);
|
|
|
|
const SDValue Op1 = N.getOperand(1);
|
2008-01-29 02:16:57 +00:00
|
|
|
|
2008-01-30 02:55:46 +00:00
|
|
|
if (Op0.getOpcode() == SPUISD::Hi
|
|
|
|
&& Op1.getOpcode() == SPUISD::Lo) {
|
2008-01-29 02:16:57 +00:00
|
|
|
// (SPUindirect (SPUhi <arg>, 0), (SPUlo <arg>, 0))
|
2008-01-11 02:53:15 +00:00
|
|
|
Base = CurDAG->getTargetConstant(0, PtrTy);
|
2008-01-29 02:16:57 +00:00
|
|
|
Index = N;
|
2008-01-11 02:53:15 +00:00
|
|
|
return true;
|
2008-01-30 02:55:46 +00:00
|
|
|
} else if (isa<ConstantSDNode>(Op0) || isa<ConstantSDNode>(Op1)) {
|
|
|
|
int32_t offset = 0;
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue idxOp;
|
2008-01-30 02:55:46 +00:00
|
|
|
|
|
|
|
if (isa<ConstantSDNode>(Op1)) {
|
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Op1);
|
2008-09-26 21:54:37 +00:00
|
|
|
offset = int32_t(CN->getSExtValue());
|
2008-01-30 02:55:46 +00:00
|
|
|
idxOp = Op0;
|
|
|
|
} else if (isa<ConstantSDNode>(Op0)) {
|
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Op0);
|
2008-09-26 21:54:37 +00:00
|
|
|
offset = int32_t(CN->getSExtValue());
|
2008-01-30 02:55:46 +00:00
|
|
|
idxOp = Op1;
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
2008-01-30 02:55:46 +00:00
|
|
|
|
|
|
|
if (offset >= minOffset && offset <= maxOffset) {
|
|
|
|
Base = CurDAG->getTargetConstant(offset, PtrTy);
|
|
|
|
Index = idxOp;
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-11 02:53:15 +00:00
|
|
|
}
|
2008-01-29 02:16:57 +00:00
|
|
|
} else if (Opc == SPUISD::AFormAddr) {
|
|
|
|
Base = CurDAG->getTargetConstant(0, N.getValueType());
|
|
|
|
Index = N;
|
2008-01-17 20:38:41 +00:00
|
|
|
return true;
|
2008-01-30 02:55:46 +00:00
|
|
|
} else if (Opc == SPUISD::LDRESULT) {
|
|
|
|
Base = CurDAG->getTargetConstant(0, N.getValueType());
|
|
|
|
Index = N;
|
|
|
|
return true;
|
2010-11-23 03:31:01 +00:00
|
|
|
} else if (Opc == ISD::Register
|
|
|
|
||Opc == ISD::CopyFromReg
|
2010-08-04 13:59:48 +00:00
|
|
|
||Opc == ISD::UNDEF
|
|
|
|
||Opc == ISD::Constant) {
|
2010-01-05 01:24:18 +00:00
|
|
|
unsigned OpOpc = Op->getOpcode();
|
2008-11-21 02:56:16 +00:00
|
|
|
|
|
|
|
if (OpOpc == ISD::STORE || OpOpc == ISD::LOAD) {
|
|
|
|
// Direct load/store without getelementptr
|
2010-06-01 13:34:47 +00:00
|
|
|
SDValue Offs;
|
2008-11-21 02:56:16 +00:00
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
Offs = ((OpOpc == ISD::STORE) ? Op->getOperand(3) : Op->getOperand(2));
|
2008-11-21 02:56:16 +00:00
|
|
|
|
|
|
|
if (Offs.getOpcode() == ISD::Constant || Offs.getOpcode() == ISD::UNDEF) {
|
|
|
|
if (Offs.getOpcode() == ISD::UNDEF)
|
|
|
|
Offs = CurDAG->getTargetConstant(0, Offs.getValueType());
|
|
|
|
|
|
|
|
Base = Offs;
|
2010-06-01 13:34:47 +00:00
|
|
|
Index = N;
|
2008-11-21 02:56:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-12-10 00:15:19 +00:00
|
|
|
} else {
|
|
|
|
/* If otherwise unadorned, default to D-form address with 0 offset: */
|
|
|
|
if (Opc == ISD::CopyFromReg) {
|
2009-01-26 03:37:41 +00:00
|
|
|
Index = N.getOperand(1);
|
2008-12-10 00:15:19 +00:00
|
|
|
} else {
|
2009-01-26 03:37:41 +00:00
|
|
|
Index = N;
|
2008-12-10 00:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Base = CurDAG->getTargetConstant(0, Index.getValueType());
|
|
|
|
return true;
|
2008-11-21 02:56:16 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-11-21 02:56:16 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\arg Op The ISD instruction operand
|
|
|
|
\arg N The address operand
|
|
|
|
\arg Base The base pointer operand
|
|
|
|
\arg Index The offset/index operand
|
|
|
|
|
2008-11-21 02:56:16 +00:00
|
|
|
If the address \a N can be expressed as an A-form or D-form address, returns
|
|
|
|
false. Otherwise, creates two operands, Base and Index that will become the
|
|
|
|
(r)(r) X-form address.
|
2007-12-04 22:23:35 +00:00
|
|
|
*/
|
|
|
|
bool
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectXFormAddr(SDNode *Op, SDValue N, SDValue &Base,
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue &Index) {
|
2008-11-21 02:56:16 +00:00
|
|
|
if (!SelectAFormAddr(Op, N, Base, Index)
|
|
|
|
&& !SelectDFormAddr(Op, N, Base, Index)) {
|
2008-11-25 17:29:43 +00:00
|
|
|
// If the address is neither A-form or D-form, punt and use an X-form
|
|
|
|
// address:
|
2008-12-01 17:56:02 +00:00
|
|
|
Base = N.getOperand(1);
|
|
|
|
Index = N.getOperand(0);
|
2008-11-25 04:03:47 +00:00
|
|
|
return true;
|
2008-11-21 02:56:16 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-21 02:56:16 +00:00
|
|
|
return false;
|
2008-01-17 20:38:41 +00:00
|
|
|
}
|
|
|
|
|
2010-09-16 12:29:33 +00:00
|
|
|
/*!
|
2010-11-23 03:31:01 +00:00
|
|
|
Utility function to use with COPY_TO_REGCLASS instructions. Returns a SDValue
|
2010-09-16 12:29:33 +00:00
|
|
|
to be used as the last parameter of a
|
|
|
|
CurDAG->getMachineNode(COPY_TO_REGCLASS,..., ) function call
|
|
|
|
\arg VT the value type for which we want a register class
|
|
|
|
*/
|
|
|
|
SDValue SPUDAGToDAGISel::getRC( MVT VT ) {
|
|
|
|
switch( VT.SimpleTy ) {
|
2010-10-07 16:32:42 +00:00
|
|
|
case MVT::i8:
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getTargetConstant(SPU::R8CRegClass.getID(), MVT::i32);
|
|
|
|
break;
|
2010-10-07 16:32:42 +00:00
|
|
|
case MVT::i16:
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getTargetConstant(SPU::R16CRegClass.getID(), MVT::i32);
|
|
|
|
break;
|
2010-09-16 12:29:33 +00:00
|
|
|
case MVT::i32:
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getTargetConstant(SPU::R32CRegClass.getID(), MVT::i32);
|
|
|
|
break;
|
2010-10-07 16:32:42 +00:00
|
|
|
case MVT::f32:
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getTargetConstant(SPU::R32FPRegClass.getID(), MVT::i32);
|
|
|
|
break;
|
2010-09-16 12:29:33 +00:00
|
|
|
case MVT::i64:
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getTargetConstant(SPU::R64CRegClass.getID(), MVT::i32);
|
2010-09-16 12:29:33 +00:00
|
|
|
break;
|
2010-11-29 09:36:26 +00:00
|
|
|
case MVT::i128:
|
|
|
|
return CurDAG->getTargetConstant(SPU::GPRCRegClass.getID(), MVT::i32);
|
|
|
|
break;
|
2010-10-07 16:32:42 +00:00
|
|
|
case MVT::v16i8:
|
|
|
|
case MVT::v8i16:
|
|
|
|
case MVT::v4i32:
|
|
|
|
case MVT::v4f32:
|
2010-09-16 12:29:33 +00:00
|
|
|
case MVT::v2i64:
|
2010-10-07 16:32:42 +00:00
|
|
|
case MVT::v2f64:
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getTargetConstant(SPU::VECREGRegClass.getID(), MVT::i32);
|
2010-09-16 12:29:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( false && "add a new case here" );
|
|
|
|
}
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
//! Convert the operand from a target-independent to a target-specific node
|
|
|
|
/*!
|
|
|
|
*/
|
|
|
|
SDNode *
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::Select(SDNode *N) {
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned Opc = N->getOpcode();
|
2008-01-17 20:38:41 +00:00
|
|
|
int n_ops = -1;
|
2011-01-23 17:05:06 +00:00
|
|
|
unsigned NewOpc = 0;
|
2010-01-05 01:24:18 +00:00
|
|
|
EVT OpVT = N->getValueType(0);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[8];
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
if (N->isMachineOpcode())
|
2007-12-04 22:23:35 +00:00
|
|
|
return NULL; // Already selected.
|
2009-01-26 03:31:40 +00:00
|
|
|
|
|
|
|
if (Opc == ISD::FrameIndex) {
|
2008-12-30 23:28:25 +00:00
|
|
|
int FI = cast<FrameIndexSDNode>(N)->getIndex();
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue TFI = CurDAG->getTargetFrameIndex(FI, N->getValueType(0));
|
|
|
|
SDValue Imm0 = CurDAG->getTargetConstant(0, N->getValueType(0));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
if (FI < 128) {
|
2008-04-30 00:30:08 +00:00
|
|
|
NewOpc = SPU::AIr32;
|
2008-12-30 23:28:25 +00:00
|
|
|
Ops[0] = TFI;
|
|
|
|
Ops[1] = Imm0;
|
2008-04-30 00:30:08 +00:00
|
|
|
n_ops = 2;
|
|
|
|
} else {
|
|
|
|
NewOpc = SPU::Ar32;
|
2010-01-05 01:24:18 +00:00
|
|
|
Ops[0] = CurDAG->getRegister(SPU::R1, N->getValueType(0));
|
2009-09-25 18:54:59 +00:00
|
|
|
Ops[1] = SDValue(CurDAG->getMachineNode(SPU::ILAr32, dl,
|
2010-12-09 16:17:31 +00:00
|
|
|
N->getValueType(0), TFI),
|
2009-09-25 18:54:59 +00:00
|
|
|
0);
|
2008-04-30 00:30:08 +00:00
|
|
|
n_ops = 2;
|
|
|
|
}
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (Opc == ISD::Constant && OpVT == MVT::i64) {
|
2009-01-26 03:31:40 +00:00
|
|
|
// Catch the i64 constants that end up here. Note: The backend doesn't
|
|
|
|
// attempt to legalize the constant (it's useless because DAGCombiner
|
|
|
|
// will insert 64-bit constants and we can't stop it).
|
2010-01-05 01:24:18 +00:00
|
|
|
return SelectI64Constant(N, OpVT, N->getDebugLoc());
|
2009-01-15 04:41:47 +00:00
|
|
|
} else if ((Opc == ISD::ZERO_EXTEND || Opc == ISD::ANY_EXTEND)
|
2009-08-11 20:47:22 +00:00
|
|
|
&& OpVT == MVT::i64) {
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue Op0 = N->getOperand(0);
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT Op0VT = Op0.getValueType();
|
2009-08-12 00:36:31 +00:00
|
|
|
EVT Op0VecVT = EVT::getVectorVT(*CurDAG->getContext(),
|
|
|
|
Op0VT, (128 / Op0VT.getSizeInBits()));
|
2010-11-23 03:31:01 +00:00
|
|
|
EVT OpVecVT = EVT::getVectorVT(*CurDAG->getContext(),
|
2009-08-12 00:36:31 +00:00
|
|
|
OpVT, (128 / OpVT.getSizeInBits()));
|
2009-01-15 04:41:47 +00:00
|
|
|
SDValue shufMask;
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
switch (Op0VT.getSimpleVT().SimpleTy) {
|
2009-01-15 04:41:47 +00:00
|
|
|
default:
|
2010-04-07 22:58:41 +00:00
|
|
|
report_fatal_error("CellSPU Select: Unhandled zero/any extend EVT");
|
2009-01-15 04:41:47 +00:00
|
|
|
/*NOTREACHED*/
|
2009-08-11 20:47:22 +00:00
|
|
|
case MVT::i32:
|
|
|
|
shufMask = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32,
|
|
|
|
CurDAG->getConstant(0x80808080, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x00010203, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x80808080, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x08090a0b, MVT::i32));
|
2009-01-15 04:41:47 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
case MVT::i16:
|
|
|
|
shufMask = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32,
|
|
|
|
CurDAG->getConstant(0x80808080, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x80800203, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x80808080, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x80800a0b, MVT::i32));
|
2009-01-15 04:41:47 +00:00
|
|
|
break;
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
case MVT::i8:
|
|
|
|
shufMask = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32,
|
|
|
|
CurDAG->getConstant(0x80808080, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x80808003, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x80808080, MVT::i32),
|
|
|
|
CurDAG->getConstant(0x8080800b, MVT::i32));
|
2009-01-15 04:41:47 +00:00
|
|
|
break;
|
2008-01-17 20:38:41 +00:00
|
|
|
}
|
2009-01-15 04:41:47 +00:00
|
|
|
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *shufMaskLoad = emitBuildVector(shufMask.getNode());
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
HandleSDNode PromoteScalar(CurDAG->getNode(SPUISD::PREFSLOT2VEC, dl,
|
|
|
|
Op0VecVT, Op0));
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
SDValue PromScalar;
|
|
|
|
if (SDNode *N = SelectCode(PromoteScalar.getValue().getNode()))
|
|
|
|
PromScalar = SDValue(N, 0);
|
|
|
|
else
|
|
|
|
PromScalar = PromoteScalar.getValue();
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2009-01-15 04:41:47 +00:00
|
|
|
SDValue zextShuffle =
|
2009-02-06 01:31:28 +00:00
|
|
|
CurDAG->getNode(SPUISD::SHUFB, dl, OpVecVT,
|
2010-11-23 03:31:01 +00:00
|
|
|
PromScalar, PromScalar,
|
2009-01-21 04:58:48 +00:00
|
|
|
SDValue(shufMaskLoad, 0));
|
2009-01-15 04:41:47 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
HandleSDNode Dummy2(zextShuffle);
|
|
|
|
if (SDNode *N = SelectCode(Dummy2.getValue().getNode()))
|
|
|
|
zextShuffle = SDValue(N, 0);
|
|
|
|
else
|
|
|
|
zextShuffle = Dummy2.getValue();
|
|
|
|
HandleSDNode Dummy(CurDAG->getNode(SPUISD::VEC2PREFSLOT, dl, OpVT,
|
|
|
|
zextShuffle));
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
CurDAG->ReplaceAllUsesWith(N, Dummy.getValue().getNode());
|
|
|
|
SelectCode(Dummy.getValue().getNode());
|
|
|
|
return Dummy.getValue().getNode();
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (Opc == ISD::ADD && (OpVT == MVT::i64 || OpVT == MVT::v2i64)) {
|
2009-01-21 04:58:48 +00:00
|
|
|
SDNode *CGLoad =
|
2010-01-05 01:24:18 +00:00
|
|
|
emitBuildVector(getCarryGenerateShufMask(*CurDAG, dl).getNode());
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
HandleSDNode Dummy(CurDAG->getNode(SPUISD::ADD64_MARKER, dl, OpVT,
|
|
|
|
N->getOperand(0), N->getOperand(1),
|
|
|
|
SDValue(CGLoad, 0)));
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
CurDAG->ReplaceAllUsesWith(N, Dummy.getValue().getNode());
|
|
|
|
if (SDNode *N = SelectCode(Dummy.getValue().getNode()))
|
|
|
|
return N;
|
|
|
|
return Dummy.getValue().getNode();
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (Opc == ISD::SUB && (OpVT == MVT::i64 || OpVT == MVT::v2i64)) {
|
2009-01-21 04:58:48 +00:00
|
|
|
SDNode *CGLoad =
|
2010-01-05 01:24:18 +00:00
|
|
|
emitBuildVector(getBorrowGenerateShufMask(*CurDAG, dl).getNode());
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
HandleSDNode Dummy(CurDAG->getNode(SPUISD::SUB64_MARKER, dl, OpVT,
|
|
|
|
N->getOperand(0), N->getOperand(1),
|
|
|
|
SDValue(CGLoad, 0)));
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
CurDAG->ReplaceAllUsesWith(N, Dummy.getValue().getNode());
|
|
|
|
if (SDNode *N = SelectCode(Dummy.getValue().getNode()))
|
|
|
|
return N;
|
|
|
|
return Dummy.getValue().getNode();
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (Opc == ISD::MUL && (OpVT == MVT::i64 || OpVT == MVT::v2i64)) {
|
2009-01-21 04:58:48 +00:00
|
|
|
SDNode *CGLoad =
|
2010-01-05 01:24:18 +00:00
|
|
|
emitBuildVector(getCarryGenerateShufMask(*CurDAG, dl).getNode());
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
HandleSDNode Dummy(CurDAG->getNode(SPUISD::MUL64_MARKER, dl, OpVT,
|
|
|
|
N->getOperand(0), N->getOperand(1),
|
|
|
|
SDValue(CGLoad, 0)));
|
|
|
|
CurDAG->ReplaceAllUsesWith(N, Dummy.getValue().getNode());
|
|
|
|
if (SDNode *N = SelectCode(Dummy.getValue().getNode()))
|
|
|
|
return N;
|
|
|
|
return Dummy.getValue().getNode();
|
2009-01-26 03:31:40 +00:00
|
|
|
} else if (Opc == ISD::TRUNCATE) {
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue Op0 = N->getOperand(0);
|
2009-01-26 03:31:40 +00:00
|
|
|
if ((Op0.getOpcode() == ISD::SRA || Op0.getOpcode() == ISD::SRL)
|
2009-08-11 20:47:22 +00:00
|
|
|
&& OpVT == MVT::i32
|
|
|
|
&& Op0.getValueType() == MVT::i64) {
|
2009-01-26 22:33:37 +00:00
|
|
|
// Catch (truncate:i32 ([sra|srl]:i64 arg, c), where c >= 32
|
|
|
|
//
|
|
|
|
// Take advantage of the fact that the upper 32 bits are in the
|
|
|
|
// i32 preferred slot and avoid shuffle gymnastics:
|
2009-01-26 03:31:40 +00:00
|
|
|
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op0.getOperand(1));
|
|
|
|
if (CN != 0) {
|
|
|
|
unsigned shift_amt = unsigned(CN->getZExtValue());
|
|
|
|
|
|
|
|
if (shift_amt >= 32) {
|
|
|
|
SDNode *hi32 =
|
2010-09-16 12:29:33 +00:00
|
|
|
CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl, OpVT,
|
|
|
|
Op0.getOperand(0), getRC(MVT::i32));
|
2009-01-26 03:31:40 +00:00
|
|
|
|
|
|
|
shift_amt -= 32;
|
|
|
|
if (shift_amt > 0) {
|
|
|
|
// Take care of the additional shift, if present:
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue shift = CurDAG->getTargetConstant(shift_amt, MVT::i32);
|
2009-01-26 03:31:40 +00:00
|
|
|
unsigned Opc = SPU::ROTMAIr32_i32;
|
2009-01-26 22:33:37 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
if (Op0.getOpcode() == ISD::SRL)
|
|
|
|
Opc = SPU::ROTMr32;
|
|
|
|
|
2009-09-25 18:54:59 +00:00
|
|
|
hi32 = CurDAG->getMachineNode(Opc, dl, OpVT, SDValue(hi32, 0),
|
|
|
|
shift);
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return hi32;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-30 23:28:25 +00:00
|
|
|
} else if (Opc == ISD::SHL) {
|
2010-02-23 05:30:43 +00:00
|
|
|
if (OpVT == MVT::i64)
|
2010-01-05 01:24:18 +00:00
|
|
|
return SelectSHLi64(N, OpVT);
|
2008-12-30 23:28:25 +00:00
|
|
|
} else if (Opc == ISD::SRL) {
|
2010-02-23 05:30:43 +00:00
|
|
|
if (OpVT == MVT::i64)
|
2010-01-05 01:24:18 +00:00
|
|
|
return SelectSRLi64(N, OpVT);
|
2008-12-30 23:28:25 +00:00
|
|
|
} else if (Opc == ISD::SRA) {
|
2010-02-23 05:30:43 +00:00
|
|
|
if (OpVT == MVT::i64)
|
2010-01-05 01:24:18 +00:00
|
|
|
return SelectSRAi64(N, OpVT);
|
2009-03-17 01:15:45 +00:00
|
|
|
} else if (Opc == ISD::FNEG
|
2009-08-11 20:47:22 +00:00
|
|
|
&& (OpVT == MVT::f64 || OpVT == MVT::v2f64)) {
|
2010-01-05 01:24:18 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2009-03-17 01:15:45 +00:00
|
|
|
// Check if the pattern is a special form of DFNMS:
|
|
|
|
// (fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue Op0 = N->getOperand(0);
|
2009-03-17 01:15:45 +00:00
|
|
|
if (Op0.getOpcode() == ISD::FSUB) {
|
|
|
|
SDValue Op00 = Op0.getOperand(0);
|
|
|
|
if (Op00.getOpcode() == ISD::FMUL) {
|
|
|
|
unsigned Opc = SPU::DFNMSf64;
|
2009-08-11 20:47:22 +00:00
|
|
|
if (OpVT == MVT::v2f64)
|
2009-03-17 01:15:45 +00:00
|
|
|
Opc = SPU::DFNMSv2f64;
|
|
|
|
|
2009-09-25 18:54:59 +00:00
|
|
|
return CurDAG->getMachineNode(Opc, dl, OpVT,
|
|
|
|
Op00.getOperand(0),
|
|
|
|
Op00.getOperand(1),
|
|
|
|
Op0.getOperand(1));
|
2009-03-17 01:15:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue negConst = CurDAG->getConstant(0x8000000000000000ULL, MVT::i64);
|
2009-03-17 01:15:45 +00:00
|
|
|
SDNode *signMask = 0;
|
2009-03-17 16:45:16 +00:00
|
|
|
unsigned Opc = SPU::XORfneg64;
|
2009-03-17 01:15:45 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
if (OpVT == MVT::f64) {
|
2010-01-05 01:24:18 +00:00
|
|
|
signMask = SelectI64Constant(negConst.getNode(), MVT::i64, dl);
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (OpVT == MVT::v2f64) {
|
2009-03-17 16:45:16 +00:00
|
|
|
Opc = SPU::XORfnegvec;
|
2009-03-17 01:15:45 +00:00
|
|
|
signMask = emitBuildVector(CurDAG->getNode(ISD::BUILD_VECTOR, dl,
|
2009-08-11 20:47:22 +00:00
|
|
|
MVT::v2i64,
|
2010-01-05 01:24:18 +00:00
|
|
|
negConst, negConst).getNode());
|
2009-03-17 01:15:45 +00:00
|
|
|
}
|
|
|
|
|
2009-09-25 18:54:59 +00:00
|
|
|
return CurDAG->getMachineNode(Opc, dl, OpVT,
|
2010-01-05 01:24:18 +00:00
|
|
|
N->getOperand(0), SDValue(signMask, 0));
|
2009-03-17 01:15:45 +00:00
|
|
|
} else if (Opc == ISD::FABS) {
|
2009-08-11 20:47:22 +00:00
|
|
|
if (OpVT == MVT::f64) {
|
|
|
|
SDNode *signMask = SelectI64Constant(0x7fffffffffffffffULL, MVT::i64, dl);
|
2009-09-25 18:54:59 +00:00
|
|
|
return CurDAG->getMachineNode(SPU::ANDfabs64, dl, OpVT,
|
2010-01-05 01:24:18 +00:00
|
|
|
N->getOperand(0), SDValue(signMask, 0));
|
2009-08-11 20:47:22 +00:00
|
|
|
} else if (OpVT == MVT::v2f64) {
|
|
|
|
SDValue absConst = CurDAG->getConstant(0x7fffffffffffffffULL, MVT::i64);
|
|
|
|
SDValue absVec = CurDAG->getNode(ISD::BUILD_VECTOR, dl, MVT::v2i64,
|
2009-03-17 01:15:45 +00:00
|
|
|
absConst, absConst);
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *signMask = emitBuildVector(absVec.getNode());
|
2009-09-25 18:54:59 +00:00
|
|
|
return CurDAG->getMachineNode(SPU::ANDfabsvec, dl, OpVT,
|
2010-01-05 01:24:18 +00:00
|
|
|
N->getOperand(0), SDValue(signMask, 0));
|
2009-03-17 01:15:45 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
} else if (Opc == SPUISD::LDRESULT) {
|
|
|
|
// Custom select instructions for LDRESULT
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT VT = N->getValueType(0);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Arg = N->getOperand(0);
|
|
|
|
SDValue Chain = N->getOperand(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
SDNode *Result;
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2010-10-01 09:20:01 +00:00
|
|
|
Result = CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl, VT,
|
|
|
|
MVT::Other, Arg,
|
|
|
|
getRC( VT.getSimpleVT()), Chain);
|
2007-12-04 22:23:35 +00:00
|
|
|
return Result;
|
2010-11-23 03:31:01 +00:00
|
|
|
|
2008-01-29 02:16:57 +00:00
|
|
|
} else if (Opc == SPUISD::IndirectAddr) {
|
2008-12-27 04:51:36 +00:00
|
|
|
// Look at the operands: SelectCode() will catch the cases that aren't
|
|
|
|
// specifically handled here.
|
|
|
|
//
|
|
|
|
// SPUInstrInfo catches the following patterns:
|
|
|
|
// (SPUindirect (SPUhi ...), (SPUlo ...))
|
|
|
|
// (SPUindirect $sp, imm)
|
2010-01-05 01:24:18 +00:00
|
|
|
EVT VT = N->getValueType(0);
|
2008-12-27 04:51:36 +00:00
|
|
|
SDValue Op0 = N->getOperand(0);
|
|
|
|
SDValue Op1 = N->getOperand(1);
|
|
|
|
RegisterSDNode *RN;
|
|
|
|
|
|
|
|
if ((Op0.getOpcode() != SPUISD::Hi && Op1.getOpcode() != SPUISD::Lo)
|
|
|
|
|| (Op0.getOpcode() == ISD::Register
|
|
|
|
&& ((RN = dyn_cast<RegisterSDNode>(Op0.getNode())) != 0
|
|
|
|
&& RN->getReg() != SPU::R1))) {
|
|
|
|
NewOpc = SPU::Ar32;
|
2010-05-04 17:58:46 +00:00
|
|
|
Ops[1] = Op1;
|
2008-01-17 20:38:41 +00:00
|
|
|
if (Op1.getOpcode() == ISD::Constant) {
|
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Op1);
|
2008-12-27 04:51:36 +00:00
|
|
|
Op1 = CurDAG->getTargetConstant(CN->getSExtValue(), VT);
|
2010-05-04 17:58:46 +00:00
|
|
|
if (isInt<10>(CN->getSExtValue())) {
|
|
|
|
NewOpc = SPU::AIr32;
|
|
|
|
Ops[1] = Op1;
|
|
|
|
} else {
|
2010-11-23 03:31:01 +00:00
|
|
|
Ops[1] = SDValue(CurDAG->getMachineNode(SPU::ILr32, dl,
|
|
|
|
N->getValueType(0),
|
2010-05-04 17:58:46 +00:00
|
|
|
Op1),
|
2010-11-23 03:31:01 +00:00
|
|
|
0);
|
2010-05-04 17:58:46 +00:00
|
|
|
}
|
2008-01-17 20:38:41 +00:00
|
|
|
}
|
2008-12-27 04:51:36 +00:00
|
|
|
Ops[0] = Op0;
|
|
|
|
n_ops = 2;
|
2008-01-17 20:38:41 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2008-01-17 20:38:41 +00:00
|
|
|
if (n_ops > 0) {
|
|
|
|
if (N->hasOneUse())
|
|
|
|
return CurDAG->SelectNodeTo(N, NewOpc, OpVT, Ops, n_ops);
|
|
|
|
else
|
2009-09-25 18:54:59 +00:00
|
|
|
return CurDAG->getMachineNode(NewOpc, dl, OpVT, Ops, n_ops);
|
2008-01-17 20:38:41 +00:00
|
|
|
} else
|
2010-01-05 01:24:18 +00:00
|
|
|
return SelectCode(N);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
/*!
|
|
|
|
* Emit the instruction sequence for i64 left shifts. The basic algorithm
|
|
|
|
* is to fill the bottom two word slots with zeros so that zeros are shifted
|
|
|
|
* in as the entire quadword is shifted left.
|
|
|
|
*
|
|
|
|
* \note This code could also be used to implement v2i64 shl.
|
|
|
|
*
|
|
|
|
* @param Op The shl operand
|
|
|
|
* @param OpVT Op's machine value value type (doesn't need to be passed, but
|
|
|
|
* makes life easier.)
|
|
|
|
* @return The SDNode with the entire instruction sequence
|
|
|
|
*/
|
|
|
|
SDNode *
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectSHLi64(SDNode *N, EVT OpVT) {
|
|
|
|
SDValue Op0 = N->getOperand(0);
|
2010-11-23 03:31:01 +00:00
|
|
|
EVT VecVT = EVT::getVectorVT(*CurDAG->getContext(),
|
2009-08-12 00:36:31 +00:00
|
|
|
OpVT, (128 / OpVT.getSizeInBits()));
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue ShiftAmt = N->getOperand(1);
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT ShiftAmtVT = ShiftAmt.getValueType();
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *VecOp0, *SelMask, *ZeroFill, *Shift = 0;
|
|
|
|
SDValue SelMaskVal;
|
2010-01-05 01:24:18 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2010-09-16 12:29:33 +00:00
|
|
|
VecOp0 = CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl, VecVT,
|
|
|
|
Op0, getRC(MVT::v2i64) );
|
2009-08-11 20:47:22 +00:00
|
|
|
SelMaskVal = CurDAG->getTargetConstant(0xff00ULL, MVT::i16);
|
2009-09-25 18:54:59 +00:00
|
|
|
SelMask = CurDAG->getMachineNode(SPU::FSMBIv2i64, dl, VecVT, SelMaskVal);
|
|
|
|
ZeroFill = CurDAG->getMachineNode(SPU::ILv2i64, dl, VecVT,
|
|
|
|
CurDAG->getTargetConstant(0, OpVT));
|
|
|
|
VecOp0 = CurDAG->getMachineNode(SPU::SELBv2i64, dl, VecVT,
|
|
|
|
SDValue(ZeroFill, 0),
|
|
|
|
SDValue(VecOp0, 0),
|
|
|
|
SDValue(SelMask, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(ShiftAmt)) {
|
|
|
|
unsigned bytes = unsigned(CN->getZExtValue()) >> 3;
|
|
|
|
unsigned bits = unsigned(CN->getZExtValue()) & 7;
|
|
|
|
|
|
|
|
if (bytes > 0) {
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::SHLQBYIv2i64, dl, VecVT,
|
|
|
|
SDValue(VecOp0, 0),
|
|
|
|
CurDAG->getTargetConstant(bytes, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bits > 0) {
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::SHLQBIIv2i64, dl, VecVT,
|
|
|
|
SDValue((Shift != 0 ? Shift : VecOp0), 0),
|
|
|
|
CurDAG->getTargetConstant(bits, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDNode *Bytes =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTMIr32, dl, ShiftAmtVT,
|
|
|
|
ShiftAmt,
|
|
|
|
CurDAG->getTargetConstant(3, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *Bits =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ANDIr32, dl, ShiftAmtVT,
|
|
|
|
ShiftAmt,
|
|
|
|
CurDAG->getTargetConstant(7, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::SHLQBYv2i64, dl, VecVT,
|
|
|
|
SDValue(VecOp0, 0), SDValue(Bytes, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::SHLQBIv2i64, dl, VecVT,
|
|
|
|
SDValue(Shift, 0), SDValue(Bits, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl,
|
2010-09-16 12:29:33 +00:00
|
|
|
OpVT, SDValue(Shift, 0), getRC(MVT::i64));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Emit the instruction sequence for i64 logical right shifts.
|
|
|
|
*
|
|
|
|
* @param Op The shl operand
|
|
|
|
* @param OpVT Op's machine value value type (doesn't need to be passed, but
|
|
|
|
* makes life easier.)
|
|
|
|
* @return The SDNode with the entire instruction sequence
|
|
|
|
*/
|
|
|
|
SDNode *
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectSRLi64(SDNode *N, EVT OpVT) {
|
|
|
|
SDValue Op0 = N->getOperand(0);
|
2009-08-12 00:36:31 +00:00
|
|
|
EVT VecVT = EVT::getVectorVT(*CurDAG->getContext(),
|
|
|
|
OpVT, (128 / OpVT.getSizeInBits()));
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue ShiftAmt = N->getOperand(1);
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT ShiftAmtVT = ShiftAmt.getValueType();
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *VecOp0, *Shift = 0;
|
2010-01-05 01:24:18 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2010-09-16 12:29:33 +00:00
|
|
|
VecOp0 = CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl, VecVT,
|
|
|
|
Op0, getRC(MVT::v2i64) );
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(ShiftAmt)) {
|
|
|
|
unsigned bytes = unsigned(CN->getZExtValue()) >> 3;
|
|
|
|
unsigned bits = unsigned(CN->getZExtValue()) & 7;
|
|
|
|
|
|
|
|
if (bytes > 0) {
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQMBYIv2i64, dl, VecVT,
|
|
|
|
SDValue(VecOp0, 0),
|
|
|
|
CurDAG->getTargetConstant(bytes, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bits > 0) {
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQMBIIv2i64, dl, VecVT,
|
|
|
|
SDValue((Shift != 0 ? Shift : VecOp0), 0),
|
|
|
|
CurDAG->getTargetConstant(bits, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDNode *Bytes =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTMIr32, dl, ShiftAmtVT,
|
|
|
|
ShiftAmt,
|
|
|
|
CurDAG->getTargetConstant(3, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *Bits =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ANDIr32, dl, ShiftAmtVT,
|
|
|
|
ShiftAmt,
|
|
|
|
CurDAG->getTargetConstant(7, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
// Ensure that the shift amounts are negated!
|
2009-09-25 18:54:59 +00:00
|
|
|
Bytes = CurDAG->getMachineNode(SPU::SFIr32, dl, ShiftAmtVT,
|
|
|
|
SDValue(Bytes, 0),
|
|
|
|
CurDAG->getTargetConstant(0, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2009-09-25 18:54:59 +00:00
|
|
|
Bits = CurDAG->getMachineNode(SPU::SFIr32, dl, ShiftAmtVT,
|
|
|
|
SDValue(Bits, 0),
|
|
|
|
CurDAG->getTargetConstant(0, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQMBYv2i64, dl, VecVT,
|
|
|
|
SDValue(VecOp0, 0), SDValue(Bytes, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQMBIv2i64, dl, VecVT,
|
|
|
|
SDValue(Shift, 0), SDValue(Bits, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl,
|
2010-09-16 12:29:33 +00:00
|
|
|
OpVT, SDValue(Shift, 0), getRC(MVT::i64));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* Emit the instruction sequence for i64 arithmetic right shifts.
|
|
|
|
*
|
|
|
|
* @param Op The shl operand
|
|
|
|
* @param OpVT Op's machine value value type (doesn't need to be passed, but
|
|
|
|
* makes life easier.)
|
|
|
|
* @return The SDNode with the entire instruction sequence
|
|
|
|
*/
|
|
|
|
SDNode *
|
2010-01-05 01:24:18 +00:00
|
|
|
SPUDAGToDAGISel::SelectSRAi64(SDNode *N, EVT OpVT) {
|
2008-12-30 23:28:25 +00:00
|
|
|
// Promote Op0 to vector
|
2010-11-23 03:31:01 +00:00
|
|
|
EVT VecVT = EVT::getVectorVT(*CurDAG->getContext(),
|
2009-08-12 00:36:31 +00:00
|
|
|
OpVT, (128 / OpVT.getSizeInBits()));
|
2010-01-05 01:24:18 +00:00
|
|
|
SDValue ShiftAmt = N->getOperand(1);
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT ShiftAmtVT = ShiftAmt.getValueType();
|
2010-01-05 01:24:18 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
SDNode *VecOp0 =
|
2010-11-23 03:31:01 +00:00
|
|
|
CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl,
|
2010-09-16 12:29:33 +00:00
|
|
|
VecVT, N->getOperand(0), getRC(MVT::v2i64));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
SDValue SignRotAmt = CurDAG->getTargetConstant(31, ShiftAmtVT);
|
|
|
|
SDNode *SignRot =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTMAIv2i64_i32, dl, MVT::v2i64,
|
|
|
|
SDValue(VecOp0, 0), SignRotAmt);
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *UpperHalfSign =
|
2010-11-23 03:31:01 +00:00
|
|
|
CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl,
|
2010-09-16 12:29:33 +00:00
|
|
|
MVT::i32, SDValue(SignRot, 0), getRC(MVT::i32));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
SDNode *UpperHalfSignMask =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::FSM64r32, dl, VecVT, SDValue(UpperHalfSign, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *UpperLowerMask =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::FSMBIv2i64, dl, VecVT,
|
|
|
|
CurDAG->getTargetConstant(0xff00ULL, MVT::i16));
|
2008-12-30 23:28:25 +00:00
|
|
|
SDNode *UpperLowerSelect =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::SELBv2i64, dl, VecVT,
|
|
|
|
SDValue(UpperHalfSignMask, 0),
|
|
|
|
SDValue(VecOp0, 0),
|
|
|
|
SDValue(UpperLowerMask, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
SDNode *Shift = 0;
|
|
|
|
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(ShiftAmt)) {
|
|
|
|
unsigned bytes = unsigned(CN->getZExtValue()) >> 3;
|
|
|
|
unsigned bits = unsigned(CN->getZExtValue()) & 7;
|
|
|
|
|
|
|
|
if (bytes > 0) {
|
|
|
|
bytes = 31 - bytes;
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQBYIv2i64, dl, VecVT,
|
|
|
|
SDValue(UpperLowerSelect, 0),
|
|
|
|
CurDAG->getTargetConstant(bytes, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (bits > 0) {
|
|
|
|
bits = 8 - bits;
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQBIIv2i64, dl, VecVT,
|
|
|
|
SDValue((Shift != 0 ? Shift : UpperLowerSelect), 0),
|
|
|
|
CurDAG->getTargetConstant(bits, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SDNode *NegShift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::SFIr32, dl, ShiftAmtVT,
|
|
|
|
ShiftAmt, CurDAG->getTargetConstant(0, ShiftAmtVT));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQBYBIv2i64_r32, dl, VecVT,
|
|
|
|
SDValue(UpperLowerSelect, 0), SDValue(NegShift, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
Shift =
|
2009-09-25 18:54:59 +00:00
|
|
|
CurDAG->getMachineNode(SPU::ROTQBIv2i64, dl, VecVT,
|
|
|
|
SDValue(Shift, 0), SDValue(NegShift, 0));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
return CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl,
|
2010-09-16 12:29:33 +00:00
|
|
|
OpVT, SDValue(Shift, 0), getRC(MVT::i64));
|
2008-12-30 23:28:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
/*!
|
|
|
|
Do the necessary magic necessary to load a i64 constant
|
|
|
|
*/
|
2010-01-05 01:24:18 +00:00
|
|
|
SDNode *SPUDAGToDAGISel::SelectI64Constant(SDNode *N, EVT OpVT,
|
2009-03-17 01:15:45 +00:00
|
|
|
DebugLoc dl) {
|
2010-01-05 01:24:18 +00:00
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(N);
|
2009-03-17 01:15:45 +00:00
|
|
|
return SelectI64Constant(CN->getZExtValue(), OpVT, dl);
|
|
|
|
}
|
|
|
|
|
2009-08-10 22:56:29 +00:00
|
|
|
SDNode *SPUDAGToDAGISel::SelectI64Constant(uint64_t Value64, EVT OpVT,
|
2009-03-17 01:15:45 +00:00
|
|
|
DebugLoc dl) {
|
2009-08-12 00:36:31 +00:00
|
|
|
EVT OpVecVT = EVT::getVectorVT(*CurDAG->getContext(), OpVT, 2);
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue i64vec =
|
2009-03-17 01:15:45 +00:00
|
|
|
SPU::LowerV2I64Splat(OpVecVT, *CurDAG, Value64, dl);
|
2009-01-26 03:31:40 +00:00
|
|
|
|
|
|
|
// Here's where it gets interesting, because we have to parse out the
|
|
|
|
// subtree handed back in i64vec:
|
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
if (i64vec.getOpcode() == ISD::BITCAST) {
|
2009-01-26 03:31:40 +00:00
|
|
|
// The degenerate case where the upper and lower bits in the splat are
|
|
|
|
// identical:
|
|
|
|
SDValue Op0 = i64vec.getOperand(0);
|
|
|
|
|
2009-01-26 22:33:37 +00:00
|
|
|
ReplaceUses(i64vec, Op0);
|
2010-09-16 12:29:33 +00:00
|
|
|
return CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl, OpVT,
|
|
|
|
SDValue(emitBuildVector(Op0.getNode()), 0),
|
|
|
|
getRC(MVT::i64));
|
2009-01-26 03:31:40 +00:00
|
|
|
} else if (i64vec.getOpcode() == SPUISD::SHUFB) {
|
|
|
|
SDValue lhs = i64vec.getOperand(0);
|
|
|
|
SDValue rhs = i64vec.getOperand(1);
|
|
|
|
SDValue shufmask = i64vec.getOperand(2);
|
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
if (lhs.getOpcode() == ISD::BITCAST) {
|
2009-01-26 03:31:40 +00:00
|
|
|
ReplaceUses(lhs, lhs.getOperand(0));
|
|
|
|
lhs = lhs.getOperand(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *lhsNode = (lhs.getNode()->isMachineOpcode()
|
|
|
|
? lhs.getNode()
|
2010-01-05 01:24:18 +00:00
|
|
|
: emitBuildVector(lhs.getNode()));
|
2009-01-26 03:31:40 +00:00
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
if (rhs.getOpcode() == ISD::BITCAST) {
|
2009-01-26 03:31:40 +00:00
|
|
|
ReplaceUses(rhs, rhs.getOperand(0));
|
|
|
|
rhs = rhs.getOperand(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *rhsNode = (rhs.getNode()->isMachineOpcode()
|
|
|
|
? rhs.getNode()
|
2010-01-05 01:24:18 +00:00
|
|
|
: emitBuildVector(rhs.getNode()));
|
2009-01-26 22:33:37 +00:00
|
|
|
|
2010-11-23 03:31:01 +00:00
|
|
|
if (shufmask.getOpcode() == ISD::BITCAST) {
|
2009-01-26 03:31:40 +00:00
|
|
|
ReplaceUses(shufmask, shufmask.getOperand(0));
|
|
|
|
shufmask = shufmask.getOperand(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDNode *shufMaskNode = (shufmask.getNode()->isMachineOpcode()
|
|
|
|
? shufmask.getNode()
|
2010-01-05 01:24:18 +00:00
|
|
|
: emitBuildVector(shufmask.getNode()));
|
2009-01-26 03:31:40 +00:00
|
|
|
|
2010-02-23 05:30:43 +00:00
|
|
|
SDValue shufNode =
|
|
|
|
CurDAG->getNode(SPUISD::SHUFB, dl, OpVecVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue(lhsNode, 0), SDValue(rhsNode, 0),
|
2010-02-23 05:30:43 +00:00
|
|
|
SDValue(shufMaskNode, 0));
|
|
|
|
HandleSDNode Dummy(shufNode);
|
|
|
|
SDNode *SN = SelectCode(Dummy.getValue().getNode());
|
|
|
|
if (SN == 0) SN = Dummy.getValue().getNode();
|
2010-11-23 03:31:01 +00:00
|
|
|
|
|
|
|
return CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl,
|
2010-09-16 12:29:33 +00:00
|
|
|
OpVT, SDValue(SN, 0), getRC(MVT::i64));
|
2009-03-17 01:15:45 +00:00
|
|
|
} else if (i64vec.getOpcode() == ISD::BUILD_VECTOR) {
|
2010-09-16 12:29:33 +00:00
|
|
|
return CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS, dl, OpVT,
|
|
|
|
SDValue(emitBuildVector(i64vec.getNode()), 0),
|
|
|
|
getRC(MVT::i64));
|
2009-01-26 03:31:40 +00:00
|
|
|
} else {
|
2010-04-07 22:58:41 +00:00
|
|
|
report_fatal_error("SPUDAGToDAGISel::SelectI64Constant: Unhandled i64vec"
|
2009-07-08 20:53:28 +00:00
|
|
|
"condition");
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
/// createSPUISelDag - This pass converts a legalized DAG into a
|
2007-12-04 22:23:35 +00:00
|
|
|
/// SPU-specific DAG, ready for instruction scheduling.
|
|
|
|
///
|
|
|
|
FunctionPass *llvm::createSPUISelDag(SPUTargetMachine &TM) {
|
|
|
|
return new SPUDAGToDAGISel(TM);
|
|
|
|
}
|