6

Allow MIR debuginfo to point to a variable's address by cjgillot · Pull Request...

 1 year ago
source link: https://github.com/rust-lang/rust/pull/111440
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Conversation

Contributor

MIR optimizations currently do not to operate on borrowed locals.

When enabling #106285, many borrows will be left as-is because they are used in debuginfo. This pass allows to replace this pattern directly in MIR debuginfo:

a => _1
_1 = &raw? mut? _2

becomes

a => &_2
// No statement to borrow _2.

This pass is implemented as a drive-by in ReferencePropagation MIR pass.

This transformation allows following following MIR opts to treat _2 as an unborrowed local, and optimize it as such, even in builds with debuginfo.

In codegen, when encountering a => &..&_2, we create a list of allocas:

store ptr %_2.dbg.spill, ptr %a.ref0.dbg.spill
store ptr %a.ref0.dbg.spill, ptr %a.ref1.dbg.spill
...
call void @llvm.dbg.declare(metadata ptr %a.ref{n}.dbg.spill, /* ... */)

Caveat: this transformation looses the exact type, we do not differentiate a as a immutable, mutable reference or a raw pointer. Everything is declared to *mut to codegen. I'm not convinced this is a blocker.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK