//////////////////////////////////////////////////////////////////////////
/// @brief Dump function to file.
-void JitManager::DumpToFile(Module* M, const char* fileName)
+void JitManager::DumpToFile(Module* M, const char* fileName, llvm::AssemblyAnnotationWriter* annotater)
{
if (KNOB_DUMP_SHADER_IR)
{
sprintf(fName, "%s.%s.ll", funcName, fileName);
#endif
raw_fd_ostream fd(fName, EC, llvm::sys::fs::F_None);
- M->print(fd, nullptr);
+ M->print(fd, annotater);
fd.flush();
}
}
return pBuf;
}
+
+void InterleaveAssemblyAnnotater::emitInstructionAnnot(const llvm::Instruction *pInst, llvm::formatted_raw_ostream &OS)
+{
+ auto dbgLoc = pInst->getDebugLoc();
+ if(dbgLoc)
+ {
+ unsigned int line = dbgLoc.getLine();
+ if(line != mCurrentLineNo)
+ {
+ if(line > 0 && line <= mAssembly.size())
+ {
+ // HACK: here we assume that OS is a formatted_raw_ostream(ods())
+ // and modify the color accordingly. We can't do the color
+ // modification on OS because formatted_raw_ostream strips
+ // the color information. The only way to fix this behavior
+ // is to patch LLVM.
+ OS << "\n; " << line << ": " << mAssembly[line-1] << "\n";
+ }
+ mCurrentLineNo = line;
+ }
+ }
+}
+
#include "jit_pch.hpp"
#include "common/isa.hpp"
+#include <llvm/IR/AssemblyAnnotationWriter.h>
//////////////////////////////////////////////////////////////////////////
void DumpAsm(llvm::Function* pFunction, const char* fileName);
static void DumpToFile(llvm::Function* f, const char* fileName);
- static void DumpToFile(llvm::Module* M, const char* fileName);
+ static void DumpToFile(llvm::Module* M, const char* fileName, llvm::AssemblyAnnotationWriter* annotater = nullptr);
static std::string GetOutputDir();
// Debugging support methods
uint32_t lineNum,
const std::vector<std::pair<std::string, uint32_t>>& members);
};
+
+class InterleaveAssemblyAnnotater : public llvm::AssemblyAnnotationWriter
+{
+public:
+ void emitInstructionAnnot(const llvm::Instruction *pInst, llvm::formatted_raw_ostream &OS) override;
+ std::vector<std::string> mAssembly;
+private:
+ uint32_t mCurrentLineNo = 0;
+};