<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div><div>following is a patch that enables shared module pass registration on Windows with as little modification as possible, basically the pass can work, but other facilities may not because the static libray used in llvm and the static (should be global across DLL and exes)variables used in llvm, to make shared library fully functional, there are more work to done, but basically, the method present here should work.</div>
</div></div></blockquote><div><br></div><div>without touch the class template and method definitions, following is the only reimplementaion of the original passregistry.cpp header lines:</div><div><br></div><div>#include "llvm/PassRegistry.h"</div>
<div>#include "llvm/PassSupport.h"</div><div>#include "llvm/Support/Compiler.h"</div><div>#include "llvm/Support/ManagedStatic.h"</div><div>#include "llvm/Support/Mutex.h"</div><div>
#include "llvm/Support/DynamicLibrary.h"</div><div>#include "llvm/ADT/DenseMap.h"</div><div>#include "llvm/ADT/SmallPtrSet.h"</div><div>#include "llvm/ADT/StringMap.h"</div><div>#include <vector></div>
<div><br></div><div>using namespace llvm;</div><div><br></div><div>// FIXME: We use ManagedStatic to erase the pass registrar on shutdown.</div><div>// Unfortunately, passes are registered with static ctors, and having</div>
<div>// llvm_shutdown clear this map prevents successful ressurection after </div><div>// llvm_shutdown is run.  Ideally we should find a solution so that we don't</div><div>// leak the map, AND can still resurrect after shutdown.</div>
<div>#if defined(_WIN32)</div><div>  typedef PassRegistry* (*getPassRegistryPtr)();</div><div>  extern "C" __declspec(dllexport) </div><div>#endif</div><div>PassRegistry *llvmapi_getPassRegistryAddress() {</div>
<div>  static ManagedStatic<PassRegistry> PassRegistryObj;</div><div>  return &*PassRegistryObj;</div><div>}</div><div><br></div><div>PassRegistry *PassRegistry::getPassRegistry() {</div><div>  getPassRegistryPtr Ap = llvmapi_getPassRegistryAddress;</div>
<div>#if defined(_WIN32)</div><div>  static void *theAp = 0;</div><div>  if (theAp==0) {</div><div>    sys::DynamicLibrary::LoadLibraryPermanently(0);</div><div>    theAp = sys::DynamicLibrary::SearchForAddressOfSymbol("llvmapi_getPassRegistryAddress");</div>
<div>    if(!theAp) theAp = (void*)-1;</div><div>  }</div><div>  if (theAp!=(void*)-1) {</div><div>    Ap = (getPassRegistryPtr)theAp;</div><div>  }  </div><div>#endif</div><div>  return (*Ap)();</div><div>}</div><div> </div>
</div><br>