Skip to content

Commit 6a2bea0

Browse files
DianaChenigcbot
authored andcommitted
Remove FCall to Call convertion and re-convertion
Remain G4_pseudo_fcall operand and lower it to Gen call instruction at encoder to avoid conversion and recovertion between FCall and Call.
1 parent b983e86 commit 6a2bea0

File tree

9 files changed

+35
-68
lines changed

9 files changed

+35
-68
lines changed

visa/BinaryEncoding.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,8 +1557,9 @@ BinaryEncoding::Status BinaryEncoding::EncodeOperandDst(G4_INST* inst)
15571557
inline BinaryEncoding::Status BinaryEncoding::EncodeOperandSrc0(G4_INST* inst)
15581558
{
15591559
Status myStatus = SUCCESS;
1560-
if (inst->isLabel() ||
1561-
inst->isCall())
1560+
if (inst->isLabel() ||
1561+
inst->isCall() ||
1562+
inst->isFCall())
15621563
return myStatus;
15631564

15641565
if (inst->isSplitSend())
@@ -3168,7 +3169,7 @@ bool BinaryEncoding::EncodeConditionalBranches(G4_INST *inst,
31683169
}
31693170
}
31703171

3171-
if (op == G4_call && inst->getSrc(0))
3172+
if ((op == G4_call || op == G4_pseudo_fcall) && inst->getSrc(0))
31723173
{
31733174

31743175
if (inst->getSrc(0)->isLabel())

visa/BinaryEncoding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -819,13 +819,13 @@ namespace vISA
819819
}
820820

821821
// ToDo: disable compacting nop/return until it is clear that we can compact them
822-
if (op == G4_nop || op == G4_return)
822+
if (op == G4_nop || op == G4_return || op == G4_pseudo_fret)
823823
{
824824
return false;
825825
}
826826

827827
// temporary WA, to be removed later
828-
if (op == G4_call)
828+
if (op == G4_call || op == G4_pseudo_fcall)
829829
{
830830
return false;
831831
}

visa/BinaryEncodingCNL.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ uint32_t BinaryEncodingBase::getEUOpcode(G4_opcode g4opc)
105105
case G4_brd: euopcode = G9HDL::EU_OPCODE_BRD; break;
106106
case G4_break: euopcode = G9HDL::EU_OPCODE_BREAK; break;
107107
case G4_call: euopcode = G9HDL::EU_OPCODE_CALL; break;
108+
case G4_pseudo_fcall: euopcode = G9HDL::EU_OPCODE_CALL; break;
108109
//case G4_calla: euopcode = G9HDL::EU_OPCODE_CALLA; break;
109110
case G4_cont: euopcode = G9HDL::EU_OPCODE_CONT; break;
110111
case G4_else: euopcode = G9HDL::EU_OPCODE_ELSE; break;
@@ -114,7 +115,10 @@ uint32_t BinaryEncodingBase::getEUOpcode(G4_opcode g4opc)
114115
case G4_if: euopcode = G9HDL::EU_OPCODE_IF; break;
115116
case G4_jmpi: euopcode = G9HDL::EU_OPCODE_JMPI; break;
116117
case G4_join: euopcode = G9HDL::EU_OPCODE_JOIN; break;
117-
case G4_return: euopcode = G9HDL::EU_OPCODE_RET; break;
118+
case G4_return:
119+
case G4_pseudo_fret:
120+
euopcode = G9HDL::EU_OPCODE_RET;
121+
break;
118122
case G4_wait: euopcode = G9HDL::EU_OPCODE_WAIT; break;
119123
case G4_while: euopcode = G9HDL::EU_OPCODE_WHILE; break;
120124

@@ -1744,8 +1748,8 @@ bool BinaryEncodingCNL::EncodeConditionalBranches(G4_INST *inst,
17441748
}
17451749
}
17461750

1747-
if (op == G4_call &&
1748-
inst->getSrc(0) &&
1751+
if ((op == G4_call || op == G4_pseudo_fcall) &&
1752+
inst->getSrc(0) &&
17491753
inst->getSrc(0)->isLabel())
17501754
{
17511755
G4_Operand *opnd = inst->getSrc(0);
@@ -2389,7 +2393,7 @@ BinaryEncodingCNL::Status BinaryEncodingCNL::DoAllEncoding(G4_INST* inst)
23892393
{
23902394
DoAllEncodingCF(inst);
23912395
}
2392-
else if (inst->opcode() == G4_call)
2396+
else if (inst->opcode() == G4_call || inst->opcode() == G4_pseudo_fcall)
23932397
{
23942398
DoAllEncodingCALL(inst);
23952399
}

visa/BinaryEncodingIGA.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,15 @@ std::pair<iga::Op,iga::Subfunction> BinaryEncodingIGA::getIgaOpInfo(
263263
case G4_break: igaOp = iga::Op::BREAK; break;
264264
case G4_cont: igaOp = iga::Op::CONT; break;
265265
case G4_halt: igaOp = iga::Op::HALT; break;
266-
case G4_call: igaOp = iga::Op::CALL; break;
267-
case G4_return: igaOp = iga::Op::RET; break;
266+
case G4_call:
267+
case G4_pseudo_fcall:
268+
//TODO: select calla for indirect call
269+
igaOp = iga::Op::CALL;
270+
break;
271+
case G4_return:
272+
case G4_pseudo_fret:
273+
igaOp = iga::Op::RET;
274+
break;
268275
case G4_goto: igaOp = iga::Op::GOTO; break;
269276
case G4_join: igaOp = iga::Op::JOIN; break;
270277
case G4_wait:
@@ -352,8 +359,6 @@ std::pair<iga::Op,iga::Subfunction> BinaryEncodingIGA::getIgaOpInfo(
352359
case G4_pseudo_or: igaOp = iga::Op::OR; break;
353360
case G4_pseudo_xor: igaOp = iga::Op::XOR; break;
354361
case G4_pseudo_not: igaOp = iga::Op::NOT; break;
355-
case G4_pseudo_fcall: igaOp = iga::Op::CALL; break;
356-
case G4_pseudo_fret: igaOp = iga::Op::RET; break;
357362
case G4_pseudo_sada2: igaOp = iga::Op::SADA2; break;
358363
case G4_pseudo_exit:
359364
ASSERT_USER(!allowUnknownOp, "G4_pseudo_exit not GEN ISA OPCODE.");

visa/BuildCISAIRImpl.cpp

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -404,20 +404,13 @@ int CISA_IR_Builder::AddFunction(VISAFunction *& function, const char* functionN
404404
void restoreFCallState(
405405
G4_Kernel* kernel, const std::map<G4_BB*, G4_INST*>& savedFCallState)
406406
{
407-
// Iterate over all BBs in kernel and fix all fcalls converted
408-
// to calls by reconverting them to fcall. This is required
409-
// because we want to reuse IR of function for next kernel.
410-
407+
// Iterate over all BBs in kernel and clean up the edges.
408+
// FIXME: do we need to do this still?
411409
for (auto&& iter : savedFCallState)
412410
{
413411
auto curBB = iter.first;
414-
auto genOffset = curBB->back()->getGenOffset();
415-
curBB->pop_back();
416412
auto origInst = iter.second;
417413
assert(origInst->isFCall() || origInst->isFReturn());
418-
curBB->push_back(origInst);
419-
// set the genOffset in case of GenOffset being used when creating symbol table
420-
origInst->setGenOffset(genOffset);
421414

422415
if (origInst->isFCall() && !origInst->asCFInst()->isIndirectCall())
423416
{
@@ -447,7 +440,6 @@ void restoreFCallState(
447440

448441
// Stitch the FG of subFunctions to mainFunc
449442
// mainFunc could be a kernel or a non-kernel function.
450-
// It also modifies pseudo_fcall/fret in to call/ret opcodes.
451443
// ToDo: may consider stitching only functions that may be called by this kernel/function
452444
static void Stitch_Compiled_Units(
453445
G4_Kernel* mainFunc, std::map<std::string, G4_Kernel*>& subFuncs,
@@ -471,8 +463,7 @@ static void Stitch_Compiled_Units(
471463
mainFunc->fg.reassignBlockIDs();
472464
mainFunc->fg.setPhysicalPredSucc(); // this is to locate the next BB after an fcall
473465

474-
auto builder = mainFunc->fg.builder;
475-
// Change fcall/fret to call/ret and setup caller/callee edges
466+
// setup caller/callee edges
476467
for (G4_BB* cur : mainFunc->fg)
477468
{
478469
if (cur->isEndWithFCall())
@@ -500,47 +491,11 @@ static void Stitch_Compiled_Units(
500491
// Connect new fg
501492
mainFunc->fg.addPredSuccEdges(cur, callee->fg.getEntryBB());
502493
mainFunc->fg.addPredSuccEdges(callee->fg.getUniqueReturnBlock(), retBlock);
503-
504-
G4_INST* calleeLabel = callee->fg.getEntryBB()->front();
505-
ASSERT_USER(calleeLabel->isLabel() == true, "Entry inst is not label");
506-
507-
auto callInst = builder->createInternalInst(
508-
fcall->getPredicate(), G4_call, nullptr, g4::NOSAT, fcall->getExecSize(),
509-
fcall->getDst(), calleeLabel->getSrc(0), fcall->getSrc(0), fcall->getOption());
510-
callInst->inheritDIFrom(fcall);
511-
cur->pop_back();
512-
cur->push_back(callInst);
513-
}
514-
else
515-
{
516-
// src0 is dont care for indirect call as long it's not a label
517-
auto callInst = builder->createInternalInst(
518-
fcall->getPredicate(), G4_call, nullptr, g4::NOSAT, fcall->getExecSize(),
519-
fcall->getDst(), fcall->getSrc(0), fcall->getSrc(0), fcall->getOption());
520-
callInst->inheritDIFrom(fcall);
521-
cur->pop_back();
522-
cur->push_back(callInst);
523494
}
524495
FCallRetMap[cur] = fcall;
525496
}
526497
}
527498

528-
// Change fret to ret
529-
for (G4_BB* cur : mainFunc->fg)
530-
{
531-
if (cur->isEndWithFRet())
532-
{
533-
G4_INST* fret = cur->back();
534-
auto retInst = builder->createInternalInst(
535-
fret->getPredicate(), G4_return, nullptr, g4::NOSAT, fret->getExecSize(),
536-
builder->createNullDst(Type_UD), fret->getSrc(0), fret->getSrc(1), fret->getOption());
537-
retInst->inheritDIFrom(fret);
538-
cur->pop_back();
539-
cur->push_back(retInst);
540-
FCallRetMap[cur] = fret;
541-
}
542-
}
543-
544499
// Append declarations and color attributes from all callees to mainFunc
545500
for (auto iter : subFuncs)
546501
{

visa/Common_BinaryEncoding.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ namespace vISA
15961596
op == G4_halt ||
15971597
op == G4_endif)
15981598
return true;
1599-
else if (op == G4_call &&
1599+
else if ((op == G4_call || op == G4_pseudo_fcall) &&
16001600
inst->getSrc(0) &&
16011601
inst->getSrc(0)->isLabel())
16021602
{
@@ -2289,7 +2289,7 @@ namespace vISA
22892289
// temporary WA, to be removed later
22902290
// we disable compacting nop/return
22912291
// until it is clear that we can compact them
2292-
if (op == G4_call || op == G4_return)
2292+
if (op == G4_call || op == G4_pseudo_fcall || op == G4_return || op == G4_pseudo_fret)
22932293
{
22942294
return false;
22952295
}

visa/LocalScheduler/SWSB_G4IR.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ void SWSB::SWSBBuildSIMDCFG()
531531
}
532532
}
533533
}
534-
else if (lastInst->isReturn() || lastInst->isCall())
534+
else if (lastInst->isReturn() || lastInst->isCall() || lastInst->isFCall() || lastInst->isFReturn())
535535
{
536536
BB_LIST_ITER iter = currBB->getBB()->Succs.begin();
537537
while (iter != currBB->getBB()->Succs.end())
@@ -671,7 +671,8 @@ void SWSB::handleIndirectCall()
671671
SBNode* node = SBNodes[BBVector[i]->last_node];
672672

673673
if ((node->GetInstruction()->isCall() && !node->GetInstruction()->getSrc(0)->isLabel()) ||
674-
node->GetInstruction()->isReturn())
674+
node->GetInstruction()->isReturn() ||
675+
node->GetInstruction()->isFReturn())
675676
{
676677
LiveGRFBuckets send_use_out(mem, kernel.getNumRegTotal(), *fg.getKernel());
677678
for (size_t j = 0; j < globalSendOpndList.size(); j++)
@@ -692,7 +693,7 @@ void SWSB::handleIndirectCall()
692693
}
693694
}
694695
}
695-
if (node->GetInstruction()->isReturn())
696+
if (node->GetInstruction()->isReturn() || node->GetInstruction()->isFReturn())
696697
{
697698
node->GetInstruction()->setDistance(1);
698699
}
@@ -999,6 +1000,7 @@ static bool isBranch(SBNode* N) {
9991000
return false;
10001001
// Skip function call/ret.
10011002
if (Inst->isCall() || Inst->isReturn() ||
1003+
Inst->isFCall() || Inst->isFReturn() ||
10021004
Inst->opcode() == G4_pseudo_fc_call ||
10031005
Inst->opcode() == G4_pseudo_fc_ret)
10041006
return false;

visa/Optimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7578,7 +7578,7 @@ bool Optimizer::foldPseudoAndOr(G4_BB* bb, INST_LIST_ITER& ii)
75787578
// check every fcall
75797579
for (auto bb : kernel.fg)
75807580
{
7581-
if (bb->back()->isFCall())
7581+
if (bb->isEndWithFCall())
75827582
{
75837583
G4_INST* fcall = bb->back();
75847584
if (fcall->getSrc(0)->isGreg() || fcall->getSrc(0)->isA0()) {

visa/VISAKernelImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ void VISAKernelImpl::adjustIndirectCallOffset()
273273
continue;
274274

275275
// At this point G4_pseudo_fcall may be converted to G4_call
276-
if (bb->back()->isCall() || bb->back()->isFCall())
276+
if (bb->isEndWithCall() || bb->isEndWithFCall())
277277
{
278278
G4_INST* fcall = bb->back();
279279
if (fcall->getSrc(0)->isGreg() || fcall->getSrc(0)->isA0())

0 commit comments

Comments
 (0)