2007-12-04 22:23:35 +00:00
|
|
|
//===-- SPUISelLowering.cpp - Cell SPU DAG Lowering Implementation --------===//
|
|
|
|
//
|
|
|
|
// 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 implements the SPUTargetLowering class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SPURegisterNames.h"
|
|
|
|
#include "SPUISelLowering.h"
|
|
|
|
#include "SPUTargetMachine.h"
|
2008-04-30 00:30:08 +00:00
|
|
|
#include "SPUFrameInfo.h"
|
2008-12-27 04:51:36 +00:00
|
|
|
#include "llvm/ADT/APInt.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "llvm/ADT/VectorExtras.h"
|
2009-01-26 03:31:40 +00:00
|
|
|
#include "llvm/CallingConv.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "llvm/CodeGen/CallingConvLower.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2007-12-31 04:13:23 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2007-12-04 22:23:35 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Used in getTargetNodeName() below
|
|
|
|
namespace {
|
|
|
|
std::map<unsigned, const char *> node_names;
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
//! MVT mapping to useful data for Cell SPU
|
2007-12-04 22:23:35 +00:00
|
|
|
struct valtype_map_s {
|
2008-11-22 23:50:42 +00:00
|
|
|
const MVT valtype;
|
|
|
|
const int prefslot_byte;
|
2007-12-04 22:23:35 +00:00
|
|
|
};
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
const valtype_map_s valtype_map[] = {
|
|
|
|
{ MVT::i1, 3 },
|
|
|
|
{ MVT::i8, 3 },
|
|
|
|
{ MVT::i16, 2 },
|
|
|
|
{ MVT::i32, 0 },
|
|
|
|
{ MVT::f32, 0 },
|
|
|
|
{ MVT::i64, 0 },
|
|
|
|
{ MVT::f64, 0 },
|
|
|
|
{ MVT::i128, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t n_valtype_map = sizeof(valtype_map) / sizeof(valtype_map[0]);
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
const valtype_map_s *getValueTypeMapEntry(MVT VT) {
|
2007-12-04 22:23:35 +00:00
|
|
|
const valtype_map_s *retval = 0;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < n_valtype_map; ++i) {
|
|
|
|
if (valtype_map[i].valtype == VT) {
|
2008-01-30 02:55:46 +00:00
|
|
|
retval = valtype_map + i;
|
|
|
|
break;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
if (retval == 0) {
|
|
|
|
cerr << "getValueTypeMapEntry returns NULL for "
|
2008-06-06 12:08:01 +00:00
|
|
|
<< VT.getMVTString()
|
2008-01-30 02:55:46 +00:00
|
|
|
<< "\n";
|
2007-12-04 22:23:35 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2009-01-15 04:41:47 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
//! Expand a library call into an actual call DAG node
|
|
|
|
/*!
|
|
|
|
\note
|
|
|
|
This code is taken from SelectionDAGLegalize, since it is not exposed as
|
|
|
|
part of the LLVM SelectionDAG API.
|
|
|
|
*/
|
|
|
|
|
|
|
|
SDValue
|
|
|
|
ExpandLibCall(RTLIB::Libcall LC, SDValue Op, SelectionDAG &DAG,
|
|
|
|
bool isSigned, SDValue &Hi, SPUTargetLowering &TLI) {
|
|
|
|
// The input chain to this libcall is the entry node of the function.
|
|
|
|
// Legalizing the call will automatically add the previous call to the
|
|
|
|
// dependence.
|
|
|
|
SDValue InChain = DAG.getEntryNode();
|
|
|
|
|
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
TargetLowering::ArgListEntry Entry;
|
|
|
|
for (unsigned i = 0, e = Op.getNumOperands(); i != e; ++i) {
|
|
|
|
MVT ArgVT = Op.getOperand(i).getValueType();
|
|
|
|
const Type *ArgTy = ArgVT.getTypeForMVT();
|
|
|
|
Entry.Node = Op.getOperand(i);
|
|
|
|
Entry.Ty = ArgTy;
|
|
|
|
Entry.isSExt = isSigned;
|
|
|
|
Entry.isZExt = !isSigned;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
}
|
|
|
|
SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(LC),
|
|
|
|
TLI.getPointerTy());
|
|
|
|
|
|
|
|
// Splice the libcall in wherever FindInputOutputChains tells us to.
|
|
|
|
const Type *RetTy = Op.getNode()->getValueType(0).getTypeForMVT();
|
|
|
|
std::pair<SDValue, SDValue> CallInfo =
|
|
|
|
TLI.LowerCallTo(InChain, RetTy, isSigned, !isSigned, false, false,
|
2009-01-30 23:10:59 +00:00
|
|
|
CallingConv::C, false, Callee, Args, DAG,
|
2009-02-07 19:59:05 +00:00
|
|
|
Op.getDebugLoc());
|
2009-01-26 03:31:40 +00:00
|
|
|
|
|
|
|
return CallInfo.first;
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SPUTargetLowering::SPUTargetLowering(SPUTargetMachine &TM)
|
|
|
|
: TargetLowering(TM),
|
|
|
|
SPUTM(TM)
|
|
|
|
{
|
|
|
|
// Fold away setcc operations if possible.
|
|
|
|
setPow2DivIsCheap();
|
|
|
|
|
|
|
|
// Use _setjmp/_longjmp instead of setjmp/longjmp.
|
|
|
|
setUseUnderscoreSetJmp(true);
|
|
|
|
setUseUnderscoreLongJmp(true);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2009-01-21 04:58:48 +00:00
|
|
|
// Set RTLIB libcall names as used by SPU:
|
|
|
|
setLibcallName(RTLIB::DIV_F64, "__fast_divdf3");
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Set up the SPU's register classes:
|
2007-12-17 22:32:34 +00:00
|
|
|
addRegisterClass(MVT::i8, SPU::R8CRegisterClass);
|
|
|
|
addRegisterClass(MVT::i16, SPU::R16CRegisterClass);
|
|
|
|
addRegisterClass(MVT::i32, SPU::R32CRegisterClass);
|
|
|
|
addRegisterClass(MVT::i64, SPU::R64CRegisterClass);
|
|
|
|
addRegisterClass(MVT::f32, SPU::R32FPRegisterClass);
|
|
|
|
addRegisterClass(MVT::f64, SPU::R64FPRegisterClass);
|
2007-12-04 22:23:35 +00:00
|
|
|
addRegisterClass(MVT::i128, SPU::GPRCRegisterClass);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// SPU has no sign or zero extended loads for i1, i8, i16:
|
2008-10-14 21:26:46 +00:00
|
|
|
setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
|
|
|
|
setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
|
|
|
|
setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand);
|
|
|
|
setLoadExtAction(ISD::EXTLOAD, MVT::f64, Expand);
|
2008-12-02 19:53:53 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// SPU constant load actions are custom lowered:
|
2008-02-14 18:43:04 +00:00
|
|
|
setOperationAction(ISD::ConstantFP, MVT::f32, Legal);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::ConstantFP, MVT::f64, Custom);
|
|
|
|
|
|
|
|
// SPU's loads and stores have to be custom lowered:
|
2009-01-06 03:36:14 +00:00
|
|
|
for (unsigned sctype = (unsigned) MVT::i8; sctype < (unsigned) MVT::i128;
|
2007-12-04 22:23:35 +00:00
|
|
|
++sctype) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = (MVT::SimpleValueType)sctype;
|
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
setOperationAction(ISD::LOAD, VT, Custom);
|
|
|
|
setOperationAction(ISD::STORE, VT, Custom);
|
|
|
|
setLoadExtAction(ISD::EXTLOAD, VT, Custom);
|
|
|
|
setLoadExtAction(ISD::ZEXTLOAD, VT, Custom);
|
|
|
|
setLoadExtAction(ISD::SEXTLOAD, VT, Custom);
|
|
|
|
|
|
|
|
for (unsigned stype = sctype - 1; stype >= (unsigned) MVT::i8; --stype) {
|
|
|
|
MVT StoreVT = (MVT::SimpleValueType) stype;
|
|
|
|
setTruncStoreAction(VT, StoreVT, Expand);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned sctype = (unsigned) MVT::f32; sctype < (unsigned) MVT::f64;
|
|
|
|
++sctype) {
|
|
|
|
MVT VT = (MVT::SimpleValueType) sctype;
|
|
|
|
|
|
|
|
setOperationAction(ISD::LOAD, VT, Custom);
|
|
|
|
setOperationAction(ISD::STORE, VT, Custom);
|
|
|
|
|
|
|
|
for (unsigned stype = sctype - 1; stype >= (unsigned) MVT::f32; --stype) {
|
|
|
|
MVT StoreVT = (MVT::SimpleValueType) stype;
|
|
|
|
setTruncStoreAction(VT, StoreVT, Expand);
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Expand the jumptable branches
|
|
|
|
setOperationAction(ISD::BR_JT, MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::BR_CC, MVT::Other, Expand);
|
2008-11-22 23:50:42 +00:00
|
|
|
|
|
|
|
// Custom lower SELECT_CC for most cases, but expand by default
|
2008-07-16 17:17:29 +00:00
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
|
2008-11-22 23:50:42 +00:00
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::i8, Custom);
|
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::i16, Custom);
|
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::i64, Custom);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// SPU has no intrinsics for these particular operations:
|
2008-02-16 14:46:26 +00:00
|
|
|
setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand);
|
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// SPU has no SREM/UREM instructions
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::SREM, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::UREM, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SREM, MVT::i64, Expand);
|
|
|
|
setOperationAction(ISD::UREM, MVT::i64, Expand);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// We don't support sin/cos/sqrt/fmod
|
|
|
|
setOperationAction(ISD::FSIN , MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FCOS , MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FREM , MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FSIN , MVT::f32, Expand);
|
|
|
|
setOperationAction(ISD::FCOS , MVT::f32, Expand);
|
|
|
|
setOperationAction(ISD::FREM , MVT::f32, Expand);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
// Expand fsqrt to the appropriate libcall (NOTE: should use h/w fsqrt
|
|
|
|
// for f32!)
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::FSQRT, MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FSQRT, MVT::f32, Expand);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand);
|
|
|
|
setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand);
|
|
|
|
|
|
|
|
// SPU can do rotate right and left, so legalize it... but customize for i8
|
|
|
|
// because instructions don't exist.
|
2008-08-31 02:59:23 +00:00
|
|
|
|
|
|
|
// FIXME: Change from "expand" to appropriate type once ROTR is supported in
|
|
|
|
// .td files.
|
|
|
|
setOperationAction(ISD::ROTR, MVT::i32, Expand /*Legal*/);
|
|
|
|
setOperationAction(ISD::ROTR, MVT::i16, Expand /*Legal*/);
|
|
|
|
setOperationAction(ISD::ROTR, MVT::i8, Expand /*Custom*/);
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::ROTL, MVT::i32, Legal);
|
|
|
|
setOperationAction(ISD::ROTL, MVT::i16, Legal);
|
|
|
|
setOperationAction(ISD::ROTL, MVT::i8, Custom);
|
2008-11-20 16:36:33 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// SPU has no native version of shift left/right for i8
|
|
|
|
setOperationAction(ISD::SHL, MVT::i8, Custom);
|
|
|
|
setOperationAction(ISD::SRL, MVT::i8, Custom);
|
|
|
|
setOperationAction(ISD::SRA, MVT::i8, Custom);
|
2008-11-21 02:56:16 +00:00
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
// Make these operations legal and handle them during instruction selection:
|
|
|
|
setOperationAction(ISD::SHL, MVT::i64, Legal);
|
|
|
|
setOperationAction(ISD::SRL, MVT::i64, Legal);
|
|
|
|
setOperationAction(ISD::SRA, MVT::i64, Legal);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-16 17:17:29 +00:00
|
|
|
// Custom lower i8, i32 and i64 multiplications
|
|
|
|
setOperationAction(ISD::MUL, MVT::i8, Custom);
|
2008-12-29 03:23:36 +00:00
|
|
|
setOperationAction(ISD::MUL, MVT::i32, Legal);
|
2009-01-15 04:41:47 +00:00
|
|
|
setOperationAction(ISD::MUL, MVT::i64, Legal);
|
2008-11-21 02:56:16 +00:00
|
|
|
|
2008-06-02 22:18:03 +00:00
|
|
|
// Need to custom handle (some) common i8, i64 math ops
|
2008-12-30 23:28:25 +00:00
|
|
|
setOperationAction(ISD::ADD, MVT::i8, Custom);
|
2009-01-15 04:41:47 +00:00
|
|
|
setOperationAction(ISD::ADD, MVT::i64, Legal);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::SUB, MVT::i8, Custom);
|
2009-01-15 04:41:47 +00:00
|
|
|
setOperationAction(ISD::SUB, MVT::i64, Legal);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// SPU does not have BSWAP. It does have i32 support CTLZ.
|
|
|
|
// CTPOP has to be custom lowered.
|
|
|
|
setOperationAction(ISD::BSWAP, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::BSWAP, MVT::i64, Expand);
|
|
|
|
|
|
|
|
setOperationAction(ISD::CTPOP, MVT::i8, Custom);
|
|
|
|
setOperationAction(ISD::CTPOP, MVT::i16, Custom);
|
|
|
|
setOperationAction(ISD::CTPOP, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::CTPOP, MVT::i64, Custom);
|
|
|
|
|
|
|
|
setOperationAction(ISD::CTTZ , MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::CTTZ , MVT::i64, Expand);
|
|
|
|
|
|
|
|
setOperationAction(ISD::CTLZ , MVT::i32, Legal);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-06-02 22:18:03 +00:00
|
|
|
// SPU has a version of select that implements (a&~c)|(b&c), just like
|
2008-03-10 23:49:09 +00:00
|
|
|
// select ought to work:
|
2008-03-10 16:58:52 +00:00
|
|
|
setOperationAction(ISD::SELECT, MVT::i8, Legal);
|
2008-03-05 23:02:02 +00:00
|
|
|
setOperationAction(ISD::SELECT, MVT::i16, Legal);
|
|
|
|
setOperationAction(ISD::SELECT, MVT::i32, Legal);
|
2008-12-27 04:51:36 +00:00
|
|
|
setOperationAction(ISD::SELECT, MVT::i64, Legal);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-03-10 16:58:52 +00:00
|
|
|
setOperationAction(ISD::SETCC, MVT::i8, Legal);
|
|
|
|
setOperationAction(ISD::SETCC, MVT::i16, Legal);
|
2008-12-29 03:23:36 +00:00
|
|
|
setOperationAction(ISD::SETCC, MVT::i32, Legal);
|
|
|
|
setOperationAction(ISD::SETCC, MVT::i64, Legal);
|
2009-01-21 04:58:48 +00:00
|
|
|
setOperationAction(ISD::SETCC, MVT::f64, Custom);
|
2008-03-05 23:02:02 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// Custom lower i128 -> i64 truncates
|
2008-12-02 19:53:53 +00:00
|
|
|
setOperationAction(ISD::TRUNCATE, MVT::i64, Custom);
|
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
// SPU has a legal FP -> signed INT instruction for f32, but for f64, need
|
|
|
|
// to expand to a libcall, hence the custom lowering:
|
|
|
|
setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// FDIV on SPU requires custom lowering
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::FDIV, MVT::f64, Expand); // to libcall
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-01-26 22:33:37 +00:00
|
|
|
// SPU has [U|S]INT_TO_FP for f32->i32, but not for f64->i32, f64->i64:
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::SINT_TO_FP, MVT::i16, Promote);
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::SINT_TO_FP, MVT::i8, Promote);
|
|
|
|
setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::UINT_TO_FP, MVT::i16, Promote);
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::UINT_TO_FP, MVT::i8, Promote);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
|
|
|
|
setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom);
|
|
|
|
|
2007-12-20 00:44:13 +00:00
|
|
|
setOperationAction(ISD::BIT_CONVERT, MVT::i32, Legal);
|
|
|
|
setOperationAction(ISD::BIT_CONVERT, MVT::f32, Legal);
|
|
|
|
setOperationAction(ISD::BIT_CONVERT, MVT::i64, Legal);
|
|
|
|
setOperationAction(ISD::BIT_CONVERT, MVT::f64, Legal);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// We cannot sextinreg(i1). Expand to shifts.
|
|
|
|
setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Support label based line numbers.
|
2008-06-30 20:59:49 +00:00
|
|
|
setOperationAction(ISD::DBG_STOPPOINT, MVT::Other, Expand);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
|
|
|
// We want to legalize GlobalAddress and ConstantPool nodes into the
|
2007-12-04 22:23:35 +00:00
|
|
|
// appropriate instructions to materialize the address.
|
2008-11-21 02:56:16 +00:00
|
|
|
for (unsigned sctype = (unsigned) MVT::i8; sctype < (unsigned) MVT::f128;
|
2008-01-29 02:16:57 +00:00
|
|
|
++sctype) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = (MVT::SimpleValueType)sctype;
|
|
|
|
|
2008-12-29 03:23:36 +00:00
|
|
|
setOperationAction(ISD::GlobalAddress, VT, Custom);
|
|
|
|
setOperationAction(ISD::ConstantPool, VT, Custom);
|
|
|
|
setOperationAction(ISD::JumpTable, VT, Custom);
|
2008-01-29 02:16:57 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// RET must be custom lowered, to meet ABI requirements
|
|
|
|
setOperationAction(ISD::RET, MVT::Other, Custom);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// VASTART needs to be custom lowered to use the VarArgsFrameIndex
|
|
|
|
setOperationAction(ISD::VASTART , MVT::Other, Custom);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Use the default implementation.
|
|
|
|
setOperationAction(ISD::VAARG , MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::VACOPY , MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::VAEND , MVT::Other, Expand);
|
2008-07-16 17:17:29 +00:00
|
|
|
setOperationAction(ISD::STACKSAVE , MVT::Other, Expand);
|
2007-12-04 22:23:35 +00:00
|
|
|
setOperationAction(ISD::STACKRESTORE , MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand);
|
|
|
|
setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i64 , Expand);
|
|
|
|
|
|
|
|
// Cell SPU has instructions for converting between i64 and fp.
|
|
|
|
setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
|
|
|
|
setOperationAction(ISD::SINT_TO_FP, MVT::i64, Custom);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// To take advantage of the above i64 FP_TO_SINT, promote i32 FP_TO_UINT
|
|
|
|
setOperationAction(ISD::FP_TO_UINT, MVT::i32, Promote);
|
|
|
|
|
|
|
|
// BUILD_PAIR can't be handled natively, and should be expanded to shl/or
|
|
|
|
setOperationAction(ISD::BUILD_PAIR, MVT::i64, Expand);
|
|
|
|
|
|
|
|
// First set operation action for all vector types to expand. Then we
|
|
|
|
// will selectively turn on ones that can be effectively codegen'd.
|
|
|
|
addRegisterClass(MVT::v16i8, SPU::VECREGRegisterClass);
|
|
|
|
addRegisterClass(MVT::v8i16, SPU::VECREGRegisterClass);
|
|
|
|
addRegisterClass(MVT::v4i32, SPU::VECREGRegisterClass);
|
|
|
|
addRegisterClass(MVT::v2i64, SPU::VECREGRegisterClass);
|
|
|
|
addRegisterClass(MVT::v4f32, SPU::VECREGRegisterClass);
|
|
|
|
addRegisterClass(MVT::v2f64, SPU::VECREGRegisterClass);
|
|
|
|
|
2009-01-06 23:10:38 +00:00
|
|
|
// "Odd size" vector classes that we're willing to support:
|
|
|
|
addRegisterClass(MVT::v2i32, SPU::VECREGRegisterClass);
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
for (unsigned i = (unsigned)MVT::FIRST_VECTOR_VALUETYPE;
|
|
|
|
i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
|
|
|
|
MVT VT = (MVT::SimpleValueType)i;
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// add/sub are legal for all supported vector VT's.
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::ADD, VT, Legal);
|
|
|
|
setOperationAction(ISD::SUB, VT, Legal);
|
2007-12-04 22:23:35 +00:00
|
|
|
// mul has to be custom lowered.
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::MUL, VT, Legal);
|
2008-06-06 12:08:01 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::AND, VT, Legal);
|
|
|
|
setOperationAction(ISD::OR, VT, Legal);
|
|
|
|
setOperationAction(ISD::XOR, VT, Legal);
|
|
|
|
setOperationAction(ISD::LOAD, VT, Legal);
|
|
|
|
setOperationAction(ISD::SELECT, VT, Legal);
|
|
|
|
setOperationAction(ISD::STORE, VT, Legal);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// These operations need to be expanded:
|
2009-01-26 03:31:40 +00:00
|
|
|
setOperationAction(ISD::SDIV, VT, Expand);
|
|
|
|
setOperationAction(ISD::SREM, VT, Expand);
|
|
|
|
setOperationAction(ISD::UDIV, VT, Expand);
|
|
|
|
setOperationAction(ISD::UREM, VT, Expand);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// Custom lower build_vector, constant pool spills, insert and
|
|
|
|
// extract vector elements:
|
2008-06-06 12:08:01 +00:00
|
|
|
setOperationAction(ISD::BUILD_VECTOR, VT, Custom);
|
|
|
|
setOperationAction(ISD::ConstantPool, VT, Custom);
|
|
|
|
setOperationAction(ISD::SCALAR_TO_VECTOR, VT, Custom);
|
|
|
|
setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom);
|
|
|
|
setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom);
|
|
|
|
setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setOperationAction(ISD::AND, MVT::v16i8, Custom);
|
|
|
|
setOperationAction(ISD::OR, MVT::v16i8, Custom);
|
|
|
|
setOperationAction(ISD::XOR, MVT::v16i8, Custom);
|
|
|
|
setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v4f32, Custom);
|
2008-01-11 02:53:15 +00:00
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
setOperationAction(ISD::FDIV, MVT::v4f32, Legal);
|
2008-12-29 03:23:36 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
setShiftAmountType(MVT::i32);
|
2008-12-27 04:51:36 +00:00
|
|
|
setBooleanContents(ZeroOrNegativeOneBooleanContent);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
setStackPointerRegisterToSaveRestore(SPU::R1);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// We have target-specific dag combine patterns for the following nodes:
|
2008-01-29 02:16:57 +00:00
|
|
|
setTargetDAGCombine(ISD::ADD);
|
2008-02-23 18:41:37 +00:00
|
|
|
setTargetDAGCombine(ISD::ZERO_EXTEND);
|
|
|
|
setTargetDAGCombine(ISD::SIGN_EXTEND);
|
|
|
|
setTargetDAGCombine(ISD::ANY_EXTEND);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
computeRegisterProperties();
|
2008-11-22 23:50:42 +00:00
|
|
|
|
2008-12-09 03:37:19 +00:00
|
|
|
// Set pre-RA register scheduler default to BURR, which produces slightly
|
|
|
|
// better code than the default (could also be TDRR, but TargetLowering.h
|
|
|
|
// needs a mod to support that model):
|
|
|
|
setSchedulingPreference(SchedulingForRegPressure);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
SPUTargetLowering::getTargetNodeName(unsigned Opcode) const
|
|
|
|
{
|
|
|
|
if (node_names.empty()) {
|
|
|
|
node_names[(unsigned) SPUISD::RET_FLAG] = "SPUISD::RET_FLAG";
|
|
|
|
node_names[(unsigned) SPUISD::Hi] = "SPUISD::Hi";
|
|
|
|
node_names[(unsigned) SPUISD::Lo] = "SPUISD::Lo";
|
|
|
|
node_names[(unsigned) SPUISD::PCRelAddr] = "SPUISD::PCRelAddr";
|
2008-01-11 02:53:15 +00:00
|
|
|
node_names[(unsigned) SPUISD::AFormAddr] = "SPUISD::AFormAddr";
|
2008-01-29 02:16:57 +00:00
|
|
|
node_names[(unsigned) SPUISD::IndirectAddr] = "SPUISD::IndirectAddr";
|
2007-12-04 22:23:35 +00:00
|
|
|
node_names[(unsigned) SPUISD::LDRESULT] = "SPUISD::LDRESULT";
|
|
|
|
node_names[(unsigned) SPUISD::CALL] = "SPUISD::CALL";
|
|
|
|
node_names[(unsigned) SPUISD::SHUFB] = "SPUISD::SHUFB";
|
2008-11-22 23:50:42 +00:00
|
|
|
node_names[(unsigned) SPUISD::SHUFFLE_MASK] = "SPUISD::SHUFFLE_MASK";
|
2007-12-04 22:23:35 +00:00
|
|
|
node_names[(unsigned) SPUISD::CNTB] = "SPUISD::CNTB";
|
2008-12-29 03:23:36 +00:00
|
|
|
node_names[(unsigned) SPUISD::PREFSLOT2VEC] = "SPUISD::PREFSLOT2VEC";
|
2008-11-24 17:11:17 +00:00
|
|
|
node_names[(unsigned) SPUISD::VEC2PREFSLOT] = "SPUISD::VEC2PREFSLOT";
|
2008-02-23 18:41:37 +00:00
|
|
|
node_names[(unsigned) SPUISD::SHLQUAD_L_BITS] = "SPUISD::SHLQUAD_L_BITS";
|
|
|
|
node_names[(unsigned) SPUISD::SHLQUAD_L_BYTES] = "SPUISD::SHLQUAD_L_BYTES";
|
2007-12-04 22:23:35 +00:00
|
|
|
node_names[(unsigned) SPUISD::VEC_SHL] = "SPUISD::VEC_SHL";
|
|
|
|
node_names[(unsigned) SPUISD::VEC_SRL] = "SPUISD::VEC_SRL";
|
|
|
|
node_names[(unsigned) SPUISD::VEC_SRA] = "SPUISD::VEC_SRA";
|
|
|
|
node_names[(unsigned) SPUISD::VEC_ROTL] = "SPUISD::VEC_ROTL";
|
|
|
|
node_names[(unsigned) SPUISD::VEC_ROTR] = "SPUISD::VEC_ROTR";
|
2009-01-21 04:58:48 +00:00
|
|
|
node_names[(unsigned) SPUISD::ROTBYTES_LEFT] = "SPUISD::ROTBYTES_LEFT";
|
|
|
|
node_names[(unsigned) SPUISD::ROTBYTES_LEFT_BITS] =
|
|
|
|
"SPUISD::ROTBYTES_LEFT_BITS";
|
2008-06-02 22:18:03 +00:00
|
|
|
node_names[(unsigned) SPUISD::SELECT_MASK] = "SPUISD::SELECT_MASK";
|
2007-12-04 22:23:35 +00:00
|
|
|
node_names[(unsigned) SPUISD::SELB] = "SPUISD::SELB";
|
2009-01-15 04:41:47 +00:00
|
|
|
node_names[(unsigned) SPUISD::ADD64_MARKER] = "SPUISD::ADD64_MARKER";
|
|
|
|
node_names[(unsigned) SPUISD::SUB64_MARKER] = "SPUISD::SUB64_MARKER";
|
|
|
|
node_names[(unsigned) SPUISD::MUL64_MARKER] = "SPUISD::MUL64_MARKER";
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::map<unsigned, const char *>::iterator i = node_names.find(Opcode);
|
|
|
|
|
|
|
|
return ((i != node_names.end()) ? i->second : 0);
|
|
|
|
}
|
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Return the Cell SPU's SETCC result type
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-01 15:52:00 +00:00
|
|
|
MVT SPUTargetLowering::getSetCCResultType(MVT VT) const {
|
2008-12-27 04:51:36 +00:00
|
|
|
// i16 and i32 are valid SETCC result types
|
|
|
|
return ((VT == MVT::i8 || VT == MVT::i16 || VT == MVT::i32) ? VT : MVT::i32);
|
2008-03-10 16:58:52 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Calling convention code:
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SPUGenCallingConv.inc"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LowerOperation implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// Custom lower loads for CellSPU
|
|
|
|
/*!
|
|
|
|
All CellSPU loads and stores are aligned to 16-byte boundaries, so for elements
|
|
|
|
within a 16-byte block, we have to rotate to extract the requested element.
|
2008-12-04 03:02:42 +00:00
|
|
|
|
|
|
|
For extending loads, we also want to ensure that the following sequence is
|
|
|
|
emitted, e.g. for MVT::f32 extending load to MVT::f64:
|
|
|
|
|
|
|
|
\verbatim
|
2008-12-29 03:23:36 +00:00
|
|
|
%1 v16i8,ch = load
|
2008-12-04 03:02:42 +00:00
|
|
|
%2 v16i8,ch = rotate %1
|
2008-12-29 03:23:36 +00:00
|
|
|
%3 v4f8, ch = bitconvert %2
|
2008-12-04 03:02:42 +00:00
|
|
|
%4 f32 = vec2perfslot %3
|
|
|
|
%5 f64 = fp_extend %4
|
|
|
|
\endverbatim
|
|
|
|
*/
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerLOAD(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
|
2007-12-04 22:23:35 +00:00
|
|
|
LoadSDNode *LN = cast<LoadSDNode>(Op);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue the_chain = LN->getChain();
|
2008-12-27 04:51:36 +00:00
|
|
|
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
2008-12-04 03:02:42 +00:00
|
|
|
MVT InVT = LN->getMemoryVT();
|
|
|
|
MVT OutVT = Op.getValueType();
|
2007-12-04 22:23:35 +00:00
|
|
|
ISD::LoadExtType ExtType = LN->getExtensionType();
|
|
|
|
unsigned alignment = LN->getAlignment();
|
2008-12-27 04:51:36 +00:00
|
|
|
const valtype_map_s *vtm = getValueTypeMapEntry(InVT);
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
switch (LN->getAddressingMode()) {
|
|
|
|
case ISD::UNINDEXED: {
|
2008-12-27 04:51:36 +00:00
|
|
|
SDValue result;
|
|
|
|
SDValue basePtr = LN->getBasePtr();
|
|
|
|
SDValue rotate;
|
|
|
|
|
|
|
|
if (alignment == 16) {
|
|
|
|
ConstantSDNode *CN;
|
|
|
|
|
|
|
|
// Special cases for a known aligned load to simplify the base pointer
|
|
|
|
// and the rotation amount:
|
|
|
|
if (basePtr.getOpcode() == ISD::ADD
|
|
|
|
&& (CN = dyn_cast<ConstantSDNode > (basePtr.getOperand(1))) != 0) {
|
|
|
|
// Known offset into basePtr
|
|
|
|
int64_t offset = CN->getSExtValue();
|
|
|
|
int64_t rotamt = int64_t((offset & 0xf) - vtm->prefslot_byte);
|
|
|
|
|
|
|
|
if (rotamt < 0)
|
|
|
|
rotamt += 16;
|
|
|
|
|
|
|
|
rotate = DAG.getConstant(rotamt, MVT::i16);
|
|
|
|
|
|
|
|
// Simplify the base pointer for this case:
|
|
|
|
basePtr = basePtr.getOperand(0);
|
|
|
|
if ((offset & ~0xf) > 0) {
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant((offset & ~0xf), PtrVT));
|
|
|
|
}
|
|
|
|
} else if ((basePtr.getOpcode() == SPUISD::AFormAddr)
|
|
|
|
|| (basePtr.getOpcode() == SPUISD::IndirectAddr
|
|
|
|
&& basePtr.getOperand(0).getOpcode() == SPUISD::Hi
|
|
|
|
&& basePtr.getOperand(1).getOpcode() == SPUISD::Lo)) {
|
|
|
|
// Plain aligned a-form address: rotate into preferred slot
|
|
|
|
// Same for (SPUindirect (SPUhi ...), (SPUlo ...))
|
|
|
|
int64_t rotamt = -vtm->prefslot_byte;
|
|
|
|
if (rotamt < 0)
|
|
|
|
rotamt += 16;
|
|
|
|
rotate = DAG.getConstant(rotamt, MVT::i16);
|
2008-01-11 02:53:15 +00:00
|
|
|
} else {
|
2008-12-27 04:51:36 +00:00
|
|
|
// Offset the rotate amount by the basePtr and the preferred slot
|
|
|
|
// byte offset
|
|
|
|
int64_t rotamt = -vtm->prefslot_byte;
|
|
|
|
if (rotamt < 0)
|
|
|
|
rotamt += 16;
|
2009-02-04 20:06:27 +00:00
|
|
|
rotate = DAG.getNode(ISD::ADD, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
2008-01-30 02:55:46 +00:00
|
|
|
DAG.getConstant(rotamt, PtrVT));
|
2008-01-11 02:53:15 +00:00
|
|
|
}
|
2008-12-27 04:51:36 +00:00
|
|
|
} else {
|
|
|
|
// Unaligned load: must be more pessimistic about addressing modes:
|
|
|
|
if (basePtr.getOpcode() == ISD::ADD) {
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
|
|
|
unsigned VReg = RegInfo.createVirtualRegister(&SPU::R32CRegClass);
|
|
|
|
SDValue Flag;
|
|
|
|
|
|
|
|
SDValue Op0 = basePtr.getOperand(0);
|
|
|
|
SDValue Op1 = basePtr.getOperand(1);
|
|
|
|
|
|
|
|
if (isa<ConstantSDNode>(Op1)) {
|
|
|
|
// Convert the (add <ptr>, <const>) to an indirect address contained
|
|
|
|
// in a register. Note that this is done because we need to avoid
|
|
|
|
// creating a 0(reg) d-form address due to the SPU's block loads.
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Op0, Op1);
|
2009-02-04 20:06:27 +00:00
|
|
|
the_chain = DAG.getCopyToReg(the_chain, dl, VReg, basePtr, Flag);
|
|
|
|
basePtr = DAG.getCopyFromReg(the_chain, dl, VReg, PtrVT);
|
2008-12-27 04:51:36 +00:00
|
|
|
} else {
|
|
|
|
// Convert the (add <arg1>, <arg2>) to an indirect address, which
|
|
|
|
// will likely be lowered as a reg(reg) x-form address.
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Op0, Op1);
|
2008-12-27 04:51:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant(0, PtrVT));
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// Offset the rotate amount by the basePtr and the preferred slot
|
|
|
|
// byte offset
|
2009-02-04 20:06:27 +00:00
|
|
|
rotate = DAG.getNode(ISD::ADD, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant(-vtm->prefslot_byte, PtrVT));
|
2008-01-11 02:53:15 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// Re-emit as a v16i8 vector load
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getLoad(MVT::v16i8, dl, the_chain, basePtr,
|
2008-12-27 04:51:36 +00:00
|
|
|
LN->getSrcValue(), LN->getSrcValueOffset(),
|
|
|
|
LN->isVolatile(), 16);
|
|
|
|
|
|
|
|
// Update the chain
|
|
|
|
the_chain = result.getValue(1);
|
|
|
|
|
|
|
|
// Rotate into the preferred slot:
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(SPUISD::ROTBYTES_LEFT, dl, MVT::v16i8,
|
2008-12-27 04:51:36 +00:00
|
|
|
result.getValue(0), rotate);
|
|
|
|
|
2008-12-04 03:02:42 +00:00
|
|
|
// Convert the loaded v16i8 vector to the appropriate vector type
|
|
|
|
// specified by the operand:
|
|
|
|
MVT vecVT = MVT::getVectorVT(InVT, (128 / InVT.getSizeInBits()));
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(SPUISD::VEC2PREFSLOT, dl, InVT,
|
|
|
|
DAG.getNode(ISD::BIT_CONVERT, dl, vecVT, result));
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-12-04 03:02:42 +00:00
|
|
|
// Handle extending loads by extending the scalar result:
|
|
|
|
if (ExtType == ISD::SEXTLOAD) {
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(ISD::SIGN_EXTEND, dl, OutVT, result);
|
2008-12-04 03:02:42 +00:00
|
|
|
} else if (ExtType == ISD::ZEXTLOAD) {
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(ISD::ZERO_EXTEND, dl, OutVT, result);
|
2008-12-04 03:02:42 +00:00
|
|
|
} else if (ExtType == ISD::EXTLOAD) {
|
|
|
|
unsigned NewOpc = ISD::ANY_EXTEND;
|
2008-01-11 02:53:15 +00:00
|
|
|
|
2008-12-04 03:02:42 +00:00
|
|
|
if (OutVT.isFloatingPoint())
|
2009-01-26 03:37:41 +00:00
|
|
|
NewOpc = ISD::FP_EXTEND;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(NewOpc, dl, OutVT, result);
|
2008-01-11 02:53:15 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-04 03:02:42 +00:00
|
|
|
SDVTList retvts = DAG.getVTList(OutVT, MVT::Other);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue retops[2] = {
|
2008-01-17 20:38:41 +00:00
|
|
|
result,
|
2008-01-30 02:55:46 +00:00
|
|
|
the_chain
|
2008-01-17 20:38:41 +00:00
|
|
|
};
|
|
|
|
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(SPUISD::LDRESULT, dl, retvts,
|
2008-01-17 20:38:41 +00:00
|
|
|
retops, sizeof(retops) / sizeof(retops[0]));
|
2008-01-11 02:53:15 +00:00
|
|
|
return result;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
case ISD::PRE_INC:
|
|
|
|
case ISD::PRE_DEC:
|
|
|
|
case ISD::POST_INC:
|
|
|
|
case ISD::POST_DEC:
|
|
|
|
case ISD::LAST_INDEXED_MODE:
|
|
|
|
cerr << "LowerLOAD: Got a LoadSDNode with an addr mode other than "
|
|
|
|
"UNINDEXED\n";
|
|
|
|
cerr << (unsigned) LN->getAddressingMode() << "\n";
|
|
|
|
abort();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Custom lower stores for CellSPU
|
|
|
|
/*!
|
|
|
|
All CellSPU stores are aligned to 16-byte boundaries, so for elements
|
|
|
|
within a 16-byte block, we have to generate a shuffle to insert the
|
|
|
|
requested element into its place, then store the resulting block.
|
|
|
|
*/
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerSTORE(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
|
2007-12-04 22:23:35 +00:00
|
|
|
StoreSDNode *SN = cast<StoreSDNode>(Op);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Value = SN->getValue();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Value.getValueType();
|
|
|
|
MVT StVT = (!SN->isTruncatingStore() ? VT : SN->getMemoryVT());
|
|
|
|
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-01-11 02:53:15 +00:00
|
|
|
unsigned alignment = SN->getAlignment();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
switch (SN->getAddressingMode()) {
|
|
|
|
case ISD::UNINDEXED: {
|
2008-11-21 02:56:16 +00:00
|
|
|
// The vector type we really want to load from the 16-byte chunk.
|
2008-11-19 17:45:08 +00:00
|
|
|
MVT vecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits())),
|
|
|
|
stVecVT = MVT::getVectorVT(StVT, (128 / StVT.getSizeInBits()));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
SDValue alignLoadVec;
|
|
|
|
SDValue basePtr = SN->getBasePtr();
|
|
|
|
SDValue the_chain = SN->getChain();
|
|
|
|
SDValue insertEltOffs;
|
|
|
|
|
|
|
|
if (alignment == 16) {
|
|
|
|
ConstantSDNode *CN;
|
|
|
|
|
|
|
|
// Special cases for a known aligned load to simplify the base pointer
|
|
|
|
// and insertion byte:
|
|
|
|
if (basePtr.getOpcode() == ISD::ADD
|
|
|
|
&& (CN = dyn_cast<ConstantSDNode>(basePtr.getOperand(1))) != 0) {
|
|
|
|
// Known offset into basePtr
|
|
|
|
int64_t offset = CN->getSExtValue();
|
|
|
|
|
|
|
|
// Simplify the base pointer for this case:
|
|
|
|
basePtr = basePtr.getOperand(0);
|
2009-02-06 21:50:26 +00:00
|
|
|
insertEltOffs = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant((offset & 0xf), PtrVT));
|
|
|
|
|
|
|
|
if ((offset & ~0xf) > 0) {
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant((offset & ~0xf), PtrVT));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Otherwise, assume it's at byte 0 of basePtr
|
2009-02-06 21:50:26 +00:00
|
|
|
insertEltOffs = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant(0, PtrVT));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Unaligned load: must be more pessimistic about addressing modes:
|
|
|
|
if (basePtr.getOpcode() == ISD::ADD) {
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
|
|
|
unsigned VReg = RegInfo.createVirtualRegister(&SPU::R32CRegClass);
|
|
|
|
SDValue Flag;
|
|
|
|
|
|
|
|
SDValue Op0 = basePtr.getOperand(0);
|
|
|
|
SDValue Op1 = basePtr.getOperand(1);
|
|
|
|
|
|
|
|
if (isa<ConstantSDNode>(Op1)) {
|
|
|
|
// Convert the (add <ptr>, <const>) to an indirect address contained
|
|
|
|
// in a register. Note that this is done because we need to avoid
|
|
|
|
// creating a 0(reg) d-form address due to the SPU's block loads.
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Op0, Op1);
|
2009-02-04 20:06:27 +00:00
|
|
|
the_chain = DAG.getCopyToReg(the_chain, dl, VReg, basePtr, Flag);
|
|
|
|
basePtr = DAG.getCopyFromReg(the_chain, dl, VReg, PtrVT);
|
2008-12-27 04:51:36 +00:00
|
|
|
} else {
|
|
|
|
// Convert the (add <arg1>, <arg2>) to an indirect address, which
|
|
|
|
// will likely be lowered as a reg(reg) x-form address.
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Op0, Op1);
|
2008-12-27 04:51:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
basePtr = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant(0, PtrVT));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insertion point is solely determined by basePtr's contents
|
2009-02-04 20:06:27 +00:00
|
|
|
insertEltOffs = DAG.getNode(ISD::ADD, dl, PtrVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
basePtr,
|
|
|
|
DAG.getConstant(0, PtrVT));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Re-emit as a v16i8 vector load
|
2009-02-04 20:06:27 +00:00
|
|
|
alignLoadVec = DAG.getLoad(MVT::v16i8, dl, the_chain, basePtr,
|
2008-12-27 04:51:36 +00:00
|
|
|
SN->getSrcValue(), SN->getSrcValueOffset(),
|
|
|
|
SN->isVolatile(), 16);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// Update the chain
|
|
|
|
the_chain = alignLoadVec.getValue(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-01-11 02:53:15 +00:00
|
|
|
LoadSDNode *LN = cast<LoadSDNode>(alignLoadVec);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue theValue = SN->getValue();
|
|
|
|
SDValue result;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
if (StVT != VT
|
2008-01-30 02:55:46 +00:00
|
|
|
&& (theValue.getOpcode() == ISD::AssertZext
|
|
|
|
|| theValue.getOpcode() == ISD::AssertSext)) {
|
2007-12-04 22:23:35 +00:00
|
|
|
// Drill down and get the value for zero- and sign-extended
|
|
|
|
// quantities
|
2008-07-16 17:17:29 +00:00
|
|
|
theValue = theValue.getOperand(0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 02:53:15 +00:00
|
|
|
// If the base pointer is already a D-form address, then just create
|
|
|
|
// a new D-form address with a slot offset and the orignal base pointer.
|
|
|
|
// Otherwise generate a D-form address with the slot offset relative
|
|
|
|
// to the stack pointer, which is always aligned.
|
2008-12-27 04:51:36 +00:00
|
|
|
#if !defined(NDEBUG)
|
|
|
|
if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) {
|
|
|
|
cerr << "CellSPU LowerSTORE: basePtr = ";
|
|
|
|
basePtr.getNode()->dump(&DAG);
|
|
|
|
cerr << "\n";
|
|
|
|
}
|
|
|
|
#endif
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-19 15:24:16 +00:00
|
|
|
SDValue insertEltOp =
|
2009-02-04 20:06:27 +00:00
|
|
|
DAG.getNode(SPUISD::SHUFFLE_MASK, dl, vecVT, insertEltOffs);
|
2008-11-19 17:45:08 +00:00
|
|
|
SDValue vectorizeOp =
|
2009-02-04 20:06:27 +00:00
|
|
|
DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, vecVT, theValue);
|
2008-11-19 15:24:16 +00:00
|
|
|
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getNode(SPUISD::SHUFB, dl, vecVT,
|
2009-01-26 03:37:41 +00:00
|
|
|
vectorizeOp, alignLoadVec,
|
2009-02-04 20:06:27 +00:00
|
|
|
DAG.getNode(ISD::BIT_CONVERT, dl,
|
|
|
|
MVT::v4i32, insertEltOp));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 20:06:27 +00:00
|
|
|
result = DAG.getStore(the_chain, dl, result, basePtr,
|
2007-12-04 22:23:35 +00:00
|
|
|
LN->getSrcValue(), LN->getSrcValueOffset(),
|
|
|
|
LN->isVolatile(), LN->getAlignment());
|
|
|
|
|
2008-12-04 17:16:59 +00:00
|
|
|
#if 0 && !defined(NDEBUG)
|
2008-11-19 15:24:16 +00:00
|
|
|
if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) {
|
|
|
|
const SDValue ¤tRoot = DAG.getRoot();
|
|
|
|
|
|
|
|
DAG.setRoot(result);
|
|
|
|
cerr << "------- CellSPU:LowerStore result:\n";
|
|
|
|
DAG.dump();
|
|
|
|
cerr << "-------\n";
|
|
|
|
DAG.setRoot(currentRoot);
|
|
|
|
}
|
|
|
|
#endif
|
2008-12-02 19:53:53 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
return result;
|
|
|
|
/*UNREACHED*/
|
|
|
|
}
|
|
|
|
case ISD::PRE_INC:
|
|
|
|
case ISD::PRE_DEC:
|
|
|
|
case ISD::POST_INC:
|
|
|
|
case ISD::POST_DEC:
|
|
|
|
case ISD::LAST_INDEXED_MODE:
|
|
|
|
cerr << "LowerLOAD: Got a LoadSDNode with an addr mode other than "
|
|
|
|
"UNINDEXED\n";
|
|
|
|
cerr << (unsigned) SN->getAddressingMode() << "\n";
|
|
|
|
abort();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 04:41:47 +00:00
|
|
|
//! Generate the address of a constant pool entry.
|
|
|
|
SDValue
|
2008-07-27 21:46:04 +00:00
|
|
|
LowerConstantPool(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = Op.getValueType();
|
2007-12-04 22:23:35 +00:00
|
|
|
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
|
|
|
|
Constant *C = CP->getConstVal();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CPI = DAG.getTargetConstantPool(C, PtrVT, CP->getAlignment());
|
|
|
|
SDValue Zero = DAG.getConstant(0, PtrVT);
|
2008-01-11 02:53:15 +00:00
|
|
|
const TargetMachine &TM = DAG.getTarget();
|
2009-02-06 21:50:26 +00:00
|
|
|
// FIXME there is no actual debug info here
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::Static) {
|
|
|
|
if (!ST->usingLargeMem()) {
|
2008-07-27 21:46:04 +00:00
|
|
|
// Just return the SDValue with the constant pool address in it.
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::AFormAddr, dl, PtrVT, CPI, Zero);
|
2007-12-04 22:23:35 +00:00
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
SDValue Hi = DAG.getNode(SPUISD::Hi, dl, PtrVT, CPI, Zero);
|
|
|
|
SDValue Lo = DAG.getNode(SPUISD::Lo, dl, PtrVT, CPI, Zero);
|
|
|
|
return DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Hi, Lo);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(0 &&
|
2008-08-31 15:37:04 +00:00
|
|
|
"LowerConstantPool: Relocation model other than static"
|
|
|
|
" not supported.");
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 04:41:47 +00:00
|
|
|
//! Alternate entry point for generating the address of a constant pool entry
|
|
|
|
SDValue
|
|
|
|
SPU::LowerConstantPool(SDValue Op, SelectionDAG &DAG, const SPUTargetMachine &TM) {
|
|
|
|
return ::LowerConstantPool(Op, DAG, TM.getSubtargetImpl());
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerJumpTable(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = Op.getValueType();
|
2007-12-04 22:23:35 +00:00
|
|
|
JumpTableSDNode *JT = cast<JumpTableSDNode>(Op);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PtrVT);
|
|
|
|
SDValue Zero = DAG.getConstant(0, PtrVT);
|
2007-12-04 22:23:35 +00:00
|
|
|
const TargetMachine &TM = DAG.getTarget();
|
2009-02-06 21:50:26 +00:00
|
|
|
// FIXME there is no actual debug info here
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
if (TM.getRelocationModel() == Reloc::Static) {
|
2008-02-23 18:41:37 +00:00
|
|
|
if (!ST->usingLargeMem()) {
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::AFormAddr, dl, PtrVT, JTI, Zero);
|
2008-02-23 18:41:37 +00:00
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
SDValue Hi = DAG.getNode(SPUISD::Hi, dl, PtrVT, JTI, Zero);
|
|
|
|
SDValue Lo = DAG.getNode(SPUISD::Lo, dl, PtrVT, JTI, Zero);
|
|
|
|
return DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Hi, Lo);
|
2008-02-23 18:41:37 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(0 &&
|
|
|
|
"LowerJumpTable: Relocation model other than static not supported.");
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerGlobalAddress(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = Op.getValueType();
|
2007-12-04 22:23:35 +00:00
|
|
|
GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op);
|
|
|
|
GlobalValue *GV = GSDN->getGlobal();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue GA = DAG.getTargetGlobalAddress(GV, PtrVT, GSDN->getOffset());
|
2007-12-04 22:23:35 +00:00
|
|
|
const TargetMachine &TM = DAG.getTarget();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Zero = DAG.getConstant(0, PtrVT);
|
2009-02-06 21:50:26 +00:00
|
|
|
// FIXME there is no actual debug info here
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
if (TM.getRelocationModel() == Reloc::Static) {
|
2008-01-29 02:16:57 +00:00
|
|
|
if (!ST->usingLargeMem()) {
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::AFormAddr, dl, PtrVT, GA, Zero);
|
2008-01-29 02:16:57 +00:00
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
SDValue Hi = DAG.getNode(SPUISD::Hi, dl, PtrVT, GA, Zero);
|
|
|
|
SDValue Lo = DAG.getNode(SPUISD::Lo, dl, PtrVT, GA, Zero);
|
|
|
|
return DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, Hi, Lo);
|
2008-01-29 02:16:57 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
} else {
|
|
|
|
cerr << "LowerGlobalAddress: Relocation model other than static not "
|
2008-01-30 02:55:46 +00:00
|
|
|
<< "supported.\n";
|
2007-12-04 22:23:35 +00:00
|
|
|
abort();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-02-14 18:43:04 +00:00
|
|
|
//! Custom lower double precision floating point constants
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerConstantFP(SDValue Op, SelectionDAG &DAG) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2009-02-06 21:50:26 +00:00
|
|
|
// FIXME there is no actual debug info here
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-02-14 18:43:04 +00:00
|
|
|
if (VT == MVT::f64) {
|
2008-12-01 17:56:02 +00:00
|
|
|
ConstantFPSDNode *FP = cast<ConstantFPSDNode>(Op.getNode());
|
|
|
|
|
|
|
|
assert((FP != 0) &&
|
|
|
|
"LowerConstantFP: Node is not ConstantFPSDNode");
|
2008-12-29 03:23:36 +00:00
|
|
|
|
2007-12-19 20:15:47 +00:00
|
|
|
uint64_t dbits = DoubleToBits(FP->getValueAPF().convertToDouble());
|
2008-12-01 17:56:02 +00:00
|
|
|
SDValue T = DAG.getConstant(dbits, MVT::i64);
|
2009-02-22 23:36:09 +00:00
|
|
|
SDValue Tvec = DAG.getBUILD_VECTOR(MVT::v2i64, dl, T, T);
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::VEC2PREFSLOT, dl, VT,
|
2009-02-07 00:55:49 +00:00
|
|
|
DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v2f64, Tvec));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerFORMAL_ARGUMENTS(SDValue Op, SelectionDAG &DAG, int &VarArgsFrameIndex)
|
2007-12-04 22:23:35 +00:00
|
|
|
{
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
2007-12-31 04:13:23 +00:00
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
2008-10-30 01:51:48 +00:00
|
|
|
SmallVector<SDValue, 48> ArgValues;
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Root = Op.getOperand(0);
|
2008-09-12 16:56:44 +00:00
|
|
|
bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() != 0;
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
const unsigned *ArgRegs = SPURegisterInfo::getArgRegs();
|
|
|
|
const unsigned NumArgRegs = SPURegisterInfo::getNumArgRegs();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned ArgOffset = SPUFrameInfo::minStackSize();
|
|
|
|
unsigned ArgRegIdx = 0;
|
|
|
|
unsigned StackSlotSize = SPUFrameInfo::stackSlotSize();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Add DAG nodes to load the arguments or copy them out of registers.
|
2008-08-31 15:37:04 +00:00
|
|
|
for (unsigned ArgNo = 0, e = Op.getNode()->getNumValues() - 1;
|
|
|
|
ArgNo != e; ++ArgNo) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ObjectVT = Op.getValue(ArgNo).getValueType();
|
|
|
|
unsigned ObjSize = ObjectVT.getSizeInBits()/8;
|
2008-10-30 01:51:48 +00:00
|
|
|
SDValue ArgVal;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-10-30 01:51:48 +00:00
|
|
|
if (ArgRegIdx < NumArgRegs) {
|
|
|
|
const TargetRegisterClass *ArgRegClass;
|
|
|
|
|
|
|
|
switch (ObjectVT.getSimpleVT()) {
|
|
|
|
default: {
|
2008-11-21 02:56:16 +00:00
|
|
|
cerr << "LowerFORMAL_ARGUMENTS Unhandled argument type: "
|
|
|
|
<< ObjectVT.getMVTString()
|
|
|
|
<< "\n";
|
|
|
|
abort();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::i8:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::R8CRegClass;
|
|
|
|
break;
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::i16:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::R16CRegClass;
|
|
|
|
break;
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::i32:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::R32CRegClass;
|
|
|
|
break;
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::i64:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::R64CRegClass;
|
|
|
|
break;
|
2009-01-06 03:36:14 +00:00
|
|
|
case MVT::i128:
|
|
|
|
ArgRegClass = &SPU::GPRCRegClass;
|
|
|
|
break;
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::f32:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::R32FPRegClass;
|
|
|
|
break;
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::f64:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::R64FPRegClass;
|
|
|
|
break;
|
2008-10-30 01:51:48 +00:00
|
|
|
case MVT::v2f64:
|
|
|
|
case MVT::v4f32:
|
|
|
|
case MVT::v2i64:
|
|
|
|
case MVT::v4i32:
|
|
|
|
case MVT::v8i16:
|
|
|
|
case MVT::v16i8:
|
2008-11-21 02:56:16 +00:00
|
|
|
ArgRegClass = &SPU::VECREGRegClass;
|
|
|
|
break;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-10-30 01:51:48 +00:00
|
|
|
unsigned VReg = RegInfo.createVirtualRegister(ArgRegClass);
|
|
|
|
RegInfo.addLiveIn(ArgRegs[ArgRegIdx], VReg);
|
2009-02-04 20:06:27 +00:00
|
|
|
ArgVal = DAG.getCopyFromReg(Root, dl, VReg, ObjectVT);
|
2008-10-30 01:51:48 +00:00
|
|
|
++ArgRegIdx;
|
|
|
|
} else {
|
|
|
|
// We need to load the argument to a virtual register if we determined
|
|
|
|
// above that we ran out of physical registers of the appropriate type
|
|
|
|
// or we're forced to do vararg
|
2008-02-13 07:35:30 +00:00
|
|
|
int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
|
2009-02-04 20:06:27 +00:00
|
|
|
ArgVal = DAG.getLoad(ObjectVT, dl, Root, FIN, NULL, 0);
|
2007-12-04 22:23:35 +00:00
|
|
|
ArgOffset += StackSlotSize;
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
ArgValues.push_back(ArgVal);
|
2008-10-30 01:51:48 +00:00
|
|
|
// Update the chain
|
|
|
|
Root = ArgVal.getOperand(0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-10-30 01:51:48 +00:00
|
|
|
// vararg handling:
|
2007-12-04 22:23:35 +00:00
|
|
|
if (isVarArg) {
|
2008-10-30 01:51:48 +00:00
|
|
|
// unsigned int ptr_size = PtrVT.getSizeInBits() / 8;
|
|
|
|
// We will spill (79-3)+1 registers to the stack
|
|
|
|
SmallVector<SDValue, 79-3+1> MemOps;
|
|
|
|
|
|
|
|
// Create the frame slot
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
for (; ArgRegIdx != NumArgRegs; ++ArgRegIdx) {
|
2008-10-30 01:51:48 +00:00
|
|
|
VarArgsFrameIndex = MFI->CreateFixedObject(StackSlotSize, ArgOffset);
|
|
|
|
SDValue FIN = DAG.getFrameIndex(VarArgsFrameIndex, PtrVT);
|
|
|
|
SDValue ArgVal = DAG.getRegister(ArgRegs[ArgRegIdx], MVT::v16i8);
|
2009-02-04 20:06:27 +00:00
|
|
|
SDValue Store = DAG.getStore(Root, dl, ArgVal, FIN, NULL, 0);
|
2008-10-30 01:51:48 +00:00
|
|
|
Root = Store.getOperand(0);
|
2007-12-04 22:23:35 +00:00
|
|
|
MemOps.push_back(Store);
|
2008-10-30 01:51:48 +00:00
|
|
|
|
|
|
|
// Increment address by stack slot size for the next stored argument
|
|
|
|
ArgOffset += StackSlotSize;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
if (!MemOps.empty())
|
2009-02-04 20:06:27 +00:00
|
|
|
Root = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
|
|
|
&MemOps[0], MemOps.size());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
ArgValues.push_back(Root);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Return the new list of results.
|
2009-02-04 20:06:27 +00:00
|
|
|
return DAG.getNode(ISD::MERGE_VALUES, dl, Op.getNode()->getVTList(),
|
2008-12-01 11:41:29 +00:00
|
|
|
&ArgValues[0], ArgValues.size());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// isLSAAddress - Return the immediate to use if the specified
|
|
|
|
/// value is representable as a LSA address.
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDNode *isLSAAddress(SDValue Op, SelectionDAG &DAG) {
|
2008-11-11 03:06:06 +00:00
|
|
|
ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op);
|
2007-12-04 22:23:35 +00:00
|
|
|
if (!C) return 0;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-09-12 16:56:44 +00:00
|
|
|
int Addr = C->getZExtValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
if ((Addr & 3) != 0 || // Low 2 bits are implicitly zero.
|
|
|
|
(Addr << 14 >> 14) != Addr)
|
|
|
|
return 0; // Top 14 bits have to be sext of immediate.
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-09-12 16:56:44 +00:00
|
|
|
return DAG.getConstant((int)C->getZExtValue() >> 2, MVT::i32).getNode();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-06 23:10:38 +00:00
|
|
|
static SDValue
|
2008-07-27 21:46:04 +00:00
|
|
|
LowerCALL(SDValue Op, SelectionDAG &DAG, const SPUSubtarget *ST) {
|
2008-09-13 01:54:27 +00:00
|
|
|
CallSDNode *TheCall = cast<CallSDNode>(Op.getNode());
|
|
|
|
SDValue Chain = TheCall->getChain();
|
|
|
|
SDValue Callee = TheCall->getCallee();
|
|
|
|
unsigned NumOps = TheCall->getNumArgs();
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned StackSlotSize = SPUFrameInfo::stackSlotSize();
|
|
|
|
const unsigned *ArgRegs = SPURegisterInfo::getArgRegs();
|
|
|
|
const unsigned NumArgRegs = SPURegisterInfo::getNumArgRegs();
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = TheCall->getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// Handy pointer type
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Accumulate how many bytes are to be pushed on the stack, including the
|
|
|
|
// linkage area, and parameter passing area. According to the SPU ABI,
|
|
|
|
// we minimally need space for [LR] and [SP]
|
|
|
|
unsigned NumStackBytes = SPUFrameInfo::minStackSize();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Set up a copy of the stack pointer for use loading and storing any
|
|
|
|
// arguments that may not fit in the registers available for argument
|
|
|
|
// passing.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue StackPtr = DAG.getRegister(SPU::R1, MVT::i32);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Figure out which arguments are going to go in registers, and which in
|
|
|
|
// memory.
|
|
|
|
unsigned ArgOffset = SPUFrameInfo::minStackSize(); // Just below [LR]
|
|
|
|
unsigned ArgRegIdx = 0;
|
|
|
|
|
|
|
|
// Keep track of registers passing arguments
|
2008-07-27 21:46:04 +00:00
|
|
|
std::vector<std::pair<unsigned, SDValue> > RegsToPass;
|
2007-12-04 22:23:35 +00:00
|
|
|
// And the arguments passed on the stack
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> MemOpChains;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0; i != NumOps; ++i) {
|
2008-09-13 01:54:27 +00:00
|
|
|
SDValue Arg = TheCall->getArg(i);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// PtrOff will be used to store the current argument to the stack if a
|
|
|
|
// register cannot be found for it.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue PtrOff = DAG.getConstant(ArgOffset, StackPtr.getValueType());
|
2009-02-04 20:06:27 +00:00
|
|
|
PtrOff = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, PtrOff);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (Arg.getValueType().getSimpleVT()) {
|
2007-12-04 22:23:35 +00:00
|
|
|
default: assert(0 && "Unexpected ValueType for argument!");
|
2009-01-06 03:36:14 +00:00
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
|
|
|
case MVT::i128:
|
|
|
|
if (ArgRegIdx != NumArgRegs) {
|
|
|
|
RegsToPass.push_back(std::make_pair(ArgRegs[ArgRegIdx++], Arg));
|
|
|
|
} else {
|
2009-02-04 20:06:27 +00:00
|
|
|
MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff, NULL, 0));
|
2008-01-30 02:55:46 +00:00
|
|
|
ArgOffset += StackSlotSize;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
|
|
|
if (ArgRegIdx != NumArgRegs) {
|
|
|
|
RegsToPass.push_back(std::make_pair(ArgRegs[ArgRegIdx++], Arg));
|
|
|
|
} else {
|
2009-02-04 20:06:27 +00:00
|
|
|
MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff, NULL, 0));
|
2008-01-30 02:55:46 +00:00
|
|
|
ArgOffset += StackSlotSize;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-12-04 21:01:44 +00:00
|
|
|
case MVT::v2i64:
|
|
|
|
case MVT::v2f64:
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::v4f32:
|
|
|
|
case MVT::v4i32:
|
|
|
|
case MVT::v8i16:
|
|
|
|
case MVT::v16i8:
|
|
|
|
if (ArgRegIdx != NumArgRegs) {
|
|
|
|
RegsToPass.push_back(std::make_pair(ArgRegs[ArgRegIdx++], Arg));
|
|
|
|
} else {
|
2009-02-04 20:06:27 +00:00
|
|
|
MemOpChains.push_back(DAG.getStore(Chain, dl, Arg, PtrOff, NULL, 0));
|
2008-01-30 02:55:46 +00:00
|
|
|
ArgOffset += StackSlotSize;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update number of stack bytes actually used, insert a call sequence start
|
|
|
|
NumStackBytes = (ArgOffset - SPUFrameInfo::minStackSize());
|
2008-10-11 22:08:30 +00:00
|
|
|
Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumStackBytes,
|
|
|
|
true));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
if (!MemOpChains.empty()) {
|
|
|
|
// Adjust the stack pointer for the stack arguments.
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2007-12-04 22:23:35 +00:00
|
|
|
&MemOpChains[0], MemOpChains.size());
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Build a sequence of copy-to-reg nodes chained together with token chain
|
|
|
|
// and flag operands which copy the outgoing args into the appropriate regs.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InFlag;
|
2007-12-04 22:23:35 +00:00
|
|
|
for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
|
|
|
|
RegsToPass[i].second, InFlag);
|
2007-12-04 22:23:35 +00:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned CallOpc = SPUISD::CALL;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-09-16 21:48:12 +00:00
|
|
|
// If the callee is a GlobalAddress/ExternalSymbol node (quite common, every
|
|
|
|
// direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol
|
|
|
|
// node so that legalize doesn't hack it.
|
2008-11-11 03:06:06 +00:00
|
|
|
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) {
|
2007-12-04 22:23:35 +00:00
|
|
|
GlobalValue *GV = G->getGlobal();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT CalleeVT = Callee.getValueType();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Zero = DAG.getConstant(0, PtrVT);
|
|
|
|
SDValue GA = DAG.getTargetGlobalAddress(GV, CalleeVT);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-01-11 02:53:15 +00:00
|
|
|
if (!ST->usingLargeMem()) {
|
|
|
|
// Turn calls to targets that are defined (i.e., have bodies) into BRSL
|
|
|
|
// style calls, otherwise, external symbols are BRASL calls. This assumes
|
|
|
|
// that declared/defined symbols are in the same compilation unit and can
|
|
|
|
// be reached through PC-relative jumps.
|
|
|
|
//
|
|
|
|
// NOTE:
|
|
|
|
// This may be an unsafe assumption for JIT and really large compilation
|
|
|
|
// units.
|
|
|
|
if (GV->isDeclaration()) {
|
2009-02-06 21:50:26 +00:00
|
|
|
Callee = DAG.getNode(SPUISD::AFormAddr, dl, CalleeVT, GA, Zero);
|
2008-01-11 02:53:15 +00:00
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
Callee = DAG.getNode(SPUISD::PCRelAddr, dl, CalleeVT, GA, Zero);
|
2008-01-11 02:53:15 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
} else {
|
2008-01-11 02:53:15 +00:00
|
|
|
// "Large memory" mode: Turn all calls into indirect calls with a X-form
|
|
|
|
// address pairs:
|
2009-02-06 21:50:26 +00:00
|
|
|
Callee = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, GA, Zero);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-12-29 03:23:36 +00:00
|
|
|
} else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) {
|
|
|
|
MVT CalleeVT = Callee.getValueType();
|
|
|
|
SDValue Zero = DAG.getConstant(0, PtrVT);
|
|
|
|
SDValue ExtSym = DAG.getTargetExternalSymbol(S->getSymbol(),
|
|
|
|
Callee.getValueType());
|
|
|
|
|
|
|
|
if (!ST->usingLargeMem()) {
|
2009-02-06 21:50:26 +00:00
|
|
|
Callee = DAG.getNode(SPUISD::AFormAddr, dl, CalleeVT, ExtSym, Zero);
|
2008-12-29 03:23:36 +00:00
|
|
|
} else {
|
2009-02-06 21:50:26 +00:00
|
|
|
Callee = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT, ExtSym, Zero);
|
2008-12-29 03:23:36 +00:00
|
|
|
}
|
|
|
|
} else if (SDNode *Dest = isLSAAddress(Callee, DAG)) {
|
2007-12-04 22:23:35 +00:00
|
|
|
// If this is an absolute destination address that appears to be a legal
|
|
|
|
// local store address, use the munged value.
|
2008-07-27 21:46:04 +00:00
|
|
|
Callee = SDValue(Dest, 0);
|
2008-01-11 02:53:15 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
Ops.push_back(Chain);
|
|
|
|
Ops.push_back(Callee);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Add argument registers to the end of the list so that they are known live
|
|
|
|
// into the call.
|
|
|
|
for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i)
|
2008-07-16 17:17:29 +00:00
|
|
|
Ops.push_back(DAG.getRegister(RegsToPass[i].first,
|
2007-12-04 22:23:35 +00:00
|
|
|
RegsToPass[i].second.getValueType()));
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (InFlag.getNode())
|
2007-12-04 22:23:35 +00:00
|
|
|
Ops.push_back(InFlag);
|
2008-07-02 17:40:58 +00:00
|
|
|
// Returns a chain and a flag for retval copy to use.
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getNode(CallOpc, dl, DAG.getVTList(MVT::Other, MVT::Flag),
|
2008-07-02 17:40:58 +00:00
|
|
|
&Ops[0], Ops.size());
|
2007-12-04 22:23:35 +00:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
2008-10-11 22:08:30 +00:00
|
|
|
Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumStackBytes, true),
|
|
|
|
DAG.getIntPtrConstant(0, true), InFlag);
|
2008-09-13 01:54:27 +00:00
|
|
|
if (TheCall->getValueType(0) != MVT::Other)
|
2008-02-05 22:44:06 +00:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ResultVals[3];
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned NumResults = 0;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// If the call has results, copy the values out of the ret val registers.
|
2008-09-13 01:54:27 +00:00
|
|
|
switch (TheCall->getValueType(0).getSimpleVT()) {
|
2007-12-04 22:23:35 +00:00
|
|
|
default: assert(0 && "Unexpected ret value!");
|
|
|
|
case MVT::Other: break;
|
|
|
|
case MVT::i32:
|
2008-09-13 01:54:27 +00:00
|
|
|
if (TheCall->getValueType(1) == MVT::i32) {
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R4,
|
|
|
|
MVT::i32, InFlag).getValue(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
ResultVals[0] = Chain.getValue(0);
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R3, MVT::i32,
|
2007-12-04 22:23:35 +00:00
|
|
|
Chain.getValue(2)).getValue(1);
|
|
|
|
ResultVals[1] = Chain.getValue(0);
|
|
|
|
NumResults = 2;
|
|
|
|
} else {
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R3, MVT::i32,
|
|
|
|
InFlag).getValue(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
ResultVals[0] = Chain.getValue(0);
|
|
|
|
NumResults = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MVT::i64:
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R3, MVT::i64,
|
|
|
|
InFlag).getValue(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
ResultVals[0] = Chain.getValue(0);
|
|
|
|
NumResults = 1;
|
|
|
|
break;
|
2009-01-06 03:36:14 +00:00
|
|
|
case MVT::i128:
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R3, MVT::i128,
|
|
|
|
InFlag).getValue(1);
|
2009-01-06 03:36:14 +00:00
|
|
|
ResultVals[0] = Chain.getValue(0);
|
|
|
|
NumResults = 1;
|
|
|
|
break;
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R3, TheCall->getValueType(0),
|
2007-12-04 22:23:35 +00:00
|
|
|
InFlag).getValue(1);
|
|
|
|
ResultVals[0] = Chain.getValue(0);
|
|
|
|
NumResults = 1;
|
|
|
|
break;
|
|
|
|
case MVT::v2f64:
|
2008-12-04 21:01:44 +00:00
|
|
|
case MVT::v2i64:
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::v4f32:
|
|
|
|
case MVT::v4i32:
|
|
|
|
case MVT::v8i16:
|
|
|
|
case MVT::v16i8:
|
2009-02-04 20:06:27 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, SPU::R3, TheCall->getValueType(0),
|
2007-12-04 22:23:35 +00:00
|
|
|
InFlag).getValue(1);
|
|
|
|
ResultVals[0] = Chain.getValue(0);
|
|
|
|
NumResults = 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-07-02 17:40:58 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// If the function returns void, just return the chain.
|
|
|
|
if (NumResults == 0)
|
|
|
|
return Chain;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Otherwise, merge everything together with a MERGE_VALUES node.
|
|
|
|
ResultVals[NumResults++] = Chain;
|
2009-02-04 20:06:27 +00:00
|
|
|
SDValue Res = DAG.getMergeValues(ResultVals, NumResults, dl);
|
2008-08-26 22:36:50 +00:00
|
|
|
return Res.getValue(Op.getResNo());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerRET(SDValue Op, SelectionDAG &DAG, TargetMachine &TM) {
|
2007-12-04 22:23:35 +00:00
|
|
|
SmallVector<CCValAssign, 16> RVLocs;
|
|
|
|
unsigned CC = DAG.getMachineFunction().getFunction()->getCallingConv();
|
|
|
|
bool isVarArg = DAG.getMachineFunction().getFunction()->isVarArg();
|
2009-02-04 23:02:30 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
CCState CCInfo(CC, isVarArg, TM, RVLocs);
|
2008-08-28 21:40:38 +00:00
|
|
|
CCInfo.AnalyzeReturn(Op.getNode(), RetCC_SPU);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// If this is the first return lowered for this function, add the regs to the
|
|
|
|
// liveout set for the function.
|
2007-12-31 04:13:23 +00:00
|
|
|
if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
|
2007-12-04 22:23:35 +00:00
|
|
|
for (unsigned i = 0; i != RVLocs.size(); ++i)
|
2007-12-31 04:13:23 +00:00
|
|
|
DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg());
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Chain = Op.getOperand(0);
|
|
|
|
SDValue Flag;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Copy the result values into the output registers.
|
|
|
|
for (unsigned i = 0; i != RVLocs.size(); ++i) {
|
|
|
|
CCValAssign &VA = RVLocs[i];
|
|
|
|
assert(VA.isRegLoc() && "Can only return in registers!");
|
2009-02-04 23:02:30 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(),
|
|
|
|
Op.getOperand(i*2+1), Flag);
|
2007-12-04 22:23:35 +00:00
|
|
|
Flag = Chain.getValue(1);
|
|
|
|
}
|
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Flag.getNode())
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(SPUISD::RET_FLAG, dl, MVT::Other, Chain, Flag);
|
2007-12-04 22:23:35 +00:00
|
|
|
else
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(SPUISD::RET_FLAG, dl, MVT::Other, Chain);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Vector related lowering:
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static ConstantSDNode *
|
|
|
|
getVecImm(SDNode *N) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue OpVal(0, 0);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Check to see if this buildvec has a single non-undef value in its elements.
|
|
|
|
for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) {
|
|
|
|
if (N->getOperand(i).getOpcode() == ISD::UNDEF) continue;
|
2008-08-28 21:40:38 +00:00
|
|
|
if (OpVal.getNode() == 0)
|
2007-12-04 22:23:35 +00:00
|
|
|
OpVal = N->getOperand(i);
|
|
|
|
else if (OpVal != N->getOperand(i))
|
|
|
|
return 0;
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (OpVal.getNode() != 0) {
|
2008-11-11 03:06:06 +00:00
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) {
|
2007-12-04 22:23:35 +00:00
|
|
|
return CN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; // All UNDEF: use implicit def.; not Constant node
|
|
|
|
}
|
|
|
|
|
|
|
|
/// get_vec_i18imm - Test if this vector is a vector filled with the same value
|
|
|
|
/// and the value fits into an unsigned 18-bit constant, and if so, return the
|
|
|
|
/// constant
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_vec_u18imm(SDNode *N, SelectionDAG &DAG,
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ValueType) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-09-12 16:56:44 +00:00
|
|
|
uint64_t Value = CN->getZExtValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
if (ValueType == MVT::i64) {
|
2008-09-12 16:56:44 +00:00
|
|
|
uint64_t UValue = CN->getZExtValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
uint32_t upper = uint32_t(UValue >> 32);
|
|
|
|
uint32_t lower = uint32_t(UValue);
|
|
|
|
if (upper != lower)
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
Value = Value >> 32;
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
if (Value <= 0x3ffff)
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant(Value, ValueType);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get_vec_i16imm - Test if this vector is a vector filled with the same value
|
|
|
|
/// and the value fits into a signed 16-bit constant, and if so, return the
|
|
|
|
/// constant
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_vec_i16imm(SDNode *N, SelectionDAG &DAG,
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ValueType) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-09-26 21:54:37 +00:00
|
|
|
int64_t Value = CN->getSExtValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
if (ValueType == MVT::i64) {
|
2008-09-12 16:56:44 +00:00
|
|
|
uint64_t UValue = CN->getZExtValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
uint32_t upper = uint32_t(UValue >> 32);
|
|
|
|
uint32_t lower = uint32_t(UValue);
|
|
|
|
if (upper != lower)
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
Value = Value >> 32;
|
|
|
|
}
|
2008-03-05 23:02:02 +00:00
|
|
|
if (Value >= -(1 << 15) && Value <= ((1 << 15) - 1)) {
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant(Value, ValueType);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get_vec_i10imm - Test if this vector is a vector filled with the same value
|
|
|
|
/// and the value fits into a signed 10-bit constant, and if so, return the
|
|
|
|
/// constant
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_vec_i10imm(SDNode *N, SelectionDAG &DAG,
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ValueType) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-09-26 21:54:37 +00:00
|
|
|
int64_t Value = CN->getSExtValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
if (ValueType == MVT::i64) {
|
2008-09-12 16:56:44 +00:00
|
|
|
uint64_t UValue = CN->getZExtValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
uint32_t upper = uint32_t(UValue >> 32);
|
|
|
|
uint32_t lower = uint32_t(UValue);
|
|
|
|
if (upper != lower)
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2008-03-06 04:02:54 +00:00
|
|
|
Value = Value >> 32;
|
|
|
|
}
|
2008-03-05 23:02:02 +00:00
|
|
|
if (isS10Constant(Value))
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant(Value, ValueType);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get_vec_i8imm - Test if this vector is a vector filled with the same value
|
|
|
|
/// and the value fits into a signed 8-bit constant, and if so, return the
|
|
|
|
/// constant.
|
|
|
|
///
|
|
|
|
/// @note: The incoming vector is v16i8 because that's the only way we can load
|
|
|
|
/// constant vectors. Thus, we test to see if the upper and lower bytes are the
|
|
|
|
/// same value.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_vec_i8imm(SDNode *N, SelectionDAG &DAG,
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ValueType) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-09-12 16:56:44 +00:00
|
|
|
int Value = (int) CN->getZExtValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ValueType == MVT::i16
|
2008-01-30 02:55:46 +00:00
|
|
|
&& Value <= 0xffff /* truncated from uint64_t */
|
|
|
|
&& ((short) Value >> 8) == ((short) Value & 0xff))
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant(Value & 0xff, ValueType);
|
2007-12-04 22:23:35 +00:00
|
|
|
else if (ValueType == MVT::i8
|
2008-01-30 02:55:46 +00:00
|
|
|
&& (Value & 0xff) == Value)
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant(Value, ValueType);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get_ILHUvec_imm - Test if this vector is a vector filled with the same value
|
|
|
|
/// and the value fits into a signed 16-bit constant, and if so, return the
|
|
|
|
/// constant
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_ILHUvec_imm(SDNode *N, SelectionDAG &DAG,
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT ValueType) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-09-12 16:56:44 +00:00
|
|
|
uint64_t Value = CN->getZExtValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
if ((ValueType == MVT::i32
|
2008-01-30 02:55:46 +00:00
|
|
|
&& ((unsigned) Value & 0xffff0000) == (unsigned) Value)
|
|
|
|
|| (ValueType == MVT::i64 && (Value & 0xffff0000) == Value))
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant(Value >> 16, ValueType);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get_v4i32_imm - Catch-all for general 32-bit constant vectors
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_v4i32_imm(SDNode *N, SelectionDAG &DAG) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant((unsigned) CN->getZExtValue(), MVT::i32);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// get_v4i32_imm - Catch-all for general 64-bit constant vectors
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue SPU::get_v2i64_imm(SDNode *N, SelectionDAG &DAG) {
|
2007-12-04 22:23:35 +00:00
|
|
|
if (ConstantSDNode *CN = getVecImm(N)) {
|
2008-11-05 02:06:09 +00:00
|
|
|
return DAG.getTargetConstant((unsigned) CN->getZExtValue(), MVT::i64);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If this is a vector of constants or undefs, get the bits. A bit in
|
2008-07-16 17:17:29 +00:00
|
|
|
// UndefBits is set if the corresponding element of the vector is an
|
2007-12-04 22:23:35 +00:00
|
|
|
// ISD::UNDEF value. For undefs, the corresponding VectorBits values are
|
|
|
|
// zero. Return true if this is not an array of constants, false if it is.
|
|
|
|
//
|
|
|
|
static bool GetConstantBuildVectorBits(SDNode *BV, uint64_t VectorBits[2],
|
|
|
|
uint64_t UndefBits[2]) {
|
|
|
|
// Start with zero'd results.
|
|
|
|
VectorBits[0] = VectorBits[1] = UndefBits[0] = UndefBits[1] = 0;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned EltBitSize = BV->getOperand(0).getValueType().getSizeInBits();
|
2007-12-04 22:23:35 +00:00
|
|
|
for (unsigned i = 0, e = BV->getNumOperands(); i != e; ++i) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue OpVal = BV->getOperand(i);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned PartNo = i >= e/2; // In the upper 128 bits?
|
|
|
|
unsigned SlotNo = e/2 - (i & (e/2-1))-1; // Which subpiece of the uint64_t.
|
|
|
|
|
|
|
|
uint64_t EltBits = 0;
|
|
|
|
if (OpVal.getOpcode() == ISD::UNDEF) {
|
|
|
|
uint64_t EltUndefBits = ~0ULL >> (64-EltBitSize);
|
|
|
|
UndefBits[PartNo] |= EltUndefBits << (SlotNo*EltBitSize);
|
|
|
|
continue;
|
2008-11-11 03:06:06 +00:00
|
|
|
} else if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(OpVal)) {
|
2008-09-12 16:56:44 +00:00
|
|
|
EltBits = CN->getZExtValue() & (~0ULL >> (64-EltBitSize));
|
2008-11-11 03:06:06 +00:00
|
|
|
} else if (ConstantFPSDNode *CN = dyn_cast<ConstantFPSDNode>(OpVal)) {
|
2007-12-04 22:23:35 +00:00
|
|
|
const APFloat &apf = CN->getValueAPF();
|
|
|
|
EltBits = (CN->getValueType(0) == MVT::f32
|
2008-01-30 02:55:46 +00:00
|
|
|
? FloatToBits(apf.convertToFloat())
|
|
|
|
: DoubleToBits(apf.convertToDouble()));
|
2007-12-04 22:23:35 +00:00
|
|
|
} else {
|
|
|
|
// Nonconstant element.
|
|
|
|
return true;
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
VectorBits[PartNo] |= EltBits << (SlotNo*EltBitSize);
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
|
|
|
//printf("%llx %llx %llx %llx\n",
|
2007-12-04 22:23:35 +00:00
|
|
|
// VectorBits[0], VectorBits[1], UndefBits[0], UndefBits[1]);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// If this is a splat (repetition) of a value across the whole vector, return
|
|
|
|
/// the smallest size that splats it. For example, "0x01010101010101..." is a
|
2008-07-16 17:17:29 +00:00
|
|
|
/// splat of 0x01, 0x0101, and 0x01010101. We return SplatBits = 0x01 and
|
2007-12-04 22:23:35 +00:00
|
|
|
/// SplatSize = 1 byte.
|
2008-07-16 17:17:29 +00:00
|
|
|
static bool isConstantSplat(const uint64_t Bits128[2],
|
2007-12-04 22:23:35 +00:00
|
|
|
const uint64_t Undef128[2],
|
2008-01-30 02:55:46 +00:00
|
|
|
int MinSplatBits,
|
2007-12-04 22:23:35 +00:00
|
|
|
uint64_t &SplatBits, uint64_t &SplatUndef,
|
|
|
|
int &SplatSize) {
|
|
|
|
// Don't let undefs prevent splats from matching. See if the top 64-bits are
|
|
|
|
// the same as the lower 64-bits, ignoring undefs.
|
|
|
|
uint64_t Bits64 = Bits128[0] | Bits128[1];
|
|
|
|
uint64_t Undef64 = Undef128[0] & Undef128[1];
|
|
|
|
uint32_t Bits32 = uint32_t(Bits64) | uint32_t(Bits64 >> 32);
|
|
|
|
uint32_t Undef32 = uint32_t(Undef64) & uint32_t(Undef64 >> 32);
|
|
|
|
uint16_t Bits16 = uint16_t(Bits32) | uint16_t(Bits32 >> 16);
|
|
|
|
uint16_t Undef16 = uint16_t(Undef32) & uint16_t(Undef32 >> 16);
|
|
|
|
|
|
|
|
if ((Bits128[0] & ~Undef128[1]) == (Bits128[1] & ~Undef128[0])) {
|
|
|
|
if (MinSplatBits < 64) {
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Check that the top 32-bits are the same as the lower 32-bits, ignoring
|
|
|
|
// undefs.
|
|
|
|
if ((Bits64 & (~Undef64 >> 32)) == ((Bits64 >> 32) & ~Undef64)) {
|
2008-01-30 02:55:46 +00:00
|
|
|
if (MinSplatBits < 32) {
|
|
|
|
|
|
|
|
// If the top 16-bits are different than the lower 16-bits, ignoring
|
|
|
|
// undefs, we have an i32 splat.
|
|
|
|
if ((Bits32 & (~Undef32 >> 16)) == ((Bits32 >> 16) & ~Undef32)) {
|
|
|
|
if (MinSplatBits < 16) {
|
|
|
|
// If the top 8-bits are different than the lower 8-bits, ignoring
|
|
|
|
// undefs, we have an i16 splat.
|
2008-08-31 15:37:04 +00:00
|
|
|
if ((Bits16 & (uint16_t(~Undef16) >> 8))
|
|
|
|
== ((Bits16 >> 8) & ~Undef16)) {
|
2008-01-30 02:55:46 +00:00
|
|
|
// Otherwise, we have an 8-bit splat.
|
|
|
|
SplatBits = uint8_t(Bits16) | uint8_t(Bits16 >> 8);
|
|
|
|
SplatUndef = uint8_t(Undef16) & uint8_t(Undef16 >> 8);
|
|
|
|
SplatSize = 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SplatBits = Bits16;
|
|
|
|
SplatUndef = Undef16;
|
|
|
|
SplatSize = 2;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SplatBits = Bits32;
|
|
|
|
SplatUndef = Undef32;
|
|
|
|
SplatSize = 4;
|
|
|
|
return true;
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SplatBits = Bits128[0];
|
|
|
|
SplatUndef = Undef128[0];
|
|
|
|
SplatSize = 8;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // Can't be a splat if two pieces don't match.
|
|
|
|
}
|
|
|
|
|
2009-01-21 04:58:48 +00:00
|
|
|
//! Lower a BUILD_VECTOR instruction creatively:
|
|
|
|
SDValue
|
2009-01-26 03:31:40 +00:00
|
|
|
LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
// If this is a vector of constants or undefs, get the bits. A bit in
|
2008-07-16 17:17:29 +00:00
|
|
|
// UndefBits is set if the corresponding element of the vector is an
|
2007-12-04 22:23:35 +00:00
|
|
|
// ISD::UNDEF value. For undefs, the corresponding VectorBits values are
|
2008-07-16 17:17:29 +00:00
|
|
|
// zero.
|
2007-12-04 22:23:35 +00:00
|
|
|
uint64_t VectorBits[2];
|
|
|
|
uint64_t UndefBits[2];
|
|
|
|
uint64_t SplatBits, SplatUndef;
|
|
|
|
int SplatSize;
|
2008-08-28 21:40:38 +00:00
|
|
|
if (GetConstantBuildVectorBits(Op.getNode(), VectorBits, UndefBits)
|
2007-12-04 22:23:35 +00:00
|
|
|
|| !isConstantSplat(VectorBits, UndefBits,
|
2008-06-06 12:08:01 +00:00
|
|
|
VT.getVectorElementType().getSizeInBits(),
|
2007-12-04 22:23:35 +00:00
|
|
|
SplatBits, SplatUndef, SplatSize))
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue(); // Not a constant vector, not a splat.
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (VT.getSimpleVT()) {
|
2007-12-04 22:23:35 +00:00
|
|
|
default:
|
2009-01-21 04:58:48 +00:00
|
|
|
cerr << "CellSPU: Unhandled VT in LowerBUILD_VECTOR, VT = "
|
|
|
|
<< VT.getMVTString()
|
|
|
|
<< "\n";
|
|
|
|
abort();
|
|
|
|
/*NOTREACHED*/
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::v4f32: {
|
2009-01-26 03:31:40 +00:00
|
|
|
uint32_t Value32 = uint32_t(SplatBits);
|
2007-12-04 22:23:35 +00:00
|
|
|
assert(SplatSize == 4
|
2008-01-30 02:55:46 +00:00
|
|
|
&& "LowerBUILD_VECTOR: Unexpected floating point vector element.");
|
2007-12-04 22:23:35 +00:00
|
|
|
// NOTE: pretend the constant is an integer. LLVM won't load FP constants
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue T = DAG.getConstant(Value32, MVT::i32);
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v4f32,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v4i32, dl, T, T, T, T));
|
2007-12-04 22:23:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::v2f64: {
|
2009-01-26 03:31:40 +00:00
|
|
|
uint64_t f64val = uint64_t(SplatBits);
|
2007-12-04 22:23:35 +00:00
|
|
|
assert(SplatSize == 8
|
2008-11-24 17:11:17 +00:00
|
|
|
&& "LowerBUILD_VECTOR: 64-bit float vector size > 8 bytes.");
|
2007-12-04 22:23:35 +00:00
|
|
|
// NOTE: pretend the constant is an integer. LLVM won't load FP constants
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue T = DAG.getConstant(f64val, MVT::i64);
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v2f64,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v2i64, dl, T, T));
|
2007-12-04 22:23:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::v16i8: {
|
|
|
|
// 8-bit constants have to be expanded to 16-bits
|
|
|
|
unsigned short Value16 = SplatBits | (SplatBits << 8);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Ops[8];
|
2007-12-04 22:23:35 +00:00
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
Ops[i] = DAG.getConstant(Value16, MVT::i16);
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, dl, VT,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v8i16, dl, Ops, 8));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
case MVT::v8i16: {
|
|
|
|
unsigned short Value16;
|
2008-07-16 17:17:29 +00:00
|
|
|
if (SplatSize == 2)
|
2007-12-04 22:23:35 +00:00
|
|
|
Value16 = (unsigned short) (SplatBits & 0xffff);
|
|
|
|
else
|
|
|
|
Value16 = (unsigned short) (SplatBits | (SplatBits << 8));
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue T = DAG.getConstant(Value16, VT.getVectorElementType());
|
|
|
|
SDValue Ops[8];
|
2007-12-04 22:23:35 +00:00
|
|
|
for (int i = 0; i < 8; ++i) Ops[i] = T;
|
2009-02-22 23:36:09 +00:00
|
|
|
return DAG.getBUILD_VECTOR(VT, dl, Ops, 8);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
case MVT::v4i32: {
|
|
|
|
unsigned int Value = SplatBits;
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue T = DAG.getConstant(Value, VT.getVectorElementType());
|
2009-02-22 23:36:09 +00:00
|
|
|
return DAG.getBUILD_VECTOR(VT, dl, T, T, T, T);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2009-01-06 23:10:38 +00:00
|
|
|
case MVT::v2i32: {
|
|
|
|
unsigned int Value = SplatBits;
|
|
|
|
SDValue T = DAG.getConstant(Value, VT.getVectorElementType());
|
2009-02-22 23:36:09 +00:00
|
|
|
return DAG.getBUILD_VECTOR(VT, dl, T, T);
|
2009-01-06 23:10:38 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::v2i64: {
|
2009-02-06 01:31:28 +00:00
|
|
|
return SPU::LowerSplat_v2i64(VT, DAG, SplatBits, dl);
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
return SDValue();
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue
|
2009-02-06 01:31:28 +00:00
|
|
|
SPU::LowerSplat_v2i64(MVT OpVT, SelectionDAG& DAG, uint64_t SplatVal,
|
|
|
|
DebugLoc dl) {
|
2009-01-26 03:31:40 +00:00
|
|
|
uint32_t upper = uint32_t(SplatVal >> 32);
|
|
|
|
uint32_t lower = uint32_t(SplatVal);
|
|
|
|
|
|
|
|
if (upper == lower) {
|
|
|
|
// Magic constant that can be matched by IL, ILA, et. al.
|
|
|
|
SDValue Val = DAG.getTargetConstant(upper, MVT::i32);
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::BIT_CONVERT, dl, OpVT,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
Val, Val, Val, Val));
|
2009-01-26 03:31:40 +00:00
|
|
|
} else {
|
|
|
|
SDValue LO32;
|
|
|
|
SDValue HI32;
|
|
|
|
SmallVector<SDValue, 16> ShufBytes;
|
|
|
|
SDValue Result;
|
|
|
|
bool upper_special, lower_special;
|
|
|
|
|
|
|
|
// NOTE: This code creates common-case shuffle masks that can be easily
|
|
|
|
// detected as common expressions. It is not attempting to create highly
|
|
|
|
// specialized masks to replace any and all 0's, 0xff's and 0x80's.
|
|
|
|
|
|
|
|
// Detect if the upper or lower half is a special shuffle mask pattern:
|
|
|
|
upper_special = (upper == 0 || upper == 0xffffffff || upper == 0x80000000);
|
|
|
|
lower_special = (lower == 0 || lower == 0xffffffff || lower == 0x80000000);
|
|
|
|
|
|
|
|
// Create lower vector if not a special pattern
|
|
|
|
if (!lower_special) {
|
|
|
|
SDValue LO32C = DAG.getConstant(lower, MVT::i32);
|
2009-02-06 01:31:28 +00:00
|
|
|
LO32 = DAG.getNode(ISD::BIT_CONVERT, dl, OpVT,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
LO32C, LO32C, LO32C, LO32C));
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
// Create upper vector if not a special pattern
|
|
|
|
if (!upper_special) {
|
|
|
|
SDValue HI32C = DAG.getConstant(upper, MVT::i32);
|
2009-02-06 01:31:28 +00:00
|
|
|
HI32 = DAG.getNode(ISD::BIT_CONVERT, dl, OpVT,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
HI32C, HI32C, HI32C, HI32C));
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
2008-06-02 22:18:03 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
// If either upper or lower are special, then the two input operands are
|
|
|
|
// the same (basically, one of them is a "don't care")
|
|
|
|
if (lower_special)
|
|
|
|
LO32 = HI32;
|
|
|
|
if (upper_special)
|
|
|
|
HI32 = LO32;
|
|
|
|
if (lower_special && upper_special) {
|
|
|
|
// Unhappy situation... both upper and lower are special, so punt with
|
|
|
|
// a target constant:
|
|
|
|
SDValue Zero = DAG.getConstant(0, MVT::i32);
|
2009-02-22 23:36:09 +00:00
|
|
|
HI32 = LO32 = DAG.getBUILD_VECTOR(MVT::v4i32, dl, Zero, Zero,
|
|
|
|
Zero, Zero);
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
uint64_t val = 0;
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
|
|
|
SDValue V;
|
|
|
|
bool process_upper, process_lower;
|
|
|
|
val <<= 8;
|
|
|
|
process_upper = (upper_special && (i & 1) == 0);
|
|
|
|
process_lower = (lower_special && (i & 1) == 1);
|
|
|
|
|
|
|
|
if (process_upper || process_lower) {
|
|
|
|
if ((process_upper && upper == 0)
|
|
|
|
|| (process_lower && lower == 0))
|
|
|
|
val |= 0x80;
|
|
|
|
else if ((process_upper && upper == 0xffffffff)
|
|
|
|
|| (process_lower && lower == 0xffffffff))
|
|
|
|
val |= 0xc0;
|
|
|
|
else if ((process_upper && upper == 0x80000000)
|
|
|
|
|| (process_lower && lower == 0x80000000))
|
|
|
|
val |= (j == 0 ? 0xe0 : 0x80);
|
|
|
|
} else
|
|
|
|
val |= i * 4 + j + ((i & 1) * 16);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
ShufBytes.push_back(DAG.getConstant(val, MVT::i32));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(SPUISD::SHUFB, dl, OpVT, HI32, LO32,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
&ShufBytes[0], ShufBytes.size()));
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// LowerVECTOR_SHUFFLE - Lower a vector shuffle (V1, V2, V3) to something on
|
|
|
|
/// which the Cell can operate. The code inspects V3 to ascertain whether the
|
|
|
|
/// permutation vector, V3, is monotonically increasing with one "exception"
|
|
|
|
/// element, e.g., (0, 1, _, 3). If this is the case, then generate a
|
2008-11-22 23:50:42 +00:00
|
|
|
/// SHUFFLE_MASK synthetic instruction. Otherwise, spill V3 to the constant pool.
|
2007-12-04 22:23:35 +00:00
|
|
|
/// In either case, the net result is going to eventually invoke SHUFB to
|
|
|
|
/// permute/shuffle the bytes from V1 and V2.
|
|
|
|
/// \note
|
2008-11-22 23:50:42 +00:00
|
|
|
/// SHUFFLE_MASK is eventually selected as one of the C*D instructions, generate
|
2007-12-04 22:23:35 +00:00
|
|
|
/// control word for byte/halfword/word insertion. This takes care of a single
|
|
|
|
/// element move from V2 into V1.
|
|
|
|
/// \note
|
|
|
|
/// SPUISD::SHUFB is eventually selected as Cell's <i>shufb</i> instructions.
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) {
|
|
|
|
SDValue V1 = Op.getOperand(0);
|
|
|
|
SDValue V2 = Op.getOperand(1);
|
|
|
|
SDValue PermMask = Op.getOperand(2);
|
2009-02-04 23:02:30 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
if (V2.getOpcode() == ISD::UNDEF) V2 = V1;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// If we have a single element being moved from V1 to V2, this can be handled
|
|
|
|
// using the C*[DX] compute mask instructions, but the vector elements have
|
|
|
|
// to be monotonically increasing with one exception element.
|
2008-12-04 21:01:44 +00:00
|
|
|
MVT VecVT = V1.getValueType();
|
|
|
|
MVT EltVT = VecVT.getVectorElementType();
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned EltsFromV2 = 0;
|
|
|
|
unsigned V2Elt = 0;
|
|
|
|
unsigned V2EltIdx0 = 0;
|
|
|
|
unsigned CurrElt = 0;
|
2008-12-04 21:01:44 +00:00
|
|
|
unsigned MaxElts = VecVT.getVectorNumElements();
|
|
|
|
unsigned PrevElt = 0;
|
|
|
|
unsigned V0Elt = 0;
|
2007-12-04 22:23:35 +00:00
|
|
|
bool monotonic = true;
|
2008-12-04 21:01:44 +00:00
|
|
|
bool rotate = true;
|
|
|
|
|
|
|
|
if (EltVT == MVT::i8) {
|
2007-12-04 22:23:35 +00:00
|
|
|
V2EltIdx0 = 16;
|
2008-12-04 21:01:44 +00:00
|
|
|
} else if (EltVT == MVT::i16) {
|
2007-12-04 22:23:35 +00:00
|
|
|
V2EltIdx0 = 8;
|
2008-12-04 21:01:44 +00:00
|
|
|
} else if (EltVT == MVT::i32 || EltVT == MVT::f32) {
|
2007-12-04 22:23:35 +00:00
|
|
|
V2EltIdx0 = 4;
|
2008-12-04 21:01:44 +00:00
|
|
|
} else if (EltVT == MVT::i64 || EltVT == MVT::f64) {
|
|
|
|
V2EltIdx0 = 2;
|
|
|
|
} else
|
2007-12-04 22:23:35 +00:00
|
|
|
assert(0 && "Unhandled vector type in LowerVECTOR_SHUFFLE");
|
|
|
|
|
2008-12-04 21:01:44 +00:00
|
|
|
for (unsigned i = 0; i != PermMask.getNumOperands(); ++i) {
|
|
|
|
if (PermMask.getOperand(i).getOpcode() != ISD::UNDEF) {
|
|
|
|
unsigned SrcElt = cast<ConstantSDNode > (PermMask.getOperand(i))->getZExtValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-04 21:01:44 +00:00
|
|
|
if (monotonic) {
|
|
|
|
if (SrcElt >= V2EltIdx0) {
|
|
|
|
if (1 >= (++EltsFromV2)) {
|
|
|
|
V2Elt = (V2EltIdx0 - SrcElt) << 2;
|
|
|
|
}
|
|
|
|
} else if (CurrElt != SrcElt) {
|
|
|
|
monotonic = false;
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-04 21:01:44 +00:00
|
|
|
++CurrElt;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rotate) {
|
|
|
|
if (PrevElt > 0 && SrcElt < MaxElts) {
|
|
|
|
if ((PrevElt == SrcElt - 1)
|
|
|
|
|| (PrevElt == MaxElts - 1 && SrcElt == 0)) {
|
|
|
|
PrevElt = SrcElt;
|
|
|
|
if (SrcElt == 0)
|
|
|
|
V0Elt = i;
|
|
|
|
} else {
|
|
|
|
rotate = false;
|
|
|
|
}
|
|
|
|
} else if (PrevElt == 0) {
|
|
|
|
// First time through, need to keep track of previous element
|
|
|
|
PrevElt = SrcElt;
|
|
|
|
} else {
|
|
|
|
// This isn't a rotation, takes elements from vector 2
|
|
|
|
rotate = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EltsFromV2 == 1 && monotonic) {
|
|
|
|
// Compute mask and shuffle
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
2007-12-31 04:13:23 +00:00
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
|
|
|
unsigned VReg = RegInfo.createVirtualRegister(&SPU::R32CRegClass);
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
2007-12-04 22:23:35 +00:00
|
|
|
// Initialize temporary register to 0
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue InitTempReg =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getCopyToReg(DAG.getEntryNode(), dl, VReg, DAG.getConstant(0, PtrVT));
|
2008-11-22 23:50:42 +00:00
|
|
|
// Copy register's contents as index in SHUFFLE_MASK:
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ShufMaskOp =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(SPUISD::SHUFFLE_MASK, dl, MVT::v4i32,
|
2008-01-30 02:55:46 +00:00
|
|
|
DAG.getTargetConstant(V2Elt, MVT::i32),
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getCopyFromReg(InitTempReg, dl, VReg, PtrVT));
|
2007-12-04 22:23:35 +00:00
|
|
|
// Use shuffle mask in SHUFB synthetic instruction:
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(SPUISD::SHUFB, dl, V1.getValueType(), V2, V1,
|
|
|
|
ShufMaskOp);
|
2008-12-04 21:01:44 +00:00
|
|
|
} else if (rotate) {
|
|
|
|
int rotamt = (MaxElts - V0Elt) * EltVT.getSizeInBits()/8;
|
2008-12-29 03:23:36 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(SPUISD::ROTBYTES_LEFT, dl, V1.getValueType(),
|
2008-12-04 21:01:44 +00:00
|
|
|
V1, DAG.getConstant(rotamt, MVT::i16));
|
2007-12-04 22:23:35 +00:00
|
|
|
} else {
|
2008-08-31 15:37:04 +00:00
|
|
|
// Convert the SHUFFLE_VECTOR mask's input element units to the
|
|
|
|
// actual bytes.
|
2008-06-06 12:08:01 +00:00
|
|
|
unsigned BytesPerElement = EltVT.getSizeInBits()/8;
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 16> ResultMask;
|
2007-12-04 22:23:35 +00:00
|
|
|
for (unsigned i = 0, e = PermMask.getNumOperands(); i != e; ++i) {
|
|
|
|
unsigned SrcElt;
|
|
|
|
if (PermMask.getOperand(i).getOpcode() == ISD::UNDEF)
|
2008-01-30 02:55:46 +00:00
|
|
|
SrcElt = 0;
|
2008-07-16 17:17:29 +00:00
|
|
|
else
|
2008-09-12 16:56:44 +00:00
|
|
|
SrcElt = cast<ConstantSDNode>(PermMask.getOperand(i))->getZExtValue();
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-02-23 18:41:37 +00:00
|
|
|
for (unsigned j = 0; j < BytesPerElement; ++j) {
|
2008-01-30 02:55:46 +00:00
|
|
|
ResultMask.push_back(DAG.getConstant(SrcElt*BytesPerElement+j,
|
|
|
|
MVT::i8));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2009-02-22 23:36:09 +00:00
|
|
|
SDValue VPermMask = DAG.getBUILD_VECTOR(MVT::v16i8, dl,
|
|
|
|
&ResultMask[0], ResultMask.size());
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(SPUISD::SHUFB, dl, V1.getValueType(), V1, V2, VPermMask);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue LowerSCALAR_TO_VECTOR(SDValue Op, SelectionDAG &DAG) {
|
|
|
|
SDValue Op0 = Op.getOperand(0); // Op0 = the scalar
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Op0.getNode()->getOpcode() == ISD::Constant) {
|
2007-12-04 22:23:35 +00:00
|
|
|
// For a constant, build the appropriate constant vector, which will
|
|
|
|
// eventually simplify to a vector register load.
|
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(Op0.getNode());
|
2008-07-27 21:46:04 +00:00
|
|
|
SmallVector<SDValue, 16> ConstVecValues;
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT;
|
2007-12-04 22:23:35 +00:00
|
|
|
size_t n_copies;
|
|
|
|
|
|
|
|
// Create a constant vector:
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (Op.getValueType().getSimpleVT()) {
|
2007-12-04 22:23:35 +00:00
|
|
|
default: assert(0 && "Unexpected constant value type in "
|
2008-01-30 02:55:46 +00:00
|
|
|
"LowerSCALAR_TO_VECTOR");
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::v16i8: n_copies = 16; VT = MVT::i8; break;
|
|
|
|
case MVT::v8i16: n_copies = 8; VT = MVT::i16; break;
|
|
|
|
case MVT::v4i32: n_copies = 4; VT = MVT::i32; break;
|
|
|
|
case MVT::v4f32: n_copies = 4; VT = MVT::f32; break;
|
|
|
|
case MVT::v2i64: n_copies = 2; VT = MVT::i64; break;
|
|
|
|
case MVT::v2f64: n_copies = 2; VT = MVT::f64; break;
|
|
|
|
}
|
|
|
|
|
2008-09-12 16:56:44 +00:00
|
|
|
SDValue CValue = DAG.getConstant(CN->getZExtValue(), VT);
|
2007-12-04 22:23:35 +00:00
|
|
|
for (size_t j = 0; j < n_copies; ++j)
|
|
|
|
ConstVecValues.push_back(CValue);
|
|
|
|
|
2009-02-22 23:36:09 +00:00
|
|
|
return DAG.getBUILD_VECTOR(Op.getValueType(), dl,
|
|
|
|
&ConstVecValues[0], ConstVecValues.size());
|
2007-12-04 22:23:35 +00:00
|
|
|
} else {
|
|
|
|
// Otherwise, copy the value from one register to another:
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (Op0.getValueType().getSimpleVT()) {
|
2007-12-04 22:23:35 +00:00
|
|
|
default: assert(0 && "Unexpected value type in LowerSCALAR_TO_VECTOR");
|
|
|
|
case MVT::i8:
|
|
|
|
case MVT::i16:
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::i64:
|
|
|
|
case MVT::f32:
|
|
|
|
case MVT::f64:
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(SPUISD::PREFSLOT2VEC, dl, Op.getValueType(), Op0, Op0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N = Op.getOperand(0);
|
|
|
|
SDValue Elt = Op.getOperand(1);
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-11-22 23:50:42 +00:00
|
|
|
SDValue retval;
|
|
|
|
|
|
|
|
if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) {
|
|
|
|
// Constant argument:
|
|
|
|
int EltNo = (int) C->getZExtValue();
|
|
|
|
|
|
|
|
// sanity checks:
|
|
|
|
if (VT == MVT::i8 && EltNo >= 16)
|
|
|
|
assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i8 extraction slot > 15");
|
|
|
|
else if (VT == MVT::i16 && EltNo >= 8)
|
|
|
|
assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i16 extraction slot > 7");
|
|
|
|
else if (VT == MVT::i32 && EltNo >= 4)
|
|
|
|
assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i32 extraction slot > 4");
|
|
|
|
else if (VT == MVT::i64 && EltNo >= 2)
|
|
|
|
assert(0 && "SPU LowerEXTRACT_VECTOR_ELT: i64 extraction slot > 2");
|
|
|
|
|
|
|
|
if (EltNo == 0 && (VT == MVT::i32 || VT == MVT::i64)) {
|
|
|
|
// i32 and i64: Element 0 is the preferred slot
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(SPUISD::VEC2PREFSLOT, dl, VT, N);
|
2008-11-22 23:50:42 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
// Need to generate shuffle mask and extract:
|
|
|
|
int prefslot_begin = -1, prefslot_end = -1;
|
|
|
|
int elt_byte = EltNo * VT.getSizeInBits() / 8;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
switch (VT.getSimpleVT()) {
|
|
|
|
default:
|
|
|
|
assert(false && "Invalid value type!");
|
|
|
|
case MVT::i8: {
|
|
|
|
prefslot_begin = prefslot_end = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::i16: {
|
|
|
|
prefslot_begin = 2; prefslot_end = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::f32: {
|
|
|
|
prefslot_begin = 0; prefslot_end = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::i64:
|
|
|
|
case MVT::f64: {
|
|
|
|
prefslot_begin = 0; prefslot_end = 7;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
assert(prefslot_begin != -1 && prefslot_end != -1 &&
|
|
|
|
"LowerEXTRACT_VECTOR_ELT: preferred slots uninitialized");
|
|
|
|
|
|
|
|
unsigned int ShufBytes[16];
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
// zero fill uppper part of preferred slot, don't care about the
|
|
|
|
// other slots:
|
|
|
|
unsigned int mask_val;
|
|
|
|
if (i <= prefslot_end) {
|
|
|
|
mask_val =
|
|
|
|
((i < prefslot_begin)
|
|
|
|
? 0x80
|
|
|
|
: elt_byte + (i - prefslot_begin));
|
|
|
|
|
|
|
|
ShufBytes[i] = mask_val;
|
|
|
|
} else
|
|
|
|
ShufBytes[i] = ShufBytes[i % (prefslot_end + 1)];
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
SDValue ShufMask[4];
|
|
|
|
for (unsigned i = 0; i < sizeof(ShufMask)/sizeof(ShufMask[0]); ++i) {
|
2008-12-04 21:01:44 +00:00
|
|
|
unsigned bidx = i * 4;
|
2008-11-22 23:50:42 +00:00
|
|
|
unsigned int bits = ((ShufBytes[bidx] << 24) |
|
|
|
|
(ShufBytes[bidx+1] << 16) |
|
|
|
|
(ShufBytes[bidx+2] << 8) |
|
|
|
|
ShufBytes[bidx+3]);
|
|
|
|
ShufMask[i] = DAG.getConstant(bits, MVT::i32);
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-22 23:36:09 +00:00
|
|
|
SDValue ShufMaskVec =
|
|
|
|
DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
&ShufMask[0], sizeof(ShufMask)/sizeof(ShufMask[0]));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-06 01:31:28 +00:00
|
|
|
retval = DAG.getNode(SPUISD::VEC2PREFSLOT, dl, VT,
|
|
|
|
DAG.getNode(SPUISD::SHUFB, dl, N.getValueType(),
|
2008-11-22 23:50:42 +00:00
|
|
|
N, N, ShufMaskVec));
|
|
|
|
} else {
|
|
|
|
// Variable index: Rotate the requested element into slot 0, then replicate
|
|
|
|
// slot 0 across the vector
|
|
|
|
MVT VecVT = N.getValueType();
|
|
|
|
if (!VecVT.isSimple() || !VecVT.isVector() || !VecVT.is128BitVector()) {
|
|
|
|
cerr << "LowerEXTRACT_VECTOR_ELT: Must have a simple, 128-bit vector type!\n";
|
|
|
|
abort();
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
// Make life easier by making sure the index is zero-extended to i32
|
|
|
|
if (Elt.getValueType() != MVT::i32)
|
2009-02-06 01:31:28 +00:00
|
|
|
Elt = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Elt);
|
2007-12-19 21:17:42 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
// Scale the index to a bit/byte shift quantity
|
|
|
|
APInt scaleFactor =
|
2008-11-24 17:11:17 +00:00
|
|
|
APInt(32, uint64_t(16 / N.getValueType().getVectorNumElements()), false);
|
|
|
|
unsigned scaleShift = scaleFactor.logBase2();
|
2008-11-22 23:50:42 +00:00
|
|
|
SDValue vecShift;
|
2008-11-24 17:11:17 +00:00
|
|
|
|
|
|
|
if (scaleShift > 0) {
|
|
|
|
// Scale the shift factor:
|
2009-02-06 01:31:28 +00:00
|
|
|
Elt = DAG.getNode(ISD::SHL, dl, MVT::i32, Elt,
|
2008-12-01 17:56:02 +00:00
|
|
|
DAG.getConstant(scaleShift, MVT::i32));
|
2008-11-22 23:50:42 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-06 01:31:28 +00:00
|
|
|
vecShift = DAG.getNode(SPUISD::SHLQUAD_L_BYTES, dl, VecVT, N, Elt);
|
2008-11-24 17:11:17 +00:00
|
|
|
|
|
|
|
// Replicate the bytes starting at byte 0 across the entire vector (for
|
|
|
|
// consistency with the notion of a unified register set)
|
2008-11-22 23:50:42 +00:00
|
|
|
SDValue replicate;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
switch (VT.getSimpleVT()) {
|
|
|
|
default:
|
|
|
|
cerr << "LowerEXTRACT_VECTOR_ELT(varable): Unhandled vector type\n";
|
|
|
|
abort();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
case MVT::i8: {
|
2008-11-24 17:11:17 +00:00
|
|
|
SDValue factor = DAG.getConstant(0x00000000, MVT::i32);
|
2009-02-22 23:36:09 +00:00
|
|
|
replicate = DAG.getBUILD_VECTOR(MVT::v4i32, dl, factor, factor,
|
|
|
|
factor, factor);
|
2008-11-22 23:50:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::i16: {
|
2008-11-24 17:11:17 +00:00
|
|
|
SDValue factor = DAG.getConstant(0x00010001, MVT::i32);
|
2009-02-22 23:36:09 +00:00
|
|
|
replicate = DAG.getBUILD_VECTOR(MVT::v4i32, dl, factor, factor,
|
|
|
|
factor, factor);
|
2008-11-22 23:50:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::i32:
|
|
|
|
case MVT::f32: {
|
|
|
|
SDValue factor = DAG.getConstant(0x00010203, MVT::i32);
|
2009-02-22 23:36:09 +00:00
|
|
|
replicate = DAG.getBUILD_VECTOR(MVT::v4i32, dl, factor, factor,
|
|
|
|
factor, factor);
|
2008-11-22 23:50:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MVT::i64:
|
|
|
|
case MVT::f64: {
|
|
|
|
SDValue loFactor = DAG.getConstant(0x00010203, MVT::i32);
|
|
|
|
SDValue hiFactor = DAG.getConstant(0x04050607, MVT::i32);
|
2009-02-22 23:36:09 +00:00
|
|
|
replicate = DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
loFactor, hiFactor, loFactor, hiFactor);
|
2008-11-22 23:50:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-06 01:31:28 +00:00
|
|
|
retval = DAG.getNode(SPUISD::VEC2PREFSLOT, dl, VT,
|
|
|
|
DAG.getNode(SPUISD::SHUFB, dl, VecVT,
|
2008-12-01 17:56:02 +00:00
|
|
|
vecShift, vecShift, replicate));
|
2008-11-22 23:50:42 +00:00
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
return retval;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) {
|
|
|
|
SDValue VecOp = Op.getOperand(0);
|
|
|
|
SDValue ValOp = Op.getOperand(1);
|
|
|
|
SDValue IdxOp = Op.getOperand(2);
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
ConstantSDNode *CN = cast<ConstantSDNode>(IdxOp);
|
|
|
|
assert(CN != 0 && "LowerINSERT_VECTOR_ELT: Index is not constant!");
|
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy();
|
2008-12-01 17:56:02 +00:00
|
|
|
// Use $sp ($1) because it's always 16-byte aligned and it's available:
|
2009-02-06 01:31:28 +00:00
|
|
|
SDValue Pointer = DAG.getNode(SPUISD::IndirectAddr, dl, PtrVT,
|
2008-12-01 17:56:02 +00:00
|
|
|
DAG.getRegister(SPU::R1, PtrVT),
|
|
|
|
DAG.getConstant(CN->getSExtValue(), PtrVT));
|
2009-02-06 01:31:28 +00:00
|
|
|
SDValue ShufMask = DAG.getNode(SPUISD::SHUFFLE_MASK, dl, VT, Pointer);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue result =
|
2009-02-06 01:31:28 +00:00
|
|
|
DAG.getNode(SPUISD::SHUFB, dl, VT,
|
|
|
|
DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, ValOp),
|
2008-12-29 03:23:36 +00:00
|
|
|
VecOp,
|
2009-02-06 01:31:28 +00:00
|
|
|
DAG.getNode(ISD::BIT_CONVERT, dl, MVT::v4i32, ShufMask));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
static SDValue LowerI8Math(SDValue Op, SelectionDAG &DAG, unsigned Opc,
|
|
|
|
const TargetLowering &TLI)
|
2008-02-23 18:41:37 +00:00
|
|
|
{
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N0 = Op.getOperand(0); // Everything has at least one operand
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-12-27 04:51:36 +00:00
|
|
|
MVT ShiftVT = TLI.getShiftAmountTy();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
assert(Op.getValueType() == MVT::i8);
|
|
|
|
switch (Opc) {
|
|
|
|
default:
|
|
|
|
assert(0 && "Unhandled i8 math operator");
|
|
|
|
/*NOTREACHED*/
|
|
|
|
break;
|
2008-12-30 23:28:25 +00:00
|
|
|
case ISD::ADD: {
|
|
|
|
// 8-bit addition: Promote the arguments up to 16-bits and truncate
|
|
|
|
// the result:
|
|
|
|
SDValue N1 = Op.getOperand(1);
|
2009-02-06 01:31:28 +00:00
|
|
|
N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i16, N0);
|
|
|
|
N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i16, N1);
|
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
|
|
|
|
DAG.getNode(Opc, dl, MVT::i16, N0, N1));
|
2008-12-30 23:28:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::SUB: {
|
|
|
|
// 8-bit subtraction: Promote the arguments up to 16-bits and truncate
|
|
|
|
// the result:
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N1 = Op.getOperand(1);
|
2009-02-06 01:31:28 +00:00
|
|
|
N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i16, N0);
|
|
|
|
N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i16, N1);
|
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
|
|
|
|
DAG.getNode(Opc, dl, MVT::i16, N0, N1));
|
2008-07-16 17:17:29 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::ROTR:
|
|
|
|
case ISD::ROTL: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N1 = Op.getOperand(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned N1Opc;
|
|
|
|
N0 = (N0.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, N0)
|
2008-09-12 16:56:44 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(),
|
|
|
|
MVT::i16));
|
2008-12-27 04:51:36 +00:00
|
|
|
N1Opc = N1.getValueType().bitsLT(ShiftVT)
|
2008-08-31 15:37:04 +00:00
|
|
|
? ISD::ZERO_EXTEND
|
|
|
|
: ISD::TRUNCATE;
|
2007-12-04 22:23:35 +00:00
|
|
|
N1 = (N1.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(N1Opc, dl, ShiftVT, N1)
|
2008-09-12 16:56:44 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
|
2008-12-27 04:51:36 +00:00
|
|
|
TLI.getShiftAmountTy()));
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue ExpandArg =
|
2009-02-06 01:31:28 +00:00
|
|
|
DAG.getNode(ISD::OR, dl, MVT::i16, N0,
|
|
|
|
DAG.getNode(ISD::SHL, dl, MVT::i16,
|
2008-10-30 19:24:28 +00:00
|
|
|
N0, DAG.getConstant(8, MVT::i32)));
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
|
|
|
|
DAG.getNode(Opc, dl, MVT::i16, ExpandArg, N1));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
case ISD::SRL:
|
|
|
|
case ISD::SHL: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N1 = Op.getOperand(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned N1Opc;
|
|
|
|
N0 = (N0.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i16, N0)
|
2008-09-12 16:56:44 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(),
|
2008-12-27 04:51:36 +00:00
|
|
|
MVT::i32));
|
|
|
|
N1Opc = N1.getValueType().bitsLT(ShiftVT)
|
2008-08-31 15:37:04 +00:00
|
|
|
? ISD::ZERO_EXTEND
|
|
|
|
: ISD::TRUNCATE;
|
2007-12-04 22:23:35 +00:00
|
|
|
N1 = (N1.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(N1Opc, dl, ShiftVT, N1)
|
2008-12-27 04:51:36 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(), ShiftVT));
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
|
|
|
|
DAG.getNode(Opc, dl, MVT::i16, N0, N1));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
case ISD::SRA: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N1 = Op.getOperand(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned N1Opc;
|
|
|
|
N0 = (N0.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i16, N0)
|
2008-12-27 04:51:36 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N0)->getSExtValue(),
|
2008-09-12 16:56:44 +00:00
|
|
|
MVT::i16));
|
2008-12-27 04:51:36 +00:00
|
|
|
N1Opc = N1.getValueType().bitsLT(ShiftVT)
|
2008-08-31 15:37:04 +00:00
|
|
|
? ISD::SIGN_EXTEND
|
|
|
|
: ISD::TRUNCATE;
|
2007-12-04 22:23:35 +00:00
|
|
|
N1 = (N1.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(N1Opc, dl, ShiftVT, N1)
|
2008-09-12 16:56:44 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N1)->getZExtValue(),
|
2008-12-27 04:51:36 +00:00
|
|
|
ShiftVT));
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
|
|
|
|
DAG.getNode(Opc, dl, MVT::i16, N0, N1));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
case ISD::MUL: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N1 = Op.getOperand(1);
|
2007-12-04 22:23:35 +00:00
|
|
|
unsigned N1Opc;
|
|
|
|
N0 = (N0.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::i16, N0)
|
2008-09-12 16:56:44 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N0)->getZExtValue(),
|
|
|
|
MVT::i16));
|
2008-06-08 20:54:56 +00:00
|
|
|
N1Opc = N1.getValueType().bitsLT(MVT::i16) ? ISD::SIGN_EXTEND : ISD::TRUNCATE;
|
2007-12-04 22:23:35 +00:00
|
|
|
N1 = (N1.getOpcode() != ISD::Constant
|
2009-02-06 01:31:28 +00:00
|
|
|
? DAG.getNode(N1Opc, dl, MVT::i16, N1)
|
2008-12-27 04:51:36 +00:00
|
|
|
: DAG.getConstant(cast<ConstantSDNode>(N1)->getSExtValue(),
|
2008-09-12 16:56:44 +00:00
|
|
|
MVT::i16));
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
|
|
|
|
DAG.getNode(Opc, dl, MVT::i16, N0, N1));
|
2007-12-04 22:23:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-15 04:41:47 +00:00
|
|
|
//! Generate the carry-generate shuffle mask.
|
2009-02-06 01:31:28 +00:00
|
|
|
SDValue SPU::getCarryGenerateShufMask(SelectionDAG &DAG, DebugLoc dl) {
|
2009-01-21 04:58:48 +00:00
|
|
|
SmallVector<SDValue, 16 > ShufBytes;
|
2009-01-06 03:36:14 +00:00
|
|
|
|
2009-01-21 04:58:48 +00:00
|
|
|
// Create the shuffle mask for "rotating" the borrow up one register slot
|
|
|
|
// once the borrow is generated.
|
|
|
|
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));
|
2009-01-06 03:36:14 +00:00
|
|
|
|
2009-02-22 23:36:09 +00:00
|
|
|
return DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
&ShufBytes[0], ShufBytes.size());
|
2009-01-15 04:41:47 +00:00
|
|
|
}
|
2008-02-23 18:41:37 +00:00
|
|
|
|
2009-01-15 04:41:47 +00:00
|
|
|
//! Generate the borrow-generate shuffle mask
|
2009-02-06 01:31:28 +00:00
|
|
|
SDValue SPU::getBorrowGenerateShufMask(SelectionDAG &DAG, DebugLoc dl) {
|
2009-01-21 04:58:48 +00:00
|
|
|
SmallVector<SDValue, 16 > ShufBytes;
|
2008-06-02 22:18:03 +00:00
|
|
|
|
2009-01-21 04:58:48 +00:00
|
|
|
// Create the shuffle mask for "rotating" the borrow up one register slot
|
|
|
|
// once the borrow is generated.
|
|
|
|
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));
|
2008-02-23 18:41:37 +00:00
|
|
|
|
2009-02-22 23:36:09 +00:00
|
|
|
return DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
&ShufBytes[0], ShufBytes.size());
|
2008-02-23 18:41:37 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
//! Lower byte immediate operations for v16i8 vectors:
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue
|
|
|
|
LowerByteImmed(SDValue Op, SelectionDAG &DAG) {
|
|
|
|
SDValue ConstVec;
|
|
|
|
SDValue Arg;
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2009-02-06 01:31:28 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
ConstVec = Op.getOperand(0);
|
|
|
|
Arg = Op.getOperand(1);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (ConstVec.getNode()->getOpcode() != ISD::BUILD_VECTOR) {
|
|
|
|
if (ConstVec.getNode()->getOpcode() == ISD::BIT_CONVERT) {
|
2007-12-04 22:23:35 +00:00
|
|
|
ConstVec = ConstVec.getOperand(0);
|
|
|
|
} else {
|
|
|
|
ConstVec = Op.getOperand(1);
|
|
|
|
Arg = Op.getOperand(0);
|
2008-08-28 21:40:38 +00:00
|
|
|
if (ConstVec.getNode()->getOpcode() == ISD::BIT_CONVERT) {
|
2008-01-30 02:55:46 +00:00
|
|
|
ConstVec = ConstVec.getOperand(0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (ConstVec.getNode()->getOpcode() == ISD::BUILD_VECTOR) {
|
2007-12-04 22:23:35 +00:00
|
|
|
uint64_t VectorBits[2];
|
|
|
|
uint64_t UndefBits[2];
|
|
|
|
uint64_t SplatBits, SplatUndef;
|
|
|
|
int SplatSize;
|
|
|
|
|
2008-08-28 21:40:38 +00:00
|
|
|
if (!GetConstantBuildVectorBits(ConstVec.getNode(), VectorBits, UndefBits)
|
2008-01-30 02:55:46 +00:00
|
|
|
&& isConstantSplat(VectorBits, UndefBits,
|
2008-06-06 12:08:01 +00:00
|
|
|
VT.getVectorElementType().getSizeInBits(),
|
2008-01-30 02:55:46 +00:00
|
|
|
SplatBits, SplatUndef, SplatSize)) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue tcVec[16];
|
|
|
|
SDValue tc = DAG.getTargetConstant(SplatBits & 0xff, MVT::i8);
|
2007-12-04 22:23:35 +00:00
|
|
|
const size_t tcVecSize = sizeof(tcVec) / sizeof(tcVec[0]);
|
|
|
|
|
|
|
|
// Turn the BUILD_VECTOR into a set of target constants:
|
|
|
|
for (size_t i = 0; i < tcVecSize; ++i)
|
2008-01-30 02:55:46 +00:00
|
|
|
tcVec[i] = tc;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-06 01:31:28 +00:00
|
|
|
return DAG.getNode(Op.getNode()->getOpcode(), dl, VT, Arg,
|
2009-02-22 23:36:09 +00:00
|
|
|
DAG.getBUILD_VECTOR(VT, dl, tcVec, tcVecSize));
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-26 22:33:37 +00:00
|
|
|
|
2008-07-29 19:07:27 +00:00
|
|
|
// These operations (AND, OR, XOR) are legal, they just couldn't be custom
|
|
|
|
// lowered. Return the operation, rather than a null SDValue.
|
|
|
|
return Op;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Custom lowering for CTPOP (count population)
|
|
|
|
/*!
|
|
|
|
Custom lowering code that counts the number ones in the input
|
|
|
|
operand. SPU has such an instruction, but it counts the number of
|
|
|
|
ones per byte, which then have to be accumulated.
|
|
|
|
*/
|
2008-07-27 21:46:04 +00:00
|
|
|
static SDValue LowerCTPOP(SDValue Op, SelectionDAG &DAG) {
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT vecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits()));
|
2009-02-04 23:02:30 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-06-06 12:08:01 +00:00
|
|
|
switch (VT.getSimpleVT()) {
|
|
|
|
default:
|
|
|
|
assert(false && "Invalid value type!");
|
2007-12-04 22:23:35 +00:00
|
|
|
case MVT::i8: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N = Op.getOperand(0);
|
|
|
|
SDValue Elt0 = DAG.getConstant(0, MVT::i32);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
SDValue Promote = DAG.getNode(SPUISD::PREFSLOT2VEC, dl, vecVT, N, N);
|
|
|
|
SDValue CNTB = DAG.getNode(SPUISD::CNTB, dl, vecVT, Promote);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i8, CNTB, Elt0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case MVT::i16: {
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
2007-12-31 04:13:23 +00:00
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2007-12-31 04:13:23 +00:00
|
|
|
unsigned CNTB_reg = RegInfo.createVirtualRegister(&SPU::R16CRegClass);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N = Op.getOperand(0);
|
|
|
|
SDValue Elt0 = DAG.getConstant(0, MVT::i16);
|
|
|
|
SDValue Mask0 = DAG.getConstant(0x0f, MVT::i16);
|
2008-10-30 19:24:28 +00:00
|
|
|
SDValue Shift1 = DAG.getConstant(8, MVT::i32);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
SDValue Promote = DAG.getNode(SPUISD::PREFSLOT2VEC, dl, vecVT, N, N);
|
|
|
|
SDValue CNTB = DAG.getNode(SPUISD::CNTB, dl, vecVT, Promote);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// CNTB_result becomes the chain to which all of the virtual registers
|
|
|
|
// CNTB_reg, SUM1_reg become associated:
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CNTB_result =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i16, CNTB, Elt0);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CNTB_rescopy =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getCopyToReg(CNTB_result, dl, CNTB_reg, CNTB_result);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
SDValue Tmp1 = DAG.getCopyFromReg(CNTB_rescopy, dl, CNTB_reg, MVT::i16);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(ISD::AND, dl, MVT::i16,
|
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i16,
|
|
|
|
DAG.getNode(ISD::SRL, dl, MVT::i16,
|
2008-01-30 02:55:46 +00:00
|
|
|
Tmp1, Shift1),
|
|
|
|
Tmp1),
|
|
|
|
Mask0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case MVT::i32: {
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
2007-12-31 04:13:23 +00:00
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2007-12-31 04:13:23 +00:00
|
|
|
unsigned CNTB_reg = RegInfo.createVirtualRegister(&SPU::R32CRegClass);
|
|
|
|
unsigned SUM1_reg = RegInfo.createVirtualRegister(&SPU::R32CRegClass);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue N = Op.getOperand(0);
|
|
|
|
SDValue Elt0 = DAG.getConstant(0, MVT::i32);
|
|
|
|
SDValue Mask0 = DAG.getConstant(0xff, MVT::i32);
|
|
|
|
SDValue Shift1 = DAG.getConstant(16, MVT::i32);
|
|
|
|
SDValue Shift2 = DAG.getConstant(8, MVT::i32);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
SDValue Promote = DAG.getNode(SPUISD::PREFSLOT2VEC, dl, vecVT, N, N);
|
|
|
|
SDValue CNTB = DAG.getNode(SPUISD::CNTB, dl, vecVT, Promote);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
// CNTB_result becomes the chain to which all of the virtual registers
|
|
|
|
// CNTB_reg, SUM1_reg become associated:
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CNTB_result =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::i32, CNTB, Elt0);
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue CNTB_rescopy =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getCopyToReg(CNTB_result, dl, CNTB_reg, CNTB_result);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Comp1 =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(ISD::SRL, dl, MVT::i32,
|
|
|
|
DAG.getCopyFromReg(CNTB_rescopy, dl, CNTB_reg, MVT::i32),
|
|
|
|
Shift1);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Sum1 =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32, Comp1,
|
|
|
|
DAG.getCopyFromReg(CNTB_rescopy, dl, CNTB_reg, MVT::i32));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Sum1_rescopy =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getCopyToReg(CNTB_result, dl, SUM1_reg, Sum1);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Comp2 =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(ISD::SRL, dl, MVT::i32,
|
|
|
|
DAG.getCopyFromReg(Sum1_rescopy, dl, SUM1_reg, MVT::i32),
|
2008-01-30 02:55:46 +00:00
|
|
|
Shift2);
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Sum2 =
|
2009-02-04 23:02:30 +00:00
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32, Comp2,
|
|
|
|
DAG.getCopyFromReg(Sum1_rescopy, dl, SUM1_reg, MVT::i32));
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getNode(ISD::AND, dl, MVT::i32, Sum2, Mask0);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case MVT::i64:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
//! Lower ISD::FP_TO_SINT, ISD::FP_TO_UINT for i32
|
2009-01-21 04:58:48 +00:00
|
|
|
/*!
|
2009-01-26 03:31:40 +00:00
|
|
|
f32->i32 passes through unchanged, whereas f64->i32 expands to a libcall.
|
|
|
|
All conversions to i64 are expanded to a libcall.
|
2009-01-21 04:58:48 +00:00
|
|
|
*/
|
2009-01-26 03:31:40 +00:00
|
|
|
static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG,
|
|
|
|
SPUTargetLowering &TLI) {
|
2009-01-21 04:58:48 +00:00
|
|
|
MVT OpVT = Op.getValueType();
|
|
|
|
SDValue Op0 = Op.getOperand(0);
|
2009-01-26 03:31:40 +00:00
|
|
|
MVT Op0VT = Op0.getValueType();
|
|
|
|
|
|
|
|
if ((OpVT == MVT::i32 && Op0VT == MVT::f64)
|
|
|
|
|| OpVT == MVT::i64) {
|
|
|
|
// Convert f32 / f64 to i32 / i64 via libcall.
|
|
|
|
RTLIB::Libcall LC =
|
|
|
|
(Op.getOpcode() == ISD::FP_TO_SINT)
|
|
|
|
? RTLIB::getFPTOSINT(Op0VT, OpVT)
|
|
|
|
: RTLIB::getFPTOUINT(Op0VT, OpVT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd fp-to-int conversion!");
|
|
|
|
SDValue Dummy;
|
|
|
|
return ExpandLibCall(LC, Op, DAG, false, Dummy, TLI);
|
|
|
|
}
|
|
|
|
|
2009-01-26 22:33:37 +00:00
|
|
|
return Op; // return unmolested, legalized op
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
//! Lower ISD::SINT_TO_FP, ISD::UINT_TO_FP for i32
|
|
|
|
/*!
|
|
|
|
i32->f32 passes through unchanged, whereas i32->f64 is expanded to a libcall.
|
|
|
|
All conversions from i64 are expanded to a libcall.
|
|
|
|
*/
|
|
|
|
static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG,
|
|
|
|
SPUTargetLowering &TLI) {
|
|
|
|
MVT OpVT = Op.getValueType();
|
|
|
|
SDValue Op0 = Op.getOperand(0);
|
|
|
|
MVT Op0VT = Op0.getValueType();
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
if ((OpVT == MVT::f64 && Op0VT == MVT::i32)
|
|
|
|
|| Op0VT == MVT::i64) {
|
|
|
|
// Convert i32, i64 to f64 via libcall:
|
|
|
|
RTLIB::Libcall LC =
|
|
|
|
(Op.getOpcode() == ISD::SINT_TO_FP)
|
|
|
|
? RTLIB::getSINTTOFP(Op0VT, OpVT)
|
|
|
|
: RTLIB::getUINTTOFP(Op0VT, OpVT);
|
|
|
|
assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unexpectd int-to-fp conversion!");
|
|
|
|
SDValue Dummy;
|
|
|
|
return ExpandLibCall(LC, Op, DAG, false, Dummy, TLI);
|
|
|
|
}
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2009-01-26 22:33:37 +00:00
|
|
|
return Op; // return unmolested, legalized
|
2009-01-21 04:58:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//! Lower ISD::SETCC
|
|
|
|
/*!
|
|
|
|
This handles MVT::f64 (double floating point) condition lowering
|
|
|
|
*/
|
|
|
|
static SDValue LowerSETCC(SDValue Op, SelectionDAG &DAG,
|
|
|
|
const TargetLowering &TLI) {
|
2009-01-26 03:31:40 +00:00
|
|
|
CondCodeSDNode *CC = dyn_cast<CondCodeSDNode>(Op.getOperand(2));
|
2009-02-07 19:59:05 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2009-01-26 03:31:40 +00:00
|
|
|
assert(CC != 0 && "LowerSETCC: CondCodeSDNode should not be null here!\n");
|
|
|
|
|
2009-01-21 04:58:48 +00:00
|
|
|
SDValue lhs = Op.getOperand(0);
|
|
|
|
SDValue rhs = Op.getOperand(1);
|
|
|
|
MVT lhsVT = lhs.getValueType();
|
|
|
|
assert(lhsVT == MVT::f64 && "LowerSETCC: type other than MVT::64\n");
|
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
MVT ccResultVT = TLI.getSetCCResultType(lhs.getValueType());
|
|
|
|
APInt ccResultOnes = APInt::getAllOnesValue(ccResultVT.getSizeInBits());
|
|
|
|
MVT IntVT(MVT::i64);
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
// Take advantage of the fact that (truncate (sra arg, 32)) is efficiently
|
|
|
|
// selected to a NOP:
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue i64lhs = DAG.getNode(ISD::BIT_CONVERT, dl, IntVT, lhs);
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue lhsHi32 =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getNode(ISD::TRUNCATE, dl, MVT::i32,
|
|
|
|
DAG.getNode(ISD::SRL, dl, IntVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
i64lhs, DAG.getConstant(32, MVT::i32)));
|
|
|
|
SDValue lhsHi32abs =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getNode(ISD::AND, dl, MVT::i32,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhsHi32, DAG.getConstant(0x7fffffff, MVT::i32));
|
|
|
|
SDValue lhsLo32 =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, i64lhs);
|
2009-01-26 03:31:40 +00:00
|
|
|
|
|
|
|
// SETO and SETUO only use the lhs operand:
|
|
|
|
if (CC->get() == ISD::SETO) {
|
|
|
|
// Evaluates to true if Op0 is not [SQ]NaN - lowers to the inverse of
|
|
|
|
// SETUO
|
|
|
|
APInt ccResultAllOnes = APInt::getAllOnesValue(ccResultVT.getSizeInBits());
|
2009-02-04 01:48:28 +00:00
|
|
|
return DAG.getNode(ISD::XOR, dl, ccResultVT,
|
|
|
|
DAG.getSetCC(dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhs, DAG.getConstantFP(0.0, lhsVT),
|
|
|
|
ISD::SETUO),
|
|
|
|
DAG.getConstant(ccResultAllOnes, ccResultVT));
|
|
|
|
} else if (CC->get() == ISD::SETUO) {
|
|
|
|
// Evaluates to true if Op0 is [SQ]NaN
|
2009-02-04 01:48:28 +00:00
|
|
|
return DAG.getNode(ISD::AND, dl, ccResultVT,
|
|
|
|
DAG.getSetCC(dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhsHi32abs,
|
|
|
|
DAG.getConstant(0x7ff00000, MVT::i32),
|
|
|
|
ISD::SETGE),
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getSetCC(dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhsLo32,
|
|
|
|
DAG.getConstant(0, MVT::i32),
|
|
|
|
ISD::SETGT));
|
|
|
|
}
|
|
|
|
|
2009-02-07 00:55:49 +00:00
|
|
|
SDValue i64rhs = DAG.getNode(ISD::BIT_CONVERT, dl, IntVT, rhs);
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue rhsHi32 =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getNode(ISD::TRUNCATE, dl, MVT::i32,
|
|
|
|
DAG.getNode(ISD::SRL, dl, IntVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
i64rhs, DAG.getConstant(32, MVT::i32)));
|
|
|
|
|
|
|
|
// If a value is negative, subtract from the sign magnitude constant:
|
|
|
|
SDValue signMag2TC = DAG.getConstant(0x8000000000000000ULL, IntVT);
|
|
|
|
|
|
|
|
// Convert the sign-magnitude representation into 2's complement:
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue lhsSelectMask = DAG.getNode(ISD::SRA, dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhsHi32, DAG.getConstant(31, MVT::i32));
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue lhsSignMag2TC = DAG.getNode(ISD::SUB, dl, IntVT, signMag2TC, i64lhs);
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue lhsSelect =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getNode(ISD::SELECT, dl, IntVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhsSelectMask, lhsSignMag2TC, i64lhs);
|
|
|
|
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue rhsSelectMask = DAG.getNode(ISD::SRA, dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
rhsHi32, DAG.getConstant(31, MVT::i32));
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue rhsSignMag2TC = DAG.getNode(ISD::SUB, dl, IntVT, signMag2TC, i64rhs);
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue rhsSelect =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getNode(ISD::SELECT, dl, IntVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
rhsSelectMask, rhsSignMag2TC, i64rhs);
|
|
|
|
|
|
|
|
unsigned compareOp;
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
switch (CC->get()) {
|
|
|
|
case ISD::SETOEQ:
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETUEQ:
|
2009-01-26 03:31:40 +00:00
|
|
|
compareOp = ISD::SETEQ; break;
|
|
|
|
case ISD::SETOGT:
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETUGT:
|
2009-01-26 03:31:40 +00:00
|
|
|
compareOp = ISD::SETGT; break;
|
|
|
|
case ISD::SETOGE:
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETUGE:
|
2009-01-26 03:31:40 +00:00
|
|
|
compareOp = ISD::SETGE; break;
|
|
|
|
case ISD::SETOLT:
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETULT:
|
2009-01-26 03:31:40 +00:00
|
|
|
compareOp = ISD::SETLT; break;
|
|
|
|
case ISD::SETOLE:
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETULE:
|
2009-01-26 03:31:40 +00:00
|
|
|
compareOp = ISD::SETLE; break;
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETUNE:
|
2009-01-26 03:31:40 +00:00
|
|
|
case ISD::SETONE:
|
|
|
|
compareOp = ISD::SETNE; break;
|
2009-01-21 04:58:48 +00:00
|
|
|
default:
|
|
|
|
cerr << "CellSPU ISel Select: unimplemented f64 condition\n";
|
|
|
|
abort();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
SDValue result =
|
2009-02-04 01:48:28 +00:00
|
|
|
DAG.getSetCC(dl, ccResultVT, lhsSelect, rhsSelect,
|
|
|
|
(ISD::CondCode) compareOp);
|
2009-01-26 03:31:40 +00:00
|
|
|
|
|
|
|
if ((CC->get() & 0x8) == 0) {
|
|
|
|
// Ordered comparison:
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue lhsNaN = DAG.getSetCC(dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
lhs, DAG.getConstantFP(0.0, MVT::f64),
|
|
|
|
ISD::SETO);
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue rhsNaN = DAG.getSetCC(dl, ccResultVT,
|
2009-01-26 03:31:40 +00:00
|
|
|
rhs, DAG.getConstantFP(0.0, MVT::f64),
|
|
|
|
ISD::SETO);
|
2009-02-04 01:48:28 +00:00
|
|
|
SDValue ordered = DAG.getNode(ISD::AND, dl, ccResultVT, lhsNaN, rhsNaN);
|
2009-01-26 03:31:40 +00:00
|
|
|
|
2009-02-04 01:48:28 +00:00
|
|
|
result = DAG.getNode(ISD::AND, dl, ccResultVT, ordered, result);
|
2009-01-26 03:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2009-01-21 04:58:48 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
//! Lower ISD::SELECT_CC
|
|
|
|
/*!
|
|
|
|
ISD::SELECT_CC can (generally) be implemented directly on the SPU using the
|
|
|
|
SELB instruction.
|
|
|
|
|
|
|
|
\note Need to revisit this in the future: if the code path through the true
|
|
|
|
and false value computations is longer than the latency of a branch (6
|
|
|
|
cycles), then it would be more advantageous to branch and insert a new basic
|
|
|
|
block and branch on the condition. However, this code does not make that
|
|
|
|
assumption, given the simplisitc uses so far.
|
|
|
|
*/
|
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
static SDValue LowerSELECT_CC(SDValue Op, SelectionDAG &DAG,
|
|
|
|
const TargetLowering &TLI) {
|
2008-11-22 23:50:42 +00:00
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
SDValue lhs = Op.getOperand(0);
|
|
|
|
SDValue rhs = Op.getOperand(1);
|
|
|
|
SDValue trueval = Op.getOperand(2);
|
|
|
|
SDValue falseval = Op.getOperand(3);
|
|
|
|
SDValue condition = Op.getOperand(4);
|
2009-02-06 21:50:26 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-11-22 23:50:42 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// NOTE: SELB's arguments: $rA, $rB, $mask
|
|
|
|
//
|
|
|
|
// SELB selects bits from $rA where bits in $mask are 0, bits from $rB
|
|
|
|
// where bits in $mask are 1. CCond will be inverted, having 1s where the
|
|
|
|
// condition was true and 0s where the condition was false. Hence, the
|
|
|
|
// arguments to SELB get reversed.
|
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
// Note: Really should be ISD::SELECT instead of SPUISD::SELB, but LLVM's
|
|
|
|
// legalizer insists on combining SETCC/SELECT into SELECT_CC, so we end up
|
|
|
|
// with another "cannot select select_cc" assert:
|
|
|
|
|
2009-02-06 21:50:26 +00:00
|
|
|
SDValue compare = DAG.getNode(ISD::SETCC, dl,
|
2009-01-01 15:52:00 +00:00
|
|
|
TLI.getSetCCResultType(Op.getValueType()),
|
2008-12-27 04:51:36 +00:00
|
|
|
lhs, rhs, condition);
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::SELB, dl, VT, falseval, trueval, compare);
|
2008-11-22 23:50:42 +00:00
|
|
|
}
|
|
|
|
|
2008-12-02 19:53:53 +00:00
|
|
|
//! Custom lower ISD::TRUNCATE
|
|
|
|
static SDValue LowerTRUNCATE(SDValue Op, SelectionDAG &DAG)
|
|
|
|
{
|
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
MVT::SimpleValueType simpleVT = VT.getSimpleVT();
|
|
|
|
MVT VecVT = MVT::getVectorVT(VT, (128 / VT.getSizeInBits()));
|
2009-02-06 21:50:26 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-12-02 19:53:53 +00:00
|
|
|
|
|
|
|
SDValue Op0 = Op.getOperand(0);
|
|
|
|
MVT Op0VT = Op0.getValueType();
|
|
|
|
MVT Op0VecVT = MVT::getVectorVT(Op0VT, (128 / Op0VT.getSizeInBits()));
|
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
if (Op0VT.getSimpleVT() == MVT::i128 && simpleVT == MVT::i64) {
|
2009-01-03 00:27:53 +00:00
|
|
|
// Create shuffle mask, least significant doubleword of quadword
|
2008-12-27 04:51:36 +00:00
|
|
|
unsigned maskHigh = 0x08090a0b;
|
|
|
|
unsigned maskLow = 0x0c0d0e0f;
|
|
|
|
// Use a shuffle to perform the truncation
|
2009-02-22 23:36:09 +00:00
|
|
|
SDValue shufMask = DAG.getBUILD_VECTOR(MVT::v4i32, dl,
|
|
|
|
DAG.getConstant(maskHigh, MVT::i32),
|
|
|
|
DAG.getConstant(maskLow, MVT::i32),
|
|
|
|
DAG.getConstant(maskHigh, MVT::i32),
|
|
|
|
DAG.getConstant(maskLow, MVT::i32));
|
2008-12-02 19:53:53 +00:00
|
|
|
|
|
|
|
|
2009-02-06 21:50:26 +00:00
|
|
|
SDValue PromoteScalar = DAG.getNode(SPUISD::PREFSLOT2VEC, dl,
|
|
|
|
Op0VecVT, Op0);
|
2008-12-02 19:53:53 +00:00
|
|
|
|
2009-02-06 21:50:26 +00:00
|
|
|
SDValue truncShuffle = DAG.getNode(SPUISD::SHUFB, dl, Op0VecVT,
|
2008-12-27 04:51:36 +00:00
|
|
|
PromoteScalar, PromoteScalar, shufMask);
|
2008-12-02 19:53:53 +00:00
|
|
|
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::VEC2PREFSLOT, dl, VT,
|
2009-02-07 00:55:49 +00:00
|
|
|
DAG.getNode(ISD::BIT_CONVERT, dl, VecVT, truncShuffle));
|
2008-12-27 04:51:36 +00:00
|
|
|
}
|
2008-12-02 19:53:53 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
return SDValue(); // Leave the truncate unmolested
|
2008-12-02 19:53:53 +00:00
|
|
|
}
|
|
|
|
|
2008-11-22 23:50:42 +00:00
|
|
|
//! Custom (target-specific) lowering entry point
|
|
|
|
/*!
|
|
|
|
This is where LLVM's DAG selection process calls to do target-specific
|
|
|
|
lowering of nodes.
|
|
|
|
*/
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue
|
|
|
|
SPUTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG)
|
2007-12-04 22:23:35 +00:00
|
|
|
{
|
2008-02-23 18:41:37 +00:00
|
|
|
unsigned Opc = (unsigned) Op.getOpcode();
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT = Op.getValueType();
|
2008-02-23 18:41:37 +00:00
|
|
|
|
|
|
|
switch (Opc) {
|
2007-12-04 22:23:35 +00:00
|
|
|
default: {
|
|
|
|
cerr << "SPUTargetLowering::LowerOperation(): need to lower this!\n";
|
2008-02-23 18:41:37 +00:00
|
|
|
cerr << "Op.getOpcode() = " << Opc << "\n";
|
2008-08-28 21:40:38 +00:00
|
|
|
cerr << "*Op.getNode():\n";
|
|
|
|
Op.getNode()->dump();
|
2007-12-04 22:23:35 +00:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
case ISD::LOAD:
|
2008-12-02 19:53:53 +00:00
|
|
|
case ISD::EXTLOAD:
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::SEXTLOAD:
|
|
|
|
case ISD::ZEXTLOAD:
|
|
|
|
return LowerLOAD(Op, DAG, SPUTM.getSubtargetImpl());
|
|
|
|
case ISD::STORE:
|
|
|
|
return LowerSTORE(Op, DAG, SPUTM.getSubtargetImpl());
|
|
|
|
case ISD::ConstantPool:
|
|
|
|
return LowerConstantPool(Op, DAG, SPUTM.getSubtargetImpl());
|
|
|
|
case ISD::GlobalAddress:
|
|
|
|
return LowerGlobalAddress(Op, DAG, SPUTM.getSubtargetImpl());
|
|
|
|
case ISD::JumpTable:
|
|
|
|
return LowerJumpTable(Op, DAG, SPUTM.getSubtargetImpl());
|
|
|
|
case ISD::ConstantFP:
|
|
|
|
return LowerConstantFP(Op, DAG);
|
|
|
|
case ISD::FORMAL_ARGUMENTS:
|
2008-01-17 20:38:41 +00:00
|
|
|
return LowerFORMAL_ARGUMENTS(Op, DAG, VarArgsFrameIndex);
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::CALL:
|
2008-01-11 02:53:15 +00:00
|
|
|
return LowerCALL(Op, DAG, SPUTM.getSubtargetImpl());
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::RET:
|
|
|
|
return LowerRET(Op, DAG, getTargetMachine());
|
|
|
|
|
2008-12-30 23:28:25 +00:00
|
|
|
// i8, i64 math ops:
|
2008-06-02 22:18:03 +00:00
|
|
|
case ISD::ADD:
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::SUB:
|
|
|
|
case ISD::ROTR:
|
|
|
|
case ISD::ROTL:
|
|
|
|
case ISD::SRL:
|
|
|
|
case ISD::SHL:
|
2008-06-02 22:18:03 +00:00
|
|
|
case ISD::SRA: {
|
2008-02-23 18:41:37 +00:00
|
|
|
if (VT == MVT::i8)
|
2008-12-27 04:51:36 +00:00
|
|
|
return LowerI8Math(Op, DAG, Opc, *this);
|
2008-02-23 18:41:37 +00:00
|
|
|
break;
|
2008-06-02 22:18:03 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2009-01-26 03:31:40 +00:00
|
|
|
case ISD::FP_TO_SINT:
|
|
|
|
case ISD::FP_TO_UINT:
|
|
|
|
return LowerFP_TO_INT(Op, DAG, *this);
|
|
|
|
|
|
|
|
case ISD::SINT_TO_FP:
|
|
|
|
case ISD::UINT_TO_FP:
|
|
|
|
return LowerINT_TO_FP(Op, DAG, *this);
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
// Vector-related lowering.
|
|
|
|
case ISD::BUILD_VECTOR:
|
2009-01-26 03:31:40 +00:00
|
|
|
return LowerBUILD_VECTOR(Op, DAG);
|
2007-12-04 22:23:35 +00:00
|
|
|
case ISD::SCALAR_TO_VECTOR:
|
|
|
|
return LowerSCALAR_TO_VECTOR(Op, DAG);
|
|
|
|
case ISD::VECTOR_SHUFFLE:
|
|
|
|
return LowerVECTOR_SHUFFLE(Op, DAG);
|
|
|
|
case ISD::EXTRACT_VECTOR_ELT:
|
|
|
|
return LowerEXTRACT_VECTOR_ELT(Op, DAG);
|
|
|
|
case ISD::INSERT_VECTOR_ELT:
|
|
|
|
return LowerINSERT_VECTOR_ELT(Op, DAG);
|
|
|
|
|
|
|
|
// Look for ANDBI, ORBI and XORBI opportunities and lower appropriately:
|
|
|
|
case ISD::AND:
|
|
|
|
case ISD::OR:
|
|
|
|
case ISD::XOR:
|
|
|
|
return LowerByteImmed(Op, DAG);
|
|
|
|
|
|
|
|
// Vector and i8 multiply:
|
|
|
|
case ISD::MUL:
|
2008-12-30 23:28:25 +00:00
|
|
|
if (VT == MVT::i8)
|
2008-12-27 04:51:36 +00:00
|
|
|
return LowerI8Math(Op, DAG, Opc, *this);
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
case ISD::CTPOP:
|
|
|
|
return LowerCTPOP(Op, DAG);
|
2008-11-22 23:50:42 +00:00
|
|
|
|
|
|
|
case ISD::SELECT_CC:
|
2008-12-27 04:51:36 +00:00
|
|
|
return LowerSELECT_CC(Op, DAG, *this);
|
2008-12-02 19:53:53 +00:00
|
|
|
|
2009-01-21 04:58:48 +00:00
|
|
|
case ISD::SETCC:
|
|
|
|
return LowerSETCC(Op, DAG, *this);
|
|
|
|
|
2008-12-02 19:53:53 +00:00
|
|
|
case ISD::TRUNCATE:
|
|
|
|
return LowerTRUNCATE(Op, DAG);
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
return SDValue();
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
2008-12-01 11:39:25 +00:00
|
|
|
void SPUTargetLowering::ReplaceNodeResults(SDNode *N,
|
|
|
|
SmallVectorImpl<SDValue>&Results,
|
|
|
|
SelectionDAG &DAG)
|
2008-11-10 23:43:06 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
unsigned Opc = (unsigned) N->getOpcode();
|
|
|
|
MVT OpVT = N->getValueType(0);
|
|
|
|
|
|
|
|
switch (Opc) {
|
|
|
|
default: {
|
|
|
|
cerr << "SPUTargetLowering::ReplaceNodeResults(): need to fix this!\n";
|
|
|
|
cerr << "Op.getOpcode() = " << Opc << "\n";
|
|
|
|
cerr << "*Op.getNode():\n";
|
|
|
|
N->dump();
|
|
|
|
abort();
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Otherwise, return unchanged */
|
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Optimization Hooks
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue
|
2007-12-04 22:23:35 +00:00
|
|
|
SPUTargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
TargetMachine &TM = getTargetMachine();
|
2008-01-29 02:16:57 +00:00
|
|
|
#endif
|
|
|
|
const SPUSubtarget *ST = SPUTM.getSubtargetImpl();
|
2007-12-04 22:23:35 +00:00
|
|
|
SelectionDAG &DAG = DCI.DAG;
|
2008-12-01 17:56:02 +00:00
|
|
|
SDValue Op0 = N->getOperand(0); // everything has at least one operand
|
|
|
|
MVT NodeVT = N->getValueType(0); // The node's value type
|
2008-12-27 04:51:36 +00:00
|
|
|
MVT Op0VT = Op0.getValueType(); // The first operand's result
|
2008-12-01 17:56:02 +00:00
|
|
|
SDValue Result; // Initially, empty result
|
2009-02-06 21:50:26 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2007-12-04 22:23:35 +00:00
|
|
|
|
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default: break;
|
2008-01-29 02:16:57 +00:00
|
|
|
case ISD::ADD: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op1 = N->getOperand(1);
|
2008-01-29 02:16:57 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
if (Op0.getOpcode() == SPUISD::IndirectAddr
|
|
|
|
|| Op1.getOpcode() == SPUISD::IndirectAddr) {
|
|
|
|
// Normalize the operands to reduce repeated code
|
|
|
|
SDValue IndirectArg = Op0, AddArg = Op1;
|
2008-12-29 03:23:36 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
if (Op1.getOpcode() == SPUISD::IndirectAddr) {
|
|
|
|
IndirectArg = Op1;
|
|
|
|
AddArg = Op0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isa<ConstantSDNode>(AddArg)) {
|
|
|
|
ConstantSDNode *CN0 = cast<ConstantSDNode > (AddArg);
|
|
|
|
SDValue IndOp1 = IndirectArg.getOperand(1);
|
|
|
|
|
|
|
|
if (CN0->isNullValue()) {
|
|
|
|
// (add (SPUindirect <arg>, <arg>), 0) ->
|
|
|
|
// (SPUindirect <arg>, <arg>)
|
2008-01-29 02:16:57 +00:00
|
|
|
|
2008-12-04 17:16:59 +00:00
|
|
|
#if !defined(NDEBUG)
|
2008-12-27 04:51:36 +00:00
|
|
|
if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) {
|
2008-12-04 03:02:42 +00:00
|
|
|
cerr << "\n"
|
2008-12-27 04:51:36 +00:00
|
|
|
<< "Replace: (add (SPUindirect <arg>, <arg>), 0)\n"
|
|
|
|
<< "With: (SPUindirect <arg>, <arg>)\n";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return IndirectArg;
|
|
|
|
} else if (isa<ConstantSDNode>(IndOp1)) {
|
|
|
|
// (add (SPUindirect <arg>, <const>), <const>) ->
|
|
|
|
// (SPUindirect <arg>, <const + const>)
|
|
|
|
ConstantSDNode *CN1 = cast<ConstantSDNode > (IndOp1);
|
|
|
|
int64_t combinedConst = CN0->getSExtValue() + CN1->getSExtValue();
|
|
|
|
SDValue combinedValue = DAG.getConstant(combinedConst, Op0VT);
|
|
|
|
|
|
|
|
#if !defined(NDEBUG)
|
|
|
|
if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) {
|
|
|
|
cerr << "\n"
|
|
|
|
<< "Replace: (add (SPUindirect <arg>, " << CN1->getSExtValue()
|
|
|
|
<< "), " << CN0->getSExtValue() << ")\n"
|
2008-12-04 03:02:42 +00:00
|
|
|
<< "With: (SPUindirect <arg>, "
|
2008-12-27 04:51:36 +00:00
|
|
|
<< combinedConst << ")\n";
|
|
|
|
}
|
2008-12-04 03:02:42 +00:00
|
|
|
#endif
|
|
|
|
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::IndirectAddr, dl, Op0VT,
|
2008-12-27 04:51:36 +00:00
|
|
|
IndirectArg, combinedValue);
|
|
|
|
}
|
2008-01-29 02:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-23 18:41:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ISD::SIGN_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::ANY_EXTEND: {
|
2008-12-01 17:56:02 +00:00
|
|
|
if (Op0.getOpcode() == SPUISD::VEC2PREFSLOT && NodeVT == Op0VT) {
|
2008-02-23 18:41:37 +00:00
|
|
|
// (any_extend (SPUextract_elt0 <arg>)) ->
|
|
|
|
// (SPUextract_elt0 <arg>)
|
|
|
|
// Types must match, however...
|
2008-12-04 17:16:59 +00:00
|
|
|
#if !defined(NDEBUG)
|
|
|
|
if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) {
|
2008-12-04 03:02:42 +00:00
|
|
|
cerr << "\nReplace: ";
|
|
|
|
N->dump(&DAG);
|
|
|
|
cerr << "\nWith: ";
|
|
|
|
Op0.getNode()->dump(&DAG);
|
|
|
|
cerr << "\n";
|
2008-12-04 17:16:59 +00:00
|
|
|
}
|
2008-12-04 03:02:42 +00:00
|
|
|
#endif
|
2008-02-23 18:41:37 +00:00
|
|
|
|
|
|
|
return Op0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SPUISD::IndirectAddr: {
|
|
|
|
if (!ST->usingLargeMem() && Op0.getOpcode() == SPUISD::AFormAddr) {
|
2009-01-21 04:58:48 +00:00
|
|
|
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1));
|
|
|
|
if (CN != 0 && CN->getZExtValue() == 0) {
|
2008-02-23 18:41:37 +00:00
|
|
|
// (SPUindirect (SPUaform <addr>, 0), 0) ->
|
|
|
|
// (SPUaform <addr>, 0)
|
|
|
|
|
|
|
|
DEBUG(cerr << "Replace: ");
|
|
|
|
DEBUG(N->dump(&DAG));
|
|
|
|
DEBUG(cerr << "\nWith: ");
|
2008-08-28 21:40:38 +00:00
|
|
|
DEBUG(Op0.getNode()->dump(&DAG));
|
2008-02-23 18:41:37 +00:00
|
|
|
DEBUG(cerr << "\n");
|
|
|
|
|
|
|
|
return Op0;
|
|
|
|
}
|
2008-12-27 04:51:36 +00:00
|
|
|
} else if (Op0.getOpcode() == ISD::ADD) {
|
|
|
|
SDValue Op1 = N->getOperand(1);
|
|
|
|
if (ConstantSDNode *CN1 = dyn_cast<ConstantSDNode>(Op1)) {
|
|
|
|
// (SPUindirect (add <arg>, <arg>), 0) ->
|
|
|
|
// (SPUindirect <arg>, <arg>)
|
|
|
|
if (CN1->isNullValue()) {
|
|
|
|
|
|
|
|
#if !defined(NDEBUG)
|
|
|
|
if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) {
|
|
|
|
cerr << "\n"
|
|
|
|
<< "Replace: (SPUindirect (add <arg>, <arg>), 0)\n"
|
|
|
|
<< "With: (SPUindirect <arg>, <arg>)\n";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-02-06 21:50:26 +00:00
|
|
|
return DAG.getNode(SPUISD::IndirectAddr, dl, Op0VT,
|
2008-12-27 04:51:36 +00:00
|
|
|
Op0.getOperand(0), Op0.getOperand(1));
|
|
|
|
}
|
|
|
|
}
|
2008-02-23 18:41:37 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SPUISD::SHLQUAD_L_BITS:
|
|
|
|
case SPUISD::SHLQUAD_L_BYTES:
|
|
|
|
case SPUISD::VEC_SHL:
|
|
|
|
case SPUISD::VEC_SRL:
|
|
|
|
case SPUISD::VEC_SRA:
|
2008-12-27 04:51:36 +00:00
|
|
|
case SPUISD::ROTBYTES_LEFT: {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op1 = N->getOperand(1);
|
2008-02-23 18:41:37 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
// Kill degenerate vector shifts:
|
|
|
|
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op1)) {
|
|
|
|
if (CN->isNullValue()) {
|
2008-02-23 18:41:37 +00:00
|
|
|
Result = Op0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-12-27 04:51:36 +00:00
|
|
|
case SPUISD::PREFSLOT2VEC: {
|
2008-02-23 18:41:37 +00:00
|
|
|
switch (Op0.getOpcode()) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case ISD::ANY_EXTEND:
|
|
|
|
case ISD::ZERO_EXTEND:
|
|
|
|
case ISD::SIGN_EXTEND: {
|
2008-12-29 03:23:36 +00:00
|
|
|
// (SPUprefslot2vec (any|zero|sign_extend (SPUvec2prefslot <arg>))) ->
|
2008-02-23 18:41:37 +00:00
|
|
|
// <arg>
|
2008-12-29 03:23:36 +00:00
|
|
|
// but only if the SPUprefslot2vec and <arg> types match.
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op00 = Op0.getOperand(0);
|
2008-11-24 17:11:17 +00:00
|
|
|
if (Op00.getOpcode() == SPUISD::VEC2PREFSLOT) {
|
2008-07-27 21:46:04 +00:00
|
|
|
SDValue Op000 = Op00.getOperand(0);
|
2008-12-01 17:56:02 +00:00
|
|
|
if (Op000.getValueType() == NodeVT) {
|
2008-02-23 18:41:37 +00:00
|
|
|
Result = Op000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-11-24 17:11:17 +00:00
|
|
|
case SPUISD::VEC2PREFSLOT: {
|
2008-12-29 03:23:36 +00:00
|
|
|
// (SPUprefslot2vec (SPUvec2prefslot <arg>)) ->
|
2008-02-23 18:41:37 +00:00
|
|
|
// <arg>
|
|
|
|
Result = Op0.getOperand(0);
|
|
|
|
break;
|
2008-07-16 17:17:29 +00:00
|
|
|
}
|
2008-02-23 18:41:37 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-01-29 02:16:57 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2009-01-21 04:58:48 +00:00
|
|
|
|
2008-01-17 20:38:41 +00:00
|
|
|
// Otherwise, return unchanged.
|
2008-12-01 17:56:02 +00:00
|
|
|
#ifndef NDEBUG
|
2008-08-28 21:40:38 +00:00
|
|
|
if (Result.getNode()) {
|
2008-02-23 18:41:37 +00:00
|
|
|
DEBUG(cerr << "\nReplace.SPU: ");
|
|
|
|
DEBUG(N->dump(&DAG));
|
|
|
|
DEBUG(cerr << "\nWith: ");
|
2008-08-28 21:40:38 +00:00
|
|
|
DEBUG(Result.getNode()->dump(&DAG));
|
2008-02-23 18:41:37 +00:00
|
|
|
DEBUG(cerr << "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return Result;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Inline Assembly Support
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
/// getConstraintType - Given a constraint letter, return the type of
|
|
|
|
/// constraint it is for this target.
|
2008-07-16 17:17:29 +00:00
|
|
|
SPUTargetLowering::ConstraintType
|
2007-12-04 22:23:35 +00:00
|
|
|
SPUTargetLowering::getConstraintType(const std::string &ConstraintLetter) const {
|
|
|
|
if (ConstraintLetter.size() == 1) {
|
|
|
|
switch (ConstraintLetter[0]) {
|
|
|
|
default: break;
|
|
|
|
case 'b':
|
|
|
|
case 'r':
|
|
|
|
case 'f':
|
|
|
|
case 'v':
|
|
|
|
case 'y':
|
|
|
|
return C_RegisterClass;
|
2008-07-16 17:17:29 +00:00
|
|
|
}
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
|
|
|
return TargetLowering::getConstraintType(ConstraintLetter);
|
|
|
|
}
|
|
|
|
|
2008-07-16 17:17:29 +00:00
|
|
|
std::pair<unsigned, const TargetRegisterClass*>
|
2007-12-04 22:23:35 +00:00
|
|
|
SPUTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint,
|
2008-06-06 12:08:01 +00:00
|
|
|
MVT VT) const
|
2007-12-04 22:23:35 +00:00
|
|
|
{
|
|
|
|
if (Constraint.size() == 1) {
|
|
|
|
// GCC RS6000 Constraint Letters
|
|
|
|
switch (Constraint[0]) {
|
|
|
|
case 'b': // R1-R31
|
|
|
|
case 'r': // R0-R31
|
|
|
|
if (VT == MVT::i64)
|
|
|
|
return std::make_pair(0U, SPU::R64CRegisterClass);
|
|
|
|
return std::make_pair(0U, SPU::R32CRegisterClass);
|
|
|
|
case 'f':
|
|
|
|
if (VT == MVT::f32)
|
|
|
|
return std::make_pair(0U, SPU::R32FPRegisterClass);
|
|
|
|
else if (VT == MVT::f64)
|
|
|
|
return std::make_pair(0U, SPU::R64FPRegisterClass);
|
|
|
|
break;
|
2008-07-16 17:17:29 +00:00
|
|
|
case 'v':
|
2007-12-04 22:23:35 +00:00
|
|
|
return std::make_pair(0U, SPU::GPRCRegisterClass);
|
|
|
|
}
|
|
|
|
}
|
2008-07-16 17:17:29 +00:00
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT);
|
|
|
|
}
|
|
|
|
|
2008-02-23 18:41:37 +00:00
|
|
|
//! Compute used/known bits for a SPU operand
|
2007-12-04 22:23:35 +00:00
|
|
|
void
|
2008-07-27 21:46:04 +00:00
|
|
|
SPUTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op,
|
2008-02-13 22:28:48 +00:00
|
|
|
const APInt &Mask,
|
2008-07-16 17:17:29 +00:00
|
|
|
APInt &KnownZero,
|
2008-02-13 00:35:47 +00:00
|
|
|
APInt &KnownOne,
|
2008-01-30 02:55:46 +00:00
|
|
|
const SelectionDAG &DAG,
|
|
|
|
unsigned Depth ) const {
|
2008-04-30 00:30:08 +00:00
|
|
|
#if 0
|
2008-02-23 18:41:37 +00:00
|
|
|
const uint64_t uint64_sizebits = sizeof(uint64_t) * 8;
|
|
|
|
|
|
|
|
switch (Op.getOpcode()) {
|
|
|
|
default:
|
|
|
|
// KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
|
|
|
|
break;
|
|
|
|
case CALL:
|
|
|
|
case SHUFB:
|
2008-11-22 23:50:42 +00:00
|
|
|
case SHUFFLE_MASK:
|
2008-02-23 18:41:37 +00:00
|
|
|
case CNTB:
|
2009-01-21 04:58:48 +00:00
|
|
|
case SPUISD::PREFSLOT2VEC:
|
2008-02-23 18:41:37 +00:00
|
|
|
case SPUISD::LDRESULT:
|
2009-01-21 04:58:48 +00:00
|
|
|
case SPUISD::VEC2PREFSLOT:
|
2008-04-30 00:30:08 +00:00
|
|
|
case SPUISD::SHLQUAD_L_BITS:
|
|
|
|
case SPUISD::SHLQUAD_L_BYTES:
|
|
|
|
case SPUISD::VEC_SHL:
|
|
|
|
case SPUISD::VEC_SRL:
|
|
|
|
case SPUISD::VEC_SRA:
|
|
|
|
case SPUISD::VEC_ROTL:
|
|
|
|
case SPUISD::VEC_ROTR:
|
|
|
|
case SPUISD::ROTBYTES_LEFT:
|
2008-06-02 22:18:03 +00:00
|
|
|
case SPUISD::SELECT_MASK:
|
|
|
|
case SPUISD::SELB:
|
2008-02-23 18:41:37 +00:00
|
|
|
}
|
2009-01-21 04:58:48 +00:00
|
|
|
#endif
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
2008-12-30 23:28:25 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
unsigned
|
|
|
|
SPUTargetLowering::ComputeNumSignBitsForTargetNode(SDValue Op,
|
|
|
|
unsigned Depth) const {
|
|
|
|
switch (Op.getOpcode()) {
|
|
|
|
default:
|
|
|
|
return 1;
|
2007-12-04 22:23:35 +00:00
|
|
|
|
2008-12-27 04:51:36 +00:00
|
|
|
case ISD::SETCC: {
|
|
|
|
MVT VT = Op.getValueType();
|
|
|
|
|
|
|
|
if (VT != MVT::i8 && VT != MVT::i16 && VT != MVT::i32) {
|
|
|
|
VT = MVT::i32;
|
|
|
|
}
|
|
|
|
return VT.getSizeInBits();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-29 03:23:36 +00:00
|
|
|
|
2008-04-30 00:30:08 +00:00
|
|
|
// LowerAsmOperandForConstraint
|
|
|
|
void
|
2008-07-27 21:46:04 +00:00
|
|
|
SPUTargetLowering::LowerAsmOperandForConstraint(SDValue Op,
|
2008-04-30 00:30:08 +00:00
|
|
|
char ConstraintLetter,
|
2008-09-24 00:05:32 +00:00
|
|
|
bool hasMemory,
|
2008-07-27 21:46:04 +00:00
|
|
|
std::vector<SDValue> &Ops,
|
2008-04-30 00:30:08 +00:00
|
|
|
SelectionDAG &DAG) const {
|
|
|
|
// Default, for the time being, to the base class handler
|
2008-09-24 00:05:32 +00:00
|
|
|
TargetLowering::LowerAsmOperandForConstraint(Op, ConstraintLetter, hasMemory,
|
|
|
|
Ops, DAG);
|
2008-04-30 00:30:08 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 22:23:35 +00:00
|
|
|
/// isLegalAddressImmediate - Return true if the integer value can be used
|
|
|
|
/// as the offset of the target addressing mode.
|
2008-08-31 15:37:04 +00:00
|
|
|
bool SPUTargetLowering::isLegalAddressImmediate(int64_t V,
|
|
|
|
const Type *Ty) const {
|
2007-12-04 22:23:35 +00:00
|
|
|
// SPU's addresses are 256K:
|
|
|
|
return (V > -(1 << 18) && V < (1 << 18) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SPUTargetLowering::isLegalAddressImmediate(llvm::GlobalValue* GV) const {
|
2008-07-16 17:17:29 +00:00
|
|
|
return false;
|
2007-12-04 22:23:35 +00:00
|
|
|
}
|
Teach DAGCombine to fold constant offsets into GlobalAddress nodes,
and add a TargetLowering hook for it to use to determine when this
is legal (i.e. not in PIC mode, etc.)
This allows instruction selection to emit folded constant offsets
in more cases, such as the included testcase, eliminating the need
for explicit arithmetic instructions.
This eliminates the need for the C++ code in X86ISelDAGToDAG.cpp
that attempted to achieve the same effect, but wasn't as effective.
Also, fix handling of offsets in GlobalAddressSDNodes in several
places, including changing GlobalAddressSDNode's offset from
int to int64_t.
The Mips, Alpha, Sparc, and CellSPU targets appear to be
unaware of GlobalAddress offsets currently, so set the hook to
false on those targets.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57748 91177308-0d34-0410-b5e6-96231b3b80d8
2008-10-18 02:06:02 +00:00
|
|
|
|
|
|
|
bool
|
|
|
|
SPUTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const {
|
|
|
|
// The SPU target isn't yet aware of offsets.
|
|
|
|
return false;
|
|
|
|
}
|