Skip to content

Commit 3a50a35

Browse files
sys-igcigcbot
authored andcommitted
Changes in code.
1 parent 4763e9c commit 3a50a35

File tree

2 files changed

+71
-32
lines changed

2 files changed

+71
-32
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ void CShader::InitializeStackVariables()
283283
// create argument-value register, limited to 12 GRF
284284
m_ARGV = GetNewVariable(getGRFSize() * 3, ISA_TYPE_D, getGRFAlignment(), false, 1, "ARGV");
285285
encoder.GetVISAPredefinedVar(m_ARGV, PREDEFINED_ARG);
286-
// create return-value register, limited to 8 GRF
287-
m_RETV = GetNewVariable(getGRFSize() * 2, ISA_TYPE_D, getGRFAlignment(), false, 1, "RETV");
286+
// create return-value register, limited to 4 GRF
287+
m_RETV = GetNewVariable(getGRFSize(), ISA_TYPE_D, getGRFAlignment(), false, 1, "ReturnValue");
288288
encoder.GetVISAPredefinedVar(m_RETV, PREDEFINED_RET);
289289
// create stack-pointer register
290290
m_SP = GetNewVariable(1, ISA_TYPE_UQ, EALIGN_QWORD, true, 1, "SP");

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11819,6 +11819,23 @@ void EmitPass::emitStackCall(llvm::CallInst* inst)
1181911819
if (argIter->use_empty()) continue;
1182011820
}
1182111821

11822+
if (Src->GetType() == ISA_TYPE_BOOL)
11823+
{
11824+
// bool args are treated as a vector of WORDs
11825+
uint nElts = numLanes(m_currShader->m_dispatchSize);
11826+
CVariable* ReplaceArg = m_currShader->GetNewVariable(
11827+
nElts,
11828+
ISA_TYPE_W,
11829+
EALIGN_HWORD, false, 1,
11830+
CName::NONE);
11831+
CVariable* one = m_currShader->ImmToVariable(1, ISA_TYPE_W);
11832+
CVariable* zero = m_currShader->ImmToVariable(0, ISA_TYPE_W);
11833+
m_encoder->Select(Src, ReplaceArg, one, zero);
11834+
11835+
argType = IntegerType::getInt16Ty(inst->getContext());
11836+
Src = ReplaceArg;
11837+
}
11838+
1182211839
// adjust offset for alignment
1182311840
uint align = getGRFSize();
1182411841
offsetA = int_cast<unsigned>(llvm::alignTo(offsetA, align));
@@ -11852,10 +11869,21 @@ void EmitPass::emitStackCall(llvm::CallInst* inst)
1185211869
// Write all arguments that does not fit in GRF to stack
1185311870
offsetS = emitStackArgumentLoadOrStore(argsOnStack, true);
1185411871

11855-
CVariable* RetV = GetSymbol(inst);
11856-
uint retSize = RetV->GetSize() <= m_currShader->GetRETV()->GetSize() ?
11857-
RetV->GetSize() : // return on GRF
11858-
0; // return on Stack
11872+
uint retSize = 0;
11873+
if (!inst->use_empty())
11874+
{
11875+
CVariable* Dst = GetSymbol(inst);
11876+
if (Dst->GetType() == ISA_TYPE_BOOL)
11877+
{
11878+
retSize = numLanes(m_currShader->m_dispatchSize) * SIZE_WORD;
11879+
}
11880+
else
11881+
{
11882+
retSize = Dst->GetSize();
11883+
}
11884+
CVariable* Src = m_currShader->GetRETV();
11885+
IGC_ASSERT_MESSAGE(retSize <= Src->GetSize(), "No support for return on stack!");
11886+
}
1185911887

1186011888
unsigned char argSizeInGRF = (offsetA + getGRFSize() - 1) / getGRFSize();
1186111889
unsigned char retSizeInGRF = (retSize + getGRFSize() - 1) / getGRFSize();
@@ -11878,26 +11906,25 @@ void EmitPass::emitStackCall(llvm::CallInst* inst)
1187811906
// lambda to read the return value
1187911907
auto CopyReturnValue = [this](CallInst* inst)->void
1188011908
{
11909+
// No need to copy if there are no uses
11910+
if (inst->use_empty())
11911+
return;
11912+
1188111913
CVariable* Dst = GetSymbol(inst);
1188211914
CVariable* Src = m_currShader->GetRETV();
11883-
bool returnOnGRF = Dst->GetSize() <= Src->GetSize();
11884-
11885-
if (returnOnGRF)
11915+
if (Dst->GetType() == ISA_TYPE_BOOL)
1188611916
{
11887-
if (!inst->use_empty())
11888-
{
11889-
// Copy from return GRF
11890-
if (Dst->GetType() != Src->GetType() || Src->IsUniform() != Dst->IsUniform())
11891-
{
11892-
Src = m_currShader->GetNewAlias(Src, Dst->GetType(), 0, Dst->GetNumberElement(), Dst->IsUniform());
11893-
}
11894-
emitCopyAll(Dst, Src, inst->getType());
11895-
}
11917+
CVariable* SrcAlias = m_currShader->GetNewAlias(Src, ISA_TYPE_W, 0, numLanes(m_currShader->m_dispatchSize), false);
11918+
m_encoder->Cmp(EPREDICATE_NE, Dst, SrcAlias, m_currShader->ImmToVariable(0, ISA_TYPE_W));
1189611919
}
1189711920
else
1189811921
{
11899-
// Copy from stack
11900-
IGC_ASSERT_MESSAGE(0, "Does not yet support return on stack");
11922+
IGC_ASSERT(Dst->GetSize() <= Src->GetSize());
11923+
if (Dst->GetType() != Src->GetType() || Src->IsUniform() != Dst->IsUniform())
11924+
{
11925+
Src = m_currShader->GetNewAlias(Src, Dst->GetType(), 0, Dst->GetNumberElement(), Dst->IsUniform());
11926+
}
11927+
emitCopyAll(Dst, Src, inst->getType());
1190111928
}
1190211929
};
1190311930

@@ -12023,15 +12050,23 @@ void EmitPass::emitStackFuncEntry(Function* F)
1202312050
uint align = getGRFSize();
1202412051
offsetA = int_cast<unsigned>(llvm::alignTo(offsetA, align));
1202512052
uint argSize = Dst->GetSize();
12026-
12053+
if (Dst->GetType() == ISA_TYPE_BOOL)
12054+
{
12055+
argSize = numLanes(m_currShader->m_dispatchSize) * SIZE_WORD;
12056+
}
1202712057
// check if an argument can be written to ARGV based upon offset + arg-size
1202812058
bool overflow = ((offsetA + argSize) > ArgBlkVar->GetSize());
1202912059
if (!overflow)
1203012060
{
1203112061
if (!Arg.use_empty())
1203212062
{
1203312063
CVariable* Src = ArgBlkVar;
12034-
if (m_FGA->isLeafFunc(F))
12064+
if (Dst->GetType() == ISA_TYPE_BOOL)
12065+
{
12066+
Src = m_currShader->GetNewAlias(ArgBlkVar, ISA_TYPE_W, (uint16_t)offsetA, numLanes(m_currShader->m_dispatchSize), false);
12067+
m_encoder->Cmp(EPREDICATE_NE, Dst, Src, m_currShader->ImmToVariable(0, ISA_TYPE_W));
12068+
}
12069+
else if (m_FGA->isLeafFunc(F))
1203512070
{
1203612071
// Directly map the dst register to an alias of ArgBlkVar, and update symbol mapping for future uses
1203712072
Dst = m_currShader->GetNewAlias(ArgBlkVar, Dst->GetType(), (uint16_t)offsetA, Dst->GetNumberElement(), Dst->IsUniform());
@@ -12094,25 +12129,29 @@ void EmitPass::emitStackFuncExit(llvm::ReturnInst* inst)
1209412129
unsigned RetSize = 0;
1209512130
unsigned nLanes = numLanes(m_currShader->m_dispatchSize);
1209612131
CVariable* Src = GetSymbol(inst->getReturnValue());
12097-
bool isSrcUniform = Src->IsUniform();
12098-
RetSize = isSrcUniform ? nLanes * Src->GetSize() : Src->GetSize();
1209912132

12100-
if (RetSize <= Dst->GetSize())
12133+
if (Src->GetType() == ISA_TYPE_BOOL)
12134+
{
12135+
CVariable* one = m_currShader->ImmToVariable(1, ISA_TYPE_W);
12136+
CVariable* zero = m_currShader->ImmToVariable(0, ISA_TYPE_W);
12137+
CVariable* DstAlias = m_currShader->GetNewAlias(Dst, ISA_TYPE_W, 0, nLanes, false);
12138+
m_encoder->Select(Src, DstAlias, one, zero);
12139+
RetSize = nLanes * SIZE_WORD;
12140+
}
12141+
else
1210112142
{
12102-
// Return on GRF
12143+
bool isSrcUniform = Src->IsUniform();
12144+
RetSize = isSrcUniform ? nLanes * Src->GetSize() : Src->GetSize();
12145+
IGC_ASSERT_MESSAGE(RetSize <= Dst->GetSize(), "No support for return on stack!");
12146+
1210312147
if (Dst->GetType() != Src->GetType() || Dst->IsUniform() != Src->IsUniform())
1210412148
{
1210512149
unsigned elements = isSrcUniform ? Src->GetNumberElement() * nLanes : Src->GetNumberElement();
1210612150
Dst = m_currShader->GetNewAlias(Dst, Src->GetType(), 0, elements, false);
1210712151
}
1210812152
emitCopyAll(Dst, Src, RetTy);
12109-
m_encoder->SetStackFunctionRetSize((RetSize + getGRFSize() - 1) / getGRFSize());
12110-
}
12111-
else
12112-
{
12113-
// Return on Stack
12114-
IGC_ASSERT_MESSAGE(0, "Does not yet support return on stack");
1211512153
}
12154+
m_encoder->SetStackFunctionRetSize((RetSize + getGRFSize() - 1) / getGRFSize());
1211612155
}
1211712156
else
1211812157
{

0 commit comments

Comments
 (0)