Revert "DebugInfo: Include lexical scopes in inlined subroutines."
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 12 May 2014 23:53:03 +0000 (23:53 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 12 May 2014 23:53:03 +0000 (23:53 +0000)
This reverts commit r208506.

Some inlined subroutine scopes appear to be missing with this change.
Reverting while I investigate.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@208642 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/STLExtras.h
include/llvm/CodeGen/LexicalScopes.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/LexicalScopes.cpp
test/DebugInfo/inline-scopes.ll [deleted file]

index 5b7b88b90085270c74e1c9a455175a3b3d024d7a..807ec59061d2c55679d195231fc52ef9bfa8573a 100644 (file)
@@ -530,13 +530,6 @@ make_unique(size_t n) {
 
 #endif
 
-template<typename First, typename Second>
-struct pair_hash {
-  size_t operator()(const std::pair<First, Second> &P) const {
-    return std::hash<First>()(P.first) * 31 + std::hash<Second>()(P.second);
-  }
-};
-
 } // End llvm namespace
 
 #endif
index 31d687267416ceaa8711705350633fdbf4511f06..31d40ff588cc7c1d4a69674016e18d2027c5e65f 100644 (file)
@@ -21,7 +21,6 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/IR/DebugLoc.h"
 #include "llvm/IR/Metadata.h"
 #include "llvm/IR/ValueHandle.h"
@@ -186,7 +185,9 @@ public:
 
   /// findInlinedScope - Find an inlined scope for the given DebugLoc or return
   /// NULL.
-  LexicalScope *findInlinedScope(DebugLoc DL);
+  LexicalScope *findInlinedScope(DebugLoc DL) {
+    return InlinedLexicalScopeMap.lookup(DL);
+  }
 
   /// findLexicalScope - Find regular lexical scope or return null.
   LexicalScope *findLexicalScope(const MDNode *N) {
@@ -229,9 +230,7 @@ private:
 
   /// InlinedLexicalScopeMap - Tracks inlined function scopes in current
   /// function.
-  std::unordered_map<std::pair<const MDNode *, const MDNode *>, LexicalScope,
-                     pair_hash<const MDNode *, const MDNode *>>
-  InlinedLexicalScopeMap;
+  DenseMap<DebugLoc, LexicalScope *> InlinedLexicalScopeMap;
 
   /// AbstractScopeMap - These scopes are  not included LexicalScopeMap.
   // Use an unordered_map to ensure value pointer validity over insertion.
index bbd00eab7f763945a35115bb73110150098a58ec..ed8360f205423bd14eb5297c7791489d5d5b96ea 100644 (file)
@@ -623,7 +623,7 @@ std::unique_ptr<DIE> DwarfDebug::constructScopeDIE(DwarfCompileUnit &TheCU,
   // avoid creating un-used children then removing them later when we find out
   // the scope DIE is null.
   std::unique_ptr<DIE> ScopeDIE;
-  if (DS.getContext() && DS.isSubprogram()) {
+  if (Scope->getInlinedAt()) {
     ScopeDIE = constructInlinedScopeDIE(TheCU, Scope);
     if (!ScopeDIE)
       return nullptr;
@@ -1210,12 +1210,10 @@ DwarfDebug::collectVariableInfo(SmallPtrSet<const MDNode *, 16> &Processed) {
     if (DV.getTag() == dwarf::DW_TAG_arg_variable &&
         DISubprogram(DV.getContext()).describes(CurFn->getFunction()))
       Scope = LScopes.getCurrentFunctionScope();
-    else if (MDNode *IA = DV.getInlinedAt()) {
-      DebugLoc DL = DebugLoc::getFromDILocation(IA);
-      Scope = LScopes.findInlinedScope(DebugLoc::get(
-          DL.getLine(), DL.getCol(), DV.getContext(), IA));
-    } else
-      Scope = LScopes.findLexicalScope(DV.getContext());
+    else if (MDNode *IA = DV.getInlinedAt())
+      Scope = LScopes.findInlinedScope(DebugLoc::getFromDILocation(IA));
+    else
+      Scope = LScopes.findLexicalScope(cast<MDNode>(DV->getOperand(1)));
     // If variable scope is not found then skip this variable.
     if (!Scope)
       continue;
index 8bf69ff630800801ea8e132a52470531036b332b..46f864ca55d2abba549935ab9f80262a01b4d670 100644 (file)
@@ -104,14 +104,6 @@ void LexicalScopes::extractLexicalScopes(
   }
 }
 
-LexicalScope *LexicalScopes::findInlinedScope(DebugLoc DL) {
-  MDNode *Scope = nullptr;
-  MDNode *IA = nullptr;
-  DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext());
-  auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));
-  return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;
-}
-
 /// findLexicalScope - Find lexical scope, either regular or inlined, for the
 /// given DebugLoc. Return NULL if not found.
 LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) {
@@ -127,10 +119,8 @@ LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) {
   if (D.isLexicalBlockFile())
     Scope = DILexicalBlockFile(Scope).getScope();
 
-  if (IA) {
-    auto I = InlinedLexicalScopeMap.find(std::make_pair(Scope, IA));
-    return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;
-  }
+  if (IA)
+    return InlinedLexicalScopeMap.lookup(DebugLoc::getFromDILocation(IA));
   return findLexicalScope(Scope);
 }
 
@@ -180,27 +170,21 @@ LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) {
 }
 
 /// getOrCreateInlinedScope - Find or create an inlined lexical scope.
-LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *ScopeNode,
+LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *Scope,
                                                      MDNode *InlinedAt) {
-  std::pair<const MDNode*, const MDNode*> P(ScopeNode, InlinedAt);
-  auto I = InlinedLexicalScopeMap.find(P);
-  if (I != InlinedLexicalScopeMap.end())
+  auto I = LexicalScopeMap.find(InlinedAt);
+  if (I != LexicalScopeMap.end())
     return &I->second;
 
-  LexicalScope *Parent;
-  DILexicalBlock Scope(ScopeNode);
-  if (Scope.isLexicalBlock()) {
-    DILexicalBlock PB(Scope.getContext());
-    Parent = getOrCreateInlinedScope(PB, InlinedAt);
-  } else
-    Parent = getOrCreateLexicalScope(DebugLoc::getFromDILocation(InlinedAt));
-
+  DebugLoc InlinedLoc = DebugLoc::getFromDILocation(InlinedAt);
   // FIXME: Use forward_as_tuple instead of make_tuple, once MSVC2012
   // compatibility is no longer required.
-  I = InlinedLexicalScopeMap.emplace(std::piecewise_construct,
-                                     std::make_tuple(P),
-                                     std::make_tuple(Parent, Scope, InlinedAt,
-                                                     false)).first;
+  I = LexicalScopeMap.emplace(
+                          std::piecewise_construct, std::make_tuple(InlinedAt),
+                          std::make_tuple(getOrCreateLexicalScope(InlinedLoc),
+                                          DIDescriptor(Scope), InlinedAt,
+                                          false)).first;
+  InlinedLexicalScopeMap[InlinedLoc] = &I->second;
   return &I->second;
 }
 
diff --git a/test/DebugInfo/inline-scopes.ll b/test/DebugInfo/inline-scopes.ll
deleted file mode 100644 (file)
index 4e18db4..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-; REQUIRES: object-emission
-
-; RUN: %llc_dwarf -O0 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
-
-; bool f1();
-; inline __attribute__((always_inline))
-; int f() {
-;   if (bool b = f1())
-;     return 1;
-;   return 2;
-; }
-; 
-; int main() {
-;   f();
-; }
-
-; Ensure that lexical_blocks within inlined_subroutines are preserved/emitted.
-; CHECK: DW_TAG_inlined_subroutine
-; CHECK-NOT: DW_TAG
-; CHECK: DW_TAG_lexical_block
-; CHECK: DW_TAG_variable
-
-; Function Attrs: uwtable
-define i32 @main() #0 {
-entry:
-  %retval.i = alloca i32, align 4
-  %b.i = alloca i8, align 1
-  call void @llvm.dbg.declare(metadata !{i8* %b.i}, metadata !13), !dbg !16
-  %call.i = call zeroext i1 @_Z2f1v(), !dbg !16
-  %frombool.i = zext i1 %call.i to i8, !dbg !16
-  store i8 %frombool.i, i8* %b.i, align 1, !dbg !16
-  %0 = load i8* %b.i, align 1, !dbg !16
-  %tobool.i = trunc i8 %0 to i1, !dbg !16
-  br i1 %tobool.i, label %if.then.i, label %if.end.i, !dbg !16
-
-if.then.i:                                        ; preds = %entry
-  store i32 1, i32* %retval.i, !dbg !18
-  br label %_Z1fv.exit, !dbg !18
-
-if.end.i:                                         ; preds = %entry
-  store i32 2, i32* %retval.i, !dbg !19
-  br label %_Z1fv.exit, !dbg !19
-
-_Z1fv.exit:                                       ; preds = %if.then.i, %if.end.i
-  %1 = load i32* %retval.i, !dbg !20
-  ret i32 0, !dbg !21
-}
-
-; Function Attrs: nounwind readnone
-declare void @llvm.dbg.declare(metadata, metadata) #1
-
-declare zeroext i1 @_Z2f1v() #2
-
-attributes #0 = { uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-attributes #1 = { nounwind readnone }
-attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
-
-!llvm.dbg.cu = !{!0}
-!llvm.module.flags = !{!10, !11}
-!llvm.ident = !{!12}
-
-!0 = metadata !{i32 786449, metadata !1, i32 4, metadata !"clang version 3.5.0 ", i1 false, metadata !"", i32 0, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2, metadata !"", i32 1} ; [ DW_TAG_compile_unit ] [/tmp/dbginfo/inline-scopes.cpp] [DW_LANG_C_plus_plus]
-!1 = metadata !{metadata !"inline-scopes.cpp", metadata !"/tmp/dbginfo"}
-!2 = metadata !{}
-!3 = metadata !{metadata !4, metadata !9}
-!4 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"main", metadata !"main", metadata !"", i32 9, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, i32 ()* @main, null, null, metadata !2, i32 9} ; [ DW_TAG_subprogram ] [line 9] [def] [main]
-!5 = metadata !{i32 786473, metadata !1}          ; [ DW_TAG_file_type ] [/tmp/dbginfo/inline-scopes.cpp]
-!6 = metadata !{i32 786453, i32 0, null, metadata !"", i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !7, i32 0, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
-!7 = metadata !{metadata !8}
-!8 = metadata !{i32 786468, null, null, metadata !"int", i32 0, i64 32, i64 32, i64 0, i32 0, i32 5} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
-!9 = metadata !{i32 786478, metadata !1, metadata !5, metadata !"f", metadata !"f", metadata !"_Z1fv", i32 3, metadata !6, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 false, null, null, null, metadata !2, i32 3} ; [ DW_TAG_subprogram ] [line 3] [def] [f]
-!10 = metadata !{i32 2, metadata !"Dwarf Version", i32 4}
-!11 = metadata !{i32 1, metadata !"Debug Info Version", i32 1}
-!12 = metadata !{metadata !"clang version 3.5.0 "}
-!13 = metadata !{i32 786688, metadata !14, metadata !"b", metadata !5, i32 4, metadata !15, i32 0, i32 0} ; [ DW_TAG_auto_variable ] [b] [line 4]
-!14 = metadata !{i32 786443, metadata !1, metadata !9, i32 4, i32 0, i32 0, i32 0} ; [ DW_TAG_lexical_block ] [/tmp/dbginfo/inline-scopes.cpp]
-!15 = metadata !{i32 786468, null, null, metadata !"bool", i32 0, i64 8, i64 8, i64 0, i32 0, i32 2} ; [ DW_TAG_base_type ] [bool] [line 0, size 8, align 8, offset 0, enc DW_ATE_boolean]
-!16 = metadata !{i32 4, i32 0, metadata !14, metadata !17}
-!17 = metadata !{i32 10, i32 0, metadata !4, null}
-!18 = metadata !{i32 5, i32 0, metadata !14, metadata !17}
-!19 = metadata !{i32 6, i32 0, metadata !9, metadata !17}
-!20 = metadata !{i32 7, i32 0, metadata !9, metadata !17}
-!21 = metadata !{i32 11, i32 0, metadata !4, null}