This is an archive of the discontinued LLVM Phabricator instance.

[DIExpression] Introduce a dedicated DW_OP_LLVM_fragment operation so we can stop using DW_OP_bit_piece with the wrong semantics.
ClosedPublic

Authored by aprantl on Dec 2 2016, 12:02 PM.

Details

Summary

The entire back story can be found here:
http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20161114/405934.html

The gist is that in LLVM we've been misinterpreting DW_OP_bit_piece's offset field to mean the offset into the source variable rather than the offset into the location at the top the DWARF expression stack. In order to be able to fix this in a subsequent patch, this patch introduces a dedicated DW_OP_LLVM_fragment operation with the semantics that we used to apply to DW_OP_bit_piece, which is what we actually need while inside of LLVM. This patch is complete with a bitcode upgrade for expressions using the old format. It does not yet fix the DWARF backend to use DW_OP_bit_piece correctly.

Implementation note: We discussed several options for implementing this, including reserving a dedicated field in DIExpression for the fragment size and offset, but using an custom operator at the end of the expression works just fine and is more efficient because we then only pay for it when we need it.

Diff Detail

Event Timeline

aprantl updated this revision to Diff 80109.Dec 2 2016, 12:02 PM
aprantl retitled this revision from to [DIExpression] Introduce a dedicated DW_OP_LLVM_fragment operation so we can stop using DW_OP_bit_piece with the wrong semantics..
aprantl updated this object.
aprantl added reviewers: dblaikie, dexonsmith.
aprantl set the repository for this revision to rL LLVM.
aprantl added a subscriber: llvm-commits.

This is kind of obvious, but I should have noted that I renamed piece to fragment whenever we use the LLVM-internal semantics to avoid confusion in the future.

Commentary nits.

include/llvm/IR/DebugInfoMetadata.h
1963–1964

Comment should also s/piece/fragment/? Here and for isFragment().

lib/CodeGen/AsmPrinter/DwarfExpression.cpp
113–114

DW_OP_LLVM_fragment (or DW_OP_piece if it really is still that).

128

DW_OP_LLVM_fragment (or DW_OP_piece if it really is still that).

lib/CodeGen/AsmPrinter/DwarfExpression.h
158

The \return line probably should not be indented like this?

test/DebugInfo/ARM/s-super-register.ll
9 ↗(On Diff #80109)

0x9d is DW_OP_bit_piece, this comment should not have changed (we're still emitting DW_OP_bit_piece in the actual DWARF, yes?).

aprantl updated this revision to Diff 80124.Dec 2 2016, 1:29 PM
aprantl removed rL LLVM as the repository for this revision.
aprantl marked 5 inline comments as done.

Address all of Paul's comments. Thanks!

aprantl updated this revision to Diff 80125.Dec 2 2016, 1:30 PM

For real.

aprantl added inline comments.Dec 2 2016, 1:33 PM
lib/CodeGen/AsmPrinter/DwarfExpression.cpp
113–114

The code here is not wrong, but do not have to do any manual shifting if we use DW_OP_bit_piece correctly here. I will fix this in a subsequent patch.

probinson accepted this revision.Dec 2 2016, 4:54 PM
probinson added a reviewer: probinson.

Duncan reviewed the bitcode upgrade part and the rest of it looks very mechanical. LGTM.

This revision is now accepted and ready to land.Dec 2 2016, 4:54 PM
aprantl closed this revision.Dec 5 2016, 10:25 AM

Thanks. r288683