Skip to content

Commit

Permalink
amdilc: store begin labels for branches and for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Cherser-s committed Jul 22, 2022
1 parent a4af134 commit ac92c58
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/amdilc/amdilc_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ typedef struct {
} IlcSampler;

typedef struct {
IlcSpvId labelBeginId;
IlcSpvId labelElseId;
IlcSpvId labelEndId;
bool hasElseBlock;
} IlcIfElseBlock;

typedef struct {
IlcSpvId labelBeginId;
IlcSpvId labelHeaderId;
IlcSpvId labelContinueId;
IlcSpvId labelBreakId;
Expand Down Expand Up @@ -147,6 +149,7 @@ typedef struct {
IlcSampler* samplers;
unsigned controlFlowBlockCount;
IlcControlFlowBlock* controlFlowBlocks;
IlcSpvId currentFunctionLabelId;
unsigned forkPhaseCount;
IlcHullPhaseBlock* forkPhases;
unsigned joinPhaseCount;
Expand Down Expand Up @@ -1799,7 +1802,7 @@ static void emitFunc(
IlcSpvId voidTypeId = ilcSpvPutVoidType(compiler->module);
IlcSpvId funcTypeId = ilcSpvPutFunctionType(compiler->module, voidTypeId, 0, NULL);
ilcSpvPutFunction(compiler->module, voidTypeId, id, SpvFunctionControlMaskNone, funcTypeId);
ilcSpvPutLabel(compiler->module, 0);
compiler->currentFunctionLabelId = ilcSpvPutLabel(compiler->module, 0);
}

static IlcHullPhaseBlock emitHullForkJoinFunction(
Expand All @@ -1810,7 +1813,7 @@ static IlcHullPhaseBlock emitHullForkJoinFunction(
IlcSpvId funcTypeId = ilcSpvPutFunctionType(compiler->module, voidTypeId, 1, &compiler->intId);
ilcSpvPutFunction(compiler->module, voidTypeId, funcId, SpvFunctionControlMaskNone, funcTypeId);
IlcSpvId paramId = ilcSpvPutFunctionParameter(compiler->module, compiler->intId);
ilcSpvPutLabel(compiler->module, 0);//TODO: handle IL_REGTYPE_SHADER_INSTANCE_ID
compiler->currentFunctionLabelId = ilcSpvPutLabel(compiler->module, 0);//TODO: handle IL_REGTYPE_SHADER_INSTANCE_ID
compiler->isInFunction = true;
return (IlcHullPhaseBlock) {
.functionId = funcId,
Expand Down Expand Up @@ -1864,7 +1867,7 @@ static void emitHullShaderPhase(
IlcSpvId voidTypeId = ilcSpvPutVoidType(compiler->module);
IlcSpvId funcTypeId = ilcSpvPutFunctionType(compiler->module, voidTypeId, 0, NULL);
ilcSpvPutFunction(compiler->module, voidTypeId, functionId, SpvFunctionControlMaskNone, funcTypeId);
ilcSpvPutLabel(compiler->module, 0);
compiler->currentFunctionLabelId = ilcSpvPutLabel(compiler->module, 0);
compiler->isInFunction = true;
compiler->controlPointPhase = (IlcHullPhaseBlock){
.type = CONTROL_POINT,
Expand Down Expand Up @@ -2524,17 +2527,17 @@ static void emitIf(
const Instruction* instr)
{
const IlcIfElseBlock ifElseBlock = {
.labelBeginId = ilcSpvAllocId(compiler->module),
.labelElseId = ilcSpvAllocId(compiler->module),
.labelEndId = ilcSpvAllocId(compiler->module),
.hasElseBlock = false,
};

IlcSpvId srcId = loadSource(compiler, &instr->srcs[0], COMP_MASK_XYZW, compiler->int4Id);
IlcSpvId labelBeginId = ilcSpvAllocId(compiler->module);
IlcSpvId condId = emitConditionCheck(compiler, srcId, instr->opcode == IL_OP_IF_LOGICALNZ);
ilcSpvPutSelectionMerge(compiler->module, ifElseBlock.labelEndId);
ilcSpvPutBranchConditional(compiler->module, condId, labelBeginId, ifElseBlock.labelElseId);
ilcSpvPutLabel(compiler->module, labelBeginId);
ilcSpvPutBranchConditional(compiler->module, condId, ifElseBlock.labelBeginId, ifElseBlock.labelElseId);
ilcSpvPutLabel(compiler->module, ifElseBlock.labelBeginId);

const IlcControlFlowBlock block = {
.type = BLOCK_IF_ELSE,
Expand Down Expand Up @@ -2597,6 +2600,7 @@ static void emitWhile(
const Instruction* instr)
{
const IlcLoopBlock loopBlock = {
.labelBeginId = ilcSpvAllocId(compiler->module),
.labelHeaderId = ilcSpvAllocId(compiler->module),
.labelContinueId = ilcSpvAllocId(compiler->module),
.labelBreakId = ilcSpvAllocId(compiler->module),
Expand All @@ -2607,9 +2611,8 @@ static void emitWhile(

ilcSpvPutLoopMerge(compiler->module, loopBlock.labelBreakId, loopBlock.labelContinueId);

IlcSpvId labelBeginId = ilcSpvAllocId(compiler->module);
ilcSpvPutBranch(compiler->module, labelBeginId);
ilcSpvPutLabel(compiler->module, labelBeginId);
ilcSpvPutBranch(compiler->module, loopBlock.labelBeginId);
ilcSpvPutLabel(compiler->module, loopBlock.labelBeginId);

const IlcControlFlowBlock block = {
.type = BLOCK_LOOP,
Expand Down Expand Up @@ -4281,6 +4284,7 @@ IlcShader ilcCompileKernel(
.samplers = NULL,
.controlFlowBlockCount = 0,
.controlFlowBlocks = NULL,
.currentFunctionLabelId = 0,
.forkPhaseCount = 0,
.forkPhases = NULL,
.forkPhaseCount = 0,
Expand Down

0 comments on commit ac92c58

Please sign in to comment.