Skip to content

Commit

Permalink
Merge rust-lang#10
Browse files Browse the repository at this point in the history
10: Annotate intrinsic calls with inlining decisions. r=ltratt a=ptersilie



Co-authored-by: Lukas Diekmann <lukas.diekmann@gmail.com>
  • Loading branch information
bors[bot] and ptersilie authored Nov 30, 2021
2 parents 30c18e4 + 7804cf1 commit b9b9cb8
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions llvm/lib/Target/X86/X86FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2588,6 +2588,17 @@ bool X86FastISel::TryEmitSmallMemcpy(X86AddressMode DestAM,
return true;
}

// Add an annotation to an intrinsic instruction, specifying whether the
// intrinsic has been inlined or not.
void annotateIntrinsic(const IntrinsicInst *II, bool Inlined) {
IntrinsicInst *CI = const_cast<IntrinsicInst *>(II);
LLVMContext& C = CI->getContext();
ConstantInt *CInt;
CInt = ConstantInt::get(C, APInt(1, Inlined ? 1: 0));
MDNode* N = MDNode::get(C, ConstantAsMetadata::get(CInt));
CI->setMetadata("yk.intrinsic.inlined", N);
}

bool X86FastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
// FIXME: Handle more intrinsics.
switch (II->getIntrinsicID()) {
Expand Down Expand Up @@ -2725,6 +2736,7 @@ bool X86FastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
// without a call if possible.
uint64_t Len = cast<ConstantInt>(MCI->getLength())->getZExtValue();
if (IsMemcpySmall(Len)) {
annotateIntrinsic(II, true);
X86AddressMode DestAM, SrcAM;
if (!X86SelectAddress(MCI->getRawDest(), DestAM) ||
!X86SelectAddress(MCI->getRawSource(), SrcAM))
Expand All @@ -2741,6 +2753,7 @@ bool X86FastISel::fastLowerIntrinsicCall(const IntrinsicInst *II) {
if (MCI->getSourceAddressSpace() > 255 || MCI->getDestAddressSpace() > 255)
return false;

annotateIntrinsic(II, false);
return lowerCallTo(II, "memcpy", II->getNumArgOperands() - 1);
}
case Intrinsic::memset: {
Expand Down

0 comments on commit b9b9cb8

Please sign in to comment.