summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2023-08-26 01:42:34 +0800
committerGitHub <noreply@github.com>2023-08-25 10:42:34 -0700
commitef4c9f1f1c297f1a33be95795a7a7561e0cc3bde (patch)
tree9ea81689432040905772aeec447adad88f212e01 /source/slang/slang-ir.cpp
parent036abc85ba1db9c8c06289f0a0492e9a95a228b9 (diff)
Initial version of spirv_asm block (#3151)
* Initial version of spirv_asm block * Correct indentation of parent instruction dumping * neater dumping for spirv_asm instructions * Add $$ DollarDollar token * Allow passing addresses to spirv_asm blocks * spirv OpUndef * String literals in spirv asm * OpName for spirv_asm ids * Correct failure in lower spirv_asm * correct position for spirv_asm idents * comment correct * several more tests for spirv_asm blocks * Fill out some unimplemented functions for spirv_asm expressions --------- Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source/slang/slang-ir.cpp')
-rw-r--r--source/slang/slang-ir.cpp103
1 files changed, 102 insertions, 1 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index 181970632..91a21754d 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -5664,6 +5664,84 @@ namespace Slang
return inst;
}
+ IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandLiteral(IRInst* literal)
+ {
+ SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent()));
+ const auto i = createInst<IRSPIRVAsmOperand>(
+ this,
+ kIROp_SPIRVAsmOperandLiteral,
+ literal->getFullType(),
+ literal
+ );
+ addInst(i);
+ return i;
+ }
+
+ IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandInst(IRInst* inst)
+ {
+ SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent()));
+ const auto i = createInst<IRSPIRVAsmOperand>(
+ this,
+ kIROp_SPIRVAsmOperandInst,
+ inst->getFullType(),
+ inst
+ );
+ addInst(i);
+ return i;
+ }
+
+ IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandId(IRInst* inst)
+ {
+ SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent()));
+ const auto i = createInst<IRSPIRVAsmOperand>(
+ this,
+ kIROp_SPIRVAsmOperandId,
+ inst->getFullType(),
+ inst
+ );
+ addInst(i);
+ return i;
+ }
+
+ IRSPIRVAsmOperand* IRBuilder::emitSPIRVAsmOperandEnum(IRInst* inst)
+ {
+ SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent()));
+ const auto i = createInst<IRSPIRVAsmOperand>(
+ this,
+ kIROp_SPIRVAsmOperandEnum,
+ inst->getFullType(),
+ inst
+ );
+ addInst(i);
+ return i;
+ }
+
+ IRSPIRVAsmInst* IRBuilder::emitSPIRVAsmInst(IRInst* opcode, List<IRInst*> operands)
+ {
+ SLANG_ASSERT(as<IRSPIRVAsm>(m_insertLoc.getParent()));
+ operands.insert(0, opcode);
+ const auto i = createInst<IRSPIRVAsmInst>(
+ this,
+ kIROp_SPIRVAsmInst,
+ getVoidType(),
+ operands.getCount(),
+ operands.getBuffer()
+ );
+ addInst(i);
+ return i;
+ }
+
+ IRSPIRVAsm* IRBuilder::emitSPIRVAsm(IRType* type)
+ {
+ const auto asmInst = createInst<IRSPIRVAsm>(
+ this,
+ kIROp_SPIRVAsm,
+ type
+ );
+ addInst(asmInst);
+ return asmInst;
+ }
+
//
// Decorations
//
@@ -6158,6 +6236,9 @@ namespace Slang
if(as<IRType>(inst))
return true;
+ if(as<IRSPIRVAsmOperand>(inst))
+ return true;
+
return false;
}
@@ -6370,7 +6451,6 @@ namespace Slang
{
auto opInfo = getIROpInfo(inst->getOp());
- dumpIndent(context);
dump(context, opInfo.name);
dump(context, " ");
dumpID(context, inst);
@@ -6398,6 +6478,7 @@ namespace Slang
}
context->indent--;
+ dumpIndent(context);
dump(context, "}\n");
}
@@ -6468,6 +6549,25 @@ namespace Slang
}
}
+ // Special case the SPIR-V asm operands as the distinction here is
+ // clear anyway to the user
+ switch(op)
+ {
+ case kIROp_SPIRVAsmOperandEnum:
+ dumpInstExpr(context, inst->getOperand(0));
+ return;
+ case kIROp_SPIRVAsmOperandLiteral:
+ dumpInstExpr(context, inst->getOperand(0));
+ return;
+ case kIROp_SPIRVAsmOperandInst:
+ dumpInstExpr(context, inst->getOperand(0));
+ return;
+ case kIROp_SPIRVAsmOperandId:
+ dump(context, "%");
+ dumpInstExpr(context, inst->getOperand(0));
+ return;
+ }
+
dump(context, opInfo.name);
dumpInstOperandList(context, inst);
}
@@ -6501,6 +6601,7 @@ namespace Slang
case kIROp_WitnessTable:
case kIROp_StructType:
+ case kIROp_SPIRVAsm:
dumpIRParentInst(context, inst);
return;