llvm.org GIT mirror llvm / 6618a24
Add a new wrapper node for a DILexicalBlock that encapsulates it and a file. Since it should only be used when necessary propagate it through the backend code generation and tweak testcases accordingly. This helps with code like in clang's test/CodeGen/debug-info-line.c where we have multiple #line directives within a single lexical block and want to generate only a single block that contains each file change. Part of rdar://10246360 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141729 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 8 years ago
10 changed file(s) with 115 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
471471
472472
473473
474

These descriptors provide debug information about nested blocks within a

474

This descriptor provides debug information about nested blocks within a

475475 subprogram. The line number and column numbers are used to dinstinguish
476476 two lexical blocks at same depth.

477
478
479

                  
                
480 !3 = metadata !{
481 i32, ;; Tag = 11 + LLVMDebugVersion (DW_TAG_lexical_block)
482 metadata ;; Reference to the scope we're annotating with a file change
483 metadata,;; Reference to the file the scope is enclosed in.
484 }
485
486
487
488

This descriptor provides a wrapper around a lexical scope to handle file

489 changes in the middle of a lexical block.

477490
478491
479492
3636 class DINameSpace;
3737 class DIVariable;
3838 class DISubrange;
39 class DILexicalBlockFile;
3940 class DILexicalBlock;
4041 class DISubprogram;
4142 class DITemplateTypeParameter;
462463 DIFile File, unsigned LineNo);
463464
464465
466 /// createLexicalBlockFile - This creates a descriptor for a lexical
467 /// block with a new file attached. This merely extends the existing
468 /// lexical block as it crosses a file.
469 /// @param Scope Lexical block.
470 /// @param File Source file.
471 DILexicalBlockFile createLexicalBlockFile(DIDescriptor Scope,
472 DIFile File);
473
465474 /// createLexicalBlock - This creates a descriptor for a lexical block
466475 /// with the specified parent context.
467476 /// @param Scope Parent lexical scope.
3939 class DIFile;
4040 class DISubprogram;
4141 class DILexicalBlock;
42 class DILexicalBlockFile;
4243 class DIVariable;
4344 class DIType;
4445
8384 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
8485 explicit DIDescriptor(const DIFile F);
8586 explicit DIDescriptor(const DISubprogram F);
87 explicit DIDescriptor(const DILexicalBlockFile F);
8688 explicit DIDescriptor(const DILexicalBlock F);
8789 explicit DIDescriptor(const DIVariable F);
8890 explicit DIDescriptor(const DIType F);
116118 bool isFile() const;
117119 bool isCompileUnit() const;
118120 bool isNameSpace() const;
121 bool isLexicalBlockFile() const;
119122 bool isLexicalBlock() const;
120123 bool isSubrange() const;
121124 bool isEnumerator() const;
698701 }
699702 };
700703
704 /// DILexicalBlockFile - This is a wrapper for a lexical block with
705 /// a filename change.
706 class DILexicalBlockFile : public DIScope {
707 public:
708 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
709 DIScope getContext() const { return getScope().getFieldAs(1); }
710 unsigned getLineNumber() const { return getScope().getUnsignedField(2); }
711 unsigned getColumnNumber() const { return getScope().getUnsignedField(3); }
712 StringRef getDirectory() const {
713 StringRef dir = getFieldAs(2).getDirectory();
714 return !dir.empty() ? dir : getContext().getDirectory();
715 }
716 StringRef getFilename() const {
717 StringRef filename = getFieldAs(2).getFilename();
718 assert(!filename.empty() && "Why'd you create this then?");
719 return filename;
720 }
721 DILexicalBlock getScope() const { return getFieldAs(1); }
722 };
723
701724 /// DINameSpace - A wrapper for a C++ style name space.
702725 class DINameSpace : public DIScope {
703726 public:
850850 return DINameSpace(MDNode::get(VMContext, Elts));
851851 }
852852
853 /// createLexicalBlockFile - This creates a new MDNode that encapsulates
854 /// an existing scope with a new filename.
855 DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
856 DIFile File) {
857 Value *Elts[] = {
858 GetTagConstant(VMContext, dwarf::DW_TAG_lexical_block),
859 Scope,
860 File
861 };
862 return DILexicalBlockFile(MDNode::get(VMContext, Elts));
863 }
864
853865 DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
854866 unsigned Line, unsigned Col) {
855867 // Defeat MDNode uniqing for lexical blocks by using unique id.
3636 }
3737
3838 DIDescriptor::DIDescriptor(const DISubprogram F) : DbgNode(F.DbgNode) {
39 }
40
41 DIDescriptor::DIDescriptor(const DILexicalBlockFile F) : DbgNode(F.DbgNode) {
3942 }
4043
4144 DIDescriptor::DIDescriptor(const DILexicalBlock F) : DbgNode(F.DbgNode) {
262265 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
263266 }
264267
268 /// isLexicalBlockFile - Return true if the specified descriptor is a
269 /// lexical block with an extra file.
270 bool DIDescriptor::isLexicalBlockFile() const {
271 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
272 (DbgNode->getNumOperands() == 3);
273 }
274
265275 /// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
266276 bool DIDescriptor::isLexicalBlock() const {
267 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block;
277 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
278 (DbgNode->getNumOperands() > 3);
268279 }
269280
270281 /// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
539550 StringRef DIScope::getFilename() const {
540551 if (!DbgNode)
541552 return StringRef();
553 if (isLexicalBlockFile())
554 return DILexicalBlockFile(DbgNode).getFilename();
542555 if (isLexicalBlock())
543556 return DILexicalBlock(DbgNode).getFilename();
544557 if (isSubprogram())
558571 StringRef DIScope::getDirectory() const {
559572 if (!DbgNode)
560573 return StringRef();
574 if (isLexicalBlockFile())
575 return DILexicalBlockFile(DbgNode).getDirectory();
561576 if (isLexicalBlock())
562577 return DILexicalBlock(DbgNode).getDirectory();
563578 if (isSubprogram())
933948 addCompileUnit(DICompileUnit(Scope));
934949 else if (Scope.isSubprogram())
935950 processSubprogram(DISubprogram(Scope));
951 else if (Scope.isLexicalBlockFile()) {
952 DILexicalBlockFile DBF = DILexicalBlockFile(Scope);
953 processLexicalBlock(DILexicalBlock(DBF.getScope()));
954 }
936955 else if (Scope.isLexicalBlock())
937956 processLexicalBlock(DILexicalBlock(Scope));
938957
966985 processSubprogram(DISubprogram(S));
967986 else if (S.isLexicalBlock())
968987 processLexicalBlock(DILexicalBlock(S));
988 else if (S.isLexicalBlockFile()) {
989 DILexicalBlockFile DBF = DILexicalBlockFile(S);
990 processLexicalBlock(DILexicalBlock(DBF.getScope()));
991 }
969992 processLocation(Loc.getOrigLocation());
970993 }
971994
9971020 DIScope Context = LB.getContext();
9981021 if (Context.isLexicalBlock())
9991022 return processLexicalBlock(DILexicalBlock(Context));
1023 else if (Context.isLexicalBlockFile()) {
1024 DILexicalBlockFile DBF = DILexicalBlockFile(Context);
1025 return processLexicalBlock(DILexicalBlock(DBF.getScope()));
1026 }
10001027 else
10011028 return processSubprogram(DISubprogram(Context));
10021029 }
10801107 if (D.isSubprogram())
10811108 return DISubprogram(Scope);
10821109
1110 if (D.isLexicalBlockFile())
1111 return getDISubprogram(DILexicalBlockFile(Scope).getContext());
1112
10831113 if (D.isLexicalBlock())
10841114 return getDISubprogram(DILexicalBlock(Scope).getContext());
10851115
13701370 DISubprogram SP(S);
13711371 Fn = SP.getFilename();
13721372 Dir = SP.getDirectory();
1373 } else if (Scope.isLexicalBlockFile()) {
1374 DILexicalBlockFile DBF(S);
1375 Fn = DBF.getFilename();
1376 Dir = DBF.getDirectory();
13731377 } else if (Scope.isLexicalBlock()) {
13741378 DILexicalBlock DB(S);
13751379 Fn = DB.getFilename();
117117 MDNode *IA = NULL;
118118 DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext());
119119 if (!Scope) return NULL;
120
121 // The scope that we were created with could have an extra file - which
122 // isn't what we care about in this case.
123 DIDescriptor D = DIDescriptor(Scope);
124 if (D.isLexicalBlockFile())
125 Scope = DILexicalBlockFile(Scope).getScope();
126
120127 if (IA)
121128 return InlinedLexicalScopeMap.lookup(DebugLoc::getFromDILocation(IA));
122 return LexicalScopeMap.lookup(DL.getScope(Scope->getContext()));
129 return LexicalScopeMap.lookup(Scope);
123130 }
124131
125132 /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If
128135 MDNode *Scope = NULL;
129136 MDNode *InlinedAt = NULL;
130137 DL.getScopeAndInlinedAt(Scope, InlinedAt, MF->getFunction()->getContext());
138
131139 if (InlinedAt) {
132140 // Create an abstract scope for inlined function.
133141 getOrCreateAbstractScope(Scope);
140148
141149 /// getOrCreateRegularScope - Find or create a regular lexical scope.
142150 LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) {
151 DIDescriptor D = DIDescriptor(Scope);
152 if (D.isLexicalBlockFile())
153 Scope = DILexicalBlockFile(Scope).getScope();
154
143155 LexicalScope *WScope = LexicalScopeMap.lookup(Scope);
144156 if (WScope)
145157 return WScope;
146158
147159 LexicalScope *Parent = NULL;
148 if (DIDescriptor(Scope).isLexicalBlock())
160 if (D.isLexicalBlock())
149161 Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope));
150162 WScope = new LexicalScope(Parent, DIDescriptor(Scope), NULL, false);
151163 LexicalScopeMap.insert(std::make_pair(Scope, WScope));
175187 LexicalScope *LexicalScopes::getOrCreateAbstractScope(const MDNode *N) {
176188 assert(N && "Invalid Scope encoding!");
177189
190 DIDescriptor Scope(N);
191 if (Scope.isLexicalBlockFile())
192 Scope = DILexicalBlockFile(Scope).getScope();
178193 LexicalScope *AScope = AbstractScopeMap.lookup(N);
179194 if (AScope)
180195 return AScope;
181196
182197 LexicalScope *Parent = NULL;
183 DIDescriptor Scope(N);
184198 if (Scope.isLexicalBlock()) {
185199 DILexicalBlock DB(N);
186200 DIDescriptor ParentDesc = DB.getContext();
2222 declare i32 @foo(i32) ssp
2323
2424 !0 = metadata !{i32 5, i32 2, metadata !1, null}
25 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
25 !1 = metadata !{i32 458763, metadata !2, i32 1, i32 1}; [DW_TAG_lexical_block ]
2626 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"bar", metadata !"bar", metadata !"bar", metadata !3, i32 4, null, i1 false, i1 true}; [DW_TAG_subprogram ]
2727 !3 = metadata !{i32 458769, i32 0, i32 12, metadata !"genmodes.i", metadata !"/Users/yash/Downloads", metadata !"clang 1.1", i1 true, i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ]
2828 !4 = metadata !{i32 459008, metadata !5, metadata !"count_", metadata !3, i32 5, metadata !6}; [ DW_TAG_auto_variable ]
29 !5 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
29 !5 = metadata !{i32 458763, metadata !1, i32 1, i32 1}; [DW_TAG_lexical_block ]
3030 !6 = metadata !{i32 458788, metadata !3, metadata !"int", metadata !3, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5}; [DW_TAG_base_type ]
3131 !7 = metadata !{i32 6, i32 1, metadata !2, null}
2222 declare i32 @foo(i32) ssp
2323
2424 !0 = metadata !{i32 5, i32 2, metadata !1, null}
25 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
25 !1 = metadata !{i32 458763, metadata !2, i32 1, i32 1}; [DW_TAG_lexical_block ]
2626 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"bar", metadata !"bar", metadata !"bar", metadata !3, i32 4, null, i1 false, i1 true}; [DW_TAG_subprogram ]
2727 !3 = metadata !{i32 458769, i32 0, i32 12, metadata !"genmodes.i", metadata !"/Users/yash/Downloads", metadata !"clang 1.1", i1 true, i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ]
2828 !4 = metadata !{i32 459008, metadata !5, metadata !"count_", metadata !3, i32 5, metadata !6}; [ DW_TAG_auto_variable ]
29 !5 = metadata !{i32 458763, metadata !1}; [DW_TAG_lexical_block ]
29 !5 = metadata !{i32 458763, metadata !1, i32 1, i32 1}; [DW_TAG_lexical_block ]
3030 !6 = metadata !{i32 458788, metadata !3, metadata !"int", metadata !3, i32 0, i64 32, i64 32, i64 0, i32 0, i32 5}; [DW_TAG_base_type ]
3131 !7 = metadata !{i32 6, i32 1, metadata !2, null}
88 }
99
1010 !0 = metadata !{i32 571, i32 3, metadata !1, null}
11 !1 = metadata !{i32 458763, metadata !2}; [DW_TAG_lexical_block ]
11 !1 = metadata !{i32 458763, metadata !2, i32 1, i32 1}; [DW_TAG_lexical_block ]
1212 !2 = metadata !{i32 458798, i32 0, metadata !3, metadata !"foo", metadata !"foo", metadata !"foo", metadata !3, i32 561, metadata !4, i1 false, i1 true}; [DW_TAG_subprogram ]
1313 !3 = metadata !{i32 458769, i32 0, i32 12, metadata !"hashtab.c", metadata !"/usr/src/gnu/usr.bin/cc/cc_tools/../../../../contrib/gcclibs/libiberty", metadata !"clang 1.1", i1 true, i1 false, metadata !"", i32 0}; [DW_TAG_compile_unit ]
1414 !4 = metadata !{i32 458773, metadata !3, metadata !"", null, i32 0, i64 0, i64 0, i64 0, i32 0, null, metadata !5, i32 0}; [DW_TAG_subroutine_type ]