Skip to content

Commit 4225d15

Browse files
daniel-manigcbot
authored andcommitted
Enabled live analysis JSON from IGC
Added the ShaderDumpEnableIGAJSON option that adds IGA JSON output to shader dumps. 1 enables the JSON output, 2 enables JSON with live analysis.
1 parent 15dfa01 commit 4225d15

File tree

8 files changed

+64
-11
lines changed

8 files changed

+64
-11
lines changed

IGC/common/igc_flags.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ DECLARE_IGC_REGKEY(bool, QualityMetricsEnable, false, "Enable Quality M
322322
DECLARE_IGC_REGKEY(bool, ShaderDumpEnable, false, "dump LLVM IR, visaasm, and GenISA", true)
323323
DECLARE_IGC_REGKEY(bool, ShaderDumpEnableAll, false, "dump all LLVM IR passes, visaasm, and GenISA", true)
324324
DECLARE_IGC_REGKEY(DWORD, ShaderDumpEnableG4, false, "same as ShaderDumpEnable but adds G4 dumps (0 = off, 1 = some, 2 = all)", 0)
325+
DECLARE_IGC_REGKEY(DWORD, ShaderDumpEnableIGAJSON, false, "adds IGA JSON output to shader dumps (0 = off, 1 = enabled, 2 = include def/use info but causes longer compile times)", 0)
325326
DECLARE_IGC_REGKEY(debugString, ShaderDumpFilter, 0, "Only dump files matching the given regex", true)
326327
DECLARE_IGC_REGKEY(bool, ElfDumpEnable, false, "dump ELF file", true)
327328
DECLARE_IGC_REGKEY(bool, ElfTempDumpEnable, false, "dump temporary ELF files", true)

visa/BinaryEncodingIGA.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct SendExDescOpts {
3131
class BinaryEncodingIGA
3232
{
3333
int IGAInstId = 0;
34+
int IGABlockId = 0;
3435
Mem_Manager& mem;
3536
G4_Kernel& kernel;
3637
std::string fileName; // .dat filename
@@ -188,6 +189,7 @@ class BinaryEncodingIGA
188189
if (itr == labelToBlockMap.end())
189190
{
190191
b = IGAKernel.createBlock();
192+
b->setID(IGABlockId++);
191193
labelToBlockMap[label] = b;
192194
}
193195
else {
@@ -913,6 +915,7 @@ void BinaryEncodingIGA::Encode()
913915
{
914916
// create a new BB if kernel does not start with label
915917
currBB = IGAKernel->createBlock();
918+
currBB->setID(IGABlockId++);
916919
IGAKernel->appendBlock(currBB);
917920
}
918921

@@ -1049,7 +1052,11 @@ void BinaryEncodingIGA::EmitJSON(int dumpJSON) {
10491052
std::ofstream ofs(jsonFileName, std::ofstream::out);
10501053
FormatOpts fos(*platformModel);
10511054
fos.printJson = true;
1052-
FormatJSON(ofs, fos, *IGAKernel, nullptr);
1055+
if (dumpJSON > 1) {
1056+
fos.printInstDefs = true;
1057+
}
1058+
iga::ErrorHandler eh;
1059+
FormatKernel(eh, ofs, fos, *IGAKernel);
10531060
}
10541061

10551062
Instruction *BinaryEncodingIGA::translateInstruction(
@@ -1256,6 +1263,7 @@ void BinaryEncodingIGA::translateInstructionBranchSrcs(
12561263
{
12571264
// Creating a fall through block
12581265
bbNew = IGAKernel->createBlock();
1266+
bbNew->setID(IGABlockId++);
12591267
igaInst->setLabelSource(SourceIndex::SRC0, bbNew, Type::UD);
12601268
IGAKernel->appendBlock(bbNew);
12611269
}

visa/iga/IGALibrary/Frontend/Formatter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,6 +1483,13 @@ void FormatKernel(
14831483
{
14841484
IGA_ASSERT(k.getModel().platform == opts.model.platform,
14851485
"kernel and options must have same platform");
1486+
if (opts.printInstDefs && opts.liveAnalysis == nullptr) {
1487+
DepAnalysis la = ComputeDepAnalysis(&k);
1488+
FormatOpts optsCopy = opts;
1489+
optsCopy.liveAnalysis = &la;
1490+
FormatKernel(e, o, optsCopy, k, bits);
1491+
return;
1492+
}
14861493
if (!opts.printJson) {
14871494
Formatter f(e, o, opts);
14881495
f.formatKernel(k, (const uint8_t *)bits);

visa/iga/IGALibrary/IR/DUAnalysis.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ struct BlockState
609609
struct DepAnalysisComputer
610610
{
611611
const Model &model;
612-
Kernel *k;
612+
const Kernel *k;
613613

614614
// precomputed sources and destination sets indexed by instruction ID
615615
std::vector<RegSet> instDstsUnion;
@@ -622,13 +622,14 @@ struct DepAnalysisComputer
622622
DepAnalysis &results;
623623

624624
DepAnalysisComputer(
625-
Kernel *_k,
625+
const Kernel *_k,
626626
DepAnalysis &_results)
627627
: model(_k->getModel())
628628
, k(_k)
629629
, results(_results)
630630
{
631631
sanityCheckIR(k); // should nop in release
632+
IGA_ASSERT(k->checkIdsUnique(), "call relabelIDs or setIDs; duplicates exist");
632633

633634
results.deps.clear();
634635
results.liveIn.clear();
@@ -639,18 +640,15 @@ struct DepAnalysisComputer
639640

640641
// we must do this so the vector doesn't resize
641642
blockState.reserve(k->getBlockList().size());
642-
int bIx = 0, iIx = 0;
643643

644644
// pre-assign ID's we know to be valid and
645645
// precompute instruction dependencies
646646
for (Block *b : k->getBlockList()) {
647647
blockState.emplace_back(b);
648-
b->setID(bIx++);
649648

650649
auto iitr = b->getInstList().begin();
651650
while (iitr != b->getInstList().end()) {
652651
Instruction *i = *iitr;
653-
i->setID(iIx++);
654652
instSrcs.emplace_back(InstSrcs::compute(*i));
655653
instDstsUnion.emplace_back(InstDsts::compute(*i).unionOf());
656654
iitr++;
@@ -1109,7 +1107,7 @@ bool Dep::operator==(const Dep &p) const
11091107
}
11101108

11111109

1112-
DepAnalysis iga::ComputeDepAnalysis(Kernel *k)
1110+
DepAnalysis iga::ComputeDepAnalysis(const Kernel *k)
11131111
{
11141112
DepAnalysis la;
11151113

visa/iga/IGALibrary/IR/DUAnalysis.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ namespace iga
102102

103103
// The primary entry point for the live analysis
104104
// The counts are counts *going into* this instruction
105-
DepAnalysis ComputeDepAnalysis(Kernel *k);
105+
DepAnalysis ComputeDepAnalysis(const Kernel *k);
106106
} // namespace IGA
107107

108108
#endif // _IGA_IR_ANALYSIS_HPP

visa/iga/IGALibrary/IR/Kernel.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ SPDX-License-Identifier: MIT
99
#include "Kernel.hpp"
1010
#include "../IR/Messages.hpp"
1111

12+
#include <set>
13+
1214
using namespace iga;
1315

1416
Kernel::Kernel(const Model &model)
@@ -31,6 +33,39 @@ Kernel::~Kernel()
3133
}
3234
}
3335

36+
void Kernel::resetIds()
37+
{
38+
// algorithm to set the IDs
39+
int blockIndex = 0, instIndex = 0;
40+
for (Block *b : getBlockList()) {
41+
b->setID(blockIndex++);
42+
for (Instruction *i : b->getInstList()) {
43+
i->setID(instIndex++);
44+
}
45+
}
46+
}
47+
48+
bool Kernel::checkIdsUnique() const
49+
{
50+
// check to make sure no duplicate IDs
51+
std::set<int> instIds, blockIds;
52+
for (const Block *b : getBlockList()) {
53+
int blockId = b->getID();
54+
if (blockIds.count(blockId) > 0) {
55+
return false;
56+
}
57+
blockIds.insert(blockId);
58+
for (const Instruction *i : b->getInstList()) {
59+
int instId = i->getID();
60+
if (instIds.count(instId) > 0) {
61+
return false;
62+
}
63+
instIds.insert(instId);
64+
}
65+
}
66+
return true;
67+
}
68+
3469
size_t Kernel::getInstructionCount() const
3570
{
3671
size_t n = 0;

visa/iga/IGALibrary/IR/Kernel.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ namespace iga {
3535
Kernel(const Kernel &) = delete;
3636
Kernel& operator=(const Kernel&) = delete;
3737

38+
void resetIds();
39+
bool checkIdsUnique() const;
40+
3841
MemManager& getMemManager() { return m_mem; }
3942
const Model& getModel() const { return m_model; }
4043
const BlockList& getBlockList() const { return m_blocks; }

visa/iga/IGALibrary/api/iga.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,10 +526,11 @@ class IGAContext {
526526
// we succeeded in decoding; now format the output to text
527527
std::stringstream ss;
528528
FormatOpts fopts = formatterOpts(dopts, formatLbl, formatLblEnv);
529-
DepAnalysis la;
530529
if (dopts.formatting_opts & IGA_FORMATTING_OPT_PRINT_DEFS) {
531-
la = ComputeDepAnalysis(k);
532-
fopts.liveAnalysis = &la;
530+
// Set the IDs here (kernel helper function)
531+
k->resetIds();
532+
// set fopts.printInstDefs
533+
fopts.printInstDefs = true;
533534
}
534535
FormatKernel(errHandler, ss, fopts, *k, bits);
535536

0 commit comments

Comments
 (0)