Skip to content

Commit e474c4e

Browse files
author
Tim Foley
authored
Add an accessor for IRInst opcode (shader-slang#1707)
* Add an accessor for IRInst opcode This main changing is renaming `IRInst::op` over to `IRInst::m_op` and then adds an accessor `IRInst::getOp()` to read it. The rest of the changes are just changing use sites to `getOp` (or to `m_op` in the limited cases where we write to it). This work is in anticipation of a future change that might need to store an extra bit in the same field as the opcode. It seemed better to do this massive refactoring as a separate PR. * fixup
1 parent 5777545 commit e474c4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+329
-327
lines changed

source/slang/slang-emit-c-like.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ void CLikeSourceEmitter::_emitUnsizedArrayType(IRUnsizedArrayType* arrayType, ED
274274

275275
void CLikeSourceEmitter::_emitType(IRType* type, EDeclarator* declarator)
276276
{
277-
switch (type->op)
277+
switch (type->getOp())
278278
{
279279
default:
280280
emitSimpleType(type);
@@ -774,7 +774,7 @@ void CLikeSourceEmitter::emitDeclarator(IRDeclaratorInfo* declarator)
774774

775775
void CLikeSourceEmitter::emitSimpleValueImpl(IRInst* inst)
776776
{
777-
switch(inst->op)
777+
switch(inst->getOp())
778778
{
779779
case kIROp_IntLit:
780780
{
@@ -880,7 +880,7 @@ void CLikeSourceEmitter::emitSimpleValueImpl(IRInst* inst)
880880
bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst)
881881
{
882882
// Certain opcodes should never/always be folded in
883-
switch( inst->op )
883+
switch( inst->getOp() )
884884
{
885885
default:
886886
break;
@@ -935,7 +935,7 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst)
935935
if(as<IRAttr>(inst))
936936
return true;
937937

938-
switch( inst->op )
938+
switch( inst->getOp() )
939939
{
940940
default:
941941
break;
@@ -1078,7 +1078,7 @@ bool CLikeSourceEmitter::shouldFoldInstIntoUseSites(IRInst* inst)
10781078
// definition for certain types on certain targets (e.g. `out TriangleStream<T>`
10791079
// for GLSL), so we check this only after all those special cases are
10801080
// considered.
1081-
if (inst->op == kIROp_undefined)
1081+
if (inst->getOp() == kIROp_undefined)
10821082
return false;
10831083

10841084
// Okay, at this point we know our instruction must have a single use.
@@ -1186,7 +1186,7 @@ void CLikeSourceEmitter::emitDereferenceOperand(IRInst* inst, EmitOpInfo const&
11861186
// emit its name. i.e. *&var ==> var.
11871187
// We apply this peep hole optimization here to reduce the clutter of
11881188
// resulting code.
1189-
if (inst->op == kIROp_Var)
1189+
if (inst->getOp() == kIROp_Var)
11901190
{
11911191
m_writer->emit(getName(inst));
11921192
return;
@@ -1230,7 +1230,7 @@ void CLikeSourceEmitter::emitOperandImpl(IRInst* inst, EmitOpInfo const& outerP
12301230
return;
12311231
}
12321232

1233-
switch(inst->op)
1233+
switch(inst->getOp())
12341234
{
12351235
case kIROp_Var:
12361236
case kIROp_GlobalVar:
@@ -1503,7 +1503,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
15031503
{
15041504
EmitOpInfo outerPrec = inOuterPrec;
15051505
bool needClose = false;
1506-
switch(inst->op)
1506+
switch(inst->getOp())
15071507
{
15081508
case kIROp_GlobalHashedStringLiterals:
15091509
/* Don't need to to output anything for this instruction - it's used for reflecting string literals that
@@ -1617,7 +1617,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
16171617
case kIROp_Geq:
16181618
case kIROp_Leq:
16191619
{
1620-
const auto emitOp = getEmitOpForOp(inst->op);
1620+
const auto emitOp = getEmitOpForOp(inst->getOp());
16211621

16221622
auto prec = getInfo(emitOp);
16231623
needClose = maybeEmitParens(outerPrec, prec);
@@ -1645,7 +1645,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
16451645
case kIROp_Or:
16461646
case kIROp_Mul:
16471647
{
1648-
const auto emitOp = getEmitOpForOp(inst->op);
1648+
const auto emitOp = getEmitOpForOp(inst->getOp());
16491649
const auto info = getInfo(emitOp);
16501650

16511651
needClose = maybeEmitParens(outerPrec, info);
@@ -1663,12 +1663,12 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
16631663
{
16641664
IRInst* operand = inst->getOperand(0);
16651665

1666-
const auto emitOp = getEmitOpForOp(inst->op);
1666+
const auto emitOp = getEmitOpForOp(inst->getOp());
16671667
const auto prec = getInfo(emitOp);
16681668

16691669
needClose = maybeEmitParens(outerPrec, prec);
16701670

1671-
switch (inst->op)
1671+
switch (inst->getOp())
16721672
{
16731673
case kIROp_BitNot:
16741674
{
@@ -1744,7 +1744,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
17441744
}
17451745
else
17461746
{
1747-
if (inst->op == kIROp_getElementPtr && doesTargetSupportPtrTypes())
1747+
if (inst->getOp() == kIROp_getElementPtr && doesTargetSupportPtrTypes())
17481748
{
17491749
const auto info = getInfo(EmitOp::Prefix);
17501750
needClose = maybeEmitParens(outerPrec, info);
@@ -1784,7 +1784,7 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
17841784
for (Index ee = 0; ee < elementCount; ++ee)
17851785
{
17861786
IRInst* irElementIndex = ii->getElementIndex(ee);
1787-
SLANG_RELEASE_ASSERT(irElementIndex->op == kIROp_IntLit);
1787+
SLANG_RELEASE_ASSERT(irElementIndex->getOp() == kIROp_IntLit);
17881788
IRConstant* irConst = (IRConstant*)irElementIndex;
17891789

17901790
UInt elementIndex = (UInt)irConst->value.intVal;
@@ -1988,7 +1988,7 @@ void CLikeSourceEmitter::_emitInst(IRInst* inst)
19881988

19891989
m_writer->advanceToSourceLocation(inst->sourceLoc);
19901990

1991-
switch(inst->op)
1991+
switch(inst->getOp())
19921992
{
19931993
default:
19941994
emitInstResultDecl(inst);
@@ -2057,7 +2057,7 @@ void CLikeSourceEmitter::_emitInst(IRInst* inst)
20572057
for (UInt ee = 0; ee < elementCount; ++ee)
20582058
{
20592059
IRInst* irElementIndex = ii->getElementIndex(ee);
2060-
SLANG_RELEASE_ASSERT(irElementIndex->op == kIROp_IntLit);
2060+
SLANG_RELEASE_ASSERT(irElementIndex->getOp() == kIROp_IntLit);
20612061
IRConstant* irConst = (IRConstant*)irElementIndex;
20622062

20632063
UInt elementIndex = (UInt)irConst->value.intVal;
@@ -2088,7 +2088,7 @@ void CLikeSourceEmitter::_emitInst(IRInst* inst)
20882088
for (UInt ee = 0; ee < elementCount; ++ee)
20892089
{
20902090
IRInst* irElementIndex = ii->getElementIndex(ee);
2091-
SLANG_RELEASE_ASSERT(irElementIndex->op == kIROp_IntLit);
2091+
SLANG_RELEASE_ASSERT(irElementIndex->getOp() == kIROp_IntLit);
20922092
IRConstant* irConst = (IRConstant*)irElementIndex;
20932093

20942094
UInt elementIndex = (UInt)irConst->value.intVal;
@@ -2398,7 +2398,7 @@ void CLikeSourceEmitter::emitRegion(Region* inRegion)
23982398
// them into the current block.
23992399
//
24002400
m_writer->advanceToSourceLocation(terminator->sourceLoc);
2401-
switch(terminator->op)
2401+
switch(terminator->getOp())
24022402
{
24032403
default:
24042404
// Don't do anything with the terminator, and assume
@@ -3231,7 +3231,7 @@ void CLikeSourceEmitter::emitGlobalInstImpl(IRInst* inst)
32313231
{
32323232
m_writer->advanceToSourceLocation(inst->sourceLoc);
32333233

3234-
switch(inst->op)
3234+
switch(inst->getOp())
32353235
{
32363236
case kIROp_GlobalHashedStringLiterals:
32373237
/* Don't need to to output anything for this instruction - it's used for reflecting string literals that
@@ -3304,7 +3304,7 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I
33043304

33053305
UInt operandCount = inst->operandCount;
33063306
auto requiredLevel = EmitAction::Definition;
3307-
if (inst->op == kIROp_InterfaceType)
3307+
if (inst->getOp() == kIROp_InterfaceType)
33083308
requiredLevel = EmitAction::ForwardDeclaration;
33093309

33103310
for(UInt ii = 0; ii < operandCount; ++ii)
@@ -3330,7 +3330,7 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I
33303330
void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst* inst, EmitAction::Level requiredLevel)
33313331
{
33323332
// Skip certain instructions that don't affect output.
3333-
switch(inst->op)
3333+
switch(inst->getOp())
33343334
{
33353335
case kIROp_Generic:
33363336
return;
@@ -3373,7 +3373,7 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst
33733373
ctx->mapInstToLevel[inst] = requiredLevel;
33743374

33753375
// Skip instructions that don't correspond to an independent entity in output.
3376-
switch (inst->op)
3376+
switch (inst->getOp())
33773377
{
33783378
case kIROp_InterfaceRequirementEntry:
33793379
return;

0 commit comments

Comments
 (0)