@@ -44,6 +44,9 @@ constexpr uint32_t kExtInstSetInIdx = 0;
44
44
constexpr uint32_t kExtInstOpInIdx = 1 ;
45
45
constexpr uint32_t kInterpolantInIdx = 2 ;
46
46
constexpr uint32_t kCooperativeMatrixLoadSourceAddrInIdx = 0 ;
47
+ constexpr uint32_t kDebugValueLocalVariable = 2 ;
48
+ constexpr uint32_t kDebugValueValue = 3 ;
49
+ constexpr uint32_t kDebugValueExpression = 4 ;
47
50
48
51
// Sorting functor to present annotation instructions in an easy-to-process
49
52
// order. The functor orders by opcode first and falls back on unique id
@@ -277,9 +280,53 @@ bool AggressiveDCEPass::AggressiveDCE(Function* func) {
277
280
live_local_vars_.clear ();
278
281
InitializeWorkList (func, structured_order);
279
282
ProcessWorkList (func);
283
+ ProcessDebugInformation (structured_order);
284
+ ProcessWorkList (func);
280
285
return KillDeadInstructions (func, structured_order);
281
286
}
282
287
288
+ void AggressiveDCEPass::ProcessDebugInformation (
289
+ std::list<BasicBlock*>& structured_order) {
290
+ for (auto bi = structured_order.begin (); bi != structured_order.end (); bi++) {
291
+ (*bi)->ForEachInst ([this ](Instruction* inst) {
292
+ // DebugDeclare is not dead. It must be converted to DebugValue in a
293
+ // later pass
294
+ if (inst->IsNonSemanticInstruction () &&
295
+ inst->GetShader100DebugOpcode () ==
296
+ NonSemanticShaderDebugInfo100DebugDeclare) {
297
+ AddToWorklist (inst);
298
+ return ;
299
+ }
300
+
301
+ // If the Value of a DebugValue is killed, set Value operand to Undef
302
+ if (inst->IsNonSemanticInstruction () &&
303
+ inst->GetShader100DebugOpcode () ==
304
+ NonSemanticShaderDebugInfo100DebugValue) {
305
+ uint32_t id = inst->GetSingleWordInOperand (kDebugValueValue );
306
+ auto def = get_def_use_mgr ()->GetDef (id);
307
+ if (!live_insts_.Set (def->unique_id ())) {
308
+ AddToWorklist (inst);
309
+ context ()->get_def_use_mgr ()->UpdateDefUse (inst);
310
+ worklist_.push (def);
311
+ def->SetOpcode (spv::Op::OpUndef);
312
+ def->SetInOperands ({});
313
+ id = inst->GetSingleWordInOperand (kDebugValueLocalVariable );
314
+ auto localVar = get_def_use_mgr ()->GetDef (id);
315
+ AddToWorklist (localVar);
316
+ context ()->get_def_use_mgr ()->UpdateDefUse (localVar);
317
+ AddOperandsToWorkList (localVar);
318
+ context ()->get_def_use_mgr ()->UpdateDefUse (def);
319
+ id = inst->GetSingleWordInOperand (kDebugValueExpression );
320
+ auto expression = get_def_use_mgr ()->GetDef (id);
321
+ AddToWorklist (expression);
322
+ context ()->get_def_use_mgr ()->UpdateDefUse (expression);
323
+ return ;
324
+ }
325
+ }
326
+ });
327
+ }
328
+ }
329
+
283
330
bool AggressiveDCEPass::KillDeadInstructions (
284
331
const Function* func, std::list<BasicBlock*>& structured_order) {
285
332
bool modified = false ;
0 commit comments