[llvm] r356454 - [DebugInfoMetadata] Move main subprogram DIFlag into DISPFlags
Petar Jovanovic via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 06:49:03 PDT 2019
Author: petarj
Date: Tue Mar 19 06:49:03 2019
New Revision: 356454
URL: http://llvm.org/viewvc/llvm-project?rev=356454&view=rev
Log:
[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
Added:
llvm/trunk/test/Bitcode/DISubprogram-v5.ll
llvm/trunk/test/Bitcode/DISubprogram-v5.ll.bc (with props)
Modified:
llvm/trunk/include/llvm-c/DebugInfo.h
llvm/trunk/include/llvm/IR/DebugInfoFlags.def
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp
llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll
llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll
llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll
llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll
llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll
Modified: llvm/trunk/include/llvm-c/DebugInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/DebugInfo.h?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/DebugInfo.h (original)
+++ llvm/trunk/include/llvm-c/DebugInfo.h Tue Mar 19 06:49:03 2019
@@ -50,7 +50,6 @@ typedef enum {
LLVMDIFlagIntroducedVirtual = 1 << 18,
LLVMDIFlagBitField = 1 << 19,
LLVMDIFlagNoReturn = 1 << 20,
- LLVMDIFlagMainSubprogram = 1 << 21,
LLVMDIFlagTypePassByValue = 1 << 22,
LLVMDIFlagTypePassByReference = 1 << 23,
LLVMDIFlagEnumClass = 1 << 24,
Modified: llvm/trunk/include/llvm/IR/DebugInfoFlags.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoFlags.def?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoFlags.def (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoFlags.def Tue Mar 19 06:49:03 2019
@@ -50,7 +50,6 @@ HANDLE_DI_FLAG((3 << 16), VirtualInherit
HANDLE_DI_FLAG((1 << 18), IntroducedVirtual)
HANDLE_DI_FLAG((1 << 19), BitField)
HANDLE_DI_FLAG((1 << 20), NoReturn)
-HANDLE_DI_FLAG((1 << 21), MainSubprogram)
HANDLE_DI_FLAG((1 << 22), TypePassByValue)
HANDLE_DI_FLAG((1 << 23), TypePassByReference)
HANDLE_DI_FLAG((1 << 24), EnumClass)
@@ -88,11 +87,12 @@ HANDLE_DISP_FLAG((1u << 4), Optimized)
HANDLE_DISP_FLAG((1u << 5), Pure)
HANDLE_DISP_FLAG((1u << 6), Elemental)
HANDLE_DISP_FLAG((1u << 7), Recursive)
+HANDLE_DISP_FLAG((1u << 8), MainSubprogram)
#ifdef DISP_FLAG_LARGEST_NEEDED
// Intended to be used with ADT/BitmaskEnum.h.
// NOTE: Always must be equal to largest flag, check this when adding new flags.
-HANDLE_DISP_FLAG((1 << 7), Largest)
+HANDLE_DISP_FLAG((1 << 8), Largest)
#undef DISP_FLAG_LARGEST_NEEDED
#endif
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Tue Mar 19 06:49:03 2019
@@ -1675,7 +1675,8 @@ public:
// Helper for converting old bitfields to new flags word.
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition,
bool IsOptimized,
- unsigned Virtuality = SPFlagNonvirtual) {
+ unsigned Virtuality = SPFlagNonvirtual,
+ bool IsMainSubprogram = false) {
// We're assuming virtuality is the low-order field.
static_assert(
int(SPFlagVirtual) == int(dwarf::DW_VIRTUALITY_virtual) &&
@@ -1685,7 +1686,8 @@ public:
(Virtuality & SPFlagVirtuality) |
(IsLocalToUnit ? SPFlagLocalToUnit : SPFlagZero) |
(IsDefinition ? SPFlagDefinition : SPFlagZero) |
- (IsOptimized ? SPFlagOptimized : SPFlagZero));
+ (IsOptimized ? SPFlagOptimized : SPFlagZero) |
+ (IsMainSubprogram ? SPFlagMainSubprogram : SPFlagZero));
}
private:
@@ -1784,6 +1786,7 @@ public:
bool isLocalToUnit() const { return getSPFlags() & SPFlagLocalToUnit; }
bool isDefinition() const { return getSPFlags() & SPFlagDefinition; }
bool isOptimized() const { return getSPFlags() & SPFlagOptimized; }
+ bool isMainSubprogram() const { return getSPFlags() & SPFlagMainSubprogram; }
bool isArtificial() const { return getFlags() & FlagArtificial; }
bool isPrivate() const {
@@ -1800,7 +1803,6 @@ public:
bool areAllCallsDescribed() const {
return getFlags() & FlagAllCallsDescribed;
}
- bool isMainSubprogram() const { return getFlags() & FlagMainSubprogram; }
bool isPure() const { return getSPFlags() & SPFlagPure; }
bool isElemental() const { return getSPFlags() & SPFlagElemental; }
bool isRecursive() const { return getSPFlags() & SPFlagRecursive; }
Modified: llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp Tue Mar 19 06:49:03 2019
@@ -1406,12 +1406,33 @@ Error MetadataLoader::MetadataLoaderImpl
return error("Invalid record");
bool HasSPFlags = Record[0] & 4;
- DISubprogram::DISPFlags SPFlags =
- HasSPFlags
- ? static_cast<DISubprogram::DISPFlags>(Record[9])
- : DISubprogram::toSPFlags(
- /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
- /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11]);
+
+ DINode::DIFlags Flags;
+ DISubprogram::DISPFlags SPFlags;
+ if (!HasSPFlags)
+ Flags = static_cast<DINode::DIFlags>(Record[11 + 2]);
+ else {
+ Flags = static_cast<DINode::DIFlags>(Record[11]);
+ SPFlags = static_cast<DISubprogram::DISPFlags>(Record[9]);
+ }
+
+ // Support for old metadata when
+ // subprogram specific flags are placed in DIFlags.
+ const unsigned DIFlagMainSubprogram = 1 << 21;
+ bool HasOldMainSubprogramFlag = Flags & DIFlagMainSubprogram;
+ if (HasOldMainSubprogramFlag)
+ // Remove old DIFlagMainSubprogram from DIFlags.
+ // Note: This assumes that any future use of bit 21 defaults to it
+ // being 0.
+ Flags &= ~static_cast<DINode::DIFlags>(DIFlagMainSubprogram);
+
+ if (HasOldMainSubprogramFlag && HasSPFlags)
+ SPFlags |= DISubprogram::SPFlagMainSubprogram;
+ else if (!HasSPFlags)
+ SPFlags = DISubprogram::toSPFlags(
+ /*IsLocalToUnit=*/Record[7], /*IsDefinition=*/Record[8],
+ /*IsOptimized=*/Record[14], /*Virtuality=*/Record[11],
+ /*DIFlagMainSubprogram*/HasOldMainSubprogramFlag);
// All definitions should be distinct.
IsDistinct = (Record[0] & 1) || (SPFlags & DISubprogram::SPFlagDefinition);
@@ -1455,7 +1476,7 @@ Error MetadataLoader::MetadataLoaderImpl
getDITypeRefOrNull(Record[8 + OffsetA]), // containingType
Record[10 + OffsetA], // virtualIndex
HasThisAdj ? Record[16 + OffsetB] : 0, // thisAdjustment
- static_cast<DINode::DIFlags>(Record[11 + OffsetA]),// flags
+ Flags, // flags
SPFlags, // SPFlags
HasUnit ? CUorFn : nullptr, // unit
getMDOrNull(Record[13 + OffsetB]), // templateParams
Added: llvm/trunk/test/Bitcode/DISubprogram-v5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/DISubprogram-v5.ll?rev=356454&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/DISubprogram-v5.ll (added)
+++ llvm/trunk/test/Bitcode/DISubprogram-v5.ll Tue Mar 19 06:49:03 2019
@@ -0,0 +1,24 @@
+ ; The .bc file was generated from this source using llvm-as from 8.0 release.
+ ; RUN: llvm-dis < %s.bc | FileCheck %s
+
+define i32 @main() !dbg !5 {
+entry:
+ %retval = alloca i32, align 4
+ store i32 0, i32* %retval
+ ret i32 0, !dbg !9
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+
+!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)
+!1 = !DIFile(filename: "mainsubprogram.c", directory: "/dir")
+!2 = !{}
+!3 = !{i32 2, !"Dwarf Version", i32 4}
+!4 = !{i32 1, !"Debug Info Version", i32 3}
+!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)
+; 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)
+!6 = !DISubroutineType(types: !7)
+!7 = !{!8}
+!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !DILocation(line: 7, scope: !5)
Added: llvm/trunk/test/Bitcode/DISubprogram-v5.ll.bc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/DISubprogram-v5.ll.bc?rev=356454&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/Bitcode/DISubprogram-v5.ll.bc
------------------------------------------------------------------------------
svn:executable = *
Propchange: llvm/trunk/test/Bitcode/DISubprogram-v5.ll.bc
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Modified: llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/containing-type-extension.ll Tue Mar 19 06:49:03 2019
@@ -25,7 +25,7 @@ attributes #0 = { nounwind uwtable }
!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)
!1 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
!2 = !{}
-!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)
+!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)
!5 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
!6 = !DISubroutineType(types: !7)
!7 = !{!8}
Modified: llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/discriminated-union.ll Tue Mar 19 06:49:03 2019
@@ -53,7 +53,7 @@ attributes #0 = { nounwind uwtable }
!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)
!3 = !DIFile(filename: "e3.rs", directory: "/home/tromey/Rust")
!4 = !{}
-!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)
+!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)
!6 = !DINamespace(name: "e3", scope: null)
!7 = !DIFile(filename: "<unknown>", directory: "")
!8 = !DISubroutineType(types: !9)
Modified: llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/mainsubprogram.ll Tue Mar 19 06:49:03 2019
@@ -25,7 +25,7 @@ attributes #0 = { nounwind uwtable "less
!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)
!1 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
!2 = !{}
-!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)
+!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)
!5 = !DIFile(filename: "CodeGen/dwarf-version.c", directory: "test")
!6 = !DISubroutineType(types: !7)
!7 = !{!8}
Modified: llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll (original)
+++ llvm/trunk/test/DebugInfo/Generic/univariant-discriminated-union.ll Tue Mar 19 06:49:03 2019
@@ -40,7 +40,7 @@ attributes #0 = { nounwind uwtable }
!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)
!3 = !DIFile(filename: "e3.rs", directory: "/home/tromey/Rust")
!4 = !{}
-!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)
+!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)
!6 = !DINamespace(name: "e3", scope: null)
!7 = !DIFile(filename: "<unknown>", directory: "")
!8 = !DISubroutineType(types: !9)
Modified: llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll?rev=356454&r1=356453&r2=356454&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/containing-type-extension-rust.ll Tue Mar 19 06:49:03 2019
@@ -109,7 +109,7 @@ attributes #3 = { "no-frame-pointer-elim
!22 = !DIExpression()
!23 = !DILocation(line: 1, scope: !11)
!24 = !DILocation(line: 59, scope: !11)
-!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)
+!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)
!26 = !DINamespace(name: "t2", scope: null)
!27 = !DISubroutineType(types: !28)
!28 = !{null}
More information about the llvm-commits
mailing list