Skip to content

Commit c754ae6

Browse files
aparshin-intelsys_zuul
authored andcommitted
vector compiler now uses DebugInfo library
Change-Id: I7f8bbf584bf3360e7c974b8f820c7ca0db41dfea
1 parent 8f1930e commit c754ae6

File tree

13 files changed

+300
-228
lines changed

13 files changed

+300
-228
lines changed

IGC/AdaptorOCL/OCL/sp/spp_g8.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ CGen8CMProgram::~CGen8CMProgram()
393393

394394
void CGen8CMProgram::CreateKernelBinaries()
395395
{
396-
for (auto *kernel : m_kernels) {
396+
for (auto *kernel : m_kernels)
397+
{
397398
// Create the kernel binary streams.
398399
KernelData data;
399400
data.kernelBinary = new Util::BinaryStream;
@@ -408,6 +409,17 @@ void CGen8CMProgram::CreateKernelBinaries()
408409
m_pSystemThreadKernelOutput,
409410
kernel->getProgramOutput().m_unpaddedProgramSize);
410411

412+
if (kernel->getProgramOutput().m_debugDataVISASize)
413+
{
414+
data.kernelDebugData = new Util::BinaryStream();
415+
m_StateProcessor.CreateKernelDebugData(
416+
reinterpret_cast<const char*>(kernel->getProgramOutput().m_debugDataVISA),
417+
kernel->getProgramOutput().m_debugDataVISASize,
418+
reinterpret_cast<const char*>(kernel->getProgramOutput().m_debugDataGenISA),
419+
kernel->getProgramOutput().m_debugDataGenISASize,
420+
kernel->m_kernelInfo.m_kernelName,
421+
*(data.kernelDebugData));
422+
}
411423
m_KernelBinaries.push_back(data);
412424
}
413425
}

IGC/AdaptorOCL/dllInterfaceCompute.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,13 +1475,21 @@ static std::error_code getErrorVC(std::error_code Err,
14751475
}
14761476

14771477
static void outputBinaryVC(llvm::StringRef Binary,
1478+
llvm::StringRef DebugInfo,
14781479
STB_TranslateOutputArgs* pOutputArgs)
14791480
{
1480-
size_t BinarySize = static_cast<size_t>(Binary.size());
1481+
size_t BinarySize = Binary.size();
14811482
char* pBinaryOutput = new char[BinarySize];
14821483
memcpy_s(pBinaryOutput, BinarySize, Binary.data(), BinarySize);
14831484
pOutputArgs->OutputSize = static_cast<uint32_t>(BinarySize);
14841485
pOutputArgs->pOutput = pBinaryOutput;
1486+
if (DebugInfo.size())
1487+
{
1488+
char* pDebugInfo = new char[DebugInfo.size()];
1489+
memcpy_s(pDebugInfo, DebugInfo.size(), DebugInfo.data(), DebugInfo.size());
1490+
pOutputArgs->pDebugData = pDebugInfo;
1491+
pOutputArgs->DebugDataSize = DebugInfo.size();
1492+
}
14851493
}
14861494

14871495
// Similar to ShaderHashOCL though reinterpretation is hidden inside
@@ -1564,7 +1572,7 @@ static std::error_code TranslateBuildVC(
15641572
case vc::BinaryKind::CM:
15651573
{
15661574
auto &CompileResult = std::get<vc::cm::CompileOutput>(Res);
1567-
outputBinaryVC(CompileResult.IsaBinary, pOutputArgs);
1575+
outputBinaryVC(CompileResult.IsaBinary, llvm::StringRef(), pOutputArgs);
15681576
break;
15691577
}
15701578
case vc::BinaryKind::OpenCL:
@@ -1578,7 +1586,13 @@ static std::error_code TranslateBuildVC(
15781586
CompileResult.PointerSizeInBytes);
15791587
llvm::StringRef BinaryRef{ProgramBinary.GetLinearPointer(),
15801588
static_cast<std::size_t>(ProgramBinary.Size())};
1581-
outputBinaryVC(BinaryRef, pOutputArgs);
1589+
1590+
Util::BinaryStream ProgramDebugData;
1591+
CMProgram.GetProgramDebugData(ProgramDebugData);
1592+
llvm::StringRef DebugInfoRef{ProgramDebugData.GetLinearPointer(),
1593+
static_cast<std::size_t>(ProgramDebugData.Size())};
1594+
1595+
outputBinaryVC(BinaryRef, DebugInfoRef, pOutputArgs);
15821596
break;
15831597
}
15841598
case vc::BinaryKind::ZE:
@@ -1590,7 +1604,13 @@ static std::error_code TranslateBuildVC(
15901604
llvm::raw_svector_ostream ProgramBinaryOS{ProgramBinary};
15911605
CMProgram.GetZEBinary(ProgramBinaryOS, CompileResult.PointerSizeInBytes);
15921606
llvm::StringRef BinaryRef{ProgramBinary.data(), ProgramBinary.size()};
1593-
outputBinaryVC(BinaryRef, pOutputArgs);
1607+
1608+
Util::BinaryStream ProgramDebugData;
1609+
CMProgram.GetProgramDebugData(ProgramDebugData);
1610+
llvm::StringRef DebugInfoRef{ProgramDebugData.GetLinearPointer(),
1611+
static_cast<std::size_t>(ProgramDebugData.Size())};
1612+
1613+
outputBinaryVC(BinaryRef, DebugInfoRef, pOutputArgs);
15941614
break;
15951615
}
15961616
}

IGC/VectorCompiler/igcdeps/src/cmc.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ static void populateKernelInfo_v2(const vc::ocl::KernelInfo& info,
509509
const FINALIZER_INFO& JITInfo,
510510
const vc::ocl::GTPinInfo* GtpinInfo,
511511
llvm::ArrayRef<uint8_t> genBin,
512+
llvm::ArrayRef<uint8_t> dbgInfo,
512513
CMKernel& kernel)
513514
{
514515
kernel.m_GRFSizeInBytes = info.GRFSizeInBytes;
@@ -570,7 +571,17 @@ static void populateKernelInfo_v2(const vc::ocl::KernelInfo& info,
570571
kernel.getProgramOutput().m_unpaddedProgramSize = size;
571572
kernel.getProgramOutput().m_InstructionCount = JITInfo.numAsmCount;
572573

573-
if (JITInfo.numBytesScratchGtpin > 0) {
574+
const size_t DbgSize = dbgInfo.size();
575+
if (DbgSize)
576+
{
577+
void* debugInfo = IGC::aligned_malloc(DbgSize, sizeof(void*));
578+
memcpy_s(debugInfo, DbgSize, dbgInfo.data(), DbgSize);
579+
kernel.getProgramOutput().m_debugDataVISA = debugInfo;
580+
kernel.getProgramOutput().m_debugDataVISASize = DbgSize;
581+
}
582+
583+
if (JITInfo.numBytesScratchGtpin > 0)
584+
{
574585
kernel.getProgramOutput().m_scratchSpaceUsedByGtpin = JITInfo.numBytesScratchGtpin;
575586
kInfo.m_executionEnivronment.PerThreadScratchSpace += JITInfo.numBytesScratchGtpin;
576587
}
@@ -632,7 +643,10 @@ void vc::createBinary(
632643
llvm::ArrayRef<uint8_t> GenBin{
633644
reinterpret_cast<const uint8_t*>(Info.GenBinary.data()),
634645
Info.GenBinary.size()};
646+
llvm::ArrayRef<uint8_t> DbgInfo{
647+
reinterpret_cast<const uint8_t*>(Info.DebugInfo.data()),
648+
Info.DebugInfo.size()};
635649
populateKernelInfo_v2(Info.KernelInfo, Info.JitInfo, &(Info.GtpinInfo),
636-
GenBin, *K);
650+
GenBin, DbgInfo, *K);
637651
}
638652
}

IGC/VectorCompiler/include/vc/GenXCodeGen/GenXWrapper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ struct CompileInfo {
119119
FINALIZER_INFO JitInfo;
120120
GTPinInfo GtpinInfo;
121121
std::vector<char> GenBinary;
122+
std::vector<char> DebugInfo;
122123
};
123124

124125
struct CompileOutput {

IGC/VectorCompiler/lib/GenXCodeGen/GenX.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ FunctionPass *createGenXTidyControlFlowPass();
115115
FunctionGroupPass *createGenXVisaRegAllocPass();
116116
FunctionGroupPass *createGenXCisaBuilderPass();
117117
ModulePass *createGenXFinalizerPass(raw_pwrite_stream &o);
118+
ModulePass *createGenXDebugInfoPass();
118119
ModulePass *createGenXImportBiFPass();
119120

120121
namespace genx {

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5858

5959
#include "llvm/GenXIntrinsics/GenXIntrinsicInst.h"
6060

61-
#include "common.h"
62-
#include "visaBuilder_interface.h"
61+
#include "visa/include/visaBuilder_interface.h"
62+
#include "visa/common.h"
6363

6464
#include "llvm/ADT/IndexedMap.h"
6565
#include "llvm/ADT/StringExtras.h"
@@ -109,10 +109,6 @@ static cl::list<std::string>
109109
static cl::opt<bool> EmitVisa("emit-visa", cl::init(false), cl::Hidden,
110110
cl::desc("Generate Visa instead of fat binary."));
111111

112-
static cl::opt<bool> GenerateDebugInfo(
113-
"emit-debug-info", cl::init(false), cl::Hidden,
114-
cl::desc("Generate DWARF debug info for each compiled kernel"));
115-
116112
static cl::opt<std::string> AsmNameOpt("asm-name", cl::init(""), cl::Hidden,
117113
cl::desc("Output assembly code to this file during compilation."));
118114

@@ -5667,19 +5663,10 @@ class GenXFinalizer : public ModulePass {
56675663
AU.setPreservesAll();
56685664
}
56695665

5670-
void emitDebugInformation(VISABuilder &VB, const GenXModule &GM,
5671-
const FunctionGroupAnalysis &FGA,
5672-
const GenXSubtarget &ST);
5673-
56745666
bool runOnModule(Module &M) {
56755667
Ctx = &M.getContext();
56765668

56775669
GenXModule &GM = getAnalysis<GenXModule>();
5678-
FunctionGroupAnalysis &FGA = getAnalysis<FunctionGroupAnalysis>();
5679-
const GenXSubtarget &ST = getAnalysis<TargetPassConfig>()
5680-
.getTM<GenXTargetMachine>()
5681-
.getGenXSubtarget();
5682-
56835670
std::stringstream ss;
56845671
VISABuilder *CisaBuilder = GM.GetCisaBuilder();
56855672
if (GM.HasInlineAsm())
@@ -5688,9 +5675,6 @@ class GenXFinalizer : public ModulePass {
56885675

56895676
dbgs() << CisaBuilder->GetCriticalMsg();
56905677

5691-
if (GenerateDebugInfo)
5692-
emitDebugInformation(*CisaBuilder, GM, FGA, ST);
5693-
56945678
Out << ss.str();
56955679
return false;
56965680
}
@@ -5703,33 +5687,6 @@ ModulePass *llvm::createGenXFinalizerPass(raw_pwrite_stream &o) {
57035687
return new GenXFinalizer(o);
57045688
}
57055689

5706-
void GenXFinalizer::emitDebugInformation(VISABuilder &VB, const GenXModule &GM,
5707-
const FunctionGroupAnalysis &FGA,
5708-
const GenXSubtarget &ST) {
5709-
for (const auto *FG : FGA) {
5710-
const auto *KF = FG->getHead();
5711-
llvm::SmallVector<char, 1000> ElfImage;
5712-
5713-
const genx::VisaDebugInfo &DbgInfo = *GM.getVisaDebugInfo(KF);
5714-
VISAKernel *VK = VB.GetVISAKernel(KF->getName().str());
5715-
IGC_ASSERT_MESSAGE(VK, "Kernel is null");
5716-
auto Err = genx::generateDebugInfo(ElfImage, *VK, DbgInfo, *KF,
5717-
ST.getTargetTriple().str());
5718-
if (Err)
5719-
llvm::report_fatal_error(toString(std::move(Err)));
5720-
5721-
std::error_code EC;
5722-
llvm::raw_fd_ostream OS(("dbg_" + KF->getName() + ".elf").str(), EC);
5723-
if (!EC) {
5724-
OS << StringRef(ElfImage.data(), ElfImage.size());
5725-
OS.close();
5726-
}
5727-
5728-
if (EC)
5729-
llvm::report_fatal_error(EC.message());
5730-
}
5731-
}
5732-
57335690
static SmallVector<const char *, 8>
57345691
collectFinalizerArgs(StringSaver &Saver, const GenXSubtarget &ST) {
57355692
SmallVector<const char *, 8> Argv;

0 commit comments

Comments
 (0)