[Mesa-dev] [PATCH 05/20] swr/rast: Debug Symbols work
George Kyriazis
george.kyriazis at intel.com
Fri Jan 19 21:47:00 UTC 2018
Added support for Fetch / Sample / LD functions
Added DLL link to JitCache implementation
---
.../drivers/swr/rasterizer/jitter/JitManager.cpp | 92 ++++++++++++++++++----
.../drivers/swr/rasterizer/jitter/JitManager.h | 7 +-
.../drivers/swr/rasterizer/jitter/fetch_jit.cpp | 2 +
.../drivers/swr/rasterizer/jitter/jit_pch.hpp | 6 ++
4 files changed, 88 insertions(+), 19 deletions(-)
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
index 2b99361..a3bda61 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
@@ -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;
}
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
index 4cf2214..fb20a36 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
@@ -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;
};
//////////////////////////////////////////////////////////////////////////
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp b/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
index d835f2d..87363d2 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/fetch_jit.cpp
@@ -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;
}
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp b/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp
index d0bb479..53c0321 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/jit_pch.hpp
@@ -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
--
2.7.4
More information about the mesa-dev
mailing list