llvm.org GIT mirror llvm / 8245988
Revert 79977. It causes llvm-gcc bootstrap failures on some platforms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80073 91177308-0d34-0410-b5e6-96231b3b80d8 Devang Patel 11 years ago
47 changed file(s) with 1968 addition(s) and 1001 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 metadata
125 in an implementation-defined format
124 description of the source-level program is maintained in LLVM global
125 variables 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, 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.

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.

246247
247248

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

248249 variables, functions, source files, etc) is inserted by the language
249 front-end in the form of LLVM metadata.

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.

250256
251257

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

252258 debugging information representation (e.g. DWARF/Stabs/etc). It uses a
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.

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.

257267
258268

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

259269 assumptions about the source-level language being debugged, though it keeps
277287
278288
279289

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

280 provides a specification for well formed debug descriptors.

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.

281293
282294

Consumers of LLVM debug information expect the descriptors for program

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

292304
293

The fields of debug descriptors used internally by LLVM

305

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

294306 are restricted to only the simple data types int, uint,
295 bool, float, double, mdstring and
296 mdnode.

297
298
299

                  
                
300 !1 = metadata !{
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 {
301316 uint, ;; A tag
302317 ...
303318 }
310325 of tags are loosely bound to the tag values of DWARF information entries.
311326 However, that does not restrict the use of the information supplied to DWARF
312327 targets. To facilitate versioning of debug information, the tag is augmented
313 with the current debug version (LLVMDebugVersion = 7 << 16 or 0x70000 or
314 458752.)

328 with the current debug version (LLVMDebugVersion = 4 << 16 or 0x40000 or
329 262144.)

315330
316331

The details of the various descriptors follow.

317332
326341
327342
328343

                  
                
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
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
341355 }
342356
343357
373387
374388
375389

                  
                
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
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
390403 }
391404
392405
405418
406419
407420

                  
                
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)
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)
421433 }
422434
423435
437449
438450
439451

                  
                
440 !3 = metadata !{
441 i32, ;; Tag = 13 + LLVMDebugVersion (DW_TAG_lexical_block)
442 metadata ;; Reference to context descriptor
452 %llvm.dbg.block = type {
453 i32, ;; Tag = 13 + LLVMDebugVersion (DW_TAG_lexical_block)
454 { }* ;; Reference to context descriptor
443455 }
444456
445457
459471
460472
461473

                  
                
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
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
474485 }
475486
476487
511522
512523
513524

                  
                
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
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
524535 }
525536
526537
579590
580591
581592

                  
                
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
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
595606 }
596607
597608
690701
691702
692703

                  
                
693 !6 = metadata !{
694 i32, ;; Tag = 40 + LLVMDebugVersion
695 ;; (DW_TAG_enumerator)
696 metadata, ;; Name
697 i64 ;; Value
704 %llvm.dbg.enumerator.type = type {
705 i32, ;; Tag = 40 + LLVMDebugVersion (DW_TAG_enumerator)
706 i8*, ;; Name
707 i64 ;; Value
698708 }
699709
700710
714724
715725
716726

                  
                
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
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
724734 }
725735
726736
767777
768778
769779

                  
                
770 void %llvm.dbg.stoppoint( uint, uint, metadata)
780 void %llvm.dbg.stoppoint( uint, uint, { }* )
771781
772782
773783

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

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

788798
789799
790800

                  
                
791 void %llvm.dbg.func.start( metadata )
801 void %llvm.dbg.func.start( { }* )
792802
793803
794804

This intrinsic is used to link the debug information

812822
813823
814824

                  
                
815 void %llvm.dbg.region.start( metadata )
825 void %llvm.dbg.region.start( { }* )
816826
817827
818828

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

832842
833843
834844

                  
                
835 void %llvm.dbg.region.end( metadata )
845 void %llvm.dbg.region.end( { }* )
836846
837847
838848

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

853863
854864
855865

                  
                
856 void %llvm.dbg.declare( { } *, metadata )
866 void %llvm.dbg.declare( { } *, { }* )
857867
858868
859869

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

860870 first argument is the alloca for the variable, cast to a { }*. The
861871 second argument is
862872 the %llvm.dbg.variable containing
863 the description of the variable.

873 the description of the variable, also cast to a { }*.

864874
865875
866876
944954
945955 ...
946956
947 call void @llvm.dbg.func.start( metadata !0)
957 call void @llvm.dbg.func.start( %llvm.dbg.subprogram.type* @llvm.dbg.subprogram )
948958
949 call void @llvm.dbg.stoppoint( uint 2, uint 2, metadata !1)
959 call void @llvm.dbg.stoppoint( uint 2, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
950960
951961 call void @llvm.dbg.declare({}* %X, ...)
952962 call void @llvm.dbg.declare({}* %Y, ...)
953963
954964 ;; Evaluate expression on line 2, assigning to X.
955965
956 call void @llvm.dbg.stoppoint( uint 3, uint 2, metadata !1)
966 call void @llvm.dbg.stoppoint( uint 3, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
957967
958968 ;; Evaluate expression on line 3, assigning to Y.
959969
960970 call void @llvm.region.start()
961 call void @llvm.dbg.stoppoint( uint 5, uint 4, metadata !1)
971 call void @llvm.dbg.stoppoint( uint 5, uint 4, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
962972 call void @llvm.dbg.declare({}* %X, ...)
963973
964974 ;; Evaluate expression on line 5, assigning to Z.
965975
966 call void @llvm.dbg.stoppoint( uint 7, uint 2, metadata !1)
976 call void @llvm.dbg.stoppoint( uint 7, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
967977 call void @llvm.region.end()
968978
969 call void @llvm.dbg.stoppoint( uint 9, uint 2, metadata !1)
979 call void @llvm.dbg.stoppoint( uint 9, uint 2, %llvm.dbg.compile_unit* @llvm.dbg.compile_unit )
970980
971981 call void @llvm.region.end()
972982
10861096

                  
                
10871097 ...
10881098 ;;
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 ;;
10891113 ;; Define the compile unit for the source file "/Users/mine/sources/MySource.cpp".
10901114 ;;
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
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
11031124 ;;
11041125 ;; Define the compile unit for the header file "/Users/mine/sources/MyHeader.h".
11051126 ;;
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
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";
11181143 ...
11191144
11201145
11411166
11421167

                  
                
11431168 ;;
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 ;;
11441179 ;; Define the global itself.
11451180 ;;
11461181 %MyGlobal = global int 100
11471182 ...
11481183 ;;
1149 ;; List of debug info of globals
1150 ;;
1151 !llvm.dbg.gv = !{!0}
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"
11521189
11531190 ;;
11541191 ;; Define the global variable descriptor. Note the reference to the global
11551192 ;; variable anchor and the global variable itself.
11561193 ;;
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
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
11721207 ;;
11731208 ;; Define the basic type of 32 bit signed integer. Note that since int is an
11741209 ;; intrinsic type the source file is NULL and line 0.
11751210 ;;
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
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"
11891228
11901229
11911230
12131252
12141253

                  
                
12151254 ;;
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
1263 ;;
12161264 ;; Define the anchor for subprograms. Note that the second field of the
12171265 ;; anchor is 46, which is the same as the tag for subprograms
12181266 ;; (46 = DW_TAG_subprogram.)
12191267 ;;
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 }
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
12331291 ;;
12341292 ;; Define the subprogram itself.
12351293 ;;
1236 define i32 @main(i32 %argc, i8** %argv) {
1294 int %main(int %argc, i8** %argv) {
12371295 ...
12381296 }
12391297
12611319
12621320
12631321

                  
                
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 }
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"
12761333
12771334
12781335
12871344
12881345
12891346

                  
                
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 }
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"
13021358
13031359
13041360
13131369
13141370
13151371

                  
                
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 }
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"
13281383
13291384
13301385
13391394
13401395
13411396

                  
                
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 }
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"
13541408
13551409
13561410
13651419
13661420
13671421

                  
                
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 }
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"
13801433
13811434
13821435
13911444
13921445
13931446

                  
                
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 }
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"
14061458
14071459
14081460
14161468
14171469
14181470

                  
                
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 }
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"
14311482
14321483
14331484
14421493
14431494
14441495

                  
                
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 }
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"
14571507
14581508
14591509
14681518
14691519
14701520

                  
                
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 }
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"
14831532
14841533
14851534
14941543
14951544
14961545

                  
                
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 }
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"
15091557
15101558
15111559
15201568
15211569
15221570

                  
                
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 }
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"
15351582
15361583
15371584
15591606 ;;
15601607 ;; Define the typedef "IntPtr".
15611608 ;;
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 }
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"
15741620
15751621 ;;
15761622 ;; Define the pointer type.
15771623 ;;
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 }
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
15901635 ;;
15911636 ;; Define the const type.
15921637 ;;
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 }
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
16051649 ;;
16061650 ;; Define the int type.
16071651 ;;
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 }
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"
16201663
16211664
16221665
16481691 ;;
16491692 ;; Define basic type for unsigned int.
16501693 ;;
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 }
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
16631706 ;;
16641707 ;; Define composite type for struct Color.
16651708 ;;
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 }
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"
16801721
16811722 ;;
16821723 ;; Define the Red field.
16831724 ;;
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 }
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"
16961736
16971737 ;;
16981738 ;; Define the Green field.
16991739 ;;
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 }
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"
17121751
17131752 ;;
17141753 ;; Define the Blue field.
17151754 ;;
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 }
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"
17281766
17291767 ;;
17301768 ;; Define the array of fields used by the composite type Color.
17311769 ;;
1732 !3 = metadata !{metadata !4, metadata !6, metadata !7}
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"
17331774
17341775
17351776
17611802 ;;
17621803 ;; Define composite type for enum Trees
17631804 ;;
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 }
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"
1817
1818 ;;
1819 ;; Define Spruce enumerator.
1820 ;;
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"
1826
1827 ;;
1828 ;; Define Oak enumerator.
1829 ;;
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"
1835
1836 ;;
1837 ;; Define Maple enumerator.
1838 ;;
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"
17781844
17791845 ;;
17801846 ;; Define the array of enumerators used by composite type Trees.
17811847 ;;
1782 !3 = metadata !{metadata !4, metadata !5, metadata !6}
1783
1784 ;;
1785 ;; Define Spruce enumerator.
1786 ;;
1787 !4 = metadata !{i32 458792, metadata !"Spruce", i64 100}
1788
1789 ;;
1790 ;; Define Oak enumerator.
1791 ;;
1792 !5 = metadata !{i32 458792, metadata !"Oak", i64 200}
1793
1794 ;;
1795 ;; Define Maple enumerator.
1796 ;;
1797 !6 = metadata !{i32 458792, metadata !"Maple", i64 300}
1798
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"
17991852
18001853
18011854
1616 #ifndef LLVM_ANALYSIS_DEBUGINFO_H
1717 #define LLVM_ANALYSIS_DEBUGINFO_H
1818
19 #include "llvm/Metadata.h"
2019 #include "llvm/Target/TargetMachine.h"
2120 #include "llvm/ADT/StringMap.h"
2221 #include "llvm/ADT/DenseMap.h"
4443
4544 class DIDescriptor {
4645 protected:
47 MDNode *DbgNode;
48
49 /// DIDescriptor constructor. If the specified node is non-null, check
46 GlobalVariable *DbgGV;
47
48 /// DIDescriptor constructor. If the specified GV is non-null, this checks
5049 /// to make sure that the tag in the descriptor matches 'RequiredTag'. If
5150 /// not, the debug info is corrupt and we ignore it.
52 DIDescriptor(MDNode *N, unsigned RequiredTag);
51 DIDescriptor(GlobalVariable *GV, unsigned RequiredTag);
5352
5453 const std::string &getStringField(unsigned Elt, std::string &Result) const;
5554 unsigned getUnsignedField(unsigned Elt) const {
6059
6160 template
6261 DescTy getFieldAs(unsigned Elt) const {
63 return DescTy(getDescriptorField(Elt).getNode());
62 return DescTy(getDescriptorField(Elt).getGV());
6463 }
6564
6665 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
6766
6867 public:
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; }
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; }
7574
7675 unsigned getVersion() const {
7776 return getUnsignedField(0) & LLVMDebugVersionMask;
8180 return getUnsignedField(0) & ~LLVMDebugVersionMask;
8281 }
8382
84 /// ValidDebugInfo - Return true if N represents valid debug info value.
85 static bool ValidDebugInfo(MDNode *N, CodeGenOpt::Level OptLevel);
83 /// ValidDebugInfo - Return true if V represents valid debug info value.
84 static bool ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel);
8685
8786 /// dump - print descriptor.
8887 void dump() const;
9190 /// DISubrange - This is used to represent ranges, for array bounds.
9291 class DISubrange : public DIDescriptor {
9392 public:
94 explicit DISubrange(MDNode *N = 0)
95 : DIDescriptor(N, dwarf::DW_TAG_subrange_type) {}
93 explicit DISubrange(GlobalVariable *GV = 0)
94 : DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {}
9695
9796 int64_t getLo() const { return (int64_t)getUInt64Field(1); }
9897 int64_t getHi() const { return (int64_t)getUInt64Field(2); }
101100 /// DIArray - This descriptor holds an array of descriptors.
102101 class DIArray : public DIDescriptor {
103102 public:
104 explicit DIArray(MDNode *N = 0)
105 : DIDescriptor(N) {}
103 explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {}
106104
107105 unsigned getNumElements() const;
108106 DIDescriptor getElement(unsigned Idx) const {
113111 /// DICompileUnit - A wrapper for a compile unit.
114112 class DICompileUnit : public DIDescriptor {
115113 public:
116 explicit DICompileUnit(MDNode *N = 0)
117 : DIDescriptor(N, dwarf::DW_TAG_compile_unit) {}
114 explicit DICompileUnit(GlobalVariable *GV = 0)
115 : DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {}
118116
119117 unsigned getLanguage() const { return getUnsignedField(2); }
120118 const std::string &getFilename(std::string &F) const {
155153 /// type/precision or a file/line pair for location info.
156154 class DIEnumerator : public DIDescriptor {
157155 public:
158 explicit DIEnumerator(MDNode *N = 0)
159 : DIDescriptor(N, dwarf::DW_TAG_enumerator) {}
156 explicit DIEnumerator(GlobalVariable *GV = 0)
157 : DIDescriptor(GV, dwarf::DW_TAG_enumerator) {}
160158
161159 const std::string &getName(std::string &F) const {
162160 return getStringField(1, F);
177175 };
178176
179177 protected:
180 DIType(MDNode *N, unsigned Tag)
181 : DIDescriptor(N, Tag) {}
178 DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {}
182179 // This ctor is used when the Tag has already been validated by a derived
183180 // ctor.
184 DIType(MDNode *N, bool, bool) : DIDescriptor(N) {}
181 DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {}
185182
186183 public:
187184 /// isDerivedType - Return true if the specified tag is legal for
201198 /// Verify - Verify that a type descriptor is well formed.
202199 bool Verify() const;
203200 public:
204 explicit DIType(MDNode *N);
201 explicit DIType(GlobalVariable *GV);
205202 explicit DIType() {}
206203 virtual ~DIType() {}
207204
237234 /// DIBasicType - A basic type, like 'int' or 'float'.
238235 class DIBasicType : public DIType {
239236 public:
240 explicit DIBasicType(MDNode *N = 0)
241 : DIType(N, dwarf::DW_TAG_base_type) {}
237 explicit DIBasicType(GlobalVariable *GV)
238 : DIType(GV, dwarf::DW_TAG_base_type) {}
242239
243240 unsigned getEncoding() const { return getUnsignedField(9); }
244241
250247 /// a typedef, a pointer or reference, etc.
251248 class DIDerivedType : public DIType {
252249 protected:
253 explicit DIDerivedType(MDNode *N, bool, bool)
254 : DIType(N, true, true) {}
255 public:
256 explicit DIDerivedType(MDNode *N = 0)
257 : DIType(N, true, true) {
258 if (DbgNode && !isDerivedType(getTag()))
259 DbgNode = 0;
250 explicit DIDerivedType(GlobalVariable *GV, bool, bool)
251 : DIType(GV, true, true) {}
252 public:
253 explicit DIDerivedType(GlobalVariable *GV)
254 : DIType(GV, true, true) {
255 if (GV && !isDerivedType(getTag()))
256 DbgGV = 0;
260257 }
261258
262259 DIType getTypeDerivedFrom() const { return getFieldAs(9); }
278275 /// FIXME: Why is this a DIDerivedType??
279276 class DICompositeType : public DIDerivedType {
280277 public:
281 explicit DICompositeType(MDNode *N = 0)
282 : DIDerivedType(N, true, true) {
283 if (N && !isCompositeType(getTag()))
284 DbgNode = 0;
278 explicit DICompositeType(GlobalVariable *GV)
279 : DIDerivedType(GV, true, true) {
280 if (GV && !isCompositeType(getTag()))
281 DbgGV = 0;
285282 }
286283
287284 DIArray getTypeArray() const { return getFieldAs(10); }
297294 /// DIGlobal - This is a common class for global variables and subprograms.
298295 class DIGlobal : public DIDescriptor {
299296 protected:
300 explicit DIGlobal(MDNode *N, unsigned RequiredTag)
301 : DIDescriptor(N, RequiredTag) {}
297 explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag)
298 : DIDescriptor(GV, RequiredTag) {}
302299
303300 /// isSubprogram - Return true if the specified tag is legal for
304301 /// DISubprogram.
341338 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
342339 class DISubprogram : public DIGlobal {
343340 public:
344 explicit DISubprogram(MDNode *N = 0)
345 : DIGlobal(N, dwarf::DW_TAG_subprogram) {}
341 explicit DISubprogram(GlobalVariable *GV = 0)
342 : DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
346343
347344 DICompositeType getType() const { return getFieldAs(8); }
348345
352349 DICompositeType DCT(getFieldAs(8));
353350 if (!DCT.isNull()) {
354351 DIArray A = DCT.getTypeArray();
355 DIType T(A.getElement(0).getNode());
352 DIType T(A.getElement(0).getGV());
356353 return T.getName(F);
357354 }
358355 DIType T(getFieldAs(8));
373370 /// DIGlobalVariable - This is a wrapper for a global variable.
374371 class DIGlobalVariable : public DIGlobal {
375372 public:
376 explicit DIGlobalVariable(MDNode *N = 0)
377 : DIGlobal(N, dwarf::DW_TAG_variable) {}
373 explicit DIGlobalVariable(GlobalVariable *GV = 0)
374 : DIGlobal(GV, dwarf::DW_TAG_variable) {}
378375
379376 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
380377
389386 /// global etc).
390387 class DIVariable : public DIDescriptor {
391388 public:
392 explicit DIVariable(MDNode *N = 0)
393 : DIDescriptor(N) {
394 if (DbgNode && !isVariable(getTag()))
395 DbgNode = 0;
389 explicit DIVariable(GlobalVariable *GV = 0)
390 : DIDescriptor(GV) {
391 if (GV && !isVariable(getTag()))
392 DbgGV = 0;
396393 }
397394
398395 DIDescriptor getContext() const { return getDescriptorField(1); }
416413 /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc).
417414 class DIBlock : public DIDescriptor {
418415 public:
419 explicit DIBlock(MDNode *N = 0)
420 : DIDescriptor(N, dwarf::DW_TAG_lexical_block) {}
416 explicit DIBlock(GlobalVariable *GV = 0)
417 : DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
421418
422419 DIDescriptor getContext() const { return getDescriptorField(1); }
423420 };
544541
545542 private:
546543 Constant *GetTagConstant(unsigned TAG);
544 Constant *GetStringConstant(const std::string &String);
545
546 /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'.
547 Constant *getCastToEmpty(DIDescriptor D);
547548 };
548549
549550 /// Finds the stoppoint coressponding to this instruction, that is the
605606
606607 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
607608 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn);
609
608610 /// DebugInfoFinder - This object collects DebugInfo from a module.
609611 class DebugInfoFinder {
610612
648650 bool addType(DIType DT);
649651
650652 public:
651 typedef SmallVector<MDNode *, 8>::iterator iterator;
653 typedef SmallVector<GlobalVariable *, 8>::iterator iterator;
652654 iterator compile_unit_begin() { return CUs.begin(); }
653655 iterator compile_unit_end() { return CUs.end(); }
654656 iterator subprogram_begin() { return SPs.begin(); }
664666 unsigned type_count() { return TYs.size(); }
665667
666668 private:
667 SmallVector CUs; // Compile Units
668 SmallVector SPs; // Subprograms
669 SmallVector GVs; // Global Variables;
670 SmallVector TYs; // Types
671 SmallPtrSet NodesSeen;
669 SmallVector CUs; // Compile Units
670 SmallVector SPs; // Subprograms
671 SmallVector GVs; // Global Variables
672 SmallVector TYs; // Types
673 SmallPtrSet NodesSeen;
674
672675 };
673676 } // end namespace llvm
674677
1414 #define LLVM_AUTOUPGRADE_H
1515
1616 namespace llvm {
17 class Module;
1817 class Function;
1918 class CallInst;
2019
3433 /// so that it can update all calls to the old function.
3534 void UpgradeCallsToIntrinsic(Function* F);
3635
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);
4036 } // End llvm namespace
4137
4238 #endif
3232 class MachineInstr;
3333 class Value;
3434 class Module;
35 class MDNode;
35 class GlobalVariable;
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(MDNode *N);
90 unsigned RecordRegionStart(GlobalVariable *V);
9191
9292 /// RecordRegionEnd - Indicate the end of a region.
93 unsigned RecordRegionEnd(MDNode *N);
93 unsigned RecordRegionEnd(GlobalVariable *V);
9494
9595 /// getRecordSourceLineCount - Count source lines.
9696 unsigned getRecordSourceLineCount();
9797
9898 /// RecordVariable - Indicate the declaration of a local variable.
9999 ///
100 void RecordVariable(MDNode *N, unsigned FrameIndex);
100 void RecordVariable(GlobalVariable *GV, 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(MDNode *CompileUnit,
329 unsigned getOrCreateDebugLocID(GlobalVariable *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, MDNode *CU);
324 unsigned Line, unsigned Col, Value *CU);
325325 SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root,
326326 unsigned LabelID);
327327
20142014 SDUse Chain;
20152015 unsigned Line;
20162016 unsigned Column;
2017 MDNode *CU;
2017 Value *CU;
20182018 friend class SelectionDAG;
20192019 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2020 MDNode *cu)
2020 Value *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 MDNode *getCompileUnit() const { return CU; }
2028 Value *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"
2827 #include "llvm/Function.h"
2928 #include "llvm/Instructions.h"
3029 #include "llvm/Intrinsics.h"
8584 struct DbgStopPointInst : public DbgInfoIntrinsic {
8685 Value *getLineValue() const { return const_cast(getOperand(1)); }
8786 Value *getColumnValue() const { return const_cast(getOperand(2)); }
88 MDNode *getContext() const {
89 return cast(getOperand(3));
87 Value *getContext() const {
88 return StripCast(getOperand(3));
9089 }
9190
9291 unsigned getLine() const {
112111 /// DbgFuncStartInst - This represents the llvm.dbg.func.start instruction.
113112 ///
114113 struct DbgFuncStartInst : public DbgInfoIntrinsic {
115 MDNode *getSubprogram() const { return cast(getOperand(1)); }
114 Value *getSubprogram() const { return StripCast(getOperand(1)); }
116115
117116 // Methods for support type inquiry through isa, cast, and dyn_cast:
118117 static inline bool classof(const DbgFuncStartInst *) { return true; }
127126 /// DbgRegionStartInst - This represents the llvm.dbg.region.start
128127 /// instruction.
129128 struct DbgRegionStartInst : public DbgInfoIntrinsic {
130 MDNode *getContext() const { return cast(getOperand(1)); }
129 Value *getContext() const { return StripCast(getOperand(1)); }
131130
132131 // Methods for support type inquiry through isa, cast, and dyn_cast:
133132 static inline bool classof(const DbgRegionStartInst *) { return true; }
142141 /// DbgRegionEndInst - This represents the llvm.dbg.region.end instruction.
143142 ///
144143 struct DbgRegionEndInst : public DbgInfoIntrinsic {
145 MDNode *getContext() const { return cast(getOperand(1)); }
144 Value *getContext() const { return StripCast(getOperand(1)); }
146145
147146 // Methods for support type inquiry through isa, cast, and dyn_cast:
148147 static inline bool classof(const DbgRegionEndInst *) { return true; }
158157 ///
159158 struct DbgDeclareInst : public DbgInfoIntrinsic {
160159 Value *getAddress() const { return getOperand(1); }
161 MDNode *getVariable() const { return cast(getOperand(2)); }
160 Value *getVariable() const { return StripCast(getOperand(2)); }
162161
163162 // Methods for support type inquiry through isa, cast, and dyn_cast:
164163 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; // !{...}
113112
114113 def llvm_v2i8_ty : LLVMType; // 2 x i8
115114 def llvm_v4i8_ty : LLVMType; // 4 x i8
278277 let Properties = [IntrNoMem] in {
279278 def int_dbg_stoppoint : Intrinsic<[llvm_void_ty],
280279 [llvm_i32_ty, llvm_i32_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]>;
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]>;
285284 def int_dbg_declare : Intrinsic<[llvm_void_ty],
286 [llvm_descriptor_ty, llvm_metadata_ty]>;
285 [llvm_descriptor_ty, llvm_descriptor_ty]>;
287286 }
288287
289288 //===------------------ Exception Handling Intrinsics----------------------===//
109109 unsigned getNumOperands() { return User::getNumOperands(); }
110110
111111 SmallVector Node;
112
112113 friend struct ConstantCreator >;
113114 protected:
114115 explicit MDNode(LLVMContext &C, Value*const* Vals, unsigned NumVals);
1818 #include
1919
2020 namespace llvm {
21 class MDNode;
21 class GlobalVariable;
2222
2323 /// DebugLocTuple - Debug location tuple of filename id, line and column.
2424 ///
2525 struct DebugLocTuple {
26 MDNode *CompileUnit;
26 GlobalVariable *CompileUnit;
2727 unsigned Line, Col;
2828
2929 DebugLocTuple()
3030 : CompileUnit(0), Line(~0U), Col(~0U) {};
3131
32 DebugLocTuple(MDNode *n, unsigned l, unsigned c)
33 : CompileUnit(n), Line(l), Col(c) {};
32 DebugLocTuple(GlobalVariable *v, unsigned l, unsigned c)
33 : CompileUnit(v), 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((MDNode*)~1U, ~1U, ~1U);
71 return DebugLocTuple((GlobalVariable*)~1U, ~1U, ~1U);
7272 }
7373 static unsigned getHashValue(const DebugLocTuple &Val) {
74 return DenseMapInfo<MDNode*>::getHashValue(Val.CompileUnit) ^
74 return DenseMapInfo<GlobalVariable*>::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(FS->getSubprogram());
92 DISubprogram Subprogram(cast(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"
2423 #include "llvm/Support/Dwarf.h"
2524 #include "llvm/Support/DebugLoc.h"
2625 #include "llvm/Support/raw_ostream.h"
3231 //===----------------------------------------------------------------------===//
3332
3433 /// ValidDebugInfo - Return true if V represents valid debug info value.
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);
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);
4146
4247 // Check current version. Allow Version6 for now.
4348 unsigned Version = DI.getVersion();
4752 unsigned Tag = DI.getTag();
4853 switch (Tag) {
4954 case DW_TAG_variable:
50 assert(DIVariable(N).Verify() && "Invalid DebugInfo value");
55 assert(DIVariable(GV).Verify() && "Invalid DebugInfo value");
5156 break;
5257 case DW_TAG_compile_unit:
53 assert(DICompileUnit(N).Verify() && "Invalid DebugInfo value");
58 assert(DICompileUnit(GV).Verify() && "Invalid DebugInfo value");
5459 break;
5560 case DW_TAG_subprogram:
56 assert(DISubprogram(N).Verify() && "Invalid DebugInfo value");
61 assert(DISubprogram(GV).Verify() && "Invalid DebugInfo value");
5762 break;
5863 case DW_TAG_lexical_block:
5964 // FIXME: This interfers with the quality of generated code during
6873 return true;
6974 }
7075
71 DIDescriptor::DIDescriptor(MDNode *N, unsigned RequiredTag) {
72 DbgNode = N;
76 DIDescriptor::DIDescriptor(GlobalVariable *GV, unsigned RequiredTag) {
77 DbgGV = GV;
7378
7479 // If this is non-null, check to see if the Tag matches. If not, set to null.
75 if (N && getTag() != RequiredTag) {
76 DbgNode = 0;
77 }
80 if (GV && getTag() != RequiredTag)
81 DbgGV = 0;
7882 }
7983
8084 const std::string &
8185 DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
82 Result.clear();
83 if (DbgNode == 0)
86 if (DbgGV == 0) {
87 Result.clear();
8488 return Result;
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
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
92101 return Result;
93102 }
94103
95104 uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
96 if (DbgNode == 0)
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())
97110 return 0;
98111
99 if (Elt < DbgNode->getNumElements())
100 if (ConstantInt *CI = dyn_cast(DbgNode->getElement(Elt)))
101 return CI->getZExtValue();
102
112 if (ConstantInt *CI = dyn_cast(C->getOperand(Elt)))
113 return CI->getZExtValue();
103114 return 0;
104115 }
105116
106117 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
107 if (DbgNode == 0)
118 if (DbgGV == 0) return DIDescriptor();
119
120 Constant *C = DbgGV->getInitializer();
121 if (C == 0 || Elt >= C->getNumOperands())
108122 return DIDescriptor();
109123
110 if (Elt < DbgNode->getNumElements() && DbgNode->getElement(Elt))
111 return DIDescriptor(dyn_cast(DbgNode->getElement(Elt)));
112
113 return DIDescriptor();
124 C = C->getOperand(Elt);
125 return DIDescriptor(dyn_cast(C->stripPointerCasts()));
114126 }
115127
116128 GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
117 if (DbgNode == 0)
129 if (DbgGV == 0) return 0;
130
131 Constant *C = DbgGV->getInitializer();
132 if (C == 0 || Elt >= C->getNumOperands())
118133 return 0;
119134
120 if (Elt < DbgNode->getNumElements())
121 return dyn_cast(DbgNode->getElement(Elt));
122 return 0;
135 C = C->getOperand(Elt);
136 return dyn_cast(C->stripPointerCasts());
123137 }
124138
125139 //===----------------------------------------------------------------------===//
127141 //===----------------------------------------------------------------------===//
128142
129143 // Needed by DIVariable::getType().
130 DIType::DIType(MDNode *N) : DIDescriptor(N) {
131 if (!N) return;
144 DIType::DIType(GlobalVariable *GV) : DIDescriptor(GV) {
145 if (!GV) return;
132146 unsigned tag = getTag();
133147 if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) &&
134 !DICompositeType::isCompositeType(tag)) {
135 DbgNode = 0;
136 }
148 !DICompositeType::isCompositeType(tag))
149 DbgGV = 0;
137150 }
138151
139152 /// isDerivedType - Return true if the specified tag is legal for
150163 case dwarf::DW_TAG_inheritance:
151164 return true;
152165 default:
153 // CompositeTypes are currently modelled as DerivedTypes.
154 return isCompositeType(Tag);
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;
155169 }
156170 }
157171
185199 }
186200
187201 unsigned DIArray::getNumElements() const {
188 assert (DbgNode && "Invalid DIArray");
189 return DbgNode->getNumElements();
202 assert (DbgGV && "Invalid DIArray");
203 Constant *C = DbgGV->getInitializer();
204 assert (C && "Invalid DIArray initializer");
205 return C->getNumOperands();
190206 }
191207
192208 /// replaceAllUsesWith - Replace all uses of debug info referenced by
197213 return;
198214
199215 assert (!D.isNull() && "Can not replace with null");
200 DbgNode->replaceAllUsesWith(D.getNode());
201 delete DbgNode;
216 getGV()->replaceAllUsesWith(D.getGV());
217 getGV()->eraseFromParent();
202218 }
203219
204220 /// Verify - Verify that a compile unit is well formed.
324340
325341 /// dump - Print descriptor.
326342 void DIDescriptor::dump() const {
327 errs() << "[" << dwarf::TagString(getTag()) << "] ";
328 errs().write_hex((intptr_t)DbgNode) << ']';
343 errs() << "[" << dwarf::TagString(getTag()) << "] [GV:";
344 errs().write_hex((intptr_t)DbgGV) << ']';
329345 }
330346
331347 /// dump - Print compile unit.
366382 errs() << " [fwd] ";
367383
368384 if (isBasicType(Tag))
369 DIBasicType(DbgNode).dump();
385 DIBasicType(DbgGV).dump();
370386 else if (isDerivedType(Tag))
371 DIDerivedType(DbgNode).dump();
387 DIDerivedType(DbgGV).dump();
372388 else if (isCompositeType(Tag))
373 DICompositeType(DbgNode).dump();
389 DICompositeType(DbgGV).dump();
374390 else {
375391 errs() << "Invalid DIType\n";
376392 return;
417433 errs() << " [def] ";
418434
419435 if (isGlobalVariable(Tag))
420 DIGlobalVariable(DbgNode).dump();
436 DIGlobalVariable(DbgGV).dump();
421437
422438 errs() << "\n";
423439 }
457473 EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
458474 }
459475
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
460483 Constant *DIFactory::GetTagConstant(unsigned TAG) {
461484 assert((TAG & LLVMDebugVersionMask) == 0 &&
462485 "Tag too large for debug encoding!");
463486 return ConstantInt::get(Type::getInt32Ty(VMContext), TAG | LLVMDebugVersion);
464487 }
465488
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
466513 //===----------------------------------------------------------------------===//
467514 // DIFactory: Primary Constructors
468515 //===----------------------------------------------------------------------===//
470517 /// GetOrCreateArray - Create an descriptor for an array of descriptors.
471518 /// This implicitly uniques the arrays created.
472519 DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
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()));
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);
482538 }
483539
484540 /// GetOrCreateSubrange - Create a descriptor for a value range. This
485541 /// implicitly uniques the values returned.
486542 DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
487 Value *Elts[] = {
543 Constant *Elts[] = {
488544 GetTagConstant(dwarf::DW_TAG_subrange_type),
489545 ConstantInt::get(Type::getInt64Ty(VMContext), Lo),
490546 ConstantInt::get(Type::getInt64Ty(VMContext), Hi)
491547 };
492548
493 return DISubrange(MDNode::get(VMContext, &Elts[0], 3));
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);
494564 }
495565
496566
505575 bool isOptimized,
506576 const char *Flags,
507577 unsigned RunTimeVer) {
508 Value *Elts[] = {
578 Constant *Elts[] = {
509579 GetTagConstant(dwarf::DW_TAG_compile_unit),
510 llvm::Constant::getNullValue(Type::getInt32Ty(VMContext)),
580 llvm::Constant::getNullValue(EmptyStructPtr),
511581 ConstantInt::get(Type::getInt32Ty(VMContext), LangID),
512 MDString::get(VMContext, Filename),
513 MDString::get(VMContext, Directory),
514 MDString::get(VMContext, Producer),
582 GetStringConstant(Filename),
583 GetStringConstant(Directory),
584 GetStringConstant(Producer),
515585 ConstantInt::get(Type::getInt1Ty(VMContext), isMain),
516586 ConstantInt::get(Type::getInt1Ty(VMContext), isOptimized),
517 MDString::get(VMContext, Flags),
587 GetStringConstant(Flags),
518588 ConstantInt::get(Type::getInt32Ty(VMContext), RunTimeVer)
519589 };
520
521 return DICompileUnit(MDNode::get(VMContext, &Elts[0], 10));
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);
522600 }
523601
524602 /// CreateEnumerator - Create a single enumerator value.
525603 DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
526 Value *Elts[] = {
604 Constant *Elts[] = {
527605 GetTagConstant(dwarf::DW_TAG_enumerator),
528 MDString::get(VMContext, Name),
606 GetStringConstant(Name),
529607 ConstantInt::get(Type::getInt64Ty(VMContext), Val)
530608 };
531
532 return DIEnumerator(MDNode::get(VMContext, &Elts[0], 3));
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);
533619 }
534620
535621
542628 uint64_t AlignInBits,
543629 uint64_t OffsetInBits, unsigned Flags,
544630 unsigned Encoding) {
545 Value *Elts[] = {
631 Constant *Elts[] = {
546632 GetTagConstant(dwarf::DW_TAG_base_type),
547 Context.getNode(),
548 MDString::get(VMContext, Name),
549 CompileUnit.getNode(),
633 getCastToEmpty(Context),
634 GetStringConstant(Name),
635 getCastToEmpty(CompileUnit),
550636 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
551637 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
552638 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
555641 ConstantInt::get(Type::getInt32Ty(VMContext), Encoding)
556642 };
557643
558 return DIBasicType(MDNode::get(VMContext, &Elts[0], 10));
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);
559653 }
560654
561655 /// CreateDerivedType - Create a derived type like const qualified type,
570664 uint64_t OffsetInBits,
571665 unsigned Flags,
572666 DIType DerivedFrom) {
573 Value *Elts[] = {
667 Constant *Elts[] = {
574668 GetTagConstant(Tag),
575 Context.getNode(),
576 MDString::get(VMContext, Name),
577 CompileUnit.getNode(),
669 getCastToEmpty(Context),
670 GetStringConstant(Name),
671 getCastToEmpty(CompileUnit),
578672 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
579673 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
580674 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
581675 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
582676 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
583 DerivedFrom.getNode(),
677 getCastToEmpty(DerivedFrom)
584678 };
585
586 return DIDerivedType(MDNode::get(VMContext, &Elts[0], 10));
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);
587689 }
588690
589691 /// CreateCompositeType - Create a composite type like array, struct, etc.
600702 DIArray Elements,
601703 unsigned RuntimeLang) {
602704
603 Value *Elts[] = {
705 Constant *Elts[] = {
604706 GetTagConstant(Tag),
605 Context.getNode(),
606 MDString::get(VMContext, Name),
607 CompileUnit.getNode(),
707 getCastToEmpty(Context),
708 GetStringConstant(Name),
709 getCastToEmpty(CompileUnit),
608710 ConstantInt::get(Type::getInt32Ty(VMContext), LineNumber),
609711 ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits),
610712 ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits),
611713 ConstantInt::get(Type::getInt64Ty(VMContext), OffsetInBits),
612714 ConstantInt::get(Type::getInt32Ty(VMContext), Flags),
613 DerivedFrom.getNode(),
614 Elements.getNode(),
715 getCastToEmpty(DerivedFrom),
716 getCastToEmpty(Elements),
615717 ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang)
616718 };
617
618 return DICompositeType(MDNode::get(VMContext, &Elts[0], 12));
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);
619729 }
620730
621731
631741 bool isLocalToUnit,
632742 bool isDefinition) {
633743
634 Value *Elts[] = {
744 Constant *Elts[] = {
635745 GetTagConstant(dwarf::DW_TAG_subprogram),
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(),
746 llvm::Constant::getNullValue(EmptyStructPtr),
747 getCastToEmpty(Context),
748 GetStringConstant(Name),
749 GetStringConstant(DisplayName),
750 GetStringConstant(LinkageName),
751 getCastToEmpty(CompileUnit),
642752 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
643 Type.getNode(),
753 getCastToEmpty(Type),
644754 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
645755 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition)
646756 };
647757
648 return DISubprogram(MDNode::get(VMContext, &Elts[0], 11));
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);
649767 }
650768
651769 /// CreateGlobalVariable - Create a new descriptor for the specified global.
656774 DICompileUnit CompileUnit,
657775 unsigned LineNo, DIType Type,bool isLocalToUnit,
658776 bool isDefinition, llvm::GlobalVariable *Val) {
659 Value *Elts[] = {
777 Constant *Elts[] = {
660778 GetTagConstant(dwarf::DW_TAG_variable),
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(),
779 llvm::Constant::getNullValue(EmptyStructPtr),
780 getCastToEmpty(Context),
781 GetStringConstant(Name),
782 GetStringConstant(DisplayName),
783 GetStringConstant(LinkageName),
784 getCastToEmpty(CompileUnit),
667785 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
668 Type.getNode(),
786 getCastToEmpty(Type),
669787 ConstantInt::get(Type::getInt1Ty(VMContext), isLocalToUnit),
670788 ConstantInt::get(Type::getInt1Ty(VMContext), isDefinition),
671 Val
789 ConstantExpr::getBitCast(Val, EmptyStructPtr)
672790 };
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);
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);
682801 }
683802
684803
687806 const std::string &Name,
688807 DICompileUnit CompileUnit, unsigned LineNo,
689808 DIType Type) {
690 Value *Elts[] = {
809 Constant *Elts[] = {
691810 GetTagConstant(Tag),
692 Context.getNode(),
693 MDString::get(VMContext, Name),
694 CompileUnit.getNode(),
811 getCastToEmpty(Context),
812 GetStringConstant(Name),
813 getCastToEmpty(CompileUnit),
695814 ConstantInt::get(Type::getInt32Ty(VMContext), LineNo),
696 Type.getNode(),
815 getCastToEmpty(Type)
697816 };
698817
699 return DIVariable(MDNode::get(VMContext, &Elts[0], 6));
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);
700827 }
701828
702829
703830 /// CreateBlock - This creates a descriptor for a lexical block with the
704831 /// specified parent VMContext.
705832 DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
706 Value *Elts[] = {
833 Constant *Elts[] = {
707834 GetTagConstant(dwarf::DW_TAG_lexical_block),
708 Context.getNode()
835 getCastToEmpty(Context)
709836 };
710
711 return DIBlock(MDNode::get(VMContext, &Elts[0], 2));
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);
712847 }
713848
714849
730865 Value *Args[] = {
731866 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo),
732867 ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ColNo),
733 CU.getNode()
868 getCastToEmpty(CU)
734869 };
735870 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
736871 }
743878 FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start);
744879
745880 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
746 CallInst::Create(FuncStartFn, SP.getNode(), "", BB);
881 CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
747882 }
748883
749884 /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
754889 RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start);
755890
756891 // Call llvm.dbg.func.start.
757 CallInst::Create(RegionStartFn, D.getNode(), "", BB);
892 CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
758893 }
759894
760895 /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
765900 RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end);
766901
767902 // Call llvm.dbg.region.end.
768 CallInst::Create(RegionEndFn, D.getNode(), "", BB);
903 CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
769904 }
770905
771906 /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
776911 if (!DeclareFn)
777912 DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
778913
779 Value *Args[] = { Storage, D.getNode() };
914 Value *Args[] = { Storage, getCastToEmpty(D) };
780915 CallInst::Create(DeclareFn, Args, Args+2, "", BB);
781916 }
782
783917
784918 //===----------------------------------------------------------------------===//
785919 // DebugInfoFinder implementations.
787921
788922 /// processModule - Process entire module and collect debug info.
789923 void DebugInfoFinder::processModule(Module &M) {
790
791
924
792925 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
793926 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
794927 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
804937 else if (DbgDeclareInst *DDI = dyn_cast(BI))
805938 processDeclare(DDI);
806939 }
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)));
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);
814949 if (addGlobalVariable(DIG)) {
815950 addCompileUnit(DIG.getCompileUnit());
816951 processType(DIG.getType());
825960
826961 addCompileUnit(DT.getCompileUnit());
827962 if (DT.isCompositeType(DT.getTag())) {
828 DICompositeType DCT(DT.getNode());
963 DICompositeType DCT(DT.getGV());
829964 processType(DCT.getTypeDerivedFrom());
830965 DIArray DA = DCT.getTypeArray();
831966 if (!DA.isNull())
832967 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
833968 DIDescriptor D = DA.getElement(i);
834 DIType TypeE = DIType(D.getNode());
969 DIType TypeE = DIType(D.getGV());
835970 if (!TypeE.isNull())
836971 processType(TypeE);
837972 else
838 processSubprogram(DISubprogram(D.getNode()));
973 processSubprogram(DISubprogram(D.getGV()));
839974 }
840975 } else if (DT.isDerivedType(DT.getTag())) {
841 DIDerivedType DDT(DT.getNode());
976 DIDerivedType DDT(DT.getGV());
842977 if (!DDT.isNull())
843978 processType(DDT.getTypeDerivedFrom());
844979 }
856991
857992 /// processStopPoint - Process DbgStopPointInst.
858993 void DebugInfoFinder::processStopPoint(DbgStopPointInst *SPI) {
859 MDNode *Context = dyn_caste>(SPI->getContext());
994 GlobalVariable *Context = dyn_caste>(SPI->getContext());
860995 addCompileUnit(DICompileUnit(Context));
861996 }
862997
863998 /// processFuncStart - Process DbgFuncStartInst.
864999 void DebugInfoFinder::processFuncStart(DbgFuncStartInst *FSI) {
865 MDNode *SP = dyn_caste>(FSI->getSubprogram());
1000 GlobalVariable *SP = dyn_caste>(FSI->getSubprogram());
8661001 processSubprogram(DISubprogram(SP));
8671002 }
8681003
8691004 /// processRegionStart - Process DbgRegionStart.
8701005 void DebugInfoFinder::processRegionStart(DbgRegionStartInst *DRS) {
871 MDNode *SP = dyn_caste>(DRS->getContext());
1006 GlobalVariable *SP = dyn_caste>(DRS->getContext());
8721007 processSubprogram(DISubprogram(SP));
8731008 }
8741009
8751010 /// processRegionEnd - Process DbgRegionEnd.
8761011 void DebugInfoFinder::processRegionEnd(DbgRegionEndInst *DRE) {
877 MDNode *SP = dyn_caste>(DRE->getContext());
1012 GlobalVariable *SP = dyn_caste>(DRE->getContext());
8781013 processSubprogram(DISubprogram(SP));
8791014 }
8801015
8811016 /// processDeclare - Process DbgDeclareInst.
8821017 void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
883 DIVariable DV(cast<MDNode>(DDI->getVariable()));
1018 DIVariable DV(cast<GlobalVariable>(DDI->getVariable()));
8841019 if (DV.isNull())
8851020 return;
8861021
887 if (!NodesSeen.insert(DV.getNode()))
1022 if (!NodesSeen.insert(DV.getGV()))
8881023 return;
8891024
8901025 addCompileUnit(DV.getCompileUnit());
8961031 if (DT.isNull())
8971032 return false;
8981033
899 if (!NodesSeen.insert(DT.getNode()))
900 return false;
901
902 TYs.push_back(DT.getNode());
1034 if (!NodesSeen.insert(DT.getGV()))
1035 return false;
1036
1037 TYs.push_back(DT.getGV());
9031038 return true;
9041039 }
9051040
9081043 if (CU.isNull())
9091044 return false;
9101045
911 if (!NodesSeen.insert(CU.getNode()))
912 return false;
913
914 CUs.push_back(CU.getNode());
1046 if (!NodesSeen.insert(CU.getGV()))
1047 return false;
1048
1049 CUs.push_back(CU.getGV());
9151050 return true;
9161051 }
9171052
9201055 if (DIG.isNull())
9211056 return false;
9221057
923 if (!NodesSeen.insert(DIG.getNode()))
924 return false;
925
926 GVs.push_back(DIG.getNode());
1058 if (!NodesSeen.insert(DIG.getGV()))
1059 return false;
1060
1061 GVs.push_back(DIG.getGV());
9271062 return true;
9281063 }
9291064
9321067 if (SP.isNull())
9331068 return false;
9341069
935 if (!NodesSeen.insert(SP.getNode()))
936 return false;
937
938 SPs.push_back(SP.getNode());
1070 if (!NodesSeen.insert(SP.getGV()))
1071 return false;
1072
1073 SPs.push_back(SP.getGV());
9391074 return true;
9401075 }
9411076
9881123
9891124 Value *findDbgGlobalDeclare(GlobalVariable *V) {
9901125 const Module *M = V->getParent();
991 NamedMDNode *NMD = M->getNamedMetadata("llvm.dbg.gv");
992 if (!NMD)
993 return 0;
9941126
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();
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 }
10011146 }
1147
1148 if (Val->getType() == Ty)
1149 return Val;
1150
10021151 return 0;
10031152 }
10041153
10351184 if (GlobalVariable *GV = dyn_cast(const_cast(V))) {
10361185 Value *DIGV = findDbgGlobalDeclare(GV);
10371186 if (!DIGV) return false;
1038 DIGlobalVariable Var(cast<MDNode>(DIGV));
1187 DIGlobalVariable Var(cast<GlobalVariable>(DIGV));
10391188
10401189 Var.getDisplayName(DisplayName);
10411190 LineNo = Var.getLineNumber();
10441193 } else {
10451194 const DbgDeclareInst *DDI = findDbgDeclare(V);
10461195 if (!DDI) return false;
1047 DIVariable Var(cast<MDNode>(DDI->getVariable()));
1196 DIVariable Var(cast<GlobalVariable>(DDI->getVariable()));
10481197
10491198 Var.getName(DisplayName);
10501199 LineNo = Var.getLineNumber();
11021251 Value *Context = SPI.getContext();
11031252
11041253 // If this location is already tracked then use it.
1105 DebugLocTuple Tuple(cast<MDNode>(Context), SPI.getLine(),
1254 DebugLocTuple Tuple(cast<GlobalVariable>(Context), SPI.getLine(),
11061255 SPI.getColumn());
11071256 DenseMap::iterator II
11081257 = DebugLocInfo.DebugIdMap.find(Tuple);
11241273 DebugLoc DL;
11251274 Value *SP = FSI.getSubprogram();
11261275
1127 DISubprogram Subprogram(cast<MDNode>(SP));
1276 DISubprogram Subprogram(cast<GlobalVariable>(SP));
11281277 unsigned Line = Subprogram.getLineNumber();
11291278 DICompileUnit CU(Subprogram.getCompileUnit());
11301279
11311280 // If this location is already tracked then use it.
1132 DebugLocTuple Tuple(CU.getNode(), Line, /* Column */ 0);
1281 DebugLocTuple Tuple(CU.getGV(), Line, /* Column */ 0);
11331282 DenseMap::iterator II
11341283 = DebugLocInfo.DebugIdMap.find(Tuple);
11351284 if (II != DebugLocInfo.DebugIdMap.end())
11451294
11461295 /// isInlinedFnStart - Return true if FSI is starting an inlined function.
11471296 bool isInlinedFnStart(DbgFuncStartInst &FSI, const Function *CurrentFn) {
1148 DISubprogram Subprogram(cast<MDNode>(FSI.getSubprogram()));
1297 DISubprogram Subprogram(cast<GlobalVariable>(FSI.getSubprogram()));
11491298 if (Subprogram.describes(CurrentFn))
11501299 return false;
11511300
11541303
11551304 /// isInlinedFnEnd - Return true if REI is ending an inlined function.
11561305 bool isInlinedFnEnd(DbgRegionEndInst &REI, const Function *CurrentFn) {
1157 DISubprogram Subprogram(cast<MDNode>(REI.getContext()));
1306 DISubprogram Subprogram(cast<GlobalVariable>(REI.getContext()));
11581307 if (Subprogram.isNull() || Subprogram.describes(CurrentFn))
11591308 return false;
11601309
11611310 return true;
11621311 }
1163 }
1312
1313 }
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);
102100 return false;
103101 }
104102
1515 #include "llvm/Constants.h"
1616 #include "llvm/DerivedTypes.h"
1717 #include "llvm/InlineAsm.h"
18 #include "llvm/IntrinsicInst.h"
18 #include "llvm/Instructions.h"
1919 #include "llvm/LLVMContext.h"
2020 #include "llvm/Metadata.h"
2121 #include "llvm/Module.h"
21912191 }
21922192 }
21932193 std::vector >().swap(UpgradedIntrinsics);
2194
2195 // Check debug info intrinsics.
2196 CheckDebugInfoIntrinsics(TheModule);
2197
2194
21982195 return TheModule;
21992196 }
22002197
17381738 // Print source line info.
17391739 O.PadToColumn(MAI->getCommentColumn());
17401740 O << MAI->getCommentString() << " SrcLine ";
1741 if (DLT.CompileUnit) {
1742 std::string Str;
1743 DICompileUnit CU(DLT.CompileUnit);
1744 O << CU.getFilename(Str) << " ";
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() << " ";
17451746 }
17461747 O << DLT.Line;
17471748 if (DLT.Col != 0)
17591760 // Print source line info
17601761 O.PadToColumn(MAI->getCommentColumn());
17611762 O << MAI->getCommentString() << " SrcLine ";
1762 if (DLT.CompileUnit) {
1763 std::string Str;
1764 DICompileUnit CU(DLT.CompileUnit);
1765 O << CU.getFilename(Str) << " ";
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() << " ";
17661768 }
17671769 O << DLT.Line;
17681770 if (DLT.Col != 0)
99 // This file contains support for writing dwarf debug info into asm files.
1010 //
1111 //===----------------------------------------------------------------------===//
12 #define DEBUG_TYPE "dwarfdebug"
12
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"
2726 #include "llvm/System/Path.h"
2827 using namespace llvm;
2928
5655
5756 /// GVToDieMap - Tracks the mapping of unit level debug informaton
5857 /// variables to debug information entries.
59 /// FIXME : Rename GVToDieMap -> NodeToDieMap
60 std::map<MDNode *, DIE *> GVToDieMap;
58 std::map<GlobalVariable *, DIE *> GVToDieMap;
6159
6260 /// GVToDIEEntryMap - Tracks the mapping of unit level debug informaton
6361 /// descriptors to debug information entries using a DIEEntry proxy.
64 /// FIXME : Rename
65 std::map<MDNode *, DIEEntry *> GVToDIEEntryMap;
62 std::map<GlobalVariable *, DIEEntry *> GVToDIEEntryMap;
6663
6764 /// Globals - A map of globally visible named entities for this unit.
6865 ///
9188
9289 /// getDieMapSlotFor - Returns the debug information entry map slot for the
9390 /// specified debug variable.
94 DIE *&getDieMapSlotFor(MDNode *N) { return GVToDieMap[N]; }
91 DIE *&getDieMapSlotFor(GlobalVariable *GV) { return GVToDieMap[GV]; }
9592
9693 /// getDIEEntrySlotFor - Returns the debug information entry proxy slot for
9794 /// the specified debug variable.
98 DIEEntry *&getDIEEntrySlotFor(MDNode *N) {
99 return GVToDIEEntryMap[N];
95 DIEEntry *&getDIEEntrySlotFor(GlobalVariable *GV) {
96 return GVToDIEEntryMap[GV];
10097 }
10198
10299 /// AddDie - Adds or interns the DIE to the compile unit.
241238 for (unsigned j = 0, M = Values.size(); j < M; ++j)
242239 delete Values[j];
243240
244 for (DenseMapMDNode *, DbgScope *>::iterator
241 for (DenseMapGlobalVariable *, DbgScope *>::iterator
245242 I = AbstractInstanceRootMap.begin(),
246243 E = AbstractInstanceRootMap.end(); I != E;++I)
247244 delete I->second;
533530 return;
534531
535532 // Check for pre-existence.
536 DIEEntry *&Slot = DW_Unit->getDIEEntrySlotFor(Ty.getNode());
533 DIEEntry *&Slot = DW_Unit->getDIEEntrySlotFor(Ty.getGV());
537534
538535 // If it exists then use the existing value.
539536 if (Slot) {
547544 // Construct type.
548545 DIE Buffer(dwarf::DW_TAG_base_type);
549546 if (Ty.isBasicType(Ty.getTag()))
550 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getNode()));
551 else if (Ty.isCompositeType(Ty.getTag()))
552 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getNode()));
547 ConstructTypeDIE(DW_Unit, Buffer, DIBasicType(Ty.getGV()));
548 else if (Ty.isDerivedType(Ty.getTag()))
549 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getGV()));
553550 else {
554 assert(Ty.isDerivedType(Ty.getTag()) && "Unknown kind of DIType");
555 ConstructTypeDIE(DW_Unit, Buffer, DIDerivedType(Ty.getNode()));
556
551 assert(Ty.isCompositeType(Ty.getTag()) && "Unknown kind of DIType");
552 ConstructTypeDIE(DW_Unit, Buffer, DICompositeType(Ty.getGV()));
557553 }
558554
559555 // Add debug information entry to entity and appropriate context.
560556 DIE *Die = NULL;
561557 DIDescriptor Context = Ty.getContext();
562558 if (!Context.isNull())
563 Die = DW_Unit->getDieMapSlotFor(Context.getNode());
559 Die = DW_Unit->getDieMapSlotFor(Context.getGV());
564560
565561 if (Die) {
566562 DIE *Child = new DIE(Buffer);
645641 // Add enumerators to enumeration type.
646642 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
647643 DIE *ElemDie = NULL;
648 DIEnumerator Enum(Elements.getElement(i).getNode());
644 DIEnumerator Enum(Elements.getElement(i).getGV());
649645 ElemDie = ConstructEnumTypeDIE(DW_Unit, &Enum);
650646 Buffer.AddChild(ElemDie);
651647 }
655651 // Add return type.
656652 DIArray Elements = CTy.getTypeArray();
657653 DIDescriptor RTy = Elements.getElement(0);
658 AddType(DW_Unit, &Buffer, DIType(RTy.getNode()));
654 AddType(DW_Unit, &Buffer, DIType(RTy.getGV()));
659655
660656 // Add prototype flag.
661657 AddUInt(&Buffer, dwarf::DW_AT_prototyped, dwarf::DW_FORM_flag, 1);
664660 for (unsigned i = 1, N = Elements.getNumElements(); i < N; ++i) {
665661 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
666662 DIDescriptor Ty = Elements.getElement(i);
667 AddType(DW_Unit, Arg, DIType(Ty.getNode()));
663 AddType(DW_Unit, Arg, DIType(Ty.getGV()));
668664 Buffer.AddChild(Arg);
669665 }
670666 }
682678 // Add elements to structure type.
683679 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
684680 DIDescriptor Element = Elements.getElement(i);
685 if (Element.isNull())
686 continue;
687681 DIE *ElemDie = NULL;
688682 if (Element.getTag() == dwarf::DW_TAG_subprogram)
689683 ElemDie = CreateSubprogramDIE(DW_Unit,
690 DISubprogram(Element.getNode()));
684 DISubprogram(Element.getGV()));
691685 else
692686 ElemDie = CreateMemberDIE(DW_Unit,
693 DIDerivedType(Element.getNode()));
687 DIDerivedType(Element.getGV()));
694688 Buffer.AddChild(ElemDie);
695689 }
696690
767761 for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
768762 DIDescriptor Element = Elements.getElement(i);
769763 if (Element.getTag() == dwarf::DW_TAG_subrange_type)
770 ConstructSubrangeDIE(Buffer, DISubrange(Element.getNode()), IndexTy);
764 ConstructSubrangeDIE(Buffer, DISubrange(Element.getGV()), IndexTy);
771765 }
772766 }
773767
894888 if (Args.isNull() || SPTag != dwarf::DW_TAG_subroutine_type)
895889 AddType(DW_Unit, SPDie, SPTy);
896890 else
897 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getNode()));
891 AddType(DW_Unit, SPDie, DIType(Args.getElement(0).getGV()));
898892 }
899893
900894 if (!SP.isDefinition()) {
905899 if (SPTag == dwarf::DW_TAG_subroutine_type)
906900 for (unsigned i = 1, N = Args.getNumElements(); i < N; ++i) {
907901 DIE *Arg = new DIE(dwarf::DW_TAG_formal_parameter);
908 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getNode()));
902 AddType(DW_Unit, Arg, DIType(Args.getElement(i).getGV()));
909903 AddUInt(Arg, dwarf::DW_AT_artificial, dwarf::DW_FORM_flag, 1); // ??
910904 SPDie->AddChild(Arg);
911905 }
915909 AddUInt(SPDie, dwarf::DW_AT_external, dwarf::DW_FORM_flag, 1);
916910
917911 // DW_TAG_inlined_subroutine may refer to this DIE.
918 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getNode());
912 DIE *&Slot = DW_Unit->getDieMapSlotFor(SP.getGV());
919913 Slot = SPDie;
920914 return SPDie;
921915 }
924918 ///
925919 CompileUnit &DwarfDebug::FindCompileUnit(DICompileUnit Unit) const {
926920 DenseMap::const_iterator I =
927 CompileUnitMap.find(Unit.getNode());
921 CompileUnitMap.find(Unit.getGV());
928922 assert(I != CompileUnitMap.end() && "Missing compile unit.");
929923 return *I->second;
930924 }
977971
978972 /// getOrCreateScope - Returns the scope associated with the given descriptor.
979973 ///
980 DbgScope *DwarfDebug::getOrCreateScope(MDNode *N) {
981 DbgScope *&Slot = DbgScopeMap[N];
974 DbgScope *DwarfDebug::getOrCreateScope(GlobalVariable *V) {
975 DbgScope *&Slot = DbgScopeMap[V];
982976 if (Slot) return Slot;
983977
984978 DbgScope *Parent = NULL;
985 DIBlock Block(N);
979 DIBlock Block(V);
986980
987981 // Don't create a new scope if we already created one for an inlined function.
988 DenseMap::iterator
989 II = AbstractInstanceRootMap.find(N);
982 DenseMap::iterator
983 II = AbstractInstanceRootMap.find(V);
990984 if (II != AbstractInstanceRootMap.end())
991985 return LexicalScopeStack.back();
992986
993987 if (!Block.isNull()) {
994988 DIDescriptor ParentDesc = Block.getContext();
995989 Parent =
996 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getNode());
997 }
998
999 Slot = new DbgScope(Parent, DIDescriptor(N));
990 ParentDesc.isNull() ? NULL : getOrCreateScope(ParentDesc.getGV());
991 }
992
993 Slot = new DbgScope(Parent, DIDescriptor(V));
1000994
1001995 if (Parent)
1002996 Parent->AddScope(Slot);
11051099 return;
11061100
11071101 // Get the subprogram debug information entry.
1108 DISubprogram SPD(Desc.getNode());
1102 DISubprogram SPD(Desc.getGV());
11091103
11101104 // Get the subprogram die.
1111 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getNode());
1105 DIE *SPDie = ModuleCU->getDieMapSlotFor(SPD.getGV());
11121106 assert(SPDie && "Missing subprogram descriptor");
11131107
11141108 if (!AbstractScope) {
11811175 return SrcId;
11821176 }
11831177
1184 void DwarfDebug::ConstructCompileUnit(MDNode *N) {
1185 DICompileUnit DIUnit(N);
1178 void DwarfDebug::ConstructCompileUnit(GlobalVariable *GV) {
1179 DICompileUnit DIUnit(GV);
11861180 std::string Dir, FN, Prod;
11871181 unsigned ID = GetOrCreateSourceID(DIUnit.getDirectory(Dir),
11881182 DIUnit.getFilename(FN));
12191213 ModuleCU = Unit;
12201214 }
12211215
1222 CompileUnitMap[DIUnit.getNode()] = Unit;
1216 CompileUnitMap[DIUnit.getGV()] = Unit;
12231217 CompileUnits.push_back(Unit);
12241218 }
12251219
1226 void DwarfDebug::ConstructGlobalVariableDIE(MDNode *N) {
1227 DIGlobalVariable DI_GV(N);
1220 void DwarfDebug::ConstructGlobalVariableDIE(GlobalVariable *GV) {
1221 DIGlobalVariable DI_GV(GV);
12281222
12291223 // Check for pre-existence.
1230 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getNode());
1224 DIE *&Slot = ModuleCU->getDieMapSlotFor(DI_GV.getGV());
12311225 if (Slot)
12321226 return;
12331227
12531247 return;
12541248 }
12551249
1256 void DwarfDebug::ConstructSubprogram(MDNode *N) {
1257 DISubprogram SP(N);
1250 void DwarfDebug::ConstructSubprogram(GlobalVariable *GV) {
1251 DISubprogram SP(GV);
12581252
12591253 // Check for pre-existence.
1260 DIE *&Slot = ModuleCU->getDieMapSlotFor(N);
1254 DIE *&Slot = ModuleCU->getDieMapSlotFor(GV);
12611255 if (Slot)
12621256 return;
12631257
15401534 /// correspondence to the source line list.
15411535 unsigned DwarfDebug::RecordSourceLine(unsigned Line, unsigned Col,
15421536 DICompileUnit CU) {
1543 if (!MMI)
1544 return 0;
1545
15461537 if (TimePassesIsEnabled)
15471538 DebugTimer->startTimer();
15481539
15771568 }
15781569
15791570 /// RecordRegionStart - Indicate the start of a region.
1580 unsigned DwarfDebug::RecordRegionStart(MDNode *N) {
1571 unsigned DwarfDebug::RecordRegionStart(GlobalVariable *V) {
15811572 if (TimePassesIsEnabled)
15821573 DebugTimer->startTimer();
15831574
1584 DbgScope *Scope = getOrCreateScope(N);
1575 DbgScope *Scope = getOrCreateScope(V);
15851576 unsigned ID = MMI->NextLabelID();
15861577 if (!Scope->getStartLabelID()) Scope->setStartLabelID(ID);
15871578 LexicalScopeStack.push_back(Scope);
15931584 }
15941585
15951586 /// RecordRegionEnd - Indicate the end of a region.
1596 unsigned DwarfDebug::RecordRegionEnd(MDNode *N) {
1587 unsigned DwarfDebug::RecordRegionEnd(GlobalVariable *V) {
15971588 if (TimePassesIsEnabled)
15981589 DebugTimer->startTimer();
15991590
1600 DbgScope *Scope = getOrCreateScope(N);
1591 DbgScope *Scope = getOrCreateScope(V);
16011592 unsigned ID = MMI->NextLabelID();
16021593 Scope->setEndLabelID(ID);
16031594 // FIXME : region.end() may not be in the last basic block.
16141605 }
16151606
16161607 /// RecordVariable - Indicate the declaration of a local variable.
1617 void DwarfDebug::RecordVariable(MDNode *N, unsigned FrameIndex) {
1608 void DwarfDebug::RecordVariable(GlobalVariable *GV, unsigned FrameIndex) {
16181609 if (TimePassesIsEnabled)
16191610 DebugTimer->startTimer();
16201611
1621 DIDescriptor Desc(N);
1612 DIDescriptor Desc(GV);
16221613 DbgScope *Scope = NULL;
16231614 bool InlinedFnVar = false;
16241615
1625 if (Desc.getTag() == dwarf::DW_TAG_variable)
1626 Scope = getOrCreateScope(DIGlobalVariable(N).getContext().getNode());
1627 else {
1616 if (Desc.getTag() == dwarf::DW_TAG_variable) {
1617 // GV is a global variable.
1618 DIGlobalVariable DG(GV);
1619 Scope = getOrCreateScope(DG.getContext().getGV());
1620 } else {
16281621 bool InlinedVar = false;
1629 MDNode *Context = DIVariable(N).getContext().getNode();
1630 DISubprogram SP(Context);
1622 DIVariable DV(GV);
1623 GlobalVariable *V = DV.getContext().getGV();
1624 DISubprogram SP(V);
16311625 if (!SP.isNull()) {
16321626 // SP is inserted into DbgAbstractScopeMap when inlined function
16331627 // start was recorded by RecordInlineFnStart.
1634 DenseMap::iterator
1635 I = DbgAbstractScopeMap.find(SP.getNode());
1628 DenseMap::iterator
1629 I = DbgAbstractScopeMap.find(SP.getGV());
16361630 if (I != DbgAbstractScopeMap.end()) {
16371631 InlinedVar = true;
16381632 Scope = I->second;
16391633 }
16401634 }
1641 if (!InlinedVar)
1642 Scope = getOrCreateScope(Context);
1635 if (!InlinedVar) {
1636 // GV is a local variable.
1637 Scope = getOrCreateScope(V);
1638 }
16431639 }
16441640
16451641 assert(Scope && "Unable to find the variable's scope");
1646 DbgVariable *DV = new DbgVariable(DIVariable(N), FrameIndex, InlinedFnVar);
1642 DbgVariable *DV = new DbgVariable(DIVariable(GV), FrameIndex, InlinedFnVar);
16471643 Scope->AddVariable(DV);
16481644
16491645 if (TimePassesIsEnabled)
16611657 if (TimePassesIsEnabled)
16621658 DebugTimer->startTimer();
16631659
1664 MDNode *Node = SP.getNode();
1665 DenseMap::iterator
1666 II = AbstractInstanceRootMap.find(Node);
1660 GlobalVariable *GV = SP.getGV();
1661 DenseMap::iterator
1662 II = AbstractInstanceRootMap.find(GV);
16671663
16681664 if (II == AbstractInstanceRootMap.end()) {
16691665 // Create an abstract instance entry for this inlined function if it doesn't
16701666 // already exist.
1671 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(Node));
1667 DbgScope *Scope = new DbgScope(NULL, DIDescriptor(GV));
16721668
16731669 // Get the compile unit context.
1674 DIE *SPDie = ModuleCU->getDieMapSlotFor(Node);
1670 DIE *SPDie = ModuleCU->getDieMapSlotFor(GV);
16751671 if (!SPDie)
16761672 SPDie = CreateSubprogramDIE(ModuleCU, SP, false, true);
16771673
16831679 AddUInt(SPDie, dwarf::DW_AT_inline, 0, dwarf::DW_INL_declared_not_inlined);
16841680
16851681 // Keep track of the abstract scope for this function.
1686 DbgAbstractScopeMap[Node] = Scope;
1687
1688 AbstractInstanceRootMap[Node] = Scope;
1682 DbgAbstractScopeMap[GV] = Scope;
1683
1684 AbstractInstanceRootMap[GV] = Scope;
16891685 AbstractInstanceRootList.push_back(Scope);
16901686 }
16911687
16921688 // Create a concrete inlined instance for this inlined function.
1693 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(Node));
1689 DbgConcreteScope *ConcreteScope = new DbgConcreteScope(DIDescriptor(GV));
16941690 DIE *ScopeDie = new DIE(dwarf::DW_TAG_inlined_subroutine);
16951691 ScopeDie->setAbstractCompileUnit(ModuleCU);
16961692
1697 DIE *Origin = ModuleCU->getDieMapSlotFor(Node);
1693 DIE *Origin = ModuleCU->getDieMapSlotFor(GV);
16981694 AddDIEEntry(ScopeDie, dwarf::DW_AT_abstract_origin,
16991695 dwarf::DW_FORM_ref4, Origin);
17001696 AddUInt(ScopeDie, dwarf::DW_AT_call_file, 0, ModuleCU->getID());
17081704 LexicalScopeStack.back()->AddConcreteInst(ConcreteScope);
17091705
17101706 // Keep track of the concrete scope that's inlined into this function.
1711 DenseMap >::iterator
1712 SI = DbgConcreteScopeMap.find(Node);
1707 DenseMap >::iterator
1708 SI = DbgConcreteScopeMap.find(GV);
17131709
17141710 if (SI == DbgConcreteScopeMap.end())
1715 DbgConcreteScopeMap[Node].push_back(ConcreteScope);
1711 DbgConcreteScopeMap[GV].push_back(ConcreteScope);
17161712 else
17171713 SI->second.push_back(ConcreteScope);
17181714
17191715 // Track the start label for this inlined function.
1720 DenseMap >::iterator
1721 I = InlineInfo.find(Node);
1716 DenseMap >::iterator
1717 I = InlineInfo.find(GV);
17221718
17231719 if (I == InlineInfo.end())
1724 InlineInfo[Node].push_back(LabelID);
1720 InlineInfo[GV].push_back(LabelID);
17251721 else
17261722 I->second.push_back(LabelID);
17271723
17391735 if (TimePassesIsEnabled)
17401736 DebugTimer->startTimer();
17411737
1742 MDNode *Node = SP.getNode();
1743 DenseMap >::iterator
1744 I = DbgConcreteScopeMap.find(Node);
1738 GlobalVariable *GV = SP.getGV();
1739 DenseMap >::iterator
1740 I = DbgConcreteScopeMap.find(GV);
17451741
17461742 if (I == DbgConcreteScopeMap.end()) {
17471743 // FIXME: Can this situation actually happen? And if so, should it?
24462442 Asm->EmitInt16(dwarf::DWARF_VERSION); Asm->EOL("Dwarf Version");
24472443 Asm->EmitInt8(TD->getPointerSize()); Asm->EOL("Address Size (in bytes)");
24482444
2449 for (DenseMap<MDNode *, SmallVector >::iterator
2445 for (DenseMap<GlobalVariable *, SmallVector >::iterator
24502446 I = InlineInfo.begin(), E = InlineInfo.end(); I != E; ++I) {
2451 MDNode *Node = I->first;
2447 GlobalVariable *GV = I->first;
24522448 SmallVector &Labels = I->second;
2453 DISubprogram SP(Node);
2449