[llvm-commits] [llvm] r73701 - /llvm/trunk/lib/VMCore/Pass.cpp

Duncan Sands baldrick at free.fr
Fri Jun 19 01:42:45 PDT 2009


Hi Owen, does sys::MemoryFence compile to nothing if
!llvm_is_multithreaded?  On SMP machines memory fences
can be expensive, so using it when not actually needed
could be costly.  So best to avoid it if LLVM is not
running multithreaded.  Since the new memory barrier you
added only has to happen before returning PassRegistrarObj,
I guess you could do something like this:

   PassRegistrar* tmp = PassRegistrarObj;
   if (llvm_is_multithreaded()) {
     sys::MemoryFence();
     if (!tmp) {
       llvm_acquire_global_lock();
       tmp = PassRegistrarObj;
       if (!tmp) {
         tmp = new PassRegistrar();
         sys::MemoryFence();
         PassRegistrarObj = tmp;
       }
       llvm_release_global_lock();
     }
   } else if (!tmp) {
     PassRegistrarObj = tmp = new PassRegistrar();
   }
   return tmp;

Ciao,

Duncan.



More information about the llvm-commits mailing list