llvm.org GIT mirror llvm / 92078fc
[DebugInfoMetadata] Move main subprogram DIFlag into DISPFlags Moving subprogram specific flags into DISPFlags makes IR code more readable. In addition, we provide free space in DIFlags for other 'non-subprogram-specific' debug info flags. Patch by Djordje Todorovic. Differential Revision: https://reviews.llvm.org/D59288 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356454 91177308-0d34-0410-b5e6-96231b3b80d8 Petar Jovanovic 5 months ago
11 changed file(s) with 64 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
4949 HANDLE_DI_FLAG((1 << 18), IntroducedVirtual)
5050 HANDLE_DI_FLAG((1 << 19), BitField)
5151 HANDLE_DI_FLAG((1 << 20), NoReturn)
52 HANDLE_DI_FLAG((1 << 21), MainSubprogram)
5352 HANDLE_DI_FLAG((1 << 22), TypePassByValue)
5453 HANDLE_DI_FLAG((1 << 23), TypePassByReference)
5554 HANDLE_DI_FLAG((1 << 24), EnumClass)
8786 HANDLE_DISP_FLAG((1u << 5), Pure)
8887 HANDLE_DISP_FLAG((1u << 6), Elemental)
8988 HANDLE_DISP_FLAG((1u << 7), Recursive)
89 HANDLE_DISP_FLAG((1u << 8), MainSubprogram)
9090
9191 #ifdef DISP_FLAG_LARGEST_NEEDED
9292 // Intended to be used with ADT/BitmaskEnum.h.
9393 // NOTE: Always must be equal to largest flag, check this when adding new flags.
94 HANDLE_DISP_FLAG((1 << 7), Largest)
94 HANDLE_DISP_FLAG((1 << 8), Largest)
9595 #undef DISP_FLAG_LARGEST_NEEDED
9696 #endif
9797
16741674 // Helper for converting old bitfields to new flags word.
16751675 static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
16761676 bool IsOptimized,
1677 unsigned Virtuality = SPFlagNonvirtual) {
1677 unsigned Virtuality = SPFlagNonvirtual,
1678 bool IsMainSubprogram = false) {
16781679 // We're assuming virtuality is the low-order field.
16791680 static_assert(
16801681 int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
16841685 (Virtuality & SPFlagVirtuality) |
16851686 (IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
16861687 (IsDefinition ? SPFlagDefinition : SPFlagZero) |
1687 (IsOptimized ? SPFlagOptimized : SPFlagZero));
1688 (IsOptimized ? SPFlagOptimized : SPFlagZero) |
1689 (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
16881690 }
16891691
16901692 private:
17831785 bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
17841786 bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
17851787 bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
1788 bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
17861789
17871790 bool isArtificial() const { return getFlags() & FlagArtificial; }
17881791 bool isPrivate() const {
17991802 bool areAllCallsDescribed() const {
18001803 return getFlags() & FlagAllCallsDescribed;
18011804 }
1802 bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; }
18031805 bool isPure() const { return getSPFlags() & SPFlagPure; }
18041806 bool isElemental() const { return getSPFlags() & SPFlagElemental; }
18051807 bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
4949 LLVMDIFlagIntroducedVirtual = 1 << 18,
5050 LLVMDIFlagBitField = 1 << 19,
5151 LLVMDIFlagNoReturn = 1 << 20,
52 LLVMDIFlagMainSubprogram = 1 << 21,
5352 LLVMDIFlagTypePassByValue = 1 << 22,
5453 LLVMDIFlagTypePassByReference = 1 << 23,
5554 LLVMDIFlagEnumClass = 1 << 24,
14051405 return error("Invalid record");
14061406
14071407 bool HasSPFlags = Record[0] & 4;
1408 DISubprogram::DISPFlags SPFlags =
1409 HasSPFlags
1410 ? static_cast(Record[9])
1411 : DISubprogram::toSPFlags(
1412 /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
1413 /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11]);
1408
1409 DINode::DIFlags Flags;
1410 DISubprogram::DISPFlags SPFlags;
1411 if (!HasSPFlags)
1412 Flags = static_cast(Record[11 + 2]);
1413 else {
1414 Flags = static_cast(Record[11]);
1415 SPFlags = static_cast(Record[9]);
1416 }
1417
1418 // Support for old metadata when
1419 // subprogram specific flags are placed in DIFlags.
1420 const unsigned DIFlagMainSubprogram = 1 << 21;
1421 bool HasOldMainSubprogramFlag = Flags & DIFlagMainSubprogram;
1422 if (HasOldMainSubprogramFlag)
1423 // Remove old DIFlagMainSubprogram from DIFlags.
1424 // Note: This assumes that any future use of bit 21 defaults to it
1425 // being 0.
1426 Flags &= ~static_cast(DIFlagMainSubprogram);
1427
1428 if (HasOldMainSubprogramFlag && HasSPFlags)
1429 SPFlags |= DISubprogram::SPFlagMainSubprogram;
1430 else if (!HasSPFlags)
1431 SPFlags = DISubprogram::toSPFlags(
1432 /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
1433 /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11],
1434 /*DIFlagMainSubprogram*/HasOldMainSubprogramFlag);
14141435
14151436 // All definitions should be distinct.
14161437 IsDistinct = (Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition);
14541475 getDITypeRefOrNull(Record[8 + OffsetA]), // containingType
14551476 Record[10 + OffsetA], // virtualIndex
14561477 HasThisAdj ? Record[16 + OffsetB] : 0, // thisAdjustment
1457 static_cast(Record[11 + OffsetA]),// flags
1478 Flags, // flags
14581479 SPFlags, // SPFlags
14591480 HasUnit ? CUorFn : nullptr, // unit
14601481 getMDOrNull(Record[13 + OffsetB]), // templateParams
0 ; The .bc file was generated from this source using llvm-as from 8.0 release.
1 ; RUN: llvm-dis < %s.bc | FileCheck %s
2
3 define i32 @main() !dbg !5 {
4 entry:
5 %retval = alloca i32, align 4
6 store i32 0, i32* %retval
7 ret i32 0, !dbg !9
8 }
9
10 !llvm.dbg.cu = !{!0}
11 !llvm.module.flags = !{!3, !4}
12
13 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
14 !1 = !DIFile(filename: "mainsubprogram.c", directory: "/dir")
15 !2 = !{}
16 !3 = !{i32 2, !"Dwarf Version", i32 4}
17 !4 = !{i32 1, !"Debug Info Version", i32 3}
18 !5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !6, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped | DIFlagMainSubprogram, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
19 ; CHECK: !5 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !6, scopeLine: 6, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !0, retainedNodes: !2)
20 !6 = !DISubroutineType(types: !7)
21 !7 = !{!8}
22 !8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
23 !9 = !DILocation(line: 7, scope: !5)
2424 !0 = distinct !DICompileUnit(language: DW_LANG_Rust, producer: "clang version 3.4 (trunk 185475)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !15, imports: !2)
2525 !1 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
2626 !2 = !{}
27 !4 = distinct !DISubprogram(name: "main", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2)
27 !4 = distinct !DISubprogram(name: "main", line: 6, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2)
2828 !5 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
2929 !6 = !DISubroutineType(types: !7)
3030 !7 = !{!8}
5252 !2 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !3, producer: "clang LLVM (rustc version 1.24.0-dev)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
5353 !3 = !DIFile(filename: "e3.rs", directory: "/home/tromey/Rust")
5454 !4 = !{}
55 !5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, isLocal: true, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4)
55 !5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4)
5656 !6 = !DINamespace(name: "e3", scope: null)
5757 !7 = !DIFile(filename: "", directory: "")
5858 !8 = !DISubroutineType(types: !9)
2424 !0 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang version 3.4 (trunk 185475)", isOptimized: false, emissionKind: FullDebug, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
2525 !1 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
2626 !2 = !{}
27 !4 = distinct !DISubprogram(name: "main", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2)
27 !4 = distinct !DISubprogram(name: "main", line: 6, virtualIndex: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !0, scopeLine: 6, file: !1, scope: !5, type: !6, retainedNodes: !2)
2828 !5 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
2929 !6 = !DISubroutineType(types: !7)
3030 !7 = !{!8}
3939 !2 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !3, producer: "clang LLVM (rustc version 1.24.0-dev)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
4040 !3 = !DIFile(filename: "e3.rs", directory: "/home/tromey/Rust")
4141 !4 = !{}
42 !5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, isLocal: true, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4)
42 !5 = distinct !DISubprogram(name: "main", linkageName: "_ZN2e34mainE", scope: !6, file: !3, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !2, templateParams: !4, retainedNodes: !4)
4343 !6 = !DINamespace(name: "e3", scope: null)
4444 !7 = !DIFile(filename: "", directory: "")
4545 !8 = !DISubroutineType(types: !9)
108108 !22 = !DIExpression()
109109 !23 = !DILocation(line: 1, scope: !11)
110110 !24 = !DILocation(line: 59, scope: !11)
111 !25 = distinct !DISubprogram(name: "main", linkageName: "_ZN2t24mainE", scope: !26, file: !9, line: 9, type: !27, isLocal: true, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped | DIFlagMainSubprogram, isOptimized: false, unit: !8, templateParams: !4, retainedNodes: !4)
111 !25 = distinct !DISubprogram(name: "main", linkageName: "_ZN2t24mainE", scope: !26, file: !9, line: 9, type: !27, scopeLine: 9, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, isOptimized: false, unit: !8, templateParams: !4, retainedNodes: !4)
112112 !26 = !DINamespace(name: "t2", scope: null)
113113 !27 = !DISubroutineType(types: !28)
114114 !28 = !{null}