[Mesa-dev] [PATCH 4/6] swr: [rasterizer jitter] support for dumping x86 asm

Tim Rowley timothy.o.rowley at intel.com
Mon Apr 25 22:12:13 UTC 2016


---
 .../drivers/swr/rasterizer/jitter/JitManager.cpp   | 49 ++++++++++++++++++++++
 .../drivers/swr/rasterizer/jitter/JitManager.h     |  1 +
 2 files changed, 50 insertions(+)

diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
index 271c196..d6755ed 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
@@ -46,6 +46,8 @@
 
 #include "llvm/Analysis/CFGPrinter.h"
 #include "llvm/IRReader/IRReader.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/FormattedStream.h"
 
 #if LLVM_USE_INTEL_JITEVENTS
 #include "llvm/ExecutionEngine/JITEventListener.h"
@@ -250,6 +252,53 @@ bool JitManager::SetupModuleFromIR(const uint8_t *pIR)
     return true;
 }
 
+
+//////////////////////////////////////////////////////////////////////////
+/// @brief Dump function x86 assembly to file.
+/// @note This should only be called after the module has been jitted to x86 and the
+///       module will not be further accessed.
+void JitManager::DumpAsm(Function* pFunction, const char* fileName)
+{
+    if (KNOB_DUMP_SHADER_IR)
+    {
+
+#if defined(_WIN32)
+        DWORD pid = GetCurrentProcessId();
+        TCHAR procname[MAX_PATH];
+        GetModuleFileName(NULL, procname, MAX_PATH);
+        const char* pBaseName = strrchr(procname, '\\');
+        std::stringstream outDir;
+        outDir << JITTER_OUTPUT_DIR << pBaseName << "_" << pid << std::ends;
+        CreateDirectory(outDir.str().c_str(), NULL);
+#endif
+
+        std::error_code EC;
+        Module* pModule = pFunction->getParent();
+        const char *funcName = pFunction->getName().data();
+        char fName[256];
+#if defined(_WIN32)
+        sprintf(fName, "%s\\%s.%s.asm", outDir.str().c_str(), funcName, fileName);
+#else
+        sprintf(fName, "%s.%s.asm", funcName, fileName);
+#endif
+
+#if HAVE_LLVM == 0x306
+        raw_fd_ostream fd(fName, EC, llvm::sys::fs::F_None);
+        formatted_raw_ostream filestream(fd);
+#else
+        raw_fd_ostream filestream(fName, EC, llvm::sys::fs::F_None);
+#endif
+
+        legacy::PassManager* pMPasses = new legacy::PassManager();
+        auto* pTarget = mpExec->getTargetMachine();
+        pTarget->Options.MCOptions.AsmVerbose = true;
+        pTarget->addPassesToEmitFile(*pMPasses, filestream, TargetMachine::CGFT_AssemblyFile);
+        pMPasses->run(*pModule);
+        delete pMPasses;
+        pTarget->Options.MCOptions.AsmVerbose = false;
+    }
+}
+
 //////////////////////////////////////////////////////////////////////////
 /// @brief Dump function to file.
 void JitManager::DumpToFile(Function *f, const char *fileName)
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
index 4ffb0fb..9861eae 100644
--- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
+++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h
@@ -184,5 +184,6 @@ struct JitManager
     void SetupNewModule();
     bool SetupModuleFromIR(const uint8_t *pIR);
 
+    void DumpAsm(Function* pFunction, const char* fileName);
     static void DumpToFile(Function *f, const char *fileName);
 };
-- 
1.9.1



More information about the mesa-dev mailing list