Refactor out code to fast-isel a memcpy operation with a small constant

length.  (I'm planning to use this to implement byval.)



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130274 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eli Friedman 2011-04-27 01:45:07 +00:00
parent 9266cc400e
commit d5089a9794

View File

@ -132,6 +132,9 @@ private:
}
bool isTypeLegal(const Type *Ty, MVT &VT, bool AllowI1 = false);
bool TryEmitSmallMemcpy(X86AddressMode DestAM,
X86AddressMode SrcAM, uint64_t Len);
};
} // end anonymous namespace.
@ -1323,28 +1326,12 @@ bool X86FastISel::X86SelectExtractValue(const Instruction *I) {
return false;
}
bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
// FIXME: Handle more intrinsics.
switch (I.getIntrinsicID()) {
default: return false;
case Intrinsic::memcpy: {
const MemCpyInst &MCI = cast<MemCpyInst>(I);
// Don't handle volatile or variable length memcpys.
if (MCI.isVolatile() || !isa<ConstantInt>(MCI.getLength()))
return false;
// Don't inline super long memcpys. We could lower these to a memcpy call,
// but we might as well bail out.
uint64_t Len = cast<ConstantInt>(MCI.getLength())->getZExtValue();
bool X86FastISel::TryEmitSmallMemcpy(X86AddressMode DestAM,
X86AddressMode SrcAM, uint64_t Len) {
// Make sure we don't bloat code by inlining very large memcpy's.
bool i64Legal = TLI.isTypeLegal(MVT::i64);
if (Len > (i64Legal ? 32 : 16)) return false;
// Get the address of the dest and source addresses.
X86AddressMode DestAM, SrcAM;
if (!X86SelectAddress(MCI.getRawDest(), DestAM) ||
!X86SelectAddress(MCI.getRawSource(), SrcAM))
return false;
// We don't care about alignment here since we just emit integer accesses.
while (Len) {
MVT VT;
@ -1371,6 +1358,27 @@ bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
}
return true;
}
bool X86FastISel::X86VisitIntrinsicCall(const IntrinsicInst &I) {
// FIXME: Handle more intrinsics.
switch (I.getIntrinsicID()) {
default: return false;
case Intrinsic::memcpy: {
const MemCpyInst &MCI = cast<MemCpyInst>(I);
// Don't handle volatile or variable length memcpys.
if (MCI.isVolatile() || !isa<ConstantInt>(MCI.getLength()))
return false;
uint64_t Len = cast<ConstantInt>(MCI.getLength())->getZExtValue();
// Get the address of the dest and source addresses.
X86AddressMode DestAM, SrcAM;
if (!X86SelectAddress(MCI.getRawDest(), DestAM) ||
!X86SelectAddress(MCI.getRawSource(), SrcAM))
return false;
return TryEmitSmallMemcpy(DestAM, SrcAM, Len);
}
case Intrinsic::stackprotector: {