This patch (6/N) stems from D69787 as suggested by reviewers.
Summary:
Whenever alloca is getting deleted, lets handle this to preserve debug info - Collect a variable description from corresponding llvm.dbg.declare intrinsic and pass that information to llvm.dbg.value intrinsic to create Before transformation %a = alloca [2 x i32], align 4 call void @llvm.dbg.declare(metadata [2 x i32]* %arr, metadata !16, metadata !DIExpression()), !dbg !22 call void @llvm.dbg.value(metadata [2 x i32]* %arr, metadata !20, metadata !DIExpression()), !dbg !24 !16 = !DILocalVariable(name: "arr", scope: !12, file: !3, line: 5, type: !17) !20 = !DILocalVariable(name: "ptr", scope: !12, file: !3, line: 6, type: !21) After Transformation %a = alloca [2 x i32], align 4 call void @llvm.dbg.declare(metadata [2 x i32]* %arr, metadata !16, metadata !DIExpression()), !dbg !22 call void @llvm.dbg.derefval(metadata !16, metadata !20, metadata !DIExpression(DW_OP_LLVM_implicit_pointer, DW_OP_LLVM_arg0, 0)), !dbg !24 call void @llvm.dbg.derefval(metadata !16, metadata !20, metadata !DIExpression(DW_OP_LLVM_implicit_pointer, DW_OP_LLVM_arg0, 4)), !dbg !24 - In case llvm.dbg.declare is getting deleted before alloca instruction, preserve variable description map to use later. Testing: - check-llvm - check-debuginfo (the debug info integration tests)
Are you using a std::map for a specific reason? Could you not use a std::unordered_map, or better yet, a DenseMap [0] or similar llvm container here instead?
[0] http://llvm.org/docs/ProgrammersManual.html#llvm-adt-densemap-h