[opengtl-commits] [313] implements call to optimization (level >= 2 start breaking tests)

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 313
Author:   cyrille
Date:     2008-08-04 10:21:27 +0200 (Mon, 04 Aug 2008)

Log Message:
-----------
implements call to optimization (level >= 2 start breaking tests)

Modified Paths:
--------------
    trunk/OpenGTL/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
    trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h
    trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp
    trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h
    trunk/OpenGTL/cmake/modules/FindLLVM.cmake


Modified: trunk/OpenGTL/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/CMakeLists.txt	2008-08-04 07:08:08 UTC (rev 312)
+++ trunk/OpenGTL/CMakeLists.txt	2008-08-04 08:21:27 UTC (rev 313)
@@ -2,6 +2,9 @@
 
 cmake_minimum_required(VERSION 2.4)
 
+cmake_policy(VERSION 2.4)
+
+
 set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
 
 enable_testing()

Modified: trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt	2008-08-04 07:08:08 UTC (rev 312)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt	2008-08-04 08:21:27 UTC (rev 313)
@@ -1,7 +1,7 @@
 add_subdirectory(tests)
 
 # Find llvm jit, interpreter and native
-FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "native bitwriter linker bitreader jit interpreter support" LLVM_LIBS LLVM_NATIVE_OBJECTS )
+FIND_LLVM_LIBS( ${LLVM_CONFIG_EXECUTABLE} "native bitwriter linker bitreader jit interpreter support ipo" LLVM_LIBS LLVM_NATIVE_OBJECTS )
 
 include_directories( ${LLVM_INCLUDE_DIR} )
 

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h	2008-08-04 07:08:08 UTC (rev 312)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h	2008-08-04 08:21:27 UTC (rev 313)
@@ -24,9 +24,14 @@
   class Compiler;
 }
 
+namespace OpenShiva {
+  class Compiler;
+}
+
 namespace GTLCore {
   class Optimiser{
     friend class OpenCTL::Compiler;
+    friend class OpenShiva::Compiler;
     private:
       Optimiser();
       ~Optimiser();
@@ -34,7 +39,7 @@
       static Optimiser* instance();
       /**
        * Set the level of optimisation.
-       * @param _level from 0 to 3 (0 means no optimisation)
+       * @param _level from 0 to 4 (0 means no optimisation, 4 is aggressive optimisation)
        */
       void setLevel(int _level);
     private:

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp	2008-08-04 07:08:08 UTC (rev 312)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp	2008-08-04 08:21:27 UTC (rev 313)
@@ -23,13 +23,59 @@
 #include <llvm/Analysis/LoopPass.h>
 #include <llvm/Analysis/LoadValueNumbering.h>
 #include <llvm/Analysis/Verifier.h>
+#include "llvm/Assembly/Parser.h"
+#include "llvm/Transforms/IPO.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Target/TargetData.h"
 
+#include "Debug.h"
+
 using namespace GTLCore;
 
+struct PassInfo {
+    String passName;
+    String passDescription;
+    int level;
+    llvm::Pass* (*creator)();
+};
+
+static const PassInfo infos[] = {
+    { "CFGSimplification", "Clean up disgusting code", 2, (llvm::Pass* (*)())(llvm::createCFGSimplificationPass) },
+//     { "GlobalDCE", "Remove unused globals", 2, (llvm::Pass* (*)())(llvm::createGlobalDCEPass) },
+    { "IPConstantPropagation", "IP Constant Propagation", 2, (llvm::Pass* (*)())(llvm::createIPConstantPropagationPass) },
+    { "InstructionCombining", "Clean up after IPCP", 2, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "CFGSimplification", "Clean up after IPCP", 2, (llvm::Pass* (*)())(llvm::createCFGSimplificationPass) },
+//     { "FunctionInlining", "Inline small definitions (functions)", 2, (llvm::Pass* (*)())(llvm::createFunctionInliningPass) },
+    { "TailDuplication", "Simplify cfg by copying code", 2, (llvm::Pass* (*)())(llvm::createTailDuplicationPass) },
+    { "CFGSimplification", "Merge & remove BBs", 3, (llvm::Pass* (*)())(llvm::createCFGSimplificationPass) },
+    { "InstructionCombining", "Compile silly sequences", 3, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "Reassociate", "Reassociate expressions", 3, (llvm::Pass* (*)())(llvm::createReassociatePass) },
+    { "InstructionCombining", "Combine silly sequences", 3, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "TailCallElimination", "Eliminate tail calls", 3, (llvm::Pass* (*)())(llvm::createTailCallEliminationPass) },
+    { "CFGSimplification", "Merge & remove BBs", 3, (llvm::Pass* (*)())(llvm::createCFGSimplificationPass) },
+    { "LICM", "Hoist loop invariants", 3, (llvm::Pass* (*)())(llvm::createLICMPass) },
+    { "InstructionCombining", "Clean up after the unroller", 3, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "IndVarSimplify", "Canonicalize indvars", 3, (llvm::Pass* (*)())(llvm::createIndVarSimplifyPass) },
+    { "LoopUnroll", "Unroll small loops", 3, (llvm::Pass* (*)())(llvm::createLoopUnrollPass) },
+    { "InstructionCombining", "Clean up after the unroller", 3, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "LoadValueNumbering", "GVN for load instructions", 3, (llvm::Pass* (*)())(llvm::createLoadValueNumberingPass) },
+    { "GCSE", "Remove common subexprs", 3, (llvm::Pass* (*)())(llvm::createGCSEPass) },
+    { "SCCP", "Constant prop with SCCP", 3, (llvm::Pass* (*)())(llvm::createSCCPPass) },
+    { "InstructionCombining", "Run instcombine again after redundancy elimination", 4, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "DeadStoreElimination", "Delete dead stores", 4, (llvm::Pass* (*)())(llvm::createDeadStoreEliminationPass) },
+    { "AggressiveDCE", "SSA based 'Aggressive DCE'", 4, (llvm::Pass* (*)())(llvm::createAggressiveDCEPass) },
+    { "CFGSimplification", "Merge & remove BBs", 4, (llvm::Pass* (*)())(llvm::createCFGSimplificationPass) },
+    { "ConstantMerge", "Merge dup global constants", 4, (llvm::Pass* (*)())(llvm::createConstantMergePass) },
+    { "CFGSimplification", "Merge & remove BBs", 1, (llvm::Pass* (*)())(llvm::createCFGSimplificationPass) },
+    { "PromoteMemoryToRegister", "Memory To Register", 1, (llvm::Pass* (*)())(llvm::createPromoteMemoryToRegisterPass) },
+    { "InstructionCombining", "Compile silly sequences", 1, (llvm::Pass* (*)())(llvm::createInstructionCombiningPass) },
+    { "", "", -1, 0 } };
+    
 Optimiser* Optimiser::Private::s_instance = new Optimiser;
 
 Optimiser::Private::Private() : m_passManager(0)
 {
+  setLevel( 1 );
 }
 
 Optimiser::Private::~Private()
@@ -42,88 +88,45 @@
   if(not m_passManager)
   {
     m_passManager = new llvm::PassManager;
+    m_passManager->add( new llvm::TargetData("") );
     m_passManager->add( llvm::createVerifierPass() );
+    for(int i = 0; infos[i].passName != ""; ++i)
+    {
+      GTL_DEBUG( infos[i].passName );
+      if( isActive( infos[i].passName ) )
+      {
+        m_passManager->add( infos[i].creator() );
+      }
+    }
+    m_passManager->add( llvm::createVerifierPass() );
   }
+  GTL_DEBUG("Finished pass manager");
   return m_passManager;
 }
 
 void Optimiser::Private::setLevel( int _level )
 {
-  delete m_passManager;
-  m_passManager = 0;
+  for(int i = 0; infos[i].passName != ""; ++i)
+  {
+    GTL_DEBUG( i << " " << infos[i].passName );
+    setActive( infos[i].passName, infos[i].level <= _level );
+  }
 }
 
 
-#if 0
+bool Optimiser::Private::isActive(const String& _passName ) const
+{
+  std::map<String, bool>::const_iterator it = m_passActivity.find( _passName );
+  if( it == m_passActivity.end() )
+  {
+    return false;;
+  }
+  return it->second;
+}
 
-        if (optLevel > 0) {
-            if (optLevel > 1) {
-                // Clean up disgusting code
-                Passes.add(createCFGSimplificationPass());
-                // Remove unused globals
-                Passes.add(createGlobalDCEPass());
-                // IP Constant Propagation
-                Passes.add(createIPConstantPropagationPass());
-                // Clean up after IPCP
-                Passes.add(createInstructionCombiningPass());
-                // Clean up after IPCP
-                Passes.add(createCFGSimplificationPass());
-                // Inline small definitions (functions)
-                Passes.add(createFunctionInliningPass());
-                // Simplify cfg by copying code
-                Passes.add(createTailDuplicationPass());
-                if (optLevel > 2) {
-                    // Merge & remove BBs
-                    Passes.add(createCFGSimplificationPass());
-                    // Compile silly sequences
-                    Passes.add(createInstructionCombiningPass());
-                    // Reassociate expressions
-                    Passes.add(createReassociatePass());
-                    // Combine silly seq's
-                    Passes.add(createInstructionCombiningPass());
-                    // Eliminate tail calls
-                    Passes.add(createTailCallEliminationPass());
-                    // Merge & remove BBs
-                    Passes.add(createCFGSimplificationPass());
-                    // Hoist loop invariants
-                    Passes.add(createLICMPass());
-                    // Clean up after the unroller
-                    Passes.add(createInstructionCombiningPass());
-                    // Canonicalize indvars
-                    Passes.add(createIndVarSimplifyPass());
-                    // Unroll small loops
-                    Passes.add(createLoopUnrollPass());
-                    // Clean up after the unroller
-                    Passes.add(createInstructionCombiningPass());
-                    // GVN for load instructions
-                    Passes.add(createLoadValueNumberingPass());
-                    // Remove common subexprs
-                    Passes.add(createGCSEPass());
-                    // Constant prop with SCCP
-                    Passes.add(createSCCPPass());
-                }
-                if (optLevel > 3) {
-                    // Run instcombine again after redundancy elimination
-                    Passes.add(createInstructionCombiningPass());
-                    // Delete dead stores
-                    Passes.add(createDeadStoreEliminationPass());
-                    // SSA based 'Aggressive DCE'
-                    Passes.add(createAggressiveDCEPass());
-                    // Merge & remove BBs
-                    Passes.add(createCFGSimplificationPass());
-                    // Merge dup global constants
-                    Passes.add(createConstantMergePass());
-                }
-            }
-
-            // Merge & remove BBs
-            Passes.add(createCFGSimplificationPass());
-            // Memory To Register
-            Passes.add(createPromoteMemoryToRegisterPass());
-            // Compile silly sequences
-            Passes.add(createInstructionCombiningPass());
-            // Make sure everything is still good.
-            Passes.add(createVerifierPass());
-        }
-
-#endif
+void Optimiser::Private::setActive(const String& _passName, bool _active )
+{
+  delete m_passManager;
+  m_passManager = 0;
+  m_passActivity[_passName] = _active;
+}

Modified: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h	2008-08-04 07:08:08 UTC (rev 312)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h	2008-08-04 08:21:27 UTC (rev 313)
@@ -22,6 +22,10 @@
 
 #include "Optimiser.h"
 
+#include <map>
+
+#include "String.h"
+
 namespace llvm {
   class PassManager;
 }
@@ -34,8 +38,11 @@
       ~Private();
       llvm::PassManager* passManager();
       void setLevel( int _level );
+      bool isActive(const String& _passName ) const;
+      void setActive(const String& _passName, bool _active );
     private:
       llvm::PassManager* m_passManager;
+      std::map<String, bool> m_passActivity;
       static Optimiser* s_instance;
   };
 }

Modified: trunk/OpenGTL/cmake/modules/FindLLVM.cmake
===================================================================
--- trunk/OpenGTL/cmake/modules/FindLLVM.cmake	2008-08-04 07:08:08 UTC (rev 312)
+++ trunk/OpenGTL/cmake/modules/FindLLVM.cmake	2008-08-04 08:21:27 UTC (rev 313)
@@ -20,9 +20,10 @@
   
   MACRO(FIND_LLVM_LIBS LLVM_CONFIG_EXECUTABLE _libname_ LIB_VAR OBJECT_VAR)
     exec_program( perl ARGS ${LLVM_CONFIG_EXECUTABLE} --libs ${_libname_}  OUTPUT_VARIABLE ${LIB_VAR} )
-    STRING(REGEX MATCHALL "[^ ]*.o[ $]"  ${OBJECT_VAR} ${${LIB_VAR}})
+    set( ${LIB_VAR} " ${${LIB_VAR}}" )
+    STRING(REGEX MATCHALL "[^ ]*[.]o[ $]"  ${OBJECT_VAR} ${${LIB_VAR}})
     SEPARATE_ARGUMENTS(${OBJECT_VAR})
-    STRING(REGEX REPLACE "[^ ]*.o[ $]" ""  ${LIB_VAR} ${${LIB_VAR}})
+    STRING(REGEX REPLACE "[^ ]*[.]o[ $]" ""  ${LIB_VAR} ${${LIB_VAR}})
   ENDMACRO(FIND_LLVM_LIBS)
   
   


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/