llvm.org GIT mirror llvm / e56023a
IR: Give 'DI' prefix to debug info metadata Finish off PR23080 by renaming the debug info IR constructs from `MD*` to `DI*`. The last of the `DIDescriptor` classes were deleted in r235356, and the last of the related typedefs removed in r235413, so this has all baked for about a week. Note: If you have out-of-tree code (like a frontend), I recommend that you get everything compiling and tests passing with the *previous* commit before updating to this one. It'll be easier to keep track of what code is using the `DIDescriptor` hierarchy and what you've already updated, and I think you're extremely unlikely to insert bugs. YMMV of course. Back to *this* commit: I did this using the rename-md-di-nodes.sh upgrade script I've attached to PR23080 (both code and testcases) and filtered through clang-format-diff.py. I edited the tests for test/Assembler/invalid-generic-debug-node-*.ll by hand since the columns were off-by-three. It should work on your out-of-tree testcases (and code, if you've followed the advice in the previous paragraph). Some of the tests are in badly named files now (e.g., test/Assembler/invalid-mdcompositetype-missing-tag.ll should be 'dicompositetype'); I'll come back and move the files in a follow-up commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236120 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
548 changed file(s) with 11528 addition(s) and 11539 deletion(s). Raw diff Collapse all Expand all
5555 unsigned Line,
5656 unsigned Column) {
5757 DIBuilder *D = unwrap(Dref);
58 auto *LB = D->createLexicalBlock(unwrap(Scope),
59 unwrap(File), Line, Column);
58 auto *LB = D->createLexicalBlock(unwrap(Scope),
59 unwrap(File), Line, Column);
6060 return wrap(LB);
6161 }
6262
6565 LLVMMetadataRef File,
6666 unsigned Discriminator) {
6767 DIBuilder *D = unwrap(Dref);
68 return wrap(D->createLexicalBlockFile(unwrap(Scope),
69 unwrap(File), Discriminator));
68 return wrap(D->createLexicalBlockFile(unwrap(Scope),
69 unwrap(File), Discriminator));
7070 }
7171
7272 LLVMMetadataRef LLVMDIBuilderCreateFunction(
7575 LLVMMetadataRef CompositeType, int IsLocalToUnit, int IsDefinition,
7676 unsigned ScopeLine, unsigned Flags, int IsOptimized, LLVMValueRef Func) {
7777 DIBuilder *D = unwrap(Dref);
78 return wrap(D->createFunction(unwrap(Scope), Name, LinkageName,
79 File ? unwrap(File) : nullptr, Line,
80 unwrap(CompositeType),
78 return wrap(D->createFunction(unwrap(Scope), Name, LinkageName,
79 File ? unwrap(File) : nullptr, Line,
80 unwrap(CompositeType),
8181 IsLocalToUnit, IsDefinition, ScopeLine, Flags,
8282 IsOptimized, unwrap(Func)));
8383 }
8888 int AlwaysPreserve, unsigned Flags, unsigned ArgNo) {
8989 DIBuilder *D = unwrap(Dref);
9090 return wrap(D->createLocalVariable(
91 Tag, unwrap(Scope), Name, unwrap(File), Line,
92 unwrap(Ty), AlwaysPreserve, Flags, ArgNo));
91 Tag, unwrap(Scope), Name, unwrap(File), Line,
92 unwrap(Ty), AlwaysPreserve, Flags, ArgNo));
9393 }
9494
9595 LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Dref,
107107 uint64_t AlignInBits,
108108 const char *Name) {
109109 DIBuilder *D = unwrap(Dref);
110 return wrap(D->createPointerType(unwrap<MDType>(PointeeType), SizeInBits,
110 return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits,
111111 AlignInBits, Name));
112112 }
113113
116116 LLVMMetadataRef ParameterTypes) {
117117 DIBuilder *D = unwrap(Dref);
118118 return wrap(
119 D->createSubroutineType(File ? unwrap(File) : nullptr,
120 MDTypeRefArray(unwrap(ParameterTypes))));
119 D->createSubroutineType(File ? unwrap(File) : nullptr,
120 DITypeRefArray(unwrap(ParameterTypes))));
121121 }
122122
123123 LLVMMetadataRef LLVMDIBuilderCreateStructType(
127127 LLVMMetadataRef ElementTypes) {
128128 DIBuilder *D = unwrap(Dref);
129129 return wrap(D->createStructType(
130 unwrap<MDScope>(Scope), Name, File ? unwrapFile>(File) : nullptr, Line,
130 unwrap<DIScope>(Scope), Name, File ? unwrapFile>(File) : nullptr, Line,
131131 SizeInBits, AlignInBits, Flags,
132 DerivedFrom ? unwrap(DerivedFrom) : nullptr,
133 ElementTypes ? DebugNodeArray(unwrap(ElementTypes)) : nullptr));
132 DerivedFrom ? unwrap(DerivedFrom) : nullptr,
133 ElementTypes ? DINodeArray(unwrap(ElementTypes)) : nullptr));
134134 }
135135
136136 LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(
140140 unsigned Flags) {
141141 DIBuilder *D = unwrap(Dref);
142142 return wrap(D->createReplaceableCompositeType(
143 Tag, Name, unwrap<MDScope>(Scope), File ? unwrapFile>(File) : nullptr,
143 Tag, Name, unwrap<DIScope>(Scope), File ? unwrapFile>(File) : nullptr,
144144 Line, RuntimeLang, SizeInBits, AlignInBits, Flags));
145145 }
146146
152152 unsigned Flags, LLVMMetadataRef Ty) {
153153 DIBuilder *D = unwrap(Dref);
154154 return wrap(D->createMemberType(
155 unwrap(Scope), Name, File ? unwrap(File) : nullptr, Line,
156 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap(Ty)));
155 unwrap(Scope), Name, File ? unwrap(File) : nullptr, Line,
156 SizeInBits, AlignInBits, OffsetInBits, Flags, unwrap(Ty)));
157157 }
158158
159159 LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Dref,
163163 LLVMMetadataRef Subscripts) {
164164 DIBuilder *D = unwrap(Dref);
165165 return wrap(D->createArrayType(SizeInBits, AlignInBits,
166 unwrap(ElementType),
167 DebugNodeArray(unwrap(Subscripts))));
166 unwrap(ElementType),
167 DINodeArray(unwrap(Subscripts))));
168168 }
169169
170170 LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Dref,
172172 LLVMMetadataRef File, unsigned Line,
173173 LLVMMetadataRef Context) {
174174 DIBuilder *D = unwrap(Dref);
175 return wrap(D->createTypedef(unwrap(Ty), Name,
176 File ? unwrap(File) : nullptr, Line,
177 Context ? unwrap(Context) : nullptr));
175 return wrap(D->createTypedef(unwrap(Ty), Name,
176 File ? unwrap(File) : nullptr, Line,
177 Context ? unwrap(Context) : nullptr));
178178 }
179179
180180 LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Dref,
189189 DIBuilder *D = unwrap(Dref);
190190 Metadata **DataValue = unwrap(Data);
191191 ArrayRef Elements(DataValue, Length);
192 DebugNodeArray A = D->getOrCreateArray(Elements);
192 DINodeArray A = D->getOrCreateArray(Elements);
193193 return wrap(A.get());
194194 }
195195
199199 DIBuilder *D = unwrap(Dref);
200200 Metadata **DataValue = unwrap(Data);
201201 ArrayRef Elements(DataValue, Length);
202 MDTypeRefArray A = D->getOrCreateTypeArray(Elements);
202 DITypeRefArray A = D->getOrCreateTypeArray(Elements);
203203 return wrap(A.get());
204204 }
205205
220220
221221 DIBuilder *D = unwrap(Dref);
222222 Instruction *Instr = D->insertDeclare(
223 unwrap(Storage), unwrap(VarInfo),
224 unwrap(Expr), /* DebugLoc */ nullptr, unwrap(Block));
223 unwrap(Storage), unwrap(VarInfo),
224 unwrap(Expr), /* DebugLoc */ nullptr, unwrap(Block));
225225 return wrap(Instr);
226226 }
227227
236236
237237 DIBuilder *D = unwrap(Dref);
238238 Instruction *Instr = D->insertDbgValueIntrinsic(
239 unwrap(Val), Offset, unwrap(VarInfo),
240 unwrap(Expr), /* DebugLoc */ nullptr, unwrap(Block));
239 unwrap(Val), Offset, unwrap(VarInfo),
240 unwrap(Expr), /* DebugLoc */ nullptr, unwrap(Block));
241241 return wrap(Instr);
242242 }
199199
200200 .. code-block:: llvm
201201
202 !0 = !MDLocation(line: 5, scope: !1, inlinedAt: !2)
203
204 ; CHECK: !MDLocation(line: 5,
202 !0 = !DILocation(line: 5, scope: !1, inlinedAt: !2)
203
204 ; CHECK: !DILocation(line: 5,
205205 ; CHECK-NOT: column:
206206 ; CHECK-SAME: scope: ![[SCOPE:[0-9]+]]
207207
29212921 These aren't inherently debug info centric, but currently all the specialized
29222922 metadata nodes are related to debug info.
29232923
2924 .. _MDCompileUnit:
2925
2926 MDCompileUnit
2924 .. _DICompileUnit:
2925
2926 DICompileUnit
29272927 """""""""""""
29282928
2929 ``MDCompileUnit`` nodes represent a compile unit. The ``enums:``,
2929 ``DICompileUnit`` nodes represent a compile unit. The ``enums:``,
29302930 ``retainedTypes:``, ``subprograms:``, ``globals:`` and ``imports:`` fields are
29312931 tuples containing the debug info to be emitted along with the compile unit,
29322932 regardless of code optimizations (some nodes are only emitted if there are
29342934
29352935 .. code-block:: llvm
29362936
2937 !0 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
2937 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang",
29382938 isOptimized: true, flags: "-O2", runtimeVersion: 2,
29392939 splitDebugFilename: "abc.debug", emissionKind: 1,
29402940 enums: !2, retainedTypes: !3, subprograms: !4,
29462946 keep track of subprograms, global variables, type information, and imported
29472947 entities (declarations and namespaces).
29482948
2949 .. _MDFile:
2950
2951 MDFile
2949 .. _DIFile:
2950
2951 DIFile
29522952 """"""
29532953
2954 ``MDFile`` nodes represent files. The ``filename:`` can include slashes.
2955
2956 .. code-block:: llvm
2957
2958 !0 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
2954 ``DIFile`` nodes represent files. The ``filename:`` can include slashes.
2955
2956 .. code-block:: llvm
2957
2958 !0 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
29592959
29602960 Files are sometimes used in ``scope:`` fields, and are the only valid target
29612961 for ``file:`` fields.
29622962
2963 .. _MDLocation:
2964
2965 MDBasicType
2963 .. _DILocation:
2964
2965 DIBasicType
29662966 """""""""""
29672967
2968 ``MDBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
2968 ``DIBasicType`` nodes represent primitive types, such as ``int``, ``bool`` and
29692969 ``float``. ``tag:`` defaults to ``DW_TAG_base_type``.
29702970
29712971 .. code-block:: llvm
29722972
2973 !0 = !MDBasicType(name: "unsigned char", size: 8, align: 8,
2973 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
29742974 encoding: DW_ATE_unsigned_char)
2975 !1 = !MDBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
2975 !1 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "decltype(nullptr)")
29762976
29772977 The ``encoding:`` describes the details of the type. Usually it's one of the
29782978 following:
29872987 DW_ATE_unsigned = 7
29882988 DW_ATE_unsigned_char = 8
29892989
2990 .. _MDSubroutineType:
2991
2992 MDSubroutineType
2990 .. _DISubroutineType:
2991
2992 DISubroutineType
29932993 """"""""""""""""
29942994
2995 ``MDSubroutineType`` nodes represent subroutine types. Their ``types:`` field
2995 ``DISubroutineType`` nodes represent subroutine types. Their ``types:`` field
29962996 refers to a tuple; the first operand is the return type, while the rest are the
29972997 types of the formal arguments in order. If the first operand is ``null``, that
29982998 represents a function with no return value (such as ``void foo() {}`` in C++).
30013001
30023002 !0 = !BasicType(name: "int", size: 32, align: 32, DW_ATE_signed)
30033003 !1 = !BasicType(name: "char", size: 8, align: 8, DW_ATE_signed_char)
3004 !2 = !MDSubroutineType(types: !{null, !0, !1}) ; void (int, char)
3005
3006 .. _MDDerivedType:
3007
3008 MDDerivedType
3004 !2 = !DISubroutineType(types: !{null, !0, !1}) ; void (int, char)
3005
3006 .. _DIDerivedType:
3007
3008 DIDerivedType
30093009 """""""""""""
30103010
3011 ``MDDerivedType`` nodes represent types derived from other types, such as
3011 ``DIDerivedType`` nodes represent types derived from other types, such as
30123012 qualified types.
30133013
30143014 .. code-block:: llvm
30153015
3016 !0 = !MDBasicType(name: "unsigned char", size: 8, align: 8,
3016 !0 = !DIBasicType(name: "unsigned char", size: 8, align: 8,
30173017 encoding: DW_ATE_unsigned_char)
3018 !1 = !MDDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
3018 !1 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !0, size: 32,
30193019 align: 32)
30203020
30213021 The following ``tag:`` values are valid:
30333033 DW_TAG_restrict_type = 55
30343034
30353035 ``DW_TAG_member`` is used to define a member of a :ref:`composite type
3036 <MDCompositeType>` or :ref:`subprogram Subprogram>`. The type of the member
3036 <DICompositeType>` or :ref:`subprogram Subprogram>`. The type of the member
30373037 is the ``baseType:``. The ``offset:`` is the member's bit offset.
30383038 ``DW_TAG_formal_parameter`` is used to define a member which is a formal
30393039 argument of a subprogram.
30463046
30473047 Note that the ``void *`` type is expressed as a type derived from NULL.
30483048
3049 .. _MDCompositeType:
3050
3051 MDCompositeType
3049 .. _DICompositeType:
3050
3051 DICompositeType
30523052 """""""""""""""
30533053
3054 ``MDCompositeType`` nodes represent types composed of other types, like
3054 ``DICompositeType`` nodes represent types composed of other types, like
30553055 structures and unions. ``elements:`` points to a tuple of the composed types.
30563056
30573057 If the source language supports ODR, the ``identifier:`` field gives the unique
30613061
30623062 .. code-block:: llvm
30633063
3064 !0 = !MDEnumerator(name: "SixKind", value: 7)
3065 !1 = !MDEnumerator(name: "SevenKind", value: 7)
3066 !2 = !MDEnumerator(name: "NegEightKind", value: -8)
3067 !3 = !MDCompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
3064 !0 = !DIEnumerator(name: "SixKind", value: 7)
3065 !1 = !DIEnumerator(name: "SevenKind", value: 7)
3066 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
3067 !3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Enum", file: !12,
30683068 line: 2, size: 32, align: 32, identifier: "_M4Enum",
30693069 elements: !{!0, !1, !2})
30703070
30823082
30833083
30843084 For ``DW_TAG_array_type``, the ``elements:`` should be :ref:`subrange
3085 descriptors <MDSubrange>`, each representing the range of subscripts at that
3085 descriptors <DISubrange>`, each representing the range of subscripts at that
30863086 level of indexing. The ``DIFlagVector`` flag to ``flags:`` indicates that an
30873087 array type is a native packed vector.
30883088
30893089 For ``DW_TAG_enumeration_type``, the ``elements:`` should be :ref:`enumerator
3090 descriptors <MDEnumerator>`, each representing the definition of an enumeration
3090 descriptors <DIEnumerator>`, each representing the definition of an enumeration
30913091 value for the set. All enumeration type descriptors are collected in the
3092 ``enums:`` field of the :ref:`compile unit <MDCompileUnit>`.
3092 ``enums:`` field of the :ref:`compile unit <DICompileUnit>`.
30933093
30943094 For ``DW_TAG_structure_type``, ``DW_TAG_class_type``, and
30953095 ``DW_TAG_union_type``, the ``elements:`` should be :ref:`derived types
3096 ` with ``tag: DW_TAG_member`` or ``tag: DW_TAG_inheritance``.
3097
3098 .. _MDSubrange:
3099
3100 MDSubrange
3101 """"""""""
3102
3103 ``MDSubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
3104 :ref:`MDCompositeType`. ``count: -1`` indicates an empty array.
3105
3106 .. code-block:: llvm
3107
3108 !0 = !MDSubrange(count: 5, lowerBound: 0) ; array counting from 0
3109 !1 = !MDSubrange(count: 5, lowerBound: 1) ; array counting from 1
3110 !2 = !MDSubrange(count: -1) ; empty array.
3111
3112 .. _MDEnumerator:
3113
3114 MDEnumerator
3096 ` with ``tag: DW_TAG_member`` or ``tag: DW_TAG_inheritance``.
3097
3098 .. _DISubrange:
3099
3100 DISubrange
3101 """"""""""
3102
3103 ``DISubrange`` nodes are the elements for ``DW_TAG_array_type`` variants of
3104 :ref:`DICompositeType`. ``count: -1`` indicates an empty array.
3105
3106 .. code-block:: llvm
3107
3108 !0 = !DISubrange(count: 5, lowerBound: 0) ; array counting from 0
3109 !1 = !DISubrange(count: 5, lowerBound: 1) ; array counting from 1
3110 !2 = !DISubrange(count: -1) ; empty array.
3111
3112 .. _DIEnumerator:
3113
3114 DIEnumerator
31153115 """"""""""""
31163116
3117 ``MDEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
3118 variants of :ref:`MDCompositeType`.
3119
3120 .. code-block:: llvm
3121
3122 !0 = !MDEnumerator(name: "SixKind", value: 7)
3123 !1 = !MDEnumerator(name: "SevenKind", value: 7)
3124 !2 = !MDEnumerator(name: "NegEightKind", value: -8)
3125
3126 MDTemplateTypeParameter
3117 ``DIEnumerator`` nodes are the elements for ``DW_TAG_enumeration_type``
3118 variants of :ref:`DICompositeType`.
3119
3120 .. code-block:: llvm
3121
3122 !0 = !DIEnumerator(name: "SixKind", value: 7)
3123 !1 = !DIEnumerator(name: "SevenKind", value: 7)
3124 !2 = !DIEnumerator(name: "NegEightKind", value: -8)
3125
3126 DITemplateTypeParameter
31273127 """""""""""""""""""""""
31283128
3129 ``MDTemplateTypeParameter`` nodes represent type parameters to generic source
3130 language constructs. They are used (optionally) in :ref:`MDCompositeType` and
3131 :ref:`MDSubprogram` ``templateParams:`` fields.
3132
3133 .. code-block:: llvm
3134
3135 !0 = !MDTemplateTypeParameter(name: "Ty", type: !1)
3136
3137 MDTemplateValueParameter
3129 ``DITemplateTypeParameter`` nodes represent type parameters to generic source
3130 language constructs. They are used (optionally) in :ref:`DICompositeType` and
3131 :ref:`DISubprogram` ``templateParams:`` fields.
3132
3133 .. code-block:: llvm
3134
3135 !0 = !DITemplateTypeParameter(name: "Ty", type: !1)
3136
3137 DITemplateValueParameter
31383138 """"""""""""""""""""""""
31393139
3140 ``MDTemplateValueParameter`` nodes represent value parameters to generic source
3140 ``DITemplateValueParameter`` nodes represent value parameters to generic source
31413141 language constructs. ``tag:`` defaults to ``DW_TAG_template_value_parameter``,
31423142 but if specified can also be set to ``DW_TAG_GNU_template_template_param`` or
31433143 ``DW_TAG_GNU_template_param_pack``. They are used (optionally) in
3144 :ref:`MDCompositeType` and :ref:`MDSubprogram` ``templateParams:`` fields.
3145
3146 .. code-block:: llvm
3147
3148 !0 = !MDTemplateValueParameter(name: "Ty", type: !1, value: i32 7)
3149
3150 MDNamespace
3144 :ref:`DICompositeType` and :ref:`DISubprogram` ``templateParams:`` fields.
3145
3146 .. code-block:: llvm
3147
3148 !0 = !DITemplateValueParameter(name: "Ty", type: !1, value: i32 7)
3149
3150 DINamespace
31513151 """""""""""
31523152
3153 ``MDNamespace`` nodes represent namespaces in the source language.
3154
3155 .. code-block:: llvm
3156
3157 !0 = !MDNamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
3158
3159 MDGlobalVariable
3153 ``DINamespace`` nodes represent namespaces in the source language.
3154
3155 .. code-block:: llvm
3156
3157 !0 = !DINamespace(name: "myawesomeproject", scope: !1, file: !2, line: 7)
3158
3159 DIGlobalVariable
31603160 """"""""""""""""
31613161
3162 ``MDGlobalVariable`` nodes represent global variables in the source language.
3163
3164 .. code-block:: llvm
3165
3166 !0 = !MDGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
3162 ``DIGlobalVariable`` nodes represent global variables in the source language.
3163
3164 .. code-block:: llvm
3165
3166 !0 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !1,
31673167 file: !2, line: 7, type: !3, isLocal: true,
31683168 isDefinition: false, variable: i32* @foo,
31693169 declaration: !4)
31703170
31713171 All global variables should be referenced by the `globals:` field of a
3172 :ref:`compile unit `.
3173
3174 .. _MDSubprogram:
3175
3176 MDSubprogram
3172 :ref:`compile unit `.
3173
3174 .. _DISubprogram:
3175
3176 DISubprogram
31773177 """"""""""""
31783178
3179 ``MDSubprogram`` nodes represent functions from the source language. The
3180 ``variables:`` field points at :ref:`variables ` that must be
3179 ``DISubprogram`` nodes represent functions from the source language. The
3180 ``variables:`` field points at :ref:`variables ` that must be
31813181 retained, even if their IR counterparts are optimized out of the IR. The
3182 ``type:`` field must point at an :ref:`MDSubroutineType`.
3183
3184 .. code-block:: llvm
3185
3186 !0 = !MDSubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
3182 ``type:`` field must point at an :ref:`DISubroutineType`.
3183
3184 .. code-block:: llvm
3185
3186 !0 = !DISubprogram(name: "foo", linkageName: "_Zfoov", scope: !1,
31873187 file: !2, line: 7, type: !3, isLocal: true,
31883188 isDefinition: false, scopeLine: 8, containingType: !4,
31893189 virtuality: DW_VIRTUALITY_pure_virtual, virtualIndex: 10,
31913191 function: void ()* @_Z3foov,
31923192 templateParams: !5, declaration: !6, variables: !7)
31933193
3194 .. _MDLexicalBlock:
3195
3196 MDLexicalBlock
3194 .. _DILexicalBlock:
3195
3196 DILexicalBlock
31973197 """"""""""""""
31983198
3199 ``MDLexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
3200 `. The line number and column numbers are used to dinstinguish
3199 ``DILexicalBlock`` nodes describe nested blocks within a :ref:`subprogram
3200 `. The line number and column numbers are used to dinstinguish
32013201 two lexical blocks at same depth. They are valid targets for ``scope:``
32023202 fields.
32033203
32043204 .. code-block:: llvm
32053205
3206 !0 = distinct !MDLexicalBlock(scope: !1, file: !2, line: 7, column: 35)
3206 !0 = distinct !DILexicalBlock(scope: !1, file: !2, line: 7, column: 35)
32073207
32083208 Usually lexical blocks are ``distinct`` to prevent node merging based on
32093209 operands.
32103210
3211 .. _MDLexicalBlockFile:
3212
3213 MDLexicalBlockFile
3211 .. _DILexicalBlockFile:
3212
3213 DILexicalBlockFile
32143214 """"""""""""""""""
32153215
3216 ``MDLexicalBlockFile`` nodes are used to discriminate between sections of a
3217 :ref:`lexical block `. The ``file:`` field can be changed to
3216 ``DILexicalBlockFile`` nodes are used to discriminate between sections of a
3217 :ref:`lexical block `. The ``file:`` field can be changed to
32183218 indicate textual inclusion, or the ``discriminator:`` field can be used to
32193219 discriminate between control flow within a single block in the source language.
32203220
32213221 .. code-block:: llvm
32223222
3223 !0 = !MDLexicalBlock(scope: !3, file: !4, line: 7, column: 35)
3224 !1 = !MDLexicalBlockFile(scope: !0, file: !4, discriminator: 0)
3225 !2 = !MDLexicalBlockFile(scope: !0, file: !4, discriminator: 1)
3226
3227 MDLocation
3228 """"""""""
3229
3230 ``MDLocation`` nodes represent source debug locations. The ``scope:`` field is
3231 mandatory, and points at an :ref:`MDLexicalBlockFile`, an
3232 :ref:`MDLexicalBlock`, or an :ref:`MDSubprogram`.
3233
3234 .. code-block:: llvm
3235
3236 !0 = !MDLocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
3237
3238 .. _MDLocalVariable:
3239
3240 MDLocalVariable
3223 !0 = !DILexicalBlock(scope: !3, file: !4, line: 7, column: 35)
3224 !1 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 0)
3225 !2 = !DILexicalBlockFile(scope: !0, file: !4, discriminator: 1)
3226
3227 DILocation
3228 """"""""""
3229
3230 ``DILocation`` nodes represent source debug locations. The ``scope:`` field is
3231 mandatory, and points at an :ref:`DILexicalBlockFile`, an
3232 :ref:`DILexicalBlock`, or an :ref:`DISubprogram`.
3233
3234 .. code-block:: llvm
3235
3236 !0 = !DILocation(line: 2900, column: 42, scope: !1, inlinedAt: !2)
3237
3238 .. _DILocalVariable:
3239
3240 DILocalVariable
32413241 """""""""""""""
32423242
3243 ``MDLocalVariable`` nodes represent local variables in the source language.
3243 ``DILocalVariable`` nodes represent local variables in the source language.
32443244 Instead of ``DW_TAG_variable``, they use LLVM-specific fake tags to
32453245 discriminate between local variables (``DW_TAG_auto_variable``) and subprogram
32463246 arguments (``DW_TAG_arg_variable``). In the latter case, the ``arg:`` field
32473247 specifies the argument position, and this variable will be included in the
3248 ``variables:`` field of its :ref:`MDSubprogram`.
3249
3250 .. code-block:: llvm
3251
3252 !0 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 0,
3248 ``variables:`` field of its :ref:`DISubprogram`.
3249
3250 .. code-block:: llvm
3251
3252 !0 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "this", arg: 0,
32533253 scope: !3, file: !2, line: 7, type: !3,
32543254 flags: DIFlagArtificial)
3255 !1 = !MDLocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1,
3255 !1 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "x", arg: 1,
32563256 scope: !4, file: !2, line: 7, type: !3)
3257 !1 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "y",
3257 !1 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "y",
32583258 scope: !5, file: !2, line: 7, type: !3)
32593259
3260 MDExpression
3260 DIExpression
32613261 """"""""""""
32623262
3263 ``MDExpression`` nodes represent DWARF expression sequences. They are used in
3263 ``DIExpression`` nodes represent DWARF expression sequences. They are used in
32643264 :ref:`debug intrinsics` (such as ``llvm.dbg.declare``) to
32653265 describe how the referenced LLVM variable relates to the source language
32663266 variable.
32743274
32753275 .. code-block:: llvm
32763276
3277 !0 = !MDExpression(DW_OP_deref)
3278 !1 = !MDExpression(DW_OP_plus, 3)
3279 !2 = !MDExpression(DW_OP_bit_piece, 3, 7)
3280 !3 = !MDExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
3281
3282 MDObjCProperty
3277 !0 = !DIExpression(DW_OP_deref)
3278 !1 = !DIExpression(DW_OP_plus, 3)
3279 !2 = !DIExpression(DW_OP_bit_piece, 3, 7)
3280 !3 = !DIExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
3281
3282 DIObjCProperty
32833283 """"""""""""""
32843284
3285 ``MDObjCProperty`` nodes represent Objective-C property nodes.
3286
3287 .. code-block:: llvm
3288
3289 !3 = !MDObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
3285 ``DIObjCProperty`` nodes represent Objective-C property nodes.
3286
3287 .. code-block:: llvm
3288
3289 !3 = !DIObjCProperty(name: "foo", file: !1, line: 7, setter: "setFoo",
32903290 getter: "getFoo", attributes: 7, type: !2)
32913291
3292 MDImportedEntity
3292 DIImportedEntity
32933293 """"""""""""""""
32943294
3295 ``MDImportedEntity`` nodes represent entities (such as modules) imported into a
3295 ``DIImportedEntity`` nodes represent entities (such as modules) imported into a
32963296 compile unit.
32973297
32983298 .. code-block:: llvm
32993299
3300 !2 = !MDImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
3300 !2 = !DIImportedEntity(tag: DW_TAG_imported_module, name: "foo", scope: !0,
33013301 entity: !1, line: 7)
33023302
33033303 '``tbaa``' Metadata
152152 To provide basic functionality, the LLVM debugger does have to make some
153153 assumptions about the source-level language being debugged, though it keeps
154154 these to a minimum. The only common features that the LLVM debugger assumes
155 exist are `source files `_, and `program objects
156 `_. These abstract objects are used by a
155 exist are `source files `_, and `program objects
156 `_. These abstract objects are used by a
157157 debugger to form stack traces, show information about local variables, etc.
158158
159159 This section of the documentation first describes the representation aspects
180180
181181 This intrinsic provides information about a local element (e.g., variable).
182182 The first argument is metadata holding the alloca for the variable. The second
183 argument is a `local variable MDLocalVariable>`_ containing a
183 argument is a `local variable DILocalVariable>`_ containing a
184184 description of the variable. The third argument is a `complex expression
185 MDExpression>`_.
185 DIExpression>`_.
186186
187187 ``llvm.dbg.value``
188188 ^^^^^^^^^^^^^^^^^^
195195 value. The first argument is the new value (wrapped as metadata). The second
196196 argument is the offset in the user source variable where the new value is
197197 written. The third argument is a `local variable
198 `_ containing a description of the variable. The
199 third argument is a `complex expression `_.
198 `_ containing a description of the variable. The
199 third argument is a `complex expression `_.
200200
201201 Object lifetimes and scoping
202202 ============================
258258 !llvm.module.flags = !{!7, !8, !9}
259259 !llvm.ident = !{!10}
260260
261 !0 = !MDCompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
262 !1 = !MDFile(filename: "/dev/stdin", directory: "/Users/dexonsmith/data/llvm/debug-info")
261 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
262 !1 = !DIFile(filename: "/dev/stdin", directory: "/Users/dexonsmith/data/llvm/debug-info")
263263 !2 = !{}
264264 !3 = !{!4}
265 !4 = !MDSubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, function: void ()* @foo, variables: !2)
266 !5 = !MDSubroutineType(types: !6)
265 !4 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, function: void ()* @foo, variables: !2)
266 !5 = !DISubroutineType(types: !6)
267267 !6 = !{null}
268268 !7 = !{i32 2, !"Dwarf Version", i32 2}
269269 !8 = !{i32 2, !"Debug Info Version", i32 3}
270270 !9 = !{i32 1, !"PIC Level", i32 2}
271271 !10 = !{!"clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)"}
272 !11 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "X", scope: !4, file: !1, line: 2, type: !12)
273 !12 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
274 !13 = !MDExpression()
275 !14 = !MDLocation(line: 2, column: 9, scope: !4)
276 !15 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "Y", scope: !4, file: !1, line: 3, type: !12)
277 !16 = !MDLocation(line: 3, column: 9, scope: !4)
278 !17 = !MDLocalVariable(tag: DW_TAG_auto_variable, name: "Z", scope: !18, file: !1, line: 5, type: !12)
279 !18 = distinct !MDLexicalBlock(scope: !4, file: !1, line: 4, column: 5)
280 !19 = !MDLocation(line: 5, column: 11, scope: !18)
281 !20 = !MDLocation(line: 6, column: 11, scope: !18)
282 !21 = !MDLocation(line: 6, column: 9, scope: !18)
283 !22 = !MDLocation(line: 8, column: 9, scope: !4)
284 !23 = !MDLocation(line: 8, column: 7, scope: !4)
285 !24 = !MDLocation(line: 9, column: 3, scope: !4)
272 !11 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "X", scope: !4, file: !1, line: 2, type: !12)
273 !12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
274 !13 = !DIExpression()
275 !14 = !DILocation(line: 2, column: 9, scope: !4)
276 !15 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "Y", scope: !4, file: !1, line: 3, type: !12)
277 !16 = !DILocation(line: 3, column: 9, scope: !4)
278 !17 = !DILocalVariable(tag: DW_TAG_auto_variable, name: "Z", scope: !18, file: !1, line: 5, type: !12)
279 !18 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
280 !19 = !DILocation(line: 5, column: 11, scope: !18)
281 !20 = !DILocation(line: 6, column: 11, scope: !18)
282 !21 = !DILocation(line: 6, column: 9, scope: !18)
283 !22 = !DILocation(line: 8, column: 9, scope: !4)
284 !23 = !DILocation(line: 8, column: 7, scope: !4)
285 !24 = !DILocation(line: 9, column: 3, scope: !4)
286286
287287
288288 This example illustrates a few important details about LLVM debugging
302302
303303 .. code-block:: llvm
304304
305 !14 = !MDLocation(line: 2, column: 9, scope: !4)
306 !4 = !MDSubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5,
305 !14 = !DILocation(line: 2, column: 9, scope: !4)
306 !4 = !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5,
307307 isLocal: false, isDefinition: true, scopeLine: 1,
308308 isOptimized: false, function: void ()* @foo,
309309 variables: !2)
310310
311311 Here ``!14`` is metadata providing `location information
312 `_. In this example, scope is encoded by ``!4``, a
313 `subprogram descriptor `_. This way the location
312 `_. In this example, scope is encoded by ``!4``, a
313 `subprogram descriptor `_. This way the location
314314 information attached to the intrinsics indicates that the variable ``X`` is
315315 declared at line number 2 at a function level scope in function ``foo``.
316316
327327
328328 .. code-block:: llvm
329329
330 !18 = distinct !MDLexicalBlock(scope: !4, file: !1, line: 4, column: 5)
331 !19 = !MDLocation(line: 5, column: 11, scope: !18)
330 !18 = distinct !DILexicalBlock(scope: !4, file: !1, line: 4, column: 5)
331 !19 = !DILocation(line: 5, column: 11, scope: !18)
332332
333333 Here ``!19`` indicates that ``Z`` is declared at line number 5 and column
334334 number 0 inside of lexical scope ``!18``. The lexical scope itself resides
405405 !llvm.module.flags = !{!6, !7}
406406
407407 ;; Define the compile unit.
408 !0 = !MDCompileUnit(language: DW_LANG_C99, file: !1,
408 !0 = !DICompileUnit(language: DW_LANG_C99, file: !1,
409409 producer:
410410 "clang version 3.7.0 (trunk 231150) (llvm/trunk 231154)",
411411 isOptimized: false, runtimeVersion: 0, emissionKind: 1,
415415 ;;
416416 ;; Define the file
417417 ;;
418 !1 = !MDFile(filename: "/dev/stdin",
418 !1 = !DIFile(filename: "/dev/stdin",
419419 directory: "/Users/dexonsmith/data/llvm/debug-info")
420420
421421 ;; An empty array.
427427 ;;
428428 ;; Define the global variable itself.
429429 ;;
430 !4 = !MDGlobalVariable(name: "MyGlobal", scope: !0, file: !1, line: 1,
430 !4 = !DIGlobalVariable(name: "MyGlobal", scope: !0, file: !1, line: 1,
431431 type: !5, isLocal: false, isDefinition: true,
432432 variable: i32* @MyGlobal)
433433
434434 ;;
435435 ;; Define the type
436436 ;;
437 !5 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
437 !5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
438438
439439 ;; Dwarf version to output.
440440 !6 = !{i32 2, !"Dwarf Version", i32 2}
460460 ;;
461461 ;; Define the anchor for subprograms.
462462 ;;
463 !4 = !MDSubprogram(name: "main", scope: !1, file: !1, line: 1, type: !5,
463 !4 = !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !5,
464464 isLocal: false, isDefinition: true, scopeLine: 1,
465465 flags: DIFlagPrototyped, isOptimized: false,
466466 function: i32 (i32, i8**)* @main, variables: !2)
186186 static DIBuilder *DBuilder;
187187
188188 struct DebugInfo {
189 MDCompileUnit *TheCU;
190 MDType *DblTy;
191
192 MDType *getDoubleTy();
189 DICompileUnit *TheCU;
190 DIType *DblTy;
191
192 DIType *getDoubleTy();
193193 } KSDbgInfo;
194194
195 MDType *DebugInfo::getDoubleTy() {
195 DIType *DebugInfo::getDoubleTy() {
196196 if (DblTy.isValid())
197197 return DblTy;
198198
244244
245245 .. code-block:: c++
246246
247 MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
247 DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
248248 KSDbgInfo.TheCU.getDirectory());
249249
250 giving us an MDFile and asking the ``Compile Unit`` we created above for the
250 giving us an DIFile and asking the ``Compile Unit`` we created above for the
251251 directory and filename where we are currently. Then, for now, we use some
252252 source locations of 0 (since our AST doesn't currently have source location
253253 information) and construct our function definition:
254254
255255 .. code-block:: c++
256256
257 MDScope *FContext = Unit;
257 DIScope *FContext = Unit;
258258 unsigned LineNo = 0;
259259 unsigned ScopeLine = 0;
260 MDSubprogram *SP = DBuilder->createFunction(
260 DISubprogram *SP = DBuilder->createFunction(
261261 FContext, Name, StringRef(), Unit, LineNo,
262262 CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
263 true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
264
265 and we now have an MDSubprogram that contains a reference to all of our
263 true /* definition */, ScopeLine, DINode::FlagPrototyped, false, F);
264
265 and we now have an DISubprogram that contains a reference to all of our
266266 metadata for the function.
267267
268268 Source Locations
329329 .. code-block:: c++
330330
331331 void DebugInfo::emitLocation(ExprAST *AST) {
332 MDScope *Scope;
332 DIScope *Scope;
333333 if (LexicalBlocks.empty())
334334 Scope = TheCU;
335335 else
346346
347347 .. code-block:: c++
348348
349 std::vector LexicalBlocks;
350 std::map FnScopeMap;
349 std::vector LexicalBlocks;
350 std::map FnScopeMap;
351351
352352 and keep a map of each function to the scope that it represents (an
353 MDSubprogram is also an MDScope).
353 DISubprogram is also an DIScope).
354354
355355 Then we make sure to:
356356
391391
392392 .. code-block:: c++
393393
394 MDScope *Scope = KSDbgInfo.LexicalBlocks.back();
395 MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
394 DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
395 DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU.getFilename(),
396396 KSDbgInfo.TheCU.getDirectory());
397 MDLocalVariable D = DBuilder->createLocalVariable(
397 DILocalVariable D = DBuilder->createLocalVariable(
398398 dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
399399 KSDbgInfo.getDoubleTy(), Idx);
400400
9292 }
9393 static IRBuilder<> Builder(getGlobalContext());
9494 struct DebugInfo {
95 MDCompileUnit *TheCU;
96 MDType *DblTy;
97 std::vector LexicalBlocks;
98 std::map FnScopeMap;
95 DICompileUnit *TheCU;
96 DIType *DblTy;
97 std::vector LexicalBlocks;
98 std::map FnScopeMap;
9999
100100 void emitLocation(ExprAST *AST);
101 MDType *getDoubleTy();
101 DIType *getDoubleTy();
102102 } KSDbgInfo;
103103
104104 static std::string IdentifierStr; // Filled in if tok_identifier
815815
816816 static DIBuilder *DBuilder;
817817
818 MDType *DebugInfo::getDoubleTy() {
818 DIType *DebugInfo::getDoubleTy() {
819819 if (DblTy)
820820 return DblTy;
821821
826826 void DebugInfo::emitLocation(ExprAST *AST) {
827827 if (!AST)
828828 return Builder.SetCurrentDebugLocation(DebugLoc());
829 MDScope *Scope;
829 DIScope *Scope;
830830 if (LexicalBlocks.empty())
831831 Scope = TheCU;
832832 else
835835 DebugLoc::get(AST->getLine(), AST->getCol(), Scope));
836836 }
837837
838 static MDSubroutineType *CreateFunctionType(unsigned NumArgs, MDFile *Unit) {
838 static DISubroutineType *CreateFunctionType(unsigned NumArgs, DIFile *Unit) {
839839 SmallVector EltTys;
840 MDType *DblTy = KSDbgInfo.getDoubleTy();
840 DIType *DblTy = KSDbgInfo.getDoubleTy();
841841
842842 // Add the result type.
843843 EltTys.push_back(DblTy);
12261226 AI->setName(Args[Idx]);
12271227
12281228 // Create a subprogram DIE for this function.
1229 MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1229 DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
12301230 KSDbgInfo.TheCU->getDirectory());
1231 MDScope *FContext = Unit;
1231 DIScope *FContext = Unit;
12321232 unsigned LineNo = Line;
12331233 unsigned ScopeLine = Line;
1234 MDSubprogram *SP = DBuilder->createFunction(
1234 DISubprogram *SP = DBuilder->createFunction(
12351235 FContext, Name, StringRef(), Unit, LineNo,
12361236 CreateFunctionType(Args.size(), Unit), false /* internal linkage */,
1237 true /* definition */, ScopeLine, DebugNode::FlagPrototyped, false, F);
1237 true /* definition */, ScopeLine, DINode::FlagPrototyped, false, F);
12381238
12391239 KSDbgInfo.FnScopeMap[this] = SP;
12401240 return F;
12491249 AllocaInst *Alloca = CreateEntryBlockAlloca(F, Args[Idx]);
12501250
12511251 // Create a debug descriptor for the variable.
1252 MDScope *Scope = KSDbgInfo.LexicalBlocks.back();
1253 MDFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
1252 DIScope *Scope = KSDbgInfo.LexicalBlocks.back();
1253 DIFile *Unit = DBuilder->createFile(KSDbgInfo.TheCU->getFilename(),
12541254 KSDbgInfo.TheCU->getDirectory());
1255 MDLocalVariable *D = DBuilder->createLocalVariable(
1255 DILocalVariable *D = DBuilder->createLocalVariable(
12561256 dwarf::DW_TAG_arg_variable, Scope, Args[Idx], Unit, Line,
12571257 KSDbgInfo.getDoubleTy(), Idx);
12581258
4444 class LexicalScope {
4545
4646 public:
47 LexicalScope(LexicalScope *P, const MDLocalScope *D, const MDLocation *I,
47 LexicalScope(LexicalScope *P, const DILocalScope *D, const DILocation *I,
4848 bool A)
4949 : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A),
5050 LastInsn(nullptr), FirstInsn(nullptr), DFSIn(0), DFSOut(0) {
5757 // Accessors.
5858 LexicalScope *getParent() const { return Parent; }
5959 const MDNode *getDesc() const { return Desc; }
60 const MDLocation *getInlinedAt() const { return InlinedAtLocation; }
61 const MDLocalScope *getScopeNode() const { return Desc; }
60 const DILocation *getInlinedAt() const { return InlinedAtLocation; }
61 const DILocalScope *getScopeNode() const { return Desc; }
6262 bool isAbstractScope() const { return AbstractScope; }
6363 SmallVectorImpl &getChildren() { return Children; }
6464 SmallVectorImpl &getRanges() { return Ranges; }
118118
119119 private:
120120 LexicalScope *Parent; // Parent to this scope.
121 const MDLocalScope *Desc; // Debug info descriptor.
122 const MDLocation *InlinedAtLocation; // Location at which this
121 const DILocalScope *Desc; // Debug info descriptor.
122 const DILocation *InlinedAtLocation; // Location at which this
123123 // scope is inlined.
124124 bool AbstractScope; // Abstract Scope
125125 SmallVector Children; // Scopes defined in scope.
158158 /// getMachineBasicBlocks - Populate given set using machine basic blocks
159159 /// which have machine instructions that belong to lexical scope identified by
160160 /// DebugLoc.
161 void getMachineBasicBlocks(const MDLocation *DL,
161 void getMachineBasicBlocks(const DILocation *DL,
162162 SmallPtrSetImpl &MBBs);
163163
164164 /// dominates - Return true if DebugLoc's lexical scope dominates at least one
165165 /// machine instruction's lexical scope in a given machine basic block.
166 bool dominates(const MDLocation *DL, MachineBasicBlock *MBB);
166 bool dominates(const DILocation *DL, MachineBasicBlock *MBB);
167167
168168 /// findLexicalScope - Find lexical scope, either regular or inlined, for the
169169 /// given DebugLoc. Return NULL if not found.
170 LexicalScope *findLexicalScope(const MDLocation *DL);
170 LexicalScope *findLexicalScope(const DILocation *DL);
171171
172172 /// getAbstractScopesList - Return a reference to list of abstract scopes.
173173 ArrayRef getAbstractScopesList() const {
175175 }
176176
177177 /// findAbstractScope - Find an abstract scope or return null.
178 LexicalScope *findAbstractScope(const MDLocalScope *N) {
178 LexicalScope *findAbstractScope(const DILocalScope *N) {
179179 auto I = AbstractScopeMap.find(N);
180180 return I != AbstractScopeMap.end() ? &I->second : nullptr;
181181 }
182182
183183 /// findInlinedScope - Find an inlined scope for the given scope/inlined-at.
184 LexicalScope *findInlinedScope(const MDLocalScope *N, const MDLocation *IA) {
184 LexicalScope *findInlinedScope(const DILocalScope *N, const DILocation *IA) {
185185 auto I = InlinedLexicalScopeMap.find(std::make_pair(N, IA));
186186 return I != InlinedLexicalScopeMap.end() ? &I->second : nullptr;
187187 }
188188
189189 /// findLexicalScope - Find regular lexical scope or return null.
190 LexicalScope *findLexicalScope(const MDLocalScope *N) {
190 LexicalScope *findLexicalScope(const DILocalScope *N) {
191191 auto I = LexicalScopeMap.find(N);
192192 return I != LexicalScopeMap.end() ? &I->second : nullptr;
193193 }
196196 void dump();
197197
198198 /// getOrCreateAbstractScope - Find or create an abstract lexical scope.
199 LexicalScope *getOrCreateAbstractScope(const MDLocalScope *Scope);
199 LexicalScope *getOrCreateAbstractScope(const DILocalScope *Scope);
200200
201201 private:
202202 /// getOrCreateLexicalScope - Find lexical scope for the given Scope/IA. If
203203 /// not available then create new lexical scope.
204 LexicalScope *getOrCreateLexicalScope(const MDLocalScope *Scope,
205 const MDLocation *IA = nullptr);
206 LexicalScope *getOrCreateLexicalScope(const MDLocation *DL) {
204 LexicalScope *getOrCreateLexicalScope(const DILocalScope *Scope,
205 const DILocation *IA = nullptr);
206 LexicalScope *getOrCreateLexicalScope(const DILocation *DL) {
207207 return DL ? getOrCreateLexicalScope(DL->getScope(), DL->getInlinedAt())
208208 : nullptr;
209209 }
210210
211211 /// getOrCreateRegularScope - Find or create a regular lexical scope.
212 LexicalScope *getOrCreateRegularScope(const MDLocalScope *Scope);
212 LexicalScope *getOrCreateRegularScope(const DILocalScope *Scope);
213213
214214 /// getOrCreateInlinedScope - Find or create an inlined lexical scope.
215 LexicalScope *getOrCreateInlinedScope(const MDLocalScope *Scope,
216 const MDLocation *InlinedAt);
215 LexicalScope *getOrCreateInlinedScope(const DILocalScope *Scope,
216 const DILocation *InlinedAt);
217217
218218 /// extractLexicalScopes - Extract instruction ranges for each lexical scopes
219219 /// for the given machine function.
229229
230230 /// LexicalScopeMap - Tracks the scopes in the current function.
231231 // Use an unordered_map to ensure value pointer validity over insertion.
232 std::unordered_mapMDLocalScope *, LexicalScope> LexicalScopeMap;
232 std::unordered_mapDILocalScope *, LexicalScope> LexicalScopeMap;
233233
234234 /// InlinedLexicalScopeMap - Tracks inlined function scopes in current
235235 /// function.
236 std::unordered_mapMDLocalScope *, const MDLocation *>,
236 std::unordered_mapDILocalScope *, const DILocation *>,
237237 LexicalScope,
238 pair_hashMDLocalScope *, const MDLocation *>>
238 pair_hashDILocalScope *, const DILocation *>>
239239 InlinedLexicalScopeMap;
240240
241241 /// AbstractScopeMap - These scopes are not included LexicalScopeMap.
242242 // Use an unordered_map to ensure value pointer validity over insertion.
243 std::unordered_mapMDLocalScope *, LexicalScope> AbstractScopeMap;
243 std::unordered_mapDILocalScope *, LexicalScope> AbstractScopeMap;
244244
245245 /// AbstractScopesList - Tracks abstract scopes constructed while processing
246246 /// a function.
245245
246246 /// \brief Return the debug variable referenced by
247247 /// this DBG_VALUE instruction.
248 const MDLocalVariable *getDebugVariable() const {
248 const DILocalVariable *getDebugVariable() const {
249249 assert(isDebugValue() && "not a DBG_VALUE");
250 return cast<MDLocalVariable>(getOperand(2).getMetadata());
250 return cast<DILocalVariable>(getOperand(2).getMetadata());
251251 }
252252
253253 /// \brief Return the complex address expression referenced by
254254 /// this DBG_VALUE instruction.
255 const MDExpression *getDebugExpression() const {
255 const DIExpression *getDebugExpression() const {
256256 assert(isDebugValue() && "not a DBG_VALUE");
257 return cast<MDExpression>(getOperand(3).getMetadata());
257 return cast<DIExpression>(getOperand(3).getMetadata());
258258 }
259259
260260 /// emitError - Emit an error referring to the source location of this
355355 const MCInstrDesc &MCID, bool IsIndirect,
356356 unsigned Reg, unsigned Offset,
357357 const MDNode *Variable, const MDNode *Expr) {
358 assert(isa(Variable) && "not a variable");
359 assert(cast(Expr)->isValid() && "not an expression");
360 assert(cast(Variable)->isValidLocationForIntrinsic(DL) &&
358 assert(isa(Variable) && "not a variable");
359 assert(cast(Expr)->isValid() && "not an expression");
360 assert(cast(Variable)->isValidLocationForIntrinsic(DL) &&
361361 "Expected inlined-at fields to agree");
362362 if (IsIndirect)
363363 return BuildMI(MF, DL, MCID)
384384 const MCInstrDesc &MCID, bool IsIndirect,
385385 unsigned Reg, unsigned Offset,
386386 const MDNode *Variable, const MDNode *Expr) {
387 assert(isa(Variable) && "not a variable");
388 assert(cast(Expr)->isValid() && "not an expression");
387 assert(isa(Variable) && "not a variable");
388 assert(cast(Expr)->isValid() && "not an expression");
389389 MachineFunction &MF = *BB.getParent();
390390 MachineInstr *MI =
391391 BuildMI(MF, DL, MCID, IsIndirect, Reg, Offset, Variable, Expr);
192192 static char ID; // Pass identification, replacement for typeid
193193
194194 struct VariableDbgInfo {
195 const MDLocalVariable *Var;
196 const MDExpression *Expr;
195 const DILocalVariable *Var;
196 const DIExpression *Expr;
197197 unsigned Slot;
198 const MDLocation *Loc;
199
200 VariableDbgInfo(const MDLocalVariable *Var, const MDExpression *Expr,
201 unsigned Slot, const MDLocation *Loc)
198 const DILocation *Loc;
199
200 VariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
201 unsigned Slot, const DILocation *Loc)
202202 : Var(Var), Expr(Expr), Slot(Slot), Loc(Loc) {}
203203 };
204204 typedef SmallVector VariableDbgInfoMapTy;
447447
448448 /// setVariableDbgInfo - Collect information used to emit debugging
449449 /// information of a variable.
450 void setVariableDbgInfo(const MDLocalVariable *Var, const MDExpression *Expr,
451 unsigned Slot, const MDLocation *Loc) {
450 void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr,
451 unsigned Slot, const DILocation *Loc) {
452452 VariableDbgInfos.emplace_back(Var, Expr, Slot, Loc);
453453 }
454454
103103 /// source location information in the back end
104104 /// without actually changing the output (e.g.,
105105 /// when using optimization remarks).
106 MDCompileUnit *createCompileUnit(unsigned Lang, StringRef File,
106 DICompileUnit *createCompileUnit(unsigned Lang, StringRef File,
107107 StringRef Dir, StringRef Producer,
108108 bool isOptimized, StringRef Flags,
109109 unsigned RV, StringRef SplitName = "",
112112
113113 /// createFile - Create a file descriptor to hold debugging information
114114 /// for a file.
115 MDFile *createFile(StringRef Filename, StringRef Directory);
115 DIFile *createFile(StringRef Filename, StringRef Directory);
116116
117117 /// createEnumerator - Create a single enumerator value.
118 MDEnumerator *createEnumerator(StringRef Name, int64_t Val);
118 DIEnumerator *createEnumerator(StringRef Name, int64_t Val);
119119
120120 /// \brief Create a DWARF unspecified type.
121 MDBasicType *createUnspecifiedType(StringRef Name);
121 DIBasicType *createUnspecifiedType(StringRef Name);
122122
123123 /// \brief Create C++11 nullptr type.
124 MDBasicType *createNullPtrType();
124 DIBasicType *createNullPtrType();
125125
126126 /// createBasicType - Create debugging information entry for a basic
127127 /// type.
129129 /// @param SizeInBits Size of the type.
130130 /// @param AlignInBits Type alignment.
131131 /// @param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
132 MDBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
132 DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
133133 uint64_t AlignInBits, unsigned Encoding);
134134
135135 /// createQualifiedType - Create debugging information entry for a qualified
136136 /// type, e.g. 'const int'.
137137 /// @param Tag Tag identifing type, e.g. dwarf::TAG_volatile_type
138138 /// @param FromTy Base Type.
139 MDDerivedType *createQualifiedType(unsigned Tag, MDType *FromTy);
139 DIDerivedType *createQualifiedType(unsigned Tag, DIType *FromTy);
140140
141141 /// createPointerType - Create debugging information entry for a pointer.
142142 /// @param PointeeTy Type pointed by this pointer.
143143 /// @param SizeInBits Size.
144144 /// @param AlignInBits Alignment. (optional)
145145 /// @param Name Pointer type name. (optional)
146 MDDerivedType *createPointerType(MDType *PointeeTy, uint64_t SizeInBits,
146 DIDerivedType *createPointerType(DIType *PointeeTy, uint64_t SizeInBits,
147147 uint64_t AlignInBits = 0,
148148 StringRef Name = "");
149149
152152 /// @param SizeInBits Size.
153153 /// @param AlignInBits Alignment. (optional)
154154 /// @param Class Type for which this pointer points to members of.
155 MDDerivedType *createMemberPointerType(MDType *PointeeTy, MDType *Class,
155 DIDerivedType *createMemberPointerType(DIType *PointeeTy, DIType *Class,
156156 uint64_t SizeInBits,
157157 uint64_t AlignInBits = 0);
158158
159159 /// createReferenceType - Create debugging information entry for a c++
160160 /// style reference or rvalue reference type.
161 MDDerivedType *createReferenceType(unsigned Tag, MDType *RTy);
161 DIDerivedType *createReferenceType(unsigned Tag, DIType *RTy);
162162
163163 /// createTypedef - Create debugging information entry for a typedef.
164164 /// @param Ty Original type.
166166 /// @param File File where this type is defined.
167167 /// @param LineNo Line number.
168168 /// @param Context The surrounding context for the typedef.
169 MDDerivedType *createTypedef(MDType *Ty, StringRef Name, MDFile *File,
170 unsigned LineNo, MDScope *Context);
169 DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
170 unsigned LineNo, DIScope *Context);
171171
172172 /// createFriend - Create debugging information entry for a 'friend'.
173 MDDerivedType *createFriend(MDType *Ty, MDType *FriendTy);
173 DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
174174
175175 /// createInheritance - Create debugging information entry to establish
176176 /// inheritance relationship between two types.
179179 /// @param BaseOffset Base offset.
180180 /// @param Flags Flags to describe inheritance attribute,
181181 /// e.g. private
182 MDDerivedType *createInheritance(MDType *Ty, MDType *BaseTy,
182 DIDerivedType *createInheritance(DIType *Ty, DIType *BaseTy,
183183 uint64_t BaseOffset, unsigned Flags);
184184
185185 /// createMemberType - Create debugging information entry for a member.
192192 /// @param OffsetInBits Member offset.
193193 /// @param Flags Flags to encode member attribute, e.g. private
194194 /// @param Ty Parent type.
195 MDDerivedType *createMemberType(MDScope *Scope, StringRef Name,
196 MDFile *File, unsigned LineNo,
195 DIDerivedType *createMemberType(DIScope *Scope, StringRef Name,
196 DIFile *File, unsigned LineNo,
197197 uint64_t SizeInBits, uint64_t AlignInBits,
198198 uint64_t OffsetInBits, unsigned Flags,
199 MDType *Ty);
199 DIType *Ty);
200200
201201 /// createStaticMemberType - Create debugging information entry for a
202202 /// C++ static data member.
207207 /// @param Ty Type of the static member.
208208 /// @param Flags Flags to encode member attribute, e.g. private.
209209 /// @param Val Const initializer of the member.
210 MDDerivedType *createStaticMemberType(MDScope *Scope, StringRef Name,
211 MDFile *File, unsigned LineNo,
212 MDType *Ty, unsigned Flags,
210 DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
211 DIFile *File, unsigned LineNo,
212 DIType *Ty, unsigned Flags,
213213 llvm::Constant *Val);
214214
215215 /// createObjCIVar - Create debugging information entry for Objective-C
223223 /// @param Flags Flags to encode member attribute, e.g. private
224224 /// @param Ty Parent type.
225225 /// @param PropertyNode Property associated with this ivar.
226 MDDerivedType *createObjCIVar(StringRef Name, MDFile *File, unsigned LineNo,
226 DIDerivedType *createObjCIVar(StringRef Name, DIFile *File, unsigned LineNo,
227227 uint64_t SizeInBits, uint64_t AlignInBits,
228228 uint64_t OffsetInBits, unsigned Flags,
229 MDType *Ty, MDNode *PropertyNode);
229 DIType *Ty, MDNode *PropertyNode);
230230
231231 /// createObjCProperty - Create debugging information entry for Objective-C
232232 /// property.
237237 /// @param SetterName Name of the Objective C property setter selector.
238238 /// @param PropertyAttributes Objective C property attributes.
239239 /// @param Ty Type.
240 MDObjCProperty *createObjCProperty(StringRef Name, MDFile *File,
240 DIObjCProperty *createObjCProperty(StringRef Name, DIFile *File,
241241 unsigned LineNumber,
242242 StringRef GetterName,
243243 StringRef SetterName,
244 unsigned PropertyAttributes, MDType *Ty);
244 unsigned PropertyAttributes, DIType *Ty);
245245
246246 /// createClassType - Create debugging information entry for a class.
247247 /// @param Scope Scope in which this class is defined.
259259 /// for more info.
260260 /// @param TemplateParms Template type parameters.
261261 /// @param UniqueIdentifier A unique identifier for the class.
262 MDCompositeType *createClassType(
263 MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
264 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
265 unsigned Flags, MDType *DerivedFrom, DebugNodeArray Elements,
266 MDType *VTableHolder = nullptr, MDNode *TemplateParms = nullptr,
267 StringRef UniqueIdentifier = "");
262 DICompositeType *createClassType(DIScope *Scope, StringRef Name,
263 DIFile *File, unsigned LineNumber,
264 uint64_t SizeInBits, uint64_t AlignInBits,
265 uint64_t OffsetInBits, unsigned Flags,
266 DIType *DerivedFrom, DINodeArray Elements,
267 DIType *VTableHolder = nullptr,
268 MDNode *TemplateParms = nullptr,
269 StringRef UniqueIdentifier = "");
268270
269271 /// createStructType - Create debugging information entry for a struct.
270272 /// @param Scope Scope in which this struct is defined.
277279 /// @param Elements Struct elements.
278280 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
279281 /// @param UniqueIdentifier A unique identifier for the struct.
280 MDCompositeType *createStructType(
281 MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
282 DICompositeType *createStructType(
283 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
282284 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Flags,
283 MDType *DerivedFrom, DebugNodeArray Elements, unsigned RunTimeLang = 0,
284 MDType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
285 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang = 0,
286 DIType *VTableHolder = nullptr, StringRef UniqueIdentifier = "");
285287
286288 /// createUnionType - Create debugging information entry for an union.
287289 /// @param Scope Scope in which this union is defined.
294296 /// @param Elements Union elements.
295297 /// @param RunTimeLang Optional parameter, Objective-C runtime version.
296298 /// @param UniqueIdentifier A unique identifier for the union.
297 MDCompositeType *createUnionType(MDScope *Scope, StringRef Name,
298 MDFile *File, unsigned LineNumber,
299 DICompositeType *createUnionType(DIScope *Scope, StringRef Name,
300 DIFile *File, unsigned LineNumber,
299301 uint64_t SizeInBits, uint64_t AlignInBits,
300 unsigned Flags, DebugNodeArray Elements,
302 unsigned Flags, DINodeArray Elements,
301303 unsigned RunTimeLang = 0,
302304 StringRef UniqueIdentifier = "");
303305
306308 /// @param Scope Scope in which this type is defined.
307309 /// @param Name Type parameter name.
308310 /// @param Ty Parameter type.
309 MDTemplateTypeParameter *
310 createTemplateTypeParameter(MDScope *Scope, StringRef Name, MDType *Ty);
311 DITemplateTypeParameter *
312 createTemplateTypeParameter(DIScope *Scope, StringRef Name, DIType *Ty);
311313
312314 /// createTemplateValueParameter - Create debugging information for template
313315 /// value parameter.
315317 /// @param Name Value parameter name.
316318 /// @param Ty Parameter type.
317319 /// @param Val Constant parameter value.
318 MDTemplateValueParameter *createTemplateValueParameter(MDScope *Scope,
320 DITemplateValueParameter *createTemplateValueParameter(DIScope *Scope,
319321 StringRef Name,
320 MDType *Ty,
322 DIType *Ty,
321323 Constant *Val);
322324
323325 /// \brief Create debugging information for a template template parameter.
325327 /// @param Name Value parameter name.
326328 /// @param Ty Parameter type.
327329 /// @param Val The fully qualified name of the template.
328 MDTemplateValueParameter *createTemplateTemplateParameter(MDScope *Scope,
330 DITemplateValueParameter *createTemplateTemplateParameter(DIScope *Scope,
329331 StringRef Name,
330 MDType *Ty,
332 DIType *Ty,
331333 StringRef Val);
332334
333335 /// \brief Create debugging information for a template parameter pack.
335337 /// @param Name Value parameter name.
336338 /// @param Ty Parameter type.
337339 /// @param Val An array of types in the pack.
338 MDTemplateValueParameter *createTemplateParameterPack(MDScope *Scope,
340 DITemplateValueParameter *createTemplateParameterPack(DIScope *Scope,
339341 StringRef Name,
340 MDType *Ty,
341 DebugNodeArray Val);
342 DIType *Ty,
343 DINodeArray Val);
342344
343345 /// createArrayType - Create debugging information entry for an array.
344346 /// @param Size Array size.
345347 /// @param AlignInBits Alignment.
346348 /// @param Ty Element type.
347349 /// @param Subscripts Subscripts.
348 MDCompositeType *createArrayType(uint64_t Size, uint64_t AlignInBits,
349 MDType *Ty, DebugNodeArray Subscripts);
350 DICompositeType *createArrayType(uint64_t Size, uint64_t AlignInBits,
351 DIType *Ty, DINodeArray Subscripts);
350352
351353 /// createVectorType - Create debugging information entry for a vector type.
352354 /// @param Size Array size.
353355 /// @param AlignInBits Alignment.
354356 /// @param Ty Element type.
355357 /// @param Subscripts Subscripts.
356 MDCompositeType *createVectorType(uint64_t Size, uint64_t AlignInBits,
357 MDType *Ty, DebugNodeArray Subscripts);
358 DICompositeType *createVectorType(uint64_t Size, uint64_t AlignInBits,
359 DIType *Ty, DINodeArray Subscripts);
358360
359361 /// createEnumerationType - Create debugging information entry for an
360362 /// enumeration.
367369 /// @param Elements Enumeration elements.
368370 /// @param UnderlyingType Underlying type of a C++11/ObjC fixed enum.
369371 /// @param UniqueIdentifier A unique identifier for the enum.
370 MDCompositeType *createEnumerationType(
371 MDScope *Scope, StringRef Name, MDFile *File, unsigned LineNumber,
372 uint64_t SizeInBits, uint64_t AlignInBits, DebugNodeArray Elements,
373 MDType *UnderlyingType, StringRef UniqueIdentifier = "");
372 DICompositeType *createEnumerationType(
373 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
374 uint64_t SizeInBits, uint64_t AlignInBits, DINodeArray Elements,
375 DIType *UnderlyingType, StringRef UniqueIdentifier = "");
374376
375377 /// createSubroutineType - Create subroutine type.
376378 /// @param File File in which this subroutine is defined.
378380 /// includes return type at 0th index.
379381 /// @param Flags E.g.: LValueReference.
380382 /// These flags are used to emit dwarf attributes.
381 MDSubroutineType *createSubroutineType(MDFile *File,
382 MDTypeRefArray ParameterTypes,
383 DISubroutineType *createSubroutineType(DIFile *File,
384 DITypeRefArray ParameterTypes,
383385 unsigned Flags = 0);
384386
385 /// createArtificialType - Create a new MDType* with "artificial" flag set.
386 MDType *createArtificialType(MDType *Ty);
387
388 /// createObjectPointerType - Create a new MDType* with the "object pointer"
387 /// createArtificialType - Create a new DIType* with "artificial" flag set.
388 DIType *createArtificialType(DIType *Ty);
389
390 /// createObjectPointerType - Create a new DIType* with the "object pointer"
389391 /// flag set.
390 MDType *createObjectPointerType(MDType *Ty);
392 DIType *createObjectPointerType(DIType *Ty);
391393
392394 /// \brief Create a permanent forward-declared type.
393 MDCompositeType *createForwardDecl(unsigned Tag, StringRef Name,
394 MDScope *Scope, MDFile *F, unsigned Line,
395 DICompositeType *createForwardDecl(unsigned Tag, StringRef Name,
396 DIScope *Scope, DIFile *F, unsigned Line,
395397 unsigned RuntimeLang = 0,
396398 uint64_t SizeInBits = 0,
397399 uint64_t AlignInBits = 0,
398400 StringRef UniqueIdentifier = "");
399401
400402 /// \brief Create a temporary forward-declared type.
401 MDCompositeType *createReplaceableCompositeType(
402 unsigned Tag, StringRef Name, MDScope *Scope, MDFile *F, unsigned Line,
403 DICompositeType *createReplaceableCompositeType(
404 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line,
403405 unsigned RuntimeLang = 0, uint64_t SizeInBits = 0,
404 uint64_t AlignInBits = 0, unsigned Flags = DebugNode::FlagFwdDecl,
406 uint64_t AlignInBits = 0, unsigned Flags = DINode::FlagFwdDecl,
405407 StringRef UniqueIdentifier = "");
406408
407 /// retainType - Retain MDType* in a module even if it is not referenced
409 /// retainType - Retain DIType* in a module even if it is not referenced
408410 /// through debug info anchors.
409 void retainType(MDType *T);
411 void retainType(DIType *T);
410412
411413 /// createUnspecifiedParameter - Create unspecified parameter type
412414 /// for a subroutine type.
413 MDBasicType *createUnspecifiedParameter();
414
415 /// getOrCreateArray - Get a DebugNodeArray, create one if required.
416 DebugNodeArray getOrCreateArray(ArrayRef Elements);
417
418 /// getOrCreateTypeArray - Get a MDTypeRefArray, create one if required.
419 MDTypeRefArray getOrCreateTypeArray(ArrayRef Elements);
415 DIBasicType *createUnspecifiedParameter();
416
417 /// getOrCreateArray - Get a DINodeArray, create one if required.
418 DINodeArray getOrCreateArray(ArrayRef Elements);
419
420 /// getOrCreateTypeArray - Get a DITypeRefArray, create one if required.
421 DITypeRefArray getOrCreateTypeArray(ArrayRef Elements);
420422
421423 /// getOrCreateSubrange - Create a descriptor for a value range. This
422424 /// implicitly uniques the values returned.
423 MDSubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
425 DISubrange *getOrCreateSubrange(int64_t Lo, int64_t Count);
424426
425427 /// createGlobalVariable - Create a new descriptor for the specified
426428 /// variable.
434436 /// externally visible or not.
435437 /// @param Val llvm::Value of the variable.
436438 /// @param Decl Reference to the corresponding declaration.
437 MDGlobalVariable *createGlobalVariable(MDScope *Context, StringRef Name,
438 StringRef LinkageName, MDFile *File,
439 unsigned LineNo, MDType *Ty,
439 DIGlobalVariable *createGlobalVariable(DIScope *Context, StringRef Name,
440 StringRef LinkageName, DIFile *File,
441 unsigned LineNo, DIType *Ty,
440442 bool isLocalToUnit,
441443 llvm::Constant *Val,
442444 MDNode *Decl = nullptr);
443445
444446 /// createTempGlobalVariableFwdDecl - Identical to createGlobalVariable
445447 /// except that the resulting DbgNode is temporary and meant to be RAUWed.
446 MDGlobalVariable *createTempGlobalVariableFwdDecl(
447 MDScope *Context, StringRef Name, StringRef LinkageName, MDFile *File,
448 unsigned LineNo, MDType *Ty, bool isLocalToUnit, llvm::Constant *Val,
448 DIGlobalVariable *createTempGlobalVariableFwdDecl(
449 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
450 unsigned LineNo, DIType *Ty, bool isLocalToUnit, llvm::Constant *Val,
449451 MDNode *Decl = nullptr);
450452
451453 /// createLocalVariable - Create a new descriptor for the specified
462464 /// @param Flags Flags, e.g. artificial variable.
463465 /// @param ArgNo If this variable is an argument then this argument's
464466 /// number. 1 indicates 1st argument.
465 MDLocalVariable *createLocalVariable(unsigned Tag, MDScope *Scope,
466 StringRef Name, MDFile *File,
467 unsigned LineNo, MDType *Ty,
467 DILocalVariable *createLocalVariable(unsigned Tag, DIScope *Scope,
468 StringRef Name, DIFile *File,
469 unsigned LineNo, DIType *Ty,
468470 bool AlwaysPreserve = false,
469471 unsigned Flags = 0,
470472 unsigned ArgNo = 0);
472474 /// createExpression - Create a new descriptor for the specified
473475 /// variable which has a complex address expression for its address.
474476 /// @param Addr An array of complex address operations.
475 MDExpression *createExpression(ArrayRef Addr = None);
476 MDExpression *createExpression(ArrayRef Addr);
477 DIExpression *createExpression(ArrayRef Addr = None);
478 DIExpression *createExpression(ArrayRef Addr);
477479
478480 /// createBitPieceExpression - Create a descriptor to describe one part
479481 /// of aggregate variable that is fragmented across multiple Values.
480482 ///
481483 /// @param OffsetInBits Offset of the piece in bits.
482484 /// @param SizeInBits Size of the piece in bits.
483 MDExpression *createBitPieceExpression(unsigned OffsetInBits,
485 DIExpression *createBitPieceExpression(unsigned OffsetInBits,
484486 unsigned SizeInBits);
485487
486488 /// createFunction - Create a new descriptor for the specified subprogram.
487 /// See comments in MDSubprogram* for descriptions of these fields.
489 /// See comments in DISubprogram* for descriptions of these fields.
488490 /// @param Scope Function scope.
489491 /// @param Name Function name.
490492 /// @param LinkageName Mangled function name.
499501 /// @param isOptimized True if optimization is ON.
500502 /// @param Fn llvm::Function pointer.
501503 /// @param TParam Function template parameters.
502 MDSubprogram *
503 createFunction(MDScope *Scope, StringRef Name, StringRef LinkageName,
504 MDFile *File, unsigned LineNo, MDSubroutineType *Ty,
504 DISubprogram *
505 createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName,
506 DIFile *File, unsigned LineNo, DISubroutineType *Ty,
505507 bool isLocalToUnit, bool isDefinition, unsigned ScopeLine,
506508 unsigned Flags = 0, bool isOptimized = false,
507509 Function *Fn = nullptr, MDNode *TParam = nullptr,
509511
510512 /// createTempFunctionFwdDecl - Identical to createFunction,
511513 /// except that the resulting DbgNode is meant to be RAUWed.
512 MDSubprogram *createTempFunctionFwdDecl(
513 MDScope *Scope, StringRef Name, StringRef LinkageName, MDFile *File,
514 unsigned LineNo, MDSubroutineType *Ty, bool isLocalToUnit,
514 DISubprogram *createTempFunctionFwdDecl(
515 DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File,
516 unsigned LineNo, DISubroutineType *Ty, bool isLocalToUnit,
515517 bool isDefinition, unsigned ScopeLine, unsigned Flags = 0,
516518 bool isOptimized = false, Function *Fn = nullptr,
517519 MDNode *TParam = nullptr, MDNode *Decl = nullptr);
518520
519521 /// FIXME: this is added for dragonegg. Once we update dragonegg
520522 /// to call resolve function, this will be removed.
521 MDSubprogram *
522 createFunction(MDScopeRef Scope, StringRef Name, StringRef LinkageName,
523 MDFile *File, unsigned LineNo, MDSubroutineType *Ty,
523 DISubprogram *
524 createFunction(DIScopeRef Scope, StringRef Name, StringRef LinkageName,
525 DIFile *File, unsigned LineNo, DISubroutineType *Ty,
524526 bool isLocalToUnit, bool isDefinition, unsigned ScopeLine,
525527 unsigned Flags = 0, bool isOptimized = false,
526528 Function *Fn = nullptr, MDNode *TParam = nullptr,
527529 MDNode *Decl = nullptr);
528530
529531 /// createMethod - Create a new descriptor for the specified C++ method.
530 /// See comments in MDSubprogram* for descriptions of these fields.
532 /// See comments in DISubprogram* for descriptions of these fields.
531533 /// @param Scope Function scope.
532534 /// @param Name Function name.
533535 /// @param LinkageName Mangled function name.
545547 /// @param isOptimized True if optimization is ON.
546548 /// @param Fn llvm::Function pointer.
547549 /// @param TParam Function template parameters.
548 MDSubprogram *
549 createMethod(MDScope *Scope, StringRef Name, StringRef LinkageName,
550 MDFile *File, unsigned LineNo, MDSubroutineType *Ty,
550 DISubprogram *
551 createMethod(DIScope *Scope, StringRef Name, StringRef LinkageName,
552 DIFile *File, unsigned LineNo, DISubroutineType *Ty,
551553 bool isLocalToUnit, bool isDefinition, unsigned Virtuality = 0,
552 unsigned VTableIndex = 0, MDType *VTableHolder = nullptr,
554 unsigned VTableIndex = 0, DIType *VTableHolder = nullptr,
553555 unsigned Flags = 0, bool isOptimized = false,
554556 Function *Fn = nullptr, MDNode *TParam = nullptr);
555557
559561 /// @param Name Name of this namespace
560562 /// @param File Source file
561563 /// @param LineNo Line number
562 MDNamespace *createNameSpace(MDScope *Scope, StringRef Name, MDFile *File,
564 DINamespace *createNameSpace(DIScope *Scope, StringRef Name, DIFile *File,
563565 unsigned LineNo);
564566
565567 /// createLexicalBlockFile - This creates a descriptor for a lexical
568570 /// @param Scope Lexical block.
569571 /// @param File Source file.
570572 /// @param Discriminator DWARF path discriminator value.
571 MDLexicalBlockFile *createLexicalBlockFile(MDScope *Scope, MDFile *File,
573 DILexicalBlockFile *createLexicalBlockFile(DIScope *Scope, DIFile *File,
572574 unsigned Discriminator = 0);
573575
574576 /// createLexicalBlock - This creates a descriptor for a lexical block
577579 /// @param File Source file.
578580 /// @param Line Line number.
579581 /// @param Col Column number.
580 MDLexicalBlock *createLexicalBlock(MDScope *Scope, MDFile *File,
582 DILexicalBlock *createLexicalBlock(DIScope *Scope, DIFile *File,
581583 unsigned Line, unsigned Col);
582584
583585 /// \brief Create a descriptor for an imported module.
584586 /// @param Context The scope this module is imported into
585587 /// @param NS The namespace being imported here
586588 /// @param Line Line number
587 MDImportedEntity *createImportedModule(MDScope *Context, MDNamespace *NS,
589 DIImportedEntity *createImportedModule(DIScope *Context, DINamespace *NS,
588590 unsigned Line);
589591
590592 /// \brief Create a descriptor for an imported module.
591593 /// @param Context The scope this module is imported into
592594 /// @param NS An aliased namespace
593595 /// @param Line Line number
594 MDImportedEntity *createImportedModule(MDScope *Context,
595 MDImportedEntity *NS, unsigned Line);
596 DIImportedEntity *createImportedModule(DIScope *Context,
597 DIImportedEntity *NS, unsigned Line);
596598
597599 /// \brief Create a descriptor for an imported function.
598600 /// @param Context The scope this module is imported into
599601 /// @param Decl The declaration (or definition) of a function, type, or
600602 /// variable
601603 /// @param Line Line number
602 MDImportedEntity *createImportedDeclaration(MDScope *Context,
603 DebugNode *Decl, unsigned Line,
604 DIImportedEntity *createImportedDeclaration(DIScope *Context, DINode *Decl,
605 unsigned Line,
604606 StringRef Name = "");
605607
606608 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
609611 /// @param Expr A complex location expression.
610612 /// @param DL Debug info location.
611613 /// @param InsertAtEnd Location for the new intrinsic.
612 Instruction *insertDeclare(llvm::Value *Storage, MDLocalVariable *VarInfo,
613 MDExpression *Expr, const MDLocation *DL,
614 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
615 DIExpression *Expr, const DILocation *DL,
614616 BasicBlock *InsertAtEnd);
615617
616618 /// insertDeclare - Insert a new llvm.dbg.declare intrinsic call.
619621 /// @param Expr A complex location expression.
620622 /// @param DL Debug info location.
621623 /// @param InsertBefore Location for the new intrinsic.
622 Instruction *insertDeclare(llvm::Value *Storage, MDLocalVariable *VarInfo,
623 MDExpression *Expr, const MDLocation *DL,
624 Instruction *insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo,
625 DIExpression *Expr, const DILocation *DL,
624626 Instruction *InsertBefore);
625627
626628 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
631633 /// @param DL Debug info location.
632634 /// @param InsertAtEnd Location for the new intrinsic.
633635 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
634 MDLocalVariable *VarInfo,
635 MDExpression *Expr,
636 const MDLocation *DL,
636 DILocalVariable *VarInfo,
637 DIExpression *Expr,
638 const DILocation *DL,
637639 BasicBlock *InsertAtEnd);
638640
639641 /// insertDbgValueIntrinsic - Insert a new llvm.dbg.value intrinsic call.
644646 /// @param DL Debug info location.
645647 /// @param InsertBefore Location for the new intrinsic.
646648 Instruction *insertDbgValueIntrinsic(llvm::Value *Val, uint64_t Offset,
647 MDLocalVariable *VarInfo,
648 MDExpression *Expr,
649 const MDLocation *DL,
649 DILocalVariable *VarInfo,
650 DIExpression *Expr,
651 const DILocation *DL,
650652 Instruction *InsertBefore);
651653
652654 /// \brief Replace the vtable holder in the given composite type.
653655 ///
654656 /// If this creates a self reference, it may orphan some unresolved cycles
655657 /// in the operands of \c T, so \a DIBuilder needs to track that.
656 void replaceVTableHolder(MDCompositeType *&T,
657 MDCompositeType *VTableHolder);
658 void replaceVTableHolder(DICompositeType *&T,
659 DICompositeType *VTableHolder);
658660
659661 /// \brief Replace arrays on a composite type.
660662 ///
661663 /// If \c T is resolved, but the arrays aren't -- which can happen if \c T
662664 /// has a self-reference -- \a DIBuilder needs to track the array to
663665 /// resolve cycles.
664 void replaceArrays(MDCompositeType *&T, DebugNodeArray Elements,
665 DebugNodeArray TParems = DebugNodeArray());
666 void replaceArrays(DICompositeType *&T, DINodeArray Elements,
667 DINodeArray TParems = DINodeArray());
666668
667669 /// \brief Replace a temporary node.
668670 ///
3333 class DbgValueInst;
3434
3535 /// \brief Maps from type identifier to the actual MDNode.
36 typedef DenseMapMDType *> DITypeIdentifierMap;
36 typedef DenseMapDIType *> DITypeIdentifierMap;
3737
3838 /// \brief Find subprogram that is enclosing this scope.
39 MDSubprogram *getDISubprogram(const MDNode *Scope);
39 DISubprogram *getDISubprogram(const MDNode *Scope);
4040
4141 /// \brief Find debug info for a given function.
4242 ///
4343 /// \returns a valid subprogram, if found. Otherwise, return \c nullptr.
44 MDSubprogram *getDISubprogram(const Function *F);
44 DISubprogram *getDISubprogram(const Function *F);
4545
4646 /// \brief Find underlying composite type.
47 MDCompositeTypeBase *getDICompositeType(MDType *T);
47 DICompositeTypeBase *getDICompositeType(DIType *T);
4848
4949 /// \brief Generate map by visiting all retained types.
5050 DITypeIdentifierMap generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes);
8080 /// \brief Process DbgValueInst.
8181 void processValue(const Module &M, const DbgValueInst *DVI);
8282 /// \brief Process debug info location.
83 void processLocation(const Module &M, const MDLocation *Loc);
83 void processLocation(const Module &M, const DILocation *Loc);
8484
8585 /// \brief Clear all lists.
8686 void reset();
8888 private:
8989 void InitializeTypeMap(const Module &M);
9090
91 void processType(MDType *DT);
92 void processSubprogram(MDSubprogram *SP);
93 void processScope(MDScope *Scope);
94 bool addCompileUnit(MDCompileUnit *CU);
95 bool addGlobalVariable(MDGlobalVariable *DIG);
96 bool addSubprogram(MDSubprogram *SP);
97 bool addType(MDType *DT);
98 bool addScope(MDScope *Scope);
91 void processType(DIType *DT);
92 void processSubprogram(DISubprogram *SP);
93 void processScope(DIScope *Scope);
94 bool addCompileUnit(DICompileUnit *CU);
95 bool addGlobalVariable(DIGlobalVariable *DIG);
96 bool addSubprogram(DISubprogram *SP);
97 bool addType(DIType *DT);
98 bool addScope(DIScope *Scope);
9999
100100 public:
101 typedef SmallVectorImpl<MDCompileUnit *>::const_iterator
101 typedef SmallVectorImpl<DICompileUnit *>::const_iterator
102102 compile_unit_iterator;
103 typedef SmallVectorImpl::const_iterator subprogram_iterator;
104 typedef SmallVectorImpl<MDGlobalVariable *>::const_iterator
103 typedef SmallVectorImpl<DISubprogram *>::const_iterator subprogram_iterator;
104 typedef SmallVectorImpl::const_iterator
105105 global_variable_iterator;
106 typedef SmallVectorImpl::const_iterator type_iterator;
107 typedef SmallVectorImpl<MDScope *>::const_iterator scope_iterator;
106 typedef SmallVectorImpl<DIType *>::const_iterator type_iterator;
107 typedef SmallVectorImpl::const_iterator scope_iterator;
108108
109109 iterator_range compile_units() const {
110110 return iterator_range(CUs.begin(), CUs.end());
133133 unsigned scope_count() const { return Scopes.size(); }
134134
135135 private:
136 SmallVector CUs;
137 SmallVector SPs;
138 SmallVector GVs;
139 SmallVector TYs;
140 SmallVector<MDScope *, 8> Scopes;
136 SmallVector<DICompileUnit *, 8> CUs;
137 SmallVector SPs;
138 SmallVector GVs;
139 SmallVector TYs;
140 SmallVector Scopes;
141141 SmallPtrSet NodesSeen;
142142 DITypeIdentifierMap TypeIdentifierMap;
143143
145145 bool TypeMapInitialized;
146146 };
147147
148 DenseMapMDSubprogram *> makeSubprogramMap(const Module &M);
148 DenseMapDISubprogram *> makeSubprogramMap(const Module &M);
149149
150150 } // end namespace llvm
151151
<
4040
4141 namespace llvm {
4242
43 /// \brief Pointer union between a subclass of DebugNode and MDString.
44 ///
45 /// \a MDCompositeType can be referenced via an \a MDString unique identifier.
43 /// \brief Pointer union between a subclass of DINode and MDString.
44 ///
45 /// \a DICompositeType can be referenced via an \a MDString unique identifier.
4646 /// This class allows some type safety in the face of that, requiring either a
4747 /// node of a particular type or an \a MDString.
48 template class TypedDebugNodeRef {
48 template class TypedDINodeRef {
4949 const Metadata *MD = nullptr;
5050
5151 public:
52 TypedDebugNodeRef() = default;
53 TypedDebugNodeRef(std::nullptr_t) {}
52 TypedDINodeRef() = default;
53 TypedDINodeRef(std::nullptr_t) {}
5454
5555 /// \brief Construct from a raw pointer.
56 explicit TypedDebugNodeRef(const Metadata *MD) : MD(MD) {
56 explicit TypedDINodeRef(const Metadata *MD) : MD(MD) {
5757 assert((!MD || isa(MD) || isa(MD)) && "Expected valid ref");
5858 }
5959
6060 template
61 TypedDebugNodeRef(
62 const TypedDebugNodeRef &X,
61 TypedDINodeRef(
62 const TypedDINodeRef &X,
6363 typename std::enable_if::value>::type * =
6464 nullptr)
6565 : MD(X) {}
6666
6767 operator Metadata *() const { return const_cast(MD); }
6868
69 bool operator==(const TypedDebugNodeRef &X) const { return MD == X.MD; };
70 bool operator!=(const TypedDebugNodeRef &X) const { return MD != X.MD; };
69 bool operator==(const TypedDINodeRef &X) const { return MD == X.MD; };
70 bool operator!=(const TypedDINodeRef &X) const { return MD != X.MD; };
7171
7272 /// \brief Create a reference.
7373 ///
7474 /// Get a reference to \c N, using an \a MDString reference if available.
75 static TypedDebugNodeRef get(const T *N);
75 static TypedDINodeRef get(const T *N);
7676
7777 template T *resolve(const MapTy &Map) const {
7878 if (!MD)
8888 }
8989 };
9090
91 typedef TypedDebugNodeRef DebugNodeRef;
92 typedef TypedDebugNodeRef MDScopeRef;
93 typedef TypedDebugNodeRef MDTypeRef;
94
95 class MDTypeRefArray {
91 typedef TypedDINodeRef DINodeRef;
92 typedef TypedDINodeRef DIScopeRef;
93 typedef TypedDINodeRef DITypeRef;
94
95 class DITypeRefArray {
9696 const MDTuple *N = nullptr;
9797
9898 public:
99 MDTypeRefArray(const MDTuple *N) : N(N) {}
99 DITypeRefArray(const MDTuple *N) : N(N) {}
100100
101101 explicit operator bool() const { return get(); }
102102 explicit operator MDTuple *() const { return get(); }
107107
108108 // FIXME: Fix callers and remove condition on N.
109109 unsigned size() const { return N ? N->getNumOperands() : 0u; }
110 MDTypeRef operator[](unsigned I) const { return MDTypeRef(N->getOperand(I)); }
111
112 class iterator : std::iterator
113 std::ptrdiff_t, void, MDTypeRef> {
110 DITypeRef operator[](unsigned I) const { return DITypeRef(N->getOperand(I)); }
111
112 class iterator : std::iterator
113 std::ptrdiff_t, void, DITypeRef> {
114114 MDNode::op_iterator I = nullptr;
115115
116116 public:
117117 iterator() = default;
118118 explicit iterator(MDNode::op_iterator I) : I(I) {}
119 MDTypeRef operator*() const { return MDTypeRef(*I); }
119 DITypeRef operator*() const { return DITypeRef(*I); }
120120 iterator &operator++() {
121121 ++I;
122122 return *this;
138138 /// \brief Tagged DWARF-like metadata node.
139139 ///
140140 /// A metadata node with a DWARF tag (i.e., a constant named \c DW_TAG_*,
141 /// defined in llvm/Support/Dwarf.h). Called \a DebugNode because it's
141 /// defined in llvm/Support/Dwarf.h). Called \a DINode because it's
142142 /// potentially used for non-DWARF output.
143 class DebugNode : public MDNode {
143 class DINode : public MDNode {
144144 friend class LLVMContextImpl;
145145 friend class MDNode;
146146
147147 protected:
148 DebugNode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
149 ArrayRef Ops1, ArrayRef Ops2 = None)
148 DINode(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
149 ArrayRef Ops1, ArrayRef Ops2 = None)
150150 : MDNode(C, ID, Storage, Ops1, Ops2) {
151151 assert(Tag < 1u << 16);
152152 SubclassData16 = Tag;
153153 }
154 ~DebugNode() = default;
154 ~DINode() = default;
155155
156156 template Ty *getOperandAs(unsigned I) const {
157157 return cast_or_null(getOperand(I));
192192 static unsigned splitFlags(unsigned Flags,
193193 SmallVectorImpl &SplitFlags);
194194
195 DebugNodeRef getRef() const { return DebugNodeRef::get(this); }
195 DINodeRef getRef() const { return DINodeRef::get(this); }
196196
197197 static bool classof(const Metadata *MD) {
198198 switch (MD->getMetadataID()) {
199199 default:
200200 return false;
201 case GenericDebugNodeKind:
202 case MDSubrangeKind:
203 case MDEnumeratorKind:
204 case MDBasicTypeKind:
205 case MDDerivedTypeKind:
206 case MDCompositeTypeKind:
207 case MDSubroutineTypeKind:
208 case MDFileKind:
209 case MDCompileUnitKind:
210 case MDSubprogramKind:
211 case MDLexicalBlockKind:
212 case MDLexicalBlockFileKind:
213 case MDNamespaceKind:
214 case MDTemplateTypeParameterKind:
215 case MDTemplateValueParameterKind:
216 case MDGlobalVariableKind:
217 case MDLocalVariableKind:
218 case MDObjCPropertyKind:
219 case MDImportedEntityKind:
201 case GenericDINodeKind:
202 case DISubrangeKind:
203 case DIEnumeratorKind:
204 case DIBasicTypeKind:
205 case DIDerivedTypeKind:
206 case DICompositeTypeKind:
207 case DISubroutineTypeKind:
208 case DIFileKind:
209 case DICompileUnitKind:
210 case DISubprogramKind:
211 case DILexicalBlockKind:
212 case DILexicalBlockFileKind:
213 case DINamespaceKind:
214 case DITemplateTypeParameterKind:
215 case DITemplateValueParameterKind:
216 case DIGlobalVariableKind:
217 case DILocalVariableKind:
218 case DIObjCPropertyKind:
219 case DIImportedEntityKind:
220220 return true;
221221 }
222222 }
223223 };
224224
225 template struct simplify_type> {
226 typedef Metadata *SimpleType;
227 static SimpleType getSimplifiedValue(const TypedDINodeRef &MD) {
228 return MD;
229 }
230 };
231
225232 template
226 struct simplify_type> {
227 typedef Metadata *SimpleType;
228 static SimpleType getSimplifiedValue(const TypedDebugNodeRef &MD) {
229 return MD;
230 }
231 };
232
233 template
234 struct simplify_type>
235 : simplify_type> {};
233 struct simplify_type>
234 : simplify_type> {};
236235
237236 /// \brief Generic tagged DWARF-like metadata node.
238237 ///
240239 /// (possibly empty) null-separated \a MDString header that contains arbitrary
241240 /// fields. The remaining operands are \a dwarf_operands(), and are pointers
242241 /// to other metadata.
243 class GenericDebugNode : public DebugNode {
242 class GenericDINode : public DINode {
244243 friend class LLVMContextImpl;
245244 friend class MDNode;
246245
247 GenericDebugNode(LLVMContext &C, StorageType Storage, unsigned Hash,
248 unsigned Tag, ArrayRef Ops1,
249 ArrayRef Ops2)
250 : DebugNode(C, GenericDebugNodeKind, Storage, Tag, Ops1, Ops2) {
246 GenericDINode(LLVMContext &C, StorageType Storage, unsigned Hash,
247 unsigned Tag, ArrayRef Ops1,
248 ArrayRef Ops2)
249 : DINode(C, GenericDINodeKind, Storage, Tag, Ops1, Ops2) {
251250 setHash(Hash);
252251 }
253 ~GenericDebugNode() { dropAllReferences(); }
252 ~GenericDINode() { dropAllReferences(); }
254253
255254 void setHash(unsigned Hash) { SubclassData32 = Hash; }
256255 void recalculateHash();
257256
258 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
259 StringRef Header,
260 ArrayRef DwarfOps,
261 StorageType Storage,
262 bool ShouldCreate = true) {
257 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
258 StringRef Header, ArrayRef DwarfOps,
259 StorageType Storage, bool ShouldCreate = true) {
263260 return getImpl(Context, Tag, getCanonicalMDString(Context, Header),
264261 DwarfOps, Storage, ShouldCreate);
265262 }
266263
267 static GenericDebugNode *getImpl(LLVMContext &Context, unsigned Tag,
268 MDString *Header,
269 ArrayRef DwarfOps,
270 StorageType Storage,
271 bool ShouldCreate = true);
272
273 TempGenericDebugNode cloneImpl() const {
264 static GenericDINode *getImpl(LLVMContext &Context, unsigned Tag,
265 MDString *Header, ArrayRef DwarfOps,
266 StorageType Storage, bool ShouldCreate = true);
267
268 TempGenericDINode cloneImpl() const {
274269 return getTemporary(
275270 getContext(), getTag(), getHeader(),
276271 SmallVector(dwarf_op_begin(), dwarf_op_end()));
279274 public:
280275 unsigned getHash() const { return SubclassData32; }
281276
282 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, StringRef Header,
283 ArrayRef DwarfOps),
277 DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, StringRef Header,
278 ArrayRef DwarfOps),
284279 (Tag, Header, DwarfOps))
285 DEFINE_MDNODE_GET(GenericDebugNode, (unsigned Tag, MDString *Header,
286 ArrayRef DwarfOps),
280 DEFINE_MDNODE_GET(GenericDINode, (unsigned Tag, MDString *Header,
281 ArrayRef DwarfOps),
287282 (Tag, Header, DwarfOps))
288283
289284 /// \brief Return a (temporary) clone of this.
290 TempGenericDebugNode clone() const { return cloneImpl(); }
285 TempGenericDINode clone() const { return cloneImpl(); }
291286
292287 unsigned getTag() const { return SubclassData16; }
293288 StringRef getHeader() const { return getStringOperand(0); }
307302 }
308303
309304 static bool classof(const Metadata *MD) {
310 return MD->getMetadataID() == GenericDebugNodeKind;
305 return MD->getMetadataID() == GenericDINodeKind;
311306 }
312307 };
313308
315310 ///
316311 /// TODO: Merge into node for DW_TAG_array_type, which should have a custom
317312 /// type.
318 class MDSubrange : public DebugNode {
313 class DISubrange : public DINode {
319314 friend class LLVMContextImpl;
320315 friend class MDNode;
321316
322317 int64_t Count;
323318 int64_t LowerBound;
324319
325 MDSubrange(LLVMContext &C, StorageType Storage, int64_t Count,
320 DISubrange(LLVMContext &C, StorageType Storage, int64_t Count,
326321 int64_t LowerBound)
327 : DebugNode(C, MDSubrangeKind, Storage, dwarf::DW_TAG_subrange_type,
328 None),
322 : DINode(C, DISubrangeKind, Storage, dwarf::DW_TAG_subrange_type, None),
329323 Count(Count), LowerBound(LowerBound) {}
330 ~MDSubrange() = default;
331
332 static MDSubrange *getImpl(LLVMContext &Context, int64_t Count,
324 ~DISubrange() = default;
325
326 static DISubrange *getImpl(LLVMContext &Context, int64_t Count,
333327 int64_t LowerBound, StorageType Storage,
334328 bool ShouldCreate = true);
335329
336 TempMDSubrange cloneImpl() const {
330 TempDISubrange cloneImpl() const {
337331 return getTemporary(getContext(), getCount(), getLowerBound());
338332 }
339333
340334 public:
341 DEFINE_MDNODE_GET(MDSubrange, (int64_t Count, int64_t LowerBound = 0),
335 DEFINE_MDNODE_GET(DISubrange, (int64_t Count, int64_t LowerBound = 0),
342336 (Count, LowerBound))
343337
344 TempMDSubrange clone() const { return cloneImpl(); }
338 TempDISubrange clone() const { return cloneImpl(); }
345339
346340 int64_t getLowerBound() const { return LowerBound; }
347341 int64_t getCount() const { return Count; }
348342
349343 static bool classof(const Metadata *MD) {
350 return MD->getMetadataID() == MDSubrangeKind;
344 return MD->getMetadataID() == DISubrangeKind;
351345 }
352346 };
353347
355349 ///
356350 /// TODO: Add a pointer to the context (DW_TAG_enumeration_type) once that no
357351 /// longer creates a type cycle.
358 class MDEnumerator : public DebugNode {
352 class DIEnumerator : public DINode {
359353 friend class LLVMContextImpl;
360354 friend class MDNode;
361355
362356 int64_t Value;
363357
364 MDEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
358 DIEnumerator(LLVMContext &C, StorageType Storage, int64_t Value,
365359 ArrayRef Ops)
366 : DebugNode(C, MDEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
360 : DINode(C, DIEnumeratorKind, Storage, dwarf::DW_TAG_enumerator, Ops),
367361 Value(Value) {}
368 ~MDEnumerator() = default;
369
370 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
362 ~DIEnumerator() = default;
363
364 static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
371365 StringRef Name, StorageType Storage,
372366 bool ShouldCreate = true) {
373367 return getImpl(Context, Value, getCanonicalMDString(Context, Name), Storage,
374368 ShouldCreate);
375369 }
376 static MDEnumerator *getImpl(LLVMContext &Context, int64_t Value,
370 static DIEnumerator *getImpl(LLVMContext &Context, int64_t Value,
377371 MDString *Name, StorageType Storage,
378372 bool ShouldCreate = true);
379373
380 TempMDEnumerator cloneImpl() const {
374 TempDIEnumerator cloneImpl() const {
381375 return getTemporary(getContext(), getValue(), getName());
382376 }
383377
384378 public:
385 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, StringRef Name),
379 DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, StringRef Name),
386380 (Value, Name))
387 DEFINE_MDNODE_GET(MDEnumerator, (int64_t Value, MDString *Name),
381 DEFINE_MDNODE_GET(DIEnumerator, (int64_t Value, MDString *Name),
388382 (Value, Name))
389383
390 TempMDEnumerator clone() const { return cloneImpl(); }
384 TempDIEnumerator clone() const { return cloneImpl(); }
391385
392386 int64_t getValue() const { return Value; }
393387 StringRef getName() const { return getStringOperand(0); }
395389 MDString *getRawName() const { return getOperandAs(0); }
396390
397391 static bool classof(const Metadata *MD) {
398 return MD->getMetadataID() == MDEnumeratorKind;
392 return MD->getMetadataID() == DIEnumeratorKind;
399393 }
400394 };
401395
405399 /// contexts).
406400 ///
407401 /// TODO: Separate the concepts of declaration contexts and lexical scopes.
408 class MDScope : public DebugNode {
402 class DIScope : public DINode {
409403 protected:
410 MDScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
404 DIScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
411405 ArrayRef Ops)
412 : DebugNode(C, ID, Storage, Tag, Ops) {}
413 ~MDScope() = default;
414
415 public:
416 MDFile *getFile() const { return cast_or_null(getRawFile()); }
406 : DINode(C, ID, Storage, Tag, Ops) {}
407 ~DIScope() = default;
408
409 public:
410 DIFile *getFile() const { return cast_or_null(getRawFile()); }
417411
418412 inline StringRef getFilename() const;
419413 inline StringRef getDirectory() const;
420414
421415 StringRef getName() const;
422 MDScopeRef getScope() const;
416 DIScopeRef getScope() const;
423417
424418 /// \brief Return the raw underlying file.
425419 ///
426 /// An \a MDFile is an \a MDScope, but it doesn't point at a separate file
427 /// (it\em is the file). If \c this is an \a MDFile, we need to return \c
420 /// An \a DIFile is an \a DIScope, but it doesn't point at a separate file
421 /// (it\em is the file). If \c this is an \a DIFile, we need to return \c
428422 /// this. Otherwise, return the first operand, which is where all other
429423 /// subclasses store their file pointer.
430424 Metadata *getRawFile() const {
431 return isa<MDFile>(this) ? const_castScope *>(this)
425 return isa<DIFile>(this) ? const_castScope *>(this)
432426 : static_cast(getOperand(0));
433427 }
434428
435 MDScopeRef getRef() const { return MDScopeRef::get(this); }
429 DIScopeRef getRef() const { return DIScopeRef::get(this); }
436430
437431 static bool classof(const Metadata *MD) {
438432 switch (MD->getMetadataID()) {
439433 default:
440434 return false;
441 case MDBasicTypeKind:
442 case MDDerivedTypeKind:
443 case MDCompositeTypeKind:
444 case MDSubroutineTypeKind:
445 case MDFileKind:
446 case MDCompileUnitKind:
447 case MDSubprogramKind:
448 case MDLexicalBlockKind:
449 case MDLexicalBlockFileKind:
450 case MDNamespaceKind:
435 case DIBasicTypeKind:
436 case DIDerivedTypeKind:
437 case DICompositeTypeKind:
438 case DISubroutineTypeKind:
439 case DIFileKind:
440 case DICompileUnitKind:
441 case DISubprogramKind:
442 case DILexicalBlockKind:
443 case DILexicalBlockFileKind:
444 case DINamespaceKind:
451445 return true;
452446 }
453447 }
457451 ///
458452 /// TODO: Merge with directory/file node (including users).
459453 /// TODO: Canonicalize paths on creation.
460 class MDFile : public MDScope {
454 class DIFile : public DIScope {
461455 friend class LLVMContextImpl;
462456 friend class MDNode;
463457
464 MDFile(LLVMContext &C, StorageType Storage, ArrayRef Ops)
465 : MDScope(C, MDFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
466 ~MDFile() = default;
467
468 static MDFile *getImpl(LLVMContext &Context, StringRef Filename,
458 DIFile(LLVMContext &C, StorageType Storage, ArrayRef Ops)
459 : DIScope(C, DIFileKind, Storage, dwarf::DW_TAG_file_type, Ops) {}
460 ~DIFile() = default;
461
462 static DIFile *getImpl(LLVMContext &Context, StringRef Filename,
469463 StringRef Directory, StorageType Storage,
470464 bool ShouldCreate = true) {
471465 return getImpl(Context, getCanonicalMDString(Context, Filename),
472466 getCanonicalMDString(Context, Directory), Storage,
473467 ShouldCreate);
474468 }
475 static MDFile *getImpl(LLVMContext &Context, MDString *Filename,
469 static DIFile *getImpl(LLVMContext &Context, MDString *Filename,
476470 MDString *Directory, StorageType Storage,
477471 bool ShouldCreate = true);
478472
479 TempMDFile cloneImpl() const {
473 TempDIFile cloneImpl() const {
480474 return getTemporary(getContext(), getFilename(), getDirectory());
481475 }
482476
483477 public:
484 DEFINE_MDNODE_GET(MDFile, (StringRef Filename, StringRef Directory),
478 DEFINE_MDNODE_GET(DIFile, (StringRef Filename, StringRef Directory),
485479 (Filename, Directory))
486 DEFINE_MDNODE_GET(MDFile, (MDString * Filename, MDString *Directory),
480 DEFINE_MDNODE_GET(DIFile, (MDString * Filename, MDString *Directory),
487481 (Filename, Directory))
488482
489 TempMDFile clone() const { return cloneImpl(); }
483 TempDIFile clone() const { return cloneImpl(); }
490484
491485 StringRef getFilename() const { return getStringOperand(0); }
492486 StringRef getDirectory() const { return getStringOperand(1); }
495489 MDString *getRawDirectory() const { return getOperandAs(1); }
496490
497491 static bool classof(const Metadata *MD) {
498 return MD->getMetadataID() == MDFileKind;
499 }
500 };
501
502 StringRef MDScope::getFilename() const {
492 return MD->getMetadataID() == DIFileKind;
493 }
494 };
495
496 StringRef DIScope::getFilename() const {
503497 if (auto *F = getFile())
504498 return F->getFilename();
505499 return "";
506500 }
507501
508 StringRef MDScope::getDirectory() const {
502 StringRef DIScope::getDirectory() const {
509503 if (auto *F = getFile())
510504 return F->getDirectory();
511505 return "";
516510 /// TODO: Remove the hardcoded name and context, since many types don't use
517511 /// them.
518512 /// TODO: Split up flags.
519 class MDType : public MDScope {
513 class DIType : public DIScope {
520514 unsigned Line;
521515 unsigned Flags;
522516 uint64_t SizeInBits;
524518 uint64_t OffsetInBits;
525519
526520 protected:
527 MDType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
521 DIType(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
528522 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
529523 uint64_t OffsetInBits, unsigned Flags, ArrayRef Ops)
530 : MDScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
524 : DIScope(C, ID, Storage, Tag, Ops), Line(Line), Flags(Flags),
531525 SizeInBits(SizeInBits), AlignInBits(AlignInBits),
532526 OffsetInBits(OffsetInBits) {}
533 ~MDType() = default;
534
535 public:
536 TempMDType clone() const {
537 return TempMDType(cast(MDNode::clone().release()));
527 ~DIType() = default;
528
529 public:
530 TempDIType clone() const {
531 return TempDIType(cast(MDNode::clone().release()));
538532 }
539533
540534 unsigned getLine() const { return Line; }
543537 uint64_t getOffsetInBits() const { return OffsetInBits; }
544538 unsigned getFlags() const { return Flags; }
545539
546 MDScopeRef getScope() const { return MDScopeRef(getRawScope()); }
540 DIScopeRef getScope() const { return DIScopeRef(getRawScope()); }
547541 StringRef getName() const { return getStringOperand(2); }
548542
549543
578572 bool isLValueReference() const { return getFlags() & FlagLValueReference; }
579573 bool isRValueReference() const { return getFlags() & FlagRValueReference; }
580574
581 MDTypeRef getRef() const { return MDTypeRef::get(this); }
575 DITypeRef getRef() const { return DITypeRef::get(this); }
582576
583577 static bool classof(const Metadata *MD) {
584578 switch (MD->getMetadataID()) {
585579 default:
586580 return false;
587 case MDBasicTypeKind:
588 case MDDerivedTypeKind:
589 case MDCompositeTypeKind:
590 case MDSubroutineTypeKind:
581 case DIBasicTypeKind:
582 case DIDerivedTypeKind:
583 case DICompositeTypeKind:
584 case DISubroutineTypeKind:
591585 return true;
592586 }
593587 }
597591 ///
598592 /// TODO: Split out DW_TAG_unspecified_type.
599593 /// TODO: Drop unused accessors.
600 class MDBasicType : public MDType {
594 class DIBasicType : public DIType {
601595 friend class LLVMContextImpl;
602596 friend class MDNode;
603597
604598 unsigned Encoding;
605599
606 MDBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
600 DIBasicType(LLVMContext &C, StorageType Storage, unsigned Tag,
607601 uint64_t SizeInBits, uint64_t AlignInBits, unsigned Encoding,
608602 ArrayRef Ops)
609 : MDType(C, MDBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
603 : DIType(C, DIBasicTypeKind, Storage, Tag, 0, SizeInBits, AlignInBits, 0,
610604 0, Ops),
611605 Encoding(Encoding) {}
612 ~MDBasicType() = default;
613
614 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
606 ~DIBasicType() = default;
607
608 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
615609 StringRef Name, uint64_t SizeInBits,
616610 uint64_t AlignInBits, unsigned Encoding,
617611 StorageType Storage, bool ShouldCreate = true) {
618612 return getImpl(Context, Tag, getCanonicalMDString(Context, Name),
619613 SizeInBits, AlignInBits, Encoding, Storage, ShouldCreate);
620614 }
621 static MDBasicType *getImpl(LLVMContext &Context, unsigned Tag,
615 static DIBasicType *getImpl(LLVMContext &Context, unsigned Tag,
622616 MDString *Name, uint64_t SizeInBits,
623617 uint64_t AlignInBits, unsigned Encoding,
624618 StorageType Storage, bool ShouldCreate = true);
625619
626 TempMDBasicType cloneImpl() const {
620 TempDIBasicType cloneImpl() const {
627621 return getTemporary(getContext(), getTag(), getName(), getSizeInBits(),
628622 getAlignInBits(), getEncoding());
629623 }
630624
631625 public:
632 DEFINE_MDNODE_GET(MDBasicType, (unsigned Tag, StringRef Name),
626 DEFINE_MDNODE_GET(DIBasicType, (unsigned Tag, StringRef Name),
633627 (Tag, Name, 0, 0, 0))
634 DEFINE_MDNODE_GET(MDBasicType,
628 DEFINE_MDNODE_GET(DIBasicType,
635629 (unsigned Tag, StringRef Name, uint64_t SizeInBits,
636630 uint64_t AlignInBits, unsigned Encoding),
637631 (Tag, Name, SizeInBits, AlignInBits, Encoding))
638 DEFINE_MDNODE_GET(MDBasicType,
632 DEFINE_MDNODE_GET(DIBasicType,
639633 (unsigned Tag, MDString *Name, uint64_t SizeInBits,
640634 uint64_t AlignInBits, unsigned Encoding),
641635 (Tag, Name, SizeInBits, AlignInBits, Encoding))
642636
643 TempMDBasicType clone() const { return cloneImpl(); }
637 TempDIBasicType clone() const { return cloneImpl(); }
644638
645639 unsigned getEncoding() const { return Encoding; }
646640
647641 static bool classof(const Metadata *MD) {
648 return MD->getMetadataID() == MDBasicTypeKind;
649 }
650 };
651
652 /// \brief Base class for MDDerivedType and MDCompositeType.
642 return MD->getMetadataID() == DIBasicTypeKind;
643 }
644 };
645
646 /// \brief Base class for DIDerivedType and DICompositeType.
653647 ///
654648 /// TODO: Delete; they're not really related.
655 class MDDerivedTypeBase : public MDType {
649 class DIDerivedTypeBase : public DIType {
656650 protected:
657 MDDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
651 DIDerivedTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
658652 unsigned Tag, unsigned Line, uint64_t SizeInBits,
659653 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
660654 ArrayRef Ops)
661 : MDType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
655 : DIType(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits, OffsetInBits,
662656 Flags, Ops) {}
663 ~MDDerivedTypeBase() = default;
664
665 public:
666 MDTypeRef getBaseType() const { return MDTypeRef(getRawBaseType()); }
657 ~DIDerivedTypeBase() = default;
658
659 public:
660 DITypeRef getBaseType() const { return DITypeRef(getRawBaseType()); }
667661 Metadata *getRawBaseType() const { return getOperand(3); }
668662
669663 static bool classof(const Metadata *MD) {
670 return MD->getMetadataID() == MDDerivedTypeKind ||
671 MD->getMetadataID() == MDCompositeTypeKind ||
672 MD->getMetadataID() == MDSubroutineTypeKind;
664 return MD->getMetadataID() == DIDerivedTypeKind ||
665 MD->getMetadataID() == DICompositeTypeKind ||
666 MD->getMetadataID() == DISubroutineTypeKind;
673667 }
674668 };
675669
679673 /// class members.
680674 ///
681675 /// TODO: Split out members (inheritance, fields, methods, etc.).
682 class MDDerivedType : public MDDerivedTypeBase {
676 class DIDerivedType : public DIDerivedTypeBase {
683677 friend class LLVMContextImpl;
684678 friend class MDNode;
685679
686 MDDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
680 DIDerivedType(LLVMContext &C, StorageType Storage, unsigned Tag,
687681 unsigned Line, uint64_t SizeInBits, uint64_t AlignInBits,
688682 uint64_t OffsetInBits, unsigned Flags, ArrayRef Ops)
689 : MDDerivedTypeBase(C, MDDerivedTypeKind, Storage, Tag, Line, SizeInBits,
683 : DIDerivedTypeBase(C, DIDerivedTypeKind, Storage, Tag, Line, SizeInBits,
690684 AlignInBits, OffsetInBits, Flags, Ops) {}
691 ~MDDerivedType() = default;
692
693 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
694 StringRef Name, MDFile *File, unsigned Line,
695 MDScopeRef Scope, MDTypeRef BaseType,
685 ~DIDerivedType() = default;
686
687 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
688 StringRef Name, DIFile *File, unsigned Line,
689 DIScopeRef Scope, DITypeRef BaseType,
696690 uint64_t SizeInBits, uint64_t AlignInBits,
697691 uint64_t OffsetInBits, unsigned Flags,
698692 Metadata *ExtraData, StorageType Storage,
701695 Line, Scope, BaseType, SizeInBits, AlignInBits, OffsetInBits,
702696 Flags, ExtraData, Storage, ShouldCreate);
703697 }
704 static MDDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
698 static DIDerivedType *getImpl(LLVMContext &Context, unsigned Tag,
705699 MDString *Name, Metadata *File, unsigned Line,
706700 Metadata *Scope, Metadata *BaseType,
707701 uint64_t SizeInBits, uint64_t AlignInBits,
709703 Metadata *ExtraData, StorageType Storage,
710704 bool ShouldCreate = true);
711705
712 TempMDDerivedType cloneImpl() const {
706 TempDIDerivedType cloneImpl() const {
713707 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
714708 getScope(), getBaseType(), getSizeInBits(),
715709 getAlignInBits(), getOffsetInBits(), getFlags(),
717711 }
718712
719713 public:
720 DEFINE_MDNODE_GET(MDDerivedType,
714 DEFINE_MDNODE_GET(DIDerivedType,
721715 (unsigned Tag, MDString *Name, Metadata *File,
722716 unsigned Line, Metadata *Scope, Metadata *BaseType,
723717 uint64_t SizeInBits, uint64_t AlignInBits,
725719 Metadata *ExtraData = nullptr),
726720 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
727721 AlignInBits, OffsetInBits, Flags, ExtraData))
728 DEFINE_MDNODE_GET(MDDerivedType,
729 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
730 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
722 DEFINE_MDNODE_GET(DIDerivedType,
723 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
724 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
731725 uint64_t AlignInBits, uint64_t OffsetInBits,
732726 unsigned Flags, Metadata *ExtraData = nullptr),
733727 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
734728 AlignInBits, OffsetInBits, Flags, ExtraData))
735729
736 TempMDDerivedType clone() const { return cloneImpl(); }
730 TempDIDerivedType clone() const { return cloneImpl(); }
737731
738732 /// \brief Get extra data associated with this derived type.
739733 ///
747741
748742 /// \brief Get casted version of extra data.
749743 /// @{
750 MDTypeRef getClassType() const {
744 DITypeRef getClassType() const {
751745 assert(getTag() == dwarf::DW_TAG_ptr_to_member_type);
752 return MDTypeRef(getExtraData());
753 }
754 MDObjCProperty *getObjCProperty() const {
755 return dyn_cast_or_null(getExtraData());
746 return DITypeRef(getExtraData());
747 }
748 DIObjCProperty *getObjCProperty() const {
749 return dyn_cast_or_null(getExtraData());
756750 }
757751 Constant *getConstant() const {
758752 assert(getTag() == dwarf::DW_TAG_member && isStaticMember());
763757 /// @}
764758
765759 static bool classof(const Metadata *MD) {
766 return MD->getMetadataID() == MDDerivedTypeKind;
767 }
768 };
769
770 /// \brief Base class for MDCompositeType and MDSubroutineType.
760 return MD->getMetadataID() == DIDerivedTypeKind;
761 }
762 };
763
764 /// \brief Base class for DICompositeType and DISubroutineType.
771765 ///
772766 /// TODO: Delete; they're not really related.
773 class MDCompositeTypeBase : public MDDerivedTypeBase {
767 class DICompositeTypeBase : public DIDerivedTypeBase {
774768 unsigned RuntimeLang;
775769
776770 protected:
777 MDCompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
771 DICompositeTypeBase(LLVMContext &C, unsigned ID, StorageType Storage,
778772 unsigned Tag, unsigned Line, unsigned RuntimeLang,
779773 uint64_t SizeInBits, uint64_t AlignInBits,
780774 uint64_t OffsetInBits, unsigned Flags,
781775 ArrayRef Ops)
782 : MDDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
776 : DIDerivedTypeBase(C, ID, Storage, Tag, Line, SizeInBits, AlignInBits,
783777 OffsetInBits, Flags, Ops),
784778 RuntimeLang(RuntimeLang) {}
785 ~MDCompositeTypeBase() = default;
779 ~DICompositeTypeBase() = default;
786780
787781 public:
788782 /// \brief Get the elements of the composite type.
789783 ///
790 /// \note Calling this is only valid for \a MDCompositeType. This assertion
791 /// can be removed once \a MDSubroutineType has been separated from
784 /// \note Calling this is only valid for \a DICompositeType. This assertion
785 /// can be removed once \a DISubroutineType has been separated from
792786 /// "composite types".
793 DebugNodeArray getElements() const {
794 assert(!isa(this) && "no elements for DISubroutineType");
787 DINodeArray getElements() const {
788 assert(!isa(this) && "no elements for DISubroutineType");
795789 return cast_or_null(getRawElements());
796790 }
797 MDTypeRef getVTableHolder() const { return MDTypeRef(getRawVTableHolder()); }
798 MDTemplateParameterArray getTemplateParams() const {
791 DITypeRef getVTableHolder() const { return DITypeRef(getRawVTableHolder()); }
792 DITemplateParameterArray getTemplateParams() const {
799793 return cast_or_null(getRawTemplateParams());
800794 }
801795 StringRef getIdentifier() const { return getStringOperand(7); }
812806 /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
813807 /// of its movement if necessary.
814808 /// @{
815 void replaceElements(DebugNodeArray Elements) {
809 void replaceElements(DINodeArray Elements) {
816810 #ifndef NDEBUG
817 for (DebugNode *Op : getElements())
811 for (DINode *Op : getElements())
818812 assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
819813 "Lost a member during member list replacement");
820814 #endif
821815 replaceOperandWith(4, Elements.get());
822816 }
823 void replaceVTableHolder(MDTypeRef VTableHolder) {
817 void replaceVTableHolder(DITypeRef VTableHolder) {
824818 replaceOperandWith(5, VTableHolder);
825819 }
826 void replaceTemplateParams(MDTemplateParameterArray TemplateParams) {
820 void replaceTemplateParams(DITemplateParameterArray TemplateParams) {
827821 replaceOperandWith(6, TemplateParams.get());
828822 }
829823 /// @}
830824
831825 static bool classof(const Metadata *MD) {
832 return MD->getMetadataID() == MDCompositeTypeKind ||
833 MD->getMetadataID() == MDSubroutineTypeKind;
826 return MD->getMetadataID() == DICompositeTypeKind ||
827 MD->getMetadataID() == DISubroutineTypeKind;
834828 }
835829 };
836830
838832 ///
839833 /// TODO: Detach from DerivedTypeBase (split out MDEnumType?).
840834 /// TODO: Create a custom, unrelated node for DW_TAG_array_type.
841 class MDCompositeType : public MDCompositeTypeBase {
835 class DICompositeType : public DICompositeTypeBase {
842836 friend class LLVMContextImpl;
843837 friend class MDNode;
844838
845 MDCompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
839 DICompositeType(LLVMContext &C, StorageType Storage, unsigned Tag,
846840 unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits,
847841 uint64_t AlignInBits, uint64_t OffsetInBits, unsigned Flags,
848842 ArrayRef Ops)
849 : MDCompositeTypeBase(C, MDCompositeTypeKind, Storage, Tag, Line,
843 : DICompositeTypeBase(C, DICompositeTypeKind, Storage, Tag, Line,
850844 RuntimeLang, SizeInBits, AlignInBits, OffsetInBits,
851845 Flags, Ops) {}
852 ~MDCompositeType() = default;
853
854 static MDCompositeType *
846 ~DICompositeType() = default;
847
848 static DICompositeType *
855849 getImpl(LLVMContext &Context, unsigned Tag, StringRef Name, Metadata *File,
856 unsigned Line, MDScopeRef Scope, MDTypeRef BaseType,
850 unsigned Line, DIScopeRef Scope, DITypeRef BaseType,
857851 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
858 uint64_t Flags, DebugNodeArray Elements, unsigned RuntimeLang,
859 MDTypeRef VTableHolder, MDTemplateParameterArray TemplateParams,
852 uint64_t Flags, DINodeArray Elements, unsigned RuntimeLang,
853 DITypeRef VTableHolder, DITemplateParameterArray TemplateParams,
860854 StringRef Identifier, StorageType Storage, bool ShouldCreate = true) {
861855 return getImpl(
862856 Context, Tag, getCanonicalMDString(Context, Name), File, Line, Scope,
864858 RuntimeLang, VTableHolder, TemplateParams.get(),
865859 getCanonicalMDString(Context, Identifier), Storage, ShouldCreate);
866860 }
867 static MDCompositeType *
861 static DICompositeType *
868862 getImpl(LLVMContext &Context, unsigned Tag, MDString *Name, Metadata *File,
869863 unsigned Line, Metadata *Scope, Metadata *BaseType,
870864 uint64_t SizeInBits, uint64_t AlignInBits, uint64_t OffsetInBits,
872866 Metadata *VTableHolder, Metadata *TemplateParams,
873867 MDString *Identifier, StorageType Storage, bool ShouldCreate = true);
874868
875 TempMDCompositeType cloneImpl() const {
869 TempDICompositeType cloneImpl() const {
876870 return getTemporary(getContext(), getTag(), getName(), getFile(), getLine(),
877871 getScope(), getBaseType(), getSizeInBits(),
878872 getAlignInBits(), getOffsetInBits(), getFlags(),
881875 }
882876
883877 public:
884 DEFINE_MDNODE_GET(MDCompositeType,
885 (unsigned Tag, StringRef Name, MDFile *File, unsigned Line,
886 MDScopeRef Scope, MDTypeRef BaseType, uint64_t SizeInBits,
878 DEFINE_MDNODE_GET(DICompositeType,
879 (unsigned Tag, StringRef Name, DIFile *File, unsigned Line,
880 DIScopeRef Scope, DITypeRef BaseType, uint64_t SizeInBits,
887881 uint64_t AlignInBits, uint64_t OffsetInBits,
888 unsigned Flags, DebugNodeArray Elements,
889 unsigned RuntimeLang, MDTypeRef VTableHolder,
890 MDTemplateParameterArray TemplateParams = nullptr,
882 unsigned Flags, DINodeArray Elements, unsigned RuntimeLang,
883 DITypeRef VTableHolder,
884 DITemplateParameterArray TemplateParams = nullptr,
891885 StringRef Identifier = ""),
892886 (Tag, Name, File, Line, Scope, BaseType, SizeInBits,
893887 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
894888 VTableHolder, TemplateParams, Identifier))
895 DEFINE_MDNODE_GET(MDCompositeType,
889 DEFINE_MDNODE_GET(DICompositeType,
896890 (unsigned Tag, MDString *Name, Metadata *File,
897891 unsigned Line, Metadata *Scope, Metadata *BaseType,
898892 uint64_t SizeInBits, uint64_t AlignInBits,
904898 AlignInBits, OffsetInBits, Flags, Elements, RuntimeLang,
905899 VTableHolder, TemplateParams, Identifier))
906900
907 TempMDCompositeType clone() const { return cloneImpl(); }
908
909 static bool classof(const Metadata *MD) {
910 return MD->getMetadataID() == MDCompositeTypeKind;
911 }
912 };
913
914 template TypedDebugNodeRef TypedDebugNodeRef::get(const T *N) {
901 TempDICompositeType clone() const { return cloneImpl(); }
902
903 static bool classof(const Metadata *MD) {
904 return MD->getMetadataID() == DICompositeTypeKind;
905 }
906 };
907
908 template TypedDINodeRef TypedDINodeRef::get(const T *N) {
915909 if (N)
916 if (auto *Composite = dyn_cast<MDCompositeType>(N))
910 if (auto *Composite = dyn_cast<DICompositeType>(N))
917911 if (auto *S = Composite->getRawIdentifier())
918 return TypedDebugNodeRef(S);
919 return TypedDebugNodeRef(N);
912 return TypedDINodeRef(S);
913 return TypedDINodeRef(N);
920914 }
921915
922916 /// \brief Type array for a subprogram.
923917 ///
924918 /// TODO: Detach from CompositeType, and fold the array of types in directly
925919 /// as operands.
926 class MDSubroutineType : public MDCompositeTypeBase {
920 class DISubroutineType : public DICompositeTypeBase {
927921 friend class LLVMContextImpl;
928922 friend class MDNode;
929923
930 MDSubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
924 DISubroutineType(LLVMContext &C, StorageType Storage, unsigned Flags,
931925 ArrayRef Ops)
932 : MDCompositeTypeBase(C, MDSubroutineTypeKind, Storage,
926 : DICompositeTypeBase(C, DISubroutineTypeKind, Storage,
933927 dwarf::DW_TAG_subroutine_type, 0, 0, 0, 0, 0, Flags,
934928 Ops) {}
935 ~MDSubroutineType() = default;
936
937 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
938 MDTypeRefArray TypeArray,
929 ~DISubroutineType() = default;
930
931 static DISubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
932 DITypeRefArray TypeArray,
939933 StorageType Storage,
940934 bool ShouldCreate = true) {
941935 return getImpl(Context, Flags, TypeArray.get(), Storage, ShouldCreate);
942936 }
943 static MDSubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
937 static DISubroutineType *getImpl(LLVMContext &Context, unsigned Flags,
944938 Metadata *TypeArray, StorageType Storage,
945939 bool ShouldCreate = true);
946940
947 TempMDSubroutineType cloneImpl() const {
941 TempDISubroutineType cloneImpl() const {
948942 return getTemporary(getContext(), getFlags(), getTypeArray());
949943 }
950944
951945 public:
952 DEFINE_MDNODE_GET(MDSubroutineType,
953 (unsigned Flags, MDTypeRefArray TypeArray),
946 DEFINE_MDNODE_GET(DISubroutineType,
947 (unsigned Flags, DITypeRefArray TypeArray),
954948 (Flags, TypeArray))
955 DEFINE_MDNODE_GET(MDSubroutineType, (unsigned Flags, Metadata *TypeArray),
949 DEFINE_MDNODE_GET(DISubroutineType, (unsigned Flags, Metadata *TypeArray),
956950 (Flags, TypeArray))
957951
958 TempMDSubroutineType clone() const { return cloneImpl(); }
959
960 MDTypeRefArray getTypeArray() const {
952 TempDISubroutineType clone() const { return cloneImpl(); }
953
954 DITypeRefArray getTypeArray() const {
961955 return cast_or_null(getRawTypeArray());
962956 }
963957 Metadata *getRawTypeArray() const { return getRawElements(); }
964958
965959 static bool classof(const Metadata *MD) {
966 return MD->getMetadataID() == MDSubroutineTypeKind;
960 return MD->getMetadataID() == DISubroutineTypeKind;
967961 }
968962 };
969963
970964 /// \brief Compile unit.
971 class MDCompileUnit : public MDScope {
965 class DICompileUnit : public DIScope {
972966 friend class LLVMContextImpl;
973967 friend class MDNode;
974968
977971 unsigned RuntimeVersion;
978972 unsigned EmissionKind;
979973
980 MDCompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
974 DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage,
981975 bool IsOptimized, unsigned RuntimeVersion,
982976 unsigned EmissionKind, ArrayRef Ops)
983 : MDScope(C, MDCompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
977 : DIScope(C, DICompileUnitKind, Storage, dwarf::DW_TAG_compile_unit, Ops),
984978 SourceLanguage(SourceLanguage), IsOptimized(IsOptimized),
985979 RuntimeVersion(RuntimeVersion), EmissionKind(EmissionKind) {}
986 ~MDCompileUnit() = default;
987
988 static MDCompileUnit *
989 getImpl(LLVMContext &Context, unsigned SourceLanguage, MDFile *File,
980 ~DICompileUnit() = default;
981
982 static DICompileUnit *
983 getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File,
990984 StringRef Producer, bool IsOptimized, StringRef Flags,
991985 unsigned RuntimeVersion, StringRef SplitDebugFilename,
992 unsigned EmissionKind, MDCompositeTypeArray EnumTypes,
993 MDTypeArray RetainedTypes, MDSubprogramArray Subprograms,
994 MDGlobalVariableArray GlobalVariables,
995 MDImportedEntityArray ImportedEntities, StorageType Storage,
986 unsigned EmissionKind, DICompositeTypeArray EnumTypes,
987 DITypeArray RetainedTypes, DISubprogramArray Subprograms,
988 DIGlobalVariableArray GlobalVariables,
989 DIImportedEntityArray ImportedEntities, StorageType Storage,
996990 bool ShouldCreate = true) {
997991 return getImpl(
998992 Context, SourceLanguage, File, getCanonicalMDString(Context, Producer),
1001995 EnumTypes.get(), RetainedTypes.get(), Subprograms.get(),
1002996 GlobalVariables.get(), ImportedEntities.get(), Storage, ShouldCreate);
1003997 }
1004 static MDCompileUnit *
998 static DICompileUnit *
1005999 getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File,
10061000 MDString *Producer, bool IsOptimized, MDString *Flags,
10071001 unsigned RuntimeVersion, MDString *SplitDebugFilename,
10101004 Metadata *ImportedEntities, StorageType Storage,
10111005 bool ShouldCreate = true);
10121006
1013 TempMDCompileUnit cloneImpl() const {
1007 TempDICompileUnit cloneImpl() const {
10141008 return getTemporary(
10151009 getContext(), getSourceLanguage(), getFile(), getProducer(),
10161010 isOptimized(), getFlags(), getRuntimeVersion(), getSplitDebugFilename(),
10191013 }
10201014
10211015 public:
1022 DEFINE_MDNODE_GET(MDCompileUnit,
1023 (unsigned SourceLanguage, MDFile *File, StringRef Producer,
1016 DEFINE_MDNODE_GET(DICompileUnit,
1017 (unsigned SourceLanguage, DIFile *File, StringRef Producer,
10241018 bool IsOptimized, StringRef Flags, unsigned RuntimeVersion,
10251019 StringRef SplitDebugFilename, unsigned EmissionKind,
1026 MDCompositeTypeArray EnumTypes, MDTypeArray RetainedTypes,
1027 MDSubprogramArray Subprograms,
1028 MDGlobalVariableArray GlobalVariables,
1029 MDImportedEntityArray ImportedEntities),
1020 DICompositeTypeArray EnumTypes, DITypeArray RetainedTypes,
1021 DISubprogramArray Subprograms,
1022 DIGlobalVariableArray GlobalVariables,
1023 DIImportedEntityArray ImportedEntities),
10301024 (SourceLanguage, File, Producer, IsOptimized, Flags,
10311025 RuntimeVersion, SplitDebugFilename, EmissionKind,
10321026 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
10331027 ImportedEntities))
1034 DEFINE_MDNODE_GET(MDCompileUnit,
1028 DEFINE_MDNODE_GET(DICompileUnit,
10351029 (unsigned SourceLanguage, Metadata *File,
10361030 MDString *Producer, bool IsOptimized, MDString *Flags,
10371031 unsigned RuntimeVersion, MDString *SplitDebugFilename,
10431037 EnumTypes, RetainedTypes, Subprograms, GlobalVariables,
10441038 ImportedEntities))
10451039
1046 TempMDCompileUnit clone() const { return cloneImpl(); }
1040 TempDICompileUnit clone() const { return cloneImpl(); }
10471041
10481042 unsigned getSourceLanguage() const { return SourceLanguage; }
10491043 bool isOptimized() const { return IsOptimized; }
10521046 StringRef getProducer() const { return getStringOperand(1); }
10531047 StringRef getFlags() const { return getStringOperand(2); }
10541048 StringRef getSplitDebugFilename() const { return getStringOperand(3); }
1055 MDCompositeTypeArray getEnumTypes() const {
1049 DICompositeTypeArray getEnumTypes() const {
10561050 return cast_or_null(getRawEnumTypes());
10571051 }
1058 MDTypeArray getRetainedTypes() const {
1052 DITypeArray getRetainedTypes() const {
10591053 return cast_or_null(getRawRetainedTypes());
10601054 }
1061 MDSubprogramArray getSubprograms() const {
1055 DISubprogramArray getSubprograms() const {
10621056 return cast_or_null(getRawSubprograms());
10631057 }
1064 MDGlobalVariableArray getGlobalVariables() const {
1058 DIGlobalVariableArray getGlobalVariables() const {
10651059 return cast_or_null(getRawGlobalVariables());
10661060 }
1067 MDImportedEntityArray getImportedEntities() const {
1061 DIImportedEntityArray getImportedEntities() const {
10681062 return cast_or_null(getRawImportedEntities());
10691063 }
10701064
10831077 ///
10841078 /// If this \a isUniqued() and not \a isResolved(), it will be RAUW'ed and
10851079 /// deleted on a uniquing collision. In practice, uniquing collisions on \a
1086 /// MDCompileUnit should be fairly rare.
1080 /// DICompileUnit should be fairly rare.
10871081 /// @{
1088 void replaceSubprograms(MDSubprogramArray N) {
1082 void replaceSubprograms(DISubprogramArray N) {
10891083 replaceOperandWith(6, N.get());
10901084 }
1091 void replaceGlobalVariables(MDGlobalVariableArray N) {
1085 void replaceGlobalVariables(DIGlobalVariableArray N) {
10921086 replaceOperandWith(7, N.get());
10931087 }
10941088 /// @}
10951089
10961090 static bool classof(const Metadata *MD) {
1097 return MD->getMetadataID() == MDCompileUnitKind;
1091 return MD->getMetadataID() == DICompileUnitKind;
10981092 }
10991093 };
11001094
11011095 /// \brief A scope for locals.
11021096 ///
11031097 /// A legal scope for lexical blocks, local variables, and debug info
1104 /// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
1105 /// MDLexicalBlockFile.
1106 class MDLocalScope : public MDScope {
1098 /// locations. Subclasses are \a DISubprogram, \a DILexicalBlock, and \a
1099 /// DILexicalBlockFile.
1100 class DILocalScope : public DIScope {
11071101 protected:
1108 MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
1102 DILocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
11091103 ArrayRef Ops)
1110 : MDScope(C, ID, Storage, Tag, Ops) {}
1111 ~MDLocalScope() = default;
1104 : DIScope(C, ID, Storage, Tag, Ops) {}
1105 ~DILocalScope() = default;
11121106
11131107 public:
11141108 /// \brief Get the subprogram for this scope.
11151109 ///
1116 /// Return this if it's an \a MDSubprogram; otherwise, look up the scope
1110 /// Return this if it's an \a DISubprogram; otherwise, look up the scope
11171111 /// chain.
1118 MDSubprogram *getSubprogram() const;
1119
1120 static bool classof(const Metadata *MD) {
1121 return MD->getMetadataID() == MDSubprogramKind ||
1122 MD->getMetadataID() == MDLexicalBlockKind ||
1123 MD->getMetadataID() == MDLexicalBlockFileKind;
1112 DISubprogram *getSubprogram() const;
1113
1114 static bool classof(const Metadata *MD) {
1115 return MD->getMetadataID() == DISubprogramKind ||
1116 MD->getMetadataID() == DILexicalBlockKind ||
1117 MD->getMetadataID() == DILexicalBlockFileKind;
11241118 }
11251119 };
11261120
11271121 /// \brief Debug location.
11281122 ///
11291123 /// A debug location in source code, used for debug info and otherwise.
1130 class MDLocation : public MDNode {
1124 class DILocation : public MDNode {
11311125 friend class LLVMContextImpl;
11321126 friend class MDNode;
11331127
1134 MDLocation(LLVMContext &C, StorageType Storage, unsigned Line,
1128 DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
11351129 unsigned Column, ArrayRef MDs);
1136 ~MDLocation() { dropAllReferences(); }
1137
1138 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1130 ~DILocation() { dropAllReferences(); }
1131
1132 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
11391133 unsigned Column, Metadata *Scope,
11401134 Metadata *InlinedAt, StorageType Storage,
11411135 bool ShouldCreate = true);
1142 static MDLocation *getImpl(LLVMContext &Context, unsigned Line,
1143 unsigned Column, MDLocalScope *Scope,
1144 MDLocation *InlinedAt, StorageType Storage,
1136 static DILocation *getImpl(LLVMContext &Context, unsigned Line,
1137 unsigned Column, DILocalScope *Scope,
1138 DILocation *InlinedAt, StorageType Storage,
11451139 bool ShouldCreate = true) {
11461140 return getImpl(Context, Line, Column, static_cast(Scope),
11471141 static_cast(InlinedAt), Storage, ShouldCreate);
11481142 }
11491143
1150 TempMDLocation cloneImpl() const {
1144 TempDILocation cloneImpl() const {
11511145 return getTemporary(getContext(), getLine(), getColumn(), getScope(),
11521146 getInlinedAt());
11531147 }
11561150 void replaceOperandWith(unsigned I, Metadata *New) = delete;