mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-21 08:17:40 +00:00
Teach simplify libcall to transform __strcpy_chk to __memcpy_chk to enable optimizations down stream.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99282 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -108,7 +108,7 @@ Value *llvm::EmitStrNCpy(Value *Dst, Value *Src, Value *Len,
|
||||
|
||||
|
||||
/// EmitMemCpy - Emit a call to the memcpy function to the builder. This always
|
||||
/// expects that the size has type 'intptr_t' and Dst/Src are pointers.
|
||||
/// expects that Len has type 'intptr_t' and Dst/Src are pointers.
|
||||
Value *llvm::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
|
||||
unsigned Align, IRBuilder<> &B, const TargetData *TD) {
|
||||
Module *M = B.GetInsertBlock()->getParent()->getParent();
|
||||
@@ -120,6 +120,30 @@ Value *llvm::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
|
||||
ConstantInt::get(B.getInt32Ty(), Align));
|
||||
}
|
||||
|
||||
/// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder.
|
||||
/// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src
|
||||
/// are pointers.
|
||||
Value *llvm::EmitMemCpyChk(Value *Dst, Value *Src, Value *Len, Value *ObjSize,
|
||||
IRBuilder<> &B, const TargetData *TD) {
|
||||
Module *M = B.GetInsertBlock()->getParent()->getParent();
|
||||
AttributeWithIndex AWI;
|
||||
AWI = AttributeWithIndex::get(~0u, Attribute::NoUnwind);
|
||||
LLVMContext &Context = B.GetInsertBlock()->getContext();
|
||||
Value *MemCpy = M->getOrInsertFunction("__memcpy_chk",
|
||||
AttrListPtr::get(&AWI, 1),
|
||||
B.getInt8PtrTy(),
|
||||
B.getInt8PtrTy(),
|
||||
B.getInt8PtrTy(),
|
||||
TD->getIntPtrType(Context),
|
||||
TD->getIntPtrType(Context), NULL);
|
||||
Dst = CastToCStr(Dst, B);
|
||||
Src = CastToCStr(Src, B);
|
||||
CallInst *CI = B.CreateCall4(MemCpy, Dst, Src, Len, ObjSize);
|
||||
if (const Function *F = dyn_cast<Function>(MemCpy->stripPointerCasts()))
|
||||
CI->setCallingConv(F->getCallingConv());
|
||||
return CI;
|
||||
}
|
||||
|
||||
/// EmitMemMove - Emit a call to the memmove function to the builder. This
|
||||
/// always expects that the size has type 'intptr_t' and Dst/Src are pointers.
|
||||
Value *llvm::EmitMemMove(Value *Dst, Value *Src, Value *Len,
|
||||
|
||||
Reference in New Issue
Block a user