[llvm-commits] [polly] r149386 - in /polly/trunk: include/polly/LinkAllPasses.h lib/CMakeLists.txt lib/DeadCodeElimination.cpp lib/RegisterPasses.cpp

Tobias Grosser grosser at fim.uni-passau.de
Tue Jan 31 06:00:27 PST 2012


Author: grosser
Date: Tue Jan 31 08:00:27 2012
New Revision: 149386

URL: http://llvm.org/viewvc/llvm-project?rev=149386&view=rev
Log:
Add a sceleton for a polyhedral dead code elimination.

Such a dead code elimination can remove redundant stores to arrays. It can also
eliminate calculations where the results are stored to memory but where they are
overwritten before ever being read. It may also fix bugs like:
http://llvm.org/bugs/show_bug.cgi?id=5117

This commit just adds a sceleton without any functionality.

If anybody is interested to learn about polyhedral optimizations this would be
a good task. Well definined, self contained and pretty simple. Ping me if you
want to start and you need some pointers to get going.

Added:
    polly/trunk/lib/DeadCodeElimination.cpp
Modified:
    polly/trunk/include/polly/LinkAllPasses.h
    polly/trunk/lib/CMakeLists.txt
    polly/trunk/lib/RegisterPasses.cpp

Modified: polly/trunk/include/polly/LinkAllPasses.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/LinkAllPasses.h?rev=149386&r1=149385&r2=149386&view=diff
==============================================================================
--- polly/trunk/include/polly/LinkAllPasses.h (original)
+++ polly/trunk/include/polly/LinkAllPasses.h Tue Jan 31 08:00:27 2012
@@ -33,6 +33,7 @@
   Pass *createCloogInfoPass();
   Pass *createCodeGenerationPass();
   Pass *createCodePreparationPass();
+  Pass *createDeadCodeElimPass();
   Pass *createDependencesPass();
   Pass *createDOTOnlyPrinterPass();
   Pass *createDOTOnlyViewerPass();
@@ -79,6 +80,7 @@
        createCloogInfoPass();
        createCodeGenerationPass();
        createCodePreparationPass();
+       createDeadCodeElimPass();
        createDependencesPass();
        createDOTOnlyPrinterPass();
        createDOTOnlyViewerPass();
@@ -111,6 +113,7 @@
   class PassRegistry;
   void initializeCodeGenerationPass(llvm::PassRegistry&);
   void initializeCodePreparationPass(llvm::PassRegistry&);
+  void initializeDeadCodeElimPass(llvm::PassRegistry&);
   void initializeIndependentBlocksPass(llvm::PassRegistry&);
   void initializeJSONExporterPass(llvm::PassRegistry&);
   void initializeJSONImporterPass(llvm::PassRegistry&);

Modified: polly/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CMakeLists.txt?rev=149386&r1=149385&r2=149386&view=diff
==============================================================================
--- polly/trunk/lib/CMakeLists.txt (original)
+++ polly/trunk/lib/CMakeLists.txt Tue Jan 31 08:00:27 2012
@@ -21,6 +21,7 @@
   Cloog.cpp
   CodePreparation.cpp
   CodeGeneration.cpp
+  DeadCodeElimination.cpp
   IndependentBlocks.cpp
   MayAliasSet.cpp
   Pocc.cpp

Added: polly/trunk/lib/DeadCodeElimination.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/DeadCodeElimination.cpp?rev=149386&view=auto
==============================================================================
--- polly/trunk/lib/DeadCodeElimination.cpp (added)
+++ polly/trunk/lib/DeadCodeElimination.cpp Tue Jan 31 08:00:27 2012
@@ -0,0 +1,75 @@
+//===- DeadCodeElimination.cpp - Eliminate dead iteration  ----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// If values calculated within an iteration are not used later on the iteration
+// can be removed entirely. This pass removes such iterations.
+//===----------------------------------------------------------------------===//
+
+#include "polly/Dependences.h"
+#include "polly/LinkAllPasses.h"
+#include "polly/ScopInfo.h"
+
+#include "isl/union_map.h"
+
+using namespace llvm;
+using namespace polly;
+
+namespace {
+
+  class DeadCodeElim : public ScopPass {
+
+  public:
+    static char ID;
+    explicit DeadCodeElim() : ScopPass(ID) {}
+
+    virtual bool runOnScop(Scop &S);
+    void printScop(llvm::raw_ostream &OS) const;
+    void getAnalysisUsage(AnalysisUsage &AU) const;
+  };
+}
+
+char DeadCodeElim::ID = 0;
+
+bool DeadCodeElim::runOnScop(Scop &S) {
+  Dependences *D = &getAnalysis<Dependences>();
+
+  int dependencyKinds = Dependences::TYPE_RAW
+                          | Dependences::TYPE_WAR
+                          | Dependences::TYPE_WAW;
+
+  isl_union_map *dependences = D->getDependences(dependencyKinds);
+
+  // The idea of this pass is to loop over all statments and remove statement
+  // iterations that do not calculate any value that is read later on. We need
+  // to make sure to forward RAR and WAR dependences.
+  //
+  // A case where this pass might be useful is
+  // http://llvm.org/bugs/show_bug.cgi?id=5117
+  isl_union_map_free(dependences);
+  return false;
+}
+
+void DeadCodeElim::printScop(raw_ostream &OS) const {
+}
+
+void DeadCodeElim::getAnalysisUsage(AnalysisUsage &AU) const {
+  ScopPass::getAnalysisUsage(AU);
+  AU.addRequired<Dependences>();
+}
+
+INITIALIZE_PASS_BEGIN(DeadCodeElim, "polly-dce",
+                      "Polly - Remove dead iterations", false, false)
+INITIALIZE_PASS_DEPENDENCY(Dependences)
+INITIALIZE_PASS_DEPENDENCY(ScopInfo)
+INITIALIZE_PASS_END(DeadCodeElim, "polly-dce",
+                      "Polly - Remove dead iterations", false, false)
+
+Pass* polly::createDeadCodeElimPass() {
+  return new DeadCodeElim();
+}

Modified: polly/trunk/lib/RegisterPasses.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/RegisterPasses.cpp?rev=149386&r1=149385&r2=149386&view=diff
==============================================================================
--- polly/trunk/lib/RegisterPasses.cpp (original)
+++ polly/trunk/lib/RegisterPasses.cpp Tue Jan 31 08:00:27 2012
@@ -61,6 +61,12 @@
        cl::desc("Enable the Polly DOT viewer in -O3"), cl::Hidden,
        cl::value_desc("Run the Polly DOT viewer at -O3"),
        cl::init(false));
+
+static cl::opt<bool>
+DeadCodeElim("polly-run-dce",
+             cl::desc("Run the dead code elimination"),
+             cl::Hidden, cl::init(false));
+
 static cl::opt<bool>
 PollyOnlyViewer("polly-show-only",
        cl::desc("Enable the Polly DOT viewer in -O3 (no BB content)"),
@@ -83,6 +89,7 @@
   initializeCloogInfoPass(Registry);
   initializeCodeGenerationPass(Registry);
   initializeCodePreparationPass(Registry);
+  initializeDeadCodeElimPass(Registry);
   initializeDependencesPass(Registry);
   initializeIndependentBlocksPass(Registry);
   initializeJSONExporterPass(Registry);
@@ -161,6 +168,9 @@
   if (ImportJScop)
     PM.add(polly::createJSONImporterPass());
 
+  if (DeadCodeElim)
+    PM.add(polly::createDeadCodeElimPass());
+
   if (RunScheduler) {
     if (Optimizer == "pocc") {
 #ifdef SCOPLIB_FOUND





More information about the llvm-commits mailing list