diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2016-08-17 19:41:29 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2016-08-17 19:41:29 +0000 | 
| commit | 6c4bc1bd2772d4db151a13576558e1320c7c3b65 (patch) | |
| tree | 06f8f3845db41aed4b2b4228d561c3f3b5a09563 /contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp | |
| parent | 4bb0738ee7438ed572a4b9d8b609271b029de5b8 (diff) | |
| parent | a7fe922b98bb45be7dce7c1cfe668ec27eeddc74 (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp')
| -rw-r--r-- | contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp | 35 | 
1 files changed, 33 insertions, 2 deletions
diff --git a/contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp b/contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp index c5ca56360fc8..4f1052d81433 100644 --- a/contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/contrib/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -14,6 +14,7 @@  //===----------------------------------------------------------------------===//  #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/ADT/SetVector.h"  #include "llvm/ADT/SmallVector.h"  #include "llvm/Analysis/ConstantFolding.h"  #include "llvm/Analysis/InstructionSimplify.h" @@ -552,9 +553,39 @@ void llvm::CloneAndPruneIntoFromInst(Function *NewFunc, const Function *OldFunc,    // two PHINodes, the iteration over the old PHIs remains valid, and the    // mapping will just map us to the new node (which may not even be a PHI    // node). +  const DataLayout &DL = NewFunc->getParent()->getDataLayout(); +  SmallSetVector<const Value *, 8> Worklist;    for (unsigned Idx = 0, Size = PHIToResolve.size(); Idx != Size; ++Idx) -    if (PHINode *PN = dyn_cast<PHINode>(VMap[PHIToResolve[Idx]])) -      recursivelySimplifyInstruction(PN); +    if (isa<PHINode>(VMap[PHIToResolve[Idx]])) +      Worklist.insert(PHIToResolve[Idx]); + +  // Note that we must test the size on each iteration, the worklist can grow. +  for (unsigned Idx = 0; Idx != Worklist.size(); ++Idx) { +    const Value *OrigV = Worklist[Idx]; +    auto *I = dyn_cast_or_null<Instruction>(VMap.lookup(OrigV)); +    if (!I) +      continue; + +    // See if this instruction simplifies. +    Value *SimpleV = SimplifyInstruction(I, DL); +    if (!SimpleV) +      continue; + +    // Stash away all the uses of the old instruction so we can check them for +    // recursive simplifications after a RAUW. This is cheaper than checking all +    // uses of To on the recursive step in most cases. +    for (const User *U : OrigV->users()) +      Worklist.insert(cast<Instruction>(U)); + +    // Replace the instruction with its simplified value. +    I->replaceAllUsesWith(SimpleV); + +    // If the original instruction had no side effects, remove it. +    if (isInstructionTriviallyDead(I)) +      I->eraseFromParent(); +    else +      VMap[OrigV] = I; +  }    // Now that the inlined function body has been fully constructed, go through    // and zap unconditional fall-through branches. This happens all the time when  | 
