2010-04-16 23:04:22 +00:00
|
|
|
//===-- ARMSelectionDAGInfo.cpp - ARM SelectionDAG Info -------------------===//
|
|
|
|
//
|
|
|
|
// 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 ARMSelectionDAGInfo class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2010-05-11 17:31:57 +00:00
|
|
|
#include "ARMTargetMachine.h"
|
2011-05-22 21:41:23 +00:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2010-04-16 23:04:22 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 02:41:26 +00:00
|
|
|
#define DEBUG_TYPE "arm-selectiondag-info"
|
|
|
|
|
2014-06-12 23:39:49 +00:00
|
|
|
ARMSelectionDAGInfo::ARMSelectionDAGInfo(const DataLayout &DL)
|
|
|
|
: TargetSelectionDAGInfo(&DL) {}
|
2010-04-16 23:04:22 +00:00
|
|
|
|
|
|
|
ARMSelectionDAGInfo::~ARMSelectionDAGInfo() {
|
|
|
|
}
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
SDValue
|
2013-05-25 02:42:55 +00:00
|
|
|
ARMSelectionDAGInfo::EmitTargetCodeForMemcpy(SelectionDAG &DAG, SDLoc dl,
|
2010-05-11 17:31:57 +00:00
|
|
|
SDValue Chain,
|
|
|
|
SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align,
|
|
|
|
bool isVolatile, bool AlwaysInline,
|
2010-09-21 05:40:29 +00:00
|
|
|
MachinePointerInfo DstPtrInfo,
|
|
|
|
MachinePointerInfo SrcPtrInfo) const {
|
2015-02-20 08:24:37 +00:00
|
|
|
const ARMSubtarget &Subtarget =
|
|
|
|
DAG.getMachineFunction().getSubtarget<ARMSubtarget>();
|
2010-05-11 17:31:57 +00:00
|
|
|
// Do repeated 4-byte loads and stores. To be improved.
|
|
|
|
// This requires 4-byte alignment.
|
|
|
|
if ((Align & 3) != 0)
|
|
|
|
return SDValue();
|
2011-04-15 05:18:47 +00:00
|
|
|
// This requires the copy size to be a constant, preferably
|
2010-05-11 17:31:57 +00:00
|
|
|
// within a subtarget-specific limit.
|
|
|
|
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
|
|
|
if (!ConstantSize)
|
|
|
|
return SDValue();
|
|
|
|
uint64_t SizeVal = ConstantSize->getZExtValue();
|
2014-06-12 23:39:49 +00:00
|
|
|
if (!AlwaysInline && SizeVal > Subtarget.getMaxInlineSizeThreshold())
|
2010-05-11 17:31:57 +00:00
|
|
|
return SDValue();
|
|
|
|
|
|
|
|
unsigned BytesLeft = SizeVal & 3;
|
|
|
|
unsigned NumMemOps = SizeVal >> 2;
|
|
|
|
unsigned EmittedNumMemOps = 0;
|
|
|
|
EVT VT = MVT::i32;
|
|
|
|
unsigned VTSize = 4;
|
|
|
|
unsigned i = 0;
|
2014-05-16 14:24:22 +00:00
|
|
|
// Emit a maximum of 4 loads in Thumb1 since we have fewer registers
|
2014-06-12 23:39:49 +00:00
|
|
|
const unsigned MAX_LOADS_IN_LDM = Subtarget.isThumb1Only() ? 4 : 6;
|
2014-05-16 14:24:22 +00:00
|
|
|
SDValue TFOps[6];
|
|
|
|
SDValue Loads[6];
|
2010-05-11 17:31:57 +00:00
|
|
|
uint64_t SrcOff = 0, DstOff = 0;
|
|
|
|
|
|
|
|
// Emit up to MAX_LOADS_IN_LDM loads, then a TokenFactor barrier, then the
|
|
|
|
// same number of stores. The loads and stores will get combined into
|
|
|
|
// ldm/stm later on.
|
|
|
|
while (EmittedNumMemOps < NumMemOps) {
|
|
|
|
for (i = 0;
|
|
|
|
i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) {
|
|
|
|
Loads[i] = DAG.getLoad(VT, dl, Chain,
|
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32, Src,
|
|
|
|
DAG.getConstant(SrcOff, MVT::i32)),
|
2010-09-21 05:40:29 +00:00
|
|
|
SrcPtrInfo.getWithOffset(SrcOff), isVolatile,
|
2011-11-08 18:42:53 +00:00
|
|
|
false, false, 0);
|
2010-05-11 17:31:57 +00:00
|
|
|
TFOps[i] = Loads[i].getValue(1);
|
|
|
|
SrcOff += VTSize;
|
|
|
|
}
|
2014-04-26 18:35:24 +00:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2014-04-30 07:17:30 +00:00
|
|
|
makeArrayRef(TFOps, i));
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
for (i = 0;
|
|
|
|
i < MAX_LOADS_IN_LDM && EmittedNumMemOps + i < NumMemOps; ++i) {
|
|
|
|
TFOps[i] = DAG.getStore(Chain, dl, Loads[i],
|
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32, Dst,
|
|
|
|
DAG.getConstant(DstOff, MVT::i32)),
|
2010-09-21 05:40:29 +00:00
|
|
|
DstPtrInfo.getWithOffset(DstOff),
|
|
|
|
isVolatile, false, 0);
|
2010-05-11 17:31:57 +00:00
|
|
|
DstOff += VTSize;
|
|
|
|
}
|
2014-04-26 18:35:24 +00:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2014-04-30 07:17:30 +00:00
|
|
|
makeArrayRef(TFOps, i));
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
EmittedNumMemOps += i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (BytesLeft == 0)
|
|
|
|
return Chain;
|
|
|
|
|
|
|
|
// Issue loads / stores for the trailing (1 - 3) bytes.
|
|
|
|
unsigned BytesLeftSave = BytesLeft;
|
|
|
|
i = 0;
|
|
|
|
while (BytesLeft) {
|
|
|
|
if (BytesLeft >= 2) {
|
|
|
|
VT = MVT::i16;
|
|
|
|
VTSize = 2;
|
|
|
|
} else {
|
|
|
|
VT = MVT::i8;
|
|
|
|
VTSize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Loads[i] = DAG.getLoad(VT, dl, Chain,
|
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32, Src,
|
|
|
|
DAG.getConstant(SrcOff, MVT::i32)),
|
2011-11-08 18:42:53 +00:00
|
|
|
SrcPtrInfo.getWithOffset(SrcOff),
|
|
|
|
false, false, false, 0);
|
2010-05-11 17:31:57 +00:00
|
|
|
TFOps[i] = Loads[i].getValue(1);
|
|
|
|
++i;
|
|
|
|
SrcOff += VTSize;
|
|
|
|
BytesLeft -= VTSize;
|
|
|
|
}
|
2014-04-26 18:35:24 +00:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2014-04-30 07:17:30 +00:00
|
|
|
makeArrayRef(TFOps, i));
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
BytesLeft = BytesLeftSave;
|
|
|
|
while (BytesLeft) {
|
|
|
|
if (BytesLeft >= 2) {
|
|
|
|
VT = MVT::i16;
|
|
|
|
VTSize = 2;
|
|
|
|
} else {
|
|
|
|
VT = MVT::i8;
|
|
|
|
VTSize = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
TFOps[i] = DAG.getStore(Chain, dl, Loads[i],
|
|
|
|
DAG.getNode(ISD::ADD, dl, MVT::i32, Dst,
|
|
|
|
DAG.getConstant(DstOff, MVT::i32)),
|
2010-09-21 05:40:29 +00:00
|
|
|
DstPtrInfo.getWithOffset(DstOff), false, false, 0);
|
2010-05-11 17:31:57 +00:00
|
|
|
++i;
|
|
|
|
DstOff += VTSize;
|
|
|
|
BytesLeft -= VTSize;
|
|
|
|
}
|
2014-04-26 18:35:24 +00:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2014-04-30 07:17:30 +00:00
|
|
|
makeArrayRef(TFOps, i));
|
2010-05-11 17:31:57 +00:00
|
|
|
}
|
2011-05-22 21:41:23 +00:00
|
|
|
|
|
|
|
// Adjust parameters for memset, EABI uses format (ptr, size, value),
|
|
|
|
// GNU library uses (ptr, value, size)
|
|
|
|
// See RTABI section 4.3.4
|
2011-09-13 20:30:37 +00:00
|
|
|
SDValue ARMSelectionDAGInfo::
|
2013-05-25 02:42:55 +00:00
|
|
|
EmitTargetCodeForMemset(SelectionDAG &DAG, SDLoc dl,
|
2011-09-13 20:30:37 +00:00
|
|
|
SDValue Chain, SDValue Dst,
|
|
|
|
SDValue Src, SDValue Size,
|
|
|
|
unsigned Align, bool isVolatile,
|
|
|
|
MachinePointerInfo DstPtrInfo) const {
|
2015-02-20 08:24:37 +00:00
|
|
|
const ARMSubtarget &Subtarget =
|
|
|
|
DAG.getMachineFunction().getSubtarget<ARMSubtarget>();
|
2014-01-06 14:28:05 +00:00
|
|
|
// Use default for non-AAPCS (or MachO) subtargets
|
2014-06-12 23:39:49 +00:00
|
|
|
if (!Subtarget.isAAPCS_ABI() || Subtarget.isTargetMachO() ||
|
|
|
|
Subtarget.isTargetWindows())
|
2011-05-22 21:41:23 +00:00
|
|
|
return SDValue();
|
|
|
|
|
2015-02-20 08:24:37 +00:00
|
|
|
const ARMTargetLowering &TLI = *Subtarget.getTargetLowering();
|
2011-05-22 21:41:23 +00:00
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
TargetLowering::ArgListEntry Entry;
|
|
|
|
|
|
|
|
// First argument: data pointer
|
2012-11-01 08:07:29 +00:00
|
|
|
Type *IntPtrTy = TLI.getDataLayout()->getIntPtrType(*DAG.getContext());
|
2011-05-22 21:41:23 +00:00
|
|
|
Entry.Node = Dst;
|
|
|
|
Entry.Ty = IntPtrTy;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
// Second argument: buffer size
|
|
|
|
Entry.Node = Size;
|
|
|
|
Entry.Ty = IntPtrTy;
|
|
|
|
Entry.isSExt = false;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
// Extend or truncate the argument to be an i32 value for the call.
|
|
|
|
if (Src.getValueType().bitsGT(MVT::i32))
|
|
|
|
Src = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Src);
|
|
|
|
else
|
|
|
|
Src = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Src);
|
|
|
|
|
|
|
|
// Third argument: value to fill
|
|
|
|
Entry.Node = Src;
|
|
|
|
Entry.Ty = Type::getInt32Ty(*DAG.getContext());
|
|
|
|
Entry.isSExt = true;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
// Emit __eabi_memset call
|
2014-05-17 21:50:17 +00:00
|
|
|
TargetLowering::CallLoweringInfo CLI(DAG);
|
|
|
|
CLI.setDebugLoc(dl).setChain(Chain)
|
|
|
|
.setCallee(TLI.getLibcallCallingConv(RTLIB::MEMSET),
|
|
|
|
Type::getVoidTy(*DAG.getContext()),
|
|
|
|
DAG.getExternalSymbol(TLI.getLibcallName(RTLIB::MEMSET),
|
2014-07-01 22:01:54 +00:00
|
|
|
TLI.getPointerTy()), std::move(Args), 0)
|
2014-05-17 21:50:17 +00:00
|
|
|
.setDiscardResult();
|
|
|
|
|
|
|
|
std::pair<SDValue,SDValue> CallResult = TLI.LowerCallTo(CLI);
|
2011-05-22 21:41:23 +00:00
|
|
|
return CallResult.second;
|
|
|
|
}
|