[vmkit-commits] [vmkit] r197341 - use a module pass manager instead of a functionpassmanager

Gael Thomas gael.thomas at lip6.fr
Sun Dec 15 04:24:20 PST 2013


Author: gthomas
Date: Sun Dec 15 06:24:20 2013
New Revision: 197341

URL: http://llvm.org/viewvc/llvm-project?rev=197341&view=rev
Log:
use a module pass manager instead of a functionpassmanager

Modified:
    vmkit/branches/mcjit/include/vmkit/compiler.h
    vmkit/branches/mcjit/include/vmkit/vmkit.h
    vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
    vmkit/branches/mcjit/lib/j3/vm/j3method.cc
    vmkit/branches/mcjit/lib/vmkit/compiler.cc
    vmkit/branches/mcjit/lib/vmkit/vmkit.cc

Modified: vmkit/branches/mcjit/include/vmkit/compiler.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/compiler.h?rev=197341&r1=197340&r2=197341&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/compiler.h (original)
+++ vmkit/branches/mcjit/include/vmkit/compiler.h Sun Dec 15 06:24:20 2013
@@ -9,6 +9,12 @@
 namespace llvm {
 	class Module;
 	class ExecutionEngine;
+
+	namespace legacy {
+		class PassManager;
+	}
+	using legacy::PassManager;
+
 };
 
 namespace vmkit {
@@ -25,19 +31,6 @@ namespace vmkit {
 		uint8_t* getSymbolAddress() { return addr; }
 	};
 
-#if 0
-	class CompilationFragment {
-		BumpAllocator*  _allocator;
-		llvm::Module*   _module;
-
-	public:
-		CompilationFragment(BumpAllocator* allocator);
-
-		BumpAllocator* allocator() { return _allocator; }
-		llvm::Module*  module() { return _module; }
-	};
-#endif
-
 	class CompilationUnit  : public llvm::SectionMemoryManager {
 		typedef std::map<const char*, Symbol*, Util::char_less_t, StdAllocator<std::pair<const char*, Symbol*> > > SymbolMap;
 
@@ -46,6 +39,7 @@ namespace vmkit {
 		pthread_mutex_t         _mutexSymbolTable;
 		llvm::ExecutionEngine*  _ee;
 		llvm::ExecutionEngine*  _oldee;
+		llvm::PassManager*      pm;
 
 	protected:
 		void  operator delete(void* self);
@@ -64,6 +58,8 @@ namespace vmkit {
 		BumpAllocator*          allocator() { return _allocator; }
 		llvm::ExecutionEngine*  ee() { return _ee; }
 		llvm::ExecutionEngine*  oldee() { return _oldee; }
+
+		void                    addModule(llvm::Module* module);
 	};
 }
 

Modified: vmkit/branches/mcjit/include/vmkit/vmkit.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/include/vmkit/vmkit.h?rev=197341&r1=197340&r2=197341&view=diff
==============================================================================
--- vmkit/branches/mcjit/include/vmkit/vmkit.h (original)
+++ vmkit/branches/mcjit/include/vmkit/vmkit.h Sun Dec 15 06:24:20 2013
@@ -13,10 +13,6 @@ namespace llvm {
 	class GlobalValue;
 	class Function;
 	class Type;
-	namespace legacy {
-		class FunctionPassManager;
-	}
-	using legacy::FunctionPassManager;
 }
 
 namespace vmkit {
@@ -75,7 +71,6 @@ namespace vmkit {
 		llvm::DataLayout*          dataLayout() { return _dataLayout; }
 		llvm::LLVMContext&         llvmContext();
 		llvm::Module*              self() { return _self; }
-		llvm::FunctionPassManager* preparePM(llvm::Module* mod);
 		llvm::Function*            getGCRoot(llvm::Module* mod);
 		llvm::Function*            introspectFunction(llvm::Module* dest, const char* name);
 		llvm::GlobalValue*         introspectGlobalValue(llvm::Module* dest, const char* name);

Modified: vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc?rev=197341&r1=197340&r2=197341&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3codegen.cc Sun Dec 15 06:24:20 2013
@@ -20,7 +20,6 @@
 
 #include "llvm/DebugInfo.h"
 #include "llvm/DIBuilder.h"
-#include "llvm/PassManager.h"
 
 using namespace j3;
 

Modified: vmkit/branches/mcjit/lib/j3/vm/j3method.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/j3/vm/j3method.cc?rev=197341&r1=197340&r2=197341&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/j3/vm/j3method.cc (original)
+++ vmkit/branches/mcjit/lib/j3/vm/j3method.cc Sun Dec 15 06:24:20 2013
@@ -7,8 +7,6 @@
 #include "j3/j3thread.h"
 #include "j3/j3codegen.h"
 
-#include "llvm/PassManager.h"
-
 #include "llvm/IR/Type.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Function.h"
@@ -61,10 +59,8 @@ uint8_t* J3Method::fnPtr() {
 
 		J3CodeGen::translate(this, _llvmFunction);
 
-		cl()->loader()->vm()->preparePM(module)->run(*_llvmFunction); /* TODO, check memory */
-
 		llvm::ExecutionEngine* ee = cl()->loader()->ee();
-		ee->addModule(module);
+		cl()->loader()->addModule(module);
 		_fnPtr = (uint8_t*)ee->getFunctionAddress(_llvmFunction->getName().data());
 	}
 

Modified: vmkit/branches/mcjit/lib/vmkit/compiler.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/compiler.cc?rev=197341&r1=197340&r2=197341&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/compiler.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/compiler.cc Sun Dec 15 06:24:20 2013
@@ -4,7 +4,11 @@
 #include "vmkit/thread.h"
 #include "vmkit/vmkit.h"
 
+#include "llvm/LinkAllPasses.h"
+#include "llvm/PassManager.h"
+
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
+
 #include "llvm/IR/Module.h"
 
 using namespace vmkit;
@@ -45,6 +49,42 @@ CompilationUnit::CompilationUnit(BumpAll
 		Thread::get()->vm()->internalError(L"Error while creating execution engine: %s\n", err.c_str());
 
 	oldee()->DisableLazyCompilation(0);
+
+	pm = new llvm::PassManager();
+	//pm->add(new llvm::TargetData(*ee->getTargetData()));
+
+	pm->add(llvm::createBasicAliasAnalysisPass());
+	
+	pm->add(llvm::createCFGSimplificationPass());      // Clean up disgusting code
+	pm->add(llvm::createPromoteMemoryToRegisterPass());// Kill useless allocas
+	pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl.
+	pm->add(llvm::createScalarReplAggregatesPass()); // Break up aggregate allocas
+	pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl.
+	pm->add(llvm::createJumpThreadingPass());        // Thread jumps.
+	pm->add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
+	pm->add(llvm::createInstructionCombiningPass()); // Combine silly seq's
+	pm->add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
+
+	pm->add(llvm::createReassociatePass());          // Reassociate expressions
+	pm->add(llvm::createLoopRotatePass());           // Rotate loops.
+	pm->add(llvm::createLICMPass());                 // Hoist loop invariants
+	pm->add(llvm::createLoopUnswitchPass());         // Unswitch loops.
+	pm->add(llvm::createInstructionCombiningPass());
+	pm->add(llvm::createIndVarSimplifyPass());       // Canonicalize indvars
+	pm->add(llvm::createLoopDeletionPass());         // Delete dead loops
+	pm->add(llvm::createLoopUnrollPass());           // Unroll small loops*/
+	pm->add(llvm::createInstructionCombiningPass()); // Clean up after the unroller
+	pm->add(llvm::createGVNPass());                  // Remove redundancies
+	pm->add(llvm::createMemCpyOptPass());            // Remove memcpy / form memset
+	pm->add(llvm::createSCCPPass());                 // Constant prop with SCCP
+
+	// Run instcombine after redundancy elimination to exploit opportunities
+	// opened up by them.
+	pm->add(llvm::createInstructionCombiningPass());
+	pm->add(llvm::createJumpThreadingPass());         // Thread jumps
+	pm->add(llvm::createDeadStoreEliminationPass());  // Delete dead stores
+	pm->add(llvm::createAggressiveDCEPass());         // Delete dead instructions
+	pm->add(llvm::createCFGSimplificationPass());     // Merge & remove BBs
 }
 
 CompilationUnit::~CompilationUnit() {
@@ -83,3 +123,8 @@ uint64_t CompilationUnit::getSymbolAddre
 	pthread_mutex_unlock(&_mutexSymbolTable);
 	return (uint64_t)(uintptr_t)res->getSymbolAddress();
 }
+
+void CompilationUnit::addModule(llvm::Module* module) {
+	pm->run(*module);
+	ee()->addModule(module);
+}

Modified: vmkit/branches/mcjit/lib/vmkit/vmkit.cc
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/mcjit/lib/vmkit/vmkit.cc?rev=197341&r1=197340&r2=197341&view=diff
==============================================================================
--- vmkit/branches/mcjit/lib/vmkit/vmkit.cc (original)
+++ vmkit/branches/mcjit/lib/vmkit/vmkit.cc Sun Dec 15 06:24:20 2013
@@ -8,12 +8,10 @@
 #include "vmkit/vmkit.h"
 #include "vmkit/thread.h"
 
-#include "llvm/LinkAllPasses.h"
-#include "llvm/PassManager.h"
-
 #include "llvm/IR/Module.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/DataLayout.h"
 
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 
@@ -118,48 +116,6 @@ llvm::Function* VMKit::getGCRoot(llvm::M
 	return llvm::Intrinsic::getDeclaration(mod, llvm::Intrinsic::gcroot);
 }
 
-llvm::FunctionPassManager* VMKit::preparePM(llvm::Module* mod) {
-	llvm::FunctionPassManager* pm = new llvm::FunctionPassManager(mod);
-	//pm->add(new llvm::TargetData(*ee->getTargetData()));
-
-	pm->add(llvm::createBasicAliasAnalysisPass());
-	
-	pm->add(llvm::createCFGSimplificationPass());      // Clean up disgusting code
-	pm->add(llvm::createPromoteMemoryToRegisterPass());// Kill useless allocas
-	pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl.
-	pm->add(llvm::createScalarReplAggregatesPass()); // Break up aggregate allocas
-	pm->add(llvm::createInstructionCombiningPass()); // Cleanup for scalarrepl.
-	pm->add(llvm::createJumpThreadingPass());        // Thread jumps.
-	pm->add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
-	pm->add(llvm::createInstructionCombiningPass()); // Combine silly seq's
-	pm->add(llvm::createCFGSimplificationPass());    // Merge & remove BBs
-
-	pm->add(llvm::createReassociatePass());          // Reassociate expressions
-	pm->add(llvm::createLoopRotatePass());           // Rotate loops.
-	pm->add(llvm::createLICMPass());                 // Hoist loop invariants
-	pm->add(llvm::createLoopUnswitchPass());         // Unswitch loops.
-	pm->add(llvm::createInstructionCombiningPass());
-	pm->add(llvm::createIndVarSimplifyPass());       // Canonicalize indvars
-	pm->add(llvm::createLoopDeletionPass());         // Delete dead loops
-	pm->add(llvm::createLoopUnrollPass());           // Unroll small loops*/
-	pm->add(llvm::createInstructionCombiningPass()); // Clean up after the unroller
-	pm->add(llvm::createGVNPass());                  // Remove redundancies
-	pm->add(llvm::createMemCpyOptPass());            // Remove memcpy / form memset
-	pm->add(llvm::createSCCPPass());                 // Constant prop with SCCP
-
-	// Run instcombine after redundancy elimination to exploit opportunities
-	// opened up by them.
-	pm->add(llvm::createInstructionCombiningPass());
-	pm->add(llvm::createJumpThreadingPass());         // Thread jumps
-	pm->add(llvm::createDeadStoreEliminationPass());  // Delete dead stores
-	pm->add(llvm::createAggressiveDCEPass());         // Delete dead instructions
-	pm->add(llvm::createCFGSimplificationPass());     // Merge & remove BBs
-
-	pm->doInitialization();
-
-	return pm;
-}
-
 void VMKit::NotifyFunctionEmitted(const llvm::Function &F,
 																	void *Code,
 																	size_t Size,





More information about the vmkit-commits mailing list