2010-04-17 01:04:22 +02: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 19:31:57 +02:00
|
|
|
#include "ARMTargetMachine.h"
|
2011-05-22 23:41:23 +02:00
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/DerivedTypes.h"
|
2010-04-17 01:04:22 +02:00
|
|
|
using namespace llvm;
|
|
|
|
|
2014-04-22 04:41:26 +02:00
|
|
|
#define DEBUG_TYPE "arm-selectiondag-info"
|
|
|
|
|
2015-05-12 15:13:38 +02:00
|
|
|
// Emit, if possible, a specialized version of the given Libcall. Typically this
|
|
|
|
// means selecting the appropriately aligned version, but we also convert memset
|
|
|
|
// of 0 into memclr.
|
2016-06-12 17:39:02 +02:00
|
|
|
SDValue ARMSelectionDAGInfo::EmitSpecializedLibcall(
|
|
|
|
SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align, RTLIB::Libcall LC) const {
|
2015-05-12 15:13:38 +02:00
|
|
|
const ARMSubtarget &Subtarget =
|
|
|
|
DAG.getMachineFunction().getSubtarget<ARMSubtarget>();
|
|
|
|
const ARMTargetLowering *TLI = Subtarget.getTargetLowering();
|
|
|
|
|
|
|
|
// Only use a specialized AEABI function if the default version of this
|
|
|
|
// Libcall is an AEABI function.
|
|
|
|
if (std::strncmp(TLI->getLibcallName(LC), "__aeabi", 7) != 0)
|
|
|
|
return SDValue();
|
|
|
|
|
|
|
|
// Translate RTLIB::Libcall to AEABILibcall. We only do this in order to be
|
|
|
|
// able to translate memset to memclr and use the value to index the function
|
|
|
|
// name array.
|
|
|
|
enum {
|
|
|
|
AEABI_MEMCPY = 0,
|
|
|
|
AEABI_MEMMOVE,
|
|
|
|
AEABI_MEMSET,
|
|
|
|
AEABI_MEMCLR
|
|
|
|
} AEABILibcall;
|
|
|
|
switch (LC) {
|
|
|
|
case RTLIB::MEMCPY:
|
|
|
|
AEABILibcall = AEABI_MEMCPY;
|
|
|
|
break;
|
|
|
|
case RTLIB::MEMMOVE:
|
|
|
|
AEABILibcall = AEABI_MEMMOVE;
|
|
|
|
break;
|
|
|
|
case RTLIB::MEMSET:
|
|
|
|
AEABILibcall = AEABI_MEMSET;
|
|
|
|
if (ConstantSDNode *ConstantSrc = dyn_cast<ConstantSDNode>(Src))
|
|
|
|
if (ConstantSrc->getZExtValue() == 0)
|
|
|
|
AEABILibcall = AEABI_MEMCLR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Choose the most-aligned libcall variant that we can
|
|
|
|
enum {
|
|
|
|
ALIGN1 = 0,
|
|
|
|
ALIGN4,
|
|
|
|
ALIGN8
|
|
|
|
} AlignVariant;
|
|
|
|
if ((Align & 7) == 0)
|
|
|
|
AlignVariant = ALIGN8;
|
|
|
|
else if ((Align & 3) == 0)
|
|
|
|
AlignVariant = ALIGN4;
|
|
|
|
else
|
|
|
|
AlignVariant = ALIGN1;
|
|
|
|
|
|
|
|
TargetLowering::ArgListTy Args;
|
|
|
|
TargetLowering::ArgListEntry Entry;
|
2015-07-09 04:09:52 +02:00
|
|
|
Entry.Ty = DAG.getDataLayout().getIntPtrType(*DAG.getContext());
|
2015-05-12 15:13:38 +02:00
|
|
|
Entry.Node = Dst;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
if (AEABILibcall == AEABI_MEMCLR) {
|
|
|
|
Entry.Node = Size;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
} else if (AEABILibcall == AEABI_MEMSET) {
|
|
|
|
// Adjust parameters for memset, EABI uses format (ptr, size, value),
|
|
|
|
// GNU library uses (ptr, value, size)
|
|
|
|
// See RTABI section 4.3.4
|
|
|
|
Entry.Node = Size;
|
|
|
|
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 if (Src.getValueType().bitsLT(MVT::i32))
|
|
|
|
Src = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Src);
|
|
|
|
|
|
|
|
Entry.Node = Src;
|
|
|
|
Entry.Ty = Type::getInt32Ty(*DAG.getContext());
|
|
|
|
Entry.isSExt = false;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
} else {
|
|
|
|
Entry.Node = Src;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
|
|
|
|
Entry.Node = Size;
|
|
|
|
Args.push_back(Entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *FunctionNames[4][3] = {
|
|
|
|
{ "__aeabi_memcpy", "__aeabi_memcpy4", "__aeabi_memcpy8" },
|
|
|
|
{ "__aeabi_memmove", "__aeabi_memmove4", "__aeabi_memmove8" },
|
|
|
|
{ "__aeabi_memset", "__aeabi_memset4", "__aeabi_memset8" },
|
|
|
|
{ "__aeabi_memclr", "__aeabi_memclr4", "__aeabi_memclr8" }
|
|
|
|
};
|
|
|
|
TargetLowering::CallLoweringInfo CLI(DAG);
|
2015-07-09 04:09:04 +02:00
|
|
|
CLI.setDebugLoc(dl)
|
|
|
|
.setChain(Chain)
|
|
|
|
.setCallee(
|
|
|
|
TLI->getLibcallCallingConv(LC), Type::getVoidTy(*DAG.getContext()),
|
|
|
|
DAG.getExternalSymbol(FunctionNames[AEABILibcall][AlignVariant],
|
|
|
|
TLI->getPointerTy(DAG.getDataLayout())),
|
2016-06-22 14:54:25 +02:00
|
|
|
std::move(Args))
|
2015-07-09 04:09:04 +02:00
|
|
|
.setDiscardResult();
|
2015-05-12 15:13:38 +02:00
|
|
|
std::pair<SDValue,SDValue> CallResult = TLI->LowerCallTo(CLI);
|
|
|
|
|
|
|
|
return CallResult.second;
|
|
|
|
}
|
|
|
|
|
2016-06-12 17:39:02 +02:00
|
|
|
SDValue ARMSelectionDAGInfo::EmitTargetCodeForMemcpy(
|
|
|
|
SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align, bool isVolatile, bool AlwaysInline,
|
|
|
|
MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
|
2015-02-20 09:24:37 +01:00
|
|
|
const ARMSubtarget &Subtarget =
|
|
|
|
DAG.getMachineFunction().getSubtarget<ARMSubtarget>();
|
2010-05-11 19:31:57 +02: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 07:18:47 +02:00
|
|
|
// This requires the copy size to be a constant, preferably
|
2010-05-11 19:31:57 +02:00
|
|
|
// within a subtarget-specific limit.
|
|
|
|
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
|
|
|
if (!ConstantSize)
|
2015-05-12 15:13:38 +02:00
|
|
|
return EmitSpecializedLibcall(DAG, dl, Chain, Dst, Src, Size, Align,
|
|
|
|
RTLIB::MEMCPY);
|
2010-05-11 19:31:57 +02:00
|
|
|
uint64_t SizeVal = ConstantSize->getZExtValue();
|
2014-06-13 01:39:49 +02:00
|
|
|
if (!AlwaysInline && SizeVal > Subtarget.getMaxInlineSizeThreshold())
|
2015-05-12 15:13:38 +02:00
|
|
|
return EmitSpecializedLibcall(DAG, dl, Chain, Dst, Src, Size, Align,
|
|
|
|
RTLIB::MEMCPY);
|
2010-05-11 19:31:57 +02:00
|
|
|
|
|
|
|
unsigned BytesLeft = SizeVal & 3;
|
|
|
|
unsigned NumMemOps = SizeVal >> 2;
|
|
|
|
unsigned EmittedNumMemOps = 0;
|
|
|
|
EVT VT = MVT::i32;
|
|
|
|
unsigned VTSize = 4;
|
|
|
|
unsigned i = 0;
|
2014-05-16 16:24:22 +02:00
|
|
|
// Emit a maximum of 4 loads in Thumb1 since we have fewer registers
|
2015-10-05 16:49:54 +02:00
|
|
|
const unsigned MaxLoadsInLDM = Subtarget.isThumb1Only() ? 4 : 6;
|
2014-05-16 16:24:22 +02:00
|
|
|
SDValue TFOps[6];
|
|
|
|
SDValue Loads[6];
|
2010-05-11 19:31:57 +02:00
|
|
|
uint64_t SrcOff = 0, DstOff = 0;
|
|
|
|
|
2015-10-05 16:49:54 +02:00
|
|
|
// FIXME: We should invent a VMEMCPY pseudo-instruction that lowers to
|
|
|
|
// VLDM/VSTM and make this code emit it when appropriate. This would reduce
|
|
|
|
// pressure on the general purpose registers. However this seems harder to map
|
|
|
|
// onto the register allocator's view of the world.
|
|
|
|
|
|
|
|
// The number of MEMCPY pseudo-instructions to emit. We use up to
|
|
|
|
// MaxLoadsInLDM registers per mcopy, which will get lowered into ldm/stm
|
|
|
|
// later on. This is a lower bound on the number of MEMCPY operations we must
|
|
|
|
// emit.
|
|
|
|
unsigned NumMEMCPYs = (NumMemOps + MaxLoadsInLDM - 1) / MaxLoadsInLDM;
|
|
|
|
|
2016-06-03 17:38:55 +02:00
|
|
|
// Code size optimisation: do not inline memcpy if expansion results in
|
|
|
|
// more instructions than the libary call.
|
|
|
|
if (NumMEMCPYs > 1 && DAG.getMachineFunction().getFunction()->optForMinSize()) {
|
|
|
|
return SDValue();
|
|
|
|
}
|
|
|
|
|
2015-10-05 16:49:54 +02:00
|
|
|
SDVTList VTs = DAG.getVTList(MVT::i32, MVT::i32, MVT::Other, MVT::Glue);
|
|
|
|
|
|
|
|
for (unsigned I = 0; I != NumMEMCPYs; ++I) {
|
|
|
|
// Evenly distribute registers among MEMCPY operations to reduce register
|
|
|
|
// pressure.
|
|
|
|
unsigned NextEmittedNumMemOps = NumMemOps * (I + 1) / NumMEMCPYs;
|
|
|
|
unsigned NumRegs = NextEmittedNumMemOps - EmittedNumMemOps;
|
|
|
|
|
|
|
|
Dst = DAG.getNode(ARMISD::MEMCPY, dl, VTs, Chain, Dst, Src,
|
|
|
|
DAG.getConstant(NumRegs, dl, MVT::i32));
|
|
|
|
Src = Dst.getValue(1);
|
|
|
|
Chain = Dst.getValue(2);
|
|
|
|
|
|
|
|
DstPtrInfo = DstPtrInfo.getWithOffset(NumRegs * VTSize);
|
|
|
|
SrcPtrInfo = SrcPtrInfo.getWithOffset(NumRegs * VTSize);
|
2010-05-11 19:31:57 +02:00
|
|
|
|
2015-10-05 16:49:54 +02:00
|
|
|
EmittedNumMemOps = NextEmittedNumMemOps;
|
2010-05-11 19:31:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2015-04-28 16:05:47 +02:00
|
|
|
DAG.getConstant(SrcOff, dl, MVT::i32)),
|
[SelectionDAG] Get rid of bool parameters in SelectionDAG::getLoad, getStore, and friends.
Summary:
Instead, we take a single flags arg (a bitset).
Also add a default 0 alignment, and change the order of arguments so the
alignment comes before the flags.
This greatly simplifies many callsites, and fixes a bug in
AMDGPUISelLowering, wherein the order of the args to getLoad was
inverted. It also greatly simplifies the process of adding another flag
to getLoad.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, jyknight, dsanders, nemanjai, llvm-commits
Differential Revision: http://reviews.llvm.org/D22249
llvm-svn: 275592
2016-07-15 20:27:10 +02:00
|
|
|
SrcPtrInfo.getWithOffset(SrcOff));
|
2010-05-11 19:31:57 +02:00
|
|
|
TFOps[i] = Loads[i].getValue(1);
|
|
|
|
++i;
|
|
|
|
SrcOff += VTSize;
|
|
|
|
BytesLeft -= VTSize;
|
|
|
|
}
|
2014-04-26 20:35:24 +02:00
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2014-04-30 09:17:30 +02:00
|
|
|
makeArrayRef(TFOps, i));
|
2010-05-11 19:31:57 +02: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,
|
2015-04-28 16:05:47 +02:00
|
|
|
DAG.getConstant(DstOff, dl, MVT::i32)),
|
[SelectionDAG] Get rid of bool parameters in SelectionDAG::getLoad, getStore, and friends.
Summary:
Instead, we take a single flags arg (a bitset).
Also add a default 0 alignment, and change the order of arguments so the
alignment comes before the flags.
This greatly simplifies many callsites, and fixes a bug in
AMDGPUISelLowering, wherein the order of the args to getLoad was
inverted. It also greatly simplifies the process of adding another flag
to getLoad.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, jyknight, dsanders, nemanjai, llvm-commits
Differential Revision: http://reviews.llvm.org/D22249
llvm-svn: 275592
2016-07-15 20:27:10 +02:00
|
|
|
DstPtrInfo.getWithOffset(DstOff));
|
2010-05-11 19:31:57 +02:00
|
|
|
++i;
|
|
|
|
DstOff += VTSize;
|
|
|
|
BytesLeft -= VTSize;
|
|
|
|
}
|
2014-04-26 20:35:24 +02:00
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
|
2014-04-30 09:17:30 +02:00
|
|
|
makeArrayRef(TFOps, i));
|
2010-05-11 19:31:57 +02:00
|
|
|
}
|
2011-05-22 23:41:23 +02:00
|
|
|
|
2016-06-12 17:39:02 +02:00
|
|
|
SDValue ARMSelectionDAGInfo::EmitTargetCodeForMemmove(
|
|
|
|
SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align, bool isVolatile,
|
|
|
|
MachinePointerInfo DstPtrInfo, MachinePointerInfo SrcPtrInfo) const {
|
2015-05-12 15:13:38 +02:00
|
|
|
return EmitSpecializedLibcall(DAG, dl, Chain, Dst, Src, Size, Align,
|
|
|
|
RTLIB::MEMMOVE);
|
|
|
|
}
|
|
|
|
|
2016-06-12 17:39:02 +02:00
|
|
|
SDValue ARMSelectionDAGInfo::EmitTargetCodeForMemset(
|
|
|
|
SelectionDAG &DAG, const SDLoc &dl, SDValue Chain, SDValue Dst, SDValue Src,
|
|
|
|
SDValue Size, unsigned Align, bool isVolatile,
|
|
|
|
MachinePointerInfo DstPtrInfo) const {
|
2015-05-12 15:13:38 +02:00
|
|
|
return EmitSpecializedLibcall(DAG, dl, Chain, Dst, Src, Size, Align,
|
|
|
|
RTLIB::MEMSET);
|
2011-05-22 23:41:23 +02:00
|
|
|
}
|