[opengtl-commits] [311] introduce the Optimiser class to control the level of optimisation of a code generated by OpenGTL |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 311
Author: cyrille
Date: 2008-08-04 09:04:45 +0200 (Mon, 04 Aug 2008)
Log Message:
-----------
introduce the Optimiser class to control the level of optimisation of a code generated by OpenGTL
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
Added Paths:
-----------
trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h
trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp
trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h
Property Changed:
----------------
trunk/OpenGTL/
Property changes on: trunk/OpenGTL
___________________________________________________________________
Name: svn:ignore
- Doxyfile
OpenGTL.kdevelop
OpenGTL.kdevelop.filelist
OpenGTL.kdevelop.pcs
OpenGTL.kdevses
OpenGTL.kdevelop.ignore_pcs
OpenGTL.tag
+ Doxyfile
OpenGTL.kdevelop
OpenGTL.kdevelop.filelist
OpenGTL.kdevelop.pcs
OpenGTL.kdevses
OpenGTL.kdevelop.ignore_pcs
OpenGTL.tag
..kdev4
OpenGTL.kdev4
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp 2008-08-01 08:41:36 UTC (rev 310)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/compiler/Compiler.cpp 2008-08-04 07:04:45 UTC (rev 311)
@@ -37,10 +37,6 @@
#include <llvm/System/DynamicLibrary.h>
// Passes
#include <llvm/PassManager.h>
-#include <llvm/Analysis/LoopPass.h>
-#include <llvm/Analysis/LoadValueNumbering.h>
-#include <llvm/Analysis/Verifier.h>
-#include <llvm/Target/TargetData.h>
#include "LexerNG.h"
#include "ParserNG.h"
@@ -60,6 +56,7 @@
#include "GTLCore/ScopedName.h"
#include "GTLCore/Type.h"
#include "GTLCore/Type_p.h"
+#include "GTLCore/Optimiser_p.h"
using namespace OpenCTL;
@@ -188,14 +185,9 @@
}
OCTL_DEBUG( *d->module );
// Success
- // Optimization taken from the Stacker example
- llvm::PassManager Passes;
- // Add in the passes we want to execute
- Passes.add(new llvm::TargetData(d->module));
- // Verify we start with valid
- Passes.add(llvm::createVerifierPass());
- // Run
- Passes.run(*d->module);
+
+ GTLCore::Optimiser::instance()->d->passManager()->run( *d->module );
+
} else {
// Failure
OCTL_DEBUG("failure " << (*errorMessages().begin()).line() << ": " << (*errorMessages().begin()).errorMessage());
Modified: trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt 2008-08-01 08:41:36 UTC (rev 310)
+++ trunk/OpenGTL/OpenGTL/GTLCore/CMakeLists.txt 2008-08-04 07:04:45 UTC (rev 311)
@@ -16,6 +16,7 @@
Debug.cpp
ErrorMessage.cpp
Function.cpp
+ Optimiser.cpp
Parameter.cpp
PixelDescription.cpp
Region.cpp
@@ -45,6 +46,7 @@
GenerationContext_p.cpp
LexerBase_p.cpp
ModuleData_p.cpp
+ Optimiser_p.cpp
ParserBase_p.cpp
Token_p.cpp
Type_p.cpp
Added: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.cpp (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.cpp 2008-08-04 07:04:45 UTC (rev 311)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "Optimiser.h"
+
+#include "Optimiser_p.h"
+
+using namespace GTLCore;
+
+Optimiser::Optimiser() : d(new Private )
+{
+}
+
+Optimiser::~Optimiser()
+{
+}
+
+Optimiser* Optimiser::instance()
+{
+ return Private::s_instance;
+}
+
+void Optimiser::setLevel(int _level)
+{
+ d->setLevel( _level );
+}
+
Added: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser.h 2008-08-04 07:04:45 UTC (rev 311)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPTIMISER_H_
+#define _OPTIMISER_H_
+
+namespace OpenCTL {
+ class Compiler;
+}
+
+namespace GTLCore {
+ class Optimiser{
+ friend class OpenCTL::Compiler;
+ private:
+ Optimiser();
+ ~Optimiser();
+ public:
+ static Optimiser* instance();
+ /**
+ * Set the level of optimisation.
+ * @param _level from 0 to 3 (0 means no optimisation)
+ */
+ void setLevel(int _level);
+ private:
+ class Private;
+ Private* const d;
+ };
+}
+
+#endif
Added: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.cpp 2008-08-04 07:04:45 UTC (rev 311)
@@ -0,0 +1,129 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "Optimiser_p.h"
+
+#include <llvm/PassManager.h>
+#include <llvm/Analysis/LoopPass.h>
+#include <llvm/Analysis/LoadValueNumbering.h>
+#include <llvm/Analysis/Verifier.h>
+
+using namespace GTLCore;
+
+Optimiser* Optimiser::Private::s_instance = new Optimiser;
+
+Optimiser::Private::Private() : m_passManager(0)
+{
+}
+
+Optimiser::Private::~Private()
+{
+ delete m_passManager;
+}
+
+llvm::PassManager* Optimiser::Private::passManager()
+{
+ if(not m_passManager)
+ {
+ m_passManager = new llvm::PassManager;
+ m_passManager->add( llvm::createVerifierPass() );
+ }
+ return m_passManager;
+}
+
+void Optimiser::Private::setLevel( int _level )
+{
+ delete m_passManager;
+ m_passManager = 0;
+}
+
+
+#if 0
+
+ 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
Added: trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h
===================================================================
--- trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h (rev 0)
+++ trunk/OpenGTL/OpenGTL/GTLCore/Optimiser_p.h 2008-08-04 07:04:45 UTC (rev 311)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2 of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _OPTIMISER_P_H_
+#define _OPTIMISER_P_H_
+
+#include "Optimiser.h"
+
+namespace llvm {
+ class PassManager;
+}
+
+namespace GTLCore {
+ class Optimiser::Private {
+ friend class Optimiser;
+ public:
+ Private();
+ ~Private();
+ llvm::PassManager* passManager();
+ void setLevel( int _level );
+ private:
+ llvm::PassManager* m_passManager;
+ static Optimiser* s_instance;
+ };
+}
+
+#endif