- Timestamp:
- Apr 19, 2011, 11:12:07 PM (14 years ago)
- Location:
- clamav/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
clamav/trunk ¶
-
Property svn:mergeinfo
set to
/clamav/vendor/0.97 merged eligible
-
Property svn:mergeinfo
set to
-
TabularUnified clamav/trunk/libclamav/c++/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp ¶
r189 r319 305 305 public: 306 306 static char ID; // Pass identification, replacement for typeid 307 MemCpyOpt() : FunctionPass( &ID) {}307 MemCpyOpt() : FunctionPass(ID) {} 308 308 309 309 private: … … 332 332 FunctionPass *llvm::createMemCpyOptPass() { return new MemCpyOpt(); } 333 333 334 static RegisterPass<MemCpyOpt> X("memcpyopt", 335 "MemCpy Optimization"); 334 INITIALIZE_PASS(MemCpyOpt, "memcpyopt", "MemCpy Optimization", false, false); 336 335 337 336 … … 375 374 // allow readonly here because we don't want something like: 376 375 // A[1] = 2; strlen(A); A[2] = 2; -> memcpy(A, ...); strlen(A). 377 if (AA.getModRefBehavior(CallSite ::get(BI)) ==376 if (AA.getModRefBehavior(CallSite(BI)) == 378 377 AliasAnalysis::DoesNotAccessMemory) 379 378 continue; … … 414 413 Ranges.addStore(0, SI); 415 414 416 Function *MemSetF = 0;417 415 418 416 // Now that we have full information about ranges, loop over the ranges and … … 434 432 // instruction needed by the start of the block. 435 433 BasicBlock::iterator InsertPt = BI; 436 437 if (MemSetF == 0) { 438 const Type *Ty = Type::getInt64Ty(Context); 439 MemSetF = Intrinsic::getDeclaration(M, Intrinsic::memset, &Ty, 1); 440 } 441 434 442 435 // Get the starting pointer of the block. 443 436 StartPtr = Range.StartPtr; 444 437 438 // Determine alignment 439 unsigned Alignment = Range.Alignment; 440 if (Alignment == 0) { 441 const Type *EltType = 442 cast<PointerType>(StartPtr->getType())->getElementType(); 443 Alignment = TD->getABITypeAlignment(EltType); 444 } 445 445 446 // Cast the start ptr to be i8* as memset requires. 446 const Type *i8Ptr = Type::getInt8PtrTy(Context); 447 if (StartPtr->getType() != i8Ptr) 447 const PointerType* StartPTy = cast<PointerType>(StartPtr->getType()); 448 const PointerType *i8Ptr = Type::getInt8PtrTy(Context, 449 StartPTy->getAddressSpace()); 450 if (StartPTy!= i8Ptr) 448 451 StartPtr = new BitCastInst(StartPtr, i8Ptr, StartPtr->getName(), 449 452 InsertPt); 450 453 451 454 Value *Ops[] = { 452 455 StartPtr, ByteVal, // Start, value … … 454 457 ConstantInt::get(Type::getInt64Ty(Context), Range.End-Range.Start), 455 458 // align 456 ConstantInt::get(Type::getInt32Ty(Context), Range.Alignment) 459 ConstantInt::get(Type::getInt32Ty(Context), Alignment), 460 // volatile 461 ConstantInt::get(Type::getInt1Ty(Context), 0), 457 462 }; 458 Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt); 463 const Type *Tys[] = { Ops[0]->getType(), Ops[2]->getType() }; 464 465 Function *MemSetF = Intrinsic::getDeclaration(M, Intrinsic::memset, Tys, 2); 466 467 Value *C = CallInst::Create(MemSetF, Ops, Ops+5, "", InsertPt); 459 468 DEBUG(dbgs() << "Replace stores:\n"; 460 469 for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i) … … 500 509 Value *cpyDest = cpy->getDest(); 501 510 Value *cpySrc = cpy->getSource(); 502 CallSite CS = CallSite::get(C);511 CallSite CS(C); 503 512 504 513 // We need to be able to reason about the size of the memcpy, so we require … … 623 632 MD.removeInstruction(cpy); 624 633 cpy->eraseFromParent(); 625 NumMemCpyInstr++;634 ++NumMemCpyInstr; 626 635 627 636 return true; 628 637 } 629 638 630 /// processMemCpy - perform simplication of memcpy's. If we have memcpy A which 631 /// copies X to Y, and memcpy B which copies Y to Z, then we can rewrite B to be 632 /// a memcpy from X to Z (or potentially a memmove, depending on circumstances). 633 /// This allows later passes to remove the first memcpy altogether. 639 /// processMemCpy - perform simplification of memcpy's. If we have memcpy A 640 /// which copies X to Y, and memcpy B which copies Y to Z, then we can rewrite 641 /// B to be a memcpy from X to Z (or potentially a memmove, depending on 642 /// circumstances). This allows later passes to remove the first memcpy 643 /// altogether. 634 644 bool MemCpyOpt::processMemCpy(MemCpyInst *M) { 635 645 MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>(); … … 681 691 682 692 // If all checks passed, then we can transform these memcpy's 683 const Type *Ty = M->getLength()->getType(); 693 const Type *ArgTys[3] = { M->getRawDest()->getType(), 694 MDep->getRawSource()->getType(), 695 M->getLength()->getType() }; 684 696 Function *MemCpyFun = Intrinsic::getDeclaration( 685 697 M->getParent()->getParent()->getParent(), 686 M->getIntrinsicID(), &Ty, 1);698 M->getIntrinsicID(), ArgTys, 3); 687 699 688 Value *Args[4] = { 689 M->getRawDest(), MDep->getRawSource(), M->getLength(), M->getAlignmentCst() 700 Value *Args[5] = { 701 M->getRawDest(), MDep->getRawSource(), M->getLength(), 702 M->getAlignmentCst(), M->getVolatileCst() 690 703 }; 691 704 692 CallInst *C = CallInst::Create(MemCpyFun, Args, Args+ 4, "", M);705 CallInst *C = CallInst::Create(MemCpyFun, Args, Args+5, "", M); 693 706 694 707 … … 698 711 MD.removeInstruction(M); 699 712 M->eraseFromParent(); 700 NumMemCpyInstr++;713 ++NumMemCpyInstr; 701 714 return true; 702 715 } … … 729 742 // If not, then we know we can transform this. 730 743 Module *Mod = M->getParent()->getParent()->getParent(); 731 const Type *Ty = M->getLength()->getType(); 732 M->setOperand(0, Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, &Ty, 1)); 744 const Type *ArgTys[3] = { M->getRawDest()->getType(), 745 M->getRawSource()->getType(), 746 M->getLength()->getType() }; 747 M->setCalledFunction(Intrinsic::getDeclaration(Mod, Intrinsic::memcpy, 748 ArgTys, 3)); 733 749 734 750 // MemDep may have over conservative information about this instruction, just
Note:
See TracChangeset
for help on using the changeset viewer.