[X86][Haswell][SchedModel] Add architecture specific scheduling models.
[oota-llvm.git] / lib / ExecutionEngine / JIT / JITEmitter.cpp
index 1e1f5d55802c58e5e039f41df89aab1a2aa59b51..2ba1f8695d7c9c195500a1a867edf14bfb189782 100644 (file)
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/IR/ValueMap.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Support/Disassembler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/Memory.h"
+#include "llvm/Support/MutexGuard.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetJITInfo.h"
@@ -49,7 +49,6 @@
 #ifndef NDEBUG
 #include <iomanip>
 #endif
-#include <mutex>
 using namespace llvm;
 
 #define DEBUG_TYPE "jit"
@@ -230,22 +229,22 @@ namespace {
     std::map<void*, JITResolver*> Map;
 
     /// Guards Map from concurrent accesses.
-    mutable std::recursive_mutex Lock;
+    mutable sys::Mutex Lock;
 
   public:
     /// Registers a Stub to be resolved by Resolver.
     void RegisterStubResolver(void *Stub, JITResolver *Resolver) {
-      std::lock_guard<std::recursive_mutex> guard(Lock);
+      MutexGuard guard(Lock);
       Map.insert(std::make_pair(Stub, Resolver));
     }
     /// Unregisters the Stub when it's invalidated.
     void UnregisterStubResolver(void *Stub) {
-      std::lock_guard<std::recursive_mutex> guard(Lock);
+      MutexGuard guard(Lock);
       Map.erase(Stub);
     }
     /// Returns the JITResolver instance that owns the Stub.
     JITResolver *getResolverFromStub(void *Stub) const {
-      std::lock_guard<std::recursive_mutex> guard(Lock);
+      MutexGuard guard(Lock);
       // The address given to us for the stub may not be exactly right, it might
       // be a little bit after the stub.  As such, use upper_bound to find it.
       // This is the same trick as in LookupFunctionFromCallSite from
@@ -258,7 +257,7 @@ namespace {
     /// True if any stubs refer to the given resolver. Only used in an assert().
     /// O(N)
     bool ResolverHasStubs(JITResolver* Resolver) const {
-      std::lock_guard<std::recursive_mutex> guard(Lock);
+      MutexGuard guard(Lock);
       for (std::map<void*, JITResolver*>::const_iterator I = Map.begin(),
              E = Map.end(); I != E; ++I) {
         if (I->second == Resolver)
@@ -494,7 +493,7 @@ JITResolver::~JITResolver() {
 /// getLazyFunctionStubIfAvailable - This returns a pointer to a function stub
 /// if it has already been created.
 void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
-  std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+  MutexGuard locked(TheJIT->lock);
 
   // If we already have a stub for this function, recycle it.
   return state.getFunctionToLazyStubMap().lookup(F);
@@ -503,7 +502,7 @@ void *JITResolver::getLazyFunctionStubIfAvailable(Function *F) {
 /// getFunctionStub - This returns a pointer to a function stub, creating
 /// one on demand as needed.
 void *JITResolver::getLazyFunctionStub(Function *F) {
-  std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+  MutexGuard locked(TheJIT->lock);
 
   // If we already have a lazy stub for this function, recycle it.
   void *&Stub = state.getFunctionToLazyStubMap()[F];
@@ -564,7 +563,7 @@ void *JITResolver::getLazyFunctionStub(Function *F) {
 /// getGlobalValueIndirectSym - Return a lazy pointer containing the specified
 /// GV address.
 void *JITResolver::getGlobalValueIndirectSym(GlobalValue *GV, void *GVAddress) {
-  std::lock_guard<std::recursive_mutex> guard(TheJIT->lock);
+  MutexGuard locked(TheJIT->lock);
 
   // If we already have a stub for this global variable, recycle it.
   void *&IndirectSym = state.getGlobalToIndirectSymMap()[GV];
@@ -622,7 +621,7 @@ void *JITResolver::JITCompilerFn(void *Stub) {
     // Only lock for getting the Function. The call getPointerToFunction made
     // in this function might trigger function materializing, which requires
     // JIT lock to be unlocked.
-    std::lock_guard<std::recursive_mutex> guard(JR->TheJIT->lock);
+    MutexGuard locked(JR->TheJIT->lock);
 
     // The address given to us for the stub may not be exactly right, it might
     // be a little bit after the stub.  As such, use upper_bound to find it.
@@ -654,7 +653,7 @@ void *JITResolver::JITCompilerFn(void *Stub) {
   }
 
   // Reacquire the lock to update the GOT map.
-  std::lock_guard<std::recursive_mutex> locked(JR->TheJIT->lock);
+  MutexGuard locked(JR->TheJIT->lock);
 
   // We might like to remove the call site from the CallSiteToFunction map, but
   // we can't do that! Multiple threads could be stuck, waiting to acquire the
@@ -929,11 +928,6 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
   MemMgr->setMemoryExecutable();
 
   DEBUG({
-      if (sys::hasDisassembler()) {
-        dbgs() << "JIT: Disassembled code:\n";
-        dbgs() << sys::disassembleBuffer(FnStart, FnEnd-FnStart,
-                                         (uintptr_t)FnStart);
-      } else {
         dbgs() << "JIT: Binary code:\n";
         uint8_t* q = FnStart;
         for (int i = 0; q < FnEnd; q += 4, ++i) {
@@ -955,7 +949,6 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
             dbgs() << '\n';
         }
         dbgs()<< '\n';
-      }
     });
 
   if (MMI)