[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-27 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.
This revision now requires changes to proceed.

I think I may haved screwed up the phabricator process for this one.
This landed as r300523.


https://reviews.llvm.org/D31440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-14 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl updated this revision to Diff 95318.
aprantl edited the summary of this revision.
Herald added a subscriber: nhaehnle.

https://reviews.llvm.org/D31440

Files:
  lib/CodeGen/CGDebugInfo.cpp
  test/CodeGen/debug-info-vla.c
  test/CodeGenCXX/debug-info.cpp
  test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl

Index: test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
===
--- test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
+++ test/CodeGenOpenCL/amdgpu-debug-info-variable-expression.cl
@@ -1,6 +1,5 @@
 // RUN: %clang -cl-std=CL2.0 -emit-llvm -g -O0 -S -target amdgcn-amd-amdhsa -mcpu=fiji -o - %s | FileCheck %s
 
-// CHECK-DAG: ![[NONE:[0-9]+]] = !DIExpression()
 // CHECK-DAG: ![[LOCAL:[0-9]+]] = !DIExpression(DW_OP_constu, 2, DW_OP_swap, DW_OP_xderef)
 // CHECK-DAG: ![[PRIVATE:[0-9]+]] = !DIExpression(DW_OP_constu, 1, DW_OP_swap, DW_OP_xderef)
 
@@ -82,7 +81,7 @@
   int *FuncVar4 = Tmp1;
 
   // CHECK-DAG: ![[FUNCVAR5:[0-9]+]] = !DILocalVariable(name: "FuncVar5", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
-  // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE]]), !dbg !{{[0-9]+}}
+  // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(1)** {{.*}}, metadata ![[FUNCVAR5]], metadata ![[NONE:[0-9]+]]), !dbg !{{[0-9]+}}
   global int *constant FuncVar5 = KernelArg0;
   // CHECK-DAG: ![[FUNCVAR6:[0-9]+]] = !DILocalVariable(name: "FuncVar6", scope: !{{[0-9]+}}, file: !{{[0-9]+}}, line: {{[0-9]+}}, type: !{{[0-9]+}})
   // CHECK-DAG: call void @llvm.dbg.declare(metadata i32 addrspace(2)** {{.*}}, metadata ![[FUNCVAR6]], metadata ![[NONE]]), !dbg !{{[0-9]+}}
Index: test/CodeGenCXX/debug-info.cpp
===
--- test/CodeGenCXX/debug-info.cpp
+++ test/CodeGenCXX/debug-info.cpp
@@ -21,6 +21,7 @@
 
 // CHECK: ![[INCTYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "incomplete"
 // CHECK-SAME:   DIFlagFwdDecl
+// CHECK: ![[EXPR]] = !DIExpression()
 
 template struct Identity {
   typedef T Type;
@@ -117,7 +118,6 @@
 // For some reason function arguments ended up down here
 // CHECK: ![[F]] = !DILocalVariable(name: "f", arg: 1, scope: ![[FUNC]]
 // CHECK-SAME:  type: ![[FOO]]
-// CHECK: ![[EXPR]] = !DIExpression(DW_OP_deref)
 foo func(foo f) {
   return f; // reference 'f' for now because otherwise we hit another bug
 }
Index: test/CodeGen/debug-info-vla.c
===
--- test/CodeGen/debug-info-vla.c
+++ test/CodeGen/debug-info-vla.c
@@ -4,8 +4,8 @@
 {
 // CHECK: dbg.declare
 // CHECK: dbg.declare({{.*}}, metadata ![[VAR:.*]], metadata ![[EXPR:.*]])
-// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+2]]
-// CHECK: ![[EXPR]] = !DIExpression(DW_OP_deref)
+// CHECK: ![[EXPR]] = !DIExpression()
+// CHECK: ![[VAR]] = !DILocalVariable(name: "vla",{{.*}} line: [[@LINE+1]]
   int vla[s];
   int i;
   for (i = 0; i < s; i++) {
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -3466,17 +3466,17 @@
   // functions there won't be an implicit param at arg1 and
   // otherwise it is 'self' or 'this'.
   if (isa(VD) && ArgNo && *ArgNo == 1)
-Flags |= llvm::DINode::FlagObjectPointer;
-  if (auto *Arg = dyn_cast(Storage))
-if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&
-!VD->getType()->isPointerType())
-  Expr.push_back(llvm::dwarf::DW_OP_deref);
+  Flags |= llvm::DINode::FlagObjectPointer;
 
+  // Note: Older versions of clang used to emit byval references with an extra
+  // DW_OP_deref, because they referenced the IR arg directly instead of
+  // referencing an alloca. Newer versions of LLVM don't treat allocas
+  // differently from other function arguments when used in a dbg.declare.
   auto *Scope = cast(LexicalBlockStack.back());
-
   StringRef Name = VD->getName();
   if (!Name.empty()) {
 if (VD->hasAttr()) {
+  // Here, we need an offset *into* the alloca.
   CharUnits offset = CharUnits::fromQuantity(32);
   Expr.push_back(llvm::dwarf::DW_OP_plus);
   // offset of __forwarding field
@@ -3488,22 +3488,7 @@
   // offset of x field
   offset = CGM.getContext().toCharUnitsFromBits(XOffset);
   Expr.push_back(offset.getQuantity());
-
-  // Create the descriptor for the variable.
-  auto *D = ArgNo
-? DBuilder.createParameterVariable(Scope, VD->getName(),
-   *ArgNo, Unit, Line, Ty)
-: DBuilder.createAutoVariable(Scope, VD->getName(), Unit,
-  Line, Ty, Align);
-
-  // Insert an llvm.dbg.declare into 

[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-11 Thread Eric Christopher via Phabricator via cfe-commits
echristo requested changes to this revision.
echristo added a comment.
This revision now requires changes to proceed.

Sounds like Dave is asking for changes so I'll put it down as Request Changes 
to get it out of my queue. :)


https://reviews.llvm.org/D31440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-03 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In https://reviews.llvm.org/D31440#713396, @aprantl wrote:

> In https://reviews.llvm.org/D31440#713308, @dblaikie wrote:
>
> > I'm a bit confused - the alloca was only emitted at -O0, by the looks of 
> > it. Presumably it's pessimizing in some way at higher optimization levels? 
> > Or is that not the case?
>
>
> I think it is really working around the odd behavior of LLVM here. What gives 
> it away is the we key the addition of the extra DW_OP_deref on whether it is 
> an alloca or not. But note that this is not how dbg.declare works: 
> dbg.declare(%alloca, !DIExpression()) is (kind of) equivalent to 
> dbg.value(%alloca, !DIExpression(DW_OP_deref)). So we are using the presence 
> of the alloca as a proxy for how the backend happens to compile the 
> DwarfExpression here and work around its idiosyncrasy by emitting an extra 
> DW_OP_deref.


I'm still not really following, sorry - perhaps it'd help me if you could 
describe the state of things in ToT currently, the state this change attempts 
to create, and the state (if distinct from the previous) that might be ideal. 
(it's not clear to me if there's still a "workaround" after your change - 
sounds like there should be/is, if previously there was no alloca above O0 but 
after this change there will be... )

> 
> 
>> Also, it looks like this change lost the "if > gmlt" test, so might cause 
>> variable declarations (& thus types) to leak into GMLT, which is undesirable.
> 
> Oh.. that was unintentional collateral damage. Thanks for noticing!




https://reviews.llvm.org/D31440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-03 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl updated this revision to Diff 93900.

https://reviews.llvm.org/D31440

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenObjC/debug-info-block-captured-self.m
  test/CodeGenObjC/debug-info-blocks.m

Index: test/CodeGenObjC/debug-info-blocks.m
===
--- test/CodeGenObjC/debug-info-blocks.m
+++ test/CodeGenObjC/debug-info-blocks.m
@@ -4,11 +4,18 @@
 // Test that we generate the proper debug location for a captured self.
 // The second half of this test is in llvm/tests/DebugInfo/debug-info-blocks.ll
 
-// CHECK: define {{.*}}_block_invoke
-// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
-// CHECK-NEXT: store <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %[[BLOCK]], <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA:.*]], align
-// CHECK-NEXT: call void @llvm.dbg.declare(metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}})
-// CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}})
+// CHECK: define {{.*}}[A init]_block_invoke
+// CHECK-NEXT: entry
+// CHECK-NEXT: %[[DESC_ALLOCA:.*]] = alloca i8*, align 8
+// CHECK-NEXT: %[[BLOCK_ALLOCA:.*]] = alloca <{{.*}}>*, align 8
+// CHECK: store i8* %.block_descriptor, i8** %[[ALLOCA:.*]], align 8
+// CHECK: call void @llvm.dbg.declare(metadata i8** %[[DESC_ALLOCA]],
+// CHECK-SAME:metadata ![[BLOCK_VAR:[0-9]+]],
+// CHECK: call void @llvm.dbg.declare(
+// CHECK-SAME: metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>**
+// CHECK-SAME:  %[[BLOCK_ALLOCA]], metadata ![[SELF_VAR:[0-9]+]],
+// CHECK-SAME:  metadata ![[SELF_EXPR:[0-9]+]])
+// CHECK: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D_VAR:[0-9]+]],
 
 // rdar://problem/14386148
 // Test that we don't emit bogus line numbers for the helper functions.
@@ -22,11 +29,13 @@
 // CHECK-NOT: ret
 // CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]]
 
-// CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
-// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
-// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
+// CHECK-DAG: ![[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
+// CHECK-DAG: ![[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
+// CHECK-DAG: ![[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
+// CHECK-DAG: ![[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
+// CHECK-DAG: ![[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
+// CHECK-DAG: ![[BLOCK_VAR]] = !DILocalVariable(name: ".block_descriptor"
+// CHECK-DAG: ![[SELF_EXPR]] = !DIExpression(DW_OP_plus, 32, DW_OP_deref)
 typedef unsigned int NSUInteger;
 
 @protocol NSObject
@@ -61,8 +70,8 @@
 {
 if ((self = [super init])) {
   run(^{
-  // CHECK-DAG: ![[SELF]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
-  // CHECK-DAG: ![[D]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
+  // CHECK-DAG: ![[SELF_VAR]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
+  // CHECK-DAG: ![[D_VAR]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
   NSMutableDictionary *d = [[NSMutableDictionary alloc] init]; 
   ivar = 42 + (int)[d count];
 });
Index: test/CodeGenObjC/debug-info-block-captured-self.m
===
--- test/CodeGenObjC/debug-info-block-captured-self.m
+++ test/CodeGenObjC/debug-info-block-captured-self.m
@@ -56,16 +56,22 @@
 // CHECK-NEXT:   [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
 // CHECK:store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
 // CHECK:%[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
-// CHECK:call void @llvm.dbg.value(metadata i8* %[[TMP0]], i64 0, metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
-// CHECK:call void @llvm.dbg.declare(metadata i8* [[BLOCK_DESC]], metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
+// CHECK:call void @llvm.dbg.declare(metadata i8** %[[MEM1]],
+// CHECK-SAME:   metadata ![[BDMD:[0-9]+]],
+// CHECK-SAME:   metadata ![[EMPTY:[0-9]+]])
 // CHECK:store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
-// CHECK:call void @llvm.dbg.declare(metadata [[BLOCK_T]]** [[DBGADDR]], metadata ![[SELF:.*]], metadata !{{.*}})
+// CHECK:call void @llvm.dbg.declare(metadata 

[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-04-03 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl updated this revision to Diff 93897.
aprantl added a comment.

Add accidentally removed check for the debug info level back in.


https://reviews.llvm.org/D31440

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenObjC/debug-info-block-captured-self.m
  test/CodeGenObjC/debug-info-blocks.m

Index: test/CodeGenObjC/debug-info-blocks.m
===
--- test/CodeGenObjC/debug-info-blocks.m
+++ test/CodeGenObjC/debug-info-blocks.m
@@ -4,11 +4,18 @@
 // Test that we generate the proper debug location for a captured self.
 // The second half of this test is in llvm/tests/DebugInfo/debug-info-blocks.ll
 
-// CHECK: define {{.*}}_block_invoke
-// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
-// CHECK-NEXT: store <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %[[BLOCK]], <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA:.*]], align
-// CHECK-NEXT: call void @llvm.dbg.declare(metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}})
-// CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}})
+// CHECK: define {{.*}}[A init]_block_invoke
+// CHECK-NEXT: entry
+// CHECK-NEXT: %[[DESC_ALLOCA:.*]] = alloca i8*, align 8
+// CHECK-NEXT: %[[BLOCK_ALLOCA:.*]] = alloca <{{.*}}>*, align 8
+// CHECK: store i8* %.block_descriptor, i8** %[[ALLOCA:.*]], align 8
+// CHECK: call void @llvm.dbg.declare(metadata i8** %[[DESC_ALLOCA]],
+// CHECK-SAME:metadata ![[BLOCK_VAR:[0-9]+]],
+// CHECK: call void @llvm.dbg.declare(
+// CHECK-SAME: metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>**
+// CHECK-SAME:  %[[BLOCK_ALLOCA]], metadata ![[SELF_VAR:[0-9]+]],
+// CHECK-SAME:  metadata ![[SELF_EXPR:[0-9]+]])
+// CHECK: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D_VAR:[0-9]+]],
 
 // rdar://problem/14386148
 // Test that we don't emit bogus line numbers for the helper functions.
@@ -22,11 +29,13 @@
 // CHECK-NOT: ret
 // CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]]
 
-// CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
-// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
-// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
+// CHECK-DAG: ![[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
+// CHECK-DAG: ![[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
+// CHECK-DAG: ![[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
+// CHECK-DAG: ![[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
+// CHECK-DAG: ![[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
+// CHECK-DAG: ![[BLOCK_VAR]] = !DILocalVariable(name: ".block_descriptor"
+// CHECK-DAG: ![[SELF_EXPR]] = !DIExpression(DW_OP_plus, 32, DW_OP_deref)
 typedef unsigned int NSUInteger;
 
 @protocol NSObject
@@ -61,8 +70,8 @@
 {
 if ((self = [super init])) {
   run(^{
-  // CHECK-DAG: ![[SELF]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
-  // CHECK-DAG: ![[D]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
+  // CHECK-DAG: ![[SELF_VAR]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
+  // CHECK-DAG: ![[D_VAR]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
   NSMutableDictionary *d = [[NSMutableDictionary alloc] init]; 
   ivar = 42 + (int)[d count];
 });
Index: test/CodeGenObjC/debug-info-block-captured-self.m
===
--- test/CodeGenObjC/debug-info-block-captured-self.m
+++ test/CodeGenObjC/debug-info-block-captured-self.m
@@ -56,16 +56,22 @@
 // CHECK-NEXT:   [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
 // CHECK:store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
 // CHECK:%[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
-// CHECK:call void @llvm.dbg.value(metadata i8* %[[TMP0]], i64 0, metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
-// CHECK:call void @llvm.dbg.declare(metadata i8* [[BLOCK_DESC]], metadata ![[BDMD:[0-9]+]], metadata !{{.*}})
+// CHECK:call void @llvm.dbg.declare(metadata i8** %[[MEM1]],
+// CHECK-SAME:   metadata ![[BDMD:[0-9]+]],
+// CHECK-SAME:   metadata ![[EMPTY:[0-9]+]])
 // CHECK:store [[BLOCK_T]]* {{%.*}}, [[BLOCK_T]]** [[DBGADDR]], align 8
-// CHECK:call void @llvm.dbg.declare(metadata [[BLOCK_T]]** [[DBGADDR]], 

[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-03-29 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added a comment.

In https://reviews.llvm.org/D31440#713308, @dblaikie wrote:

> I'm a bit confused - the alloca was only emitted at -O0, by the looks of it. 
> Presumably it's pessimizing in some way at higher optimization levels? Or is 
> that not the case?


I think it is really working around the odd behavior of LLVM here. What gives 
it away is the we key the addition of the extra DW_OP_deref on whether it is an 
alloca or not. But note that this is not how dbg.declare works: 
dbg.declare(%alloca, !DIExpression()) is (kind of) equivalent to 
dbg.value(%alloca, !DIExpression(DW_OP_deref)). So we are using the presence of 
the alloca as a proxy for how the backend happens to compile the 
DwarfExpression here and work around its idiosyncrasy by emitting an extra 
DW_OP_deref.

> Also, it looks like this change lost the "if > gmlt" test, so might cause 
> variable declarations (& thus types) to leak into GMLT, which is undesirable.

Oh.. that was unintentional collateral damage. Thanks for noticing!


https://reviews.llvm.org/D31440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-03-29 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

I'm a bit confused - the alloca was only emitted at -O0, by the looks of it. 
Presumably it's pessimizing in some way at higher optimization levels? Or is 
that not the case?

Also, it looks like this change lost the "if > gmlt" test, so might cause 
variable declarations (& thus types) to leak into GMLT, which is undesirable.


https://reviews.llvm.org/D31440



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D31440: PR32382: Adapt to LLVM changes in DIExpression.

2017-03-28 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl created this revision.

LLVM now interprets DIExpressions correctly and no longer determines the 
location description kind by looking at whether the first operator is a 
DW_OP_deref.

  

The code that emitted debug info for block captures used to rely on this and 
used the presence of an alloca (which was only emitted when optimizations were 
enabled) as a proxy for tweaking the expression in a way the resulted in the 
backend doing the right thing. This is now unnecessary and this patch 
unconditionally emits an alloca for block descriptors, which is then elided by 
mem2reg.

  

https://bugs.llvm.org/show_bug.cgi?id=32382
rdar://problem/31205000


https://reviews.llvm.org/D31440

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGenObjC/debug-info-block-captured-self.m
  test/CodeGenObjC/debug-info-blocks.m

Index: test/CodeGenObjC/debug-info-blocks.m
===
--- test/CodeGenObjC/debug-info-blocks.m
+++ test/CodeGenObjC/debug-info-blocks.m
@@ -4,11 +4,18 @@
 // Test that we generate the proper debug location for a captured self.
 // The second half of this test is in llvm/tests/DebugInfo/debug-info-blocks.ll
 
-// CHECK: define {{.*}}_block_invoke
-// CHECK: %[[BLOCK:.*]] = bitcast i8* %.block_descriptor to <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>*, !dbg
-// CHECK-NEXT: store <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>* %[[BLOCK]], <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA:.*]], align
-// CHECK-NEXT: call void @llvm.dbg.declare(metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>** %[[ALLOCA]], metadata ![[SELF:[0-9]+]], metadata !{{.*}})
-// CHECK-NEXT: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D:[0-9]+]], metadata !{{.*}})
+// CHECK: define {{.*}}[A init]_block_invoke
+// CHECK-NEXT: entry
+// CHECK-NEXT: %[[DESC_ALLOCA:.*]] = alloca i8*, align 8
+// CHECK-NEXT: %[[BLOCK_ALLOCA:.*]] = alloca <{{.*}}>*, align 8
+// CHECK: store i8* %.block_descriptor, i8** %[[ALLOCA:.*]], align 8
+// CHECK: call void @llvm.dbg.declare(metadata i8** %[[DESC_ALLOCA]],
+// CHECK-SAME:metadata ![[BLOCK_VAR:[0-9]+]],
+// CHECK: call void @llvm.dbg.declare(
+// CHECK-SAME: metadata <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, %0* }>**
+// CHECK-SAME:  %[[BLOCK_ALLOCA]], metadata ![[SELF_VAR:[0-9]+]],
+// CHECK-SAME:  metadata ![[SELF_EXPR:[0-9]+]])
+// CHECK: call void @llvm.dbg.declare(metadata %1** %d, metadata ![[D_VAR:[0-9]+]],
 
 // rdar://problem/14386148
 // Test that we don't emit bogus line numbers for the helper functions.
@@ -22,11 +29,13 @@
 // CHECK-NOT: ret
 // CHECK: load {{.*}}, !dbg ![[DESTROY_LINE:[0-9]+]]
 
-// CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
-// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
-// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
+// CHECK-DAG: ![[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
+// CHECK-DAG: ![[COPY_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
+// CHECK-DAG: ![[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_"
+// CHECK-DAG: ![[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
+// CHECK-DAG: ![[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_"
+// CHECK-DAG: ![[BLOCK_VAR]] = !DILocalVariable(name: ".block_descriptor"
+// CHECK-DAG: ![[SELF_EXPR]] = !DIExpression(DW_OP_plus, 32, DW_OP_deref)
 typedef unsigned int NSUInteger;
 
 @protocol NSObject
@@ -61,8 +70,8 @@
 {
 if ((self = [super init])) {
   run(^{
-  // CHECK-DAG: ![[SELF]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
-  // CHECK-DAG: ![[D]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
+  // CHECK-DAG: ![[SELF_VAR]] = !DILocalVariable(name: "self", scope:{{.*}}, line: [[@LINE+4]],
+  // CHECK-DAG: ![[D_VAR]] = !DILocalVariable(name: "d", scope:{{.*}}, line: [[@LINE+1]],
   NSMutableDictionary *d = [[NSMutableDictionary alloc] init]; 
   ivar = 42 + (int)[d count];
 });
Index: test/CodeGenObjC/debug-info-block-captured-self.m
===
--- test/CodeGenObjC/debug-info-block-captured-self.m
+++ test/CodeGenObjC/debug-info-block-captured-self.m
@@ -56,16 +56,22 @@
 // CHECK-NEXT:   [[DBGADDR:%.*]] = alloca [[BLOCK_T:<{.*}>]]*, align 8
 // CHECK:store i8* [[BLOCK_DESC:%.*]], i8** %[[MEM1]], align 8
 // CHECK:%[[TMP0:.*]] = load i8*, i8** %[[MEM1]]
-// CHECK:call void @llvm.dbg.value(metadata i8* %[[TMP0]], i64 0, metadata