[llvm-commits] [llvm] r122719 - in /llvm/trunk: include/llvm/InitializePasses.h include/llvm/Transforms/Scalar.h lib/Transforms/Scalar/CMakeLists.txt lib/Transforms/Scalar/LoopInstSimplify.cpp lib/Transforms/Scalar/Scalar.cpp
Cameron Zwarich
zwarich at apple.com
Sun Jan 2 16:25:16 PST 2011
Author: zwarich
Date: Sun Jan 2 18:25:16 2011
New Revision: 122719
URL: http://llvm.org/viewvc/llvm-project?rev=122719&view=rev
Log:
Add a new loop-instsimplify pass, with the intention of replacing the instance
of instcombine that is currently in the middle of the loop pass pipeline. This
commit only checks in the pass; it will hopefully be enabled by default later.
Added:
llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
Modified:
llvm/trunk/include/llvm/InitializePasses.h
llvm/trunk/include/llvm/Transforms/Scalar.h
llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt
llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
Modified: llvm/trunk/include/llvm/InitializePasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=122719&r1=122718&r2=122719&view=diff
==============================================================================
--- llvm/trunk/include/llvm/InitializePasses.h (original)
+++ llvm/trunk/include/llvm/InitializePasses.h Sun Jan 2 18:25:16 2011
@@ -128,6 +128,7 @@
void initializeLoopDependenceAnalysisPass(PassRegistry&);
void initializeLoopExtractorPass(PassRegistry&);
void initializeLoopInfoPass(PassRegistry&);
+void initializeLoopInstSimplifyPass(PassRegistry&);
void initializeLoopRotatePass(PassRegistry&);
void initializeLoopSimplifyPass(PassRegistry&);
void initializeLoopSplitterPass(PassRegistry&);
Modified: llvm/trunk/include/llvm/Transforms/Scalar.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar.h?rev=122719&r1=122718&r2=122719&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Scalar.h (original)
+++ llvm/trunk/include/llvm/Transforms/Scalar.h Sun Jan 2 18:25:16 2011
@@ -119,6 +119,12 @@
//===----------------------------------------------------------------------===//
//
+// LoopInstSimplify - This pass simplifies instructions in a loop's body.
+//
+Pass *createLoopInstSimplifyPass();
+
+//===----------------------------------------------------------------------===//
+//
// LoopUnroll - This pass is a simple loop unrolling pass.
//
Pass *createLoopUnrollPass();
Modified: llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt?rev=122719&r1=122718&r2=122719&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt (original)
+++ llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt Sun Jan 2 18:25:16 2011
@@ -13,6 +13,7 @@
LICM.cpp
LoopDeletion.cpp
LoopIdiomRecognize.cpp
+ LoopInstSimplify.cpp
LoopRotation.cpp
LoopStrengthReduce.cpp
LoopUnrollPass.cpp
Added: llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp?rev=122719&view=auto
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp (added)
+++ llvm/trunk/lib/Transforms/Scalar/LoopInstSimplify.cpp Sun Jan 2 18:25:16 2011
@@ -0,0 +1,112 @@
+//===- LoopInstSimplify.cpp - Loop Instruction Simplification Pass --------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass performs lightweight instruction simplification on loop bodies.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "loop-instsimplify"
+#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/Dominators.h"
+#include "llvm/Analysis/InstructionSimplify.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/Local.h"
+#include "llvm/ADT/Statistic.h"
+using namespace llvm;
+
+STATISTIC(NumSimplified, "Number of redundant instructions simplified");
+
+namespace {
+ class LoopInstSimplify : public LoopPass {
+ public:
+ static char ID; // Pass ID, replacement for typeid
+ LoopInstSimplify() : LoopPass(ID) {
+ initializeLoopInstSimplifyPass(*PassRegistry::getPassRegistry());
+ }
+
+ bool runOnLoop(Loop*, LPPassManager&);
+
+ virtual void getAnalysisUsage(AnalysisUsage& AU) const {
+ AU.setPreservesCFG();
+ AU.addRequired<DominatorTree>();
+ AU.addPreserved<DominatorTree>();
+ AU.addRequired<LoopInfo>();
+ AU.addPreserved<LoopInfo>();
+ AU.addPreservedID(LCSSAID);
+ }
+ };
+}
+
+char LoopInstSimplify::ID = 0;
+INITIALIZE_PASS_BEGIN(LoopInstSimplify, "loop-instsimplify",
+ "Simplify instructions in loops", false, false)
+INITIALIZE_PASS_DEPENDENCY(DominatorTree)
+INITIALIZE_PASS_DEPENDENCY(LoopInfo)
+INITIALIZE_PASS_DEPENDENCY(LCSSA)
+INITIALIZE_PASS_END(LoopInstSimplify, "loop-instsimplify",
+ "Simplify instructions in loops", false, false)
+
+Pass* llvm::createLoopInstSimplifyPass() {
+ return new LoopInstSimplify();
+}
+
+bool LoopInstSimplify::runOnLoop(Loop* L, LPPassManager& LPM) {
+ DominatorTree* DT = &getAnalysis<DominatorTree>();
+ const LoopInfo* LI = &getAnalysis<LoopInfo>();
+ const TargetData* TD = getAnalysisIfAvailable<TargetData>();
+
+ bool Changed = false;
+ bool LocalChanged;
+ 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;) {
+ Instruction* I = BI++;
+ // Don't bother simplifying unused instructions.
+ if (!I->use_empty()) {
+ if (Value* V = SimplifyInstruction(I, TD, DT)) {
+ I->replaceAllUsesWith(V);
+ LocalChanged = true;
+ ++NumSimplified;
+ }
+ }
+ 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);
+ }
+ }
+ } while (LocalChanged);
+
+ // Nothing that SimplifyInstruction() does should invalidate LCSSA form.
+ assert(L->isLCSSAForm(*DT));
+
+ return Changed;
+}
Modified: llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Scalar.cpp?rev=122719&r1=122718&r2=122719&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Scalar.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Scalar.cpp Sun Jan 2 18:25:16 2011
@@ -41,6 +41,7 @@
initializeJumpThreadingPass(Registry);
initializeLICMPass(Registry);
initializeLoopDeletionPass(Registry);
+ initializeLoopInstSimplifyPass(Registry);
initializeLoopRotatePass(Registry);
initializeLoopStrengthReducePass(Registry);
initializeLoopUnrollPass(Registry);
More information about the llvm-commits
mailing list