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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "arm-selectiondag-info"
|
2010-05-11 17:31:57 +00:00
|
|
|
#include "ARMTargetMachine.h"
|
2010-04-16 23:04:22 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2010-05-11 17:31:57 +00:00
|
|
|
ARMSelectionDAGInfo::ARMSelectionDAGInfo(const TargetMachine &TM)
|
|
|
|
: TargetSelectionDAGInfo(TM),
|
|
|
|
Subtarget(&TM.getSubtarget<ARMSubtarget>()) {
|
2010-04-16 23:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ARMSelectionDAGInfo::~ARMSelectionDAGInfo() {
|
|
|
|
}
|
2010-05-11 17:31:57 +00:00
|
|
|
|
|
|
|
SDValue
|
|
|
|
ARMSelectionDAGInfo::EmitTargetCodeForMemcpy(SelectionDAG &DAG, DebugLoc dl,
|
|
|
|
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 {
|
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();
|
|
|
|
// This requires the copy size to be a constant, preferrably
|
|
|
|
// within a subtarget-specific limit.
|
|
|
|
ConstantSDNode *ConstantSize = dyn_cast<ConstantSDNode>(Size);
|
|
|
|
if (!ConstantSize)
|
|
|
|
return SDValue();
|
|
|
|
uint64_t SizeVal = ConstantSize->getZExtValue();
|
|
|
|
if (!AlwaysInline && SizeVal > Subtarget->getMaxInlineSizeThreshold())
|
|
|
|
return SDValue();
|
|
|
|
|
|
|
|
unsigned BytesLeft = SizeVal & 3;
|
|
|
|
unsigned NumMemOps = SizeVal >> 2;
|
|
|
|
unsigned EmittedNumMemOps = 0;
|
|
|
|
EVT VT = MVT::i32;
|
|
|
|
unsigned VTSize = 4;
|
|
|
|
unsigned i = 0;
|
|
|
|
const unsigned MAX_LOADS_IN_LDM = 6;
|
|
|
|
SDValue TFOps[MAX_LOADS_IN_LDM];
|
|
|
|
SDValue Loads[MAX_LOADS_IN_LDM];
|
|
|
|
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,
|
|
|
|
false, 0);
|
2010-05-11 17:31:57 +00:00
|
|
|
TFOps[i] = Loads[i].getValue(1);
|
|
|
|
SrcOff += VTSize;
|
|
|
|
}
|
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
|
|
|
|
|
|
|
|
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)),
|
2010-09-21 05:40:29 +00:00
|
|
|
SrcPtrInfo.getWithOffset(SrcOff), false, false, 0);
|
2010-05-11 17:31:57 +00:00
|
|
|
TFOps[i] = Loads[i].getValue(1);
|
|
|
|
++i;
|
|
|
|
SrcOff += VTSize;
|
|
|
|
BytesLeft -= VTSize;
|
|
|
|
}
|
|
|
|
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
return DAG.getNode(ISD::TokenFactor, dl, MVT::Other, &TFOps[0], i);
|
|
|
|
}
|