1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#pragma once
#include "common/Types.hpp"
#include "AdaptorCommon/customApi.hpp"
#include "Compiler/CodeGenPublicEnums.h"
#include <iStdLib/utility.h>
#include "common/LLVMWarningsPush.hpp"
#include <llvm/Support/raw_ostream.h>
#include <llvm/IR/Module.h>
#include <llvm/ADT/Optional.h>
#include <llvm/Pass.h>
#include "common/LLVMWarningsPop.hpp"
#include "AdaptorCommon/API/igc.h"
#include <string>
#include <vector>
#include <stdarg.h>
#include <mutex>
// Forward declarations
struct D3D10DDIARG_SIGNATURE_ENTRY;
struct D3D10DDIARG_STAGE_IO_SIGNATURES;
struct D3D11DDIARG_TESSELLATION_IO_SIGNATURES;
namespace IGC { class CodeGenContext; }
namespace USC
{
struct ShaderD3D;
struct SPixelShaderNOS;
struct SVertexShaderNOS;
}
namespace IGC
{
class CShader;
namespace Debug
{
const char* GetShaderTypeAcronym(ShaderType shaderType);
/*************************************************************************************************\
* Generic
*/
class DumpName
{
public:
explicit DumpName(std::string const& dumpName);
DumpName();
//Needs to be static so that all objects of the class share it and public so that all derived classes have access to it.
static std::mutex hashMapLock;
static unsigned int shaderNum;
DumpName ShaderName(std::string const& name) const;
DumpName Type(ShaderType type) const;
DumpName Extension(std::string const& extension) const;
DumpName StagedInfo(void const* context) const;
DumpName SIMDSize(SIMDMode width) const;
DumpName DispatchMode(ShaderDispatchMode mode) const;
DumpName Hash(ShaderHash hash) const;
DumpName PostFix(std::string const& postfixStr) const;
DumpName Pass(std::string const& name, llvm::Optional<uint32_t> index = llvm::Optional<uint32_t>()) const;
DumpName PSPhase(PixelShaderPhaseType phase) const;
DumpName Retry(unsigned retryId) const;
std::string str() const;
std::string overridePath() const;
std::string RelativePath() const;
std::string AbsolutePath(OutputFolderName folder) const;
std::string GetKernelName() const;
bool allow() const;
private:
class CPassDescriptor
{
public:
std::string m_name;
llvm::Optional<unsigned int> m_index;
};
llvm::Optional<std::string> m_dumpName;
llvm::Optional<std::string> m_shaderName;
llvm::Optional<ShaderType> m_type;
llvm::Optional<PixelShaderPhaseType> m_psPhase;
llvm::Optional<std::string> m_extension;
llvm::Optional<SIMDMode> m_simdWidth;
llvm::Optional<CG_FLAG_t> m_cgFlag;
llvm::Optional<ShaderDispatchMode> m_ShaderMode;
llvm::Optional<ShaderHash> m_hash;
llvm::Optional<std::string> m_postfixStr;
llvm::Optional<CPassDescriptor> m_pass;
llvm::Optional<unsigned> m_retryId;
};
/// return the name of the file to dump
std::string GetDumpName(const CShader* pProgram, const char* ext);
/// return the name of the file to dump
DumpName GetDumpNameObj(const CShader* pProgram, const char* ext);
/// return the name of the file to dump for llvm IR
DumpName GetLLDumpName(IGC::CodeGenContext* pContext, const char* dumpName);
class Dump
{
public:
Dump( DumpName const& dumpName, DumpType type );
virtual ~Dump();
llvm::raw_ostream& stream() const;
void flush();
template<typename T>
llvm::raw_ostream& operator<< ( T const& val ) const
{
stream() << val;
return stream();
}
private:
std::string m_string;
const DumpName m_name;
std::unique_ptr<llvm::raw_ostream> m_pStream;
llvm::raw_ostream* m_pStringStream;
const DumpType m_type;
bool m_ClearFile;
};
// Common implementation of the flush pass
template<typename PassT>
class CommonFlushDumpPass : public PassT
{
public:
CommonFlushDumpPass(Dump& dump, char& pid) : PassT(pid), m_Dump(dump) {}
void getAnalysisUsage(llvm::AnalysisUsage& AU) const override
{
AU.setPreservesAll();
}
llvm::StringRef getPassName() const override
{
return "Flush Dump";
}
protected:
Dump& m_Dump;
};
class ModuleFlushDumpPass : public CommonFlushDumpPass<llvm::ModulePass>
{
public:
static char ID;
ModuleFlushDumpPass(Dump& dump) : CommonFlushDumpPass(dump, ID) {}
bool runOnModule(llvm::Module&) override
{
m_Dump.flush();
return false;
}
};
class FunctionFlushDumpPass : public CommonFlushDumpPass<llvm::FunctionPass>
{
public:
static char ID;
FunctionFlushDumpPass(Dump& dump) : CommonFlushDumpPass(dump, ID) {}
bool runOnFunction(llvm::Function&) override
{
m_Dump.flush();
return false;
}
};
void DumpLLVMIRText(
llvm::Module* pModule,
const DumpName& dumpName,
llvm::AssemblyAnnotationWriter* optionalAnnotationWriter = nullptr);
int PrintDebugMsgV(
const Dump* dump,
const char* fmt,
va_list ap);
void PrintDebugMsg(
const Dump* dump,
const char* fmt,
...);
inline FILE* OpenDumpFile(
const char* fileNamePrefix,
const char* fileNameExt,
const ShaderHash& hash,
const char* flag)
{
std::string name =
IGC::Debug::DumpName(fileNamePrefix)
.Hash(hash)
.Extension(fileNameExt)
.str();
FILE* fp = fopen(name.c_str(), flag);
return fp;
}
ShaderHash ShaderHashOCL(const UINT* pShaderCode, size_t size);
ShaderHash ShaderHashOGL(QWORD glslHash, QWORD nosHash);
} // namespace Debug
} // namespace IGC
|