Use DW_FORM_sdata for signed constant values and udata on occasion

when we can. Migrate from using blocks when we're adding just a
single attribute and floating point values are an unsigned, not signed,
bag of bits.

Update all test cases accordingly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189419 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Christopher 2013-08-27 23:49:04 +00:00
parent 6e74bfc0e6
commit 7b2ee399d9
5 changed files with 68 additions and 33 deletions

View File

@ -606,21 +606,36 @@ void CompileUnit::addConstantValue(DIE *Die, const MachineOperand &MO,
// their maximum bit width which is a bit unfortunate (& doesn't prefer
// udata/sdata over dataN as suggested by the DWARF spec)
assert(MO.isImm() && "Invalid machine operand!");
DIEBlock *Block = new (DIEValueAllocator) DIEBlock();
int SizeInBits = -1;
bool SignedConstant = isTypeSigned(Ty, &SizeInBits);
uint16_t Form = SignedConstant ? dwarf::DW_FORM_sdata : dwarf::DW_FORM_udata;
switch (SizeInBits) {
case 8: Form = dwarf::DW_FORM_data1; break;
case 16: Form = dwarf::DW_FORM_data2; break;
case 32: Form = dwarf::DW_FORM_data4; break;
case 64: Form = dwarf::DW_FORM_data8; break;
default: break;
}
SignedConstant ? addSInt(Block, 0, Form, MO.getImm())
: addUInt(Block, 0, Form, MO.getImm());
uint16_t Form;
addBlock(Die, dwarf::DW_AT_const_value, 0, Block);
// If we're a signed constant definitely use sdata.
if (SignedConstant) {
addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata, MO.getImm());
return;
}
// Else use data for now unless it's larger than we can deal with.
switch (SizeInBits) {
case 8:
Form = dwarf::DW_FORM_data1;
break;
case 16:
Form = dwarf::DW_FORM_data2;
break;
case 32:
Form = dwarf::DW_FORM_data4;
break;
case 64:
Form = dwarf::DW_FORM_data8;
break;
default:
Form = dwarf::DW_FORM_udata;
addUInt(Die, dwarf::DW_AT_const_value, Form, MO.getImm());
return;
}
addUInt(Die, dwarf::DW_AT_const_value, Form, MO.getImm());
}
/// addConstantFPValue - Add constant value entry in variable DIE.
@ -649,7 +664,8 @@ void CompileUnit::addConstantFPValue(DIE *Die, const MachineOperand &MO) {
/// addConstantFPValue - Add constant value entry in variable DIE.
void CompileUnit::addConstantFPValue(DIE *Die, const ConstantFP *CFP) {
addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), false);
// Pass this down to addConstantValue as an unsigned bag of bits.
addConstantValue(Die, CFP->getValueAPF().bitcastToAPInt(), true);
}
/// addConstantValue - Add constant value entry in variable DIE.
@ -662,19 +678,34 @@ void CompileUnit::addConstantValue(DIE *Die, const ConstantInt *CI,
void CompileUnit::addConstantValue(DIE *Die, const APInt &Val, bool Unsigned) {
unsigned CIBitWidth = Val.getBitWidth();
if (CIBitWidth <= 64) {
unsigned form = 0;
switch (CIBitWidth) {
case 8: form = dwarf::DW_FORM_data1; break;
case 16: form = dwarf::DW_FORM_data2; break;
case 32: form = dwarf::DW_FORM_data4; break;
case 64: form = dwarf::DW_FORM_data8; break;
default:
form = Unsigned ? dwarf::DW_FORM_udata : dwarf::DW_FORM_sdata;
// If we're a signed constant definitely use sdata.
if (!Unsigned) {
addSInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
Val.getSExtValue());
return;
}
if (Unsigned)
addUInt(Die, dwarf::DW_AT_const_value, form, Val.getZExtValue());
else
addSInt(Die, dwarf::DW_AT_const_value, form, Val.getSExtValue());
// Else use data for now unless it's larger than we can deal with.
uint16_t Form;
switch (CIBitWidth) {
case 8:
Form = dwarf::DW_FORM_data1;
break;
case 16:
Form = dwarf::DW_FORM_data2;
break;
case 32:
Form = dwarf::DW_FORM_data4;
break;
case 64:
Form = dwarf::DW_FORM_data8;
break;
default:
addUInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata,
Val.getZExtValue());
return;
}
addUInt(Die, dwarf::DW_AT_const_value, Form, Val.getZExtValue());
return;
}

View File

@ -1,9 +1,13 @@
; RUN: llc < %s - | FileCheck %s
; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj %s -o %t
; RUN: llvm-dwarfdump %t | FileCheck %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-macosx10.6.7"
; Radar 9511391
;CHECK: .byte 4 ## DW_AT_const_value
; CHECK: DW_TAG_variable
; CHECK: "i"
; CHECK: DW_AT_const_value [DW_FORM_sdata] (42)
define i32 @foo() nounwind uwtable readnone optsize ssp {
entry:
tail call void @llvm.dbg.value(metadata !8, i64 0, metadata !6), !dbg !9

View File

@ -120,7 +120,7 @@ declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
; PRESENT: DW_TAG_member
; PRESENT-NEXT: DW_AT_name {{.*}} "const_c"
; PRESENT: DW_AT_accessibility [DW_FORM_data1] (0x01)
; PRESENT: DW_AT_const_value {{.*}} (0x00000012)
; PRESENT: DW_AT_const_value {{.*}} (18)
; While we're here, a normal member has data_member_location and
; accessibility attributes.
; PRESENT: DW_TAG_member
@ -173,7 +173,7 @@ declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
; DARWINP: DW_TAG_member
; DARWINP-NEXT: DW_AT_name {{.*}} "const_c"
; DARWINP: DW_AT_accessibility [DW_FORM_data1] (0x01)
; DARWINP: DW_AT_const_value {{.*}} (0x00000012)
; DARWINP: DW_AT_const_value {{.*}} (18)
; While we're here, a normal member has data_member_location and
; accessibility attributes.
; DARWINP: DW_TAG_member

View File

@ -8,7 +8,7 @@
; CHECK: DW_TAG_class_type
; CHECK: DW_TAG_member
; CHECK: badbit
; CHECK: DW_AT_const_value [DW_FORM_data4] (0x00000001)
; CHECK: DW_AT_const_value [DW_FORM_sdata] (1)
; CHECK-NOT: DW_AT_const_value
; CHECK: NULL

View File

@ -27,7 +27,7 @@
; even as data1. DWARF strongly urges implementations to prefer
; _sdata/_udata rather than dataN
; CHECK-NEXT: DW_AT_const_value [DW_FORM_data4]{{.*}}(0x00000003)
; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(3)
; CHECK: DW_TAG_template_value_parameter
; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INTPTR:0x[0-9a-f]*]]}
@ -47,11 +47,11 @@
; CHECK-NOT: NULL
; CHECK: DW_TAG_template_value_parameter
; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]}
; CHECK-NEXT: DW_AT_const_value [DW_FORM_data4]{{.*}}(0x00000001)
; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(1)
; CHECK-NOT: NULL
; CHECK: DW_TAG_template_value_parameter
; CHECK-NEXT: DW_AT_type{{.*}}=> {[[INT]]}
; CHECK-NEXT: DW_AT_const_value [DW_FORM_data4]{{.*}}(0x00000002)
; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]{{.*}}(2)
; CHECK: [[INTPTR]]:{{ *}}DW_TAG_pointer_type
; CHECK-NEXT: DW_AT_type{{.*}} => {[[INT]]}