llvm.org GIT mirror llvm / 2a610c7
Update DebugInfo interface to use metadata, instead of special named llvm.dbg.... global variables, to encode debugging information in llvm IR. This is mostly a mechanical change that tests metadata support very well. This change speeds up llvm-gcc by more then 6% at "-O0 -g" (measured by compiling InstructionCombining.cpp!) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79977 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 11 years ago
47 changed file(s) with 1020 addition(s) and 1987 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);
174176 };
175177
176178 protected:
177 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
179 DIType(MDNode *N, unsigned Tag)
180 : DIDescriptor(N, Tag) {}
178181 // This ctor is used when the Tag has already been validated by a derived
179182 // ctor.
180 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
183 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
181184
182185 public:
183186 /// isDerivedType - Return true if the specified tag is legal for
197200 /// Verify - Verify that a type descriptor is well formed.
198201 bool Verify() const;
199202 public:
200 explicit DIType(GlobalVariable *GV);
203 explicit DIType(MDNode *N);
201204 explicit DIType() {}
202205 virtual ~DIType() {}
203206
230233 /// DIBasicType - A basic type, like 'int' or 'float'.
231234 class DIBasicType : public DIType {
232235 public:
233 explicit DIBasicType(GlobalVariable *GV)
234 : DIType(GV, dwarf::DW_TAG_base_type) {}
236 explicit DIBasicType(MDNode *N = 0)
237 : DIType(N, dwarf::DW_TAG_base_type) {}
235238
236239 unsigned getEncoding() const { return getUnsignedField(9); }
237240
243246 /// a typedef, a pointer or reference, etc.
244247 class DIDerivedType : public DIType {
245248 protected:
246 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
247 : DIType(GV, true, true) {}
248 public:
249 explicit DIDerivedType(GlobalVariable *GV)
250 : DIType(GV, true, true) {
251 if (GV && !isDerivedType(getTag()))
252 DbgGV = 0;
249 explicit DIDerivedType(MDNode *N, bool, bool)
250 : DIType(N, true, true) {}
251 public:
252 explicit DIDerivedType(MDNode *N = 0)
253 : DIType(N, true, true) {
254 if (DbgNode && !isDerivedType(getTag()))
255 DbgNode = 0;
253256 }
254257
255258 DIType getTypeDerivedFrom() const { return getFieldAs(9); }
271274 /// FIXME: Why is this a DIDerivedType??
272275 class DICompositeType : public DIDerivedType {
273276 public:
274 explicit DICompositeType(GlobalVariable *GV)
275 : DIDerivedType(GV, true, true) {
276 if (GV && !isCompositeType(getTag()))
277 DbgGV = 0;
277 explicit DICompositeType(MDNode *N = 0)
278 : DIDerivedType(N, true, true) {
279 if (N && !isCompositeType(getTag()))
280 DbgNode = 0;
278281 }
279282
280283 DIArray getTypeArray() const { return getFieldAs(10); }
290293 /// DIGlobal - This is a common class for global variables and subprograms.
291294 class DIGlobal : public DIDescriptor {
292295 protected:
293 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
294 : DIDescriptor(GV, RequiredTag) {}
296 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
297 : DIDescriptor(N, RequiredTag) {}
295298
296299 /// isSubprogram - Return true if the specified tag is legal for
297300 /// DISubprogram.
334337 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
335338 class DISubprogram : public DIGlobal {
336339 public:
337 explicit DISubprogram(GlobalVariable *GV = 0)
338 : DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
340 explicit DISubprogram(MDNode *N = 0)
341 : DIGlobal(N, dwarf::DW_TAG_subprogram) {}
339342
340343 DICompositeType getType() const { return getFieldAs(8); }
341344
345348 DICompositeType DCT(getFieldAs(8));
346349 if (!DCT.isNull()) {
347350 DIArray A = DCT.getTypeArray();
348 DIType T(A.getElement(0).getGV());
351 DIType T(A.getElement(0).getNode());
349352 return T.getName(F);
350353 }
351354 DIType T(getFieldAs(8));
366369 /// DIGlobalVariable - This is a wrapper for a global variable.
367370 class DIGlobalVariable : public DIGlobal {
368371 public:
369 explicit DIGlobalVariable(GlobalVariable *GV = 0)
370 : DIGlobal(GV, dwarf::DW_TAG_variable) {}
372 explicit DIGlobalVariable(MDNode *N = 0)
373 : DIGlobal(N, dwarf::DW_TAG_variable) {}
371374
372375 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
373376
382385 /// global etc).
383386 class DIVariable : public DIDescriptor {
384387 public:
385 explicit DIVariable(GlobalVariable *GV = 0)
386 : DIDescriptor(GV) {
387 if (GV && !isVariable(getTag()))
388 DbgGV = 0;
388 explicit DIVariable(MDNode *N = 0)
389 : DIDescriptor(N) {
390 if (DbgNode && !isVariable(getTag()))
391 DbgNode = 0;
389392 }
390393
391394 DIDescriptor getContext() const { return getDescriptorField(1); }
409412 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
410413 class DIBlock : public DIDescriptor {
411414 public:
412 explicit DIBlock(GlobalVariable *GV = 0)
413 : DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
415 explicit DIBlock(MDNode *N = 0)
416 : DIDescriptor(N, dwarf::DW_TAG_lexical_block) {}
414417
415418 DIDescriptor getContext() const { return getDescriptorField(1); }
416419 };
537540
538541 private:
539542 Constant *GetTagConstant(unsigned TAG);
540 Constant *GetStringConstant(const std::string &String);
541
542 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
543 Constant *getCastToEmpty(DIDescriptor D);
544543 };
545544
546545 /// Finds the stoppoint coressponding to this instruction, that is the
602601
603602 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
604603 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
605
606604 /// DebugInfoFinder - This object collects DebugInfo from a module.
607605 class DebugInfoFinder {
608606
646644 bool addType(DIType DT);
647645
648646 public:
649 typedef SmallVector<GlobalVariable *, 8>::iterator iterator;
647 typedef SmallVector<MDNode *, 8>::iterator iterator;
650648 iterator compile_unit_begin() { return CUs.begin(); }
651649 iterator compile_unit_end() { return CUs.end(); }
652650 iterator subprogram_begin() { return SPs.begin(); }
662660 unsigned type_count() { return TYs.size(); }
663661
664662 private:
665 SmallVector CUs; // Compile Units
666 SmallVector SPs; // Subprograms
667 SmallVector GVs; // Global Variables
668 SmallVector TYs; // Types
669 SmallPtrSet NodesSeen;
670
663 SmallVector CUs; // Compile Units
664 SmallVector SPs; // Subprograms
665 SmallVector GVs; // Global Variables;
666 SmallVector TYs; // Types
667 SmallPtrSet NodesSeen;
671668 };
672669 } // end namespace llvm
673670
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
20142014 SDUse Chain;
20152015 unsigned Line;
20162016 unsigned Column;
2017 Value *CU;
2017 MDNode *CU;
20182018 friend class SelectionDAG;
20192019 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2020 Value *cu)
2020 MDNode *cu)
20212021 : SDNode(ISD::DBG_STOPPOINT, DebugLoc::getUnknownLoc(),
20222022 getSDVTList(MVT::Other)), Line(l), Column(c), CU(cu) {
20232023 InitOperands(&Chain, ch);
20252025 public:
20262026 unsigned getLine() const { return Line; }
20272027 unsigned getColumn() const { return Column; }
2028 Value *getCompileUnit() const { return CU; }
2028 MDNode *getCompileUnit() const { return CU; }
20292029
20302030 static bool classof(const DbgStopPointSDNode *) { return true; }
20312031 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
532 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
619533 }
620534
621535
628542 uint64_t AlignInBits,
629543 uint64_t OffsetInBits, unsigned Flags,
630544 unsigned Encoding) {
631 Constant *Elts[] = {
545 Value *Elts[] = {
632546 GetTagConstant(dwarf::DW_TAG_base_type),
633 getCastToEmpty(Context),
634 GetStringConstant(Name),
635 getCastToEmpty(CompileUnit),
547 Context.getNode(),
548 MDString::get(VMContext, Name),
549 CompileUnit.getNode(),
636550 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
637551 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
638552 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
641555 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
642556 };
643557
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);
558 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
653559 }
654560
655561 /// CreateDerivedType - Create a derived type like const qualified type,
664570 uint64_t OffsetInBits,
665571 unsigned Flags,
666572 DIType DerivedFrom) {
667 Constant *Elts[] = {
573 Value *Elts[] = {
668574 GetTagConstant(Tag),
669 getCastToEmpty(Context),
670 GetStringConstant(Name),
671 getCastToEmpty(CompileUnit),
575 Context.getNode(),
576 MDString::get(VMContext, Name),
577 CompileUnit.getNode(),
672578 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
673579 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
674580 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
675581 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
676582 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
677 getCastToEmpty(DerivedFrom)
583 DerivedFrom.getNode(),
678584 };
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);
585
586 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
689587 }
690588
691589 /// CreateCompositeType - Create a composite type like array, struct, etc.
702600 DIArray Elements,
703601 unsigned RuntimeLang) {
704602
705 Constant *Elts[] = {
603 Value *Elts[] = {
706604 GetTagConstant(Tag),
707 getCastToEmpty(Context),
708 GetStringConstant(Name),
709 getCastToEmpty(CompileUnit),
605 Context.getNode(),
606 MDString::get(VMContext, Name),
607 CompileUnit.getNode(),
710608 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
711609 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
712610 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
713611 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
714612 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
715 getCastToEmpty(DerivedFrom),
716 getCastToEmpty(Elements),
613 DerivedFrom.getNode(),
614 Elements.getNode(),
717615 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
718616 };
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);
617
618 return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
729619 }
730620
731621
741631 bool isLocalToUnit,
742632 bool isDefinition) {
743633
744 Constant *Elts[] = {
634 Value *Elts[] = {
745635 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),
636 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
637 Context.getNode(),
638 MDString::get(VMContext, Name),
639 MDString::get(VMContext, DisplayName),
640 MDString::get(VMContext, LinkageName),
641 CompileUnit.getNode(),
752642 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
753 getCastToEmpty(Type),
643 Type.getNode(),
754644 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
755645 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
756646 };
757647
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);
648 return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
767649 }
768650
769651 /// CreateGlobalVariable - Create a new descriptor for the specified global.
774656 DICompileUnit CompileUnit,
775657 unsigned LineNo, DIType Type,bool isLocalToUnit,
776658 bool isDefinition, llvm::GlobalVariable *Val) {
777 Constant *Elts[] = {
659 Value *Elts[] = {
778660 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),
661 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
662 Context.getNode(),
663 MDString::get(VMContext, Name),
664 MDString::get(VMContext, DisplayName),
665 MDString::get(VMContext, LinkageName),
666 CompileUnit.getNode(),
785667 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
786 getCastToEmpty(Type),
668 Type.getNode(),
787669 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
788670 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
789 ConstantExpr::getBitCast(Val, EmptyStructPtr)
671 Val
790672 };
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);
673
674 Value *const *Vs = &Elts[0];
675 MDNode *Node = MDNode::get(VMContext,Vs, 12);
676
677 // Create a named metadata so that we do not lose this mdnode.
678 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
679 NMD->addElement(Node);
680
681 return DIGlobalVariable(Node);
801682 }
802683
803684
806687 const std::string &Name,
807688 DICompileUnit CompileUnit, unsigned LineNo,
808689 DIType Type) {
809 Constant *Elts[] = {
690 Value *Elts[] = {
810691 GetTagConstant(Tag),
811 getCastToEmpty(Context),
812 GetStringConstant(Name),
813 getCastToEmpty(CompileUnit),
692 Context.getNode(),
693 MDString::get(VMContext, Name),
694 CompileUnit.getNode(),
814695 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
815 getCastToEmpty(Type)
696 Type.getNode(),
816697 };
817698
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);
699 return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
827700 }
828701
829702
830703 /// CreateBlock - This creates a descriptor for a lexical block with the
831704 /// specified parent VMContext.
832705 DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
833 Constant *Elts[] = {
706 Value *Elts[] = {
834707 GetTagConstant(dwarf::DW_TAG_lexical_block),
835 getCastToEmpty(Context)
708 Context.getNode()
836709 };
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);
710
711 return DIBlock(MDNode::get(VMContext, &Elts[0], 2));
847712 }
848713
849714
865730 Value *Args[] = {
866731 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo),
867732 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo),
868 getCastToEmpty(CU)
733 CU.getNode()
869734 };
870735 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
871736 }
878743 FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start);
879744
880745 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
881 CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
746 CallInst::Create(FuncStartFn, SP.getNode(), "", BB);
882747 }
883748
884749 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
889754 RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start);
890755
891756 // Call llvm.dbg.func.start.
892 CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
757 CallInst::Create(RegionStartFn, D.getNode(), "", BB);
893758 }
894759
895760 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
900765 RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end);
901766
902767 // Call llvm.dbg.region.end.
903 CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
768 CallInst::Create(RegionEndFn, D.getNode(), "", BB);
904769 }
905770
906771 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
911776 if (!DeclareFn)
912777 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
913778
914 Value *Args[] = { Storage, getCastToEmpty(D) };
779 Value *Args[] = { Storage, D.getNode() };
915780 CallInst::Create(DeclareFn, Args, Args+2, "", BB);
916781 }
782
917783
918784 //===----------------------------------------------------------------------===//
919785 // DebugInfoFinder implementations.
921787
922788 /// processModule - Process entire module and collect debug info.
923789 void DebugInfoFinder::processModule(Module &M) {
924
790
791
925792 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
926793 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
927794 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
937804 else if (DbgDeclareInst *DDI = dyn_cast(BI))
938805 processDeclare(DDI);
939806 }
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);
807
808 NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv");
809 if (!NMD)
810 return;
811
812 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
813 DIGlobalVariable DIG(cast(NMD->getElement(i)));
949814 if (addGlobalVariable(DIG)) {
950815 addCompileUnit(DIG.getCompileUnit());
951816 processType(DIG.getType());
960825
961826 addCompileUnit(DT.getCompileUnit());
962827 if (DT.isCompositeType(DT.getTag())) {
963 DICompositeType DCT(DT.getGV());
828 DICompositeType DCT(DT.getNode());
964829 processType(DCT.getTypeDerivedFrom());
965830 DIArray DA = DCT.getTypeArray();
966831 if (!DA.isNull())
967832 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
968833 DIDescriptor D = DA.getElement(i);
969 DIType TypeE = DIType(D.getGV());
834 DIType TypeE = DIType(D.getNode());
970835 if (!TypeE.isNull())
971836 processType(TypeE);
972837 else
973 processSubprogram(DISubprogram(D.getGV()));
838 processSubprogram(DISubprogram(D.getNode()));
974839 }
975840 } else if (DT.isDerivedType(DT.getTag())) {
976 DIDerivedType DDT(DT.getGV());
841 DIDerivedType DDT(DT.getNode());
977842 if (!DDT.isNull())
978843 processType(DDT.getTypeDerivedFrom());
979844 }
991856
992857 /// processStopPoint - Process DbgStopPointInst.
993858 void DebugInfoFinder::processStopPoint(DbgStopPointInst *SPI) {
994 GlobalVariable *Context = dyn_caste>(SPI->getContext());
859 MDNode *Context = dyn_caste>(SPI->getContext());
995860 addCompileUnit(DICompileUnit(Context));
996861 }
997862
998863 /// processFuncStart - Process DbgFuncStartInst.
999864 void DebugInfoFinder::processFuncStart(DbgFuncStartInst *FSI) {
1000 GlobalVariable *SP = dyn_caste>(FSI->getSubprogram());
865 MDNode *SP = dyn_caste>(FSI->getSubprogram());
1001866 processSubprogram(DISubprogram(SP));
1002867 }
1003868
1004869 /// processRegionStart - Process DbgRegionStart.
1005870 void DebugInfoFinder::processRegionStart(DbgRegionStartInst *DRS) {
1006 GlobalVariable *SP = dyn_caste>(DRS->getContext());
871 MDNode *SP = dyn_caste>(DRS->getContext());
1007872 processSubprogram(DISubprogram(SP));
1008873 }
1009874
1010875 /// processRegionEnd - Process DbgRegionEnd.
1011876 void DebugInfoFinder::processRegionEnd(DbgRegionEndInst *DRE) {
1012 GlobalVariable *SP = dyn_caste>(DRE->getContext());
877 MDNode *SP = dyn_caste>(DRE->getContext());
1013878 processSubprogram(DISubprogram(SP));
1014879 }
1015880
1016881 /// processDeclare - Process DbgDeclareInst.
1017882 void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
1018 DIVariable DV(cast<GlobalVariable>(DDI->getVariable()));
883 DIVariable DV(cast<MDNode>(DDI->getVariable()));
1019884 if (DV.isNull())
1020885 return;
1021886
1022 if (!NodesSeen.insert(DV.getGV()))
887 if (!NodesSeen.insert(DV.getNode()))
1023888 return;
1024889
1025890 addCompileUnit(DV.getCompileUnit());
1031896 if (DT.isNull())
1032897 return false;
1033898
1034 if (!NodesSeen.insert(DT.getGV()))
1035 return false;
1036
1037 TYs.push_back(DT.getGV());
899 if (!NodesSeen.insert(DT.getNode()))
900 return false;
901
902 TYs.push_back(DT.getNode());
1038903 return true;
1039904 }
1040905
1043908 if (CU.isNull())
1044909 return false;
1045910
1046 if (!NodesSeen.insert(CU.getGV()))
1047 return false;
1048
1049 CUs.push_back(CU.getGV());
911 if (!NodesSeen.insert(CU.getNode()))
912 return false;
913
914 CUs.push_back(CU.getNode());
1050915 return true;
1051916 }
1052917
1055920 if (DIG.isNull())
1056921 return false;
1057922
1058 if (!NodesSeen.insert(DIG.getGV()))
1059 return false;
1060
1061 GVs.push_back(DIG.getGV());
923 if (!NodesSeen.insert(DIG.getNode()))
924 return false;
925
926 GVs.push_back(DIG.getNode());
1062927 return true;
1063928 }
1064929
1067932 if (SP.isNull())
1068933 return false;
1069934
1070 if (!NodesSeen.insert(SP.getGV()))
1071 return false;
1072
1073 SPs.push_back(SP.getGV());
935 if (!NodesSeen.insert(SP.getNode()))
936 return false;
937
938 SPs.push_back(SP.getNode());
1074939 return true;
1075940 }
1076941
1123988
1124989 Value *findDbgGlobalDeclare(GlobalVariable *V) {
1125990 const Module *M = V->getParent();
991 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
992 if (!NMD)
993 return 0;
1126994
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 }
995 for (unsigned i = 0, e = NMD->getNumElements(); i != e; ++i) {
996 DIGlobalVariable DIG(cast_or_null(NMD->getElement(i)));
997 if (DIG.isNull())
998 continue;
999 if (DIG.getGlobal() == V)
1000 return DIG.getNode();
11461001 }
1147
1148 if (Val->getType() == Ty)
1149 return Val;
1150
11511002 return 0;
11521003 }
11531004
11841035 if (GlobalVariable *GV = dyn_cast(const_cast(V))) {
11851036 Value *DIGV = findDbgGlobalDeclare(GV);
11861037 if (!DIGV) return false;
1187 DIGlobalVariable Var(cast<GlobalVariable>(DIGV));
1038 DIGlobalVariable Var(cast<MDNode>(DIGV));
11881039
11891040 Var.getDisplayName(DisplayName);
11901041 LineNo = Var.getLineNumber();
11931044 } else {
11941045 const DbgDeclareInst *DDI = findDbgDeclare(V);
11951046 if (!DDI) return false;
1196 DIVariable Var(cast<GlobalVariable>(DDI->getVariable()));
1047 DIVariable Var(cast<MDNode>(DDI->getVariable()));
11971048
11981049 Var.getName(DisplayName);
11991050 LineNo = Var.getLineNumber();
12511102 Value *Context = SPI.getContext();
12521103
12531104 // If this location is already tracked then use it.
1254 DebugLocTuple Tuple(cast<GlobalVariable>(Context), SPI.getLine(),
1105 DebugLocTuple Tuple(cast<MDNode>(Context), SPI.getLine(),
12551106 SPI.getColumn());
12561107 DenseMap::iterator II
12571108 = DebugLocInfo.DebugIdMap.find(Tuple);
12731124 DebugLoc DL;
12741125 Value *SP = FSI.getSubprogram();
12751126
1276 DISubprogram Subprogram(cast<GlobalVariable>(SP));
1127 DISubprogram Subprogram(cast<MDNode>(SP));
12771128 unsigned Line = Subprogram.getLineNumber();
12781129 DICompileUnit CU(Subprogram.getCompileUnit());
12791130
12801131 // If this location is already tracked then use it.
1281 DebugLocTuple Tuple(CU.getGV(), Line, /* Column */ 0);
1132 DebugLocTuple Tuple(CU.getNode(), Line, /* Column */ 0);
12821133 DenseMap::iterator II
12831134 = DebugLocInfo.DebugIdMap.find(Tuple);
12841135 if (II != DebugLocInfo.DebugIdMap.end())
12941145
12951146 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
12961147 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn) {
1297 DISubprogram Subprogram(cast<GlobalVariable>(FSI.getSubprogram()));
1148 DISubprogram Subprogram(cast<MDNode>(FSI.getSubprogram()));
12981149 if (Subprogram.describes(CurrentFn))
12991150 return false;
13001151
13031154
13041155 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
13051156 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn) {
1306 DISubprogram Subprogram(cast<GlobalVariable>(REI.getContext()));
1157 DISubprogram Subprogram(cast<MDNode>(REI.getContext()));
13071158 if (Subprogram.isNull() || Subprogram.describes(CurrentFn))
13081159 return false;
13091160
13101161 return true;
13111162 }
1312
1313 }
1163 }
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
764770 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
765771 DIDescriptor Element = Elements.getElement(i);
766772 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
767 ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy);
773 ConstructSubrangeDIE(Buffer, DISubrange(Element.getNode()), IndexTy);
768774 }
769775 }
770776
891897 if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
892898 AddType(DW_Unit, SPDie, SPTy);
893899 else
894 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV()));
900 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode()));
895901 }
896902
897903 if (!SP.isDefinition()) {
902908 if (SPTag == dwarf::DW_TAG_subroutine_type)
903909 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
904910 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
905 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV()));
911 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getNode()));
906912 AddUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
907913 SPDie->AddChild(Arg);
908914 }
912918 AddUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
913919
914920 // DW_TAG_inlined_subroutine may refer to this DIE.
915 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getGV());
921 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getNode());
916922 Slot = SPDie;
917923 return SPDie;
918924 }
921927 ///
922928 CompileUnit &DwarfDebug::FindCompileUnit(DICompileUnit Unit) const {
923929 DenseMap::const_iterator I =
924 CompileUnitMap.find(Unit.getGV());
930 CompileUnitMap.find(Unit.getNode());
925931 assert(I != CompileUnitMap.end() && "Missing compile unit.");
926932 return *I->second;
927933 }
974980
975981 /// getOrCreateScope - Returns the scope associated with the given descriptor.
976982 ///
977 DbgScope *DwarfDebug::getOrCreateScope(GlobalVariable *V) {
978 DbgScope *&Slot = DbgScopeMap[V];
983 DbgScope *DwarfDebug::getOrCreateScope(MDNode *N) {
984 DbgScope *&Slot = DbgScopeMap[N];
979985 if (Slot) return Slot;
980986
981987 DbgScope *Parent = NULL;
982 DIBlock Block(V);
988 DIBlock Block(N);
983989
984990 // Don't create a new scope if we already created one for an inlined function.
985 DenseMap::iterator
986 II = AbstractInstanceRootMap.find(V);
991 DenseMap::iterator
992 II = AbstractInstanceRootMap.find(N);
987993 if (II != AbstractInstanceRootMap.end())
988994 return LexicalScopeStack.back();
989995
990996 if (!Block.isNull()) {
991997 DIDescriptor ParentDesc = Block.getContext();
992998 Parent =
993 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getGV());
994 }
995
996 Slot = new DbgScope(Parent, DIDescriptor(V));
999 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getNode());
1000 }
1001
1002 Slot = new DbgScope(Parent, DIDescriptor(N));
9971003
9981004 if (Parent)
9991005 Parent->AddScope(Slot);
11021108 return;
11031109
11041110 // Get the subprogram debug information entry.
1105 DISubprogram SPD(Desc.getGV());
1111 DISubprogram SPD(Desc.getNode());
11061112
11071113 // Get the subprogram die.
1108 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getGV());
1114 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getNode());
11091115 assert(SPDie && "Missing subprogram descriptor");
11101116
11111117 if (!AbstractScope) {
11781184 return SrcId;
11791185 }
11801186
1181 void DwarfDebug::ConstructCompileUnit(GlobalVariable *GV) {
1182 DICompileUnit DIUnit(GV);
1187 void DwarfDebug::ConstructCompileUnit(MDNode *N) {
1188 DICompileUnit DIUnit(N);
11831189 std::string Dir, FN, Prod;
11841190 unsigned ID = GetOrCreateSourceID(DIUnit.getDirectory(Dir),
11851191 DIUnit.getFilename(FN));
12161222 ModuleCU = Unit;
12171223 }
12181224
1219 CompileUnitMap[DIUnit.getGV()] = Unit;
1225 CompileUnitMap[DIUnit.getNode()] = Unit;
12201226 CompileUnits.push_back(Unit);
12211227 }
12221228
1223 void DwarfDebug::ConstructGlobalVariableDIE(GlobalVariable *GV) {
1224 DIGlobalVariable DI_GV(GV);
1229 void DwarfDebug::ConstructGlobalVariableDIE(MDNode *N) {
1230 DIGlobalVariable DI_GV(N);
12251231
12261232 // Check for pre-existence.
1227 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getGV());
1233 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getNode());
12281234 if (Slot)
12291235 return;
12301236
12501256 return;
12511257 }
12521258
1253 void DwarfDebug::ConstructSubprogram(GlobalVariable *GV) {
1254 DISubprogram SP(GV);
1259 void DwarfDebug::ConstructSubprogram(MDNode *N) {
1260 DISubprogram SP(N);
12551261
12561262 // Check for pre-existence.
1257 DIE *&Slot = ModuleCU->getDieMapSlotFor(GV);
1263 DIE *&Slot = ModuleCU->getDieMapSlotFor(N);
12581264 if (Slot)
12591265 return;
12601266
15371543 /// correspondence to the source line list.
15381544 unsigned DwarfDebug::RecordSourceLine(unsigned Line, unsigned Col,
15391545 DICompileUnit CU) {
1546 if (!MMI)
1547 return 0;
1548
15401549 if (TimePassesIsEnabled)
15411550 DebugTimer->startTimer();
15421551
15711580 }
15721581
15731582 /// RecordRegionStart - Indicate the start of a region.
1574 unsigned DwarfDebug::RecordRegionStart(GlobalVariable *V) {
1583 unsigned DwarfDebug::RecordRegionStart(MDNode *N) {
15751584 if (TimePassesIsEnabled)
15761585 DebugTimer->startTimer();
15771586
1578 DbgScope *Scope = getOrCreateScope(V);
1587 DbgScope *Scope = getOrCreateScope(N);
15791588 unsigned ID = MMI->NextLabelID();
15801589 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
15811590 LexicalScopeStack.push_back(Scope);
15871596 }
15881597
15891598 /// RecordRegionEnd - Indicate the end of a region.
1590 unsigned DwarfDebug::RecordRegionEnd(GlobalVariable *V) {
1599 unsigned DwarfDebug::RecordRegionEnd(MDNode *N) {
15911600 if (TimePassesIsEnabled)
15921601 DebugTimer->startTimer();
15931602
1594 DbgScope *Scope = getOrCreateScope(V);
1603 DbgScope *Scope = getOrCreateScope(N);
15951604 unsigned ID = MMI->NextLabelID();
15961605 Scope->setEndLabelID(ID);
15971606 // FIXME : region.end() may not be in the last basic block.
16081617 }
16091618
16101619 /// RecordVariable - Indicate the declaration of a local variable.
1611 void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
1620 void DwarfDebug::RecordVariable(MDNode *N, unsigned FrameIndex) {
16121621 if (TimePassesIsEnabled)
16131622 DebugTimer->startTimer();
16141623
1615 DIDescriptor Desc(GV);
1624 DIDescriptor Desc(N);
16161625 DbgScope *Scope = NULL;
16171626 bool InlinedFnVar = false;
16181627
1619 if (Desc.getTag() == dwarf::DW_TAG_variable) {
1620 // GV is a global variable.
1621 DIGlobalVariable DG(GV);
1622 Scope = getOrCreateScope(DG.getContext().getGV());
1623 } else {
1628 if (Desc.getTag() == dwarf::DW_TAG_variable)
1629 Scope = getOrCreateScope(DIGlobalVariable(N).getContext().getNode());
1630 else {
16241631 bool InlinedVar = false;
1625 DIVariable DV(GV);
1626 GlobalVariable *V = DV.getContext().getGV();
1627 DISubprogram SP(V);
1632 MDNode *Context = DIVariable(N).getContext().getNode();
1633 DISubprogram SP(Context);
16281634 if (!SP.isNull()) {
16291635 // SP is inserted into DbgAbstractScopeMap when inlined function
16301636 // start was recorded by RecordInlineFnStart.
1631 DenseMap::iterator
1632 I = DbgAbstractScopeMap.find(SP.getGV());
1637 DenseMap::iterator
1638 I = DbgAbstractScopeMap.find(SP.getNode());
16331639 if (I != DbgAbstractScopeMap.end()) {
16341640 InlinedVar = true;
16351641 Scope = I->second;
16361642 }
16371643 }
1638 if (!InlinedVar) {
1639 // GV is a local variable.
1640 Scope = getOrCreateScope(V);
1641 }
1644 if (!InlinedVar)
1645 Scope = getOrCreateScope(Context);
16421646 }
16431647
16441648 assert(Scope && "Unable to find the variable's scope");
1645 DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex, InlinedFnVar);
1649 DbgVariable *DV = new DbgVariable(DIVariable(N), FrameIndex, InlinedFnVar);
16461650 Scope->AddVariable(DV);
16471651
16481652 if (TimePassesIsEnabled)
16601664 if (TimePassesIsEnabled)
16611665 DebugTimer->startTimer();
16621666
1663 GlobalVariable *GV = SP.getGV();
1664 DenseMap::iterator
1665 II = AbstractInstanceRootMap.find(GV);
1667 MDNode *Node = SP.getNode();
1668 DenseMap::iterator
1669 II = AbstractInstanceRootMap.find(Node);
16661670
16671671 if (II == AbstractInstanceRootMap.end()) {
16681672 // Create an abstract instance entry for this inlined function if it doesn't
16691673 // already exist.
1670 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
1674 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(Node));
16711675
16721676 // Get the compile unit context.
1673 DIE *SPDie = ModuleCU->getDieMapSlotFor(GV);
1677 DIE *SPDie = ModuleCU->getDieMapSlotFor(Node);
16741678 if (!SPDie)
16751679 SPDie = CreateSubprogramDIE(ModuleCU, SP, false, true);
16761680
16821686 AddUInt(SPDie, dwarf::DW_AT_inline, 0, dwarf::DW_INL_declared_not_inlined);
16831687
16841688 // Keep track of the abstract scope for this function.
1685 DbgAbstractScopeMap[GV] = Scope;
1686
1687 AbstractInstanceRootMap[GV] = Scope;
1689 DbgAbstractScopeMap[Node] = Scope;
1690
1691 AbstractInstanceRootMap[Node] = Scope;
16881692 AbstractInstanceRootList.push_back(Scope);
16891693 }
16901694
16911695 // Create a concrete inlined instance for this inlined function.
1692 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
1696 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(Node));
16931697 DIE *ScopeDie = new DIE(dwarf::DW_TAG_inlined_subroutine);
16941698 ScopeDie->setAbstractCompileUnit(ModuleCU);
16951699
1696 DIE *Origin = ModuleCU->getDieMapSlotFor(GV);
1700 DIE *Origin = ModuleCU->getDieMapSlotFor(Node);
16971701 AddDIEEntry(ScopeDie, dwarf::DW_AT_abstract_origin,
16981702 dwarf::DW_FORM_ref4, Origin);
16991703 AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
17071711 LexicalScopeStack.back()->AddConcreteInst(ConcreteScope);
17081712
17091713 // Keep track of the concrete scope that's inlined into this function.
1710 DenseMap >::iterator
1711 SI = DbgConcreteScopeMap.find(GV);
1714 DenseMap >::iterator
1715 SI = DbgConcreteScopeMap.find(Node);
17121716
17131717 if (SI == DbgConcreteScopeMap.end())
1714 DbgConcreteScopeMap[GV].push_back(ConcreteScope);
1718 DbgConcreteScopeMap[Node].push_back(ConcreteScope);
17151719 else
17161720 SI->second.push_back(ConcreteScope);
17171721
17181722 // Track the start label for this inlined function.
1719 DenseMap >::iterator
1720 I = InlineInfo.find(GV);
1723 DenseMap >::iterator
1724 I = InlineInfo.find(Node);
17211725
17221726 if (I == InlineInfo.end())
1723 InlineInfo[GV].push_back(LabelID);
1727 InlineInfo[Node].push_back(LabelID);
17241728 else
17251729 I->second.push_back(LabelID);
17261730
17381742 if (TimePassesIsEnabled)
17391743 DebugTimer->startTimer();
17401744
1741 GlobalVariable *GV = SP.getGV();
1742 DenseMap >::iterator
1743 I = DbgConcreteScopeMap.find(GV);
1745 MDNode *Node = SP.getNode();
1746 DenseMap >::iterator
1747 I = DbgConcreteScopeMap.find(Node);
17441748
17451749 if (I == DbgConcreteScopeMap.end()) {
17461750 // FIXME: Can this situation actually happen? And if so, should it?
24452449 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version");
24462450 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
24472451
2448 for (DenseMap<GlobalVariable *, SmallVector >::iterator
2452 for (DenseMap<MDNode *, SmallVector >::iterator
24492453 I = InlineInfo.begin(), E = InlineInfo.end(); I != E; ++I) {
2450 GlobalVariable *GV = I->first;
2454 MDNode *Node = I->first;
24512455 SmallVector &Labels = I->second;
2452 DISubprogram SP(GV);
2456 DISubprogram SP(Node);
24532457 std::string Name;
24542458 std::string LName;
24552459
24752479
24762480 for (SmallVector::iterator LI = Labels.begin(),
24772481 LE = Labels.end(); LI != LE; ++LI) {
2478 DIE *SP = ModuleCU->getDieMapSlotFor(GV);
2482 DIE *SP = ModuleCU->getDieMapSlotFor(Node);
24792483 Asm->EmitInt32(SP->getOffset()); Asm->EOL("DIE offset");
24802484
24812485 if (TD->getPointerSize() == sizeof(int32_t))