Skip to content

Commit

Permalink
clang: Cleanup usage of CreateMemCpy
Browse files Browse the repository at this point in the history
It handles the the pointee type casts in preparation for opaque
pointers.
  • Loading branch information
arsenm committed May 9, 2020
1 parent 9a11174 commit 03cb328
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -1262,11 +1262,9 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,

// Otherwise do coercion through memory. This is stupid, but simple.
Address Tmp = CreateTempAllocaForCoercion(CGF, Ty, Src.getAlignment());
Address Casted = CGF.Builder.CreateElementBitCast(Tmp,CGF.Int8Ty);
Address SrcCasted = CGF.Builder.CreateElementBitCast(Src,CGF.Int8Ty);
CGF.Builder.CreateMemCpy(Casted, SrcCasted,
llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize),
false);
CGF.Builder.CreateMemCpy(Tmp.getPointer(), Tmp.getAlignment().getAsAlign(),
Src.getPointer(), Src.getAlignment().getAsAlign(),
llvm::ConstantInt::get(CGF.IntPtrTy, SrcSize));
return CGF.Builder.CreateLoad(Tmp);
}

Expand Down Expand Up @@ -1349,11 +1347,9 @@ static void CreateCoercedStore(llvm::Value *Src,
// to that information.
Address Tmp = CreateTempAllocaForCoercion(CGF, SrcTy, Dst.getAlignment());
CGF.Builder.CreateStore(Src, Tmp);
Address Casted = CGF.Builder.CreateElementBitCast(Tmp,CGF.Int8Ty);
Address DstCasted = CGF.Builder.CreateElementBitCast(Dst,CGF.Int8Ty);
CGF.Builder.CreateMemCpy(DstCasted, Casted,
llvm::ConstantInt::get(CGF.IntPtrTy, DstSize),
false);
CGF.Builder.CreateMemCpy(Dst.getPointer(), Dst.getAlignment().getAsAlign(),
Tmp.getPointer(), Tmp.getAlignment().getAsAlign(),
llvm::ConstantInt::get(CGF.IntPtrTy, DstSize));
}
}

Expand Down Expand Up @@ -2404,10 +2400,10 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
// FIXME: We should have a common utility for generating an aggregate
// copy.
CharUnits Size = getContext().getTypeSizeInChars(Ty);
auto SizeVal = llvm::ConstantInt::get(IntPtrTy, Size.getQuantity());
Address Dst = Builder.CreateBitCast(AlignedTemp, Int8PtrTy);
Address Src = Builder.CreateBitCast(ParamAddr, Int8PtrTy);
Builder.CreateMemCpy(Dst, Src, SizeVal, false);
Builder.CreateMemCpy(
AlignedTemp.getPointer(), AlignedTemp.getAlignment().getAsAlign(),
ParamAddr.getPointer(), ParamAddr.getAlignment().getAsAlign(),
llvm::ConstantInt::get(IntPtrTy, Size.getQuantity()));
V = AlignedTemp;
}
ArgVals.push_back(ParamValue::forIndirect(V));
Expand Down

0 comments on commit 03cb328

Please sign in to comment.