[polly] r198376 - Introduce -polly-canonicalize pass

Tobias Grosser tobias at grosser.es
Thu Jan 2 15:39:18 PST 2014


Author: grosser
Date: Thu Jan  2 17:39:18 2014
New Revision: 198376

URL: http://llvm.org/viewvc/llvm-project?rev=198376&view=rev
Log:
Introduce -polly-canonicalize pass

This ModulePass schedules the set of Polly canonicalization passes. It is a
debugging tool that can be used to preoptimize .ll files for Polly processing.

Added:
    polly/trunk/include/polly/Canonicalization.h   (with props)
    polly/trunk/lib/Canonicalization.cpp
Modified:
    polly/trunk/include/polly/LinkAllPasses.h
    polly/trunk/lib/CMakeLists.txt
    polly/trunk/lib/RegisterPasses.cpp
    polly/trunk/www/example_manual_matmul.html
    polly/trunk/www/experiments/matmul/runall.sh

Added: polly/trunk/include/polly/Canonicalization.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/Canonicalization.h?rev=198376&view=auto
==============================================================================
--- polly/trunk/include/polly/Canonicalization.h (added)
+++ polly/trunk/include/polly/Canonicalization.h Thu Jan  2 17:39:18 2014
@@ -0,0 +1,30 @@
+//===--- Canonicalization.h - The set of canonicalization passes------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef POLLY_CANONICALIZATION_H
+#define POLLY_CANONICALIZATION_H
+
+#include "llvm/PassManager.h"
+
+namespace polly {
+
+/// @brief Schedule a set of canonicalization passes to prepare for Polly
+///
+/// The set of optimization passes was partially taken/copied from the
+/// set of default optimization passes in LLVM. It is used to bring the code
+/// into a canonical form that simplifies the analysis and optimization passes
+/// of Polly. The set of optimization passes scheduled here is probably not yet
+/// optimal. TODO: Optimize the set of canonicalization passes.
+void registerCanonicalicationPasses(llvm::PassManagerBase &PM,
+                                    bool SCEVCodegen = false);
+
+}
+
+
+#endif

Propchange: polly/trunk/include/polly/Canonicalization.h
------------------------------------------------------------------------------
    svn:executable = *

Modified: polly/trunk/include/polly/LinkAllPasses.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/LinkAllPasses.h?rev=198376&r1=198375&r2=198376&view=diff
==============================================================================
--- polly/trunk/include/polly/LinkAllPasses.h (original)
+++ polly/trunk/include/polly/LinkAllPasses.h Thu Jan  2 17:39:18 2014
@@ -45,6 +45,7 @@ llvm::Pass *createJSONImporterPass();
 #ifdef PLUTO_FOUND
 llvm::Pass *createPlutoOptimizerPass();
 #endif
+llvm::Pass *createPollyCanonicalizePass();
 llvm::Pass *createScopDetectionPass();
 llvm::Pass *createScopInfoPass();
 llvm::Pass *createIslAstInfoPass();
@@ -100,6 +101,7 @@ struct PollyForcePassLinking {
 #ifdef PLUTO_FOUND
     createPlutoOptimizerPass();
 #endif
+    createPollyCanonicalizePass();
     createIslAstInfoPass();
     createIslCodeGenerationPass();
     createIslScheduleOptimizerPass();
@@ -134,6 +136,7 @@ void initializeIslScheduleOptimizerPass(
 #ifdef PLUTO_FOUND
 void initializePlutoOptimizerPass(llvm::PassRegistry &);
 #endif
+void initializePollyCanonicalizePass(llvm::PassRegistry &);
 #ifdef SCOPLIB_FOUND
 void initializePoccPass(llvm::PassRegistry &);
 #endif

Modified: polly/trunk/lib/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CMakeLists.txt?rev=198376&r1=198375&r2=198376&view=diff
==============================================================================
--- polly/trunk/lib/CMakeLists.txt (original)
+++ polly/trunk/lib/CMakeLists.txt Thu Jan  2 17:39:18 2014
@@ -24,6 +24,7 @@ set(LLVM_USED_LIBS
   )
 
 add_polly_loadable_module(LLVMPolly
+  Canonicalization.cpp
   CodePreparation.cpp
   DeadCodeElimination.cpp
   IndependentBlocks.cpp

Added: polly/trunk/lib/Canonicalization.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Canonicalization.cpp?rev=198376&view=auto
==============================================================================
--- polly/trunk/lib/Canonicalization.cpp (added)
+++ polly/trunk/lib/Canonicalization.cpp Thu Jan  2 17:39:18 2014
@@ -0,0 +1,86 @@
+//===---- Canonicalization.cpp - Run canonicalization passes ======-------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Run the set of default canonicalization passes.
+//
+// This pass is mainly used for debugging.
+//
+//===----------------------------------------------------------------------===//
+
+#include "polly/LinkAllPasses.h"
+#include "polly/Canonicalization.h"
+#include "llvm/Transforms/Scalar.h"
+
+using namespace llvm;
+using namespace polly;
+
+void polly::registerCanonicalicationPasses(llvm::PassManagerBase &PM,
+                                           bool SCEVCodegen) {
+  PM.add(llvm::createPromoteMemoryToRegisterPass());
+  PM.add(llvm::createPromoteMemoryToRegisterPass());
+  PM.add(llvm::createInstructionCombiningPass());
+  PM.add(llvm::createCFGSimplificationPass());
+  PM.add(llvm::createTailCallEliminationPass());
+  PM.add(llvm::createCFGSimplificationPass());
+  PM.add(llvm::createReassociatePass());
+  PM.add(llvm::createLoopRotatePass());
+  PM.add(llvm::createInstructionCombiningPass());
+
+  if (!SCEVCodegen)
+    PM.add(polly::createIndVarSimplifyPass());
+
+  PM.add(polly::createCodePreparationPass());
+}
+
+namespace {
+class PollyCanonicalize : public ModulePass {
+  PollyCanonicalize(const PollyCanonicalize &) LLVM_DELETED_FUNCTION;
+  const PollyCanonicalize &
+  operator=(const PollyCanonicalize &) LLVM_DELETED_FUNCTION;
+
+public:
+  static char ID;
+
+  explicit PollyCanonicalize() : ModulePass(ID) {}
+  ~PollyCanonicalize();
+
+  /// @name FunctionPass interface.
+  //@{
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
+  virtual void releaseMemory();
+  virtual bool runOnModule(Module &M);
+  virtual void print(raw_ostream &OS, const Module *) const;
+  //@}
+};
+}
+
+PollyCanonicalize::~PollyCanonicalize() {}
+
+void PollyCanonicalize::getAnalysisUsage(AnalysisUsage &AU) const {}
+
+void PollyCanonicalize::releaseMemory() {}
+
+bool PollyCanonicalize::runOnModule(Module &M) {
+  PassManager PM;
+  registerCanonicalicationPasses(PM);
+  PM.run(M);
+
+  return true;
+}
+
+void PollyCanonicalize::print(raw_ostream &OS, const Module *) const {}
+
+char PollyCanonicalize::ID = 0;
+
+Pass *polly::createPollyCanonicalizePass() { return new PollyCanonicalize(); }
+
+INITIALIZE_PASS_BEGIN(PollyCanonicalize, "polly-canonicalize",
+                      "Polly - Run canonicalization passes", false, false)
+INITIALIZE_PASS_END(PollyCanonicalize, "polly-canonicalize",
+                    "Polly - Run canonicalization passes", false, false)

Modified: polly/trunk/lib/RegisterPasses.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/RegisterPasses.cpp?rev=198376&r1=198375&r2=198376&view=diff
==============================================================================
--- polly/trunk/lib/RegisterPasses.cpp (original)
+++ polly/trunk/lib/RegisterPasses.cpp Thu Jan  2 17:39:18 2014
@@ -20,6 +20,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "polly/RegisterPasses.h"
+#include "polly/Canonicalization.h"
 #include "polly/CodeGen/BlockGenerators.h"
 #include "polly/CodeGen/Cloog.h"
 #include "polly/CodeGen/CodeGeneration.h"
@@ -172,6 +173,7 @@ static void initializePollyPasses(PassRe
   initializePoccPass(Registry);
 #endif
   initializePollyIndVarSimplifyPass(Registry);
+  initializePollyCanonicalizePass(Registry);
   initializeScopDetectionPass(Registry);
   initializeScopInfoPass(Registry);
   initializeTempScopInfoPass(Registry);
@@ -191,29 +193,6 @@ public:
 };
 static StaticInitializer InitializeEverything;
 
-/// @brief Schedule a set of canonicalization passes to prepare for Polly
-///
-/// The set of optimization passes was partially taken/copied from the
-/// set of default optimization passes in LLVM. It is used to bring the code
-/// into a canonical form that simplifies the analysis and optimization passes
-/// of Polly. The set of optimization passes scheduled here is probably not yet
-/// optimal. TODO: Optimize the set of canonicalization passes.
-static void registerCanonicalicationPasses(llvm::PassManagerBase &PM) {
-  PM.add(llvm::createPromoteMemoryToRegisterPass());
-  PM.add(llvm::createInstructionCombiningPass());
-  PM.add(llvm::createCFGSimplificationPass());
-  PM.add(llvm::createTailCallEliminationPass());
-  PM.add(llvm::createCFGSimplificationPass());
-  PM.add(llvm::createReassociatePass());
-  PM.add(llvm::createLoopRotatePass());
-  PM.add(llvm::createInstructionCombiningPass());
-
-  if (!SCEVCodegen)
-    PM.add(polly::createIndVarSimplifyPass());
-
-  PM.add(polly::createCodePreparationPass());
-}
-
 /// @brief Register Polly passes such that they form a polyhedral optimizer.
 ///
 /// The individual Polly passes are registered in the pass manager such that
@@ -245,7 +224,7 @@ static void registerCanonicalicationPass
 /// code generator. For the moment, the CLooG code generator is enabled by
 /// default.
 static void registerPollyPasses(llvm::PassManagerBase &PM) {
-  registerCanonicalicationPasses(PM);
+  registerCanonicalicationPasses(PM, SCEVCodegen);
 
   PM.add(polly::createScopInfoPass());
 

Modified: polly/trunk/www/example_manual_matmul.html
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/www/example_manual_matmul.html?rev=198376&r1=198375&r2=198376&view=diff
==============================================================================
--- polly/trunk/www/example_manual_matmul.html (original)
+++ polly/trunk/www/example_manual_matmul.html Thu Jan  2 17:39:18 2014
@@ -54,11 +54,9 @@ alias opt="opt -load ${PATH_TO_POLLY_LIB
 <li><h4>Prepare the LLVM-IR for Polly</h4>
 
 Polly is only able to work with code that matches a canonical form. To translate
-the LLVM-IR into this form we use a set of canonicalication passes. For this
-example only three passes are necessary. To get good coverage on more
-complicated input files often more canonicalization passes are needed. pollycc
-contains a list of passes that have shown to be beneficial.
-<pre class="code">opt -S -mem2reg -loop-simplify -polly-indvars matmul.s > matmul.preopt.ll</pre></li>
+the LLVM-IR into this form we use a set of canonicalication passes. They are
+scheduled by using '-polly-canonicalize'.
+<pre class="code">opt -S -polly-canonicalize matmul.s > matmul.preopt.ll</pre></li>
 
 <li><h4>Show the SCoPs detected by Polly (optional)</h4>
 

Modified: polly/trunk/www/experiments/matmul/runall.sh
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/www/experiments/matmul/runall.sh?rev=198376&r1=198375&r2=198376&view=diff
==============================================================================
--- polly/trunk/www/experiments/matmul/runall.sh (original)
+++ polly/trunk/www/experiments/matmul/runall.sh Thu Jan  2 17:39:18 2014
@@ -8,7 +8,7 @@ export PATH_TO_POLLY_LIB="~/polly/build/
 alias opt="opt -load ${PATH_TO_POLLY_LIB}/LLVMPolly.so"
 
 echo "--> 3. Prepare the LLVM-IR for Polly"
-opt -S -mem2reg -loop-simplify -polly-indvars matmul.s > matmul.preopt.ll
+opt -S -polly-canonicalize matmul.s > matmul.preopt.ll
 
 echo "--> 4. Show the SCoPs detected by Polly"
 opt -basicaa -polly-cloog -analyze -q matmul.preopt.ll





More information about the llvm-commits mailing list