Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -270,7 +270,7 @@ // mixes non-fragments and fragments for the same variable is too expensive // to detect in the verifier. if (DwarfExpr->isUnknownLocation()) - DwarfExpr->setMemoryLocationKind(); + DwarfExpr->setMemoryLocationFlag(); DwarfExpr->addExpression(Expr); } if (Asm->TM.getTargetTriple().isNVPTX() && DD->tuneForGDB()) { @@ -674,7 +674,7 @@ if (Expr) Ops.append(Expr->elements_begin(), Expr->elements_end()); DIExpressionCursor Cursor(Ops); - DwarfExpr.setMemoryLocationKind(); + DwarfExpr.setMemoryLocationFlag(); if (const MCSymbol *FrameSymbol = Asm->getFunctionFrameSymbol()) addOpAddress(*Loc, FrameSymbol); else @@ -1107,7 +1107,7 @@ DIELoc *Loc = new (DIEValueAllocator) DIELoc; DIEDwarfExpression DwarfExpr(*Asm, *this, *Loc); if (Location.isIndirect()) - DwarfExpr.setMemoryLocationKind(); + DwarfExpr.setMemoryLocationFlag(); DIExpressionCursor Cursor({}); const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo(); @@ -1131,7 +1131,7 @@ const DIExpression *DIExpr = DV.getSingleExpression(); DwarfExpr.addFragmentOffset(DIExpr); if (Location.isIndirect()) - DwarfExpr.setMemoryLocationKind(); + DwarfExpr.setMemoryLocationFlag(); DIExpressionCursor Cursor(DIExpr); const TargetRegisterInfo &TRI = *Asm->MF->getSubtarget().getRegisterInfo(); Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1969,7 +1969,7 @@ } else if (Value.isLocation()) { MachineLocation Location = Value.getLoc(); if (Location.isIndirect()) - DwarfExpr.setMemoryLocationKind(); + DwarfExpr.setMemoryLocationFlag(); DIExpressionCursor Cursor(DIExpr); const TargetRegisterInfo &TRI = *AP.MF->getSubtarget().getRegisterInfo(); if (!DwarfExpr.addMachineRegExpression(TRI, Cursor, Location.getReg())) Index: lib/CodeGen/AsmPrinter/DwarfExpression.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfExpression.h +++ lib/CodeGen/AsmPrinter/DwarfExpression.h @@ -117,9 +117,34 @@ unsigned SubRegisterSizeInBits = 0; unsigned SubRegisterOffsetInBits = 0; - /// The kind of location description being produced. - enum { Unknown = 0, Register, Memory, Implicit } LocationKind = Unknown; + /// The flags of location description being produced. + enum LocationFlags : uint8_t { + Unknown = 0, + Register = 1, + Memory = 1 << 1, + Implicit = 1 << 2 + }; + + uint8_t LocationFlags = 0; + +public: + bool isUnknownLocation() { + return LocationFlags == Unknown; + } + + bool isRegisterLocation() { + return LocationFlags & Register; + } + bool isMemoryLocation() { + return LocationFlags & Memory; + } + + bool isImplicitLocation() { + return LocationFlags & Implicit; + } + +protected: /// Push a DW_OP_piece / DW_OP_bit_piece for emitting later, if one is needed /// to represent a subregister. void setSubRegisterPiece(unsigned SizeInBits, unsigned OffsetInBits) { @@ -220,13 +245,10 @@ /// Emit an unsigned constant. void addUnsignedConstant(const APInt &Value); - bool isMemoryLocation() const { return LocationKind == Memory; } - bool isUnknownLocation() const { return LocationKind == Unknown; } - /// Lock this down to become a memory location description. - void setMemoryLocationKind() { - assert(LocationKind == Unknown); - LocationKind = Memory; + void setMemoryLocationFlag() { + assert(isUnknownLocation()); + LocationFlags |= Memory; } /// Emit a machine register location. As an optimization this may also consume Index: lib/CodeGen/AsmPrinter/DwarfExpression.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -40,9 +40,9 @@ void DwarfExpression::addReg(int DwarfReg, const char *Comment) { assert(DwarfReg >= 0 && "invalid negative dwarf register number"); - assert((LocationKind == Unknown || LocationKind == Register) && + assert((isUnknownLocation() || isRegisterLocation()) && "location description already locked down"); - LocationKind = Register; + LocationFlags |= Register; if (DwarfReg < 32) { emitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment); } else { @@ -53,7 +53,7 @@ void DwarfExpression::addBReg(int DwarfReg, int Offset) { assert(DwarfReg >= 0 && "invalid negative dwarf register number"); - assert(LocationKind != Register && "location description already locked down"); + assert(!isRegisterLocation() && "location description already locked down"); if (DwarfReg < 32) { emitOp(dwarf::DW_OP_breg0 + DwarfReg); } else { @@ -184,21 +184,21 @@ } void DwarfExpression::addSignedConstant(int64_t Value) { - assert(LocationKind == Implicit || LocationKind == Unknown); - LocationKind = Implicit; + assert(isImplicitLocation() || isUnknownLocation()); + LocationFlags |= Implicit; emitOp(dwarf::DW_OP_consts); emitSigned(Value); } void DwarfExpression::addUnsignedConstant(uint64_t Value) { - assert(LocationKind == Implicit || LocationKind == Unknown); - LocationKind = Implicit; + assert(isImplicitLocation() || isUnknownLocation()); + LocationFlags |= Implicit; emitConstu(Value); } void DwarfExpression::addUnsignedConstant(const APInt &Value) { - assert(LocationKind == Implicit || LocationKind == Unknown); - LocationKind = Implicit; + assert(isImplicitLocation() || isUnknownLocation()); + LocationFlags |= Implicit; unsigned Size = Value.getBitWidth(); const uint64_t *Data = Value.getRawData(); @@ -222,7 +222,7 @@ unsigned FragmentOffsetInBits) { auto Fragment = ExprCursor.getFragmentInfo(); if (!addMachineReg(TRI, MachineReg, Fragment ? Fragment->SizeInBits : ~1U)) { - LocationKind = Unknown; + LocationFlags = Unknown; return false; } @@ -237,12 +237,12 @@ // operation to multiple DW_OP_pieces. if (HasComplexExpression && DwarfRegs.size() > 1) { DwarfRegs.clear(); - LocationKind = Unknown; + LocationFlags = Unknown; return false; } // Handle simple register locations. - if (LocationKind != Memory && !HasComplexExpression) { + if (!isMemoryLocation() && !HasComplexExpression) { for (auto &Reg : DwarfRegs) { if (Reg.DwarfRegNo >= 0) addReg(Reg.DwarfRegNo, Reg.Comment); @@ -258,7 +258,7 @@ return Op.getOp() == dwarf::DW_OP_stack_value; })) { DwarfRegs.clear(); - LocationKind = Unknown; + LocationFlags = Unknown; return false; } @@ -343,18 +343,18 @@ SizeInBits = std::min(SizeInBits, SubRegisterSizeInBits); // Emit a DW_OP_stack_value for implicit location descriptions. - if (LocationKind == Implicit) + if (isImplicitLocation()) addStackValue(); // Emit the DW_OP_piece. addOpPiece(SizeInBits, SubRegisterOffsetInBits); setSubRegisterPiece(0, 0); // Reset the location description kind. - LocationKind = Unknown; + LocationFlags = Unknown; return; } case dwarf::DW_OP_plus_uconst: - assert(LocationKind != Register); + assert(!isRegisterLocation()); emitOp(dwarf::DW_OP_plus_uconst); emitUnsigned(Op->getArg(0)); break; @@ -375,16 +375,16 @@ emitOp(Op->getOp()); break; case dwarf::DW_OP_deref: - assert(LocationKind != Register); - if (LocationKind != Memory && ::isMemoryLocation(ExprCursor)) + assert(!isRegisterLocation()); + if (!isMemoryLocation() && ::isMemoryLocation(ExprCursor)) // Turning this into a memory location description makes the deref // implicit. - LocationKind = Memory; + LocationFlags |= Memory; else emitOp(dwarf::DW_OP_deref); break; case dwarf::DW_OP_constu: - assert(LocationKind != Register); + assert(!isRegisterLocation()); emitConstu(Op->getArg(0)); break; case dwarf::DW_OP_LLVM_convert: { @@ -424,14 +424,14 @@ break; } case dwarf::DW_OP_stack_value: - LocationKind = Implicit; + LocationFlags |= Implicit; break; case dwarf::DW_OP_swap: - assert(LocationKind != Register); + assert(!isRegisterLocation()); emitOp(dwarf::DW_OP_swap); break; case dwarf::DW_OP_xderef: - assert(LocationKind != Register); + assert(!isRegisterLocation()); emitOp(dwarf::DW_OP_xderef); break; case dwarf::DW_OP_deref_size: @@ -443,7 +443,7 @@ } } - if (LocationKind == Implicit) + if (isImplicitLocation()) // Turn this into an implicit location description. addStackValue(); }