[llvm-commits] a windows pass registration patch

hume npx humeafo at gmail.com
Thu Jun 16 19:11:15 PDT 2011


---------- Forwarded message ----------
From: hume npx <humeafo at gmail.com>
Date: 2011/6/15
Subject: a windows pass registration patch
To: llvm-commits at cs.uiuc.edu


Is this the right place to commit the patch?
This patch make loadable pass on windows possible, because I'm new to llvm,
so it maybe incomplete, but the similar method can be implemented to support
windows loadable pass. the patch try not to break anything when not run on
windows, tested under msvc 10, under mingw should also work, this require
loadable pass module to define a macro when compiling, corresponding cmake
files is not corrected, but if this is accepted, I'd like to work on similar
problems.

------------------------------------------------------------------------------------------------------------------------

Index: include/llvm/PassRegistry.h

===================================================================

--- include/llvm/PassRegistry.h (revision 133049)

+++ include/llvm/PassRegistry.h (working copy)

@@ -41,7 +41,7 @@

   /// getPassRegistry - Access the global registry object, which is
   /// automatically initialized at application launch and destroyed by
   /// llvm_shutdown.
-  static PassRegistry *getPassRegistry();
+  static PassRegistry *getPassRegistry(bool sharedPass=false);

   /// getPassInfo - Look up a pass' corresponding PassInfo, indexed by the
pass'
   /// type identifier (&MyPass::ID).
Index: include/llvm/PassSupport.h

===================================================================

--- include/llvm/PassSupport.h (revision 133049)

+++ include/llvm/PassSupport.h (working copy)

@@ -194,7 +194,13 @@

 ///
 /// static RegisterPass<PassClassName> tmp("passopt", "My Name");
 ///
-template<typename passName>
+template<typename passName, bool bSharedPass=
+#if defined(_WIN32) && defined(LLVM_SHARED_PASS)
+  true
+#else
+  false
+#endif
+>
 struct RegisterPass : public PassInfo {

   // Register Pass using default constructor...
@@ -203,7 +209,7 @@

     : PassInfo(Name, PassArg, &passName::ID,
                PassInfo::NormalCtor_t(callDefaultCtor<passName>),
                CFGOnly, is_analysis) {
-    PassRegistry::getPassRegistry()->registerPass(*this);
+    PassRegistry::getPassRegistry(bSharedPass)->registerPass(*this);
   }
 };

Index: lib/VMCore/PassRegistry.cpp

===================================================================

--- lib/VMCore/PassRegistry.cpp (revision 133049)

+++ lib/VMCore/PassRegistry.cpp (working copy)

@@ -30,7 +30,29 @@

 // llvm_shutdown is run.  Ideally we should find a solution so that we
don't
 // leak the map, AND can still resurrect after shutdown.
 static ManagedStatic<PassRegistry> PassRegistryObj;
-PassRegistry *PassRegistry::getPassRegistry() {
+#if defined(_WIN32)
+  #include <tchar.h>
+  #include <windows.h>
+  typedef PassRegistry* (*getPassRegistryPortablePtr)();
+  extern "C" __declspec(dllexport) llvm::PassRegistry
*lapi_getPassRegistryPortable() {return &*PassRegistryObj;}
+#endif
+
+PassRegistry *PassRegistry::getPassRegistry(bool sharedPass) {
+#if defined(_WIN32)
+  std::vector<TCHAR> buf(MAX_PATH+1);
+  if (sharedPass) {
+    DWORD nSiz = GetModuleFileName(NULL, &buf[0], MAX_PATH);
+    if (nSiz) {
+      buf[nSiz] = 0;
+      HMODULE hMain = 0;
+      getPassRegistryPortablePtr pGetPassRegistryPortable = 0;
+      if ((hMain=LoadLibrary(&buf[0])) &&
+
 (pGetPassRegistryPortable=(getPassRegistryPortablePtr)GetProcAddress(hMain,
_T("lapi_getPassRegistryPortable")))) {
+            return (*pGetPassRegistryPortable)();
+      }
+    }
+  }
+#endif
   return &*PassRegistryObj;
 }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110617/53795b4f/attachment.html>


More information about the llvm-commits mailing list