Skip to content

Commit 5be4852

Browse files
franciszek-majkusiakigcbot
authored andcommitted
Parse build options from .visaasm shader override
Parse and use build options when using shader override with .visaasm files.
1 parent 6fcd40f commit 5be4852

File tree

7 files changed

+60
-2
lines changed

7 files changed

+60
-2
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6403,6 +6403,7 @@ namespace IGC
64036403
bool vISAAsmParseError = false;
64046404
// Parse the generated VISA text
64056405
if (visaAsmOverride) {
6406+
vAsmTextBuilder->SetOption(vISA_ParseBuildOptions, true);
64066407
for (const std::string &tmpVisaFile : visaOverrideFiles) {
64076408
llvm::SmallVector<char, 1024> visaAsmNameVector;
64086409
std::string visaAsmName = GetDumpFileName("");
@@ -6424,6 +6425,7 @@ namespace IGC
64246425
break;
64256426
}
64266427
}
6428+
vAsmTextBuilder->SetOption(vISA_ParseBuildOptions, false);
64276429
} else {
64286430
int result = 0;
64296431
if (m_hasInlineAsm) {

visa/BuildCISAIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,8 @@ class CISA_IR_Builder : public VISABuilder {
529529

530530
void CISA_post_file_parse();
531531

532+
void CISA_parse_build_options(const char* argStr);
533+
532534
VISA_opnd *CISA_create_gen_src_operand(const char *var_name, short v_stride,
533535
short width, short h_stride,
534536
unsigned char row_offset,

visa/BuildCISAIRImpl.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,7 @@ extern int CISAparse(CISA_IR_Builder *builder);
15591559
extern YY_BUFFER_STATE CISA_scan_string(const char *yy_str);
15601560
extern void CISA_delete_buffer(YY_BUFFER_STATE buf);
15611561
static std::mutex mtx;
1562+
extern void resetGlobalVariables();
15621563

15631564
int CISA_IR_Builder::ParseVISAText(const std::string &visaText,
15641565
const std::string &visaTextFile) {
@@ -1581,6 +1582,7 @@ int CISA_IR_Builder::ParseVISAText(const std::string &visaText,
15811582
}
15821583
}
15831584

1585+
resetGlobalVariables();
15841586
YY_BUFFER_STATE visaBuf = CISA_scan_string(visaText.c_str());
15851587
if (CISAparse(this) != 0) {
15861588
#ifndef DLL_MODE
@@ -1622,6 +1624,7 @@ int CISA_IR_Builder::ParseVISAText(const std::string &visaFile) {
16221624
return VISA_FAILURE;
16231625
}
16241626

1627+
resetGlobalVariables();
16251628
if (CISAparse(this) != 0) {
16261629
vISA_ASSERT(false, "Parsing visa text failed");
16271630
return VISA_FAILURE;
@@ -4012,6 +4015,30 @@ CISA_IR_Builder::get_input_class(Common_ISA_Var_Class var_class) {
40124015
}
40134016
void CISA_IR_Builder::CISA_post_file_parse() { return; }
40144017

4018+
void CISA_IR_Builder::CISA_parse_build_options(const char* argStr) {
4019+
std::string args(argStr);
4020+
size_t first_quote = args.find_first_of('"');
4021+
size_t last_quote = args.find_last_of('"');
4022+
4023+
if (first_quote != std::string::npos &&
4024+
last_quote != std::string::npos &&
4025+
first_quote < last_quote) {
4026+
args = args.substr(first_quote + 1, last_quote - first_quote - 1);
4027+
std::vector<std::string> argvStrings;
4028+
std::vector<const char*> argv;
4029+
std::string token;
4030+
std::istringstream ss(args);
4031+
while (ss >> token) {
4032+
argvStrings.push_back(token);
4033+
}
4034+
argv.reserve(argvStrings.size());
4035+
for (const std::string& s : argvStrings) {
4036+
argv.push_back(s.c_str());
4037+
}
4038+
getOptions()->parseOptions(argv.size(), argv.data());
4039+
}
4040+
}
4041+
40154042
// place it here so that internal Gen_IR files don't have to include
40164043
// VISAKernel.h
40174044
std::stringstream &IR_Builder::criticalMsgStream() {

visa/CISA.l

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ static unsigned char FENCEOptions(const char* str);
5353
static COMMON_ISA_VME_OP_MODE VMEType(const char *str);
5454
static CHANNEL_OUTPUT_FORMAT Get_Channel_Output(const char* str);
5555
static void appendStringLiteralChar(char c, char *buf, size_t *len);
56+
57+
static bool buildOptionPresent = false;
58+
void resetGlobalVariables() {
59+
buildOptionPresent = false;
60+
}
5661
%}
5762

5863
%option yylineno
@@ -66,6 +71,17 @@ static void appendStringLiteralChar(char c, char *buf, size_t
6671
return NEWLINE;
6772
}
6873

74+
"//Build option:"[ \t]*\"([^\"\n]*)\"[ \t]* {
75+
if(pBuilder->getOptions()->getOption(vISA_ParseBuildOptions)) {
76+
if(buildOptionPresent)
77+
YY_FATAL_ERROR("more then one instance of build options");
78+
buildOptionPresent = true;
79+
TRACE("** BUILD_OPTION\n");
80+
CISAlval.string = strdup(yytext);
81+
return BUILD_OPTION_LINE;
82+
}
83+
}
84+
6985
[ \t] { /*drop non-newline spaces*/}
7086
"//"[^\n]* {
7187
// drop comments

visa/CISA.y

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,8 @@ std::vector<attr_gen_struct*> AttrOptVar;
397397

398398
%token NEWLINE
399399

400+
%token <string> BUILD_OPTION_LINE
401+
400402

401403
%token UNIFORM
402404
%token <string> RTWRITE_OPTION
@@ -689,6 +691,7 @@ Statement:
689691
| Instruction
690692
| Label
691693
| Scope
694+
| BuildOptions
692695

693696

694697
// ------------- Scope -------------
@@ -3165,6 +3168,12 @@ DataTypeIntOrVector:
31653168
ITYPE
31663169
| VTYPE
31673170

3171+
// --------- BuildOptions --------------------------------
3172+
BuildOptions: BUILD_OPTION_LINE
3173+
{
3174+
pBuilder->CISA_parse_build_options($1);
3175+
}
3176+
31683177

31693178
%%
31703179
///////////////////////////////////////////////////////////////////////////////

visa/Common_ISA_framework.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ int CISA_IR_Builder::isaDump(const char *combinedIsaasmName) const {
190190
#else
191191
const bool isaasmToConsole = m_options.getOption(vISA_ISAASMToConsole);
192192
const bool genIsaasm = m_options.getOption(vISA_GenerateISAASM);
193-
const bool allowIsaasmDump = CisaFramework::allowDump(m_options,
194-
combinedIsaasmName ? combinedIsaasmName : std::string());
193+
const bool allowIsaasmDump = combinedIsaasmName && combinedIsaasmName[0] != '\0' &&
194+
CisaFramework::allowDump(m_options, combinedIsaasmName);
195195
const bool genCombinedIsaasm =
196196
m_options.getOption(vISA_GenerateCombinedISAASM) &&
197197
(isaasmToConsole || allowIsaasmDump);

visa/include/VISAOptionsDefs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,8 @@ DEF_VISA_OPTION(
626626
"1 enables basic output, 2 enables with def/use dataflow information "
627627
"(may increase compile time significantly for large shaders)",
628628
0)
629+
DEF_VISA_OPTION(vISA_ParseBuildOptions, ET_BOOL, "-parseBuildOptions", UNUSED,
630+
false)
629631

630632
//=== misc options ===
631633
DEF_VISA_OPTION(vISA_PlatformSet, ET_INT32, NULLSTR, UNUSED, -1 /*GENX_NONE*/)

0 commit comments

Comments
 (0)