Skip to content

Commit edcf21d

Browse files
fda0igcbot
authored andcommitted
Add AddVISADumpDeclarationsToEnd flag
Add a IGC flag that adds a comment with .decl section at the end of VISAASM console dump.
1 parent ff57226 commit edcf21d

File tree

8 files changed

+83
-31
lines changed

8 files changed

+83
-31
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3819,6 +3819,9 @@ void CEncoder::InitVISABuilderOptions(TARGET_PLATFORM VISAPlatform, bool canAbor
38193819
if (IGC_IS_FLAG_ENABLED(DumpASMToConsole)) {
38203820
SaveOption(vISA_asmToConsole, true);
38213821
}
3822+
if (IGC_IS_FLAG_ENABLED(AddVISADumpDeclarationsToEnd)) {
3823+
SaveOption(vISA_AddISAASMDeclarationsToEnd, true);
3824+
}
38223825
if (IGC_IS_FLAG_ENABLED(AddExtraIntfInfo)) {
38233826
SaveOption(vISA_AddExtraIntfInfo, true);
38243827
}

IGC/common/igc_flags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ DECLARE_IGC_REGKEY(bool, EnableIGAEncoder, false, "Enable VISA IGA encoder", fal
5656
DECLARE_IGC_REGKEY(bool, EnableVISADumpCommonISA, false, "Enable VISA Dump Common ISA", true)
5757
DECLARE_IGC_REGKEY(bool, DumpVISAASMToConsole, false, "Dump VISAASM to console and do early exit", true)
5858
DECLARE_IGC_REGKEY(bool, DumpASMToConsole, false, "Dump ASM to console and do early exit", true)
59+
DECLARE_IGC_REGKEY(bool, AddVISADumpDeclarationsToEnd, false,
60+
"Add a comment with .decl section to the end of VISA console dump. Used in tests.", true)
5961
DECLARE_IGC_REGKEY(bool, EnableVISABinary, false, "Enable VISA Binary", true)
6062
DECLARE_IGC_REGKEY(bool, EnableVISAOutput, false, "Enable VISA GenISA output", true)
6163
DECLARE_IGC_REGKEY(bool, EnableVISASlowpath, false, "Enable VISA Slowpath. Needed to dump .visaasm", true)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2025 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
// REQUIRES: regkeys
10+
11+
// RUN: ocloc compile -file %s -device dg2 -options "-igc_opts 'DumpVISAASMToConsole=1,AddVISADumpDeclarationsToEnd=1,ForceOCLSIMDWidth=8'" | FileCheck %s
12+
13+
// CHECK-LABEL: .kernel "foo"
14+
// CHECK: add (M1_NM, 1) [[DST:.*]](0,0)<1> [[SRC_A:.*]](0,0)<0;1,0> [[SRC_B:.*]](0,0)<0;1,0>
15+
// CHECK: lsc_store{{.*}} (M1_NM, 1) {{.*}} [[DST]]
16+
// CHECK-DAG: // .decl [[SRC_A]] v_type=G type=d num_elts=1
17+
// CHECK-DAG: // .decl [[SRC_B]] v_type=G type=d num_elts=1
18+
// CHECK-DAG: // .decl [[DST]] v_type=G type=d num_elts=1
19+
20+
__kernel void foo(int a, int b, __global int *res) {
21+
*res = a + b;
22+
}

visa/BuildCISAIR.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class CISA_IR_Builder : public VISABuilder {
127127

128128
std::string isaDump(const VISAKernelImpl *kernel,
129129
const VISAKernelImpl *mainKernel,
130-
bool printVersion = true) const;
130+
bool printVersion = true,
131+
bool addDeclCommentAtEnd = false) const;
131132

132133
static void cat(std::stringstream &ss) {}
133134
template <typename T, typename... Ts>

visa/Common_ISA_framework.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ bool allowDump(const Options &options, const std::string &fullPath) {
152152
// repKernel has the actual shader body.
153153
std::string CISA_IR_Builder::isaDump(const VISAKernelImpl *kernel,
154154
const VISAKernelImpl *repKernel,
155-
bool printVersion) const {
155+
bool printVersion,
156+
bool addDeclCommentAtEnd) const {
156157
std::stringstream sstr;
157158
VISAKernel_format_provider header(repKernel);
158159

@@ -170,6 +171,12 @@ std::string CISA_IR_Builder::isaDump(const VISAKernelImpl *kernel,
170171
sstr << header.printInstruction(inst, kernel->getOptions()) << "\n";
171172
}
172173

174+
if (addDeclCommentAtEnd) {
175+
// This path is enabled vISA_AddISAASMDeclarationsToEnd
176+
// and is used in tests to verify the .decl section.
177+
sstr << header.printDeclSection(true) << "\n";
178+
}
179+
173180
#ifdef DLL_MODE
174181
// Print the options used to compile this vISA object to assist debugging.
175182
if (kernel->getCISABuilder()->getBuilderOption() == VISA_BUILDER_BOTH) {
@@ -189,6 +196,7 @@ int CISA_IR_Builder::isaDump(const char *combinedIsaasmName) const {
189196
return VISA_SUCCESS;
190197
#else
191198
const bool isaasmToConsole = m_options.getOption(vISA_ISAASMToConsole);
199+
const bool isaasmaddDeclAtEnd = m_options.getOption(vISA_AddISAASMDeclarationsToEnd);
192200
const bool genIsaasm = m_options.getOption(vISA_GenerateISAASM);
193201
const bool allowIsaasmDump = combinedIsaasmName && combinedIsaasmName[0] != '\0' &&
194202
CisaFramework::allowDump(m_options, combinedIsaasmName);
@@ -239,7 +247,7 @@ int CISA_IR_Builder::isaDump(const char *combinedIsaasmName) const {
239247
}
240248
if (genIsaasm) {
241249
if (isaasmToConsole) {
242-
std::cout << isaDump(kTemp, repKernel);
250+
std::cout << isaDump(kTemp, repKernel, true, isaasmaddDeclAtEnd);
243251
} else {
244252
std::ofstream out(asmFileName);
245253
out << isaDump(kTemp, repKernel);

visa/IsaDisassembly.cpp

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,34 +3435,7 @@ std::string VISAKernel_format_provider::printKernelHeader(bool printVersion) {
34353435
}
34363436
sstr << "\n";
34373437

3438-
// emit var decls
3439-
//.decl V<#> name=<name> type=<type> num_elts=<num_elements> [align=<align>]
3440-
//[alias=(<alias_index>,<alias_offset>)]
3441-
for (unsigned i = 0; i < getVarCount(); i++) {
3442-
sstr << "\n" << printVariableDecl(this, i, options);
3443-
}
3444-
// address decls
3445-
for (unsigned i = 0; i < getAddrCount(); i++) {
3446-
sstr << "\n" << printAddressDecl(this, i);
3447-
}
3448-
// pred decls
3449-
for (unsigned i = 0; i < getPredCount(); i++) {
3450-
// P0 is reserved; starting from P1 if there is predicate decl
3451-
sstr << "\n" << printPredicateDecl(this, i);
3452-
}
3453-
// sampler
3454-
for (unsigned i = 0; i < getSamplerCount(); i++) {
3455-
sstr << "\n" << printSamplerDecl(this, i);
3456-
}
3457-
// surface
3458-
unsigned numPreDefinedSurfs = Get_CISA_PreDefined_Surf_Count();
3459-
for (unsigned i = 0; i < getSurfaceCount(); i++) {
3460-
sstr << "\n" << printSurfaceDecl(this, i, numPreDefinedSurfs);
3461-
}
3462-
// inputs to kernel
3463-
for (unsigned i = 0; i < getInputCount(); i++) {
3464-
sstr << "\n" << printFuncInput(this, i, options);
3465-
}
3438+
sstr << printDeclSection(false);
34663439

34673440
bool isTargetSet = false;
34683441
for (unsigned i = 0; i < getAttrCount(); i++) {
@@ -3500,6 +3473,46 @@ std::string VISAKernel_format_provider::printKernelHeader(bool printVersion) {
35003473
return sstr.str();
35013474
}
35023475

3476+
std::string VISAKernel_format_provider::printDeclSection(bool printAsComment) {
3477+
// printAsComment adds "// " at the beginning of each line
3478+
// This is used for adding duplicated decl section at the end
3479+
// of the dump when vISA_AddISAASMDeclarationsToEnd is enabled.
3480+
3481+
std::stringstream sstr;
3482+
const Options *options = m_kernel->getOptions();
3483+
const char *newLine = printAsComment ? "\n// " : "\n";
3484+
3485+
// emit var decls
3486+
//.decl V<#> name=<name> type=<type> num_elts=<num_elements> [align=<align>]
3487+
//[alias=(<alias_index>,<alias_offset>)]
3488+
for (unsigned i = 0; i < getVarCount(); i++) {
3489+
sstr << newLine << printVariableDecl(this, i, options);
3490+
}
3491+
// address decls
3492+
for (unsigned i = 0; i < getAddrCount(); i++) {
3493+
sstr << newLine << printAddressDecl(this, i);
3494+
}
3495+
// pred decls
3496+
for (unsigned i = 0; i < getPredCount(); i++) {
3497+
// P0 is reserved; starting from P1 if there is predicate decl
3498+
sstr << newLine << printPredicateDecl(this, i);
3499+
}
3500+
// sampler
3501+
for (unsigned i = 0; i < getSamplerCount(); i++) {
3502+
sstr << newLine << printSamplerDecl(this, i);
3503+
}
3504+
// surface
3505+
unsigned numPreDefinedSurfs = Get_CISA_PreDefined_Surf_Count();
3506+
for (unsigned i = 0; i < getSurfaceCount(); i++) {
3507+
sstr << newLine << printSurfaceDecl(this, i, numPreDefinedSurfs);
3508+
}
3509+
// inputs to kernel
3510+
for (unsigned i = 0; i < getInputCount(); i++) {
3511+
sstr << newLine << printFuncInput(this, i, options);
3512+
}
3513+
return sstr.str();
3514+
}
3515+
35033516
std::string printFunctionDecl(const print_format_provider_t *header,
35043517
bool isKernel) {
35053518
std::stringstream sstr;

visa/VISAKernel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,6 +1503,7 @@ class VISAKernel_format_provider : public print_format_provider_t {
15031503
uint32_t getInputCount() const { return m_kernel->m_input_count; }
15041504

15051505
std::string printKernelHeader(bool printVersion);
1506+
std::string printDeclSection(bool printAsComment);
15061507

15071508
std::string printInstruction(const CISA_INST *instruction,
15081509
const Options *opt) const;

visa/include/VISAOptionsDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,8 @@ DEF_VISA_OPTION(vISA_GenerateCombinedISAASM, ET_BOOL, "-dumpcombinedcisa",
622622
DEF_VISA_OPTION(vISA_ISAASMToConsole, ET_BOOL, "-isaasmToConsole",
623623
"The option can be used with -dumpcommonisa to make finalizer"
624624
"emit isaasm to stdout instead of file and do early exit", false)
625+
DEF_VISA_OPTION(vISA_AddISAASMDeclarationsToEnd, ET_BOOL, "-isaasmAddDeclarationsAtEnd",
626+
"Add a comment with .decl section to the end of isaasm console dump. Used in tests.", false)
625627
DEF_VISA_OPTION(vISA_DumpIsaVarNames, ET_BOOL, "-dumpisavarnames", UNUSED, true)
626628
DEF_VISA_OPTION(vISA_UniqueLabels, ET_BOOL, "-uniqueLabel", UNUSED, false)
627629
DEF_VISA_OPTION(vISA_ShaderDumpRegexFilter, ET_CSTR, "-shaderDumpRegexFilter",

0 commit comments

Comments
 (0)