llvm.org GIT mirror llvm / e4b2756
Reapply 79977. Use MDNodes to encode debug info in llvm IR. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80406 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 11 years ago
46 changed file(s) with 1015 addition(s) and 1989 deletion(s). Raw diff Collapse all Expand all
121121

The approach used by the LLVM implementation is to use a small set

122122 of intrinsic functions to define a
123123 mapping between LLVM program objects and the source-level objects. The
124 description of the source-level program is maintained in LLVM global
125 variables in an implementation-defined format
124 description of the source-level program is maintained in LLVM metadata
125 in an implementation-defined format
126126 (the C/C++ front-end currently uses working draft 7 of
127127 the DWARF 3
128128 standard).

239239

LLVM debugging information has been carefully designed to make it possible

240240 for the optimizer to optimize the program and debugging information without
241241 necessarily having to know anything about debugging information. In
242 particular, the global constant merging pass automatically eliminates
243 duplicated debugging information (often caused by header files), the global
244 dead code elimination pass automatically deletes debugging information for a
245 function if it decides to delete the function, and the linker eliminates
246 debug information when it merges linkonce functions.

242 particular, te use of metadadta avoids duplicated dubgging information from
243 the beginning, and the global dead code elimination pass automatically
244 deletes debugging information for a function if it decides to delete the
245 function.

247246
248247

To do this, most of the debugging information (descriptors for types,

249248 variables, functions, source files, etc) is inserted by the language
250 front-end in the form of LLVM global variables. These LLVM global variables
251 are no different from any other global variables, except that they have a web
252 of LLVM intrinsic functions that point to them. If the last references to a
253 particular piece of debugging information are deleted (for example, by the
254 -globaldce pass), the extraneous debug information will
255 automatically become dead and be removed by the optimizer.

249 front-end in the form of LLVM metadata.

256250
257251

Debug information is designed to be agnostic about the target debugger and

258252 debugging information representation (e.g. DWARF/Stabs/etc). It uses a
259 generic machine debug information pass to decode the information that
260 represents variables, types, functions, namespaces, etc: this allows for
261 arbitrary source-language semantics and type-systems to be used, as long as
262 there is a module written for the target debugger to interpret the
263 information. In addition, debug global variables are declared in
264 the "llvm.metadata" section. All values declared in this section
265 are stripped away after target debug information is constructed and before
266 the program object is emitted.

253 generic pass to decode the information that represents variables, types,
254 functions, namespaces, etc: this allows for arbitrary source-language
255 semantics and type-systems to be used, as long as there is a module
256 written for the target debugger to interpret the information.

267257
268258

To provide basic functionality, the LLVM debugger does have to make some

269259 assumptions about the source-level language being debugged, though it keeps
287277
288278
289279

In consideration of the complexity and volume of debug information, LLVM

290 provides a specification for well formed debug global variables. The
291 constant value of each of these globals is one of a limited set of
292 structures, known as debug descriptors.

280 provides a specification for well formed debug descriptors.

293281
294282

Consumers of LLVM debug information expect the descriptors for program

295283 objects to start in a canonical format, but the descriptors can include
302290 the range 0x1000 thru 0x2000 (there is a defined enum DW_TAG_user_base =
303291 0x1000.)

304292
305

The fields of debug descriptors used internally by LLVM (MachineModuleInfo)

293

The fields of debug descriptors used internally by LLVM

306294 are restricted to only the simple data types int, uint,
307 bool, float, double, i8* and
308 { }*. References to arbitrary values are handled using a
309 { }* and a cast to { }* expression; typically
310 references to other field descriptors, arrays of descriptors or global
311 variables.

312
313
314

                  
                
315 %llvm.dbg.object.type = type {
295 bool, float, double, mdstring and
296 mdnode.

297
298
299

                  
                
300 !1 = metadata !{
316301 uint, ;; A tag
317302 ...
318303 }
325310 of tags are loosely bound to the tag values of DWARF information entries.
326311 However, that does not restrict the use of the information supplied to DWARF
327312 targets. To facilitate versioning of debug information, the tag is augmented
328 with the current debug version (LLVMDebugVersion = 4 << 16 or 0x40000 or
329 262144.)

313 with the current debug version (LLVMDebugVersion = 7 << 16 or 0x70000 or
314 458752.)

330315
331316

The details of the various descriptors follow.

332317
341326
342327
343328

                  
                
344 %llvm.dbg.compile_unit.type = type {
345 i32, ;; Tag = 17 + LLVMDebugVersion (DW_TAG_compile_unit)
346 { }*, ;; Compile unit anchor = cast = (%llvm.dbg.anchor.type* %llvm.dbg.compile_units to { }*)
347 i32, ;; DWARF language identifier (ex. DW_LANG_C89)
348 i8*, ;; Source file name
349 i8*, ;; Source file directory (includes trailing slash)
350 i8* ;; Producer (ex. "4.0.1 LLVM (LLVM research group)")
351 i1, ;; True if this is a main compile unit.
352 i1, ;; True if this is optimized.
353 i8*, ;; Flags
354 i32 ;; Runtime version
329 !0 = metadata !{
330 i32, ;; Tag = 17 + LLVMDebugVersion
331 ;; (DW_TAG_compile_unit)
332 i32, ;; Unused field.
333 i32, ;; DWARF language identifier (ex. DW_LANG_C89)
334 metadata, ;; Source file name
335 metadata, ;; Source file directory (includes trailing slash)
336 metadata ;; Producer (ex. "4.0.1 LLVM (LLVM research group)")
337 i1, ;; True if this is a main compile unit.
338 i1, ;; True if this is optimized.
339 metadata, ;; Flags
340 i32 ;; Runtime version
355341 }
356342
357343
387373
388374
389375

                  
                
390 %llvm.dbg.global_variable.type = type {
391 i32, ;; Tag = 52 + LLVMDebugVersion (DW_TAG_variable)
392 { }*, ;; Global variable anchor = cast (%llvm.dbg.anchor.type* %llvm.dbg.global_variables to { }*),
393 { }*, ;; Reference to context descriptor
394 i8*, ;; Name
395 i8*, ;; Display name (fully qualified C++ name)
396 i8*, ;; MIPS linkage name (for C++)
397 { }*, ;; Reference to compile unit where defined
398 i32, ;; Line number where defined
399 { }*, ;; Reference to type descriptor
400 i1, ;; True if the global is local to compile unit (static)
401 i1, ;; True if the global is defined in the compile unit (not extern)
402 { }* ;; Reference to the global variable
376 !1 = metadata !{
377 i32, ;; Tag = 52 + LLVMDebugVersion
378 ;; (DW_TAG_variable)
379 i32, ;; Unused field.
380 metadata, ;; Reference to context descriptor
381 metadata, ;; Name
382 metadata, ;; Display name (fully qualified C++ name)
383 metadata, ;; MIPS linkage name (for C++)
384 metadata, ;; Reference to compile unit where defined
385 i32, ;; Line number where defined
386 metadata, ;; Reference to type descriptor
387 i1, ;; True if the global is local to compile unit (static)
388 i1, ;; True if the global is defined in the compile unit (not extern)
389 { }* ;; Reference to the global variable
403390 }
404391
405392
418405
419406
420407

                  
                
421 %llvm.dbg.subprogram.type = type {
422 i32, ;; Tag = 46 + LLVMDebugVersion (DW_TAG_subprogram)
423 { }*, ;; Subprogram anchor = cast (%llvm.dbg.anchor.type* %llvm.dbg.subprograms to { }*),
424 { }*, ;; Reference to context descriptor
425 i8*, ;; Name
426 i8*, ;; Display name (fully qualified C++ name)
427 i8*, ;; MIPS linkage name (for C++)
428 { }*, ;; Reference to compile unit where defined
429 i32, ;; Line number where defined
430 { }*, ;; Reference to type descriptor
431 i1, ;; True if the global is local to compile unit (static)
432 i1 ;; True if the global is defined in the compile unit (not extern)
408 !2 = metadata !{
409 i32, ;; Tag = 46 + LLVMDebugVersion
410 ;; (DW_TAG_subprogram)
411 i32, ;; Unused field.
412 metadata, ;; Reference to context descriptor
413 metadata, ;; Name
414 metadata, ;; Display name (fully qualified C++ name)
415 metadata, ;; MIPS linkage name (for C++)
416 metadata, ;; Reference to compile unit where defined
417 i32, ;; Line number where defined
418 metadata, ;; Reference to type descriptor
419 i1, ;; True if the global is local to compile unit (static)
420 i1 ;; True if the global is defined in the compile unit (not extern)
433421 }
434422
435423
449437
450438
451439

                  
                
452 %llvm.dbg.block = type {
453 i32, ;; Tag = 13 + LLVMDebugVersion (DW_TAG_lexical_block)
454 { }* ;; Reference to context descriptor
440 !3 = metadata !{
441 i32, ;; Tag = 13 + LLVMDebugVersion (DW_TAG_lexical_block)
442 metadata ;; Reference to context descriptor
455443 }
456444
457445
471459
472460
473461

                  
                
474 %llvm.dbg.basictype.type = type {
475 i32, ;; Tag = 36 + LLVMDebugVersion (DW_TAG_base_type)
476 { }*, ;; Reference to context (typically a compile unit)
477 i8*, ;; Name (may be "" for anonymous types)
478 { }*, ;; Reference to compile unit where defined (may be NULL)
479 i32, ;; Line number where defined (may be 0)
480 i64, ;; Size in bits
481 i64, ;; Alignment in bits
482 i64, ;; Offset in bits
483 i32, ;; Flags
484 i32 ;; DWARF type encoding
462 !4 = metadata !{
463 i32, ;; Tag = 36 + LLVMDebugVersion
464 ;; (DW_TAG_base_type)
465 metadata, ;; Reference to context (typically a compile unit)
466 metadata, ;; Name (may be "" for anonymous types)
467 metadata, ;; Reference to compile unit where defined (may be NULL)
468 i32, ;; Line number where defined (may be 0)
469 i64, ;; Size in bits
470 i64, ;; Alignment in bits
471 i64, ;; Offset in bits
472 i32, ;; Flags
473 i32 ;; DWARF type encoding
485474 }
486475
487476
522511
523512
524513

                  
                
525 %llvm.dbg.derivedtype.type = type {
526 i32, ;; Tag (see below)
527 { }*, ;; Reference to context
528 i8*, ;; Name (may be "" for anonymous types)
529 { }*, ;; Reference to compile unit where defined (may be NULL)
530 i32, ;; Line number where defined (may be 0)
531 i32, ;; Size in bits
532 i32, ;; Alignment in bits
533 i32, ;; Offset in bits
534 { }* ;; Reference to type derived from
514 !5 = metadata !{
515 i32, ;; Tag (see below)
516 metadata, ;; Reference to context
517 metadata, ;; Name (may be "" for anonymous types)
518 metadata, ;; Reference to compile unit where defined (may be NULL)
519 i32, ;; Line number where defined (may be 0)
520 i32, ;; Size in bits
521 i32, ;; Alignment in bits
522 i32, ;; Offset in bits
523 metadata ;; Reference to type derived from
535524 }
536525
537526
590579
591580
592581

                  
                
593 %llvm.dbg.compositetype.type = type {
594 i32, ;; Tag (see below)
595 { }*, ;; Reference to context
596 i8*, ;; Name (may be "" for anonymous types)
597 { }*, ;; Reference to compile unit where defined (may be NULL)
598 i32, ;; Line number where defined (may be 0)
599 i64, ;; Size in bits
600 i64, ;; Alignment in bits
601 i64, ;; Offset in bits
602 i32, ;; Flags
603 { }*, ;; Reference to type derived from
604 { }*, ;; Reference to array of member descriptors
605 i32 ;; Runtime languages
582 !6 = metadata !{
583 i32, ;; Tag (see below)
584 metadata, ;; Reference to context
585 metadata, ;; Name (may be "" for anonymous types)
586 metadata, ;; Reference to compile unit where defined (may be NULL)
587 i32, ;; Line number where defined (may be 0)
588 i64, ;; Size in bits
589 i64, ;; Alignment in bits
590 i64, ;; Offset in bits
591 i32, ;; Flags
592 metadata, ;; Reference to type derived from
593 metadata, ;; Reference to array of member descriptors
594 i32 ;; Runtime languages
606595 }
607596
608597
701690
702691
703692

                  
                
704 %llvm.dbg.enumerator.type = type {
705 i32, ;; Tag = 40 + LLVMDebugVersion (DW_TAG_enumerator)
706 i8*, ;; Name
707 i64 ;; Value
693 !6 = metadata !{
694 i32, ;; Tag = 40 + LLVMDebugVersion
695 ;; (DW_TAG_enumerator)
696 metadata, ;; Name
697 i64 ;; Value
708698 }
709699
710700
724714
725715
726716

                  
                
727 %llvm.dbg.variable.type = type {
728 i32, ;; Tag (see below)
729 { }*, ;; Context
730 i8*, ;; Name
731 { }*, ;; Reference to compile unit where defined
732 i32, ;; Line number where defined
733 { }* ;; Type descriptor
717 !7 = metadata !{
718 i32, ;; Tag (see below)
719 metadata, ;; Context
720 metadata, ;; Name
721 metadata, ;; Reference to compile unit where defined
722 i32, ;; Line number where defined
723 metadata ;; Type descriptor
734724 }
735725
736726
777767
778768
779769

                  
                
780 void %llvm.dbg.stoppoint( uint, uint, { }* )
770 void %llvm.dbg.stoppoint( uint, uint, metadata)
781771
782772
783773

This intrinsic is used to provide correspondence between the source file and

784774 the generated code. The first argument is the line number (base 1), second
785775 argument is the column number (0 if unknown) and the third argument the
786 source %llvm.dbg.compile_unit*
787 cast to a { }*. Code following a call to this intrinsic will
776 source %llvm.dbg.compile_unit.
777 Code following a call to this intrinsic will
788778 have been defined in close proximity of the line, column and file. This
789779 information holds until the next call
790780 to %lvm.dbg.stoppoint.

798788
799789
800790

                  
                
801 void %llvm.dbg.func.start( { }* )
791 void %llvm.dbg.func.start( metadata )
802792
803793
804794

This intrinsic is used to link the debug information

822812
823813
824814

                  
                
825 void %llvm.dbg.region.start( { }* )
815 void %llvm.dbg.region.start( metadata )
826816
827817
828818

This intrinsic is used to define the beginning of a declarative scope (ex.

842832
843833
844834

                  
                
845 void %llvm.dbg.region.end( { }* )
835 void %llvm.dbg.region.end( metadata )
846836
847837
848838

This intrinsic is used to define the end of a declarative scope (ex. block)

863853
864854
865855

                  
                
866 void %llvm.dbg.declare( { } *, { }* )
856 void %llvm.dbg.declare( { } *, metadata )
867857
868858
869859

This intrinsic provides information about a local element (ex. variable.) The

870860 first argument is the alloca for the variable, cast to a { }*. The
871861 second argument is
872862 the %llvm.dbg.variable containing
873 the description of the variable, also cast to a { }*.

863 the description of the variable.

874864
875865
876866
954944
955945 ...
956946
957 call void @llvm.dbg.func.start( %llvm.dbg.subprogram.type* @llvm.dbg.subprogram )
947 call void @llvm.dbg.func.start( metadata !0)
958948
959 call void @llvm.dbg.stoppoint( uint 2, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
949 call void @llvm.dbg.stoppoint( uint 2, uint 2, metadata !1)
960950
961951 call void @llvm.dbg.declare({}* %X, ...)
962952 call void @llvm.dbg.declare({}* %Y, ...)
963953
964954 ;; Evaluate expression on line 2, assigning to X.
965955
966 call void @llvm.dbg.stoppoint( uint 3, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
956 call void @llvm.dbg.stoppoint( uint 3, uint 2, metadata !1)
967957
968958 ;; Evaluate expression on line 3, assigning to Y.
969959
970960 call void @llvm.region.start()
971 call void @llvm.dbg.stoppoint( uint 5, uint 4, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
961 call void @llvm.dbg.stoppoint( uint 5, uint 4, metadata !1)
972962 call void @llvm.dbg.declare({}* %X, ...)
973963
974964 ;; Evaluate expression on line 5, assigning to Z.
975965
976 call void @llvm.dbg.stoppoint( uint 7, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
966 call void @llvm.dbg.stoppoint( uint 7, uint 2, metadata !1)
977967 call void @llvm.region.end()
978968
979 call void @llvm.dbg.stoppoint( uint 9, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
969 call void @llvm.dbg.stoppoint( uint 9, uint 2, metadata !1)
980970
981971 call void @llvm.region.end()
982972
10961086

                  
                
10971087 ...
10981088 ;;
1099 ;; Define types used. In this case we need one for compile unit anchors and one
1100 ;; for compile units.
1101 ;;
1102 %llvm.dbg.anchor.type = type { uint, uint }
1103 %llvm.dbg.compile_unit.type = type { uint, { }*, uint, uint, i8*, i8*, i8* }
1104 ...
1105 ;;
1106 ;; Define the anchor for compile units. Note that the second field of the
1107 ;; anchor is 17, which is the same as the tag for compile units
1108 ;; (17 = DW_TAG_compile_unit.)
1109 ;;
1110 %llvm.dbg.compile_units = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 17 }, section "llvm.metadata"
1111
1112 ;;
11131089 ;; Define the compile unit for the source file "/Users/mine/sources/MySource.cpp".
11141090 ;;
1115 %llvm.dbg.compile_unit1 = internal constant %llvm.dbg.compile_unit.type {
1116 uint add(uint 17, uint 262144),
1117 { }* cast (%llvm.dbg.anchor.type* %llvm.dbg.compile_units to { }*),
1118 uint 1,
1119 uint 1,
1120 i8* getelementptr ([13 x i8]* %str1, i32 0, i32 0),
1121 i8* getelementptr ([21 x i8]* %str2, i32 0, i32 0),
1122 i8* getelementptr ([33 x i8]* %str3, i32 0, i32 0) }, section "llvm.metadata"
1123
1091 !3 = metadata !{
1092 i32 458769, ;; Tag
1093 i32 0, ;; Unused
1094 i32 4, ;; Language Id
1095 metadata !"MySource.cpp",
1096 metadata !"/Users/mine/sources",
1097 metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build 00)",
1098 i1 true, ;; Main Compile Unit
1099 i1 false, ;; Optimized compile unit
1100 metadata !"", ;; Compiler flags
1101 i32 0} ;; Runtime version
1102
11241103 ;;
11251104 ;; Define the compile unit for the header file "/Users/mine/sources/MyHeader.h".
11261105 ;;
1127 %llvm.dbg.compile_unit2 = internal constant %llvm.dbg.compile_unit.type {
1128 uint add(uint 17, uint 262144),
1129 { }* cast (%llvm.dbg.anchor.type* %llvm.dbg.compile_units to { }*),
1130 uint 1,
1131 uint 1,
1132 i8* getelementptr ([11 x i8]* %str4, int 0, int 0),
1133 i8* getelementptr ([21 x i8]* %str2, int 0, int 0),
1134 i8* getelementptr ([33 x i8]* %str3, int 0, int 0) }, section "llvm.metadata"
1135
1136 ;;
1137 ;; Define each of the strings used in the compile units.
1138 ;;
1139 %str1 = internal constant [13 x i8] c"MySource.cpp\00", section "llvm.metadata";
1140 %str2 = internal constant [21 x i8] c"/Users/mine/sources/\00", section "llvm.metadata";
1141 %str3 = internal constant [33 x i8] c"4.0.1 LLVM (LLVM research group)\00", section "llvm.metadata";
1142 %str4 = internal constant [11 x i8] c"MyHeader.h\00", section "llvm.metadata";
1106 !1 = metadata !{
1107 i32 458769, ;; Tag
1108 i32 0, ;; Unused
1109 i32 4, ;; Language Id
1110 metadata !"MyHeader.h",
1111 metadata !"/Users/mine/sources",
1112 metadata !"4.2.1 (Based on Apple Inc. build 5649) (LLVM build 00)",
1113 i1 false, ;; Main Compile Unit
1114 i1 false, ;; Optimized compile unit
1115 metadata !"", ;; Compiler flags
1116 i32 0} ;; Runtime version
1117
11431118 ...
11441119
11451120
11661141
11671142

                  
                
11681143 ;;
1169 ;; Define types used. One for global variable anchors, one for the global
1170 ;; variable descriptor, one for the global's basic type and one for the global's
1171 ;; compile unit.
1172 ;;
1173 %llvm.dbg.anchor.type = type { uint, uint }
1174 %llvm.dbg.global_variable.type = type { uint, { }*, { }*, i8*, { }*, uint, { }*, bool, bool, { }*, uint }
1175 %llvm.dbg.basictype.type = type { uint, { }*, i8*, { }*, int, uint, uint, uint, uint }
1176 %llvm.dbg.compile_unit.type = ...
1177 ...
1178 ;;
11791144 ;; Define the global itself.
11801145 ;;
11811146 %MyGlobal = global int 100
11821147 ...
11831148 ;;
1184 ;; Define the anchor for global variables. Note that the second field of the
1185 ;; anchor is 52, which is the same as the tag for global variables
1186 ;; (52 = DW_TAG_variable.)
1187 ;;
1188 %llvm.dbg.global_variables = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 52 }, section "llvm.metadata"
1149 ;; List of debug info of globals
1150 ;;
1151 !llvm.dbg.gv = !{!0}
11891152
11901153 ;;
11911154 ;; Define the global variable descriptor. Note the reference to the global
11921155 ;; variable anchor and the global variable itself.
11931156 ;;
1194 %llvm.dbg.global_variable = internal constant %llvm.dbg.global_variable.type {
1195 uint add(uint 52, uint 262144),
1196 { }* cast (%llvm.dbg.anchor.type* %llvm.dbg.global_variables to { }*),
1197 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1198 i8* getelementptr ([9 x i8]* %str1, int 0, int 0),
1199 i8* getelementptr ([1 x i8]* %str2, int 0, int 0),
1200 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1201 uint 1,
1202 { }* cast (%llvm.dbg.basictype.type* %llvm.dbg.basictype to { }*),
1203 bool false,
1204 bool true,
1205 { }* cast (int* %MyGlobal to { }*) }, section "llvm.metadata"
1206
1157 !0 = metadata !{
1158 i32 458804, ;; Tag
1159 i32 0, ;; Unused
1160 metadata !1, ;; Context
1161 metadata !"MyGlobal", ;; Name
1162 metadata !"MyGlobal", ;; Display Name
1163 metadata !"MyGlobal", ;; Linkage Name
1164 metadata !1, ;; Compile Unit
1165 i32 1, ;; Line Number
1166 metadata !2, ;; Type
1167 i1 false, ;; Is a local variable
1168 i1 true, ;; Is this a definition
1169 i32* @MyGlobal ;; The global variable
1170 }
1171
12071172 ;;
12081173 ;; Define the basic type of 32 bit signed integer. Note that since int is an
12091174 ;; intrinsic type the source file is NULL and line 0.
12101175 ;;
1211 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1212 uint add(uint 36, uint 262144),
1213 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1214 i8* getelementptr ([4 x i8]* %str3, int 0, int 0),
1215 { }* null,
1216 int 0,
1217 uint 32,
1218 uint 32,
1219 uint 0,
1220 uint 5 }, section "llvm.metadata"
1221
1222 ;;
1223 ;; Define the names of the global variable and basic type.
1224 ;;
1225 %str1 = internal constant [9 x i8] c"MyGlobal\00", section "llvm.metadata"
1226 %str2 = internal constant [1 x i8] c"\00", section "llvm.metadata"
1227 %str3 = internal constant [4 x i8] c"int\00", section "llvm.metadata"
1176 !2 = metadata !{
1177 i32 458788, ;; Tag
1178 metadata !1, ;; Context
1179 metadata !"int", ;; Name
1180 metadata !1, ;; Compile Unit
1181 i32 0, ;; Line number
1182 i64 32, ;; Size in Bits
1183 i64 32, ;; Align in Bits
1184 i64 0, ;; Offset in Bits
1185 i32 0, ;; Flags
1186 i32 5 ;; Encoding
1187 }
1188
12281189
12291190
12301191
12511212
12521213
12531214

                  
                
1254 ;;
1255 ;; Define types used. One for subprogram anchors, one for the subprogram
1256 ;; descriptor, one for the global's basic type and one for the subprogram's
1257 ;; compile unit.
1258 ;;
1259 %llvm.dbg.subprogram.type = type { uint, { }*, { }*, i8*, { }*, bool, bool }
1260 %llvm.dbg.anchor.type = type { uint, uint }
1261 %llvm.dbg.compile_unit.type = ...
1262
12631215 ;;
12641216 ;; Define the anchor for subprograms. Note that the second field of the
12651217 ;; anchor is 46, which is the same as the tag for subprograms
12661218 ;; (46 = DW_TAG_subprogram.)
12671219 ;;
1268 %llvm.dbg.subprograms = linkonce constant %llvm.dbg.anchor.type { uint 0, uint 46 }, section "llvm.metadata"
1269
1270 ;;
1271 ;; Define the descriptor for the subprogram. TODO - more details.
1272 ;;
1273 %llvm.dbg.subprogram = internal constant %llvm.dbg.subprogram.type {
1274 uint add(uint 46, uint 262144),
1275 { }* cast (%llvm.dbg.anchor.type* %llvm.dbg.subprograms to { }*),
1276 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1277 i8* getelementptr ([5 x i8]* %str1, int 0, int 0),
1278 i8* getelementptr ([1 x i8]* %str2, int 0, int 0),
1279 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1280 uint 1,
1281 { }* null,
1282 bool false,
1283 bool true }, section "llvm.metadata"
1284
1285 ;;
1286 ;; Define the name of the subprogram.
1287 ;;
1288 %str1 = internal constant [5 x i8] c"main\00", section "llvm.metadata"
1289 %str2 = internal constant [1 x i8] c"\00", section "llvm.metadata"
1290
1220 !0 = metadata !{
1221 i32 458798, ;; Tag
1222 i32 0, ;; Unused
1223 metadata !1, ;; Context
1224 metadata !"main", ;; Name
1225 metadata !"main", ;; Display name
1226 metadata !"main", ;; Linkage name
1227 metadata !1, ;; Compile unit
1228 i32 1, ;; Line number
1229 metadata !2, ;; Type
1230 i1 false, ;; Is local
1231 i1 true ;; Is definition
1232 }
12911233 ;;
12921234 ;; Define the subprogram itself.
12931235 ;;
1294 int %main(int %argc, i8** %argv) {
1236 define i32 @main(i32 %argc, i8** %argv) {
12951237 ...
12961238 }
12971239
13191261
13201262
13211263

                  
                
1322 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1323 uint add(uint 36, uint 262144),
1324 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1325 i8* getelementptr ([5 x i8]* %str1, int 0, int 0),
1326 { }* null,
1327 int 0,
1328 uint 32,
1329 uint 32,
1330 uint 0,
1331 uint 2 }, section "llvm.metadata"
1332 %str1 = internal constant [5 x i8] c"bool\00", section "llvm.metadata"
1264 !2 = metadata !{
1265 i32 458788, ;; Tag
1266 metadata !1, ;; Context
1267 metadata !"bool", ;; Name
1268 metadata !1, ;; Compile Unit
1269 i32 0, ;; Line number
1270 i64 8, ;; Size in Bits
1271 i64 8, ;; Align in Bits
1272 i64 0, ;; Offset in Bits
1273 i32 0, ;; Flags
1274 i32 2 ;; Encoding
1275 }
13331276
13341277
13351278
13441287
13451288
13461289

                  
                
1347 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1348 uint add(uint 36, uint 262144),
1349 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1350 i8* getelementptr ([5 x i8]* %str1, int 0, int 0),
1351 { }* null,
1352 int 0,
1353 uint 8,
1354 uint 8,
1355 uint 0,
1356 uint 6 }, section "llvm.metadata"
1357 %str1 = internal constant [5 x i8] c"char\00", section "llvm.metadata"
1290 !2 = metadata !{
1291 i32 458788, ;; Tag
1292 metadata !1, ;; Context
1293 metadata !"char", ;; Name
1294 metadata !1, ;; Compile Unit
1295 i32 0, ;; Line number
1296 i64 8, ;; Size in Bits
1297 i64 8, ;; Align in Bits
1298 i64 0, ;; Offset in Bits
1299 i32 0, ;; Flags
1300 i32 6 ;; Encoding
1301 }
13581302
13591303
13601304
13691313
13701314
13711315

                  
                
1372 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1373 uint add(uint 36, uint 262144),
1374 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1375 i8* getelementptr ([14 x i8]* %str1, int 0, int 0),
1376 { }* null,
1377 int 0,
1378 uint 8,
1379 uint 8,
1380 uint 0,
1381 uint 8 }, section "llvm.metadata"
1382 %str1 = internal constant [14 x i8] c"unsigned char\00", section "llvm.metadata"
1316 !2 = metadata !{
1317 i32 458788, ;; Tag
1318 metadata !1, ;; Context
1319 metadata !"unsigned char",
1320 metadata !1, ;; Compile Unit
1321 i32 0, ;; Line number
1322 i64 8, ;; Size in Bits
1323 i64 8, ;; Align in Bits
1324 i64 0, ;; Offset in Bits
1325 i32 0, ;; Flags
1326 i32 8 ;; Encoding
1327 }
13831328
13841329
13851330
13941339
13951340
13961341

                  
                
1397 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1398 uint add(uint 36, uint 262144),
1399 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1400 i8* getelementptr ([10 x i8]* %str1, int 0, int 0),
1401 { }* null,
1402 int 0,
1403 uint 16,
1404 uint 16,
1405 uint 0,
1406 uint 5 }, section "llvm.metadata"
1407 %str1 = internal constant [10 x i8] c"short int\00", section "llvm.metadata"
1342 !2 = metadata !{
1343 i32 458788, ;; Tag
1344 metadata !1, ;; Context
1345 metadata !"short int",
1346 metadata !1, ;; Compile Unit
1347 i32 0, ;; Line number
1348 i64 16, ;; Size in Bits
1349 i64 16, ;; Align in Bits
1350 i64 0, ;; Offset in Bits
1351 i32 0, ;; Flags
1352 i32 5 ;; Encoding
1353 }
14081354
14091355
14101356
14191365
14201366
14211367

                  
                
1422 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1423 uint add(uint 36, uint 262144),
1424 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1425 i8* getelementptr ([19 x i8]* %str1, int 0, int 0),
1426 { }* null,
1427 int 0,
1428 uint 16,
1429 uint 16,
1430 uint 0,
1431 uint 7 }, section "llvm.metadata"
1432 %str1 = internal constant [19 x i8] c"short unsigned int\00", section "llvm.metadata"
1368 !2 = metadata !{
1369 i32 458788, ;; Tag
1370 metadata !1, ;; Context
1371 metadata !"short unsigned int",
1372 metadata !1, ;; Compile Unit
1373 i32 0, ;; Line number
1374 i64 16, ;; Size in Bits
1375 i64 16, ;; Align in Bits
1376 i64 0, ;; Offset in Bits
1377 i32 0, ;; Flags
1378 i32 7 ;; Encoding
1379 }
14331380
14341381
14351382
14441391
14451392
14461393

                  
                
1447 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1448 uint add(uint 36, uint 262144),
1449 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1450 i8* getelementptr ([4 x i8]* %str1, int 0, int 0),
1451 { }* null,
1452 int 0,
1453 uint 32,
1454 uint 32,
1455 uint 0,
1456 uint 5 }, section "llvm.metadata"
1457 %str1 = internal constant [4 x i8] c"int\00", section "llvm.metadata"
1394 !2 = metadata !{
1395 i32 458788, ;; Tag
1396 metadata !1, ;; Context
1397 metadata !"int", ;; Name
1398 metadata !1, ;; Compile Unit
1399 i32 0, ;; Line number
1400 i64 32, ;; Size in Bits
1401 i64 32, ;; Align in Bits
1402 i64 0, ;; Offset in Bits
1403 i32 0, ;; Flags
1404 i32 5 ;; Encoding
1405 }
14581406
14591407
14601408
14681416
14691417
14701418

                  
                
1471 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1472 uint add(uint 36, uint 262144),
1473 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1474 i8* getelementptr ([13 x i8]* %str1, int 0, int 0),
1475 { }* null,
1476 int 0,
1477 uint 32,
1478 uint 32,
1479 uint 0,
1480 uint 7 }, section "llvm.metadata"
1481 %str1 = internal constant [13 x i8] c"unsigned int\00", section "llvm.metadata"
1419 !2 = metadata !{
1420 i32 458788, ;; Tag
1421 metadata !1, ;; Context
1422 metadata !"unsigned int",
1423 metadata !1, ;; Compile Unit
1424 i32 0, ;; Line number
1425 i64 32, ;; Size in Bits
1426 i64 32, ;; Align in Bits
1427 i64 0, ;; Offset in Bits
1428 i32 0, ;; Flags
1429 i32 7 ;; Encoding
1430 }
14821431
14831432
14841433
14931442
14941443
14951444

                  
                
1496 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1497 uint add(uint 36, uint 262144),
1498 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1499 i8* getelementptr ([14 x i8]* %str1, int 0, int 0),
1500 { }* null,
1501 int 0,
1502 uint 64,
1503 uint 64,
1504 uint 0,
1505 uint 5 }, section "llvm.metadata"
1506 %str1 = internal constant [14 x i8] c"long long int\00", section "llvm.metadata"
1445 !2 = metadata !{
1446 i32 458788, ;; Tag
1447 metadata !1, ;; Context
1448 metadata !"long long int",
1449 metadata !1, ;; Compile Unit
1450 i32 0, ;; Line number
1451 i64 64, ;; Size in Bits
1452 i64 64, ;; Align in Bits
1453 i64 0, ;; Offset in Bits
1454 i32 0, ;; Flags
1455 i32 5 ;; Encoding
1456 }
15071457
15081458
15091459
15181468
15191469
15201470

                  
                
1521 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1522 uint add(uint 36, uint 262144),
1523 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1524 i8* getelementptr ([23 x i8]* %str1, int 0, int 0),
1525 { }* null,
1526 int 0,
1527 uint 64,
1528 uint 64,
1529 uint 0,
1530 uint 7 }, section "llvm.metadata"
1531 %str1 = internal constant [23 x 8] c"long long unsigned int\00", section "llvm.metadata"
1471 !2 = metadata !{
1472 i32 458788, ;; Tag
1473 metadata !1, ;; Context
1474 metadata !"long long unsigned int",
1475 metadata !1, ;; Compile Unit
1476 i32 0, ;; Line number
1477 i64 64, ;; Size in Bits
1478 i64 64, ;; Align in Bits
1479 i64 0, ;; Offset in Bits
1480 i32 0, ;; Flags
1481 i32 7 ;; Encoding
1482 }
15321483
15331484
15341485
15431494
15441495
15451496

                  
                
1546 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1547 uint add(uint 36, uint 262144),
1548 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1549 i8* getelementptr ([6 x i8]* %str1, int 0, int 0),
1550 { }* null,
1551 int 0,
1552 uint 32,
1553 uint 32,
1554 uint 0,
1555 uint 4 }, section "llvm.metadata"
1556 %str1 = internal constant [6 x i8] c"float\00", section "llvm.metadata"
1497 !2 = metadata !{
1498 i32 458788, ;; Tag
1499 metadata !1, ;; Context
1500 metadata !"float",
1501 metadata !1, ;; Compile Unit
1502 i32 0, ;; Line number
1503 i64 32, ;; Size in Bits
1504 i64 32, ;; Align in Bits
1505 i64 0, ;; Offset in Bits
1506 i32 0, ;; Flags
1507 i32 4 ;; Encoding
1508 }
15571509
15581510
15591511
15681520
15691521
15701522

                  
                
1571 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1572 uint add(uint 36, uint 262144),
1573 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1574 8* getelementptr ([7 x 8]* %str1, int 0, int 0),
1575 { }* null,
1576 int 0,
1577 uint 64,
1578 uint 64,
1579 uint 0,
1580 uint 4 }, section "llvm.metadata"
1581 %str1 = internal constant [7 x 8] c"double\00", section "llvm.metadata"
1523 !2 = metadata !{
1524 i32 458788, ;; Tag
1525 metadata !1, ;; Context
1526 metadata !"double",;; Name
1527 metadata !1, ;; Compile Unit
1528 i32 0, ;; Line number
1529 i64 64, ;; Size in Bits
1530 i64 64, ;; Align in Bits
1531 i64 0, ;; Offset in Bits
1532 i32 0, ;; Flags
1533 i32 4 ;; Encoding
1534 }
15821535
15831536
15841537
16061559 ;;
16071560 ;; Define the typedef "IntPtr".
16081561 ;;
1609 %llvm.dbg.derivedtype1 = internal constant %llvm.dbg.derivedtype.type {
1610 uint add(uint 22, uint 262144),
1611 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1612 i8* getelementptr ([7 x 8]* %str1, int 0, int 0),
1613 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1614 int 1,
1615 uint 0,
1616 uint 0,
1617 uint 0,
1618 { }* cast (%llvm.dbg.derivedtype.type* %llvm.dbg.derivedtype2 to { }*) }, section "llvm.metadata"
1619 %str1 = internal constant [7 x 8] c"IntPtr\00", section "llvm.metadata"
1562 !2 = metadata !{
1563 i32 458774, ;; Tag
1564 metadata !1, ;; Context
1565 metadata !"IntPtr", ;; Name
1566 metadata !3, ;; Compile unit
1567 i32 0, ;; Line number
1568 i64 0, ;; Size in bits
1569 i64 0, ;; Align in bits
1570 i64 0, ;; Offset in bits
1571 i32 0, ;; Flags
1572 metadata !4 ;; Derived From type
1573 }
16201574
16211575 ;;
16221576 ;; Define the pointer type.
16231577 ;;
1624 %llvm.dbg.derivedtype2 = internal constant %llvm.dbg.derivedtype.type {
1625 uint add(uint 15, uint 262144),
1626 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1627 i8* null,
1628 { }* null,
1629 int 0,
1630 uint 32,
1631 uint 32,
1632 uint 0,
1633 { }* cast (%llvm.dbg.derivedtype.type* %llvm.dbg.derivedtype3 to { }*) }, section "llvm.metadata"
1634
1578 !4 = metadata !{
1579 i32 458767, ;; Tag
1580 metadata !1, ;; Context
1581 metadata !"", ;; Name
1582 metadata !1, ;; Compile unit
1583 i32 0, ;; Line number
1584 i64 64, ;; Size in bits
1585 i64 64, ;; Align in bits
1586 i64 0, ;; Offset in bits
1587 i32 0, ;; Flags
1588 metadata !5 ;; Derived From type
1589 }
16351590 ;;
16361591 ;; Define the const type.
16371592 ;;
1638 %llvm.dbg.derivedtype3 = internal constant %llvm.dbg.derivedtype.type {
1639 uint add(uint 38, uint 262144),
1640 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1641 i8* null,
1642 { }* null,
1643 int 0,
1644 uint 0,
1645 uint 0,
1646 uint 0,
1647 { }* cast (%llvm.dbg.basictype.type* %llvm.dbg.basictype1 to { }*) }, section "llvm.metadata"
1648
1593 !5 = metadata !{
1594 i32 458790, ;; Tag
1595 metadata !1, ;; Context
1596 metadata !"", ;; Name
1597 metadata !1, ;; Compile unit
1598 i32 0, ;; Line number
1599 i64 32, ;; Size in bits
1600 i64 32, ;; Align in bits
1601 i64 0, ;; Offset in bits
1602 i32 0, ;; Flags
1603 metadata !6 ;; Derived From type
1604 }
16491605 ;;
16501606 ;; Define the int type.
16511607 ;;
1652 %llvm.dbg.basictype1 = internal constant %llvm.dbg.basictype.type {
1653 uint add(uint 36, uint 262144),
1654 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1655 8* getelementptr ([4 x 8]* %str2, int 0, int 0),
1656 { }* null,
1657 int 0,
1658 uint 32,
1659 uint 32,
1660 uint 0,
1661 uint 5 }, section "llvm.metadata"
1662 %str2 = internal constant [4 x 8] c"int\00", section "llvm.metadata"
1608 !6 = metadata !{
1609 i32 458788, ;; Tag
1610 metadata !1, ;; Context
1611 metadata !"int", ;; Name
1612 metadata !1, ;; Compile unit
1613 i32 0, ;; Line number
1614 i64 32, ;; Size in bits
1615 i64 32, ;; Align in bits
1616 i64 0, ;; Offset in bits
1617 i32 0, ;; Flags
1618 5 ;; Encoding
1619 }
16631620
16641621
16651622
16911648 ;;
16921649 ;; Define basic type for unsigned int.
16931650 ;;
1694 %llvm.dbg.basictype = internal constant %llvm.dbg.basictype.type {
1695 uint add(uint 36, uint 262144),
1696 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1697 i8* getelementptr ([13 x i8]* %str1, int 0, int 0),
1698 { }* null,
1699 int 0,
1700 uint 32,
1701 uint 32,
1702 uint 0,
1703 uint 7 }, section "llvm.metadata"
1704 %str1 = internal constant [13 x i8] c"unsigned int\00", section "llvm.metadata"
1705
1651 !5 = metadata !{
1652 i32 458788, ;; Tag
1653 metadata !1, ;; Context
1654 metadata !"unsigned int",
1655 metadata !1, ;; Compile Unit
1656 i32 0, ;; Line number
1657 i64 32, ;; Size in Bits
1658 i64 32, ;; Align in Bits
1659 i64 0, ;; Offset in Bits
1660 i32 0, ;; Flags
1661 i32 7 ;; Encoding
1662 }
17061663 ;;
17071664 ;; Define composite type for struct Color.
17081665 ;;
1709 %llvm.dbg.compositetype = internal constant %llvm.dbg.compositetype.type {
1710 uint add(uint 19, uint 262144),
1711 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1712 i8* getelementptr ([6 x i8]* %str2, int 0, int 0),
1713 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1714 int 1,
1715 uint 96,
1716 uint 32,
1717 uint 0,
1718 { }* null,
1719 { }* cast ([3 x { }*]* %llvm.dbg.array to { }*) }, section "llvm.metadata"
1720 %str2 = internal constant [6 x i8] c"Color\00", section "llvm.metadata"
1666 !2 = metadata !{
1667 i32 458771, ;; Tag
1668 metadata !1, ;; Context
1669 metadata !"Color", ;; Name
1670 metadata !1, ;; Compile unit
1671 i32 1, ;; Line number
1672 i64 96, ;; Size in bits
1673 i64 32, ;; Align in bits
1674 i64 0, ;; Offset in bits
1675 i32 0, ;; Flags
1676 null, ;; Derived From
1677 metadata !3, ;; Elements
1678 i32 0 ;; Runtime Language
1679 }
17211680
17221681 ;;
17231682 ;; Define the Red field.
17241683 ;;
1725 %llvm.dbg.derivedtype1 = internal constant %llvm.dbg.derivedtype.type {
1726 uint add(uint 13, uint 262144),
1727 { }* null,
1728 i8* getelementptr ([4 x i8]* %str3, int 0, int 0),
1729 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1730 int 2,
1731 uint 32,
1732 uint 32,
1733 uint 0,
1734 { }* cast (%llvm.dbg.basictype.type* %llvm.dbg.basictype to { }*) }, section "llvm.metadata"
1735 %str3 = internal constant [4 x i8] c"Red\00", section "llvm.metadata"
1684 !4 = metadata !{
1685 i32 458765, ;; Tag
1686 metadata !1, ;; Context
1687 metadata !"Red", ;; Name
1688 metadata !1, ;; Compile Unit
1689 i32 2, ;; Line number
1690 i64 32, ;; Size in bits
1691 i64 32, ;; Align in bits
1692 i64 0, ;; Offset in bits
1693 i32 0, ;; Flags
1694 metadata !5 ;; Derived From type
1695 }
17361696
17371697 ;;
17381698 ;; Define the Green field.
17391699 ;;
1740 %llvm.dbg.derivedtype2 = internal constant %llvm.dbg.derivedtype.type {
1741 uint add(uint 13, uint 262144),
1742 { }* null,
1743 i8* getelementptr ([6 x i8]* %str4, int 0, int 0),
1744 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1745 int 3,
1746 uint 32,
1747 uint 32,
1748 uint 32,
1749 { }* cast (%llvm.dbg.basictype.type* %llvm.dbg.basictype to { }*) }, section "llvm.metadata"
1750 %str4 = internal constant [6 x i8] c"Green\00", section "llvm.metadata"
1700 !6 = metadata !{
1701 i32 458765, ;; Tag
1702 metadata !1, ;; Context
1703 metadata !"Green", ;; Name
1704 metadata !1, ;; Compile Unit
1705 i32 3, ;; Line number
1706 i64 32, ;; Size in bits
1707 i64 32, ;; Align in bits
1708 i64 32, ;; Offset in bits
1709 i32 0, ;; Flags
1710 metadata !5 ;; Derived From type
1711 }
17511712
17521713 ;;
17531714 ;; Define the Blue field.
17541715 ;;
1755 %llvm.dbg.derivedtype3 = internal constant %llvm.dbg.derivedtype.type {
1756 uint add(uint 13, uint 262144),
1757 { }* null,
1758 i8* getelementptr ([5 x i8]* %str5, int 0, int 0),
1759 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1760 int 4,
1761 uint 32,
1762 uint 32,
1763 uint 64,
1764 { }* cast (%llvm.dbg.basictype.type* %llvm.dbg.basictype to { }*) }, section "llvm.metadata"
1765 %str5 = internal constant [5 x 8] c"Blue\00", section "llvm.metadata"
1716 !7 = metadata !{
1717 i32 458765, ;; Tag
1718 metadata !1, ;; Context
1719 metadata !"Blue", ;; Name
1720 metadata !1, ;; Compile Unit
1721 i32 4, ;; Line number
1722 i64 32, ;; Size in bits
1723 i64 32, ;; Align in bits
1724 i64 64, ;; Offset in bits
1725 i32 0, ;; Flags
1726 metadata !5 ;; Derived From type
1727 }
17661728
17671729 ;;
17681730 ;; Define the array of fields used by the composite type Color.
17691731 ;;
1770 %llvm.dbg.array = internal constant [3 x { }*] [
1771 { }* cast (%llvm.dbg.derivedtype.type* %llvm.dbg.derivedtype1 to { }*),
1772 { }* cast (%llvm.dbg.derivedtype.type* %llvm.dbg.derivedtype2 to { }*),
1773 { }* cast (%llvm.dbg.derivedtype.type* %llvm.dbg.derivedtype3 to { }*) ], section "llvm.metadata"
1732 !3 = metadata !{metadata !4, metadata !6, metadata !7}
17741733
17751734
17761735
18021761 ;;
18031762 ;; Define composite type for enum Trees
18041763 ;;
1805 %llvm.dbg.compositetype = internal constant %llvm.dbg.compositetype.type {
1806 uint add(uint 4, uint 262144),
1807 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1808 i8* getelementptr ([6 x i8]* %str1, int 0, int 0),
1809 { }* cast (%llvm.dbg.compile_unit.type* %llvm.dbg.compile_unit to { }*),
1810 int 1,
1811 uint 32,
1812 uint 32,
1813 uint 0,
1814 { }* null,
1815 { }* cast ([3 x { }*]* %llvm.dbg.array to { }*) }, section "llvm.metadata"
1816 %str1 = internal constant [6 x i8] c"Trees\00", section "llvm.metadata"
1764 !2 = metadata !{
1765 i32 458756, ;; Tag
1766 metadata !1, ;; Context
1767 metadata !"Trees", ;; Name
1768 metadata !1, ;; Compile unit
1769 i32 1, ;; Line number
1770 i64 32, ;; Size in bits
1771 i64 32, ;; Align in bits
1772 i64 0, ;; Offset in bits
1773 i32 0, ;; Flags
1774 null, ;; Derived From type
1775 metadata !3, ;; Elements
1776 i32 0 ;; Runtime language
1777 }
1778
1779 ;;
1780 ;; Define the array of enumerators used by composite type Trees.
1781 ;;
1782 !3 = metadata !{metadata !4, metadata !5, metadata !6}
18171783
18181784 ;;
18191785 ;; Define Spruce enumerator.
18201786 ;;
1821 %llvm.dbg.enumerator1 = internal constant %llvm.dbg.enumerator.type {
1822 uint add(uint 40, uint 262144),
1823 i8* getelementptr ([7 x i8]* %str2, int 0, int 0),
1824 int 100 }, section "llvm.metadata"
1825 %str2 = internal constant [7 x i8] c"Spruce\00", section "llvm.metadata"
1787 !4 = metadata !{i32 458792, metadata !"Spruce", i64 100}
18261788
18271789 ;;
18281790 ;; Define Oak enumerator.
18291791 ;;
1830 %llvm.dbg.enumerator2 = internal constant %llvm.dbg.enumerator.type {
1831 uint add(uint 40, uint 262144),
1832 i8* getelementptr ([4 x i8]* %str3, int 0, int 0),
1833 int 200 }, section "llvm.metadata"
1834 %str3 = internal constant [4 x i8] c"Oak\00", section "llvm.metadata"
1792 !5 = metadata !{i32 458792, metadata !"Oak", i64 200}
18351793
18361794 ;;
18371795 ;; Define Maple enumerator.
18381796 ;;
1839 %llvm.dbg.enumerator3 = internal constant %llvm.dbg.enumerator.type {
1840 uint add(uint 40, uint 262144),
1841 i8* getelementptr ([6 x i8]* %str4, int 0, int 0),
1842 int 300 }, section "llvm.metadata"
1843 %str4 = internal constant [6 x i8] c"Maple\00", section "llvm.metadata"
1844
1845 ;;
1846 ;; Define the array of enumerators used by composite type Trees.
1847 ;;
1848 %llvm.dbg.array = internal constant [3 x { }*] [
1849 { }* cast (%llvm.dbg.enumerator.type* %llvm.dbg.enumerator1 to { }*),
1850 { }* cast (%llvm.dbg.enumerator.type* %llvm.dbg.enumerator2 to { }*),
1851 { }* cast (%llvm.dbg.enumerator.type* %llvm.dbg.enumerator3 to { }*) ], section "llvm.metadata"
1797 !6 = metadata !{i32 458792, metadata !"Maple", i64 300}
1798
18521799
18531800
18541801
1616 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
1717 #define LLVM_ANALYSIS_DEBUGINFO_H
1818
19 #include "llvm/Metadata.h"
1920 #include "llvm/Target/TargetMachine.h"
2021 #include "llvm/ADT/StringMap.h"
2122 #include "llvm/ADT/DenseMap.h"
4344
4445 class DIDescriptor {
4546 protected:
46 GlobalVariable *DbgGV;
47
48 /// DIDescriptor constructor. If the specified GV is non-null, this checks
47 MDNode *DbgNode;
48
49 /// DIDescriptor constructor. If the specified node is non-null, check
4950 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
5051 /// not, the debug info is corrupt and we ignore it.
51 DIDescriptor(GlobalVariable *GV, unsigned RequiredTag);
52 DIDescriptor(MDNode *N, unsigned RequiredTag);
5253
5354 const std::string &getStringField(unsigned Elt, std::string &Result) const;
5455 unsigned getUnsignedField(unsigned Elt) const {
5960
6061 template
6162 DescTy getFieldAs(unsigned Elt) const {
62 return DescTy(getDescriptorField(Elt).getGV());
63 return DescTy(getDescriptorField(Elt).getNode());
6364 }
6465
6566 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
6667
6768 public:
68 explicit DIDescriptor() : DbgGV(0) {}
69 explicit DIDescriptor(GlobalVariable *GV) : DbgGV(GV) {}
70
71 bool isNull() const { return DbgGV == 0; }
72
73 GlobalVariable *getGV() const { return DbgGV; }
69 explicit DIDescriptor() : DbgNode(0) {}
70 explicit DIDescriptor(MDNode *N) : DbgNode(N) {}
71
72 bool isNull() const { return DbgNode == 0; }
73
74 MDNode *getNode() const { return DbgNode; }
7475
7576 unsigned getVersion() const {
7677 return getUnsignedField(0) & LLVMDebugVersionMask;
8081 return getUnsignedField(0) & ~LLVMDebugVersionMask;
8182 }
8283
83 /// ValidDebugInfo - Return true if V represents valid debug info value.
84 static bool ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel);
84 /// ValidDebugInfo - Return true if N represents valid debug info value.
85 static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel);
8586
8687 /// dump - print descriptor.
8788 void dump() const;
9091 /// DISubrange - This is used to represent ranges, for array bounds.
9192 class DISubrange : public DIDescriptor {
9293 public:
93 explicit DISubrange(GlobalVariable *GV = 0)
94 : DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {}
94 explicit DISubrange(MDNode *N = 0)
95 : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
9596
9697 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
9798 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
100101 /// DIArray - This descriptor holds an array of descriptors.
101102 class DIArray : public DIDescriptor {
102103 public:
103 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
104 explicit DIArray(MDNode *N = 0)
105 : DIDescriptor(N) {}
104106
105107 unsigned getNumElements() const;
106108 DIDescriptor getElement(unsigned Idx) const {
111113 /// DICompileUnit - A wrapper for a compile unit.
112114 class DICompileUnit : public DIDescriptor {
113115 public:
114 explicit DICompileUnit(GlobalVariable *GV = 0)
115 : DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {}
116 explicit DICompileUnit(MDNode *N = 0)
117 : DIDescriptor(N, dwarf::DW_TAG_compile_unit) {}
116118
117119 unsigned getLanguage() const { return getUnsignedField(2); }
118120 const std::string &getFilename(std::string &F) const {
153155 /// type/precision or a file/line pair for location info.
154156 class DIEnumerator : public DIDescriptor {
155157 public:
156 explicit DIEnumerator(GlobalVariable *GV = 0)
157 : DIDescriptor(GV, dwarf::DW_TAG_enumerator) {}
158 explicit DIEnumerator(MDNode *N = 0)
159 : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
158160
159161 const std::string &getName(std::string &F) const {
160162 return getStringField(1, F);
175177 };
176178
177179 protected:
178 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
180 DIType(MDNode *N, unsigned Tag)
181 : DIDescriptor(N, Tag) {}
179182 // This ctor is used when the Tag has already been validated by a derived
180183 // ctor.
181 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
184 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
182185
183186 public:
184187 /// isDerivedType - Return true if the specified tag is legal for
198201 /// Verify - Verify that a type descriptor is well formed.
199202 bool Verify() const;
200203 public:
201 explicit DIType(GlobalVariable *GV);
204 explicit DIType(MDNode *N);
202205 explicit DIType() {}
203206 virtual ~DIType() {}
204207
235238 /// DIBasicType - A basic type, like 'int' or 'float'.
236239 class DIBasicType : public DIType {
237240 public:
238 explicit DIBasicType(GlobalVariable *GV)
239 : DIType(GV, dwarf::DW_TAG_base_type) {}
241 explicit DIBasicType(MDNode *N = 0)
242 : DIType(N, dwarf::DW_TAG_base_type) {}
240243
241244 unsigned getEncoding() const { return getUnsignedField(9); }
242245
248251 /// a typedef, a pointer or reference, etc.
249252 class DIDerivedType : public DIType {
250253 protected:
251 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
252 : DIType(GV, true, true) {}
253 public:
254 explicit DIDerivedType(GlobalVariable *GV)
255 : DIType(GV, true, true) {
256 if (GV && !isDerivedType(getTag()))
257 DbgGV = 0;
254 explicit DIDerivedType(MDNode *N, bool, bool)
255 : DIType(N, true, true) {}
256 public:
257 explicit DIDerivedType(MDNode *N = 0)
258 : DIType(N, true, true) {
259 if (DbgNode && !isDerivedType(getTag()))
260 DbgNode = 0;
258261 }
259262
260263 DIType getTypeDerivedFrom() const { return getFieldAs(9); }
276279 /// FIXME: Why is this a DIDerivedType??
277280 class DICompositeType : public DIDerivedType {
278281 public:
279 explicit DICompositeType(GlobalVariable *GV)
280 : DIDerivedType(GV, true, true) {
281 if (GV && !isCompositeType(getTag()))
282 DbgGV = 0;
282 explicit DICompositeType(MDNode *N = 0)
283 : DIDerivedType(N, true, true) {
284 if (N && !isCompositeType(getTag()))
285 DbgNode = 0;
283286 }
284287
285288 DIArray getTypeArray() const { return getFieldAs(10); }
295298 /// DIGlobal - This is a common class for global variables and subprograms.
296299 class DIGlobal : public DIDescriptor {
297300 protected:
298 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
299 : DIDescriptor(GV, RequiredTag) {}
301 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
302 : DIDescriptor(N, RequiredTag) {}
300303
301304 /// isSubprogram - Return true if the specified tag is legal for
302305 /// DISubprogram.
339342 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
340343 class DISubprogram : public DIGlobal {
341344 public:
342 explicit DISubprogram(GlobalVariable *GV = 0)
343 : DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
345 explicit DISubprogram(MDNode *N = 0)
346 : DIGlobal(N, dwarf::DW_TAG_subprogram) {}
344347
345348 DICompositeType getType() const { return getFieldAs(8); }
346349
350353 DICompositeType DCT(getFieldAs(8));
351354 if (!DCT.isNull()) {
352355 DIArray A = DCT.getTypeArray();
353 DIType T(A.getElement(0).getGV());
356 DIType T(A.getElement(0).getNode());
354357 return T.getName(F);
355358 }
356359 DIType T(getFieldAs(8));
371374 /// DIGlobalVariable - This is a wrapper for a global variable.
372375 class DIGlobalVariable : public DIGlobal {
373376 public:
374 explicit DIGlobalVariable(GlobalVariable *GV = 0)
375 : DIGlobal(GV, dwarf::DW_TAG_variable) {}
377 explicit DIGlobalVariable(MDNode *N = 0)
378 : DIGlobal(N, dwarf::DW_TAG_variable) {}
376379
377380 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
378381
387390 /// global etc).
388391 class DIVariable : public DIDescriptor {
389392 public:
390 explicit DIVariable(GlobalVariable *GV = 0)
391 : DIDescriptor(GV) {
392 if (GV && !isVariable(getTag()))
393 DbgGV = 0;
393 explicit DIVariable(MDNode *N = 0)
394 : DIDescriptor(N) {
395 if (DbgNode && !isVariable(getTag()))
396 DbgNode = 0;
394397 }
395398
396399 DIDescriptor getContext() const { return getDescriptorField(1); }
414417 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
415418 class DIBlock : public DIDescriptor {
416419 public:
417 explicit DIBlock(GlobalVariable *GV = 0)
418 : DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
420 explicit DIBlock(MDNode *N = 0)
421 : DIDescriptor(N, dwarf::DW_TAG_lexical_block) {}
419422
420423 DIDescriptor getContext() const { return getDescriptorField(1); }
421424 };
542545
543546 private:
544547 Constant *GetTagConstant(unsigned TAG);
545 Constant *GetStringConstant(const std::string &String);
546
547 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
548 Constant *getCastToEmpty(DIDescriptor D);
549548 };
550549
551550 /// Finds the stoppoint coressponding to this instruction, that is the
607606
608607 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
609608 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
610
611609 /// DebugInfoFinder - This object collects DebugInfo from a module.
612610 class DebugInfoFinder {
613611
651649 bool addType(DIType DT);
652650
653651 public:
654 typedef SmallVector<GlobalVariable *, 8>::iterator iterator;
652 typedef SmallVector<MDNode *, 8>::iterator iterator;
655653 iterator compile_unit_begin() { return CUs.begin(); }
656654 iterator compile_unit_end() { return CUs.end(); }
657655 iterator subprogram_begin() { return SPs.begin(); }
667665 unsigned type_count() { return TYs.size(); }
668666
669667 private:
670 SmallVector CUs; // Compile Units
671 SmallVector SPs; // Subprograms
672 SmallVector GVs; // Global Variables
673 SmallVector TYs; // Types
674 SmallPtrSet NodesSeen;
675
668 SmallVector CUs; // Compile Units
669 SmallVector SPs; // Subprograms
670 SmallVector GVs; // Global Variables;
671 SmallVector TYs; // Types
672 SmallPtrSet NodesSeen;
676673 };
677674 } // end namespace llvm
678675
1414 #define LLVM_AUTOUPGRADE_H
1515
1616 namespace llvm {
17 class Module;
1718 class Function;
1819 class CallInst;
1920
3334 /// so that it can update all calls to the old function.
3435 void UpgradeCallsToIntrinsic(Function* F);
3536
37 /// This function checks debug info intrinsics. If an intrinsic is invalid
38 /// then this function simply removes the intrinsic.
39 void CheckDebugInfoIntrinsics(Module *M);
3640 } // End llvm namespace
3741
3842 #endif
3232 class MachineInstr;
3333 class Value;
3434 class Module;
35 class GlobalVariable;
35 class MDNode;
3636 class MCAsmInfo;
3737 class raw_ostream;
3838 class Instruction;
8787 unsigned RecordSourceLine(unsigned Line, unsigned Col, DICompileUnit CU);
8888
8989 /// RecordRegionStart - Indicate the start of a region.
90 unsigned RecordRegionStart(GlobalVariable *V);
90 unsigned RecordRegionStart(MDNode *N);
9191
9292 /// RecordRegionEnd - Indicate the end of a region.
93 unsigned RecordRegionEnd(GlobalVariable *V);
93 unsigned RecordRegionEnd(MDNode *N);
9494
9595 /// getRecordSourceLineCount - Count source lines.
9696 unsigned getRecordSourceLineCount();
9797
9898 /// RecordVariable - Indicate the declaration of a local variable.
9999 ///
100 void RecordVariable(GlobalVariable *GV, unsigned FrameIndex);
100 void RecordVariable(MDNode *N, unsigned FrameIndex);
101101
102102 /// ShouldEmitDwarfDebug - Returns true if Dwarf debugging declarations should
103103 /// be emitted.
326326 /// getOrCreateDebugLocID - Look up the DebugLocTuple index with the given
327327 /// source file, line, and column. If none currently exists, create a new
328328 /// DebugLocTuple, and insert it into the DebugIdMap.
329 unsigned getOrCreateDebugLocID(GlobalVariable *CompileUnit,
329 unsigned getOrCreateDebugLocID(MDNode *CompileUnit,
330330 unsigned Line, unsigned Col);
331331
332332 /// getDebugLocTuple - Get the DebugLocTuple for a given DebugLoc object.
321321 SDValue getValueType(EVT);
322322 SDValue getRegister(unsigned Reg, EVT VT);
323323 SDValue getDbgStopPoint(DebugLoc DL, SDValue Root,
324 unsigned Line, unsigned Col, Value *CU);
324 unsigned Line, unsigned Col, MDNode *CU);
325325 SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root,
326326 unsigned LabelID);
327327
20152015 SDUse Chain;
20162016 unsigned Line;
20172017 unsigned Column;
2018 Value *CU;
2018 MDNode *CU;
20192019 friend class SelectionDAG;
20202020 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2021 Value *cu)
2021 MDNode *cu)
20222022 : SDNode(ISD::DBG_STOPPOINT, DebugLoc::getUnknownLoc(),
20232023 getSDVTList(MVT::Other)), Line(l), Column(c), CU(cu) {
20242024 InitOperands(&Chain, ch);
20262026 public:
20272027 unsigned getLine() const { return Line; }
20282028 unsigned getColumn() const { return Column; }
2029 Value *getCompileUnit() const { return CU; }
2029 MDNode *getCompileUnit() const { return CU; }
20302030
20312031 static bool classof(const DbgStopPointSDNode *) { return true; }
20322032 static bool classof(const SDNode *N) {
2424 #define LLVM_INTRINSICINST_H
2525
2626 #include "llvm/Constants.h"
27 #include "llvm/Metadata.h"
2728 #include "llvm/Function.h"
2829 #include "llvm/Instructions.h"
2930 #include "llvm/Intrinsics.h"
8485 struct DbgStopPointInst : public DbgInfoIntrinsic {
8586 Value *getLineValue() const { return const_cast(getOperand(1)); }
8687 Value *getColumnValue() const { return const_cast(getOperand(2)); }
87 Value *getContext() const {
88 return StripCast(getOperand(3));
88 MDNode *getContext() const {
89 return cast(getOperand(3));
8990 }
9091
9192 unsigned getLine() const {
111112 /// DbgFuncStartInst - This represents the llvm.dbg.func.start instruction.
112113 ///
113114 struct DbgFuncStartInst : public DbgInfoIntrinsic {
114 Value *getSubprogram() const { return StripCast(getOperand(1)); }
115 MDNode *getSubprogram() const { return cast(getOperand(1)); }
115116
116117 // Methods for support type inquiry through isa, cast, and dyn_cast:
117118 static inline bool classof(const DbgFuncStartInst *) { return true; }
126127 /// DbgRegionStartInst - This represents the llvm.dbg.region.start
127128 /// instruction.
128129 struct DbgRegionStartInst : public DbgInfoIntrinsic {
129 Value *getContext() const { return StripCast(getOperand(1)); }
130 MDNode *getContext() const { return cast(getOperand(1)); }
130131
131132 // Methods for support type inquiry through isa, cast, and dyn_cast:
132133 static inline bool classof(const DbgRegionStartInst *) { return true; }
141142 /// DbgRegionEndInst - This represents the llvm.dbg.region.end instruction.
142143 ///
143144 struct DbgRegionEndInst : public DbgInfoIntrinsic {
144 Value *getContext() const { return StripCast(getOperand(1)); }
145 MDNode *getContext() const { return cast(getOperand(1)); }
145146
146147 // Methods for support type inquiry through isa, cast, and dyn_cast:
147148 static inline bool classof(const DbgRegionEndInst *) { return true; }
157158 ///
158159 struct DbgDeclareInst : public DbgInfoIntrinsic {
159160 Value *getAddress() const { return getOperand(1); }
160 Value *getVariable() const { return StripCast(getOperand(2)); }
161 MDNode *getVariable() const { return cast(getOperand(2)); }
161162
162163 // Methods for support type inquiry through isa, cast, and dyn_cast:
163164 static inline bool classof(const DbgDeclareInst *) { return true; }
109109 def llvm_anyptr_ty : LLVMAnyPointerType; // (space)i8*
110110 def llvm_empty_ty : LLVMType; // { }
111111 def llvm_descriptor_ty : LLVMPointerType; // { }*
112 def llvm_metadata_ty : LLVMType; // !{...}
112113
113114 def llvm_v2i8_ty : LLVMType; // 2 x i8
114115 def llvm_v4i8_ty : LLVMType; // 4 x i8
277278 let Properties = [IntrNoMem] in {
278279 def int_dbg_stoppoint : Intrinsic<[llvm_void_ty],
279280 [llvm_i32_ty, llvm_i32_ty,
280 llvm_descriptor_ty]>;
281 def int_dbg_region_start : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty]>;
282 def int_dbg_region_end : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty]>;
283 def int_dbg_func_start : Intrinsic<[llvm_void_ty], [llvm_descriptor_ty]>;
281 llvm_metadata_ty]>;
282 def int_dbg_region_start : Intrinsic<[llvm_void_ty], [llvm_metadata_ty]>;
283 def int_dbg_region_end : Intrinsic<[llvm_void_ty], [llvm_metadata_ty]>;
284 def int_dbg_func_start : Intrinsic<[llvm_void_ty], [llvm_metadata_ty]>;
284285 def int_dbg_declare : Intrinsic<[llvm_void_ty],
285 [llvm_descriptor_ty, llvm_descriptor_ty]>;
286 [llvm_descriptor_ty, llvm_metadata_ty]>;
286287 }
287288
288289 //===------------------ Exception Handling Intrinsics----------------------===//
109109 unsigned getNumOperands() { return User::getNumOperands(); }
110110
111111 SmallVector Node;
112
113112 friend struct ConstantCreator >;
114113 protected:
115114 explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
1818 #include
1919
2020 namespace llvm {
21 class GlobalVariable;
21 class MDNode;
2222
2323 /// DebugLocTuple - Debug location tuple of filename id, line and column.
2424 ///
2525 struct DebugLocTuple {
26 GlobalVariable *CompileUnit;
26 MDNode *CompileUnit;
2727 unsigned Line, Col;
2828
2929 DebugLocTuple()
3030 : CompileUnit(0), Line(~0U), Col(~0U) {};
3131
32 DebugLocTuple(GlobalVariable *v, unsigned l, unsigned c)
33 : CompileUnit(v), Line(l), Col(c) {};
32 DebugLocTuple(MDNode *n, unsigned l, unsigned c)
33 : CompileUnit(n), Line(l), Col(c) {};
3434
3535 bool operator==(const DebugLocTuple &DLT) const {
3636 return CompileUnit == DLT.CompileUnit &&
6868 return DebugLocTuple(0, ~0U, ~0U);
6969 }
7070 static inline DebugLocTuple getTombstoneKey() {
71 return DebugLocTuple((GlobalVariable*)~1U, ~1U, ~1U);
71 return DebugLocTuple((MDNode*)~1U, ~1U, ~1U);
7272 }
7373 static unsigned getHashValue(const DebugLocTuple &Val) {
74 return DenseMapInfo<GlobalVariable*>::getHashValue(Val.CompileUnit) ^
74 return DenseMapInfo<MDNode*>::getHashValue(Val.CompileUnit) ^
7575 DenseMapInfo::getHashValue(Val.Line) ^
7676 DenseMapInfo::getHashValue(Val.Col);
7777 }
8989 }
9090
9191 void PrintDbgInfo::printFuncStart(const DbgFuncStartInst *FS) {
92 DISubprogram Subprogram(cast(FS->getSubprogram()));
92 DISubprogram Subprogram(FS->getSubprogram());
9393 std::string Res1, Res2;
9494 Out << "; fully qualified function name: " << Subprogram.getDisplayName(Res1)
9595 << " return type: " << Subprogram.getReturnTypeName(Res2)
2020 #include "llvm/LLVMContext.h"
2121 #include "llvm/Module.h"
2222 #include "llvm/Analysis/ValueTracking.h"
23 #include "llvm/ADT/SmallPtrSet.h"
2324 #include "llvm/Support/Dwarf.h"
2425 #include "llvm/Support/DebugLoc.h"
2526 #include "llvm/Support/raw_ostream.h"
3132 //===----------------------------------------------------------------------===//
3233
3334 /// ValidDebugInfo - Return true if V represents valid debug info value.
34 bool DIDescriptor::ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel) {
35 if (!V)
36 return false;
37
38 GlobalVariable *GV = dyn_cast(V->stripPointerCasts());
39 if (!GV)
40 return false;
41
42 if (!GV->hasInternalLinkage () && !GV->hasLinkOnceLinkage())
43 return false;
44
45 DIDescriptor DI(GV);
35 /// FIXME : Add DIDescriptor.isValid()
36 bool DIDescriptor::ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel) {
37 if (!N)
38 return false;
39
40 DIDescriptor DI(N);
4641
4742 // Check current version. Allow Version6 for now.
4843 unsigned Version = DI.getVersion();
5247 unsigned Tag = DI.getTag();
5348 switch (Tag) {
5449 case DW_TAG_variable:
55 assert(DIVariable(GV).Verify() && "Invalid DebugInfo value");
50 assert(DIVariable(N).Verify() && "Invalid DebugInfo value");
5651 break;
5752 case DW_TAG_compile_unit:
58 assert(DICompileUnit(GV).Verify() && "Invalid DebugInfo value");
53 assert(DICompileUnit(N).Verify() && "Invalid DebugInfo value");
5954 break;
6055 case DW_TAG_subprogram:
61 assert(DISubprogram(GV).Verify() && "Invalid DebugInfo value");
56 assert(DISubprogram(N).Verify() && "Invalid DebugInfo value");
6257 break;
6358 case DW_TAG_lexical_block:
6459 // FIXME: This interfers with the quality of generated code during
7368 return true;
7469 }
7570
76 DIDescriptor::DIDescriptor(GlobalVariable *GV, unsigned RequiredTag) {
77 DbgGV = GV;
71 DIDescriptor::DIDescriptor(MDNode *N, unsigned RequiredTag) {
72 DbgNode = N;
7873
7974 // If this is non-null, check to see if the Tag matches. If not, set to null.
80 if (GV && getTag() != RequiredTag)
81 DbgGV = 0;
75 if (N && getTag() != RequiredTag) {
76 DbgNode = 0;
77 }
8278 }
8379
8480 const std::string &
8581 DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
86 if (DbgGV == 0) {
87 Result.clear();
82 Result.clear();
83 if (DbgNode == 0)
8884 return Result;
89 }
90
91 Constant *C = DbgGV->getInitializer();
92 if (C == 0 || Elt >= C->getNumOperands()) {
93 Result.clear();
94 return Result;
95 }
96
97 // Fills in the string if it succeeds
98 if (!GetConstantStringInfo(C->getOperand(Elt), Result))
99 Result.clear();
100
85
86 if (Elt < DbgNode->getNumElements())
87 if (MDString *MDS = dyn_cast_or_null(DbgNode->getElement(Elt))) {
88 Result.assign(MDS->begin(), MDS->begin() + MDS->length());
89 return Result;
90 }
91
10192 return Result;
10293 }
10394
10495 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
105 if (DbgGV == 0) return 0;
106 if (!DbgGV->hasInitializer()) return 0;
107
108 Constant *C = DbgGV->getInitializer();
109 if (C == 0 || Elt >= C->getNumOperands())
96 if (DbgNode == 0)
11097 return 0;
11198
112 if (ConstantInt *CI = dyn_cast(C->getOperand(Elt)))
113 return CI->getZExtValue();
99 if (Elt < DbgNode->getNumElements())
100 if (ConstantInt *CI = dyn_cast(DbgNode->getElement(Elt)))
101 return CI->getZExtValue();
102
114103 return 0;
115104 }
116105
117106 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
118 if (DbgGV == 0) return DIDescriptor();
119
120 Constant *C = DbgGV->getInitializer();
121 if (C == 0 || Elt >= C->getNumOperands())
107 if (DbgNode == 0)
122108 return DIDescriptor();
123109
124 C = C->getOperand(Elt);
125 return DIDescriptor(dyn_cast(C->stripPointerCasts()));
110 if (Elt < DbgNode->getNumElements() && DbgNode->getElement(Elt))
111 return DIDescriptor(dyn_cast(DbgNode->getElement(Elt)));
112
113 return DIDescriptor();
126114 }
127115
128116 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
129 if (DbgGV == 0) return 0;
130
131 Constant *C = DbgGV->getInitializer();
132 if (C == 0 || Elt >= C->getNumOperands())
117 if (DbgNode == 0)
133118 return 0;
134119
135 C = C->getOperand(Elt);
136 return dyn_cast(C->stripPointerCasts());
120 if (Elt < DbgNode->getNumElements())
121 return dyn_cast(DbgNode->getElement(Elt));
122 return 0;
137123 }
138124
139125 //===----------------------------------------------------------------------===//
141127 //===----------------------------------------------------------------------===//
142128
143129 // Needed by DIVariable::getType().
144 DIType::DIType(GlobalVariable *GV) : DIDescriptor(GV) {
145 if (!GV) return;
130 DIType::DIType(MDNode *N) : DIDescriptor(N) {
131 if (!N) return;
146132 unsigned tag = getTag();
147133 if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) &&
148 !DICompositeType::isCompositeType(tag))
149 DbgGV = 0;
134 !DICompositeType::isCompositeType(tag)) {
135 DbgNode = 0;
136 }
150137 }
151138
152139 /// isDerivedType - Return true if the specified tag is legal for
163150 case dwarf::DW_TAG_inheritance:
164151 return true;
165152 default:
166 // FIXME: Even though it doesn't make sense, CompositeTypes are current
167 // modelled as DerivedTypes, this should return true for them as well.
168 return false;
153 // CompositeTypes are currently modelled as DerivedTypes.
154 return isCompositeType(Tag);
169155 }
170156 }
171157
199185 }
200186
201187 unsigned DIArray::getNumElements() const {
202 assert (DbgGV && "Invalid DIArray");
203 Constant *C = DbgGV->getInitializer();
204 assert (C && "Invalid DIArray initializer");
205 return C->getNumOperands();
188 assert (DbgNode && "Invalid DIArray");
189 return DbgNode->getNumElements();
206190 }
207191
208192 /// replaceAllUsesWith - Replace all uses of debug info referenced by
213197 return;
214198
215199 assert (!D.isNull() && "Can not replace with null");
216 getGV()->replaceAllUsesWith(D.getGV());
217 getGV()->eraseFromParent();
200 DbgNode->replaceAllUsesWith(D.getNode());
201 delete DbgNode;
218202 }
219203
220204 /// Verify - Verify that a compile unit is well formed.
340324
341325 /// dump - Print descriptor.
342326 void DIDescriptor::dump() const {
343 errs() << "[" << dwarf::TagString(getTag()) << "] [GV:";
344 errs().write_hex((intptr_t)DbgGV) << ']';
327 errs() << "[" << dwarf::TagString(getTag()) << "] ";
328 errs().write_hex((intptr_t)DbgNode) << ']';
345329 }
346330
347331 /// dump - Print compile unit.
382366 errs() << " [fwd] ";
383367
384368 if (isBasicType(Tag))
385 DIBasicType(DbgGV).dump();
369 DIBasicType(DbgNode).dump();
386370 else if (isDerivedType(Tag))
387 DIDerivedType(DbgGV).dump();
371 DIDerivedType(DbgNode).dump();
388372 else if (isCompositeType(Tag))
389 DICompositeType(DbgGV).dump();
373 DICompositeType(DbgNode).dump();
390374 else {
391375 errs() << "Invalid DIType\n";
392376 return;
433417 errs() << " [def] ";
434418
435419 if (isGlobalVariable(Tag))
436 DIGlobalVariable(DbgGV).dump();
420 DIGlobalVariable(DbgNode).dump();
437421
438422 errs() << "\n";
439423 }
473457 EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
474458 }
475459
476 /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
477 /// This is only valid when the descriptor is non-null.
478 Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
479 if (D.isNull()) return llvm::Constant::getNullValue(EmptyStructPtr);
480 return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
481 }
482
483460 Constant *DIFactory::GetTagConstant(unsigned TAG) {
484461 assert((TAG & LLVMDebugVersionMask) == 0 &&
485462 "Tag too large for debug encoding!");
486463 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
487464 }
488465
489 Constant *DIFactory::GetStringConstant(const std::string &String) {
490 // Check string cache for previous edition.
491 Constant *&Slot = StringCache[String];
492
493 // Return Constant if previously defined.
494 if (Slot) return Slot;
495
496 const PointerType *DestTy = PointerType::getUnqual(Type::getInt8Ty(VMContext));
497
498 // If empty string then use a i8* null instead.
499 if (String.empty())
500 return Slot = ConstantPointerNull::get(DestTy);
501
502 // Construct string as an llvm constant.
503 Constant *ConstStr = ConstantArray::get(VMContext, String);
504
505 // Otherwise create and return a new string global.
506 GlobalVariable *StrGV = new GlobalVariable(M, ConstStr->getType(), true,
507 GlobalVariable::InternalLinkage,
508 ConstStr, ".str");
509 StrGV->setSection("llvm.metadata");
510 return Slot = ConstantExpr::getBitCast(StrGV, DestTy);
511 }
512
513466 //===----------------------------------------------------------------------===//
514467 // DIFactory: Primary Constructors
515468 //===----------------------------------------------------------------------===//
517470 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
518471 /// This implicitly uniques the arrays created.
519472 DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
520 SmallVector Elts;
521
522 for (unsigned i = 0; i != NumTys; ++i)
523 Elts.push_back(getCastToEmpty(Tys[i]));
524
525 Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
526 Elts.size()),
527 Elts.data(), Elts.size());
528 // If we already have this array, just return the uniqued version.
529 DIDescriptor &Entry = SimpleConstantCache[Init];
530 if (!Entry.isNull()) return DIArray(Entry.getGV());
531
532 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
533 GlobalValue::InternalLinkage,
534 Init, "llvm.dbg.array");
535 GV->setSection("llvm.metadata");
536 Entry = DIDescriptor(GV);
537 return DIArray(GV);
473 SmallVector Elts;
474
475 if (NumTys == 0)
476 Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)));
477 else
478 for (unsigned i = 0; i != NumTys; ++i)
479 Elts.push_back(Tys[i].getNode());
480
481 return DIArray(MDNode::get(VMContext,Elts.data(), Elts.size()));
538482 }
539483
540484 /// GetOrCreateSubrange - Create a descriptor for a value range. This
541485 /// implicitly uniques the values returned.
542486 DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
543 Constant *Elts[] = {
487 Value *Elts[] = {
544488 GetTagConstant(dwarf::DW_TAG_subrange_type),
545489 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
546490 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
547491 };
548492
549 Constant *Init = ConstantStruct::get(VMContext, Elts,
550 sizeof(Elts)/sizeof(Elts[0]));
551
552 // If we already have this range, just return the uniqued version.
553 DIDescriptor &Entry = SimpleConstantCache[Init];
554 if (!Entry.isNull()) return DISubrange(Entry.getGV());
555
556 M.addTypeName("llvm.dbg.subrange.type", Init->getType());
557
558 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
559 GlobalValue::InternalLinkage,
560 Init, "llvm.dbg.subrange");
561 GV->setSection("llvm.metadata");
562 Entry = DIDescriptor(GV);
563 return DISubrange(GV);
493 return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
564494 }
565495
566496
575505 bool isOptimized,
576506 const char *Flags,
577507 unsigned RunTimeVer) {
578 Constant *Elts[] = {
508 Value *Elts[] = {
579509 GetTagConstant(dwarf::DW_TAG_compile_unit),
580 llvm::Constant::getNullValue(EmptyStructPtr),
510 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
581511 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
582 GetStringConstant(Filename),
583 GetStringConstant(Directory),
584 GetStringConstant(Producer),
512 MDString::get(VMContext, Filename),
513 MDString::get(VMContext, Directory),
514 MDString::get(VMContext, Producer),
585515 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
586516 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
587 GetStringConstant(Flags),
517 MDString::get(VMContext, Flags),
588518 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
589519 };
590
591 Constant *Init = ConstantStruct::get(VMContext, Elts,
592 sizeof(Elts)/sizeof(Elts[0]));
593
594 M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
595 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
596 GlobalValue::InternalLinkage,
597 Init, "llvm.dbg.compile_unit");
598 GV->setSection("llvm.metadata");
599 return DICompileUnit(GV);
520
521 return DICompileUnit(MDNode::get(VMContext, &Elts[0], 10));
600522 }
601523
602524 /// CreateEnumerator - Create a single enumerator value.
603525 DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
604 Constant *Elts[] = {
526 Value *Elts[] = {
605527 GetTagConstant(dwarf::DW_TAG_enumerator),
606 GetStringConstant(Name),
528 MDString::get(VMContext, Name),
607529 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
608530 };
609
610 Constant *Init = ConstantStruct::get(VMContext, Elts,
611 sizeof(Elts)/sizeof(Elts[0]));
612
613 M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
614 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
615 GlobalValue::InternalLinkage,
616 Init, "llvm.dbg.enumerator");
617 GV->setSection("llvm.metadata");
618 return DIEnumerator(GV);
531 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
619532 }
620533
621534
628541 uint64_t AlignInBits,
629542 uint64_t OffsetInBits, unsigned Flags,
630543 unsigned Encoding) {
631 Constant *Elts[] = {
544 Value *Elts[] = {
632545 GetTagConstant(dwarf::DW_TAG_base_type),
633 getCastToEmpty(Context),
634 GetStringConstant(Name),
635 getCastToEmpty(CompileUnit),
546 Context.getNode(),
547 MDString::get(VMContext, Name),
548 CompileUnit.getNode(),
636549 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
637550 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
638551 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
640553 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
641554 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
642555 };
643
644 Constant *Init = ConstantStruct::get(VMContext, Elts,
645 sizeof(Elts)/sizeof(Elts[0]));
646
647 M.addTypeName("llvm.dbg.basictype.type", Init->getType());
648 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
649 GlobalValue::InternalLinkage,
650 Init, "llvm.dbg.basictype");
651 GV->setSection("llvm.metadata");
652 return DIBasicType(GV);
556 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
653557 }
654558
655559 /// CreateDerivedType - Create a derived type like const qualified type,
664568 uint64_t OffsetInBits,
665569 unsigned Flags,
666570 DIType DerivedFrom) {
667 Constant *Elts[] = {
571 Value *Elts[] = {
668572 GetTagConstant(Tag),
669 getCastToEmpty(Context),
670 GetStringConstant(Name),
671 getCastToEmpty(CompileUnit),
573 Context.getNode(),
574 MDString::get(VMContext, Name),
575 CompileUnit.getNode(),
672576 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
673577 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
674578 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
675579 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
676580 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
677 getCastToEmpty(DerivedFrom)
581 DerivedFrom.getNode(),
678582 };
679
680 Constant *Init = ConstantStruct::get(VMContext, Elts,
681 sizeof(Elts)/sizeof(Elts[0]));
682
683 M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
684 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
685 GlobalValue::InternalLinkage,
686 Init, "llvm.dbg.derivedtype");
687 GV->setSection("llvm.metadata");
688 return DIDerivedType(GV);
583 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
689584 }
690585
691586 /// CreateCompositeType - Create a composite type like array, struct, etc.
702597 DIArray Elements,
703598 unsigned RuntimeLang) {
704599
705 Constant *Elts[] = {
600 Value *Elts[] = {
706601 GetTagConstant(Tag),
707 getCastToEmpty(Context),
708 GetStringConstant(Name),
709 getCastToEmpty(CompileUnit),
602 Context.getNode(),
603 MDString::get(VMContext, Name),
604 CompileUnit.getNode(),
710605 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
711606 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
712607 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
713608 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
714609 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
715 getCastToEmpty(DerivedFrom),
716 getCastToEmpty(Elements),
610 DerivedFrom.getNode(),
611 Elements.getNode(),
717612 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
718613 };
719
720 Constant *Init = ConstantStruct::get(VMContext, Elts,
721 sizeof(Elts)/sizeof(Elts[0]));
722
723 M.addTypeName("llvm.dbg.composite.type", Init->getType());
724 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
725 GlobalValue::InternalLinkage,
726 Init, "llvm.dbg.composite");
727 GV->setSection("llvm.metadata");
728 return DICompositeType(GV);
614 return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
729615 }
730616
731617
741627 bool isLocalToUnit,
742628 bool isDefinition) {
743629
744 Constant *Elts[] = {
630 Value *Elts[] = {
745631 GetTagConstant(dwarf::DW_TAG_subprogram),
746 llvm::Constant::getNullValue(EmptyStructPtr),
747 getCastToEmpty(Context),
748 GetStringConstant(Name),
749 GetStringConstant(DisplayName),
750 GetStringConstant(LinkageName),
751 getCastToEmpty(CompileUnit),
632 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
633 Context.getNode(),
634 MDString::get(VMContext, Name),
635 MDString::get(VMContext, DisplayName),
636 MDString::get(VMContext, LinkageName),
637 CompileUnit.getNode(),
752638 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
753 getCastToEmpty(Type),
639 Type.getNode(),
754640 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
755641 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
756642 };
757
758 Constant *Init = ConstantStruct::get(VMContext, Elts,
759 sizeof(Elts)/sizeof(Elts[0]));
760
761 M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
762 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
763 GlobalValue::InternalLinkage,
764 Init, "llvm.dbg.subprogram");
765 GV->setSection("llvm.metadata");
766 return DISubprogram(GV);
643 return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
767644 }
768645
769646 /// CreateGlobalVariable - Create a new descriptor for the specified global.
774651 DICompileUnit CompileUnit,
775652 unsigned LineNo, DIType Type,bool isLocalToUnit,
776653 bool isDefinition, llvm::GlobalVariable *Val) {
777 Constant *Elts[] = {
654 Value *Elts[] = {
778655 GetTagConstant(dwarf::DW_TAG_variable),
779 llvm::Constant::getNullValue(EmptyStructPtr),
780 getCastToEmpty(Context),
781 GetStringConstant(Name),
782 GetStringConstant(DisplayName),
783 GetStringConstant(LinkageName),
784 getCastToEmpty(CompileUnit),
656 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
657 Context.getNode(),
658 MDString::get(VMContext, Name),
659 MDString::get(VMContext, DisplayName),
660 MDString::get(VMContext, LinkageName),
661 CompileUnit.getNode(),
785662 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
786 getCastToEmpty(Type),
663 Type.getNode(),
787664 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
788665 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
789 ConstantExpr::getBitCast(Val, EmptyStructPtr)
666 Val
790667 };
791
792 Constant *Init = ConstantStruct::get(VMContext, Elts,
793 sizeof(Elts)/sizeof(Elts[0]));
794
795 M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
796 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
797 GlobalValue::LinkOnceAnyLinkage,
798 Init, "llvm.dbg.global_variable");
799 GV->setSection("llvm.metadata");
800 return DIGlobalVariable(GV);
668
669 Value *const *Vs = &Elts[0];
670 MDNode *Node = MDNode::get(VMContext,Vs, 12);
671
672 // Create a named metadata so that we do not lose this mdnode.
673 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
674 NMD->addElement(Node);
675
676 return DIGlobalVariable(Node);
801677 }
802678
803679
806682 const std::string &Name,
807683 DICompileUnit CompileUnit, unsigned LineNo,
808684 DIType Type) {
809 Constant *Elts[] = {
685 Value *Elts[] = {
810686 GetTagConstant(Tag),
811 getCastToEmpty(Context),
812 GetStringConstant(Name),
813 getCastToEmpty(CompileUnit),
687 Context.getNode(),
688 MDString::get(VMContext, Name),
689 CompileUnit.getNode(),
814690 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
815 getCastToEmpty(Type)
691 Type.getNode(),
816692 };
817
818 Constant *Init = ConstantStruct::get(VMContext, Elts,
819 sizeof(Elts)/sizeof(Elts[0]));
820
821 M.addTypeName("llvm.dbg.variable.type", Init->getType());
822 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
823 GlobalValue::InternalLinkage,
824 Init, "llvm.dbg.variable");
825 GV->setSection("llvm.metadata");
826 return DIVariable(GV);
693 return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
827694 }
828695
829696
830697 /// CreateBlock - This creates a descriptor for a lexical block with the
831698 /// specified parent VMContext.
832699 DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
833 Constant *Elts[] = {
700 Value *Elts[] = {
834701 GetTagConstant(dwarf::DW_TAG_lexical_block),
835 getCastToEmpty(Context)
702 Context.getNode()
836703 };
837
838 Constant *Init = ConstantStruct::get(VMContext, Elts,
839 sizeof(Elts)/sizeof(Elts[0]));
840
841 M.addTypeName("llvm.dbg.block.type", Init->getType());
842 GlobalVariable *GV = new GlobalVariable(M, Init->getType(), true,
843 GlobalValue::InternalLinkage,
844 Init, "llvm.dbg.block");
845 GV->setSection("llvm.metadata");
846 return DIBlock(GV);
704 return DIBlock(MDNode::get(VMContext, &Elts[0], 2));
847705 }
848706
849707
865723 Value *Args[] = {
866724 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo),
867725 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo),
868 getCastToEmpty(CU)
726 CU.getNode()
869727 };
870728 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
871729 }
878736 FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start);
879737
880738 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
881 CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
739 CallInst::Create(FuncStartFn, SP.getNode(), "", BB);
882740 }
883741
884742 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
889747 RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start);
890748
891749 // Call llvm.dbg.func.start.
892 CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
750 CallInst::Create(RegionStartFn, D.getNode(), "", BB);
893751 }
894752
895753 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
900758 RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end);
901759
902760 // Call llvm.dbg.region.end.
903 CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
761 CallInst::Create(RegionEndFn, D.getNode(), "", BB);
904762 }
905763
906764 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
911769 if (!DeclareFn)
912770 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
913771
914 Value *Args[] = { Storage, getCastToEmpty(D) };
772 Value *Args[] = { Storage, D.getNode() };
915773 CallInst::Create(DeclareFn, Args, Args+2, "", BB);
916774 }
775
917776
918777 //===----------------------------------------------------------------------===//
919778 // DebugInfoFinder implementations.
921780
922781 /// processModule - Process entire module and collect debug info.
923782 void DebugInfoFinder::processModule(Module &M) {
924
783
784
925785 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
926786 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
927787 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
937797 else if (DbgDeclareInst *DDI = dyn_cast(BI))
938798 processDeclare(DDI);
939799 }
940
941 for (Module::global_iterator GVI = M.global_begin(), GVE = M.global_end();
942 GVI != GVE; ++GVI) {
943 GlobalVariable *GV = GVI;
944 if (!GV->hasName() || !GV->isConstant()
945 || strncmp(GV->getName().data(), "llvm.dbg.global_variable", 24)
946 || !GV->hasInitializer())
947 continue;
948 DIGlobalVariable DIG(GV);
800
801 NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
802 if (!NMD)
803 return;
804
805 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
806 DIGlobalVariable DIG(cast(NMD->getElement(i)));
949807 if (addGlobalVariable(DIG)) {
950808 addCompileUnit(DIG.getCompileUnit());
951809 processType(DIG.getType());
960818
961819 addCompileUnit(DT.getCompileUnit());
962820 if (DT.isCompositeType(DT.getTag())) {
963 DICompositeType DCT(DT.getGV());
821 DICompositeType DCT(DT.getNode());
964822 processType(DCT.getTypeDerivedFrom());
965823 DIArray DA = DCT.getTypeArray();
966824 if (!DA.isNull())
967825 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
968826 DIDescriptor D = DA.getElement(i);
969 DIType TypeE = DIType(D.getGV());
827 DIType TypeE = DIType(D.getNode());
970828 if (!TypeE.isNull())
971829 processType(TypeE);
972830 else
973 processSubprogram(DISubprogram(D.getGV()));
831 processSubprogram(DISubprogram(D.getNode()));
974832 }
975833 } else if (DT.isDerivedType(DT.getTag())) {
976 DIDerivedType DDT(DT.getGV());
834 DIDerivedType DDT(DT.getNode());
977835 if (!DDT.isNull())
978836 processType(DDT.getTypeDerivedFrom());
979837 }
991849
992850 /// processStopPoint - Process DbgStopPointInst.
993851 void DebugInfoFinder::processStopPoint(DbgStopPointInst *SPI) {
994 GlobalVariable *Context = dyn_caste>(SPI->getContext());
852 MDNode *Context = dyn_caste>(SPI->getContext());
995853 addCompileUnit(DICompileUnit(Context));
996854 }
997855
998856 /// processFuncStart - Process DbgFuncStartInst.
999857 void DebugInfoFinder::processFuncStart(DbgFuncStartInst *FSI) {
1000 GlobalVariable *SP = dyn_caste>(FSI->getSubprogram());
858 MDNode *SP = dyn_caste>(FSI->getSubprogram());
1001859 processSubprogram(DISubprogram(SP));
1002860 }
1003861
1004862 /// processRegionStart - Process DbgRegionStart.
1005863 void DebugInfoFinder::processRegionStart(DbgRegionStartInst *DRS) {
1006 GlobalVariable *SP = dyn_caste>(DRS->getContext());
864 MDNode *SP = dyn_caste>(DRS->getContext());
1007865 processSubprogram(DISubprogram(SP));
1008866 }
1009867
1010868 /// processRegionEnd - Process DbgRegionEnd.
1011869 void DebugInfoFinder::processRegionEnd(DbgRegionEndInst *DRE) {
1012 GlobalVariable *SP = dyn_caste>(DRE->getContext());
870 MDNode *SP = dyn_caste>(DRE->getContext());
1013871 processSubprogram(DISubprogram(SP));
1014872 }
1015873
1016874 /// processDeclare - Process DbgDeclareInst.
1017875 void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
1018 DIVariable DV(cast<GlobalVariable>(DDI->getVariable()));
876 DIVariable DV(cast<MDNode>(DDI->getVariable()));
1019877 if (DV.isNull())
1020878 return;
1021879
1022 if (!NodesSeen.insert(DV.getGV()))
880 if (!NodesSeen.insert(DV.getNode()))
1023881 return;
1024882
1025883 addCompileUnit(DV.getCompileUnit());
1031889 if (DT.isNull())
1032890 return false;
1033891
1034 if (!NodesSeen.insert(DT.getGV()))
1035 return false;
1036
1037 TYs.push_back(DT.getGV());
892 if (!NodesSeen.insert(DT.getNode()))
893 return false;
894
895 TYs.push_back(DT.getNode());
1038896 return true;
1039897 }
1040898
1043901 if (CU.isNull())
1044902 return false;
1045903
1046 if (!NodesSeen.insert(CU.getGV()))
1047 return false;
1048
1049 CUs.push_back(CU.getGV());
904 if (!NodesSeen.insert(CU.getNode()))
905 return false;
906
907 CUs.push_back(CU.getNode());
1050908 return true;
1051909 }
1052910
1055913 if (DIG.isNull())
1056914 return false;
1057915
1058 if (!NodesSeen.insert(DIG.getGV()))
1059 return false;
1060
1061 GVs.push_back(DIG.getGV());
916 if (!NodesSeen.insert(DIG.getNode()))
917 return false;
918
919 GVs.push_back(DIG.getNode());
1062920 return true;
1063921 }
1064922
1067925 if (SP.isNull())
1068926 return false;
1069927
1070 if (!NodesSeen.insert(SP.getGV()))
1071 return false;
1072
1073 SPs.push_back(SP.getGV());
928 if (!NodesSeen.insert(SP.getNode()))
929 return false;
930
931 SPs.push_back(SP.getNode());
1074932 return true;
1075933 }
1076934
1123981
1124982 Value *findDbgGlobalDeclare(GlobalVariable *V) {
1125983 const Module *M = V->getParent();
984 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
985 if (!NMD)
986 return 0;
1126987
1127 const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type");
1128 if (!Ty) return 0;
1129
1130 Ty = PointerType::get(Ty, 0);
1131
1132 Value *Val = V->stripPointerCasts();
1133 for (Value::use_iterator I = Val->use_begin(), E = Val->use_end();
1134 I != E; ++I) {
1135 if (ConstantExpr *CE = dyn_cast(I)) {
1136 if (CE->getOpcode() == Instruction::BitCast) {
1137 Value *VV = CE;
1138
1139 while (VV->hasOneUse())
1140 VV = *VV->use_begin();
1141
1142 if (VV->getType() == Ty)
1143 return VV;
1144 }
1145 }
988 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
989 DIGlobalVariable DIG(cast_or_null(NMD->getElement(i)));
990 if (DIG.isNull())
991 continue;
992 if (DIG.getGlobal() == V)
993 return DIG.getNode();
1146994 }
1147
1148 if (Val->getType() == Ty)
1149 return Val;
1150
1151995 return 0;
1152996 }
1153997
11841028 if (GlobalVariable *GV = dyn_cast(const_cast(V))) {
11851029 Value *DIGV = findDbgGlobalDeclare(GV);
11861030 if (!DIGV) return false;
1187 DIGlobalVariable Var(cast<GlobalVariable>(DIGV));
1031 DIGlobalVariable Var(cast<MDNode>(DIGV));
11881032
11891033 Var.getDisplayName(DisplayName);
11901034 LineNo = Var.getLineNumber();
11931037 } else {
11941038 const DbgDeclareInst *DDI = findDbgDeclare(V);
11951039 if (!DDI) return false;
1196 DIVariable Var(cast<GlobalVariable>(DDI->getVariable()));
1040 DIVariable Var(cast<MDNode>(DDI->getVariable()));
11971041
11981042 Var.getName(DisplayName);
11991043 LineNo = Var.getLineNumber();
12511095 Value *Context = SPI.getContext();
12521096
12531097 // If this location is already tracked then use it.
1254 DebugLocTuple Tuple(cast<GlobalVariable>(Context), SPI.getLine(),
1098 DebugLocTuple Tuple(cast<MDNode>(Context), SPI.getLine(),
12551099 SPI.getColumn());
12561100 DenseMap::iterator II
12571101 = DebugLocInfo.DebugIdMap.find(Tuple);
12731117 DebugLoc DL;
12741118 Value *SP = FSI.getSubprogram();
12751119
1276 DISubprogram Subprogram(cast<GlobalVariable>(SP));
1120 DISubprogram Subprogram(cast<MDNode>(SP));
12771121 unsigned Line = Subprogram.getLineNumber();
12781122 DICompileUnit CU(Subprogram.getCompileUnit());
12791123
12801124 // If this location is already tracked then use it.
1281 DebugLocTuple Tuple(CU.getGV(), Line, /* Column */ 0);
1125 DebugLocTuple Tuple(CU.getNode(), Line, /* Column */ 0);
12821126 DenseMap::iterator II
12831127 = DebugLocInfo.DebugIdMap.find(Tuple);
12841128 if (II != DebugLocInfo.DebugIdMap.end())
12941138
12951139 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
12961140 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn) {
1297 DISubprogram Subprogram(cast<GlobalVariable>(FSI.getSubprogram()));
1141 DISubprogram Subprogram(cast<MDNode>(FSI.getSubprogram()));
12981142 if (Subprogram.describes(CurrentFn))
12991143 return false;
13001144
13031147
13041148 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
13051149 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn) {
1306 DISubprogram Subprogram(cast<GlobalVariable>(REI.getContext()));
1150 DISubprogram Subprogram(cast<MDNode>(REI.getContext()));
13071151 if (Subprogram.isNull() || Subprogram.describes(CurrentFn))
13081152 return false;
13091153
13101154 return true;
13111155 }
1312
1313 }
1156 }
9797 for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; )
9898 UpgradeCallsToIntrinsic(FI++); // must be post-increment, as we remove
9999
100 // Check debug info intrinsics.
101 CheckDebugInfoIntrinsics(M);
100102 return false;
101103 }
102104
1515 #include "llvm/Constants.h"
1616 #include "llvm/DerivedTypes.h"
1717 #include "llvm/InlineAsm.h"
18 #include "llvm/Instructions.h"
18 #include "llvm/IntrinsicInst.h"
1919 #include "llvm/LLVMContext.h"
2020 #include "llvm/Metadata.h"
2121 #include "llvm/Module.h"
21912191 }
21922192 }
21932193 std::vector >().swap(UpgradedIntrinsics);
2194
2194
2195 // Check debug info intrinsics.
2196 CheckDebugInfoIntrinsics(TheModule);
2197
21952198 return TheModule;
21962199 }
21972200
17381738 // Print source line info.
17391739 O.PadToColumn(MAI->getCommentColumn());
17401740 O << MAI->getCommentString() << " SrcLine ";
1741 if (DLT.CompileUnit->hasInitializer()) {
1742 Constant *Name = DLT.CompileUnit->getInitializer();
1743 if (ConstantArray *NameString = dyn_cast(Name))
1744 if (NameString->isString())
1745 O << NameString->getAsString() << " ";
1741 if (DLT.CompileUnit) {
1742 std::string Str;
1743 DICompileUnit CU(DLT.CompileUnit);
1744 O << CU.getFilename(Str) << " ";
17461745 }
17471746 O << DLT.Line;
17481747 if (DLT.Col != 0)
17601759 // Print source line info
17611760 O.PadToColumn(MAI->getCommentColumn());
17621761 O << MAI->getCommentString() << " SrcLine ";
1763 if (DLT.CompileUnit->hasInitializer()) {
1764 Constant *Name = DLT.CompileUnit->getInitializer();
1765 if (ConstantArray *NameString = dyn_cast(Name))
1766 if (NameString->isString())
1767 O << NameString->getAsString() << " ";
1762 if (DLT.CompileUnit) {
1763 std::string Str;
1764 DICompileUnit CU(DLT.CompileUnit);
1765 O << CU.getFilename(Str) << " ";
17681766 }
17691767 O << DLT.Line;
17701768 if (DLT.Col != 0)
99 // This file contains support for writing dwarf debug info into asm files.
1010 //
1111 //===----------------------------------------------------------------------===//
12
12 #define DEBUG_TYPE "dwarfdebug"
1313 #include "DwarfDebug.h"
1414 #include "llvm/Module.h"
1515 #include "llvm/CodeGen/MachineFunction.h"
2323 #include "llvm/Target/TargetRegisterInfo.h"
2424 #include "llvm/ADT/StringExtras.h"
2525 #include "llvm/Support/Timer.h"
26 #include "llvm/Support/Debug.h"
2627 #include "llvm/System/Path.h"
2728 using namespace llvm;
2829
5556
5657 /// GVToDieMap - Tracks the mapping of unit level debug informaton
5758 /// variables to debug information entries.
58 std::map GVToDieMap;
59 /// FIXME : Rename GVToDieMap -> NodeToDieMap
60 std::map GVToDieMap;
5961
6062 /// GVToDIEEntryMap - Tracks the mapping of unit level debug informaton
6163 /// descriptors to debug information entries using a DIEEntry proxy.
62 std::map GVToDIEEntryMap;
64 /// FIXME : Rename
65 std::map GVToDIEEntryMap;
6366
6467 /// Globals - A map of globally visible named entities for this unit.
6568 ///
8891
8992 /// getDieMapSlotFor - Returns the debug information entry map slot for the
9093 /// specified debug variable.
91 DIE *&getDieMapSlotFor(GlobalVariable *GV) { return GVToDieMap[GV]; }
94 DIE *&getDieMapSlotFor(MDNode *N) { return GVToDieMap[N]; }
9295
9396 /// getDIEEntrySlotFor - Returns the debug information entry proxy slot for
9497 /// the specified debug variable.
95 DIEEntry *&getDIEEntrySlotFor(GlobalVariable *GV) {
96 return GVToDIEEntryMap[GV];
98 DIEEntry *&getDIEEntrySlotFor(MDNode *N) {
99 return GVToDIEEntryMap[N];
97100 }
98101
99102 /// AddDie - Adds or interns the DIE to the compile unit.
238241 for (unsigned j = 0, M = Values.size(); j < M; ++j)
239242 delete Values[j];
240243
241 for (DenseMapGlobalVariable *, DbgScope *>::iterator
244 for (DenseMapMDNode *, DbgScope *>::iterator
242245 I = AbstractInstanceRootMap.begin(),
243246 E = AbstractInstanceRootMap.end(); I != E;++I)
244247 delete I->second;
530533 return;
531534
532535 // Check for pre-existence.
533 DIEEntry *&Slot = DW_Unit->getDIEEntrySlotFor(Ty.getGV());
536 DIEEntry *&Slot = DW_Unit->getDIEEntrySlotFor(Ty.getNode());
534537
535538 // If it exists then use the existing value.
536539 if (Slot) {
544547 // Construct type.
545548 DIE Buffer(dwarf::DW_TAG_base_type);
546549 if (Ty.isBasicType(Ty.getTag()))
547 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getGV()));
548 else if (Ty.isDerivedType(Ty.getTag()))
549 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getGV()));
550 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getNode()));
551 else if (Ty.isCompositeType(Ty.getTag()))
552 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getNode()));
550553 else {
551 assert(Ty.isCompositeType(Ty.getTag()) && "Unknown kind of DIType");
552 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getGV()));
554 assert(Ty.isDerivedType(Ty.getTag()) && "Unknown kind of DIType");
555 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getNode()));
556
553557 }
554558
555559 // Add debug information entry to entity and appropriate context.
556560 DIE *Die = NULL;
557561 DIDescriptor Context = Ty.getContext();
558562 if (!Context.isNull())
559 Die = DW_Unit->getDieMapSlotFor(Context.getGV());
563 Die = DW_Unit->getDieMapSlotFor(Context.getNode());
560564
561565 if (Die) {
562566 DIE *Child = new DIE(Buffer);
641645 // Add enumerators to enumeration type.
642646 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
643647 DIE *ElemDie = NULL;
644 DIEnumerator Enum(Elements.getElement(i).getGV());
648 DIEnumerator Enum(Elements.getElement(i).getNode());
645649 ElemDie = ConstructEnumTypeDIE(DW_Unit, &Enum);
646650 Buffer.AddChild(ElemDie);
647651 }
651655 // Add return type.
652656 DIArray Elements = CTy.getTypeArray();
653657 DIDescriptor RTy = Elements.getElement(0);
654 AddType(DW_Unit, &Buffer, DIType(RTy.getGV()));
658 AddType(DW_Unit, &Buffer, DIType(RTy.getNode()));
655659
656660 // Add prototype flag.
657661 AddUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
660664 for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
661665 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
662666 DIDescriptor Ty = Elements.getElement(i);
663 AddType(DW_Unit, Arg, DIType(Ty.getGV()));
667 AddType(DW_Unit, Arg, DIType(Ty.getNode()));
664668 Buffer.AddChild(Arg);
665669 }
666670 }
678682 // Add elements to structure type.
679683 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
680684 DIDescriptor Element = Elements.getElement(i);
685 if (Element.isNull())
686 continue;
681687 DIE *ElemDie = NULL;
682688 if (Element.getTag() == dwarf::DW_TAG_subprogram)
683689 ElemDie = CreateSubprogramDIE(DW_Unit,
684 DISubprogram(Element.getGV()));
690 DISubprogram(Element.getNode()));
685691 else
686692 ElemDie = CreateMemberDIE(DW_Unit,
687 DIDerivedType(Element.getGV()));
693 DIDerivedType(Element.getNode()));
688694 Buffer.AddChild(ElemDie);
689695 }
690696
761767 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
762768 DIDescriptor Element = Elements.getElement(i);
763769 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
764 ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy);
770 ConstructSubrangeDIE(Buffer, DISubrange(Element.getNode()), IndexTy);
765771 }
766772 }
767773
888894 if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
889895 AddType(DW_Unit, SPDie, SPTy);
890896 else
891 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV()));
897 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode()));
892898 }
893899
894900 if (!SP.isDefinition()) {
899905 if (SPTag == dwarf::DW_TAG_subroutine_type)
900906 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
901907 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
902 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV()));
908 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getNode()));
903909 AddUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
904910 SPDie->AddChild(Arg);
905911 }
909915 AddUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
910916
911917 // DW_TAG_inlined_subroutine may refer to this DIE.
912 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getGV());
918 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getNode());
913919 Slot = SPDie;
914920 return SPDie;
915921 }
918924 ///
919925 CompileUnit &DwarfDebug::FindCompileUnit(DICompileUnit Unit) const {
920926 DenseMap::const_iterator I =
921 CompileUnitMap.find(Unit.getGV());
927 CompileUnitMap.find(Unit.getNode());
922928 assert(I != CompileUnitMap.end() && "Missing compile unit.");
923929 return *I->second;
924930 }
971977
972978 /// getOrCreateScope - Returns the scope associated with the given descriptor.
973979 ///
974 DbgScope *DwarfDebug::getOrCreateScope(GlobalVariable *V) {
975 DbgScope *&Slot = DbgScopeMap[V];
980 DbgScope *DwarfDebug::getOrCreateScope(MDNode *N) {
981 DbgScope *&Slot = DbgScopeMap[N];
976982 if (Slot) return Slot;
977983
978984 DbgScope *Parent = NULL;
979 DIBlock Block(V);
985 DIBlock Block(N);
980986
981987 // Don't create a new scope if we already created one for an inlined function.
982 DenseMap::iterator
983 II = AbstractInstanceRootMap.find(V);
988 DenseMap::iterator
989 II = AbstractInstanceRootMap.find(N);
984990 if (II != AbstractInstanceRootMap.end())
985991 return LexicalScopeStack.back();
986992
987993 if (!Block.isNull()) {
988994 DIDescriptor ParentDesc = Block.getContext();
989995 Parent =
990 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getGV());
991 }
992
993 Slot = new DbgScope(Parent, DIDescriptor(V));
996 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getNode());
997 }
998
999 Slot = new DbgScope(Parent, DIDescriptor(N));
9941000
9951001 if (Parent)
9961002 Parent->AddScope(Slot);
10991105 return;
11001106
11011107 // Get the subprogram debug information entry.
1102 DISubprogram SPD(Desc.getGV());
1108 DISubprogram SPD(Desc.getNode());
11031109
11041110 // Get the subprogram die.
1105 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getGV());
1111 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getNode());
11061112 assert(SPDie && "Missing subprogram descriptor");
11071113
11081114 if (!AbstractScope) {
11751181 return SrcId;
11761182 }
11771183
1178 void DwarfDebug::ConstructCompileUnit(GlobalVariable *GV) {
1179 DICompileUnit DIUnit(GV);
1184 void DwarfDebug::ConstructCompileUnit(MDNode *N) {
1185 DICompileUnit DIUnit(N);
11801186 std::string Dir, FN, Prod;
11811187 unsigned ID = GetOrCreateSourceID(DIUnit.getDirectory(Dir),
11821188 DIUnit.getFilename(FN));
12131219 ModuleCU = Unit;
12141220 }
12151221
1216 CompileUnitMap[DIUnit.getGV()] = Unit;
1222 CompileUnitMap[DIUnit.getNode()] = Unit;
12171223 CompileUnits.push_back(Unit);
12181224 }
12191225
1220 void DwarfDebug::ConstructGlobalVariableDIE(GlobalVariable *GV) {
1221 DIGlobalVariable DI_GV(GV);
1226 void DwarfDebug::ConstructGlobalVariableDIE(MDNode *N) {
1227 DIGlobalVariable DI_GV(N);
12221228
12231229 // Check for pre-existence.
1224 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getGV());
1230 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getNode());
12251231 if (Slot)
12261232 return;
12271233
12471253 return;
12481254 }
12491255
1250 void DwarfDebug::ConstructSubprogram(GlobalVariable *GV) {
1251 DISubprogram SP(GV);
1256 void DwarfDebug::ConstructSubprogram(MDNode *N) {
1257 DISubprogram SP(N);
12521258
12531259 // Check for pre-existence.
1254 DIE *&Slot = ModuleCU->getDieMapSlotFor(GV);
1260 DIE *&Slot = ModuleCU->getDieMapSlotFor(N);
12551261 if (Slot)
12561262 return;
12571263
15341540 /// correspondence to the source line list.
15351541 unsigned DwarfDebug::RecordSourceLine(unsigned Line, unsigned Col,
15361542 DICompileUnit CU) {
1543 if (!MMI)
1544 return 0;
1545
15371546 if (TimePassesIsEnabled)
15381547 DebugTimer->startTimer();
15391548
15681577 }
15691578
15701579 /// RecordRegionStart - Indicate the start of a region.
1571 unsigned DwarfDebug::RecordRegionStart(GlobalVariable *V) {
1580 unsigned DwarfDebug::RecordRegionStart(MDNode *N) {
15721581 if (TimePassesIsEnabled)
15731582 DebugTimer->startTimer();
15741583
1575 DbgScope *Scope = getOrCreateScope(V);
1584 DbgScope *Scope = getOrCreateScope(N);
15761585 unsigned ID = MMI->NextLabelID();
15771586 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
15781587 LexicalScopeStack.push_back(Scope);
15841593 }
15851594
15861595 /// RecordRegionEnd - Indicate the end of a region.
1587 unsigned DwarfDebug::RecordRegionEnd(GlobalVariable *V) {
1596 unsigned DwarfDebug::RecordRegionEnd(MDNode *N) {
15881597 if (TimePassesIsEnabled)
15891598 DebugTimer->startTimer();
15901599
1591 DbgScope *Scope = getOrCreateScope(V);
1600 DbgScope *Scope = getOrCreateScope(N);
15921601 unsigned ID = MMI->NextLabelID();
15931602 Scope->setEndLabelID(ID);
15941603 // FIXME : region.end() may not be in the last basic block.
16051614 }
16061615
16071616 /// RecordVariable - Indicate the declaration of a local variable.
1608 void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
1617 void DwarfDebug::RecordVariable(MDNode *N, unsigned FrameIndex) {
16091618 if (TimePassesIsEnabled)
16101619 DebugTimer->startTimer();
16111620
1612 DIDescriptor Desc(GV);
1621 DIDescriptor Desc(N);
16131622 DbgScope *Scope = NULL;
16141623 bool InlinedFnVar = false;
16151624
1616 if (Desc.getTag() == dwarf::DW_TAG_variable) {
1617 // GV is a global variable.
1618 DIGlobalVariable DG(GV);
1619 Scope = getOrCreateScope(DG.getContext().getGV());
1620 } else {
1625 if (Desc.getTag() == dwarf::DW_TAG_variable)
1626 Scope = getOrCreateScope(DIGlobalVariable(N).getContext().getNode());
1627 else {
16211628 bool InlinedVar = false;
1622 DIVariable DV(GV);
1623 GlobalVariable *V = DV.getContext().getGV();
1624 DISubprogram SP(V);
1629 MDNode *Context = DIVariable(N).getContext().getNode();
1630 DISubprogram SP(Context);
16251631 if (!SP.isNull()) {
16261632 // SP is inserted into DbgAbstractScopeMap when inlined function
16271633 // start was recorded by RecordInlineFnStart.
1628 DenseMap::iterator
1629 I = DbgAbstractScopeMap.find(SP.getGV());
1634 DenseMap::iterator
1635 I = DbgAbstractScopeMap.find(SP.getNode());
16301636 if (I != DbgAbstractScopeMap.end()) {
16311637 InlinedVar = true;
16321638 Scope = I->second;
16331639 }
16341640 }
1635 if (!InlinedVar) {
1636 // GV is a local variable.
1637 Scope = getOrCreateScope(V);
1638 }
1641 if (!InlinedVar)
1642 Scope = getOrCreateScope(Context);
16391643 }
16401644
16411645 assert(Scope && "Unable to find the variable's scope");
1642 DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex, InlinedFnVar);
1646 DbgVariable *DV = new DbgVariable(DIVariable(N), FrameIndex, InlinedFnVar);
16431647 Scope->AddVariable(DV);
16441648
16451649 if (TimePassesIsEnabled)
16571661 if (TimePassesIsEnabled)
16581662 DebugTimer->startTimer();
16591663
1660 GlobalVariable *GV = SP.getGV();
1661 DenseMap::iterator
1662 II = AbstractInstanceRootMap.find(GV);
1664 MDNode *Node = SP.getNode();
1665 DenseMap::iterator
1666 II = AbstractInstanceRootMap.find(Node);
16631667
16641668 if (II == AbstractInstanceRootMap.end()) {
16651669 // Create an abstract instance entry for this inlined function if it doesn't
16661670 // already exist.
1667 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
1671 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(Node));
16681672
16691673 // Get the compile unit context.
1670 DIE *SPDie = ModuleCU->getDieMapSlotFor(GV);
1674 DIE *SPDie = ModuleCU->getDieMapSlotFor(Node);
16711675 if (!SPDie)
16721676 SPDie = CreateSubprogramDIE(ModuleCU, SP, false, true);
16731677
16791683 AddUInt(SPDie, dwarf::DW_AT_inline, 0, dwarf::DW_INL_declared_not_inlined);
16801684
16811685 // Keep track of the abstract scope for this function.
1682 DbgAbstractScopeMap[GV] = Scope;
1683
1684 AbstractInstanceRootMap[GV] = Scope;
1686 DbgAbstractScopeMap[Node] = Scope;
1687
1688 AbstractInstanceRootMap[Node] = Scope;
16851689 AbstractInstanceRootList.push_back(Scope);
16861690 }
16871691
16881692 // Create a concrete inlined instance for this inlined function.
1689 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
1693 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(Node));
16901694 DIE *ScopeDie = new DIE(dwarf::DW_TAG_inlined_subroutine);
16911695 ScopeDie->setAbstractCompileUnit(ModuleCU);
16921696
1693 DIE *Origin = ModuleCU->getDieMapSlotFor(GV);
1697 DIE *Origin = ModuleCU->getDieMapSlotFor(Node);
16941698 AddDIEEntry(ScopeDie, dwarf::DW_AT_abstract_origin,
16951699 dwarf::DW_FORM_ref4, Origin);
16961700 AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
17041708 LexicalScopeStack.back()->AddConcreteInst(ConcreteScope);
17051709
17061710 // Keep track of the concrete scope that's inlined into this function.
1707 DenseMap >::iterator
1708 SI = DbgConcreteScopeMap.find(GV);
1711 DenseMap >::iterator
1712 SI = DbgConcreteScopeMap.find(Node);
17091713
17101714 if (SI == DbgConcreteScopeMap.end())
1711 DbgConcreteScopeMap[GV].push_back(ConcreteScope);
1715 DbgConcreteScopeMap[Node].push_back(ConcreteScope);
17121716 else
17131717 SI->second.push_back(ConcreteScope);
17141718
17151719 // Track the start label for this inlined function.
1716 DenseMap >::iterator
1717 I = InlineInfo.find(GV);
1720 DenseMap >::iterator
1721 I = InlineInfo.find(Node);
17181722
17191723 if (I == InlineInfo.end())
1720 InlineInfo[GV].push_back(LabelID);
1724 InlineInfo[Node].push_back(LabelID);
17211725 else
17221726 I->second.push_back(LabelID);
17231727
17351739 if (TimePassesIsEnabled)
17361740 DebugTimer->startTimer();
17371741
1738 GlobalVariable *GV = SP.getGV();
1739 DenseMap >::iterator
1740 I = DbgConcreteScopeMap.find(GV);
1742 MDNode *Node = SP.getNode();
1743 DenseMap >::iterator
1744 I = DbgConcreteScopeMap.find(Node);
17411745
17421746 if (I == DbgConcreteScopeMap.end()) {
17431747 // FIXME: Can this situation actually happen? And if so, should it?
24422446 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version");
24432447 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
24442448
2445 for (DenseMap<GlobalVariable *, SmallVector >::iterator
2449 for (DenseMap<MDNode *, SmallVector >::iterator
24462450 I = InlineInfo.begin(), E = InlineInfo.end(); I != E; ++I) {
2447 GlobalVariable *GV = I->first;
2451 MDNode *Node = I->first;
24482452 SmallVector &Labels = I->second;
2449 DISubprogram SP(GV);
2453 DISubprogram SP(Node);
24502454 std::string Name;
24512455 std::string LName;
24522456
24722476
24732477 for (SmallVector::iterator LI = Labels.begin(),
24742478 LE = Labels.end(); LI != LE; ++LI) {
2475 DIE *SP = ModuleCU->getDieMapSlotFor(GV);
2479 DIE *SP = ModuleCU->getDieMapSlotFor(Node);
24762480 Asm->EmitInt32(SP->getOffset()); Asm->EOL("DIE offset");
24772481
24782482 if (TD->getPointerSize() == sizeof(int32_t))
138138 DbgScope *FunctionDbgScope;