swr/rast: Debug Symbols work
authorGeorge Kyriazis <george.kyriazis@intel.com>
Fri, 19 Jan 2018 21:47:00 +0000 (15:47 -0600)
committerGeorge Kyriazis <george.kyriazis@intel.com>
Fri, 19 Jan 2018 22:52:30 +0000 (16:52 -0600)
Added support for Fetch / Sample / LD functions
Added DLL link to JitCache implementation

Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp

index 2b993613f535f6ac28659273c3094ca31ca2f9ae..a3bda616f956cb6fee02fd3397f00c380eb63e92 100644 (file)
@@ -104,7 +104,7 @@ JitManager::JitManager(uint32_t simdWidth, const char *arch, const char* core)
 
     if (KNOB_JIT_ENABLE_CACHE)
     {
-        mCache.SetCpu(hostCPUName);
+        mCache.Init(this, hostCPUName);
         mpExec->setObjectCache(&mCache);
     }
 
@@ -474,7 +474,7 @@ struct JitCacheFileHeader
     uint64_t GetBufferCRC() const { return m_objCRC; }
 
 private:
-    static const uint64_t   JC_MAGIC_NUMBER = 0xfedcba9876543211ULL;
+    static const uint64_t   JC_MAGIC_NUMBER = 0xfedcba9876543211ULL + 1;
     static const size_t     JC_STR_MAX_LEN = 32;
     static const uint32_t   JC_PLATFORM_KEY =
         (LLVM_VERSION_MAJOR << 24)  |
@@ -522,6 +522,45 @@ JitCache::JitCache()
     }
 }
 
+#if defined(_WIN32)
+int ExecUnhookedProcess(const char* pCmdLine)
+{
+    static const char *g_pEnv = "RASTY_DISABLE_HOOK=1\0";
+
+    STARTUPINFOA StartupInfo{};
+    StartupInfo.cb = sizeof(STARTUPINFOA);
+    PROCESS_INFORMATION procInfo{};
+
+    BOOL ProcessValue = CreateProcessA(
+        NULL,
+        (LPSTR)pCmdLine,
+        NULL,
+        NULL,
+        TRUE,
+        0,
+        (LPVOID)g_pEnv,
+        NULL,
+        &StartupInfo,
+        &procInfo);
+
+    if (ProcessValue && procInfo.hProcess)
+    {
+        WaitForSingleObject(procInfo.hProcess, INFINITE);
+        DWORD exitVal = 0;
+        if (!GetExitCodeProcess(procInfo.hProcess, &exitVal))
+        {
+            exitVal = 1;
+        }
+
+        CloseHandle(procInfo.hProcess);
+
+        return exitVal;
+    }
+
+    return -1;
+}
+#endif
+
 /// notifyObjectCompiled - Provides a pointer to compiled code for Module M.
 void JitCache::notifyObjectCompiled(const llvm::Module *M, llvm::MemoryBufferRef Obj)
 {
@@ -541,24 +580,28 @@ void JitCache::notifyObjectCompiled(const llvm::Module *M, llvm::MemoryBufferRef
     llvm::SmallString<MAX_PATH> filePath = mCacheDir;
     llvm::sys::path::append(filePath, moduleID);
 
-    std::error_code err;
-    llvm::raw_fd_ostream fileObj(filePath.c_str(), err, llvm::sys::fs::F_None);
+    {
+        std::error_code err;
+        llvm::raw_fd_ostream fileObj(filePath.c_str(), err, llvm::sys::fs::F_None);
+
+        uint32_t objcrc = ComputeCRC(0, Obj.getBufferStart(), Obj.getBufferSize());
 
-    uint32_t objcrc = ComputeCRC(0, Obj.getBufferStart(), Obj.getBufferSize());
+        JitCacheFileHeader header;
+        header.Init(mCurrentModuleCRC, objcrc, moduleID, mCpu, Obj.getBufferSize());
 
-    JitCacheFileHeader header;
-    header.Init(mCurrentModuleCRC, objcrc, moduleID, mCpu, Obj.getBufferSize());
+        fileObj.write((const char*)&header, sizeof(header));
+        fileObj.flush();
+    }
 
-    fileObj.write((const char*)&header, sizeof(header));
-    fileObj << Obj.getBuffer();
-    fileObj.flush();
+    filePath += JIT_OBJ_EXT;
+
+    {
+        std::error_code err;
+        llvm::raw_fd_ostream fileObj(filePath.c_str(), err, llvm::sys::fs::F_None);
+        fileObj << Obj.getBuffer();
+        fileObj.flush();
+    }
 
-    llvm::SmallString<MAX_PATH> filePath2 = filePath;
-    filePath2 += ".obj";
-    
-    llvm::raw_fd_ostream fileObj2(filePath2.c_str(), err, llvm::sys::fs::F_None);
-    fileObj2 << Obj.getBuffer();
-    fileObj2.flush();
 }
 
 /// Returns a pointer to a newly allocated MemoryBuffer that contains the
@@ -582,6 +625,10 @@ std::unique_ptr<llvm::MemoryBuffer> JitCache::getObject(const llvm::Module* M)
     llvm::SmallString<MAX_PATH> filePath = mCacheDir;
     llvm::sys::path::append(filePath, moduleID);
 
+    llvm::SmallString<MAX_PATH> objFilePath = filePath;
+    objFilePath += JIT_OBJ_EXT;
+
+    FILE* fpObjIn = nullptr;
     FILE* fpIn = fopen(filePath.c_str(), "rb");
     if (!fpIn)
     {
@@ -602,12 +649,18 @@ std::unique_ptr<llvm::MemoryBuffer> JitCache::getObject(const llvm::Module* M)
             break;
         }
 
+        fpObjIn = fopen(objFilePath.c_str(), "rb");
+        if (!fpObjIn)
+        {
+            break;
+        }
+
 #if LLVM_VERSION_MAJOR < 6
         pBuf = llvm::MemoryBuffer::getNewUninitMemBuffer(size_t(header.GetBufferSize()));
 #else
         pBuf = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(size_t(header.GetBufferSize()));
 #endif
-        if (!fread(const_cast<char*>(pBuf->getBufferStart()), header.GetBufferSize(), 1, fpIn))
+        if (!fread(const_cast<char*>(pBuf->getBufferStart()), header.GetBufferSize(), 1, fpObjIn))
         {
             pBuf = nullptr;
             break;
@@ -623,5 +676,10 @@ std::unique_ptr<llvm::MemoryBuffer> JitCache::getObject(const llvm::Module* M)
 
     fclose(fpIn);
 
+    if (fpObjIn)
+    {
+        fclose(fpObjIn);
+    }
+
     return pBuf;
 }
index 4cf2214fd6fa509780a0c37de8437b0a54f30cd9..fb20a36625d4a2b4bfe12f77f4ad84c4eb1ce1d4 100644 (file)
@@ -84,9 +84,11 @@ struct JitLLVMContext : llvm::LLVMContext
 {
 };
 
+
 //////////////////////////////////////////////////////////////////////////
 /// JitCache
 //////////////////////////////////////////////////////////////////////////
+struct JitManager; // Forward Decl
 class JitCache : public llvm::ObjectCache
 {
 public:
@@ -94,7 +96,7 @@ public:
     JitCache();
     virtual ~JitCache() {}
 
-    void SetCpu(const llvm::StringRef& cpu) { mCpu = cpu.str(); }
+    void Init(JitManager* pJitMgr, const llvm::StringRef& cpu) { mCpu = cpu.str(); mpJitMgr = pJitMgr; }
 
     /// notifyObjectCompiled - Provides a pointer to compiled code for Module M.
     virtual void notifyObjectCompiled(const llvm::Module *M, llvm::MemoryBufferRef Obj);
@@ -107,7 +109,8 @@ public:
 private:
     std::string mCpu;
     llvm::SmallString<MAX_PATH> mCacheDir;
-    uint32_t mCurrentModuleCRC;
+    uint32_t mCurrentModuleCRC = 0;
+    JitManager* mpJitMgr = nullptr;
 };
 
 //////////////////////////////////////////////////////////////////////////
index d835f2d0296bbe2be8fa15615c83f3484bdc1b32..87363d27ef10c69816e0050bff18fb8c3450a46f 100644 (file)
@@ -358,6 +358,7 @@ Function* FetchJit::Create(const FETCH_COMPILE_STATE& fetchState)
 
     JitManager::DumpToFile(fetch, "opt");
 
+
     return fetch;
 }
 
@@ -2917,6 +2918,7 @@ PFN_FETCH_FUNC JitFetchFunc(HANDLE hJitMgr, const HANDLE hFunc)
     pJitMgr->DumpAsm(const_cast<llvm::Function*>(func), "final");
 
 
+
     return pfnFetch;
 }
 
index d0bb479128f16171b5750d11b115f942a8d87ddc..53c03214aad90799ddc670f9b242c01dc1c87eb7 100644 (file)
@@ -132,3 +132,9 @@ using PassManager = llvm::legacy::PassManager;
 #include <mutex>
 
 #include "common/os.h"
+
+#if defined(_WIN32)
+#define JIT_OBJ_EXT ".obj"
+#else
+#define JIT_OBJ_EXT ".o"
+#endif // _WIN32