llvm.org GIT mirror llvm / f82fc00
Debug Info: Implement DwarfCompileUnit::addComplexAddress() using DIEDwarfExpression (and get rid of a bunch of redundant code). NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225900 91177308-0d34-0410-b5e6-96231b3b80d8 Adrian Prantl 5 years ago
1 changed file(s) with 14 addition(s) and 47 deletion(s). Raw diff Collapse all Expand all
0 #include "DwarfCompileUnit.h"
11
2 #include "DwarfExpression.h"
23 #include "llvm/CodeGen/MachineFunction.h"
34 #include "llvm/IR/DataLayout.h"
45 #include "llvm/IR/GlobalValue.h"
770771 dwarf::Attribute Attribute,
771772 const MachineLocation &Location) {
772773 DIELoc *Loc = new (DIEValueAllocator) DIELoc();
773 unsigned N = DV.getNumAddrElements();
774 unsigned i = 0;
775 bool validReg;
776 if (Location.isReg()) {
777 if (N >= 2 && DV.getAddrElement(0) == dwarf::DW_OP_plus) {
778 assert(!DV.getVariable().isIndirect() &&
779 "double indirection not handled");
780 // If first address element is OpPlus then emit
781 // DW_OP_breg + Offset instead of DW_OP_reg + Offset.
782 validReg = addRegisterOffset(*Loc, Location.getReg(), DV.getAddrElement(1));
783 i = 2;
784 } else if (N >= 2 && DV.getAddrElement(0) == dwarf::DW_OP_deref) {
785 assert(!DV.getVariable().isIndirect() &&
786 "double indirection not handled");
787 validReg = addRegisterOpPiece(*Loc, Location.getReg(),
788 DV.getExpression().getPieceSize(),
789 DV.getExpression().getPieceOffset());
790 i = 3;
791 } else
792 validReg = addRegisterOpPiece(*Loc, Location.getReg());
793 } else
794 validReg = addRegisterOffset(*Loc, Location.getReg(), Location.getOffset());
795
796 if (!validReg)
797 return;
798
799 for (; i < N; ++i) {
800 uint64_t Element = DV.getAddrElement(i);
801 if (Element == dwarf::DW_OP_plus) {
802 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_plus_uconst);
803 addUInt(*Loc, dwarf::DW_FORM_udata, DV.getAddrElement(++i));
804
805 } else if (Element == dwarf::DW_OP_deref) {
806 if (!Location.isReg())
807 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_deref);
808
809 } else if (Element == dwarf::DW_OP_piece) {
810 const unsigned SizeOfByte = 8;
811 unsigned PieceOffsetInBits = DV.getAddrElement(++i) * SizeOfByte;
812 unsigned PieceSizeInBits = DV.getAddrElement(++i) * SizeOfByte;
813 // Emit DW_OP_bit_piece Size Offset.
814 assert(PieceSizeInBits > 0 && "piece has zero size");
815 addUInt(*Loc, dwarf::DW_FORM_data1, dwarf::DW_OP_bit_piece);
816 addUInt(*Loc, dwarf::DW_FORM_udata, PieceSizeInBits);
817 addUInt(*Loc, dwarf::DW_FORM_udata, PieceOffsetInBits);
818 } else
819 llvm_unreachable("unknown DIBuilder Opcode");
774 DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc);
775 DIExpression Expr = DV.getExpression();
776 if (Location.getOffset()) {
777 if (DwarfExpr.AddMachineRegIndirect(Location.getReg(),
778 Location.getOffset())) {
779 DwarfExpr.AddExpression(Expr);
780 assert(!DV.getVariable().isIndirect()
781 && "double indirection not handled");
782 }
783 } else {
784 if (DwarfExpr.AddMachineRegExpression(Expr, Location.getReg()))
785 if (DV.getVariable().isIndirect())
786 DwarfExpr.EmitOp(dwarf::DW_OP_deref);
820787 }
821788
822789 // Now attach the location information to the DIE.