summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-insert-debug-value-store.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-insert-debug-value-store.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-insert-debug-value-store.cpp')
-rw-r--r--source/slang/slang-ir-insert-debug-value-store.cpp333
1 files changed, 164 insertions, 169 deletions
diff --git a/source/slang/slang-ir-insert-debug-value-store.cpp b/source/slang/slang-ir-insert-debug-value-store.cpp
index af86cb6dd..338ee128c 100644
--- a/source/slang/slang-ir-insert-debug-value-store.cpp
+++ b/source/slang/slang-ir-insert-debug-value-store.cpp
@@ -1,38 +1,35 @@
#include "slang-ir-insert-debug-value-store.h"
-#include "slang-ir.h"
#include "slang-ir-insts.h"
#include "slang-ir-util.h"
+#include "slang-ir.h"
namespace Slang
{
- struct DebugValueStoreContext
+struct DebugValueStoreContext
+{
+ Dictionary<IRType*, bool> m_mapTypeToDebugability;
+ bool isTypeKind(IRInst* inst)
{
- Dictionary<IRType*, bool> m_mapTypeToDebugability;
- bool isTypeKind(IRInst* inst)
+ if (!inst)
+ return true;
+ switch (inst->getOp())
{
- if (!inst)
- return true;
- switch (inst->getOp())
- {
- case kIROp_TypeKind:
- case kIROp_TypeType:
- return true;
- default:
- return false;
- }
+ case kIROp_TypeKind:
+ case kIROp_TypeType: return true;
+ default: return false;
}
- bool isDebuggableType(IRType* type)
- {
- if (bool* result = m_mapTypeToDebugability.tryGetValue(type))
- return *result;
+ }
+ bool isDebuggableType(IRType* type)
+ {
+ if (bool* result = m_mapTypeToDebugability.tryGetValue(type))
+ return *result;
- bool debuggable = false;
- switch (type->getOp())
- {
- case kIROp_VoidType:
- break;
- case kIROp_StructType:
+ bool debuggable = false;
+ switch (type->getOp())
+ {
+ case kIROp_VoidType: break;
+ case kIROp_StructType:
{
auto structType = static_cast<IRStructType*>(type);
bool structDebuggable = true;
@@ -47,208 +44,206 @@ namespace Slang
debuggable = structDebuggable;
break;
}
- case kIROp_ArrayType:
- case kIROp_UnsizedArrayType:
+ case kIROp_ArrayType:
+ case kIROp_UnsizedArrayType:
{
auto arrayType = static_cast<IRArrayTypeBase*>(type);
debuggable = isDebuggableType(arrayType->getElementType());
break;
}
- case kIROp_VectorType:
- case kIROp_MatrixType:
- case kIROp_PtrType:
- debuggable = true;
- break;
- case kIROp_Param:
- // Assume generic parameters are debuggable.
- debuggable = true;
- break;
- case kIROp_Specialize:
+ case kIROp_VectorType:
+ case kIROp_MatrixType:
+ case kIROp_PtrType: debuggable = true; break;
+ case kIROp_Param:
+ // Assume generic parameters are debuggable.
+ debuggable = true;
+ break;
+ case kIROp_Specialize:
{
auto specType = as<IRSpecialize>(type);
- auto specTypeDebuggable = isDebuggableType((IRType*)getResolvedInstForDecorations(specType));
+ auto specTypeDebuggable =
+ isDebuggableType((IRType*)getResolvedInstForDecorations(specType));
if (!specTypeDebuggable)
break;
for (UInt i = 0; i < specType->getArgCount(); i++)
{
auto arg = specType->getArg(i);
- if (isTypeKind(arg->getDataType()) && !isDebuggableType((IRType*)specType->getArg(i)))
+ if (isTypeKind(arg->getDataType()) &&
+ !isDebuggableType((IRType*)specType->getArg(i)))
{
specTypeDebuggable = false;
break;
}
}
- debuggable = false;// specTypeDebuggable;
- break;
- }
- default:
- if (as<IRBasicType>(type))
- debuggable = true;
+ debuggable = false; // specTypeDebuggable;
break;
}
- m_mapTypeToDebugability[type] = debuggable;
- return debuggable;
+ default:
+ if (as<IRBasicType>(type))
+ debuggable = true;
+ break;
}
+ m_mapTypeToDebugability[type] = debuggable;
+ return debuggable;
+ }
- void insertDebugValueStore(IRFunc* func)
+ void insertDebugValueStore(IRFunc* func)
+ {
+ IRBuilder builder(func);
+ Dictionary<IRInst*, IRInst*> mapVarToDebugVar;
+ auto firstBlock = func->getFirstBlock();
+ if (!firstBlock)
+ return;
+ auto funcDebugLoc = func->findDecoration<IRDebugLocationDecoration>();
+ if (!funcDebugLoc)
+ return;
+ List<IRInst*> params;
+ for (auto param : firstBlock->getParams())
{
- IRBuilder builder(func);
- Dictionary<IRInst*, IRInst*> mapVarToDebugVar;
- auto firstBlock = func->getFirstBlock();
- if (!firstBlock)
- return;
- auto funcDebugLoc = func->findDecoration<IRDebugLocationDecoration>();
- if (!funcDebugLoc)
- return;
- List<IRInst*> params;
- for (auto param : firstBlock->getParams())
+ params.add(param);
+ }
+ Index paramIndex = 0;
+ for (auto param : params)
+ {
+ builder.setInsertBefore(firstBlock->getFirstOrdinaryInst());
+ auto paramType = param->getDataType();
+ bool isRefParam = false;
+ if (auto outType = as<IROutTypeBase>(paramType))
{
- params.add(param);
+ isRefParam = true;
+ paramType = outType->getValueType();
}
- Index paramIndex = 0;
- for (auto param : params)
- {
- builder.setInsertBefore(firstBlock->getFirstOrdinaryInst());
- auto paramType = param->getDataType();
- bool isRefParam = false;
- if (auto outType = as<IROutTypeBase>(paramType))
- {
- isRefParam = true;
- paramType = outType->getValueType();
- }
- if (!isDebuggableType(paramType))
- continue;
- auto debugVar = builder.emitDebugVar(
- paramType,
- funcDebugLoc->getSource(),
- funcDebugLoc->getLine(),
- funcDebugLoc->getCol(),
- builder.getIntValue(builder.getUIntType(), paramIndex));
- copyNameHintAndDebugDecorations(debugVar, param);
+ if (!isDebuggableType(paramType))
+ continue;
+ auto debugVar = builder.emitDebugVar(
+ paramType,
+ funcDebugLoc->getSource(),
+ funcDebugLoc->getLine(),
+ funcDebugLoc->getCol(),
+ builder.getIntValue(builder.getUIntType(), paramIndex));
+ copyNameHintAndDebugDecorations(debugVar, param);
- mapVarToDebugVar[param] = debugVar;
+ mapVarToDebugVar[param] = debugVar;
- // Store the initial value of the parameter into the debug var.
- IRInst* paramVal = nullptr;
- if (!isRefParam)
- paramVal = param;
- else if (as<IRInOutType>(param->getDataType()))
- paramVal = builder.emitLoad(param);
- if (paramVal)
- {
- builder.emitDebugValue(debugVar, paramVal);
- }
- paramIndex++;
+ // Store the initial value of the parameter into the debug var.
+ IRInst* paramVal = nullptr;
+ if (!isRefParam)
+ paramVal = param;
+ else if (as<IRInOutType>(param->getDataType()))
+ paramVal = builder.emitLoad(param);
+ if (paramVal)
+ {
+ builder.emitDebugValue(debugVar, paramVal);
}
+ paramIndex++;
+ }
- for (auto block : func->getBlocks())
+ for (auto block : func->getBlocks())
+ {
+ IRInst* nextInst = nullptr;
+ for (auto inst = block->getFirstInst(); inst; inst = nextInst)
{
- IRInst* nextInst = nullptr;
- for (auto inst = block->getFirstInst(); inst; inst = nextInst)
+ nextInst = inst->getNextInst();
+ if (auto varInst = as<IRVar>(inst))
{
- nextInst = inst->getNextInst();
- if (auto varInst = as<IRVar>(inst))
+ if (auto debugLoc = varInst->findDecoration<IRDebugLocationDecoration>())
{
- if (auto debugLoc = varInst->findDecoration<IRDebugLocationDecoration>())
- {
- auto varType = tryGetPointedToType(&builder, varInst->getDataType());
- builder.setInsertBefore(varInst);
- if (!isDebuggableType(varType))
- continue;
- auto debugVar = builder.emitDebugVar(
- varType,
- debugLoc->getSource(),
- debugLoc->getLine(),
- debugLoc->getCol());
- copyNameHintAndDebugDecorations(debugVar, varInst);
- mapVarToDebugVar[varInst] = debugVar;
- }
+ auto varType = tryGetPointedToType(&builder, varInst->getDataType());
+ builder.setInsertBefore(varInst);
+ if (!isDebuggableType(varType))
+ continue;
+ auto debugVar = builder.emitDebugVar(
+ varType,
+ debugLoc->getSource(),
+ debugLoc->getLine(),
+ debugLoc->getCol());
+ copyNameHintAndDebugDecorations(debugVar, varInst);
+ mapVarToDebugVar[varInst] = debugVar;
}
}
}
+ }
- // Collect all stores and insert debug value insts to update debug vars.
+ // Collect all stores and insert debug value insts to update debug vars.
- // Helper func to insert debugValue updates.
- auto setDebugValue = [&](
- IRInst* debugVar, IRInst* newValue,
- ArrayView<IRInst*> accessChain)
- {
- auto ptr = builder.emitElementAddress(debugVar, accessChain);
- builder.emitDebugValue(ptr, newValue);
- };
- for (auto block : func->getBlocks())
+ // Helper func to insert debugValue updates.
+ auto setDebugValue = [&](IRInst* debugVar, IRInst* newValue, ArrayView<IRInst*> accessChain)
+ {
+ auto ptr = builder.emitElementAddress(debugVar, accessChain);
+ builder.emitDebugValue(ptr, newValue);
+ };
+ for (auto block : func->getBlocks())
+ {
+ IRInst* nextInst = nullptr;
+ for (auto inst = block->getFirstInst(); inst; inst = nextInst)
{
- IRInst* nextInst = nullptr;
- for (auto inst = block->getFirstInst(); inst; inst = nextInst)
- {
- nextInst = inst->getNextInst();
+ nextInst = inst->getNextInst();
- if (auto storeInst = as<IRStore>(inst))
+ if (auto storeInst = as<IRStore>(inst))
+ {
+ List<IRInst*> accessChain;
+ auto varInst = getRootAddr(storeInst->getPtr(), accessChain);
+ IRInst* debugVar = nullptr;
+ if (mapVarToDebugVar.tryGetValue(varInst, debugVar))
{
- List<IRInst*> accessChain;
- auto varInst = getRootAddr(storeInst->getPtr(), accessChain);
- IRInst* debugVar = nullptr;
- if (mapVarToDebugVar.tryGetValue(varInst, debugVar))
- {
- builder.setInsertAfter(storeInst);
- setDebugValue(debugVar, storeInst->getVal(), accessChain.getArrayView());
- }
+ builder.setInsertAfter(storeInst);
+ setDebugValue(debugVar, storeInst->getVal(), accessChain.getArrayView());
+ }
+ }
+ else if (auto swizzledStore = as<IRSwizzledStore>(inst))
+ {
+ List<IRInst*> accessChain;
+ auto varInst = getRootAddr(swizzledStore->getDest(), accessChain);
+ IRInst* debugVar = nullptr;
+ if (mapVarToDebugVar.tryGetValue(varInst, debugVar))
+ {
+ builder.setInsertAfter(swizzledStore);
+ auto loadVal = builder.emitLoad(swizzledStore->getDest());
+ setDebugValue(debugVar, loadVal, accessChain.getArrayView());
}
- else if (auto swizzledStore = as<IRSwizzledStore>(inst))
+ }
+ else if (auto callInst = as<IRCall>(inst))
+ {
+ auto funcValue = getResolvedInstForDecorations(callInst->getCallee());
+ if (!funcValue)
+ continue;
+ for (UInt i = 0; i < callInst->getArgCount(); i++)
{
+ auto arg = callInst->getArg(i);
+ if (!as<IRPtrTypeBase>(arg->getDataType()))
+ continue;
List<IRInst*> accessChain;
- auto varInst = getRootAddr(swizzledStore->getDest(), accessChain);
+ auto varInst = getRootAddr(arg, accessChain);
IRInst* debugVar = nullptr;
if (mapVarToDebugVar.tryGetValue(varInst, debugVar))
{
- builder.setInsertAfter(swizzledStore);
- auto loadVal = builder.emitLoad(swizzledStore->getDest());
+ builder.setInsertAfter(callInst);
+ auto loadVal = builder.emitLoad(arg);
setDebugValue(debugVar, loadVal, accessChain.getArrayView());
}
}
- else if (auto callInst = as<IRCall>(inst))
- {
- auto funcValue = getResolvedInstForDecorations(callInst->getCallee());
- if (!funcValue)
- continue;
- for (UInt i = 0; i < callInst->getArgCount(); i++)
- {
- auto arg = callInst->getArg(i);
- if (!as<IRPtrTypeBase>(arg->getDataType()))
- continue;
- List<IRInst*> accessChain;
- auto varInst = getRootAddr(arg, accessChain);
- IRInst* debugVar = nullptr;
- if (mapVarToDebugVar.tryGetValue(varInst, debugVar))
- {
- builder.setInsertAfter(callInst);
- auto loadVal = builder.emitLoad(arg);
- setDebugValue(debugVar, loadVal, accessChain.getArrayView());
- }
- }
- }
}
}
}
- };
+ }
+};
- void insertDebugValueStore(IRModule* module)
+void insertDebugValueStore(IRModule* module)
+{
+ DebugValueStoreContext context;
+ for (auto globalInst : module->getGlobalInsts())
{
- DebugValueStoreContext context;
- for (auto globalInst : module->getGlobalInsts())
+ if (auto genericInst = as<IRGeneric>(globalInst))
{
- if (auto genericInst = as<IRGeneric>(globalInst))
- {
- if (auto func = as<IRFunc>(findGenericReturnVal(genericInst)))
- {
- context.insertDebugValueStore(func);
- }
- }
- else if (auto func = as<IRFunc>(globalInst))
+ if (auto func = as<IRFunc>(findGenericReturnVal(genericInst)))
{
context.insertDebugValueStore(func);
}
}
+ else if (auto func = as<IRFunc>(globalInst))
+ {
+ context.insertDebugValueStore(func);
+ }
}
}
+} // namespace Slang