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/Utils/SimplifyCFG.cpp

    r189 r319  
    225225      if (!AggressiveInsts) return false;
    226226      // Okay, it looks like the instruction IS in the "condition".  Check to
    227       // see if its a cheap instruction to unconditionally compute, and if it
     227      // see if it's a cheap instruction to unconditionally compute, and if it
    228228      // only uses stuff defined outside of the condition.  If so, hoist it out.
    229229      if (!I->isSafeToSpeculativelyExecute())
     
    950950    // Ignore any user that is not a PHI node in BB2.  These can only occur in
    951951    // unreachable blocks, because they would not be dominated by the instr.
    952     PHINode *PN = dyn_cast<PHINode>(UI);
     952    PHINode *PN = dyn_cast<PHINode>(*UI);
    953953    if (!PN || PN->getParent() != BB2)
    954954      return false;
     
    13781378  BasicBlock *BB = BI->getParent();
    13791379  Instruction *Cond = dyn_cast<Instruction>(BI->getCondition());
    1380   if (Cond == 0) return false;
    1381 
     1380  if (Cond == 0 || (!isa<CmpInst>(Cond) && !isa<BinaryOperator>(Cond)) ||
     1381    Cond->getParent() != BB || !Cond->hasOneUse())
     1382  return false;
    13821383 
    13831384  // Only allow this if the condition is a simple instruction that can be
     
    13881389  while(isa<DbgInfoIntrinsic>(FrontIt))
    13891390    ++FrontIt;
    1390   if ((!isa<CmpInst>(Cond) && !isa<BinaryOperator>(Cond)) ||
    1391       Cond->getParent() != BB || &*FrontIt != Cond || !Cond->hasOneUse()) {
     1391   
     1392  // Allow a single instruction to be hoisted in addition to the compare
     1393  // that feeds the branch.  We later ensure that any values that _it_ uses
     1394  // were also live in the predecessor, so that we don't unnecessarily create
     1395  // register pressure or inhibit out-of-order execution.
     1396  Instruction *BonusInst = 0;
     1397  if (&*FrontIt != Cond &&
     1398      FrontIt->hasOneUse() && *FrontIt->use_begin() == Cond &&
     1399      FrontIt->isSafeToSpeculativelyExecute()) {
     1400    BonusInst = &*FrontIt;
     1401    ++FrontIt;
     1402  }
     1403 
     1404  // Only a single bonus inst is allowed.
     1405  if (&*FrontIt != Cond)
    13921406    return false;
    1393   }
    13941407 
    13951408  // Make sure the instruction after the condition is the cond branch.
     
    14291442        !SafeToMergeTerminators(BI, PBI))
    14301443      continue;
     1444   
     1445    // Ensure that any values used in the bonus instruction are also used
     1446    // by the terminator of the predecessor.  This means that those values
     1447    // must already have been resolved, so we won't be inhibiting the
     1448    // out-of-order core by speculating them earlier.
     1449    if (BonusInst) {
     1450      // Collect the values used by the bonus inst
     1451      SmallPtrSet<Value*, 4> UsedValues;
     1452      for (Instruction::op_iterator OI = BonusInst->op_begin(),
     1453           OE = BonusInst->op_end(); OI != OE; ++OI) {
     1454        Value* V = *OI;
     1455        if (!isa<Constant>(V))
     1456          UsedValues.insert(V);
     1457      }
     1458
     1459      SmallVector<std::pair<Value*, unsigned>, 4> Worklist;
     1460      Worklist.push_back(std::make_pair(PBI->getOperand(0), 0));
     1461     
     1462      // Walk up to four levels back up the use-def chain of the predecessor's
     1463      // terminator to see if all those values were used.  The choice of four
     1464      // levels is arbitrary, to provide a compile-time-cost bound.
     1465      while (!Worklist.empty()) {
     1466        std::pair<Value*, unsigned> Pair = Worklist.back();
     1467        Worklist.pop_back();
     1468       
     1469        if (Pair.second >= 4) continue;
     1470        UsedValues.erase(Pair.first);
     1471        if (UsedValues.empty()) break;
     1472       
     1473        if (Instruction* I = dyn_cast<Instruction>(Pair.first)) {
     1474          for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
     1475               OI != OE; ++OI)
     1476            Worklist.push_back(std::make_pair(OI->get(), Pair.second+1));
     1477        }       
     1478      }
     1479     
     1480      if (!UsedValues.empty()) return false;
     1481    }
    14311482   
    14321483    Instruction::BinaryOps Opc;
     
    14581509    }
    14591510   
     1511    // If we have a bonus inst, clone it into the predecessor block.
     1512    Instruction *NewBonus = 0;
     1513    if (BonusInst) {
     1514      NewBonus = BonusInst->clone();
     1515      PredBlock->getInstList().insert(PBI, NewBonus);
     1516      NewBonus->takeName(BonusInst);
     1517      BonusInst->setName(BonusInst->getName()+".old");
     1518    }
     1519   
    14601520    // Clone Cond into the predecessor basic block, and or/and the
    14611521    // two conditions together.
    14621522    Instruction *New = Cond->clone();
     1523    if (BonusInst) New->replaceUsesOfWith(BonusInst, NewBonus);
    14631524    PredBlock->getInstList().insert(PBI, New);
    14641525    New->takeName(Cond);
     
    15141575      // predecessor, compute the PHI'd conditional value for all of the preds.
    15151576      // Any predecessor where the condition is not computable we keep symbolic.
    1516       for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
    1517         if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) &&
     1577      for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
     1578        BasicBlock *P = *PI;
     1579        if ((PBI = dyn_cast<BranchInst>(P->getTerminator())) &&
    15181580            PBI != BI && PBI->isConditional() &&
    15191581            PBI->getCondition() == BI->getCondition() &&
     
    15211583          bool CondIsTrue = PBI->getSuccessor(0) == BB;
    15221584          NewPN->addIncoming(ConstantInt::get(Type::getInt1Ty(BB->getContext()),
    1523                                               CondIsTrue), *PI);
     1585                                              CondIsTrue), P);
    15241586        } else {
    1525           NewPN->addIncoming(BI->getCondition(), *PI);
     1587          NewPN->addIncoming(BI->getCondition(), P);
    15261588        }
     1589      }
    15271590     
    15281591      BI->setCondition(NewPN);
     
    16621725  assert(BB && BB->getParent() && "Block not embedded in function!");
    16631726  assert(BB->getTerminator() && "Degenerate basic block encountered!");
    1664   assert(&BB->getParent()->getEntryBlock() != BB &&
    1665          "Can't Simplify entry block!");
    1666 
    1667   // Remove basic blocks that have no predecessors... or that just have themself
    1668   // as a predecessor.  These are unreachable.
    1669   if (pred_begin(BB) == pred_end(BB) || BB->getSinglePredecessor() == BB) {
     1727
     1728  // Remove basic blocks that have no predecessors (except the entry block)...
     1729  // or that just have themself as a predecessor.  These are unreachable.
     1730  if ((pred_begin(BB) == pred_end(BB) &&
     1731       &BB->getParent()->getEntryBlock() != BB) ||
     1732      BB->getSinglePredecessor() == BB) {
    16701733    DEBUG(dbgs() << "Removing BB: \n" << *BB);
    16711734    DeleteDeadBlock(BB);
     
    16981761      SmallVector<BranchInst*, 8> CondBranchPreds;
    16991762      for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) {
    1700         TerminatorInst *PTI = (*PI)->getTerminator();
     1763        BasicBlock *P = *PI;
     1764        TerminatorInst *PTI = P->getTerminator();
    17011765        if (BranchInst *BI = dyn_cast<BranchInst>(PTI)) {
    17021766          if (BI->isUnconditional())
    1703             UncondBranchPreds.push_back(*PI);
     1767            UncondBranchPreds.push_back(P);
    17041768          else
    17051769            CondBranchPreds.push_back(BI);
     
    17691833
    17701834          // Insert the call now.
    1771           SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
     1835          SmallVector<Value*,8> Args(II->op_begin(), II->op_end()-3);
    17721836          CallInst *CI = CallInst::Create(II->getCalledValue(),
    17731837                                          Args.begin(), Args.end(),
     
    18171881        ++BBI;
    18181882      if (BBI->isTerminator()) // Terminator is the only non-phi instruction!
    1819         if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
    1820           return true;
     1883        if (BB != &BB->getParent()->getEntryBlock())
     1884          if (TryToSimplifyUncondBranchFromEmptyBlock(BB))
     1885            return true;
    18211886     
    18221887    } else {  // Conditional branch
     
    18271892        if (BasicBlock *OnlyPred = BB->getSinglePredecessor())
    18281893          if (SimplifyEqualityComparisonWithOnlyPredecessor(BI, OnlyPred))
    1829             return SimplifyCFG(BB) || 1;
     1894            return SimplifyCFG(BB) | true;
    18301895
    18311896        // This block must be empty, except for the setcond inst, if it exists.
     
    18611926      // predecessor and use logical operations to pick the right destination.
    18621927      if (FoldBranchToCommonDest(BI))
    1863         return SimplifyCFG(BB) | 1;
     1928        return SimplifyCFG(BB) | true;
    18641929
    18651930
     
    19712036
    19722037            // Insert the call now...
    1973             SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
     2038            SmallVector<Value*, 8> Args(II->op_begin(), II->op_end()-3);
    19742039            CallInst *CI = CallInst::Create(II->getCalledValue(),
    19752040                                            Args.begin(), Args.end(),
     
    19772042            CI->setCallingConv(II->getCallingConv());
    19782043            CI->setAttributes(II->getAttributes());
    1979             // If the invoke produced a value, the Call does now instead.
     2044            // If the invoke produced a value, the call does now instead.
    19802045            II->replaceAllUsesWith(CI);
    19812046            delete II;
     
    19862051
    19872052      // If this block is now dead, remove it.
    1988       if (pred_begin(BB) == pred_end(BB)) {
     2053      if (pred_begin(BB) == pred_end(BB) &&
     2054          BB != &BB->getParent()->getEntryBlock()) {
    19892055        // We know there are no successors, so just nuke the block.
    19902056        M->getBasicBlockList().erase(BB);
    19912057        return true;
    19922058      }
     2059    }
     2060  } else if (IndirectBrInst *IBI =
     2061               dyn_cast<IndirectBrInst>(BB->getTerminator())) {
     2062    // Eliminate redundant destinations.
     2063    SmallPtrSet<Value *, 8> Succs;
     2064    for (unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
     2065      BasicBlock *Dest = IBI->getDestination(i);
     2066      if (!Dest->hasAddressTaken() || !Succs.insert(Dest)) {
     2067        Dest->removePredecessor(BB);
     2068        IBI->removeDestination(i);
     2069        --i; --e;
     2070        Changed = true;
     2071      }
     2072    }
     2073
     2074    if (IBI->getNumDestinations() == 0) {
     2075      // If the indirectbr has no successors, change it to unreachable.
     2076      new UnreachableInst(IBI->getContext(), IBI);
     2077      IBI->eraseFromParent();
     2078      Changed = true;
     2079    } else if (IBI->getNumDestinations() == 1) {
     2080      // If the indirectbr has one successor, change it to a direct branch.
     2081      BranchInst::Create(IBI->getDestination(0), IBI);
     2082      IBI->eraseFromParent();
     2083      Changed = true;
    19932084    }
    19942085  }
     
    20052096  // into our predecessor.
    20062097  pred_iterator PI(pred_begin(BB)), PE(pred_end(BB));
    2007   BasicBlock *OnlyPred = *PI++;
    2008   for (; PI != PE; ++PI)  // Search all predecessors, see if they are all same
    2009     if (*PI != OnlyPred) {
     2098  BasicBlock *OnlyPred = 0;
     2099  for (; PI != PE; ++PI) { // Search all predecessors, see if they are all same
     2100    if (!OnlyPred)
     2101      OnlyPred = *PI;
     2102    else if (*PI != OnlyPred) {
    20102103      OnlyPred = 0;       // There are multiple different predecessors...
    20112104      break;
    20122105    }
     2106  }
    20132107 
    20142108  if (OnlyPred)
     
    21092203/// of the CFG.  It returns true if a modification was made.
    21102204///
    2111 /// WARNING:  The entry node of a function may not be simplified.
    2112 ///
    21132205bool llvm::SimplifyCFG(BasicBlock *BB, const TargetData *TD) {
    21142206  return SimplifyCFGOpt(TD).run(BB);
Note: See TracChangeset for help on using the changeset viewer.