[PATCH] D58034: [IR/DIVar] Add flag for params that have unchanged values

Djordje Todorovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 12 03:00:57 PST 2019

djtodoro added a comment.

@aprantl Thanks for your comments!

> I'm assuming the idea is that this is analyzed by the language frontend?

You got the idea right! :)

> To make sure that we're getting the design right: Could you make an argument for why it is not sufficient to deduce this information at the MIR level by looking at the DBG_VALUEs of each variable?
> For example, if the first DBG_VALUE is at the beginning of the variable's lexical scope and no other DBG_VALUE for the variable exists the variable should be constant, because every other SSA value associated with the same variable should have contributed another DBG_VALUE and even if >the debug info got lost there should be a DBG_VALUE undef that survived. I guess it won't be hard to come up with a counterexample...

Actually, here is the example.

  DBG_VALUE $edi, $noreg, !"a",…
  $ebp = MOV32rr $edi
  DBG_VALUE $ebp, $noreg, !"a"…
  CALL64pcrel32 …

If we have a function with parameter `a` and it is located in a callee-clobbered register at the beginning of the function. If there is a use of the parameter in the rest of the function (after a call), there will be such move instruction (such in the example shown above) that changes the location of the parameter into some callee-saved register, even the parameter did not change its value. It will imply generating a new DBG_VALUE for variable `a`. By using some heuristics, this could be handled I guess and figure it out that a parameter is only moved to another location.
On IR level, it should be possible to make a verifier.

> Lastly, I've been meaning to add an isConstant flag to DIFlags to support programming languages with immutable variables (such as Swift let bindings) better. An isConstant would be emitted as a DW_TAG_constant instead of DW_TAG_variable. I'm wondering if isNotChanged and isConstant >are close enough that they could be merged. What do you think?

In general, every `isConstant` should be `IsNotChanged`. Those are very similar, but I would say not exactly the same. We mark parameters as `isNotChanged` when its value did not changed through the course of a function (that implies its value was constant in that function, but it is not necessary declared as `const`). But, for example in Swift by using `let` keyword you declare a constant. For such cases, it makes sense to generate `DW_TAG_constant`.



More information about the llvm-commits mailing list