2008-11-07 10:59:00 +00:00
|
|
|
//===-- XCoreISelLowering.cpp - XCore DAG Lowering Implementation ------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the XCoreTargetLowering class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "xcore-lower"
|
|
|
|
|
|
|
|
#include "XCoreISelLowering.h"
|
|
|
|
#include "XCoreMachineFunctionInfo.h"
|
|
|
|
#include "XCore.h"
|
2009-07-28 03:13:23 +00:00
|
|
|
#include "XCoreTargetObjectFile.h"
|
2008-11-07 10:59:00 +00:00
|
|
|
#include "XCoreTargetMachine.h"
|
|
|
|
#include "XCoreSubtarget.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Intrinsics.h"
|
|
|
|
#include "llvm/CallingConv.h"
|
|
|
|
#include "llvm/GlobalVariable.h"
|
|
|
|
#include "llvm/GlobalAlias.h"
|
|
|
|
#include "llvm/CodeGen/CallingConvLower.h"
|
|
|
|
#include "llvm/CodeGen/MachineFrameInfo.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2010-02-23 13:25:07 +00:00
|
|
|
#include "llvm/CodeGen/MachineJumpTableInfo.h"
|
2008-11-07 10:59:00 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
|
|
|
#include "llvm/CodeGen/ValueTypes.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2009-07-08 20:53:28 +00:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-07-25 00:23:56 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2008-11-07 10:59:00 +00:00
|
|
|
#include "llvm/ADT/VectorExtras.h"
|
|
|
|
#include <queue>
|
|
|
|
#include <set>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
const char *XCoreTargetLowering::
|
|
|
|
getTargetNodeName(unsigned Opcode) const
|
|
|
|
{
|
|
|
|
switch (Opcode)
|
|
|
|
{
|
|
|
|
case XCoreISD::BL : return "XCoreISD::BL";
|
|
|
|
case XCoreISD::PCRelativeWrapper : return "XCoreISD::PCRelativeWrapper";
|
|
|
|
case XCoreISD::DPRelativeWrapper : return "XCoreISD::DPRelativeWrapper";
|
|
|
|
case XCoreISD::CPRelativeWrapper : return "XCoreISD::CPRelativeWrapper";
|
|
|
|
case XCoreISD::STWSP : return "XCoreISD::STWSP";
|
|
|
|
case XCoreISD::RETSP : return "XCoreISD::RETSP";
|
2009-10-08 17:14:57 +00:00
|
|
|
case XCoreISD::LADD : return "XCoreISD::LADD";
|
|
|
|
case XCoreISD::LSUB : return "XCoreISD::LSUB";
|
2010-03-10 13:27:10 +00:00
|
|
|
case XCoreISD::LMUL : return "XCoreISD::LMUL";
|
2010-03-10 11:41:08 +00:00
|
|
|
case XCoreISD::MACCU : return "XCoreISD::MACCU";
|
|
|
|
case XCoreISD::MACCS : return "XCoreISD::MACCS";
|
2010-02-23 13:25:07 +00:00
|
|
|
case XCoreISD::BR_JT : return "XCoreISD::BR_JT";
|
|
|
|
case XCoreISD::BR_JT32 : return "XCoreISD::BR_JT32";
|
2010-03-10 11:42:05 +00:00
|
|
|
default : return NULL;
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XCoreTargetLowering::XCoreTargetLowering(XCoreTargetMachine &XTM)
|
2009-07-31 18:48:30 +00:00
|
|
|
: TargetLowering(XTM, new XCoreTargetObjectFile()),
|
2008-11-07 10:59:00 +00:00
|
|
|
TM(XTM),
|
|
|
|
Subtarget(*XTM.getSubtargetImpl()) {
|
|
|
|
|
|
|
|
// Set up the register classes.
|
2009-08-11 20:47:22 +00:00
|
|
|
addRegisterClass(MVT::i32, XCore::GRRegsRegisterClass);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Compute derived properties from the register classes
|
|
|
|
computeRegisterProperties();
|
|
|
|
|
|
|
|
// Division is expensive
|
|
|
|
setIntDivIsCheap(false);
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
setShiftAmountType(MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
setStackPointerRegisterToSaveRestore(XCore::SP);
|
|
|
|
|
2010-05-19 20:19:50 +00:00
|
|
|
setSchedulingPreference(Sched::RegPressure);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Use i32 for setcc operations results (slt, sgt, ...).
|
2008-11-23 15:47:28 +00:00
|
|
|
setBooleanContents(ZeroOrOneBooleanContent);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// XCore does not have the NodeTypes below.
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::BR_CC, MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::ADDC, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::ADDE, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SUBC, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SUBE, MVT::i32, Expand);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Stop the combiner recombining select and set_cc
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// 64bit
|
2009-10-06 16:01:09 +00:00
|
|
|
setOperationAction(ISD::ADD, MVT::i64, Custom);
|
|
|
|
setOperationAction(ISD::SUB, MVT::i64, Custom);
|
2010-03-10 13:20:07 +00:00
|
|
|
setOperationAction(ISD::SMUL_LOHI, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::UMUL_LOHI, MVT::i32, Custom);
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::MULHS, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::MULHU, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SRA_PARTS, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::SRL_PARTS, MVT::i32, Expand);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Bit Manipulation
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::CTPOP, MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::ROTL , MVT::i32, Expand);
|
|
|
|
setOperationAction(ISD::ROTR , MVT::i32, Expand);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::TRAP, MVT::Other, Legal);
|
2008-12-03 10:59:16 +00:00
|
|
|
|
2010-02-23 13:25:07 +00:00
|
|
|
// Jump tables.
|
|
|
|
setOperationAction(ISD::BR_JT, MVT::Other, Custom);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
|
2009-11-18 23:20:42 +00:00
|
|
|
setOperationAction(ISD::BlockAddress, MVT::i32 , Custom);
|
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
// Thread Local Storage
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Conversion of i64 -> double produces constantpool nodes
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::ConstantPool, MVT::i32, Custom);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Loads
|
2009-08-11 20:47:22 +00:00
|
|
|
setLoadExtAction(ISD::EXTLOAD, MVT::i1, Promote);
|
|
|
|
setLoadExtAction(ISD::ZEXTLOAD, MVT::i1, Promote);
|
|
|
|
setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
setLoadExtAction(ISD::SEXTLOAD, MVT::i8, Expand);
|
|
|
|
setLoadExtAction(ISD::ZEXTLOAD, MVT::i16, Expand);
|
2009-07-16 10:21:18 +00:00
|
|
|
|
|
|
|
// Custom expand misaligned loads / stores.
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::LOAD, MVT::i32, Custom);
|
|
|
|
setOperationAction(ISD::STORE, MVT::i32, Custom);
|
2009-07-16 10:21:18 +00:00
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
// Varargs
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::VAEND, MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::VACOPY, MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::VAARG, MVT::Other, Custom);
|
|
|
|
setOperationAction(ISD::VASTART, MVT::Other, Custom);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Dynamic stack
|
2009-08-11 20:47:22 +00:00
|
|
|
setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
|
|
|
|
setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
2009-07-16 12:41:34 +00:00
|
|
|
maxStoresPerMemset = 4;
|
|
|
|
maxStoresPerMemmove = maxStoresPerMemcpy = 2;
|
2009-07-16 12:50:48 +00:00
|
|
|
|
|
|
|
// We have target-specific dag combine patterns for the following nodes:
|
|
|
|
setTargetDAGCombine(ISD::STORE);
|
2010-03-10 16:19:31 +00:00
|
|
|
setTargetDAGCombine(ISD::ADD);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerOperation(SDValue Op, SelectionDAG &DAG) const {
|
2008-11-07 10:59:00 +00:00
|
|
|
switch (Op.getOpcode())
|
|
|
|
{
|
|
|
|
case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG);
|
|
|
|
case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG);
|
2009-11-18 23:20:42 +00:00
|
|
|
case ISD::BlockAddress: return LowerBlockAddress(Op, DAG);
|
2008-11-07 10:59:00 +00:00
|
|
|
case ISD::ConstantPool: return LowerConstantPool(Op, DAG);
|
2010-02-23 13:25:07 +00:00
|
|
|
case ISD::BR_JT: return LowerBR_JT(Op, DAG);
|
2009-07-16 10:21:18 +00:00
|
|
|
case ISD::LOAD: return LowerLOAD(Op, DAG);
|
|
|
|
case ISD::STORE: return LowerSTORE(Op, DAG);
|
2008-11-07 10:59:00 +00:00
|
|
|
case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
|
|
|
|
case ISD::VAARG: return LowerVAARG(Op, DAG);
|
|
|
|
case ISD::VASTART: return LowerVASTART(Op, DAG);
|
2010-03-10 13:20:07 +00:00
|
|
|
case ISD::SMUL_LOHI: return LowerSMUL_LOHI(Op, DAG);
|
|
|
|
case ISD::UMUL_LOHI: return LowerUMUL_LOHI(Op, DAG);
|
2008-11-07 10:59:00 +00:00
|
|
|
// FIXME: Remove these when LegalizeDAGTypes lands.
|
|
|
|
case ISD::ADD:
|
2008-12-01 11:39:25 +00:00
|
|
|
case ISD::SUB: return ExpandADDSUB(Op.getNode(), DAG);
|
2008-11-07 10:59:00 +00:00
|
|
|
case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG);
|
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("unimplemented operand");
|
2008-11-07 10:59:00 +00:00
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-01 11:39:25 +00:00
|
|
|
/// ReplaceNodeResults - Replace the results of node with an illegal result
|
|
|
|
/// type with new values built out of custom code.
|
|
|
|
void XCoreTargetLowering::ReplaceNodeResults(SDNode *N,
|
|
|
|
SmallVectorImpl<SDValue>&Results,
|
2010-04-17 15:26:15 +00:00
|
|
|
SelectionDAG &DAG) const {
|
2008-11-07 10:59:00 +00:00
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Don't know how to custom expand this!");
|
2008-12-01 11:39:25 +00:00
|
|
|
return;
|
2008-11-14 15:59:19 +00:00
|
|
|
case ISD::ADD:
|
2008-12-01 11:39:25 +00:00
|
|
|
case ISD::SUB:
|
|
|
|
Results.push_back(ExpandADDSUB(N, DAG));
|
|
|
|
return;
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-01 18:50:55 +00:00
|
|
|
/// getFunctionAlignment - Return the Log2 alignment of this function.
|
2009-06-30 22:38:32 +00:00
|
|
|
unsigned XCoreTargetLowering::
|
|
|
|
getFunctionAlignment(const Function *) const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Misc Lower Operation implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2009-02-06 21:50:26 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue Cond = DAG.getNode(ISD::SETCC, dl, MVT::i32, Op.getOperand(2),
|
2008-11-07 10:59:00 +00:00
|
|
|
Op.getOperand(3), Op.getOperand(4));
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(ISD::SELECT, dl, MVT::i32, Cond, Op.getOperand(0),
|
2008-11-07 10:59:00 +00:00
|
|
|
Op.getOperand(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
getGlobalAddressWrapper(SDValue GA, const GlobalValue *GV,
|
|
|
|
SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2009-02-07 00:55:49 +00:00
|
|
|
// FIXME there is no actual debug info here
|
|
|
|
DebugLoc dl = GA.getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
if (isa<Function>(GV)) {
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(XCoreISD::PCRelativeWrapper, dl, MVT::i32, GA);
|
2009-10-06 16:01:09 +00:00
|
|
|
}
|
|
|
|
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
|
|
|
if (!GVar) {
|
|
|
|
// If GV is an alias then use the aliasee to determine constness
|
|
|
|
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
|
|
|
|
GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal());
|
|
|
|
}
|
|
|
|
bool isConst = GVar && GVar->isConstant();
|
|
|
|
if (isConst) {
|
|
|
|
return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, GA);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(XCoreISD::DPRelativeWrapper, dl, MVT::i32, GA);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerGlobalAddress(SDValue Op, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
2010-07-06 22:08:15 +00:00
|
|
|
SDValue GA = DAG.getTargetGlobalAddress(GV, Op.getDebugLoc(), MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
// If it's a debug information descriptor, don't mess with it.
|
|
|
|
if (DAG.isVerifiedDebugInfoDesc(Op))
|
|
|
|
return GA;
|
|
|
|
return getGlobalAddressWrapper(GA, GV, DAG);
|
|
|
|
}
|
|
|
|
|
2009-02-07 00:55:49 +00:00
|
|
|
static inline SDValue BuildGetId(SelectionDAG &DAG, DebugLoc dl) {
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32,
|
|
|
|
DAG.getConstant(Intrinsic::xcore_getid, MVT::i32));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isZeroLengthArray(const Type *Ty) {
|
|
|
|
const ArrayType *AT = dyn_cast_or_null<ArrayType>(Ty);
|
|
|
|
return AT && (AT->getNumElements() == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2009-02-06 21:50:26 +00:00
|
|
|
// FIXME there isn't really debug info here
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
// transform to label + getid() * size
|
2010-04-15 01:51:59 +00:00
|
|
|
const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
2010-07-06 22:08:15 +00:00
|
|
|
SDValue GA = DAG.getTargetGlobalAddress(GV, dl, MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
|
|
|
if (!GVar) {
|
|
|
|
// If GV is an alias then use the aliasee to determine size
|
|
|
|
if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
|
|
|
|
GVar = dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal());
|
|
|
|
}
|
|
|
|
if (! GVar) {
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Thread local object not a GlobalVariable?");
|
2008-11-07 10:59:00 +00:00
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
const Type *Ty = cast<PointerType>(GV->getType())->getElementType();
|
|
|
|
if (!Ty->isSized() || isZeroLengthArray(Ty)) {
|
2009-07-08 20:53:28 +00:00
|
|
|
#ifndef NDEBUG
|
2009-07-25 00:23:56 +00:00
|
|
|
errs() << "Size of thread local object " << GVar->getName()
|
|
|
|
<< " is unknown\n";
|
2009-07-08 20:53:28 +00:00
|
|
|
#endif
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable(0);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
SDValue base = getGlobalAddressWrapper(GA, GV, DAG);
|
|
|
|
const TargetData *TD = TM.getTargetData();
|
2009-05-09 07:06:46 +00:00
|
|
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue offset = DAG.getNode(ISD::MUL, dl, MVT::i32, BuildGetId(DAG, dl),
|
|
|
|
DAG.getConstant(Size, MVT::i32));
|
|
|
|
return DAG.getNode(ISD::ADD, dl, MVT::i32, base, offset);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
2009-11-18 23:20:42 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerBlockAddress(SDValue Op, SelectionDAG &DAG) const
|
2009-11-18 23:20:42 +00:00
|
|
|
{
|
|
|
|
DebugLoc DL = Op.getDebugLoc();
|
|
|
|
|
2010-04-15 01:51:59 +00:00
|
|
|
const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress();
|
2009-11-20 23:18:13 +00:00
|
|
|
SDValue Result = DAG.getBlockAddress(BA, getPointerTy(), /*isTarget=*/true);
|
2009-11-18 23:20:42 +00:00
|
|
|
|
|
|
|
return DAG.getNode(XCoreISD::PCRelativeWrapper, DL, getPointerTy(), Result);
|
|
|
|
}
|
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerConstantPool(SDValue Op, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
|
|
|
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
|
2009-02-06 21:50:26 +00:00
|
|
|
// FIXME there isn't really debug info here
|
|
|
|
DebugLoc dl = CP->getDebugLoc();
|
2009-10-06 16:01:09 +00:00
|
|
|
EVT PtrVT = Op.getValueType();
|
|
|
|
SDValue Res;
|
|
|
|
if (CP->isMachineConstantPoolEntry()) {
|
|
|
|
Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT,
|
|
|
|
CP->getAlignment());
|
2008-11-07 10:59:00 +00:00
|
|
|
} else {
|
2009-10-06 16:01:09 +00:00
|
|
|
Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT,
|
|
|
|
CP->getAlignment());
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
2009-10-06 16:01:09 +00:00
|
|
|
return DAG.getNode(XCoreISD::CPRelativeWrapper, dl, MVT::i32, Res);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
2010-03-11 14:58:56 +00:00
|
|
|
unsigned XCoreTargetLowering::getJumpTableEncoding() const {
|
|
|
|
return MachineJumpTableInfo::EK_Inline;
|
|
|
|
}
|
|
|
|
|
2010-02-23 13:25:07 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerBR_JT(SDValue Op, SelectionDAG &DAG) const
|
2010-02-23 13:25:07 +00:00
|
|
|
{
|
|
|
|
SDValue Chain = Op.getOperand(0);
|
|
|
|
SDValue Table = Op.getOperand(1);
|
|
|
|
SDValue Index = Op.getOperand(2);
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
|
|
|
JumpTableSDNode *JT = cast<JumpTableSDNode>(Table);
|
|
|
|
unsigned JTI = JT->getIndex();
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
const MachineJumpTableInfo *MJTI = MF.getJumpTableInfo();
|
|
|
|
SDValue TargetJT = DAG.getTargetJumpTable(JT->getIndex(), MVT::i32);
|
|
|
|
|
|
|
|
unsigned NumEntries = MJTI->getJumpTables()[JTI].MBBs.size();
|
|
|
|
if (NumEntries <= 32) {
|
|
|
|
return DAG.getNode(XCoreISD::BR_JT, dl, MVT::Other, Chain, TargetJT, Index);
|
|
|
|
}
|
|
|
|
assert((NumEntries >> 31) == 0);
|
|
|
|
SDValue ScaledIndex = DAG.getNode(ISD::SHL, dl, MVT::i32, Index,
|
|
|
|
DAG.getConstant(1, MVT::i32));
|
|
|
|
return DAG.getNode(XCoreISD::BR_JT32, dl, MVT::Other, Chain, TargetJT,
|
|
|
|
ScaledIndex);
|
|
|
|
}
|
|
|
|
|
2009-07-16 10:42:35 +00:00
|
|
|
static bool
|
|
|
|
IsWordAlignedBasePlusConstantOffset(SDValue Addr, SDValue &AlignedBase,
|
|
|
|
int64_t &Offset)
|
|
|
|
{
|
|
|
|
if (Addr.getOpcode() != ISD::ADD) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ConstantSDNode *CN = 0;
|
|
|
|
if (!(CN = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
int64_t off = CN->getSExtValue();
|
|
|
|
const SDValue &Base = Addr.getOperand(0);
|
|
|
|
const SDValue *Root = &Base;
|
|
|
|
if (Base.getOpcode() == ISD::ADD &&
|
|
|
|
Base.getOperand(1).getOpcode() == ISD::SHL) {
|
|
|
|
ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Base.getOperand(1)
|
|
|
|
.getOperand(1));
|
|
|
|
if (CN && (CN->getSExtValue() >= 2)) {
|
|
|
|
Root = &Base.getOperand(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isa<FrameIndexSDNode>(*Root)) {
|
|
|
|
// All frame indicies are word aligned
|
|
|
|
AlignedBase = Base;
|
|
|
|
Offset = off;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Root->getOpcode() == XCoreISD::DPRelativeWrapper ||
|
|
|
|
Root->getOpcode() == XCoreISD::CPRelativeWrapper) {
|
|
|
|
// All dp / cp relative addresses are word aligned
|
|
|
|
AlignedBase = Base;
|
|
|
|
Offset = off;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-16 10:21:18 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-09-21 17:04:51 +00:00
|
|
|
LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
|
2009-07-16 10:21:18 +00:00
|
|
|
LoadSDNode *LD = cast<LoadSDNode>(Op);
|
2009-08-15 21:21:19 +00:00
|
|
|
assert(LD->getExtensionType() == ISD::NON_EXTLOAD &&
|
|
|
|
"Unexpected extension type");
|
2009-08-11 20:47:22 +00:00
|
|
|
assert(LD->getMemoryVT() == MVT::i32 && "Unexpected load EVT");
|
2010-09-21 17:04:51 +00:00
|
|
|
if (allowsUnalignedMemoryAccesses(LD->getMemoryVT()))
|
2009-07-16 10:21:18 +00:00
|
|
|
return SDValue();
|
2010-09-21 17:04:51 +00:00
|
|
|
|
2009-07-16 10:21:18 +00:00
|
|
|
unsigned ABIAlignment = getTargetData()->
|
2009-08-12 00:36:31 +00:00
|
|
|
getABITypeAlignment(LD->getMemoryVT().getTypeForEVT(*DAG.getContext()));
|
2009-07-16 10:21:18 +00:00
|
|
|
// Leave aligned load alone.
|
2010-09-21 17:04:51 +00:00
|
|
|
if (LD->getAlignment() >= ABIAlignment)
|
2009-07-16 10:21:18 +00:00
|
|
|
return SDValue();
|
2010-09-21 17:04:51 +00:00
|
|
|
|
2009-07-16 10:21:18 +00:00
|
|
|
SDValue Chain = LD->getChain();
|
|
|
|
SDValue BasePtr = LD->getBasePtr();
|
2010-09-21 17:04:51 +00:00
|
|
|
DebugLoc DL = Op.getDebugLoc();
|
2009-07-16 10:21:18 +00:00
|
|
|
|
2009-07-16 10:42:35 +00:00
|
|
|
SDValue Base;
|
|
|
|
int64_t Offset;
|
|
|
|
if (!LD->isVolatile() &&
|
|
|
|
IsWordAlignedBasePlusConstantOffset(BasePtr, Base, Offset)) {
|
|
|
|
if (Offset % 4 == 0) {
|
|
|
|
// We've managed to infer better alignment information than the load
|
|
|
|
// already has. Use an aligned load.
|
2010-02-15 16:49:52 +00:00
|
|
|
//
|
2010-09-21 17:04:51 +00:00
|
|
|
return DAG.getLoad(getPointerTy(), DL, Chain, BasePtr,
|
2010-09-21 06:44:06 +00:00
|
|
|
MachinePointerInfo(),
|
2010-02-15 16:49:52 +00:00
|
|
|
false, false, 0);
|
2009-07-16 10:42:35 +00:00
|
|
|
}
|
|
|
|
// Lower to
|
|
|
|
// ldw low, base[offset >> 2]
|
|
|
|
// ldw high, base[(offset >> 2) + 1]
|
|
|
|
// shr low_shifted, low, (offset & 0x3) * 8
|
|
|
|
// shl high_shifted, high, 32 - (offset & 0x3) * 8
|
|
|
|
// or result, low_shifted, high_shifted
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue LowOffset = DAG.getConstant(Offset & ~0x3, MVT::i32);
|
|
|
|
SDValue HighOffset = DAG.getConstant((Offset & ~0x3) + 4, MVT::i32);
|
|
|
|
SDValue LowShift = DAG.getConstant((Offset & 0x3) * 8, MVT::i32);
|
|
|
|
SDValue HighShift = DAG.getConstant(32 - (Offset & 0x3) * 8, MVT::i32);
|
2009-07-16 10:42:35 +00:00
|
|
|
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue LowAddr = DAG.getNode(ISD::ADD, DL, MVT::i32, Base, LowOffset);
|
|
|
|
SDValue HighAddr = DAG.getNode(ISD::ADD, DL, MVT::i32, Base, HighOffset);
|
2009-07-16 10:42:35 +00:00
|
|
|
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue Low = DAG.getLoad(getPointerTy(), DL, Chain,
|
2010-09-21 06:44:06 +00:00
|
|
|
LowAddr, MachinePointerInfo(), false, false, 0);
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue High = DAG.getLoad(getPointerTy(), DL, Chain,
|
2010-09-21 06:44:06 +00:00
|
|
|
HighAddr, MachinePointerInfo(), false, false, 0);
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue LowShifted = DAG.getNode(ISD::SRL, DL, MVT::i32, Low, LowShift);
|
|
|
|
SDValue HighShifted = DAG.getNode(ISD::SHL, DL, MVT::i32, High, HighShift);
|
|
|
|
SDValue Result = DAG.getNode(ISD::OR, DL, MVT::i32, LowShifted, HighShifted);
|
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Low.getValue(1),
|
2009-07-16 10:42:35 +00:00
|
|
|
High.getValue(1));
|
|
|
|
SDValue Ops[] = { Result, Chain };
|
2010-09-21 17:04:51 +00:00
|
|
|
return DAG.getMergeValues(Ops, 2, DL);
|
2009-07-16 10:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (LD->getAlignment() == 2) {
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue Low = DAG.getExtLoad(ISD::ZEXTLOAD, MVT::i32, DL, Chain,
|
|
|
|
BasePtr, LD->getPointerInfo(), MVT::i16,
|
2010-02-15 16:49:52 +00:00
|
|
|
LD->isVolatile(), LD->isNonTemporal(), 2);
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue HighAddr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr,
|
2009-08-11 20:47:22 +00:00
|
|
|
DAG.getConstant(2, MVT::i32));
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue High = DAG.getExtLoad(ISD::EXTLOAD, MVT::i32, DL, Chain,
|
|
|
|
HighAddr,
|
|
|
|
LD->getPointerInfo().getWithOffset(2),
|
2010-02-15 16:49:52 +00:00
|
|
|
MVT::i16, LD->isVolatile(),
|
|
|
|
LD->isNonTemporal(), 2);
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue HighShifted = DAG.getNode(ISD::SHL, DL, MVT::i32, High,
|
2009-08-11 20:47:22 +00:00
|
|
|
DAG.getConstant(16, MVT::i32));
|
2010-09-21 17:04:51 +00:00
|
|
|
SDValue Result = DAG.getNode(ISD::OR, DL, MVT::i32, Low, HighShifted);
|
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Low.getValue(1),
|
2009-07-16 10:42:35 +00:00
|
|
|
High.getValue(1));
|
|
|
|
SDValue Ops[] = { Result, Chain };
|
2010-09-21 17:04:51 +00:00
|
|
|
return DAG.getMergeValues(Ops, 2, DL);
|
2009-07-16 10:42:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 10:21:18 +00:00
|
|
|
// Lower to a call to __misaligned_load(BasePtr).
|
2009-08-13 21:58:54 +00:00
|
|
|
const Type *IntPtrTy = getTargetData()->getIntPtrType(*DAG.getContext());
|
2009-07-16 10:21:18 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
TargetLowering::ArgListEntry Entry;
|
|
|
|
|
|
|
|
Entry.Ty = IntPtrTy;
|
|
|
|
Entry.Node = BasePtr;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
std::pair<SDValue, SDValue> CallResult =
|
|
|
|
LowerCallTo(Chain, IntPtrTy, false, false,
|
|
|
|
false, false, 0, CallingConv::C, false,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
/*isReturnValueUsed=*/true,
|
2009-07-16 10:21:18 +00:00
|
|
|
DAG.getExternalSymbol("__misaligned_load", getPointerTy()),
|
2010-09-21 17:04:51 +00:00
|
|
|
Args, DAG, DL);
|
2009-07-16 10:21:18 +00:00
|
|
|
|
|
|
|
SDValue Ops[] =
|
|
|
|
{ CallResult.first, CallResult.second };
|
|
|
|
|
2010-09-21 17:04:51 +00:00
|
|
|
return DAG.getMergeValues(Ops, 2, DL);
|
2009-07-16 10:21:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerSTORE(SDValue Op, SelectionDAG &DAG) const
|
2009-07-16 10:21:18 +00:00
|
|
|
{
|
|
|
|
StoreSDNode *ST = cast<StoreSDNode>(Op);
|
|
|
|
assert(!ST->isTruncatingStore() && "Unexpected store type");
|
2009-08-11 20:47:22 +00:00
|
|
|
assert(ST->getMemoryVT() == MVT::i32 && "Unexpected store EVT");
|
2009-08-15 21:21:19 +00:00
|
|
|
if (allowsUnalignedMemoryAccesses(ST->getMemoryVT())) {
|
2009-07-16 10:21:18 +00:00
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
unsigned ABIAlignment = getTargetData()->
|
2009-08-12 00:36:31 +00:00
|
|
|
getABITypeAlignment(ST->getMemoryVT().getTypeForEVT(*DAG.getContext()));
|
2009-07-16 10:21:18 +00:00
|
|
|
// Leave aligned store alone.
|
|
|
|
if (ST->getAlignment() >= ABIAlignment) {
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
SDValue Chain = ST->getChain();
|
|
|
|
SDValue BasePtr = ST->getBasePtr();
|
|
|
|
SDValue Value = ST->getValue();
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
|
|
|
|
2009-07-16 10:42:35 +00:00
|
|
|
if (ST->getAlignment() == 2) {
|
|
|
|
SDValue Low = Value;
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue High = DAG.getNode(ISD::SRL, dl, MVT::i32, Value,
|
|
|
|
DAG.getConstant(16, MVT::i32));
|
2009-07-16 10:42:35 +00:00
|
|
|
SDValue StoreLow = DAG.getTruncStore(Chain, dl, Low, BasePtr,
|
2010-09-21 17:42:31 +00:00
|
|
|
ST->getPointerInfo(), MVT::i16,
|
2010-02-15 16:49:52 +00:00
|
|
|
ST->isVolatile(), ST->isNonTemporal(),
|
|
|
|
2);
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue HighAddr = DAG.getNode(ISD::ADD, dl, MVT::i32, BasePtr,
|
|
|
|
DAG.getConstant(2, MVT::i32));
|
2009-07-16 10:42:35 +00:00
|
|
|
SDValue StoreHigh = DAG.getTruncStore(Chain, dl, High, HighAddr,
|
2010-09-21 17:42:31 +00:00
|
|
|
ST->getPointerInfo().getWithOffset(2),
|
2010-02-15 16:49:52 +00:00
|
|
|
MVT::i16, ST->isVolatile(),
|
|
|
|
ST->isNonTemporal(), 2);
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, StoreLow, StoreHigh);
|
2009-07-16 10:42:35 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 10:21:18 +00:00
|
|
|
// Lower to a call to __misaligned_store(BasePtr, Value).
|
2009-08-13 21:58:54 +00:00
|
|
|
const Type *IntPtrTy = getTargetData()->getIntPtrType(*DAG.getContext());
|
2009-07-16 10:21:18 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
TargetLowering::ArgListEntry Entry;
|
|
|
|
|
|
|
|
Entry.Ty = IntPtrTy;
|
|
|
|
Entry.Node = BasePtr;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
Entry.Node = Value;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
std::pair<SDValue, SDValue> CallResult =
|
2009-08-13 21:58:54 +00:00
|
|
|
LowerCallTo(Chain, Type::getVoidTy(*DAG.getContext()), false, false,
|
2009-07-16 10:21:18 +00:00
|
|
|
false, false, 0, CallingConv::C, false,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
/*isReturnValueUsed=*/true,
|
2009-07-16 10:21:18 +00:00
|
|
|
DAG.getExternalSymbol("__misaligned_store", getPointerTy()),
|
2010-03-02 01:55:18 +00:00
|
|
|
Args, DAG, dl);
|
2009-07-16 10:21:18 +00:00
|
|
|
|
|
|
|
return CallResult.second;
|
|
|
|
}
|
|
|
|
|
2010-03-10 13:20:07 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerSMUL_LOHI(SDValue Op, SelectionDAG &DAG) const
|
2010-03-10 13:20:07 +00:00
|
|
|
{
|
|
|
|
assert(Op.getValueType() == MVT::i32 && Op.getOpcode() == ISD::SMUL_LOHI &&
|
|
|
|
"Unexpected operand to lower!");
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
|
|
|
SDValue LHS = Op.getOperand(0);
|
|
|
|
SDValue RHS = Op.getOperand(1);
|
|
|
|
SDValue Zero = DAG.getConstant(0, MVT::i32);
|
|
|
|
SDValue Hi = DAG.getNode(XCoreISD::MACCS, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), Zero, Zero,
|
|
|
|
LHS, RHS);
|
|
|
|
SDValue Lo(Hi.getNode(), 1);
|
|
|
|
SDValue Ops[] = { Lo, Hi };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerUMUL_LOHI(SDValue Op, SelectionDAG &DAG) const
|
2010-03-10 13:20:07 +00:00
|
|
|
{
|
|
|
|
assert(Op.getValueType() == MVT::i32 && Op.getOpcode() == ISD::UMUL_LOHI &&
|
|
|
|
"Unexpected operand to lower!");
|
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
|
|
|
SDValue LHS = Op.getOperand(0);
|
|
|
|
SDValue RHS = Op.getOperand(1);
|
|
|
|
SDValue Zero = DAG.getConstant(0, MVT::i32);
|
2010-03-10 13:27:10 +00:00
|
|
|
SDValue Hi = DAG.getNode(XCoreISD::LMUL, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), LHS, RHS,
|
|
|
|
Zero, Zero);
|
2010-03-10 13:20:07 +00:00
|
|
|
SDValue Lo(Hi.getNode(), 1);
|
|
|
|
SDValue Ops[] = { Lo, Hi };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
|
|
|
|
2010-03-10 17:10:35 +00:00
|
|
|
/// isADDADDMUL - Return whether Op is in a form that is equivalent to
|
|
|
|
/// add(add(mul(x,y),a),b). If requireIntermediatesHaveOneUse is true then
|
|
|
|
/// each intermediate result in the calculation must also have a single use.
|
|
|
|
/// If the Op is in the correct form the constituent parts are written to Mul0,
|
|
|
|
/// Mul1, Addend0 and Addend1.
|
|
|
|
static bool
|
|
|
|
isADDADDMUL(SDValue Op, SDValue &Mul0, SDValue &Mul1, SDValue &Addend0,
|
|
|
|
SDValue &Addend1, bool requireIntermediatesHaveOneUse)
|
|
|
|
{
|
|
|
|
if (Op.getOpcode() != ISD::ADD)
|
|
|
|
return false;
|
|
|
|
SDValue N0 = Op.getOperand(0);
|
|
|
|
SDValue N1 = Op.getOperand(1);
|
|
|
|
SDValue AddOp;
|
|
|
|
SDValue OtherOp;
|
|
|
|
if (N0.getOpcode() == ISD::ADD) {
|
|
|
|
AddOp = N0;
|
|
|
|
OtherOp = N1;
|
|
|
|
} else if (N1.getOpcode() == ISD::ADD) {
|
|
|
|
AddOp = N1;
|
|
|
|
OtherOp = N0;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2010-03-10 17:16:29 +00:00
|
|
|
if (requireIntermediatesHaveOneUse && !AddOp.hasOneUse())
|
|
|
|
return false;
|
2010-03-10 17:10:35 +00:00
|
|
|
if (OtherOp.getOpcode() == ISD::MUL) {
|
|
|
|
// add(add(a,b),mul(x,y))
|
2010-03-10 17:16:29 +00:00
|
|
|
if (requireIntermediatesHaveOneUse && !OtherOp.hasOneUse())
|
2010-03-10 17:10:35 +00:00
|
|
|
return false;
|
|
|
|
Mul0 = OtherOp.getOperand(0);
|
|
|
|
Mul1 = OtherOp.getOperand(1);
|
|
|
|
Addend0 = AddOp.getOperand(0);
|
|
|
|
Addend1 = AddOp.getOperand(1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (AddOp.getOperand(0).getOpcode() == ISD::MUL) {
|
|
|
|
// add(add(mul(x,y),a),b)
|
|
|
|
if (requireIntermediatesHaveOneUse && !AddOp.getOperand(0).hasOneUse())
|
|
|
|
return false;
|
|
|
|
Mul0 = AddOp.getOperand(0).getOperand(0);
|
|
|
|
Mul1 = AddOp.getOperand(0).getOperand(1);
|
|
|
|
Addend0 = AddOp.getOperand(1);
|
|
|
|
Addend1 = OtherOp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (AddOp.getOperand(1).getOpcode() == ISD::MUL) {
|
|
|
|
// add(add(a,mul(x,y)),b)
|
|
|
|
if (requireIntermediatesHaveOneUse && !AddOp.getOperand(1).hasOneUse())
|
|
|
|
return false;
|
|
|
|
Mul0 = AddOp.getOperand(1).getOperand(0);
|
|
|
|
Mul1 = AddOp.getOperand(1).getOperand(1);
|
|
|
|
Addend0 = AddOp.getOperand(0);
|
|
|
|
Addend1 = OtherOp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-10 11:41:08 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
TryExpandADDWithMul(SDNode *N, SelectionDAG &DAG) const
|
2010-03-10 11:41:08 +00:00
|
|
|
{
|
|
|
|
SDValue Mul;
|
|
|
|
SDValue Other;
|
|
|
|
if (N->getOperand(0).getOpcode() == ISD::MUL) {
|
|
|
|
Mul = N->getOperand(0);
|
|
|
|
Other = N->getOperand(1);
|
|
|
|
} else if (N->getOperand(1).getOpcode() == ISD::MUL) {
|
|
|
|
Mul = N->getOperand(1);
|
|
|
|
Other = N->getOperand(0);
|
|
|
|
} else {
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
DebugLoc dl = N->getDebugLoc();
|
|
|
|
SDValue LL, RL, AddendL, AddendH;
|
|
|
|
LL = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Mul.getOperand(0), DAG.getConstant(0, MVT::i32));
|
|
|
|
RL = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Mul.getOperand(1), DAG.getConstant(0, MVT::i32));
|
|
|
|
AddendL = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Other, DAG.getConstant(0, MVT::i32));
|
|
|
|
AddendH = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Other, DAG.getConstant(1, MVT::i32));
|
|
|
|
APInt HighMask = APInt::getHighBitsSet(64, 32);
|
|
|
|
unsigned LHSSB = DAG.ComputeNumSignBits(Mul.getOperand(0));
|
|
|
|
unsigned RHSSB = DAG.ComputeNumSignBits(Mul.getOperand(1));
|
|
|
|
if (DAG.MaskedValueIsZero(Mul.getOperand(0), HighMask) &&
|
|
|
|
DAG.MaskedValueIsZero(Mul.getOperand(1), HighMask)) {
|
|
|
|
// The inputs are both zero-extended.
|
|
|
|
SDValue Hi = DAG.getNode(XCoreISD::MACCU, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), AddendH,
|
|
|
|
AddendL, LL, RL);
|
|
|
|
SDValue Lo(Hi.getNode(), 1);
|
|
|
|
return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi);
|
|
|
|
}
|
|
|
|
if (LHSSB > 32 && RHSSB > 32) {
|
|
|
|
// The inputs are both sign-extended.
|
|
|
|
SDValue Hi = DAG.getNode(XCoreISD::MACCS, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), AddendH,
|
|
|
|
AddendL, LL, RL);
|
|
|
|
SDValue Lo(Hi.getNode(), 1);
|
|
|
|
return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi);
|
|
|
|
}
|
|
|
|
SDValue LH, RH;
|
|
|
|
LH = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Mul.getOperand(0), DAG.getConstant(1, MVT::i32));
|
|
|
|
RH = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Mul.getOperand(1), DAG.getConstant(1, MVT::i32));
|
|
|
|
SDValue Hi = DAG.getNode(XCoreISD::MACCU, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), AddendH,
|
|
|
|
AddendL, LL, RL);
|
|
|
|
SDValue Lo(Hi.getNode(), 1);
|
|
|
|
RH = DAG.getNode(ISD::MUL, dl, MVT::i32, LL, RH);
|
|
|
|
LH = DAG.getNode(ISD::MUL, dl, MVT::i32, LH, RL);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, MVT::i32, Hi, RH);
|
|
|
|
Hi = DAG.getNode(ISD::ADD, dl, MVT::i32, Hi, LH);
|
|
|
|
return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi);
|
|
|
|
}
|
|
|
|
|
2008-12-01 11:39:25 +00:00
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
ExpandADDSUB(SDNode *N, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2009-08-11 20:47:22 +00:00
|
|
|
assert(N->getValueType(0) == MVT::i64 &&
|
2008-11-07 10:59:00 +00:00
|
|
|
(N->getOpcode() == ISD::ADD || N->getOpcode() == ISD::SUB) &&
|
|
|
|
"Unknown operand to lower!");
|
2010-03-10 11:41:08 +00:00
|
|
|
|
2010-03-10 16:27:11 +00:00
|
|
|
if (N->getOpcode() == ISD::ADD) {
|
|
|
|
SDValue Result = TryExpandADDWithMul(N, DAG);
|
|
|
|
if (Result.getNode() != 0)
|
|
|
|
return Result;
|
|
|
|
}
|
2010-03-10 11:41:08 +00:00
|
|
|
|
2009-02-05 01:01:16 +00:00
|
|
|
DebugLoc dl = N->getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Extract components
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue LHSL = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
N->getOperand(0), DAG.getConstant(0, MVT::i32));
|
|
|
|
SDValue LHSH = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
N->getOperand(0), DAG.getConstant(1, MVT::i32));
|
|
|
|
SDValue RHSL = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
N->getOperand(1), DAG.getConstant(0, MVT::i32));
|
|
|
|
SDValue RHSH = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
N->getOperand(1), DAG.getConstant(1, MVT::i32));
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Expand
|
|
|
|
unsigned Opcode = (N->getOpcode() == ISD::ADD) ? XCoreISD::LADD :
|
|
|
|
XCoreISD::LSUB;
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue Zero = DAG.getConstant(0, MVT::i32);
|
|
|
|
SDValue Carry = DAG.getNode(Opcode, dl, DAG.getVTList(MVT::i32, MVT::i32),
|
2008-11-07 10:59:00 +00:00
|
|
|
LHSL, RHSL, Zero);
|
|
|
|
SDValue Lo(Carry.getNode(), 1);
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue Ignored = DAG.getNode(Opcode, dl, DAG.getVTList(MVT::i32, MVT::i32),
|
2008-11-07 10:59:00 +00:00
|
|
|
LHSH, RHSH, Carry);
|
|
|
|
SDValue Hi(Ignored.getNode(), 1);
|
|
|
|
// Merge the pieces
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerVAARG(SDValue Op, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("unimplemented");
|
2008-11-07 10:59:00 +00:00
|
|
|
// FIX Arguments passed by reference need a extra dereference.
|
|
|
|
SDNode *Node = Op.getNode();
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = Node->getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
const Value *V = cast<SrcValueSDNode>(Node->getOperand(2))->getValue();
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT VT = Node->getValueType(0);
|
2009-02-04 20:06:27 +00:00
|
|
|
SDValue VAList = DAG.getLoad(getPointerTy(), dl, Node->getOperand(0),
|
2010-09-21 06:44:06 +00:00
|
|
|
Node->getOperand(1), MachinePointerInfo(V),
|
|
|
|
false, false, 0);
|
2008-11-07 10:59:00 +00:00
|
|
|
// Increment the pointer, VAList, to the next vararg
|
2009-02-04 20:06:27 +00:00
|
|
|
SDValue Tmp3 = DAG.getNode(ISD::ADD, dl, getPointerTy(), VAList,
|
2008-11-07 10:59:00 +00:00
|
|
|
DAG.getConstant(VT.getSizeInBits(),
|
|
|
|
getPointerTy()));
|
|
|
|
// Store the incremented VAList to the legalized pointer
|
2010-09-21 18:41:36 +00:00
|
|
|
Tmp3 = DAG.getStore(VAList.getValue(1), dl, Tmp3, Node->getOperand(1),
|
|
|
|
MachinePointerInfo(V), false, false, 0);
|
2008-11-07 10:59:00 +00:00
|
|
|
// Load the actual argument out of the pointer VAList
|
2010-09-21 06:44:06 +00:00
|
|
|
return DAG.getLoad(VT, dl, Tmp3, VAList, MachinePointerInfo(),
|
|
|
|
false, false, 0);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::
|
2010-04-17 15:26:15 +00:00
|
|
|
LowerVASTART(SDValue Op, SelectionDAG &DAG) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
2009-02-04 20:06:27 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
// vastart stores the address of the VarArgsFrameIndex slot into the
|
|
|
|
// memory location argument
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue Addr = DAG.getFrameIndex(XFI->getVarArgsFrameIndex(), MVT::i32);
|
2010-09-21 18:41:36 +00:00
|
|
|
return DAG.getStore(Op.getOperand(0), dl, Addr, Op.getOperand(1),
|
|
|
|
MachinePointerInfo(), false, false, 0);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
2010-04-17 15:26:15 +00:00
|
|
|
SDValue XCoreTargetLowering::LowerFRAMEADDR(SDValue Op,
|
|
|
|
SelectionDAG &DAG) const {
|
2009-02-04 23:02:30 +00:00
|
|
|
DebugLoc dl = Op.getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
// Depths > 0 not supported yet!
|
|
|
|
if (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue() > 0)
|
|
|
|
return SDValue();
|
|
|
|
|
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
const TargetRegisterInfo *RegInfo = getTargetMachine().getRegisterInfo();
|
2009-02-04 23:02:30 +00:00
|
|
|
return DAG.getCopyFromReg(DAG.getEntryNode(), dl,
|
2009-08-11 20:47:22 +00:00
|
|
|
RegInfo->getFrameRegister(MF), MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Calling Convention Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "XCoreGenCallingConv.inc"
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
// Call Calling Convention Implementation
|
2008-11-07 10:59:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
/// XCore call implementation
|
|
|
|
SDValue
|
2010-02-02 23:55:14 +00:00
|
|
|
XCoreTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
2010-01-27 00:07:07 +00:00
|
|
|
bool &isTailCall,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
2010-07-07 15:54:55 +00:00
|
|
|
const SmallVectorImpl<SDValue> &OutVals,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
DebugLoc dl, SelectionDAG &DAG,
|
2010-04-17 15:26:15 +00:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const {
|
2010-01-27 00:07:07 +00:00
|
|
|
// XCore target does not yet support tail call optimization.
|
|
|
|
isTailCall = false;
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
// For now, only CallingConv::C implemented
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
switch (CallConv)
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unsupported calling convention");
|
2008-11-07 10:59:00 +00:00
|
|
|
case CallingConv::Fast:
|
|
|
|
case CallingConv::C:
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
return LowerCCCCallTo(Chain, Callee, CallConv, isVarArg, isTailCall,
|
2010-07-07 15:54:55 +00:00
|
|
|
Outs, OutVals, Ins, dl, DAG, InVals);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// LowerCCCCallTo - functions arguments are copied from virtual
|
|
|
|
/// regs to (physical regs)/(stack frame), CALLSEQ_START and
|
|
|
|
/// CALLSEQ_END are emitted.
|
|
|
|
/// TODO: isTailCall, sret.
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
SDValue
|
|
|
|
XCoreTargetLowering::LowerCCCCallTo(SDValue Chain, SDValue Callee,
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
bool isTailCall,
|
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
2010-07-07 15:54:55 +00:00
|
|
|
const SmallVectorImpl<SDValue> &OutVals,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
DebugLoc dl, SelectionDAG &DAG,
|
2010-04-17 15:26:15 +00:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const {
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Analyze operands of the call, assigning locations to each operand.
|
|
|
|
SmallVector<CCValAssign, 16> ArgLocs;
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
|
|
|
|
ArgLocs, *DAG.getContext());
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// The ABI dictates there should be one stack slot available to the callee
|
|
|
|
// on function entry (for saving lr).
|
|
|
|
CCInfo.AllocateStack(4, 4);
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCInfo.AnalyzeCallOperands(Outs, CC_XCore);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Get a count of how many bytes are to be pushed on the stack.
|
|
|
|
unsigned NumBytes = CCInfo.getNextStackOffset();
|
|
|
|
|
|
|
|
Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes,
|
|
|
|
getPointerTy(), true));
|
|
|
|
|
|
|
|
SmallVector<std::pair<unsigned, SDValue>, 4> RegsToPass;
|
|
|
|
SmallVector<SDValue, 12> MemOpChains;
|
|
|
|
|
|
|
|
// Walk the register/memloc assignments, inserting copies/loads.
|
|
|
|
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
|
|
|
|
CCValAssign &VA = ArgLocs[i];
|
2010-07-07 15:54:55 +00:00
|
|
|
SDValue Arg = OutVals[i];
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Promote the value if needed.
|
|
|
|
switch (VA.getLocInfo()) {
|
2009-07-14 16:55:14 +00:00
|
|
|
default: llvm_unreachable("Unknown loc info!");
|
2008-11-07 10:59:00 +00:00
|
|
|
case CCValAssign::Full: break;
|
|
|
|
case CCValAssign::SExt:
|
2009-02-04 23:02:30 +00:00
|
|
|
Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
|
2008-11-07 10:59:00 +00:00
|
|
|
break;
|
|
|
|
case CCValAssign::ZExt:
|
2009-02-04 23:02:30 +00:00
|
|
|
Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
|
2008-11-07 10:59:00 +00:00
|
|
|
break;
|
|
|
|
case CCValAssign::AExt:
|
2009-02-04 23:02:30 +00:00
|
|
|
Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg);
|
2008-11-07 10:59:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arguments that can be passed on register must be kept at
|
|
|
|
// RegsToPass vector
|
|
|
|
if (VA.isRegLoc()) {
|
|
|
|
RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
|
|
|
|
} else {
|
|
|
|
assert(VA.isMemLoc());
|
|
|
|
|
|
|
|
int Offset = VA.getLocMemOffset();
|
|
|
|
|
2009-08-11 20:47:22 +00:00
|
|
|
MemOpChains.push_back(DAG.getNode(XCoreISD::STWSP, dl, MVT::Other,
|
2009-02-04 23:02:30 +00:00
|
|
|
Chain, Arg,
|
2009-08-11 20:47:22 +00:00
|
|
|
DAG.getConstant(Offset/4, MVT::i32)));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Transform all store nodes into one single node because
|
|
|
|
// all store nodes are independent of each other.
|
|
|
|
if (!MemOpChains.empty())
|
2009-08-11 20:47:22 +00:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2008-11-07 10:59:00 +00:00
|
|
|
&MemOpChains[0], MemOpChains.size());
|
|
|
|
|
|
|
|
// Build a sequence of copy-to-reg nodes chained together with token
|
|
|
|
// chain and flag operands which copy the outgoing args into registers.
|
|
|
|
// The InFlag in necessary since all emited instructions must be
|
|
|
|
// stuck together.
|
|
|
|
SDValue InFlag;
|
|
|
|
for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) {
|
2009-02-04 23:02:30 +00:00
|
|
|
Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first,
|
2008-11-07 10:59:00 +00:00
|
|
|
RegsToPass[i].second, InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the callee is a GlobalAddress node (quite common, every direct call is)
|
|
|
|
// turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
|
|
|
|
// Likewise ExternalSymbol -> TargetExternalSymbol.
|
|
|
|
if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
|
2010-07-06 22:08:15 +00:00
|
|
|
Callee = DAG.getTargetGlobalAddress(G->getGlobal(), dl, MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
else if (ExternalSymbolSDNode *E = dyn_cast<ExternalSymbolSDNode>(Callee))
|
2009-08-11 20:47:22 +00:00
|
|
|
Callee = DAG.getTargetExternalSymbol(E->getSymbol(), MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// XCoreBranchLink = #chain, #target_address, #opt_in_flags...
|
|
|
|
// = Chain, Callee, Reg#1, Reg#2, ...
|
|
|
|
//
|
|
|
|
// Returns a chain & a flag for retval copy to use.
|
2009-08-11 20:47:22 +00:00
|
|
|
SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Flag);
|
2008-11-07 10:59:00 +00:00
|
|
|
SmallVector<SDValue, 8> Ops;
|
|
|
|
Ops.push_back(Chain);
|
|
|
|
Ops.push_back(Callee);
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
Ops.push_back(DAG.getRegister(RegsToPass[i].first,
|
|
|
|
RegsToPass[i].second.getValueType()));
|
|
|
|
|
|
|
|
if (InFlag.getNode())
|
|
|
|
Ops.push_back(InFlag);
|
|
|
|
|
2009-02-04 23:02:30 +00:00
|
|
|
Chain = DAG.getNode(XCoreISD::BL, dl, NodeTys, &Ops[0], Ops.size());
|
2008-11-07 10:59:00 +00:00
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
|
|
|
// Create the CALLSEQ_END node.
|
|
|
|
Chain = DAG.getCALLSEQ_END(Chain,
|
|
|
|
DAG.getConstant(NumBytes, getPointerTy(), true),
|
|
|
|
DAG.getConstant(0, getPointerTy(), true),
|
|
|
|
InFlag);
|
|
|
|
InFlag = Chain.getValue(1);
|
|
|
|
|
|
|
|
// Handle result values, copying them out of physregs into vregs that we
|
|
|
|
// return.
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
return LowerCallResult(Chain, InFlag, CallConv, isVarArg,
|
|
|
|
Ins, dl, DAG, InVals);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
/// LowerCallResult - Lower the result values of a call into the
|
|
|
|
/// appropriate copies out of appropriate physical registers.
|
|
|
|
SDValue
|
|
|
|
XCoreTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag,
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
DebugLoc dl, SelectionDAG &DAG,
|
2010-04-17 15:26:15 +00:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const {
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Assign locations to each value returned by this call.
|
|
|
|
SmallVector<CCValAssign, 16> RVLocs;
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
|
2009-07-22 00:24:57 +00:00
|
|
|
RVLocs, *DAG.getContext());
|
2008-11-07 10:59:00 +00:00
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCInfo.AnalyzeCallResult(Ins, RetCC_XCore);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Copy all of the result registers out of their specified physreg.
|
|
|
|
for (unsigned i = 0; i != RVLocs.size(); ++i) {
|
2009-02-04 23:02:30 +00:00
|
|
|
Chain = DAG.getCopyFromReg(Chain, dl, RVLocs[i].getLocReg(),
|
2008-11-07 10:59:00 +00:00
|
|
|
RVLocs[i].getValVT(), InFlag).getValue(1);
|
|
|
|
InFlag = Chain.getValue(2);
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
InVals.push_back(Chain.getValue(0));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
return Chain;
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
// Formal Arguments Calling Convention Implementation
|
2008-11-07 10:59:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
/// XCore formal arguments implementation
|
|
|
|
SDValue
|
|
|
|
XCoreTargetLowering::LowerFormalArguments(SDValue Chain,
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CallConv,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg> &Ins,
|
|
|
|
DebugLoc dl,
|
|
|
|
SelectionDAG &DAG,
|
2010-04-17 15:26:15 +00:00
|
|
|
SmallVectorImpl<SDValue> &InVals)
|
|
|
|
const {
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
switch (CallConv)
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
|
|
|
default:
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable("Unsupported calling convention");
|
2008-11-07 10:59:00 +00:00
|
|
|
case CallingConv::C:
|
|
|
|
case CallingConv::Fast:
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
return LowerCCCArguments(Chain, CallConv, isVarArg,
|
|
|
|
Ins, dl, DAG, InVals);
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// LowerCCCArguments - transform physical registers into
|
|
|
|
/// virtual registers and generate load operations for
|
|
|
|
/// arguments places on the stack.
|
|
|
|
/// TODO: sret
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
SDValue
|
|
|
|
XCoreTargetLowering::LowerCCCArguments(SDValue Chain,
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CallConv,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
bool isVarArg,
|
|
|
|
const SmallVectorImpl<ISD::InputArg>
|
|
|
|
&Ins,
|
|
|
|
DebugLoc dl,
|
|
|
|
SelectionDAG &DAG,
|
2010-04-17 15:26:15 +00:00
|
|
|
SmallVectorImpl<SDValue> &InVals) const {
|
2008-11-07 10:59:00 +00:00
|
|
|
MachineFunction &MF = DAG.getMachineFunction();
|
|
|
|
MachineFrameInfo *MFI = MF.getFrameInfo();
|
|
|
|
MachineRegisterInfo &RegInfo = MF.getRegInfo();
|
|
|
|
|
|
|
|
// Assign locations to all of the incoming arguments.
|
|
|
|
SmallVector<CCValAssign, 16> ArgLocs;
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
|
|
|
|
ArgLocs, *DAG.getContext());
|
2008-11-07 10:59:00 +00:00
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCInfo.AnalyzeFormalArguments(Ins, CC_XCore);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
unsigned StackSlotSize = XCoreFrameInfo::stackSlotSize();
|
|
|
|
|
|
|
|
unsigned LRSaveSize = StackSlotSize;
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
|
|
|
|
|
|
|
|
CCValAssign &VA = ArgLocs[i];
|
|
|
|
|
|
|
|
if (VA.isRegLoc()) {
|
|
|
|
// Arguments passed in registers
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT RegVT = VA.getLocVT();
|
2009-08-11 20:47:22 +00:00
|
|
|
switch (RegVT.getSimpleVT().SimpleTy) {
|
2008-11-07 10:59:00 +00:00
|
|
|
default:
|
2009-07-08 19:04:27 +00:00
|
|
|
{
|
2009-07-08 20:53:28 +00:00
|
|
|
#ifndef NDEBUG
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
errs() << "LowerFormalArguments Unhandled argument type: "
|
2009-08-11 20:47:22 +00:00
|
|
|
<< RegVT.getSimpleVT().SimpleTy << "\n";
|
2009-07-08 20:53:28 +00:00
|
|
|
#endif
|
2009-07-14 16:55:14 +00:00
|
|
|
llvm_unreachable(0);
|
2009-07-08 19:04:27 +00:00
|
|
|
}
|
2009-08-11 20:47:22 +00:00
|
|
|
case MVT::i32:
|
2008-11-07 10:59:00 +00:00
|
|
|
unsigned VReg = RegInfo.createVirtualRegister(
|
|
|
|
XCore::GRRegsRegisterClass);
|
|
|
|
RegInfo.addLiveIn(VA.getLocReg(), VReg);
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
InVals.push_back(DAG.getCopyFromReg(Chain, dl, VReg, RegVT));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// sanity check
|
|
|
|
assert(VA.isMemLoc());
|
|
|
|
// Load the argument to a virtual register
|
|
|
|
unsigned ObjSize = VA.getLocVT().getSizeInBits()/8;
|
|
|
|
if (ObjSize > StackSlotSize) {
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
errs() << "LowerFormalArguments Unhandled argument type: "
|
2009-08-11 20:47:22 +00:00
|
|
|
<< (unsigned)VA.getLocVT().getSimpleVT().SimpleTy
|
2009-07-25 00:23:56 +00:00
|
|
|
<< "\n";
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
// Create the frame index object for this incoming parameter...
|
|
|
|
int FI = MFI->CreateFixedObject(ObjSize,
|
2009-11-12 20:49:22 +00:00
|
|
|
LRSaveSize + VA.getLocMemOffset(),
|
2010-07-03 00:40:23 +00:00
|
|
|
true);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// Create the SelectionDAG nodes corresponding to a load
|
|
|
|
//from this parameter
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue FIN = DAG.getFrameIndex(FI, MVT::i32);
|
2010-09-21 06:44:06 +00:00
|
|
|
InVals.push_back(DAG.getLoad(VA.getLocVT(), dl, Chain, FIN,
|
|
|
|
MachinePointerInfo::getFixedStack(FI),
|
2010-02-15 16:49:52 +00:00
|
|
|
false, false, 0));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVarArg) {
|
|
|
|
/* Argument registers */
|
|
|
|
static const unsigned ArgRegs[] = {
|
|
|
|
XCore::R0, XCore::R1, XCore::R2, XCore::R3
|
|
|
|
};
|
|
|
|
XCoreFunctionInfo *XFI = MF.getInfo<XCoreFunctionInfo>();
|
|
|
|
unsigned FirstVAReg = CCInfo.getFirstUnallocated(ArgRegs,
|
|
|
|
array_lengthof(ArgRegs));
|
|
|
|
if (FirstVAReg < array_lengthof(ArgRegs)) {
|
|
|
|
SmallVector<SDValue, 4> MemOps;
|
|
|
|
int offset = 0;
|
|
|
|
// Save remaining registers, storing higher register numbers at a higher
|
|
|
|
// address
|
|
|
|
for (unsigned i = array_lengthof(ArgRegs) - 1; i >= FirstVAReg; --i) {
|
|
|
|
// Create a stack slot
|
2010-07-03 00:40:23 +00:00
|
|
|
int FI = MFI->CreateFixedObject(4, offset, true);
|
2008-11-07 10:59:00 +00:00
|
|
|
if (i == FirstVAReg) {
|
|
|
|
XFI->setVarArgsFrameIndex(FI);
|
|
|
|
}
|
|
|
|
offset -= StackSlotSize;
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue FIN = DAG.getFrameIndex(FI, MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
// Move argument from phys reg -> virt reg
|
|
|
|
unsigned VReg = RegInfo.createVirtualRegister(
|
|
|
|
XCore::GRRegsRegisterClass);
|
|
|
|
RegInfo.addLiveIn(ArgRegs[i], VReg);
|
2009-08-11 20:47:22 +00:00
|
|
|
SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32);
|
2008-11-07 10:59:00 +00:00
|
|
|
// Move argument from virt reg -> stack
|
2010-09-21 18:41:36 +00:00
|
|
|
SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, FIN,
|
|
|
|
MachinePointerInfo(), false, false, 0);
|
2008-11-07 10:59:00 +00:00
|
|
|
MemOps.push_back(Store);
|
|
|
|
}
|
|
|
|
if (!MemOps.empty())
|
2009-08-11 20:47:22 +00:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
&MemOps[0], MemOps.size());
|
2008-11-07 10:59:00 +00:00
|
|
|
} else {
|
|
|
|
// This will point to the next argument passed via stack.
|
|
|
|
XFI->setVarArgsFrameIndex(
|
2009-11-12 20:49:22 +00:00
|
|
|
MFI->CreateFixedObject(4, LRSaveSize + CCInfo.getNextStackOffset(),
|
2010-07-03 00:40:23 +00:00
|
|
|
true));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
return Chain;
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Return Value Calling Convention Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-11-14 19:33:35 +00:00
|
|
|
bool XCoreTargetLowering::
|
|
|
|
CanLowerReturn(CallingConv::ID CallConv, bool isVarArg,
|
2010-07-10 09:00:22 +00:00
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
2010-07-06 22:19:37 +00:00
|
|
|
LLVMContext &Context) const {
|
2009-11-14 19:33:35 +00:00
|
|
|
SmallVector<CCValAssign, 16> RVLocs;
|
|
|
|
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
|
2010-07-06 22:19:37 +00:00
|
|
|
RVLocs, Context);
|
2010-07-10 09:00:22 +00:00
|
|
|
return CCInfo.CheckReturn(Outs, RetCC_XCore);
|
2009-11-14 19:33:35 +00:00
|
|
|
}
|
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
SDValue
|
|
|
|
XCoreTargetLowering::LowerReturn(SDValue Chain,
|
2009-09-02 08:44:58 +00:00
|
|
|
CallingConv::ID CallConv, bool isVarArg,
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
const SmallVectorImpl<ISD::OutputArg> &Outs,
|
2010-07-07 15:54:55 +00:00
|
|
|
const SmallVectorImpl<SDValue> &OutVals,
|
2010-04-17 15:26:15 +00:00
|
|
|
DebugLoc dl, SelectionDAG &DAG) const {
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
// CCValAssign - represent the assignment of
|
|
|
|
// the return value to a location
|
|
|
|
SmallVector<CCValAssign, 16> RVLocs;
|
|
|
|
|
|
|
|
// CCState - Info about the registers and stack slot.
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
CCState CCInfo(CallConv, isVarArg, getTargetMachine(),
|
|
|
|
RVLocs, *DAG.getContext());
|
2008-11-07 10:59:00 +00:00
|
|
|
|
Major calling convention code refactoring.
Instead of awkwardly encoding calling-convention information with ISD::CALL,
ISD::FORMAL_ARGUMENTS, ISD::RET, and ISD::ARG_FLAGS nodes, TargetLowering
provides three virtual functions for targets to override:
LowerFormalArguments, LowerCall, and LowerRet, which replace the custom
lowering done on the special nodes. They provide the same information, but
in a more immediately usable format.
This also reworks much of the target-independent tail call logic. The
decision of whether or not to perform a tail call is now cleanly split
between target-independent portions, and the target dependent portion
in IsEligibleForTailCallOptimization.
This also synchronizes all in-tree targets, to help enable future
refactoring and feature work.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78142 91177308-0d34-0410-b5e6-96231b3b80d8
2009-08-05 01:29:28 +00:00
|
|
|
// Analize return values.
|
|
|
|
CCInfo.AnalyzeReturn(Outs, RetCC_XCore);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// If this is the first return lowered for this function, add
|
|
|
|
// the regs to the liveout set for the function.
|
|
|
|
if (DAG.getMachineFunction().getRegInfo().liveout_empty()) {
|
|
|
|
for (unsigned i = 0; i != RVLocs.size(); ++i)
|
|
|
|
if (RVLocs[i].isRegLoc())
|
|
|
|
DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg());
|
|
|
|
}
|
|
|
|
|
|
|
|
SDValue Flag;
|
|
|
|
|
|
|
|
// 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(),
|
2010-07-07 15:54:55 +00:00
|
|
|
OutVals[i], Flag);
|
2008-11-07 10:59:00 +00:00
|
|
|
|
|
|
|
// guarantee that all emitted copies are
|
|
|
|
// stuck together, avoiding something bad
|
|
|
|
Flag = Chain.getValue(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return on XCore is always a "retsp 0"
|
|
|
|
if (Flag.getNode())
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(XCoreISD::RETSP, dl, MVT::Other,
|
|
|
|
Chain, DAG.getConstant(0, MVT::i32), Flag);
|
2008-11-07 10:59:00 +00:00
|
|
|
else // Return Void
|
2009-08-11 20:47:22 +00:00
|
|
|
return DAG.getNode(XCoreISD::RETSP, dl, MVT::Other,
|
|
|
|
Chain, DAG.getConstant(0, MVT::i32));
|
2008-11-07 10:59:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Other Lowering Code
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
MachineBasicBlock *
|
|
|
|
XCoreTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI,
|
2010-05-01 00:01:06 +00:00
|
|
|
MachineBasicBlock *BB) const {
|
2008-11-07 10:59:00 +00:00
|
|
|
const TargetInstrInfo &TII = *getTargetMachine().getInstrInfo();
|
2009-02-13 02:32:04 +00:00
|
|
|
DebugLoc dl = MI->getDebugLoc();
|
2008-11-07 10:59:00 +00:00
|
|
|
assert((MI->getOpcode() == XCore::SELECT_CC) &&
|
|
|
|
"Unexpected instr type to insert");
|
|
|
|
|
|
|
|
// To "insert" a SELECT_CC instruction, we actually have to insert the diamond
|
|
|
|
// control-flow pattern. The incoming instruction knows the destination vreg
|
|
|
|
// to set, the condition code register to branch on, the true/false values to
|
|
|
|
// select between, and a branch opcode to use.
|
|
|
|
const BasicBlock *LLVM_BB = BB->getBasicBlock();
|
|
|
|
MachineFunction::iterator It = BB;
|
|
|
|
++It;
|
|
|
|
|
|
|
|
// thisMBB:
|
|
|
|
// ...
|
|
|
|
// TrueVal = ...
|
|
|
|
// cmpTY ccX, r1, r2
|
|
|
|
// bCC copy1MBB
|
|
|
|
// fallthrough --> copy0MBB
|
|
|
|
MachineBasicBlock *thisMBB = BB;
|
|
|
|
MachineFunction *F = BB->getParent();
|
|
|
|
MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB);
|
|
|
|
MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB);
|
|
|
|
F->insert(It, copy0MBB);
|
|
|
|
F->insert(It, sinkMBB);
|
2010-07-06 20:24:04 +00:00
|
|
|
|
|
|
|
// Transfer the remainder of BB and its successor edges to sinkMBB.
|
|
|
|
sinkMBB->splice(sinkMBB->begin(), BB,
|
|
|
|
llvm::next(MachineBasicBlock::iterator(MI)),
|
|
|
|
BB->end());
|
|
|
|
sinkMBB->transferSuccessorsAndUpdatePHIs(BB);
|
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
// Next, add the true and fallthrough blocks as its successors.
|
|
|
|
BB->addSuccessor(copy0MBB);
|
|
|
|
BB->addSuccessor(sinkMBB);
|
|
|
|
|
2010-07-06 20:24:04 +00:00
|
|
|
BuildMI(BB, dl, TII.get(XCore::BRFT_lru6))
|
|
|
|
.addReg(MI->getOperand(1).getReg()).addMBB(sinkMBB);
|
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
// copy0MBB:
|
|
|
|
// %FalseValue = ...
|
|
|
|
// # fallthrough to sinkMBB
|
|
|
|
BB = copy0MBB;
|
|
|
|
|
|
|
|
// Update machine-CFG edges
|
|
|
|
BB->addSuccessor(sinkMBB);
|
|
|
|
|
|
|
|
// sinkMBB:
|
|
|
|
// %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
|
|
|
|
// ...
|
|
|
|
BB = sinkMBB;
|
2010-07-06 20:24:04 +00:00
|
|
|
BuildMI(*BB, BB->begin(), dl,
|
|
|
|
TII.get(XCore::PHI), MI->getOperand(0).getReg())
|
2008-11-07 10:59:00 +00:00
|
|
|
.addReg(MI->getOperand(3).getReg()).addMBB(copy0MBB)
|
|
|
|
.addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
|
|
|
|
|
2010-07-06 20:24:04 +00:00
|
|
|
MI->eraseFromParent(); // The pseudo instruction is gone now.
|
2008-11-07 10:59:00 +00:00
|
|
|
return BB;
|
|
|
|
}
|
|
|
|
|
2009-07-16 12:50:48 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Target Optimization Hooks
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
SDValue XCoreTargetLowering::PerformDAGCombine(SDNode *N,
|
|
|
|
DAGCombinerInfo &DCI) const {
|
|
|
|
SelectionDAG &DAG = DCI.DAG;
|
|
|
|
DebugLoc dl = N->getDebugLoc();
|
|
|
|
switch (N->getOpcode()) {
|
|
|
|
default: break;
|
2010-03-09 16:07:47 +00:00
|
|
|
case XCoreISD::LADD: {
|
|
|
|
SDValue N0 = N->getOperand(0);
|
|
|
|
SDValue N1 = N->getOperand(1);
|
|
|
|
SDValue N2 = N->getOperand(2);
|
|
|
|
ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
|
|
|
|
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
|
|
|
|
EVT VT = N0.getValueType();
|
|
|
|
|
2010-03-09 16:13:57 +00:00
|
|
|
// canonicalize constant to RHS
|
|
|
|
if (N0C && !N1C)
|
|
|
|
return DAG.getNode(XCoreISD::LADD, dl, DAG.getVTList(VT, VT), N1, N0, N2);
|
|
|
|
|
2010-03-09 16:07:47 +00:00
|
|
|
// fold (ladd 0, 0, x) -> 0, x & 1
|
|
|
|
if (N0C && N0C->isNullValue() && N1C && N1C->isNullValue()) {
|
|
|
|
SDValue Carry = DAG.getConstant(0, VT);
|
|
|
|
SDValue Result = DAG.getNode(ISD::AND, dl, VT, N2,
|
|
|
|
DAG.getConstant(1, VT));
|
|
|
|
SDValue Ops [] = { Carry, Result };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
2010-03-09 16:34:25 +00:00
|
|
|
|
|
|
|
// fold (ladd x, 0, y) -> 0, add x, y iff carry is unused and y has only the
|
|
|
|
// low bit set
|
|
|
|
if (N1C && N1C->isNullValue() && N->hasNUsesOfValue(0, 0)) {
|
|
|
|
APInt KnownZero, KnownOne;
|
|
|
|
APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(),
|
|
|
|
VT.getSizeInBits() - 1);
|
|
|
|
DAG.ComputeMaskedBits(N2, Mask, KnownZero, KnownOne);
|
|
|
|
if (KnownZero == Mask) {
|
|
|
|
SDValue Carry = DAG.getConstant(0, VT);
|
|
|
|
SDValue Result = DAG.getNode(ISD::ADD, dl, VT, N0, N2);
|
|
|
|
SDValue Ops [] = { Carry, Result };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
|
|
|
}
|
2010-03-09 16:07:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XCoreISD::LSUB: {
|
|
|
|
SDValue N0 = N->getOperand(0);
|
|
|
|
SDValue N1 = N->getOperand(1);
|
|
|
|
SDValue N2 = N->getOperand(2);
|
|
|
|
ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
|
|
|
|
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
|
|
|
|
EVT VT = N0.getValueType();
|
|
|
|
|
|
|
|
// fold (lsub 0, 0, x) -> x, -x iff x has only the low bit set
|
|
|
|
if (N0C && N0C->isNullValue() && N1C && N1C->isNullValue()) {
|
|
|
|
APInt KnownZero, KnownOne;
|
|
|
|
APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(),
|
|
|
|
VT.getSizeInBits() - 1);
|
|
|
|
DAG.ComputeMaskedBits(N2, Mask, KnownZero, KnownOne);
|
|
|
|
if (KnownZero == Mask) {
|
|
|
|
SDValue Borrow = N2;
|
|
|
|
SDValue Result = DAG.getNode(ISD::SUB, dl, VT,
|
|
|
|
DAG.getConstant(0, VT), N2);
|
|
|
|
SDValue Ops [] = { Borrow, Result };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
|
|
|
}
|
2010-03-09 16:34:25 +00:00
|
|
|
|
|
|
|
// fold (lsub x, 0, y) -> 0, sub x, y iff borrow is unused and y has only the
|
|
|
|
// low bit set
|
|
|
|
if (N1C && N1C->isNullValue() && N->hasNUsesOfValue(0, 0)) {
|
|
|
|
APInt KnownZero, KnownOne;
|
|
|
|
APInt Mask = APInt::getHighBitsSet(VT.getSizeInBits(),
|
|
|
|
VT.getSizeInBits() - 1);
|
|
|
|
DAG.ComputeMaskedBits(N2, Mask, KnownZero, KnownOne);
|
|
|
|
if (KnownZero == Mask) {
|
|
|
|
SDValue Borrow = DAG.getConstant(0, VT);
|
|
|
|
SDValue Result = DAG.getNode(ISD::SUB, dl, VT, N0, N2);
|
|
|
|
SDValue Ops [] = { Borrow, Result };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
|
|
|
}
|
2010-03-09 16:07:47 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-03-11 16:26:35 +00:00
|
|
|
case XCoreISD::LMUL: {
|
|
|
|
SDValue N0 = N->getOperand(0);
|
|
|
|
SDValue N1 = N->getOperand(1);
|
|
|
|
SDValue N2 = N->getOperand(2);
|
|
|
|
SDValue N3 = N->getOperand(3);
|
|
|
|
ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0);
|
|
|
|
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
|
|
|
|
EVT VT = N0.getValueType();
|
|
|
|
// Canonicalize multiplicative constant to RHS. If both multiplicative
|
|
|
|
// operands are constant canonicalize smallest to RHS.
|
|
|
|
if ((N0C && !N1C) ||
|
|
|
|
(N0C && N1C && N0C->getZExtValue() < N1C->getZExtValue()))
|
|
|
|
return DAG.getNode(XCoreISD::LMUL, dl, DAG.getVTList(VT, VT), N1, N0, N2, N3);
|
|
|
|
|
|
|
|
// lmul(x, 0, a, b)
|
|
|
|
if (N1C && N1C->isNullValue()) {
|
|
|
|
// If the high result is unused fold to add(a, b)
|
|
|
|
if (N->hasNUsesOfValue(0, 0)) {
|
|
|
|
SDValue Lo = DAG.getNode(ISD::ADD, dl, VT, N2, N3);
|
|
|
|
SDValue Ops [] = { Lo, Lo };
|
|
|
|
return DAG.getMergeValues(Ops, 2, dl);
|
|
|
|
}
|
|
|
|
// Otherwise fold to ladd(a, b, 0)
|
|
|
|
return DAG.getNode(XCoreISD::LADD, dl, DAG.getVTList(VT, VT), N2, N3, N1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2010-03-10 16:19:31 +00:00
|
|
|
case ISD::ADD: {
|
2010-03-10 18:12:27 +00:00
|
|
|
// Fold 32 bit expressions such as add(add(mul(x,y),a),b) ->
|
|
|
|
// lmul(x, y, a, b). The high result of lmul will be ignored.
|
2010-03-10 16:19:31 +00:00
|
|
|
// This is only profitable if the intermediate results are unused
|
|
|
|
// elsewhere.
|
2010-03-10 17:10:35 +00:00
|
|
|
SDValue Mul0, Mul1, Addend0, Addend1;
|
2010-03-10 18:12:27 +00:00
|
|
|
if (N->getValueType(0) == MVT::i32 &&
|
|
|
|
isADDADDMUL(SDValue(N, 0), Mul0, Mul1, Addend0, Addend1, true)) {
|
2010-03-10 17:10:35 +00:00
|
|
|
SDValue Ignored = DAG.getNode(XCoreISD::LMUL, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), Mul0,
|
|
|
|
Mul1, Addend0, Addend1);
|
|
|
|
SDValue Result(Ignored.getNode(), 1);
|
|
|
|
return Result;
|
2010-03-10 16:19:31 +00:00
|
|
|
}
|
2010-03-10 18:12:27 +00:00
|
|
|
APInt HighMask = APInt::getHighBitsSet(64, 32);
|
|
|
|
// Fold 64 bit expression such as add(add(mul(x,y),a),b) ->
|
|
|
|
// lmul(x, y, a, b) if all operands are zero-extended. We do this
|
|
|
|
// before type legalization as it is messy to match the operands after
|
|
|
|
// that.
|
|
|
|
if (N->getValueType(0) == MVT::i64 &&
|
|
|
|
isADDADDMUL(SDValue(N, 0), Mul0, Mul1, Addend0, Addend1, false) &&
|
|
|
|
DAG.MaskedValueIsZero(Mul0, HighMask) &&
|
|
|
|
DAG.MaskedValueIsZero(Mul1, HighMask) &&
|
|
|
|
DAG.MaskedValueIsZero(Addend0, HighMask) &&
|
|
|
|
DAG.MaskedValueIsZero(Addend1, HighMask)) {
|
|
|
|
SDValue Mul0L = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Mul0, DAG.getConstant(0, MVT::i32));
|
|
|
|
SDValue Mul1L = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Mul1, DAG.getConstant(0, MVT::i32));
|
|
|
|
SDValue Addend0L = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Addend0, DAG.getConstant(0, MVT::i32));
|
|
|
|
SDValue Addend1L = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32,
|
|
|
|
Addend1, DAG.getConstant(0, MVT::i32));
|
|
|
|
SDValue Hi = DAG.getNode(XCoreISD::LMUL, dl,
|
|
|
|
DAG.getVTList(MVT::i32, MVT::i32), Mul0L, Mul1L,
|
|
|
|
Addend0L, Addend1L);
|
|
|
|
SDValue Lo(Hi.getNode(), 1);
|
|
|
|
return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi);
|
|
|
|
}
|
2010-03-10 16:19:31 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-07-16 12:50:48 +00:00
|
|
|
case ISD::STORE: {
|
|
|
|
// Replace unaligned store of unaligned load with memmove.
|
|
|
|
StoreSDNode *ST = cast<StoreSDNode>(N);
|
2009-08-15 21:21:19 +00:00
|
|
|
if (!DCI.isBeforeLegalize() ||
|
|
|
|
allowsUnalignedMemoryAccesses(ST->getMemoryVT()) ||
|
2009-07-16 12:50:48 +00:00
|
|
|
ST->isVolatile() || ST->isIndexed()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SDValue Chain = ST->getChain();
|
|
|
|
|
|
|
|
unsigned StoreBits = ST->getMemoryVT().getStoreSizeInBits();
|
|
|
|
if (StoreBits % 8) {
|
|
|
|
break;
|
|
|
|
}
|
2009-08-12 00:36:31 +00:00
|
|
|
unsigned ABIAlignment = getTargetData()->getABITypeAlignment(
|
|
|
|
ST->getMemoryVT().getTypeForEVT(*DCI.DAG.getContext()));
|
2009-07-16 12:50:48 +00:00
|
|
|
unsigned Alignment = ST->getAlignment();
|
|
|
|
if (Alignment >= ABIAlignment) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LoadSDNode *LD = dyn_cast<LoadSDNode>(ST->getValue())) {
|
|
|
|
if (LD->hasNUsesOfValue(1, 0) && ST->getMemoryVT() == LD->getMemoryVT() &&
|
|
|
|
LD->getAlignment() == Alignment &&
|
|
|
|
!LD->isVolatile() && !LD->isIndexed() &&
|
|
|
|
Chain.reachesChainWithoutSideEffects(SDValue(LD, 1))) {
|
|
|
|
return DAG.getMemmove(Chain, dl, ST->getBasePtr(),
|
|
|
|
LD->getBasePtr(),
|
2009-08-11 20:47:22 +00:00
|
|
|
DAG.getConstant(StoreBits/8, MVT::i32),
|
2010-09-21 05:40:29 +00:00
|
|
|
Alignment, false, ST->getPointerInfo(),
|
|
|
|
LD->getPointerInfo());
|
2009-07-16 12:50:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
|
2010-03-09 16:07:47 +00:00
|
|
|
void XCoreTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op,
|
|
|
|
const APInt &Mask,
|
|
|
|
APInt &KnownZero,
|
|
|
|
APInt &KnownOne,
|
|
|
|
const SelectionDAG &DAG,
|
|
|
|
unsigned Depth) const {
|
|
|
|
KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0);
|
|
|
|
switch (Op.getOpcode()) {
|
|
|
|
default: break;
|
|
|
|
case XCoreISD::LADD:
|
|
|
|
case XCoreISD::LSUB:
|
|
|
|
if (Op.getResNo() == 0) {
|
|
|
|
// Top bits of carry / borrow are clear.
|
|
|
|
KnownZero = APInt::getHighBitsSet(Mask.getBitWidth(),
|
|
|
|
Mask.getBitWidth() - 1);
|
|
|
|
KnownZero &= Mask;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-07 10:59:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Addressing mode description hooks
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static inline bool isImmUs(int64_t val)
|
|
|
|
{
|
|
|
|
return (val >= 0 && val <= 11);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isImmUs2(int64_t val)
|
|
|
|
{
|
|
|
|
return (val%2 == 0 && isImmUs(val/2));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isImmUs4(int64_t val)
|
|
|
|
{
|
|
|
|
return (val%4 == 0 && isImmUs(val/4));
|
|
|
|
}
|
|
|
|
|
|
|
|
/// isLegalAddressingMode - Return true if the addressing mode represented
|
|
|
|
/// by AM is legal for this target, for a load/store of the specified type.
|
|
|
|
bool
|
|
|
|
XCoreTargetLowering::isLegalAddressingMode(const AddrMode &AM,
|
|
|
|
const Type *Ty) const {
|
2009-07-17 07:16:38 +00:00
|
|
|
if (Ty->getTypeID() == Type::VoidTyID)
|
2010-02-26 16:44:51 +00:00
|
|
|
return AM.Scale == 0 && isImmUs(AM.BaseOffs) && isImmUs4(AM.BaseOffs);
|
2009-07-17 07:16:38 +00:00
|
|
|
|
2009-07-15 15:46:56 +00:00
|
|
|
const TargetData *TD = TM.getTargetData();
|
|
|
|
unsigned Size = TD->getTypeAllocSize(Ty);
|
2008-11-07 10:59:00 +00:00
|
|
|
if (AM.BaseGV) {
|
2009-07-15 15:46:56 +00:00
|
|
|
return Size >= 4 && !AM.HasBaseReg && AM.Scale == 0 &&
|
2008-11-07 10:59:00 +00:00
|
|
|
AM.BaseOffs%4 == 0;
|
|
|
|
}
|
|
|
|
|
2009-07-15 15:46:56 +00:00
|
|
|
switch (Size) {
|
|
|
|
case 1:
|
2008-11-07 10:59:00 +00:00
|
|
|
// reg + imm
|
|
|
|
if (AM.Scale == 0) {
|
|
|
|
return isImmUs(AM.BaseOffs);
|
|
|
|
}
|
2009-07-15 15:46:56 +00:00
|
|
|
// reg + reg
|
2008-11-07 10:59:00 +00:00
|
|
|
return AM.Scale == 1 && AM.BaseOffs == 0;
|
2009-07-15 15:46:56 +00:00
|
|
|
case 2:
|
|
|
|
case 3:
|
2008-11-07 10:59:00 +00:00
|
|
|
// reg + imm
|
|
|
|
if (AM.Scale == 0) {
|
|
|
|
return isImmUs2(AM.BaseOffs);
|
|
|
|
}
|
2009-07-15 15:46:56 +00:00
|
|
|
// reg + reg<<1
|
2008-11-07 10:59:00 +00:00
|
|
|
return AM.Scale == 2 && AM.BaseOffs == 0;
|
2009-07-15 15:46:56 +00:00
|
|
|
default:
|
2008-11-07 10:59:00 +00:00
|
|
|
// reg + imm
|
|
|
|
if (AM.Scale == 0) {
|
|
|
|
return isImmUs4(AM.BaseOffs);
|
|
|
|
}
|
|
|
|
// reg + reg<<2
|
|
|
|
return AM.Scale == 4 && AM.BaseOffs == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// XCore Inline Assembly Support
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
std::vector<unsigned> XCoreTargetLowering::
|
|
|
|
getRegClassForInlineAsmConstraint(const std::string &Constraint,
|
2009-08-10 22:56:29 +00:00
|
|
|
EVT VT) const
|
2008-11-07 10:59:00 +00:00
|
|
|
{
|
|
|
|
if (Constraint.size() != 1)
|
|
|
|
return std::vector<unsigned>();
|
|
|
|
|
|
|
|
switch (Constraint[0]) {
|
|
|
|
default : break;
|
|
|
|
case 'r':
|
|
|
|
return make_vector<unsigned>(XCore::R0, XCore::R1, XCore::R2,
|
|
|
|
XCore::R3, XCore::R4, XCore::R5,
|
|
|
|
XCore::R6, XCore::R7, XCore::R8,
|
|
|
|
XCore::R9, XCore::R10, XCore::R11, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return std::vector<unsigned>();
|
|
|
|
}
|