From 1049085c788ac6628200fe3758b6f280ddbc6e2a Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 21 Sep 2016 15:55:53 +0000 Subject: [PATCH] Revert r281895 "Add @llvm.dbg.value entries for the phi node created by -mem2reg" (And follow-up r281964.) It caused PR30468. llvm-svn: 282077 --- llvm/include/llvm/Transforms/Utils/Local.h | 15 +---- llvm/lib/Transforms/Utils/Local.cpp | 52 ++------------- .../Transforms/Utils/PromoteMemoryToRegister.cpp | 2 - llvm/test/Transforms/Util/mem2reg-dbg.ll | 76 ---------------------- 4 files changed, 7 insertions(+), 138 deletions(-) delete mode 100644 llvm/test/Transforms/Util/mem2reg-dbg.ll diff --git a/llvm/include/llvm/Transforms/Utils/Local.h b/llvm/include/llvm/Transforms/Utils/Local.h index e418544..9267b10 100644 --- a/llvm/include/llvm/Transforms/Utils/Local.h +++ b/llvm/include/llvm/Transforms/Utils/Local.h @@ -32,7 +32,6 @@ class BranchInst; class Instruction; class CallInst; class DbgDeclareInst; -class DbgValueInst; class StoreInst; class LoadInst; class Value; @@ -49,8 +48,6 @@ class LazyValueInfo; template class SmallVectorImpl; -typedef SmallVector DbgValueList; - //===----------------------------------------------------------------------===// // Local constant propagation. // @@ -258,19 +255,14 @@ Value *EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value /// that has an associated llvm.dbg.decl intrinsic. -void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, +bool ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, StoreInst *SI, DIBuilder &Builder); /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value /// that has an associated llvm.dbg.decl intrinsic. -void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, +bool ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, LoadInst *LI, DIBuilder &Builder); -/// Inserts a llvm.dbg.value intrinsic after a phi of an alloca'd value -/// that has an associated llvm.dbg.decl intrinsic. -void ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, - PHINode *LI, DIBuilder &Builder); - /// Lowers llvm.dbg.declare intrinsics into appropriate set of /// llvm.dbg.value intrinsics. bool LowerDbgDeclare(Function &F); @@ -278,9 +270,6 @@ bool LowerDbgDeclare(Function &F); /// Finds the llvm.dbg.declare intrinsic corresponding to an alloca, if any. DbgDeclareInst *FindAllocaDbgDeclare(Value *V); -/// Finds the llvm.dbg.value intrinsics corresponding to an alloca, if any. -void FindAllocaDbgValues(DbgValueList &DbgValues, Value *V); - /// Replaces llvm.dbg.declare instruction when the address it describes /// is replaced with a new value. If Deref is true, an additional DW_OP_deref is /// prepended to the expression. If Offset is non-zero, a constant displacement diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 5a79071..c1ef655 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1053,27 +1053,9 @@ static bool LdStHasDebugValue(DILocalVariable *DIVar, DIExpression *DIExpr, return false; } -/// See if there is a dbg.value intrinsic for DIVar for the PHI node. -static bool PhiHasDebugValue(DILocalVariable *DIVar, - DIExpression *DIExpr, - PHINode *APN) { - // Since we can't guarantee that the original dbg.declare instrinsic - // is removed by LowerDbgDeclare(), we need to make sure that we are - // not inserting the same dbg.value intrinsic over and over. - DbgValueList DbgValues; - FindAllocaDbgValues(DbgValues, APN); - for (auto DVI : DbgValues) { - assert (DVI->getValue() == APN); - assert (DVI->getOffset() == 0); - if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr)) - return true; - } - return false; -} - /// Inserts a llvm.dbg.value intrinsic before a store to an alloca'd value /// that has an associated llvm.dbg.decl intrinsic. -void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, +bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, StoreInst *SI, DIBuilder &Builder) { auto *DIVar = DDI->getVariable(); auto *DIExpr = DDI->getExpression(); @@ -1114,18 +1096,19 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, } else if (!LdStHasDebugValue(DIVar, DIExpr, SI)) Builder.insertDbgValueIntrinsic(SI->getOperand(0), 0, DIVar, DIExpr, DDI->getDebugLoc(), SI); + return true; } /// Inserts a llvm.dbg.value intrinsic before a load of an alloca'd value /// that has an associated llvm.dbg.decl intrinsic. -void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, +bool llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, LoadInst *LI, DIBuilder &Builder) { auto *DIVar = DDI->getVariable(); auto *DIExpr = DDI->getExpression(); assert(DIVar && "Missing variable"); if (LdStHasDebugValue(DIVar, DIExpr, LI)) - return; + return true; // We are now tracking the loaded value instead of the address. In the // future if multi-location support is added to the IR, it might be @@ -1134,22 +1117,7 @@ void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, Instruction *DbgValue = Builder.insertDbgValueIntrinsic( LI, 0, DIVar, DIExpr, DDI->getDebugLoc(), (Instruction *)nullptr); DbgValue->insertAfter(LI); -} - -/// Inserts a llvm.dbg.value intrinsic after a phi -/// that has an associated llvm.dbg.decl intrinsic. -void llvm::ConvertDebugDeclareToDebugValue(DbgDeclareInst *DDI, - PHINode *APN, DIBuilder &Builder) { - auto *DIVar = DDI->getVariable(); - auto *DIExpr = DDI->getExpression(); - assert(DIVar && "Missing variable"); - - if (PhiHasDebugValue(DIVar, DIExpr, APN)) - return; - - Instruction *DbgValue = Builder.insertDbgValueIntrinsic( - APN, 0, DIVar, DIExpr, DDI->getDebugLoc(), (Instruction *)nullptr); - DbgValue->insertBefore(&*APN->getParent()->getFirstInsertionPt()); + return true; } /// Determine whether this alloca is either a VLA or an array. @@ -1219,16 +1187,6 @@ DbgDeclareInst *llvm::FindAllocaDbgDeclare(Value *V) { return nullptr; } -/// FindAllocaDbgValues - Finds the llvm.dbg.value intrinsics describing the -/// alloca 'V', if any. -void llvm::FindAllocaDbgValues(DbgValueList &DbgValues, Value *V) { - if (auto *L = LocalAsMetadata::getIfExists(V)) - if (auto *MDV = MetadataAsValue::getIfExists(V->getContext(), L)) - for (User *U : MDV->users()) - if (DbgValueInst *DVI = dyn_cast(U)) - DbgValues.push_back(DVI); -} - static void DIExprAddDeref(SmallVectorImpl &Expr) { Expr.push_back(dwarf::DW_OP_deref); } diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 35faa6f..cbf385d 100644 --- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -907,8 +907,6 @@ NextIteration: // The currently active variable for this block is now the PHI. IncomingVals[AllocaNo] = APN; - if (DbgDeclareInst *DDI = AllocaDbgDeclares[AllocaNo]) - ConvertDebugDeclareToDebugValue(DDI, APN, DIB); // Get the next phi node. ++PNI; diff --git a/llvm/test/Transforms/Util/mem2reg-dbg.ll b/llvm/test/Transforms/Util/mem2reg-dbg.ll deleted file mode 100644 index 8eca6e8..0000000 --- a/llvm/test/Transforms/Util/mem2reg-dbg.ll +++ /dev/null @@ -1,76 +0,0 @@ -; RUN: opt -mem2reg -S < %s | FileCheck %s - -; Test that a @llvm.dbg.value node is created to describe the value returned by a phi node when -; lowering a @llvm.dbg.declare node - -; Created from the C code, compiled with -O0 -g: -; -; int func(int a) -; { -; int c = 1; -; if (a < 0 ) { -; c = 12; -; } -; return c; -; } - -; Function Attrs: nounwind -define i32 @func(i32 %a) #0 !dbg !8 { -entry: - %a.addr = alloca i32, align 4 - %c = alloca i32, align 4 - store i32 %a, i32* %a.addr, align 4 - call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !12, metadata !13), !dbg !14 - call void @llvm.dbg.declare(metadata i32* %c, metadata !15, metadata !13), !dbg !16 - store i32 1, i32* %c, align 4, !dbg !16 - %0 = load i32, i32* %a.addr, align 4, !dbg !17 - %cmp = icmp slt i32 %0, 0, !dbg !19 - br i1 %cmp, label %if.then, label %if.end, !dbg !20 - -if.then: ; preds = %entry - store i32 12, i32* %c, align 4, !dbg !21 - br label %if.end, !dbg !23 - -if.end: ; preds = %if.then, %entry - %1 = load i32, i32* %c, align 4, !dbg !24 -; CHECK: [[PHI:%.*]] = phi i32 [ 12, {{.*}} ], [ 1, {{.*}} ] -; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 [[PHI]], i64 0, metadata !15, metadata !13), !dbg !16 - ret i32 %1, !dbg !25 -} - -; Function Attrs: nounwind readnone -declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 - -attributes #1 = { nounwind readnone } - -!llvm.dbg.cu = !{!0} -!llvm.module.flags = !{!3, !4, !5, !6} -!llvm.ident = !{!7} - -!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) -!1 = !DIFile(filename: "a.c", directory: "/tmp") -!2 = !{} -!3 = !{i32 2, !"Dwarf Version", i32 4} -!4 = !{i32 2, !"Debug Info Version", i32 3} -!5 = !{i32 1, !"wchar_size", i32 4} -!6 = !{i32 1, !"min_enum_size", i32 4} -!7 = !{!"clang"} -!8 = distinct !DISubprogram(name: "func", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) -!9 = !DISubroutineType(types: !10) -!10 = !{!11, !11} -!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) -!12 = !DILocalVariable(name: "a", arg: 1, scope: !8, file: !1, line: 1, type: !11) -!13 = !DIExpression() -!14 = !DILocation(line: 1, column: 14, scope: !8) -!15 = !DILocalVariable(name: "c", scope: !8, file: !1, line: 3, type: !11) -!16 = !DILocation(line: 3, column: 6, scope: !8) -!17 = !DILocation(line: 4, column: 6, scope: !18) -!18 = distinct !DILexicalBlock(scope: !8, file: !1, line: 4, column: 6) -!19 = !DILocation(line: 4, column: 8, scope: !18) -!20 = !DILocation(line: 4, column: 6, scope: !8) -!21 = !DILocation(line: 5, column: 5, scope: !22) -!22 = distinct !DILexicalBlock(scope: !18, file: !1, line: 4, column: 14) -!23 = !DILocation(line: 6, column: 2, scope: !22) -!24 = !DILocation(line: 7, column: 9, scope: !8) -!25 = !DILocation(line: 7, column: 2, scope: !8) - -- 2.7.4