BuildLibCalls.cpp (208954) | BuildLibCalls.cpp (210299) |
---|---|
1//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 55 unchanged lines hidden (view full) --- 64 I8Ptr, I8Ptr, I32Ty, NULL); 65 CallInst *CI = B.CreateCall2(StrChr, CastToCStr(Ptr, B), 66 ConstantInt::get(I32Ty, C), "strchr"); 67 if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts())) 68 CI->setCallingConv(F->getCallingConv()); 69 return CI; 70} 71 | 1//===- BuildLibCalls.cpp - Utility builder for libcalls -------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// --- 55 unchanged lines hidden (view full) --- 64 I8Ptr, I8Ptr, I32Ty, NULL); 65 CallInst *CI = B.CreateCall2(StrChr, CastToCStr(Ptr, B), 66 ConstantInt::get(I32Ty, C), "strchr"); 67 if (const Function *F = dyn_cast<Function>(StrChr->stripPointerCasts())) 68 CI->setCallingConv(F->getCallingConv()); 69 return CI; 70} 71 |
72/// EmitStrNCmp - Emit a call to the strncmp function to the builder. 73Value *llvm::EmitStrNCmp(Value *Ptr1, Value *Ptr2, Value *Len, 74 IRBuilder<> &B, const TargetData *TD) { 75 Module *M = B.GetInsertBlock()->getParent()->getParent(); 76 AttributeWithIndex AWI[3]; 77 AWI[0] = AttributeWithIndex::get(1, Attribute::NoCapture); 78 AWI[1] = AttributeWithIndex::get(2, Attribute::NoCapture); 79 AWI[2] = AttributeWithIndex::get(~0u, Attribute::ReadOnly | 80 Attribute::NoUnwind); 81 82 LLVMContext &Context = B.GetInsertBlock()->getContext(); 83 Value *StrNCmp = M->getOrInsertFunction("strncmp", AttrListPtr::get(AWI, 3), 84 B.getInt32Ty(), 85 B.getInt8PtrTy(), 86 B.getInt8PtrTy(), 87 TD->getIntPtrType(Context), NULL); 88 CallInst *CI = B.CreateCall3(StrNCmp, CastToCStr(Ptr1, B), 89 CastToCStr(Ptr2, B), Len, "strncmp"); 90 91 if (const Function *F = dyn_cast<Function>(StrNCmp->stripPointerCasts())) 92 CI->setCallingConv(F->getCallingConv()); 93 94 return CI; 95} 96 |
|
72/// EmitStrCpy - Emit a call to the strcpy function to the builder, for the 73/// specified pointer arguments. 74Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, 75 const TargetData *TD, StringRef Name) { 76 Module *M = B.GetInsertBlock()->getParent()->getParent(); 77 AttributeWithIndex AWI[2]; 78 AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture); 79 AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); --- 27 unchanged lines hidden (view full) --- 107} 108 109 110/// EmitMemCpy - Emit a call to the memcpy function to the builder. This always 111/// expects that Len has type 'intptr_t' and Dst/Src are pointers. 112Value *llvm::EmitMemCpy(Value *Dst, Value *Src, Value *Len, unsigned Align, 113 bool isVolatile, IRBuilder<> &B, const TargetData *TD) { 114 Module *M = B.GetInsertBlock()->getParent()->getParent(); | 97/// EmitStrCpy - Emit a call to the strcpy function to the builder, for the 98/// specified pointer arguments. 99Value *llvm::EmitStrCpy(Value *Dst, Value *Src, IRBuilder<> &B, 100 const TargetData *TD, StringRef Name) { 101 Module *M = B.GetInsertBlock()->getParent()->getParent(); 102 AttributeWithIndex AWI[2]; 103 AWI[0] = AttributeWithIndex::get(2, Attribute::NoCapture); 104 AWI[1] = AttributeWithIndex::get(~0u, Attribute::NoUnwind); --- 27 unchanged lines hidden (view full) --- 132} 133 134 135/// EmitMemCpy - Emit a call to the memcpy function to the builder. This always 136/// expects that Len has type 'intptr_t' and Dst/Src are pointers. 137Value *llvm::EmitMemCpy(Value *Dst, Value *Src, Value *Len, unsigned Align, 138 bool isVolatile, IRBuilder<> &B, const TargetData *TD) { 139 Module *M = B.GetInsertBlock()->getParent()->getParent(); |
115 const Type *ArgTys[3] = { Dst->getType(), Src->getType(), Len->getType() }; 116 Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, ArgTys, 3); | |
117 Dst = CastToCStr(Dst, B); 118 Src = CastToCStr(Src, B); | 140 Dst = CastToCStr(Dst, B); 141 Src = CastToCStr(Src, B); |
142 const Type *ArgTys[3] = { Dst->getType(), Src->getType(), Len->getType() }; 143 Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, ArgTys, 3); |
|
119 return B.CreateCall5(MemCpy, Dst, Src, Len, 120 ConstantInt::get(B.getInt32Ty(), Align), 121 ConstantInt::get(B.getInt1Ty(), isVolatile)); 122} 123 124/// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder. 125/// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src 126/// are pointers. --- 263 unchanged lines hidden (view full) --- 390 if (Name == "__memcpy_chk") { 391 // Check if this has the right signature. 392 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 393 !FT->getParamType(0)->isPointerTy() || 394 !FT->getParamType(1)->isPointerTy() || 395 FT->getParamType(2) != TD->getIntPtrType(Context) || 396 FT->getParamType(3) != TD->getIntPtrType(Context)) 397 return false; | 144 return B.CreateCall5(MemCpy, Dst, Src, Len, 145 ConstantInt::get(B.getInt32Ty(), Align), 146 ConstantInt::get(B.getInt1Ty(), isVolatile)); 147} 148 149/// EmitMemCpyChk - Emit a call to the __memcpy_chk function to the builder. 150/// This expects that the Len and ObjSize have type 'intptr_t' and Dst/Src 151/// are pointers. --- 263 unchanged lines hidden (view full) --- 415 if (Name == "__memcpy_chk") { 416 // Check if this has the right signature. 417 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 418 !FT->getParamType(0)->isPointerTy() || 419 !FT->getParamType(1)->isPointerTy() || 420 FT->getParamType(2) != TD->getIntPtrType(Context) || 421 FT->getParamType(3) != TD->getIntPtrType(Context)) 422 return false; |
398 399 if (isFoldable(4, 3, false)) { 400 EmitMemCpy(CI->getOperand(1), CI->getOperand(2), CI->getOperand(3), | 423 424 if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) { 425 EmitMemCpy(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), |
401 1, false, B, TD); | 426 1, false, B, TD); |
402 replaceCall(CI->getOperand(1)); | 427 replaceCall(CI->getArgOperand(0)); |
403 return true; 404 } 405 return false; 406 } 407 408 // Should be similar to memcpy. 409 if (Name == "__mempcpy_chk") { 410 return false; 411 } 412 413 if (Name == "__memmove_chk") { 414 // Check if this has the right signature. 415 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 416 !FT->getParamType(0)->isPointerTy() || 417 !FT->getParamType(1)->isPointerTy() || 418 FT->getParamType(2) != TD->getIntPtrType(Context) || 419 FT->getParamType(3) != TD->getIntPtrType(Context)) 420 return false; | 428 return true; 429 } 430 return false; 431 } 432 433 // Should be similar to memcpy. 434 if (Name == "__mempcpy_chk") { 435 return false; 436 } 437 438 if (Name == "__memmove_chk") { 439 // Check if this has the right signature. 440 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 441 !FT->getParamType(0)->isPointerTy() || 442 !FT->getParamType(1)->isPointerTy() || 443 FT->getParamType(2) != TD->getIntPtrType(Context) || 444 FT->getParamType(3) != TD->getIntPtrType(Context)) 445 return false; |
421 422 if (isFoldable(4, 3, false)) { 423 EmitMemMove(CI->getOperand(1), CI->getOperand(2), CI->getOperand(3), | 446 447 if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) { 448 EmitMemMove(CI->getArgOperand(0), CI->getArgOperand(1), CI->getArgOperand(2), |
424 1, false, B, TD); | 449 1, false, B, TD); |
425 replaceCall(CI->getOperand(1)); | 450 replaceCall(CI->getArgOperand(0)); |
426 return true; 427 } 428 return false; 429 } 430 431 if (Name == "__memset_chk") { 432 // Check if this has the right signature. 433 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 434 !FT->getParamType(0)->isPointerTy() || 435 !FT->getParamType(1)->isIntegerTy() || 436 FT->getParamType(2) != TD->getIntPtrType(Context) || 437 FT->getParamType(3) != TD->getIntPtrType(Context)) 438 return false; | 451 return true; 452 } 453 return false; 454 } 455 456 if (Name == "__memset_chk") { 457 // Check if this has the right signature. 458 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 459 !FT->getParamType(0)->isPointerTy() || 460 !FT->getParamType(1)->isIntegerTy() || 461 FT->getParamType(2) != TD->getIntPtrType(Context) || 462 FT->getParamType(3) != TD->getIntPtrType(Context)) 463 return false; |
439 440 if (isFoldable(4, 3, false)) { 441 Value *Val = B.CreateIntCast(CI->getOperand(2), B.getInt8Ty(), | 464 465 if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) { 466 Value *Val = B.CreateIntCast(CI->getArgOperand(1), B.getInt8Ty(), |
442 false); | 467 false); |
443 EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), false, B, TD); 444 replaceCall(CI->getOperand(1)); | 468 EmitMemSet(CI->getArgOperand(0), Val, CI->getArgOperand(2), false, B, TD); 469 replaceCall(CI->getArgOperand(0)); |
445 return true; 446 } 447 return false; 448 } 449 450 if (Name == "__strcpy_chk" || Name == "__stpcpy_chk") { 451 // Check if this has the right signature. 452 if (FT->getNumParams() != 3 || --- 4 unchanged lines hidden (view full) --- 457 return 0; 458 459 460 // If a) we don't have any length information, or b) we know this will 461 // fit then just lower to a plain st[rp]cpy. Otherwise we'll keep our 462 // st[rp]cpy_chk call which may fail at runtime if the size is too long. 463 // TODO: It might be nice to get a maximum length out of the possible 464 // string lengths for varying. | 470 return true; 471 } 472 return false; 473 } 474 475 if (Name == "__strcpy_chk" || Name == "__stpcpy_chk") { 476 // Check if this has the right signature. 477 if (FT->getNumParams() != 3 || --- 4 unchanged lines hidden (view full) --- 482 return 0; 483 484 485 // If a) we don't have any length information, or b) we know this will 486 // fit then just lower to a plain st[rp]cpy. Otherwise we'll keep our 487 // st[rp]cpy_chk call which may fail at runtime if the size is too long. 488 // TODO: It might be nice to get a maximum length out of the possible 489 // string lengths for varying. |
465 if (isFoldable(3, 2, true)) { 466 Value *Ret = EmitStrCpy(CI->getOperand(1), CI->getOperand(2), B, TD, | 490 if (isFoldable(2 + CallInst::ArgOffset, 1 + CallInst::ArgOffset, true)) { 491 Value *Ret = EmitStrCpy(CI->getArgOperand(0), CI->getArgOperand(1), B, TD, |
467 Name.substr(2, 6)); 468 replaceCall(Ret); 469 return true; 470 } 471 return false; 472 } 473 474 if (Name == "__strncpy_chk" || Name == "__stpncpy_chk") { 475 // Check if this has the right signature. 476 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 477 FT->getParamType(0) != FT->getParamType(1) || 478 FT->getParamType(0) != Type::getInt8PtrTy(Context) || 479 !FT->getParamType(2)->isIntegerTy() || 480 FT->getParamType(3) != TD->getIntPtrType(Context)) 481 return false; | 492 Name.substr(2, 6)); 493 replaceCall(Ret); 494 return true; 495 } 496 return false; 497 } 498 499 if (Name == "__strncpy_chk" || Name == "__stpncpy_chk") { 500 // Check if this has the right signature. 501 if (FT->getNumParams() != 4 || FT->getReturnType() != FT->getParamType(0) || 502 FT->getParamType(0) != FT->getParamType(1) || 503 FT->getParamType(0) != Type::getInt8PtrTy(Context) || 504 !FT->getParamType(2)->isIntegerTy() || 505 FT->getParamType(3) != TD->getIntPtrType(Context)) 506 return false; |
482 483 if (isFoldable(4, 3, false)) { 484 Value *Ret = EmitStrNCpy(CI->getOperand(1), CI->getOperand(2), 485 CI->getOperand(3), B, TD, Name.substr(2, 7)); | 507 508 if (isFoldable(3 + CallInst::ArgOffset, 2 + CallInst::ArgOffset, false)) { 509 Value *Ret = EmitStrNCpy(CI->getArgOperand(0), CI->getArgOperand(1), 510 CI->getArgOperand(2), B, TD, Name.substr(2, 7)); |
486 replaceCall(Ret); 487 return true; 488 } 489 return false; 490 } 491 492 if (Name == "__strcat_chk") { 493 return false; 494 } 495 496 if (Name == "__strncat_chk") { 497 return false; 498 } 499 500 return false; 501} | 511 replaceCall(Ret); 512 return true; 513 } 514 return false; 515 } 516 517 if (Name == "__strcat_chk") { 518 return false; 519 } 520 521 if (Name == "__strncat_chk") { 522 return false; 523 } 524 525 return false; 526} |