summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorTim Rowley <[email protected]>2016-04-21 14:37:19 -0600
committerTim Rowley <[email protected]>2016-04-27 10:41:32 -0500
commitfa36f8ec9ce492d65eab8ad599897b3e3045094a (patch)
tree720342917da5e2a967d12fcb427674a03c71bdaa /src/gallium
parenta646ffdacff1d8895c129b556fccc77d79f6c4a3 (diff)
swr: [rasterizer jitter] support for dumping x86 asm
Reviewed-by: Bruce Cherniak <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp49
-rw-r--r--src/gallium/drivers/swr/rasterizer/jitter/JitManager.h1
2 files changed, 50 insertions, 0 deletions
diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp
index 271c1969be6..d6755edf817 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 4ffb0fbee01..9861eae78aa 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);
};