<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<div>> Yeah, because that decision can only be made much later in LLVM in AsmPrinter/DwarfExpression.cpp.</div>
<div>> In DWARF, DW_OP_reg(x) is a register l-value, all others can either be l-values or r-values depending on whether there is a DW_OP_stack_value/DW_OP_implicit* at the end.
<br>
</div>
<div><br>
</div>
<div>Yes, it might not be clear but that's what I'm trying to say. Out of the non-empty DWARF locations, register and memory locations are l-values, implicit locations are r-values. You can technically use
<span style="font-family:Consolas,Courier,monospace">DW_OP_breg</span> in an l-value, but not for register locations. This is why when we have a DBG_VALUE that has a single register location operand with an otherwise empty DIExpression, we need some indicator
 to determine whether we want to produce the register location [<span style="font-family:Consolas,Courier,monospace">DW_OP_reg</span>] or the memory location [<span style="font-family:Consolas,Courier,monospace">DW_OP_breg</span>] (currently this indicator
 is the indirectness flag). <br>
</div>
<div><br>
</div>
<div>> I think it would be confusing to talk about registers at the LLVM IR / DIExpression level. "SSA-Values"?</div>
<div><br>
</div>
<div>I think terminology is a bit difficult here because this work concerns both the llvm.dbg.value intrinsic and the DBG_VALUE instruction, which operate on different kinds of arguments. I think "location operands" is probably the best description for them,
 since they are operands to a DIExpression which is used to compute the variable location.<br>
</div>
<div><br>
</div>
<div>> I don't think that's correct, because a <span style="font-family:Consolas,Courier,monospace">
DW_OP_stack_value </span>is an rvalue. But maybe I misunderstood what you were trying to say.</div>
<div>> We should start be defining what <span style="font-family:Consolas,Courier,monospace">
DW_OP_stack_value </span>really means in LLVM debug info metadata. I believe it should just mean "r-value".</div>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
Having given it some more thought, I've changed my mind - I agree that we shouldn't use
<span style="font-family:Consolas,Courier,monospace">DW_OP_stack_value</span> in this case, because it would be changing its meaning which is to explicitly declare the expression to be an implicit location/r-value. My current line of thinking is that it would
 be better to introduce a new operator, named <span style="font-family:Consolas,Courier,monospace">
DW_OP_LLVM_direct </span>or something similar, which has the meaning "the variable's exact value is produced by the preceding expression", and would replace
<span style="font-family:Consolas,Courier,monospace">DW_OP_stack_value</span> as it is currently used within LLVM.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
To summarise the logic behind using this operator: LLVM debug info does not need to explicitly care about r-values or l-values before DWARF emission, only whether we're describing a variable's memory location, a variable's exact value, or some other implicit
 location (such as implicit_pointer). Whether an expression is an r-value or l-value can be trivially determined at the end of the pipeline (<span style="font-family:Consolas,Courier,monospace">addMachineRegExpression</span> already does this).</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
For an expression ending with DW_OP_LLVM_direct: if the preceding expression is only a single register then we emit a register location, if the preceding expression ends with DW_OP_deref then we can remove the deref and emit a memory location, and otherwise
 we emit the expression with <span style="font-family:Consolas,Courier,monospace">
DW_OP_stack_value</span>. In expression syntax it would behave like an implicit operator, in that it can only appear at the end of an expression and is incompatible with any implicit operators, including
<span style="font-family:Consolas,Courier,monospace">DW_OP_stack_value</span>. <br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
The alternative I see for this is using a flag or a new DIExpression operator that explicitly declares a single register DBG_VALUE to be a register location, while it would otherwise be treated as a memory location, and use stack_value for all other cases.
 The main reason I prefer the "direct" operator is that LLVM doesn't need to know whether a DIExpression results in an l-value location or an r-value location; it only needs to know how to compute the variable's location and then determine whether that computation
 resolves to an l-value or r-value at the end. Maintaining two separate representations for stack value locations and register locations when we don't need to is an unnecessary burden, especially when it may be possible for a given dbg.value/DBG_VALUE to switch
 back and forth between them.<br>
</div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
</body>
</html>