forked from OSchip/llvm-project
PR32288: Describe a bool parameter's DWARF location with a simple register
There's no need (& a bit incorrect) to mask off the high bits of the register reference when describing a simple bool value. Reviewers: aprantl Differential Revision: https://reviews.llvm.org/D31062 llvm-svn: 303117
This commit is contained in:
parent
e29686e5c1
commit
441cfee780
|
@ -1105,8 +1105,9 @@ static bool PhiHasDebugValue(DILocalVariable *DIVar,
|
|||
void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
|
||||
StoreInst *SI, DIBuilder &Builder) {
|
||||
auto *DIVar = DDI->getVariable();
|
||||
auto *DIExpr = DDI->getExpression();
|
||||
assert(DIVar && "Missing variable");
|
||||
auto *DIExpr = DDI->getExpression();
|
||||
Value *DV = SI->getOperand(0);
|
||||
|
||||
// If an argument is zero extended then use argument directly. The ZExt
|
||||
// may be zapped by an optimization pass in future.
|
||||
|
@ -1116,34 +1117,28 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI,
|
|||
if (SExtInst *SExt = dyn_cast<SExtInst>(SI->getOperand(0)))
|
||||
ExtendedArg = dyn_cast<Argument>(SExt->getOperand(0));
|
||||
if (ExtendedArg) {
|
||||
// We're now only describing a subset of the variable. The fragment we're
|
||||
// describing will always be smaller than the variable size, because
|
||||
// VariableSize == Size of Alloca described by DDI. Since SI stores
|
||||
// to the alloca described by DDI, if it's first operand is an extend,
|
||||
// we're guaranteed that before extension, the value was narrower than
|
||||
// the size of the alloca, hence the size of the described variable.
|
||||
SmallVector<uint64_t, 3> Ops;
|
||||
unsigned FragmentOffset = 0;
|
||||
// If this already is a bit fragment, we drop the bit fragment from the
|
||||
// expression and record the offset.
|
||||
auto Fragment = DIExpr->getFragmentInfo();
|
||||
if (Fragment) {
|
||||
Ops.append(DIExpr->elements_begin(), DIExpr->elements_end()-3);
|
||||
FragmentOffset = Fragment->OffsetInBits;
|
||||
} else {
|
||||
Ops.append(DIExpr->elements_begin(), DIExpr->elements_end());
|
||||
}
|
||||
// If this DDI was already describing only a fragment of a variable, ensure
|
||||
// that fragment is appropriately narrowed here.
|
||||
// But if a fragment wasn't used, describe the value as the original
|
||||
// argument (rather than the zext or sext) so that it remains described even
|
||||
// if the sext/zext is optimized away. This widens the variable description,
|
||||
// leaving it up to the consumer to know how the smaller value may be
|
||||
// represented in a larger register.
|
||||
if (auto Fragment = DIExpr->getFragmentInfo()) {
|
||||
unsigned FragmentOffset = Fragment->OffsetInBits;
|
||||
SmallVector<uint64_t, 3> Ops(DIExpr->elements_begin(),
|
||||
DIExpr->elements_end() - 3);
|
||||
Ops.push_back(dwarf::DW_OP_LLVM_fragment);
|
||||
Ops.push_back(FragmentOffset);
|
||||
const DataLayout &DL = DDI->getModule()->getDataLayout();
|
||||
Ops.push_back(DL.getTypeSizeInBits(ExtendedArg->getType()));
|
||||
auto NewDIExpr = Builder.createExpression(Ops);
|
||||
if (!LdStHasDebugValue(DIVar, NewDIExpr, SI))
|
||||
Builder.insertDbgValueIntrinsic(ExtendedArg, 0, DIVar, NewDIExpr,
|
||||
DDI->getDebugLoc(), SI);
|
||||
} else if (!LdStHasDebugValue(DIVar, DIExpr, SI))
|
||||
Builder.insertDbgValueIntrinsic(SI->getOperand(0), 0, DIVar, DIExpr,
|
||||
DDI->getDebugLoc(), SI);
|
||||
DIExpr = Builder.createExpression(Ops);
|
||||
}
|
||||
DV = ExtendedArg;
|
||||
}
|
||||
if (!LdStHasDebugValue(DIVar, DIExpr, SI))
|
||||
Builder.insertDbgValueIntrinsic(DV, 0, DIVar, DIExpr, DDI->getDebugLoc(),
|
||||
SI);
|
||||
}
|
||||
|
||||
/// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value
|
||||
|
|
|
@ -3,43 +3,85 @@
|
|||
; if it only describes part of the variable.
|
||||
; RUN: opt -S -sroa %s | FileCheck %s
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
|
||||
; Built from:
|
||||
; struct foo { bool b; long i; };
|
||||
; void f(bool b, bool expr, foo g) {
|
||||
; }
|
||||
; And modifying the frag dbg.declare to use a fragmented DIExpression (with offset: 0, size: 4)
|
||||
; to test the dbg.declare+fragment case here.
|
||||
|
||||
; Function Attrs: nounwind uwtable
|
||||
define hidden void @_ZN6__tsan9FastState14SetHistorySizeEi(i32 %hs) #1 align 2 {
|
||||
; Expect two fragments:
|
||||
; * first starting at bit 0, 8 bits (for the bool)
|
||||
; * second starting at bit 32, 32 bits (for the long)
|
||||
; (this happens to create/demonstrate a gap from bits [7, 32))
|
||||
|
||||
; But also check that a complex expression is not used for a lone bool
|
||||
; parameter. It can reference the register it's in directly without masking off
|
||||
; high bits or anything
|
||||
|
||||
; CHECK: call void @llvm.dbg.value(metadata i8 %g.coerce0, i64 0, metadata ![[VAR_STRUCT:[0-9]+]], metadata ![[EXPR_STRUCT1:[0-9]+]])
|
||||
; CHECK: call void @llvm.dbg.value(metadata i64 %g.coerce1, i64 0, metadata ![[VAR_STRUCT]], metadata ![[EXPR_STRUCT2:[0-9]+]])
|
||||
; CHECK: call void @llvm.dbg.value(metadata i1 %b, i64 0, metadata ![[VAR_BOOL:[0-9]+]], metadata ![[EXPR_BOOL:[0-9]+]])
|
||||
; CHECK: call void @llvm.dbg.value(metadata i1 %frag, i64 0, metadata ![[FRAG_BOOL:[0-9]+]], metadata ![[FRAG_BOOL:[0-9]+]])
|
||||
; CHECK: ![[EXPR_STRUCT1]] = !DIExpression(DW_OP_LLVM_fragment, 0, 8)
|
||||
; CHECK: ![[EXPR_STRUCT2]] = !DIExpression(DW_OP_LLVM_fragment, 32, 64)
|
||||
; CHECK: ![[EXPR_BOOL]] = !DIExpression()
|
||||
; CHECK: ![[FRAG_BOOL]] = !DIExpression(DW_OP_LLVM_fragment, 0, 1)
|
||||
|
||||
%struct.foo = type { i8, i64 }
|
||||
|
||||
; Function Attrs: noinline nounwind uwtable
|
||||
define void @_Z1fbb3foo(i1 zeroext %b, i1 zeroext %frag, i8 %g.coerce0, i64 %g.coerce1) #0 !dbg !6 {
|
||||
entry:
|
||||
%hs.addr = alloca i32, align 4
|
||||
%v1 = alloca i64, align 8
|
||||
%v2 = alloca i64, align 8
|
||||
store i32 %hs, i32* %hs.addr, align 4
|
||||
; CHECK: call void @llvm.dbg.value(metadata i32 %hs, i64 0, metadata !{{[0-9]+}}, metadata ![[EXPR:[0-9]+]])
|
||||
; CHECK: ![[EXPR]] = !DIExpression(DW_OP_LLVM_fragment, 0
|
||||
call void @llvm.dbg.declare(metadata i64* %v1, metadata !9, metadata !12), !dbg !13
|
||||
%0 = load i32, i32* %hs.addr, align 4
|
||||
%conv = sext i32 %0 to i64
|
||||
store i64 %conv, i64* %v1, align 8
|
||||
%1 = load i64, i64* %v2, align 8
|
||||
unreachable
|
||||
%g = alloca %struct.foo, align 8
|
||||
%b.addr = alloca i8, align 1
|
||||
%frag.addr = alloca i8, align 1
|
||||
%0 = bitcast %struct.foo* %g to { i8, i64 }*
|
||||
%1 = getelementptr inbounds { i8, i64 }, { i8, i64 }* %0, i32 0, i32 0
|
||||
store i8 %g.coerce0, i8* %1, align 8
|
||||
%2 = getelementptr inbounds { i8, i64 }, { i8, i64 }* %0, i32 0, i32 1
|
||||
store i64 %g.coerce1, i64* %2, align 8
|
||||
%frombool = zext i1 %b to i8
|
||||
store i8 %frombool, i8* %b.addr, align 1
|
||||
call void @llvm.dbg.declare(metadata i8* %b.addr, metadata !15, metadata !16), !dbg !17
|
||||
%frombool1 = zext i1 %frag to i8
|
||||
store i8 %frombool1, i8* %frag.addr, align 1
|
||||
call void @llvm.dbg.declare(metadata i8* %frag.addr, metadata !18, metadata !23), !dbg !19
|
||||
call void @llvm.dbg.declare(metadata %struct.foo* %g, metadata !20, metadata !16), !dbg !21
|
||||
ret void, !dbg !22
|
||||
}
|
||||
|
||||
attributes #0 = { nounwind readnone }
|
||||
; Function Attrs: nounwind readnone speculatable
|
||||
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
|
||||
|
||||
attributes #0 = { noinline nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #1 = { nounwind readnone speculatable }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!7}
|
||||
!llvm.ident = !{!8}
|
||||
!llvm.module.flags = !{!3, !4}
|
||||
!llvm.ident = !{!5}
|
||||
|
||||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 256979) (llvm/trunk 257107)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2)
|
||||
!1 = !DIFile(filename: "tsan_shadow_test.cc", directory: "/tmp")
|
||||
!2 = !{!3, !5}
|
||||
!3 = !DICompositeType(tag: DW_TAG_class_type, name: "FastState", file: !4, line: 91, size: 64, align: 64, identifier: "_ZTSN6__tsan9FastStateE")
|
||||
!4 = !DIFile(filename: "/mnt/extra/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_rtl.h", directory: "/tmp")
|
||||
!5 = distinct !DIDerivedType(tag: DW_TAG_typedef, name: "u64", line: 78, baseType: !6)
|
||||
!6 = !DIBasicType(name: "long long unsigned int", size: 64, align: 64, encoding: DW_ATE_unsigned)
|
||||
!7 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!8 = !{!"clang version 3.8.0 (trunk 256979) (llvm/trunk 257107)"}
|
||||
!9 = !DILocalVariable(name: "v1", scope: !10, file: !4, line: 136, type: !5)
|
||||
!10 = distinct !DILexicalBlock(scope: !11, file: !4, line: 136, column: 5)
|
||||
!11 = distinct !DISubprogram(name: "SetHistorySize", linkageName: "_ZN6__tsan9FastState14SetHistorySizeEi", scope: !3, file: !4, line: 135, isLocal: false, isDefinition: true, scopeLine: 135, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
|
||||
!12 = !DIExpression()
|
||||
!13 = !DILocation(line: 136, column: 5, scope: !10)
|
||||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 5.0.0 (trunk 303077) (llvm/trunk 303098)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
|
||||
!1 = !DIFile(filename: "foo.cpp", directory: "/usr/local/google/home/blaikie/dev/scratch")
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!5 = !{!"clang version 5.0.0 (trunk 303077) (llvm/trunk 303098)"}
|
||||
!6 = distinct !DISubprogram(name: "f", linkageName: "_Z1fbb3foo", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
|
||||
!7 = !DISubroutineType(types: !8)
|
||||
!8 = !{null, !9, !9, !10}
|
||||
!9 = !DIBasicType(name: "bool", size: 8, encoding: DW_ATE_boolean)
|
||||
!10 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "foo", file: !1, line: 1, size: 128, elements: !11, identifier: "_ZTS3foo")
|
||||
!11 = !{!12, !13}
|
||||
!12 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !10, file: !1, line: 1, baseType: !9, size: 8)
|
||||
!13 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !10, file: !1, line: 1, baseType: !14, size: 64, offset: 64)
|
||||
!14 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed)
|
||||
!15 = !DILocalVariable(name: "b", arg: 1, scope: !6, file: !1, line: 2, type: !9)
|
||||
!16 = !DIExpression()
|
||||
!17 = !DILocation(line: 2, column: 13, scope: !6)
|
||||
!18 = !DILocalVariable(name: "frag", arg: 2, scope: !6, file: !1, line: 2, type: !9)
|
||||
!19 = !DILocation(line: 2, column: 21, scope: !6)
|
||||
!20 = !DILocalVariable(name: "g", arg: 3, scope: !6, file: !1, line: 2, type: !10)
|
||||
!21 = !DILocation(line: 2, column: 31, scope: !6)
|
||||
!22 = !DILocation(line: 3, column: 1, scope: !6)
|
||||
!23 = !DIExpression(DW_OP_LLVM_fragment, 0, 4)
|
||||
|
|
Loading…
Reference in New Issue