This patch continues the work discussed in the RFC[0] for DBG_VALUE_LIST.
This is a very simple patch that is not needed for the basic addition of the DBG_VALUE_LIST instruction, but is needed for both the LiveDebugValues and LiveDebugVariables patches that follow it.
When a DBG_VALUE_LIST contains 2 or more identical debug operands, at certain passes we want to be able to remove the duplicate operands; the purpose of the replaceArg function is to modify a DIExpression by removing a duplicated operand. This means given a base operand x and a duplicate operand y, replacing each instance of DW_OP_LLVM_arg y with DW_OP_LLVM_arg x, and decrementing all arg > y as the operand array indices shift. For example, if we have:
DBG_VALUE_LIST "x", DIExpression(DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus, DW_OP_LLVM_arg 2, DW_OP_mul), %0, %0, %1
The debug operands 0 and 1 are the same, so we can remove debug operand 1 and replace its uses with debug operand 0, giving us:
DBG_VALUE_LIST "x", DIExpression(DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 0, DW_OP_plus, DW_OP_LLVM_arg 1, DW_OP_mul), %0, %1
This isn't necessary when handling the instruction in generic passes, but when we perform more in-depth analysis on debug value liveness (as in LiveDebugValues and LiveDebugVariables) having the same location appear more than once in a variable location is an issue, so we remove duplicates only as we enter those passes.
[0] http://lists.llvm.org/pipermail/llvm-dev/2020-February/139376.html
would you mind fixing this, too?