summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-lower-generic-type.cpp8
-rw-r--r--source/slang/slang-ir-specialize.cpp4
-rw-r--r--source/slang/slang-ir.cpp31
-rw-r--r--source/slang/slang-ir.h5
4 files changed, 47 insertions, 1 deletions
diff --git a/source/slang/slang-ir-lower-generic-type.cpp b/source/slang/slang-ir-lower-generic-type.cpp
index 9579b0a2b..c4dcd92a9 100644
--- a/source/slang/slang-ir-lower-generic-type.cpp
+++ b/source/slang/slang-ir-lower-generic-type.cpp
@@ -50,6 +50,14 @@ struct GenericTypeLoweringContext
structField->setOperand(1, loweredFieldType);
}
break;
+ case kIROp_DebugFunction:
+ {
+ auto oldFuncType = as<IRDebugFunction>(inst)->getDebugType();
+ auto newFuncType = sharedContext->lowerType(builder, oldFuncType);
+ if (newFuncType != oldFuncType)
+ inst = builder->replaceOperand(inst->getOperandUse(4), newFuncType);
+ }
+ break;
}
return inst;
}
diff --git a/source/slang/slang-ir-specialize.cpp b/source/slang/slang-ir-specialize.cpp
index bc7bcab12..0f8672531 100644
--- a/source/slang/slang-ir-specialize.cpp
+++ b/source/slang/slang-ir-specialize.cpp
@@ -1163,7 +1163,8 @@ struct SpecializationContext
// top-down through the program, so that we want to process
// the children of an instruction in their original order.
//
- for (auto child = inst->getLastChild(); child; child = child->getPrevInst())
+ for (auto child = inst->getLastDecorationOrChild(); child;
+ child = child->getPrevInst())
{
// Also note that `addToWorkList` has been written
// to avoid adding any instruction that is a descendent
@@ -2055,6 +2056,7 @@ struct SpecializationContext
}
}
+ fixUpDebugFuncType(newFunc);
return newFunc;
}
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp
index ba8864684..7b7d5ec17 100644
--- a/source/slang/slang-ir.cpp
+++ b/source/slang/slang-ir.cpp
@@ -815,6 +815,37 @@ IRType* IRFunc::getParamType(UInt index)
return getDataType()->getParamType(index);
}
+void fixUpDebugFuncType(IRFunc* func)
+{
+ SLANG_ASSERT(func);
+
+ if (auto debugFuncDecor = func->findDecoration<IRDebugFuncDecoration>())
+ {
+ auto funcType = func->getDataType();
+ auto oldDebugFunc = cast<IRDebugFunction>(debugFuncDecor->getDebugFunc());
+
+ // If the existing debug func type is already the same, there's no need
+ // to do anything.
+ if (isTypeEqual(funcType, as<IRType>(oldDebugFunc->getDebugType())))
+ return;
+
+ auto irModule = func->getModule();
+ SLANG_ASSERT(irModule);
+
+ IRBuilder builder(irModule);
+ builder.setInsertInto(irModule->getModuleInst());
+
+ auto newDebugFunc = builder.emitDebugFunction(
+ oldDebugFunc->getName(),
+ oldDebugFunc->getLine(),
+ oldDebugFunc->getCol(),
+ oldDebugFunc->getFile(),
+ funcType);
+ debugFuncDecor->removeAndDeallocate();
+ builder.addDecoration(funcType, kIROp_DebugFuncDecoration, newDebugFunc);
+ }
+}
+
void fixUpFuncType(IRFunc* func, IRType* resultType)
{
SLANG_ASSERT(func);
diff --git a/source/slang/slang-ir.h b/source/slang/slang-ir.h
index aef3d6aeb..54bf23754 100644
--- a/source/slang/slang-ir.h
+++ b/source/slang/slang-ir.h
@@ -2148,6 +2148,11 @@ void fixUpFuncType(IRFunc* func, IRType* resultType);
///
void fixUpFuncType(IRFunc* func);
+/// If the function has a DebugFuncDecoration, replaces the function type in
+/// that decoration to match the current type of the function.
+///
+void fixUpDebugFuncType(IRFunc* func);
+
// A generic is akin to a function, but is conceptually executed
// before runtime, to specialize the code nested within.
//