summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2013-08-27 23:49:04 +0000
committerEric Christopher <echristo@gmail.com>2013-08-27 23:49:04 +0000
commit7b2ee399d9c1b2112962d29540c25b94fa98e8ed (patch)
tree091e20b1a9eaba3b3e303bd61158a9328ecdfcbf
parent6e74bfc0e6b7ab56c15ca5b6444a1ff83ff60709 (diff)
downloadllvm-7b2ee399d9c1b2112962d29540c25b94fa98e8ed.tar.gz
llvm-7b2ee399d9c1b2112962d29540c25b94fa98e8ed.tar.bz2
llvm-7b2ee399d9c1b2112962d29540c25b94fa98e8ed.tar.xz
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
-rw-r--r--lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp75
-rw-r--r--test/DebugInfo/X86/dbg-const-int.ll8
-rw-r--r--test/DebugInfo/X86/debug-info-static-member.ll4
-rw-r--r--test/DebugInfo/X86/multiple-at-const-val.ll2
-rw-r--r--test/DebugInfo/X86/template.ll6
5 files changed, 65 insertions, 30 deletions
diff --git a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 8cef3e2b25..7b3842811a 100644
--- a/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -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;
+ uint16_t Form;
+
+ // 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;
}
- SignedConstant ? addSInt(Block, 0, Form, MO.getImm())
- : addUInt(Block, 0, Form, MO.getImm());
- addBlock(Die, dwarf::DW_AT_const_value, 0, Block);
+ // 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;
+ // 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;
+ }
+
+ // 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;
+ 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;
+ addUInt(Die, dwarf::DW_AT_const_value, dwarf::DW_FORM_udata,
+ Val.getZExtValue());
+ return;
}
- if (Unsigned)
- addUInt(Die, dwarf::DW_AT_const_value, form, Val.getZExtValue());
- else
- addSInt(Die, dwarf::DW_AT_const_value, form, Val.getSExtValue());
+ addUInt(Die, dwarf::DW_AT_const_value, Form, Val.getZExtValue());
return;
}
diff --git a/test/DebugInfo/X86/dbg-const-int.ll b/test/DebugInfo/X86/dbg-const-int.ll
index 4ff0301bc1..7b6c40cc0a 100644
--- a/test/DebugInfo/X86/dbg-const-int.ll
+++ b/test/DebugInfo/X86/dbg-const-int.ll
@@ -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
diff --git a/test/DebugInfo/X86/debug-info-static-member.ll b/test/DebugInfo/X86/debug-info-static-member.ll
index cda725a7ff..4378115c6f 100644
--- a/test/DebugInfo/X86/debug-info-static-member.ll
+++ b/test/DebugInfo/X86/debug-info-static-member.ll
@@ -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
diff --git a/test/DebugInfo/X86/multiple-at-const-val.ll b/test/DebugInfo/X86/multiple-at-const-val.ll
index 13fa48b109..e966fc0509 100644
--- a/test/DebugInfo/X86/multiple-at-const-val.ll
+++ b/test/DebugInfo/X86/multiple-at-const-val.ll
@@ -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
diff --git a/test/DebugInfo/X86/template.ll b/test/DebugInfo/X86/template.ll
index 16808e1e4c..e7aff79b7c 100644
--- a/test/DebugInfo/X86/template.ll
+++ b/test/DebugInfo/X86/template.ll
@@ -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]]}