DwarfUnit: Pick a winner between isTypeSigned and isUnsignedDIType.

And the winner by a nose is isUnsignedDIType, for no particular reason.

These two functions were just complements of each other and used in very
related code, so refactor callers to just use one of them.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208500 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-05-11 16:08:41 +00:00
parent 9cfc5b23a1
commit f2bd335042
2 changed files with 17 additions and 24 deletions

View File

@ -745,17 +745,6 @@ void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
addBlock(Die, Attribute, Loc);
}
/// isTypeSigned - Return true if the type is signed.
static bool isTypeSigned(DwarfDebug *DD, DIType Ty) {
if (Ty.isDerivedType())
return isTypeSigned(DD,
DD->resolve(DIDerivedType(Ty).getTypeDerivedFrom()));
return Ty.isBasicType() &&
(DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed ||
DIBasicType(Ty).getEncoding() == dwarf::DW_ATE_signed_char);
}
/// Return true if type encoding is unsigned.
static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
DIDerivedType DTy(Ty);
@ -763,14 +752,17 @@ static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
return isUnsignedDIType(DD, DD->resolve(DTy.getTypeDerivedFrom()));
DIBasicType BTy(Ty);
if (BTy.isBasicType()) {
unsigned Encoding = BTy.getEncoding();
if (Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char ||
Encoding == dwarf::DW_ATE_boolean)
return true;
}
return false;
if (!BTy.isBasicType())
return false;
unsigned Encoding = BTy.getEncoding();
assert(Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char ||
Encoding == dwarf::DW_ATE_signed ||
Encoding == dwarf::DW_ATE_signed_char ||
Encoding == dwarf::DW_ATE_boolean && "Unsupported encoding");
return (Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char ||
Encoding == dwarf::DW_ATE_boolean);
}
/// If this type is derived from a base type then return base type size.
@ -841,14 +833,14 @@ void DwarfUnit::addConstantValue(DIE &Die, const MachineOperand &MO,
DIType Ty) {
assert(MO.isImm() && "Invalid machine operand!");
addConstantValue(Die, isTypeSigned(DD, Ty), MO.getImm());
addConstantValue(Die, isUnsignedDIType(DD, Ty), MO.getImm());
}
void DwarfUnit::addConstantValue(DIE &Die, bool Signed, uint64_t Val) {
void DwarfUnit::addConstantValue(DIE &Die, bool Unsigned, uint64_t Val) {
// FIXME: This is a bit conservative/simple - it emits negative values always
// sign extended to 64 bits rather than minimizing the number of bytes.
addUInt(Die, dwarf::DW_AT_const_value,
Signed ? dwarf::DW_FORM_sdata : dwarf::DW_FORM_udata, Val);
Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata, Val);
}
void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, DIType Ty) {
@ -859,7 +851,8 @@ void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, DIType Ty) {
void DwarfUnit::addConstantValue(DIE &Die, const APInt &Val, bool Unsigned) {
unsigned CIBitWidth = Val.getBitWidth();
if (CIBitWidth <= 64) {
addConstantValue(Die, !Unsigned, Unsigned ? Val.getZExtValue() : Val.getSExtValue());
addConstantValue(Die, Unsigned,
Unsigned ? Val.getZExtValue() : Val.getSExtValue());
return;
}

View File

@ -351,7 +351,7 @@ public:
void addConstantValue(DIE &Die, const ConstantInt *CI, DIType Ty);
void addConstantValue(DIE &Die, const APInt &Val, DIType Ty);
void addConstantValue(DIE &Die, const APInt &Val, bool Unsigned);
void addConstantValue(DIE &Die, bool Signed, uint64_t Val);
void addConstantValue(DIE &Die, bool Unsigned, uint64_t Val);
/// addConstantFPValue - Add constant value entry in variable DIE.
void addConstantFPValue(DIE &Die, const MachineOperand &MO);