]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/commitdiff
DwarfUnit: Pick a winner between isTypeSigned and isUnsignedDIType.
authorDavid Blaikie <dblaikie@gmail.com>
Sun, 11 May 2014 16:08:41 +0000 (16:08 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Sun, 11 May 2014 16:08:41 +0000 (16:08 +0000)
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

lib/CodeGen/AsmPrinter/DwarfUnit.cpp
lib/CodeGen/AsmPrinter/DwarfUnit.h

index e8a723800b1bf537b30829d425a812fd2a39a57a..7e1a9879c67757f5e3c0f354bc72a91a6c577afd 100644 (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;
   }
 
index 8be601bf8cfac54cc097bcfda2935abd3d29b225..e44f256c3a352e51b6bcdac70e4fd436d64ae53a 100644 (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);