Using entry values on IR will give us better debugging user experience when debugging "optimized" code (swift uses llvm.dbg.values even in non-optimized code, so this refers to that code as well). This patch implements a utility (within Transforms/Utils/Local.cpp) that finds an entry Value for a given Variable.
Consider this (simple) test case:
void f1(int); void f2(int i) { f1(1); i = i + 5; f1(3); }
IR ($ clang -g -O2 -S) for the func looks:
define dso_local void @f2(i32 %i) local_unnamed_addr !dbg !7 { entry: call void @llvm.dbg.value(metadata i32 %i, metadata !12, metadata !DIExpression()), !dbg !13 tail call void @f1(i32 1), !dbg !14 call void @llvm.dbg.value(metadata i32 %i, metadata !12, metadata !DIExpression(DW_OP_plus_uconst, 5, DW_OP_stack_value)), !dbg !13 tail call void @f1(i32 3), !dbg !15 ret void, !dbg !16 }
SelectionDAG for the second dbg.value generates:
DBG_VALUE $noreg, $noreg, !"i", !DIExpression(DW_OP_plus_uconst, 5, DW_OP_stack_value), debug-location !13; test.c:0 line no:2
After this set of patches, we will salvage the value by using the entry values, so the DBG_VALUE looks as following:
DBG_VALUE $edi, $noreg, !12, !DIExpression(DW_OP_LLVM_entry_value, 1, DW_OP_plus_uconst, 5, DW_OP_stack_value), debug-location !13
Ah, I it seems that we did not have a small Verifier case for the last condition. Perhaps we now should add a small permissive one. Something like this: