[llvm-commits] [llvm] r122791 - /llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp

Chris Lattner clattner at apple.com
Mon Jan 3 17:58:01 PST 2011


On Jan 3, 2011, at 4:12 PM, Cameron Zwarich wrote:

> Author: zwarich
> Date: Mon Jan  3 18:12:46 2011
> New Revision: 122791
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=122791&view=rev
> Log:
> Address most of Duncan's review comments. Also, make LoopInstSimplify a simple
> FunctionPass. It probably doesn't have a reason to be a LoopPass, as it will
> probably drop the simple fixed point and either use RPO iteration or Duncan's
> approach in instsimplify of only revisiting instructions that have changed.

Hi Cameron,

If it's not a loop pass, it won't be pipelined along with the other loop passes, right?

-Chris

> 
> The next step is to preserve LoopSimplify. This looks like it won't be too hard,
> although the pass manager doesn't actually seem to respect when non-loop passes
> claim to preserve LCSSA or LoopSimplify. This will have to be fixed.
> 
> Modified:
>    llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
> 
> Modified: llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp?rev=122791&r1=122790&r2=122791&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp Mon Jan  3 18:12:46 2011
> @@ -12,9 +12,11 @@
> //===----------------------------------------------------------------------===//
> 
> #define DEBUG_TYPE "loop-instsimplify"
> -#include "llvm/Analysis/LoopPass.h"
> +#include "llvm/Function.h"
> +#include "llvm/Pass.h"
> #include "llvm/Analysis/Dominators.h"
> #include "llvm/Analysis/InstructionSimplify.h"
> +#include "llvm/Analysis/LoopInfo.h"
> #include "llvm/Target/TargetData.h"
> #include "llvm/Transforms/Scalar.h"
> #include "llvm/Transforms/Utils/Local.h"
> @@ -24,19 +26,17 @@
> STATISTIC(NumSimplified, "Number of redundant instructions simplified");
> 
> namespace {
> -  class LoopInstSimplify : public LoopPass {
> +  class LoopInstSimplify : public FunctionPass {
>   public:
>     static char ID; // Pass ID, replacement for typeid
> -    LoopInstSimplify() : LoopPass(ID) {
> +    LoopInstSimplify() : FunctionPass(ID) {
>       initializeLoopInstSimplifyPass(*PassRegistry::getPassRegistry());
>     }
> 
> -    bool runOnLoop(Loop*, LPPassManager&);
> +    bool runOnFunction(Function&);
> 
>     virtual void getAnalysisUsage(AnalysisUsage& AU) const {
>       AU.setPreservesCFG();
> -      AU.addRequired<DominatorTree>();
> -      AU.addPreserved<DominatorTree>();
>       AU.addRequired<LoopInfo>();
>       AU.addPreserved<LoopInfo>();
>       AU.addPreservedID(LCSSAID);
> @@ -57,9 +57,9 @@
>   return new LoopInstSimplify();
> }
> 
> -bool LoopInstSimplify::runOnLoop(Loop* L, LPPassManager& LPM) {
> -  DominatorTree* DT = &getAnalysis<DominatorTree>();
> -  const LoopInfo* LI = &getAnalysis<LoopInfo>();
> +bool LoopInstSimplify::runOnFunction(Function& F) {
> +  DominatorTree* DT = getAnalysisIfAvailable<DominatorTree>();
> +  LoopInfo* LI = &getAnalysis<LoopInfo>();
>   const TargetData* TD = getAnalysisIfAvailable<TargetData>();
> 
>   bool Changed = false;
> @@ -67,24 +67,14 @@
>   do {
>     LocalChanged = false;
> 
> -    SmallPtrSet<BasicBlock*, 32> Visited;
> -    SmallVector<BasicBlock*, 32> VisitStack;
> -
> -    VisitStack.push_back(L->getHeader());
> -
> -    while (!VisitStack.empty()) {
> -      BasicBlock* BB = VisitStack.back();
> -      VisitStack.pop_back();
> -
> -      if (Visited.count(BB))
> -        continue;
> -      Visited.insert(BB);
> -
> -      for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
> +    for (df_iterator<BasicBlock*> DI = df_begin(&F.getEntryBlock()),
> +         DE = df_end(&F.getEntryBlock()); DI != DE; ++DI)
> +      for (BasicBlock::iterator BI = DI->begin(), BE = DI->end(); BI != BE;) {
>         Instruction* I = BI++;
>         // Don't bother simplifying unused instructions.
>         if (!I->use_empty()) {
> -          if (Value* V = SimplifyInstruction(I, TD, DT)) {
> +          Value* V = SimplifyInstruction(I, TD, DT);
> +          if (V && LI->replacementPreservesLCSSAForm(I, V)) {
>             I->replaceAllUsesWith(V);
>             LocalChanged = true;
>             ++NumSimplified;
> @@ -92,21 +82,9 @@
>         }
>         LocalChanged |= RecursivelyDeleteTriviallyDeadInstructions(I);
>       }
> -      Changed |= LocalChanged;
> 
> -      DomTreeNode* Node = DT->getNode(BB);
> -      const std::vector<DomTreeNode*>& Children = Node->getChildren();
> -      for (unsigned i = 0; i < Children.size(); ++i) {
> -        // Only visit children that are in the same loop.
> -        BasicBlock* ChildBB = Children[i]->getBlock();
> -        if (!Visited.count(ChildBB) && LI->getLoopFor(ChildBB) == L)
> -          VisitStack.push_back(ChildBB);
> -      }
> -    }
> +    Changed |= LocalChanged;
>   } while (LocalChanged);
> 
> -  // Nothing that SimplifyInstruction() does should invalidate LCSSA form.
> -  assert(L->isLCSSAForm(*DT));
> -
>   return Changed;
> }
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list