[DebugInfo] Shorten legacy [s|z]ext dwarf expressions

Take advantage of the emitConstu helper to emit slightly shorter dwarf
expressions to implement legacy [s|z]ext operations.
This commit is contained in:
Vedant Kumar 2020-10-21 09:22:13 -07:00
parent 9905346221
commit 2ce36ebca5
3 changed files with 5 additions and 8 deletions

View File

@ -638,14 +638,12 @@ void DwarfExpression::addFragmentOffset(const DIExpression *Expr) {
void DwarfExpression::emitLegacySExt(unsigned FromBits) { void DwarfExpression::emitLegacySExt(unsigned FromBits) {
// (((X >> (FromBits - 1)) * (~0)) << FromBits) | X // (((X >> (FromBits - 1)) * (~0)) << FromBits) | X
emitOp(dwarf::DW_OP_dup); emitOp(dwarf::DW_OP_dup);
emitOp(dwarf::DW_OP_constu); emitConstu(FromBits - 1);
emitUnsigned(FromBits - 1);
emitOp(dwarf::DW_OP_shr); emitOp(dwarf::DW_OP_shr);
emitOp(dwarf::DW_OP_lit0); emitOp(dwarf::DW_OP_lit0);
emitOp(dwarf::DW_OP_not); emitOp(dwarf::DW_OP_not);
emitOp(dwarf::DW_OP_mul); emitOp(dwarf::DW_OP_mul);
emitOp(dwarf::DW_OP_constu); emitConstu(FromBits);
emitUnsigned(FromBits);
emitOp(dwarf::DW_OP_shl); emitOp(dwarf::DW_OP_shl);
emitOp(dwarf::DW_OP_or); emitOp(dwarf::DW_OP_or);
} }
@ -653,8 +651,7 @@ void DwarfExpression::emitLegacySExt(unsigned FromBits) {
void DwarfExpression::emitLegacyZExt(unsigned FromBits, unsigned ToBits) { void DwarfExpression::emitLegacyZExt(unsigned FromBits, unsigned ToBits) {
if (FromBits < 64) { if (FromBits < 64) {
// X & ((1 << FromBits) - 1) // X & ((1 << FromBits) - 1)
emitOp(dwarf::DW_OP_constu); emitConstu((1ULL << FromBits) - 1);
emitUnsigned((1ULL << FromBits) - 1);
emitOp(dwarf::DW_OP_and); emitOp(dwarf::DW_OP_and);
} else { } else {
addOpPiece(FromBits, 0); addOpPiece(FromBits, 0);

View File

@ -62,7 +62,7 @@
; NOCONV: DW_TAG_formal_parameter ; NOCONV: DW_TAG_formal_parameter
; NOCONV: DW_TAG_variable ; NOCONV: DW_TAG_variable
; NOCONV: DW_AT_location ( ; NOCONV: DW_AT_location (
; NOCONV: {{.*}}, DW_OP_dup, DW_OP_constu 0x7, DW_OP_shr, DW_OP_lit0, DW_OP_not, DW_OP_mul, DW_OP_constu 0x8, DW_OP_shl, DW_OP_or, DW_OP_stack_value) ; NOCONV: {{.*}}, DW_OP_dup, DW_OP_lit7, DW_OP_shr, DW_OP_lit0, DW_OP_not, DW_OP_mul, DW_OP_lit8, DW_OP_shl, DW_OP_or, DW_OP_stack_value)
; NOCONV: DW_AT_name ("y") ; NOCONV: DW_AT_name ("y")
; NOCONV: NULL ; NOCONV: NULL
; NOCONV: DW_TAG_base_type ; NOCONV: DW_TAG_base_type

View File

@ -26,7 +26,7 @@
; DW4: DW_TAG_compile_unit ; DW4: DW_TAG_compile_unit
; DW4: DW_TAG_variable ; DW4: DW_TAG_variable
; DW4: DW_AT_name ("global") ; DW4: DW_AT_name ("global")
; DW4: DW_AT_location (DW_OP_addr 0x0, DW_OP_deref, DW_OP_dup, DW_OP_constu 0x7, DW_OP_shr, DW_OP_lit0, DW_OP_not, DW_OP_mul, DW_OP_constu 0x8, DW_OP_shl, DW_OP_or, DW_OP_stack_value) ; DW4: DW_AT_location (DW_OP_addr 0x0, DW_OP_deref, DW_OP_dup, DW_OP_lit7, DW_OP_shr, DW_OP_lit0, DW_OP_not, DW_OP_mul, DW_OP_lit8, DW_OP_shl, DW_OP_or, DW_OP_stack_value)
; DW4: DW_TAG_base_type ; DW4: DW_TAG_base_type
; DW4: DW_AT_name ("int") ; DW4: DW_AT_name ("int")
; DW4: NULL ; DW4: NULL