summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-util.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-util.cpp')
-rw-r--r--source/slang/slang-ir-util.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/source/slang/slang-ir-util.cpp b/source/slang/slang-ir-util.cpp
index a2ec15661..497281114 100644
--- a/source/slang/slang-ir-util.cpp
+++ b/source/slang/slang-ir-util.cpp
@@ -2348,6 +2348,45 @@ bool isInstHoistable(IROp op, IRType* type, IRInst* const* fixedArgs)
isSpecConstOpHoistable(op, type, fixedArgs);
}
+IRType* getUnsignedTypeFromSignedType(IRBuilder* builder, IRType* type)
+{
+ SLANG_RELEASE_ASSERT(isSignedType(type));
+
+ auto elementType = getVectorOrCoopMatrixElementType(type);
+
+ IROp op = type->getOp();
+ switch (op)
+ {
+ case kIROp_MatrixType:
+ {
+ auto unsignedTypeOp = getOppositeSignIntTypeOp(elementType->getOp());
+ auto matType = as<IRMatrixType>(type);
+ SLANG_RELEASE_ASSERT(matType);
+ return builder->getMatrixType(
+ builder->getType(unsignedTypeOp),
+ matType->getRowCount(),
+ matType->getColumnCount(),
+ matType->getLayout());
+ }
+ case kIROp_VectorType:
+ {
+ auto unsignedTypeOp = getOppositeSignIntTypeOp(elementType->getOp());
+ auto vecType = as<IRVectorType>(type);
+ SLANG_RELEASE_ASSERT(vecType);
+ return builder->getVectorType(
+ builder->getType(unsignedTypeOp),
+ vecType->getElementCount());
+ }
+ case kIROp_IntType:
+ case kIROp_Int16Type:
+ case kIROp_Int64Type:
+ case kIROp_Int8Type:
+ return builder->getType(getOppositeSignIntTypeOp(elementType->getOp()));
+ default:
+ return type;
+ }
+}
+
bool isSignedType(IRType* type)
{
switch (type->getOp())