Skip to content

Commit 5136a85

Browse files
pratikasharigcbot
authored andcommitted
Add support for ".uniform" modifier in ifcall instruction
Add support for ".uniform" modifier in ifcall instruction. When IGC marks an ifcall as uniform, VISA skips running special EU fusion call WA when -fusedCallWA = 2.
1 parent 4c55256 commit 5136a85

File tree

17 files changed

+89
-36
lines changed

17 files changed

+89
-36
lines changed

IGC/Compiler/CISACodeGen/CISABuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,8 @@ namespace IGC
416416
VISA_EMask_Ctrl emask = m_encoderState.m_noMask ? vISA_EMASK_M1_NM : vISA_EMASK_M1;
417417
VISA_Exec_Size execSize = visaExecSize(m_program->m_dispatchSize);
418418
VISA_VectorOpnd* funcAddrOpnd = GetSourceOperandNoModifier(funcPtr);
419-
V(vKernel->AppendVISACFIndirectFuncCallInst(predOpnd, emask, execSize, funcAddrOpnd, argSize, retSize));
419+
V(vKernel->AppendVISACFIndirectFuncCallInst(
420+
predOpnd, emask, execSize, false, funcAddrOpnd, argSize, retSize));
420421
}
421422

422423
void CEncoder::SubroutineRet(CVariable* flag, llvm::Function* F)

IGC/VectorCompiler/lib/GenXCodeGen/GenXCisaBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ class GenXKernelBuilder {
867867
unsigned char ReturnSize) {
868868
updateSIMDSize(ExecMask, ExecSize);
869869
CISA_CALL(Kernel->AppendVISACFIndirectFuncCallInst(
870-
Pred, ExecMask, ExecSize, FuncAddr, ArgSize, ReturnSize));
870+
Pred, ExecMask, ExecSize, false, FuncAddr, ArgSize, ReturnSize));
871871
}
872872

873873
inline void appendVISACFRetInst(VISA_PredOpnd *Pred, VISA_EMask_Ctrl ExecMask,

documentation/visa/instructions/IFCALL.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ SPDX-License-Identifier: MIT
8787
8888
8989
90-
[(<P>)] IFCALL (<exec_size>) <func_id> <arg_size> <return_size>
90+
[(<P>)] IFCALL.[uniform] (<exec_size>) <func_id> <arg_size> <return_size>
9191
```
9292
## Notes
9393

@@ -96,6 +96,8 @@ SPDX-License-Identifier: MIT
9696

9797

9898
```
99+
Optional .uniform modifier is set if all threads invoke same callee.
100+
99101
If <exec_size> is one: Execution jumps to the function if the predicate is true. The call mask will be initialized to all ones at function entry. Scalar calls must be marked with {NoMask}.
100102
101103
If <exec_size> is greater than one: The call is executed if any of the active channels are predicated. At function entry, the call mask will be initialized to the set of active channels that are predicated.

visa/BuildCISAIR.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,9 @@ class CISA_IR_Builder : public VISABuilder {
487487

488488
bool CISA_create_ifcall_instruction(VISA_opnd *pred_opnd,
489489
VISA_EMask_Ctrl emask, unsigned exec_size,
490-
VISA_opnd *funcAddr, unsigned arg_size,
491-
unsigned return_size, int lineNum);
490+
bool isUniform, VISA_opnd *funcAddr,
491+
unsigned arg_size, unsigned return_size,
492+
int lineNum);
492493

493494
bool CISA_create_faddr_instruction(const char *sym_name, VISA_opnd *dst,
494495
int lineNum);

visa/BuildCISAIRImpl.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,7 +1177,8 @@ void CISA_IR_Builder::LinkTimeOptimization(
11771177
auto orig_fcallinfo = callee->fg.builder->getFcallInfo(fret);
11781178
if (orig_fcallinfo) {
11791179
builder->addFcallInfo(inst, orig_fcallinfo->getArgSize(),
1180-
orig_fcallinfo->getRetSize());
1180+
orig_fcallinfo->getRetSize(),
1181+
orig_fcallinfo->isUniform());
11811182
}
11821183
}
11831184

@@ -1264,8 +1265,9 @@ void CISA_IR_Builder::LinkTimeOptimization(
12641265
if (inst->opcode() == G4_pseudo_fcall) {
12651266
auto orig_fcallinfo = callee->fg.builder->getFcallInfo(fret);
12661267
if (orig_fcallinfo) {
1267-
caller->fg.builder->addFcallInfo(inst, orig_fcallinfo->getArgSize(),
1268-
orig_fcallinfo->getRetSize());
1268+
caller->fg.builder->addFcallInfo(
1269+
inst, orig_fcallinfo->getArgSize(),
1270+
orig_fcallinfo->getRetSize(), orig_fcallinfo->isUniform());
12691271
}
12701272
}
12711273
for (int i = 0, numSrc = inst->getNumSrc(); i < numSrc; ++i) {
@@ -3593,12 +3595,13 @@ bool CISA_IR_Builder::CISA_create_fcall_instruction(
35933595

35943596
bool CISA_IR_Builder::CISA_create_ifcall_instruction(
35953597
VISA_opnd *pred_opnd, VISA_EMask_Ctrl emask, unsigned exec_size,
3596-
VISA_opnd *funcAddr, unsigned arg_size, unsigned return_size,
3598+
bool isUniform, VISA_opnd *funcAddr, unsigned arg_size,
3599+
unsigned return_size,
35973600
int lineNum) // last index
35983601
{
35993602
VISA_Exec_Size executionSize = Get_VISA_Exec_Size_From_Raw_Size(exec_size);
36003603
VISA_CALL_TO_BOOL(AppendVISACFIndirectFuncCallInst,
3601-
(VISA_PredOpnd *)pred_opnd, emask, executionSize,
3604+
(VISA_PredOpnd *)pred_opnd, emask, executionSize, isUniform,
36023605
(VISA_VectorOpnd *)funcAddr, (uint8_t)arg_size,
36033606
(uint8_t)return_size);
36043607
return true;

visa/BuildIR.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ class IR_Builder {
619619

620620
std::optional<G4_FCALL> getFcallInfo(const G4_INST *inst) const;
621621
void addFcallInfo(const G4_INST *FcallInst, uint16_t ArgSize,
622-
uint16_t RetSize) {
623-
m_fcallInfo.emplace(FcallInst, G4_FCALL(ArgSize, RetSize));
622+
uint16_t RetSize, bool isUniform) {
623+
m_fcallInfo.emplace(FcallInst, G4_FCALL(ArgSize, RetSize, isUniform));
624624
}
625625

626626
// If this is true (detected in TranslateInterface.cpp), we need a sampler
@@ -1573,8 +1573,9 @@ class IR_Builder {
15731573
uint8_t argSize, uint8_t returnSize);
15741574

15751575
int translateVISACFIFCallInst(VISA_Exec_Size execsize, VISA_EMask_Ctrl emask,
1576-
G4_Predicate *predOpnd, G4_Operand *funcAddr,
1577-
uint8_t argSize, uint8_t returnSize);
1576+
G4_Predicate *predOpnd, bool isUniform,
1577+
G4_Operand *funcAddr, uint8_t argSize,
1578+
uint8_t returnSize);
15781579

15791580
int translateVISACFSymbolInst(const std::string &symbolName,
15801581
G4_DstRegRegion *dst);

visa/ByteCodeReaderNG.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,12 +1194,13 @@ static void readInstructionControlFlow(unsigned &bytePos, const char *buf,
11941194
? readPredicateOperandNG(bytePos, buf, container)
11951195
: nullptr;
11961196

1197+
bool isUniform = false;
11971198
VISA_VectorOpnd *funcAddr =
11981199
readVectorOperandNG(bytePos, buf, container, false);
11991200
uint8_t argSize = readPrimitiveOperandNG<uint8_t>(bytePos, buf);
12001201
uint8_t retSize = readPrimitiveOperandNG<uint8_t>(bytePos, buf);
1201-
kernelBuilder->AppendVISACFIndirectFuncCallInst(pred, emask, esize,
1202-
funcAddr, argSize, retSize);
1202+
kernelBuilder->AppendVISACFIndirectFuncCallInst(
1203+
pred, emask, esize, isUniform, funcAddr, argSize, retSize);
12031204
return;
12041205
}
12051206
case ISA_FADDR: {

visa/CISA.l

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,11 @@ arg {return LSC_AM_ARG;}
12281228
return IDENT;
12291229
}
12301230

1231+
".uniform" {
1232+
TRACE("** UNIFORM");
1233+
CISAlval.string = strdup(yytext);
1234+
return UNIFORM;
1235+
}
12311236

12321237

12331238

visa/CISA.y

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ std::vector<attr_gen_struct*> AttrOptVar;
394394
%token NEWLINE
395395

396396

397+
%token UNIFORM
397398
%token <string> RTWRITE_OPTION
398399
%token <media_mode> MEDIA_MODE
399400
%token <oword_mod> OWORD_MODIFIER
@@ -2259,9 +2260,16 @@ BranchInstruction: Predicate BRANCH_OP ExecSize IdentOrStringLit
22592260
| Predicate IFCALL ExecSize VecSrcOperand_G_I_IMM DEC_LIT DEC_LIT
22602261
{
22612262
pBuilder->CISA_create_ifcall_instruction(
2262-
$1, $3.emask, $3.exec_size,
2263+
$1, $3.emask, $3.exec_size, false,
22632264
$4.cisa_gen_opnd, (unsigned)$5, (unsigned)$6, CISAlineno);
22642265
}
2266+
// 1 2 3 4 5 6 7
2267+
| Predicate IFCALL UNIFORM ExecSize VecSrcOperand_G_I_IMM DEC_LIT DEC_LIT
2268+
{
2269+
pBuilder->CISA_create_ifcall_instruction(
2270+
$1, $4.emask, $4.exec_size, true,
2271+
$5.cisa_gen_opnd, (unsigned)$6, (unsigned)$7, CISAlineno);
2272+
}
22652273
// 1 2 3
22662274
| FADDR IdentOrStringLit VecDstOperand_G_I
22672275
{

visa/G4_IR.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ class BinInst;
8787
class G4_FCALL {
8888
uint16_t argSize;
8989
uint16_t retSize;
90+
bool uniform = false;
9091

9192
public:
9293
G4_FCALL() = delete;
93-
G4_FCALL(uint16_t argVarSz, uint16_t retVarSz)
94-
: argSize(argVarSz), retSize(retVarSz) {}
94+
G4_FCALL(uint16_t argVarSz, uint16_t retVarSz, bool isUniform)
95+
: argSize(argVarSz), retSize(retVarSz), uniform(isUniform) {}
9596

9697
uint16_t getArgSize() const { return argSize; }
9798
uint16_t getRetSize() const { return retSize; }
99+
bool isUniform() const { return uniform; }
98100
};
99101

100102
// Forward references for classes used by G4_INST.

0 commit comments

Comments
 (0)