Ignore:
Timestamp:
Apr 19, 2011, 11:12:07 PM (14 years ago)
Author:
Yuri Dario
Message:

clamav: update trunk to 0.97.

Location:
clamav/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • clamav/trunk

  • TabularUnified clamav/trunk/libclamav/c++/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

    r189 r319  
    305305  public:
    306306    static char ID; // Pass identification, replacement for typeid
    307     MemCpyOpt() : FunctionPass(&ID) {}
     307    MemCpyOpt() : FunctionPass(ID) {}
    308308
    309309  private:
     
    332332FunctionPass *llvm::createMemCpyOptPass() { return new MemCpyOpt(); }
    333333
    334 static RegisterPass<MemCpyOpt> X("memcpyopt",
    335                                  "MemCpy Optimization");
     334INITIALIZE_PASS(MemCpyOpt, "memcpyopt", "MemCpy Optimization", false, false);
    336335
    337336
     
    375374      // allow readonly here because we don't want something like:
    376375      // 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)) ==
    378377            AliasAnalysis::DoesNotAccessMemory)
    379378        continue;
     
    414413  Ranges.addStore(0, SI);
    415414 
    416   Function *MemSetF = 0;
    417415 
    418416  // Now that we have full information about ranges, loop over the ranges and
     
    434432    // instruction needed by the start of the block.
    435433    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
    442435    // Get the starting pointer of the block.
    443436    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
    445446    // 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)
    448451      StartPtr = new BitCastInst(StartPtr, i8Ptr, StartPtr->getName(),
    449452                                 InsertPt);
    450  
     453
    451454    Value *Ops[] = {
    452455      StartPtr, ByteVal,   // Start, value
     
    454457      ConstantInt::get(Type::getInt64Ty(Context), Range.End-Range.Start),
    455458      // 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),
    457462    };
    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);
    459468    DEBUG(dbgs() << "Replace stores:\n";
    460469          for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i)
     
    500509  Value *cpyDest = cpy->getDest();
    501510  Value *cpySrc = cpy->getSource();
    502   CallSite CS = CallSite::get(C);
     511  CallSite CS(C);
    503512
    504513  // We need to be able to reason about the size of the memcpy, so we require
     
    623632  MD.removeInstruction(cpy);
    624633  cpy->eraseFromParent();
    625   NumMemCpyInstr++;
     634  ++NumMemCpyInstr;
    626635
    627636  return true;
    628637}
    629638
    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.
    634644bool MemCpyOpt::processMemCpy(MemCpyInst *M) {
    635645  MemoryDependenceAnalysis &MD = getAnalysis<MemoryDependenceAnalysis>();
     
    681691 
    682692  // 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() };
    684696  Function *MemCpyFun = Intrinsic::getDeclaration(
    685697                                 M->getParent()->getParent()->getParent(),
    686                                  M->getIntrinsicID(), &Ty, 1);
     698                                 M->getIntrinsicID(), ArgTys, 3);
    687699   
    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()
    690703  };
    691704 
    692   CallInst *C = CallInst::Create(MemCpyFun, Args, Args+4, "", M);
     705  CallInst *C = CallInst::Create(MemCpyFun, Args, Args+5, "", M);
    693706 
    694707 
     
    698711    MD.removeInstruction(M);
    699712    M->eraseFromParent();
    700     NumMemCpyInstr++;
     713    ++NumMemCpyInstr;
    701714    return true;
    702715  }
     
    729742  // If not, then we know we can transform this.
    730743  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));
    733749
    734750  // MemDep may have over conservative information about this instruction, just
Note: See TracChangeset for help on using the changeset viewer.