1 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Collect meta information for a module. This information should be in a
11 // neutral form that can be used by different debugging and exception handling
14 // The organization of information is primarily clustered around the source
15 // compile units. The main exception is source line correspondence where
16 // inlining may interleave code from various compile units.
18 // The following information can be retrieved from the MachineModuleInfo.
20 // -- Source directories - Directories are uniqued based on their canonical
21 // string and assigned a sequential numeric ID (base 1.)
22 // -- Source files - Files are also uniqued based on their name and directory
23 // ID. A file ID is sequential number (base 1.)
24 // -- Source line correspondence - A vector of file ID, line#, column# triples.
25 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer
26 // corresponding to each entry in the source line list. This allows a debug
27 // emitter to generate labels referenced by debug information tables.
29 //===----------------------------------------------------------------------===//
31 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
32 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
34 #include "llvm/Support/Dwarf.h"
35 #include "llvm/Support/DataTypes.h"
36 #include "llvm/ADT/SmallVector.h"
37 #include "llvm/ADT/UniqueVector.h"
38 #include "llvm/ADT/SmallPtrSet.h"
39 #include "llvm/GlobalValue.h"
40 #include "llvm/Pass.h"
44 //===----------------------------------------------------------------------===//
45 // Forward declarations.
49 class MachineBasicBlock;
50 class MachineFunction;
56 //===----------------------------------------------------------------------===//
57 // Debug info constants.
60 LLVMDebugVersion = (6 << 16), // Current version of debug information.
61 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
62 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
63 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
66 //===----------------------------------------------------------------------===//
67 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
68 /// the supplied DebugInfoDesc.
72 virtual ~DIVisitor() {}
74 /// ApplyToFields - Target the visitor to each field of the debug information
76 void ApplyToFields(DebugInfoDesc *DD);
78 /// Apply - Subclasses override each of these methods to perform the
79 /// appropriate action for the type of field.
80 virtual void Apply(int &Field) = 0;
81 virtual void Apply(unsigned &Field) = 0;
82 virtual void Apply(int64_t &Field) = 0;
83 virtual void Apply(uint64_t &Field) = 0;
84 virtual void Apply(bool &Field) = 0;
85 virtual void Apply(std::string &Field) = 0;
86 virtual void Apply(DebugInfoDesc *&Field) = 0;
87 virtual void Apply(GlobalVariable *&Field) = 0;
88 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
91 //===----------------------------------------------------------------------===//
92 /// DebugInfoDesc - This class is the base class for debug info descriptors.
96 unsigned Tag; // Content indicator. Dwarf values are
97 // used but that does not limit use to
101 explicit DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
104 virtual ~DebugInfoDesc() {}
107 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
108 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
109 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
111 /// TagFromGlobal - Returns the tag number from a debug info descriptor
112 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
113 static unsigned TagFromGlobal(GlobalVariable *GV);
115 /// VersionFromGlobal - Returns the version number from a debug info
116 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
118 static unsigned VersionFromGlobal(GlobalVariable *GV);
120 /// DescFactory - Create an instance of debug info descriptor based on Tag.
121 /// Return NULL if not a recognized Tag.
122 static DebugInfoDesc *DescFactory(unsigned Tag);
124 /// getLinkage - get linkage appropriate for this type of descriptor.
126 virtual GlobalValue::LinkageTypes getLinkage() const;
128 //===--------------------------------------------------------------------===//
129 // Subclasses should supply the following static methods.
131 // Implement isa/cast/dyncast.
132 static bool classof(const DebugInfoDesc *) { return true; }
134 //===--------------------------------------------------------------------===//
135 // Subclasses should supply the following virtual methods.
137 /// ApplyToFields - Target the vistor to the fields of the descriptor.
139 virtual void ApplyToFields(DIVisitor *Visitor);
141 /// getDescString - Return a string used to compose global names and labels.
143 virtual const char *getDescString() const = 0;
145 /// getTypeString - Return a string used to label this descriptor's type.
147 virtual const char *getTypeString() const = 0;
150 virtual void dump() = 0;
154 //===----------------------------------------------------------------------===//
155 /// AnchorDesc - Descriptors of this class act as markers for identifying
156 /// descriptors of certain groups.
158 class AnchorDesc : public DebugInfoDesc {
160 unsigned AnchorTag; // Tag number of descriptors anchored
165 explicit AnchorDesc(AnchoredDesc *D);
168 unsigned getAnchorTag() const { return AnchorTag; }
170 // Implement isa/cast/dyncast.
171 static bool classof(const AnchorDesc *) { return true; }
172 static bool classof(const DebugInfoDesc *D);
174 /// getLinkage - get linkage appropriate for this type of descriptor.
176 virtual GlobalValue::LinkageTypes getLinkage() const;
178 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
180 virtual void ApplyToFields(DIVisitor *Visitor);
182 /// getDescString - Return a string used to compose global names and labels.
184 virtual const char *getDescString() const;
186 /// getTypeString - Return a string used to label this descriptor's type.
188 virtual const char *getTypeString() const;
195 //===----------------------------------------------------------------------===//
196 /// AnchoredDesc - This class manages anchors for a variety of top level
198 class AnchoredDesc : public DebugInfoDesc {
200 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
205 explicit AnchoredDesc(unsigned T);
209 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
210 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
212 //===--------------------------------------------------------------------===//
213 // Subclasses should supply the following virtual methods.
215 /// getAnchorString - Return a string used to label descriptor's anchor.
217 virtual const char *getAnchorString() const = 0;
219 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
221 virtual void ApplyToFields(DIVisitor *Visitor);
224 //===----------------------------------------------------------------------===//
225 /// CompileUnitDesc - This class packages debug information associated with a
226 /// source/header file.
227 class CompileUnitDesc : public AnchoredDesc {
229 unsigned Language; // Language number (ex. DW_LANG_C89.)
230 std::string FileName; // Source file name.
231 std::string Directory; // Source file directory.
232 std::string Producer; // Compiler string.
239 unsigned getLanguage() const { return Language; }
240 const std::string &getFileName() const { return FileName; }
241 const std::string &getDirectory() const { return Directory; }
242 const std::string &getProducer() const { return Producer; }
243 void setLanguage(unsigned L) { Language = L; }
244 void setFileName(const std::string &FN) { FileName = FN; }
245 void setDirectory(const std::string &D) { Directory = D; }
246 void setProducer(const std::string &P) { Producer = P; }
248 // FIXME - Need translation unit getter/setter.
250 // Implement isa/cast/dyncast.
251 static bool classof(const CompileUnitDesc *) { return true; }
252 static bool classof(const DebugInfoDesc *D);
254 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
256 virtual void ApplyToFields(DIVisitor *Visitor);
258 /// getDescString - Return a string used to compose global names and labels.
260 virtual const char *getDescString() const;
262 /// getTypeString - Return a string used to label this descriptor's type.
264 virtual const char *getTypeString() const;
266 /// getAnchorString - Return a string used to label this descriptor's anchor.
268 static const char *const AnchorString;
269 virtual const char *getAnchorString() const;
276 //===----------------------------------------------------------------------===//
277 /// TypeDesc - This class packages debug information associated with a type.
279 class TypeDesc : public DebugInfoDesc {
282 FlagPrivate = 1 << 0,
283 FlagProtected = 1 << 1
285 DebugInfoDesc *Context; // Context debug descriptor.
286 std::string Name; // Type name (may be empty.)
287 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
288 unsigned Line; // Defined line# (may be zero.)
289 uint64_t Size; // Type bit size (may be zero.)
290 uint64_t Align; // Type bit alignment (may be zero.)
291 uint64_t Offset; // Type bit offset (may be zero.)
292 unsigned Flags; // Miscellaneous flags.
295 explicit TypeDesc(unsigned T);
298 DebugInfoDesc *getContext() const { return Context; }
299 const std::string &getName() const { return Name; }
300 CompileUnitDesc *getFile() const {
301 return static_cast<CompileUnitDesc *>(File);
303 unsigned getLine() const { return Line; }
304 uint64_t getSize() const { return Size; }
305 uint64_t getAlign() const { return Align; }
306 uint64_t getOffset() const { return Offset; }
307 bool isPrivate() const {
308 return (Flags & FlagPrivate) != 0;
310 bool isProtected() const {
311 return (Flags & FlagProtected) != 0;
313 void setContext(DebugInfoDesc *C) { Context = C; }
314 void setName(const std::string &N) { Name = N; }
315 void setFile(CompileUnitDesc *U) {
316 File = static_cast<DebugInfoDesc *>(U);
318 void setLine(unsigned L) { Line = L; }
319 void setSize(uint64_t S) { Size = S; }
320 void setAlign(uint64_t A) { Align = A; }
321 void setOffset(uint64_t O) { Offset = O; }
322 void setIsPrivate() { Flags |= FlagPrivate; }
323 void setIsProtected() { Flags |= FlagProtected; }
325 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
327 virtual void ApplyToFields(DIVisitor *Visitor);
329 /// getDescString - Return a string used to compose global names and labels.
331 virtual const char *getDescString() const;
333 /// getTypeString - Return a string used to label this descriptor's type.
335 virtual const char *getTypeString() const;
342 //===----------------------------------------------------------------------===//
343 /// BasicTypeDesc - This class packages debug information associated with a
344 /// basic type (eg. int, bool, double.)
345 class BasicTypeDesc : public TypeDesc {
347 unsigned Encoding; // Type encoding.
353 unsigned getEncoding() const { return Encoding; }
354 void setEncoding(unsigned E) { Encoding = E; }
356 // Implement isa/cast/dyncast.
357 static bool classof(const BasicTypeDesc *) { return true; }
358 static bool classof(const DebugInfoDesc *D);
360 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
362 virtual void ApplyToFields(DIVisitor *Visitor);
364 /// getDescString - Return a string used to compose global names and labels.
366 virtual const char *getDescString() const;
368 /// getTypeString - Return a string used to label this descriptor's type.
370 virtual const char *getTypeString() const;
378 //===----------------------------------------------------------------------===//
379 /// DerivedTypeDesc - This class packages debug information associated with a
380 /// derived types (eg., typedef, pointer, reference.)
381 class DerivedTypeDesc : public TypeDesc {
383 DebugInfoDesc *FromType; // Type derived from.
386 explicit DerivedTypeDesc(unsigned T);
389 TypeDesc *getFromType() const {
390 return static_cast<TypeDesc *>(FromType);
392 void setFromType(TypeDesc *F) {
393 FromType = static_cast<DebugInfoDesc *>(F);
396 // Implement isa/cast/dyncast.
397 static bool classof(const DerivedTypeDesc *) { return true; }
398 static bool classof(const DebugInfoDesc *D);
400 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
402 virtual void ApplyToFields(DIVisitor *Visitor);
404 /// getDescString - Return a string used to compose global names and labels.
406 virtual const char *getDescString() const;
408 /// getTypeString - Return a string used to label this descriptor's type.
410 virtual const char *getTypeString() const;
417 //===----------------------------------------------------------------------===//
418 /// CompositeTypeDesc - This class packages debug information associated with a
419 /// array/struct types (eg., arrays, struct, union, enums.)
420 class CompositeTypeDesc : public DerivedTypeDesc {
422 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
425 explicit CompositeTypeDesc(unsigned T);
428 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
430 // Implement isa/cast/dyncast.
431 static bool classof(const CompositeTypeDesc *) { return true; }
432 static bool classof(const DebugInfoDesc *D);
434 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
436 virtual void ApplyToFields(DIVisitor *Visitor);
438 /// getDescString - Return a string used to compose global names and labels.
440 virtual const char *getDescString() const;
442 /// getTypeString - Return a string used to label this descriptor's type.
444 virtual const char *getTypeString() const;
451 //===----------------------------------------------------------------------===//
452 /// SubrangeDesc - This class packages debug information associated with integer
454 class SubrangeDesc : public DebugInfoDesc {
456 int64_t Lo; // Low value of range.
457 int64_t Hi; // High value of range.
463 int64_t getLo() const { return Lo; }
464 int64_t getHi() const { return Hi; }
465 void setLo(int64_t L) { Lo = L; }
466 void setHi(int64_t H) { Hi = H; }
468 // Implement isa/cast/dyncast.
469 static bool classof(const SubrangeDesc *) { return true; }
470 static bool classof(const DebugInfoDesc *D);
472 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
474 virtual void ApplyToFields(DIVisitor *Visitor);
476 /// getDescString - Return a string used to compose global names and labels.
478 virtual const char *getDescString() const;
480 /// getTypeString - Return a string used to label this descriptor's type.
482 virtual const char *getTypeString() const;
489 //===----------------------------------------------------------------------===//
490 /// EnumeratorDesc - This class packages debug information associated with
491 /// named integer constants.
492 class EnumeratorDesc : public DebugInfoDesc {
494 std::string Name; // Enumerator name.
495 int64_t Value; // Enumerator value.
501 const std::string &getName() const { return Name; }
502 int64_t getValue() const { return Value; }
503 void setName(const std::string &N) { Name = N; }
504 void setValue(int64_t V) { Value = V; }
506 // Implement isa/cast/dyncast.
507 static bool classof(const EnumeratorDesc *) { return true; }
508 static bool classof(const DebugInfoDesc *D);
510 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
512 virtual void ApplyToFields(DIVisitor *Visitor);
514 /// getDescString - Return a string used to compose global names and labels.
516 virtual const char *getDescString() const;
518 /// getTypeString - Return a string used to label this descriptor's type.
520 virtual const char *getTypeString() const;
527 //===----------------------------------------------------------------------===//
528 /// VariableDesc - This class packages debug information associated with a
529 /// subprogram variable.
531 class VariableDesc : public DebugInfoDesc {
533 DebugInfoDesc *Context; // Context debug descriptor.
534 std::string Name; // Type name (may be empty.)
535 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
536 unsigned Line; // Defined line# (may be zero.)
537 DebugInfoDesc *TyDesc; // Type of variable.
540 explicit VariableDesc(unsigned T);
543 DebugInfoDesc *getContext() const { return Context; }
544 const std::string &getName() const { return Name; }
545 CompileUnitDesc *getFile() const {
546 return static_cast<CompileUnitDesc *>(File);
548 unsigned getLine() const { return Line; }
549 TypeDesc *getType() const {
550 return static_cast<TypeDesc *>(TyDesc);
552 void setContext(DebugInfoDesc *C) { Context = C; }
553 void setName(const std::string &N) { Name = N; }
554 void setFile(CompileUnitDesc *U) {
555 File = static_cast<DebugInfoDesc *>(U);
557 void setLine(unsigned L) { Line = L; }
558 void setType(TypeDesc *T) {
559 TyDesc = static_cast<DebugInfoDesc *>(T);
562 // Implement isa/cast/dyncast.
563 static bool classof(const VariableDesc *) { return true; }
564 static bool classof(const DebugInfoDesc *D);
566 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
568 virtual void ApplyToFields(DIVisitor *Visitor);
570 /// getDescString - Return a string used to compose global names and labels.
572 virtual const char *getDescString() const;
574 /// getTypeString - Return a string used to label this descriptor's type.
576 virtual const char *getTypeString() const;
583 //===----------------------------------------------------------------------===//
584 /// GlobalDesc - This class is the base descriptor for global functions and
586 class GlobalDesc : public AnchoredDesc {
588 DebugInfoDesc *Context; // Context debug descriptor.
589 std::string Name; // Global name.
590 std::string FullName; // Fully qualified name.
591 std::string LinkageName; // Name for binding to MIPS linkage.
592 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
593 unsigned Line; // Defined line# (may be zero.)
594 DebugInfoDesc *TyDesc; // Type debug descriptor.
595 bool IsStatic; // Is the global a static.
596 bool IsDefinition; // Is the global defined in context.
599 explicit GlobalDesc(unsigned T);
603 DebugInfoDesc *getContext() const { return Context; }
604 const std::string &getName() const { return Name; }
605 const std::string &getFullName() const { return FullName; }
606 const std::string &getLinkageName() const { return LinkageName; }
607 CompileUnitDesc *getFile() const {
608 return static_cast<CompileUnitDesc *>(File);
610 unsigned getLine() const { return Line; }
611 TypeDesc *getType() const {
612 return static_cast<TypeDesc *>(TyDesc);
614 bool isStatic() const { return IsStatic; }
615 bool isDefinition() const { return IsDefinition; }
616 void setContext(DebugInfoDesc *C) { Context = C; }
617 void setName(const std::string &N) { Name = N; }
618 void setFullName(const std::string &N) { FullName = N; }
619 void setLinkageName(const std::string &N) { LinkageName = N; }
620 void setFile(CompileUnitDesc *U) {
621 File = static_cast<DebugInfoDesc *>(U);
623 void setLine(unsigned L) { Line = L; }
624 void setType(TypeDesc *T) {
625 TyDesc = static_cast<DebugInfoDesc *>(T);
627 void setIsStatic(bool IS) { IsStatic = IS; }
628 void setIsDefinition(bool ID) { IsDefinition = ID; }
630 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
632 virtual void ApplyToFields(DIVisitor *Visitor);
635 //===----------------------------------------------------------------------===//
636 /// GlobalVariableDesc - This class packages debug information associated with a
638 class GlobalVariableDesc : public GlobalDesc {
640 GlobalVariable *Global; // llvm global.
643 GlobalVariableDesc();
646 GlobalVariable *getGlobalVariable() const { return Global; }
647 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
649 // Implement isa/cast/dyncast.
650 static bool classof(const GlobalVariableDesc *) { return true; }
651 static bool classof(const DebugInfoDesc *D);
653 /// ApplyToFields - Target the visitor to the fields of the
654 /// GlobalVariableDesc.
655 virtual void ApplyToFields(DIVisitor *Visitor);
657 /// getDescString - Return a string used to compose global names and labels.
659 virtual const char *getDescString() const;
661 /// getTypeString - Return a string used to label this descriptor's type.
663 virtual const char *getTypeString() const;
665 /// getAnchorString - Return a string used to label this descriptor's anchor.
667 static const char *const AnchorString;
668 virtual const char *getAnchorString() const;
675 //===----------------------------------------------------------------------===//
676 /// SubprogramDesc - This class packages debug information associated with a
677 /// subprogram/function.
678 class SubprogramDesc : public GlobalDesc {
686 // Implement isa/cast/dyncast.
687 static bool classof(const SubprogramDesc *) { return true; }
688 static bool classof(const DebugInfoDesc *D);
690 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
692 virtual void ApplyToFields(DIVisitor *Visitor);
694 /// getDescString - Return a string used to compose global names and labels.
696 virtual const char *getDescString() const;
698 /// getTypeString - Return a string used to label this descriptor's type.
700 virtual const char *getTypeString() const;
702 /// getAnchorString - Return a string used to label this descriptor's anchor.
704 static const char *const AnchorString;
705 virtual const char *getAnchorString() const;
712 //===----------------------------------------------------------------------===//
713 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
715 class BlockDesc : public DebugInfoDesc {
717 DebugInfoDesc *Context; // Context debug descriptor.
723 DebugInfoDesc *getContext() const { return Context; }
724 void setContext(DebugInfoDesc *C) { Context = C; }
726 // Implement isa/cast/dyncast.
727 static bool classof(const BlockDesc *) { return true; }
728 static bool classof(const DebugInfoDesc *D);
730 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
732 virtual void ApplyToFields(DIVisitor *Visitor);
734 /// getDescString - Return a string used to compose global names and labels.
736 virtual const char *getDescString() const;
738 /// getTypeString - Return a string used to label this descriptor's type.
740 virtual const char *getTypeString() const;
747 //===----------------------------------------------------------------------===//
748 /// DIDeserializer - This class is responsible for casting GlobalVariables
749 /// into DebugInfoDesc objects.
750 class DIDeserializer {
752 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
753 // Previously defined gloabls.
759 const std::map<GlobalVariable *, DebugInfoDesc *> &getGlobalDescs() const {
763 /// Deserialize - Reconstitute a GlobalVariable into it's component
764 /// DebugInfoDesc objects.
765 DebugInfoDesc *Deserialize(Value *V);
766 DebugInfoDesc *Deserialize(GlobalVariable *GV);
769 //===----------------------------------------------------------------------===//
770 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
771 /// into GlobalVariables.
774 Module *M; // Definition space module.
775 PointerType *StrPtrTy; // A "i8*" type. Created lazily.
776 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
777 std::map<unsigned, StructType *> TagTypes;
778 // Types per Tag. Created lazily.
779 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
780 // Previously defined descriptors.
781 std::map<const std::string, Constant *> StringCache;
782 // Previously defined strings.
788 , EmptyStructPtrTy(NULL)
796 Module *getModule() const { return M; };
797 void setModule(Module *module) { M = module; }
799 /// getStrPtrType - Return a "i8*" type.
801 const PointerType *getStrPtrType();
803 /// getEmptyStructPtrType - Return a "{ }*" type.
805 const PointerType *getEmptyStructPtrType();
807 /// getTagType - Return the type describing the specified descriptor (via
809 const StructType *getTagType(DebugInfoDesc *DD);
811 /// getString - Construct the string as constant string global.
813 Constant *getString(const std::string &String);
815 /// Serialize - Recursively cast the specified descriptor into a
816 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
817 GlobalVariable *Serialize(DebugInfoDesc *DD);
819 /// addDescriptor - Directly connect DD with existing GV.
820 void addDescriptor(DebugInfoDesc *DD, GlobalVariable *GV);
823 //===----------------------------------------------------------------------===//
824 /// DIVerifier - This class is responsible for verifying the given network of
825 /// GlobalVariables are valid as DebugInfoDesc objects.
833 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
834 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
843 /// Verify - Return true if the GlobalVariable appears to be a valid
844 /// serialization of a DebugInfoDesc.
845 bool Verify(Value *V);
846 bool Verify(GlobalVariable *GV);
848 /// isVerified - Return true if the specified GV has already been
849 /// verified as a debug information descriptor.
850 bool isVerified(GlobalVariable *GV);
853 //===----------------------------------------------------------------------===//
854 /// SourceLineInfo - This class is used to record source line correspondence.
856 class SourceLineInfo {
858 unsigned Line; // Source line number.
859 unsigned Column; // Source column.
860 unsigned SourceID; // Source ID number.
861 unsigned LabelID; // Label in code ID number.
864 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
865 : Line(L), Column(C), SourceID(S), LabelID(I) {}
868 unsigned getLine() const { return Line; }
869 unsigned getColumn() const { return Column; }
870 unsigned getSourceID() const { return SourceID; }
871 unsigned getLabelID() const { return LabelID; }
874 //===----------------------------------------------------------------------===//
875 /// SourceFileInfo - This class is used to track source information.
877 class SourceFileInfo {
879 unsigned DirectoryID; // Directory ID number.
880 std::string Name; // File name (not including directory.)
883 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
886 unsigned getDirectoryID() const { return DirectoryID; }
887 const std::string &getName() const { return Name; }
889 /// operator== - Used by UniqueVector to locate entry.
891 bool operator==(const SourceFileInfo &SI) const {
892 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
895 /// operator< - Used by UniqueVector to locate entry.
897 bool operator<(const SourceFileInfo &SI) const {
898 return getDirectoryID() < SI.getDirectoryID() ||
899 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
903 //===----------------------------------------------------------------------===//
904 /// DebugVariable - This class is used to track local variable information.
906 class DebugVariable {
908 VariableDesc *Desc; // Variable Descriptor.
909 unsigned FrameIndex; // Variable frame index.
912 DebugVariable(VariableDesc *D, unsigned I)
918 VariableDesc *getDesc() const { return Desc; }
919 unsigned getFrameIndex() const { return FrameIndex; }
922 //===----------------------------------------------------------------------===//
923 /// DebugScope - This class is used to track scope information.
927 DebugScope *Parent; // Parent to this scope.
928 DebugInfoDesc *Desc; // Debug info descriptor for scope.
929 // Either subprogram or block.
930 unsigned StartLabelID; // Label ID of the beginning of scope.
931 unsigned EndLabelID; // Label ID of the end of scope.
932 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
933 std::vector<DebugVariable *> Variables;// Variables declared in scope.
936 DebugScope(DebugScope *P, DebugInfoDesc *D)
947 DebugScope *getParent() const { return Parent; }
948 DebugInfoDesc *getDesc() const { return Desc; }
949 unsigned getStartLabelID() const { return StartLabelID; }
950 unsigned getEndLabelID() const { return EndLabelID; }
951 std::vector<DebugScope *> &getScopes() { return Scopes; }
952 std::vector<DebugVariable *> &getVariables() { return Variables; }
953 void setStartLabelID(unsigned S) { StartLabelID = S; }
954 void setEndLabelID(unsigned E) { EndLabelID = E; }
956 /// AddScope - Add a scope to the scope.
958 void AddScope(DebugScope *S) { Scopes.push_back(S); }
960 /// AddVariable - Add a variable to the scope.
962 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
965 //===----------------------------------------------------------------------===//
966 /// LandingPadInfo - This structure is used to retain landing pad info for
967 /// the current function.
969 struct LandingPadInfo {
970 MachineBasicBlock *LandingPadBlock; // Landing pad block.
971 SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
972 SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
973 unsigned LandingPadLabel; // Label at beginning of landing pad.
974 Function *Personality; // Personality function.
975 std::vector<int> TypeIds; // List of type ids (filters negative)
977 explicit LandingPadInfo(MachineBasicBlock *MBB)
978 : LandingPadBlock(MBB)
984 //===----------------------------------------------------------------------===//
985 /// MachineModuleInfo - This class contains meta information specific to a
986 /// module. Queries can be made by different debugging and exception handling
987 /// schemes and reformated for specific use.
989 class MachineModuleInfo : public ImmutablePass {
991 // Use the same deserializer/verifier for the module.
995 // CompileUnits - Uniquing vector for compile units.
996 UniqueVector<CompileUnitDesc *> CompileUnits;
998 // Directories - Uniquing vector for directories.
999 UniqueVector<std::string> Directories;
1001 // SourceFiles - Uniquing vector for source files.
1002 UniqueVector<SourceFileInfo> SourceFiles;
1004 // Lines - List of of source line correspondence.
1005 std::vector<SourceLineInfo> Lines;
1007 // LabelIDList - One entry per assigned label. Normally the entry is equal to
1008 // the list index(+1). If the entry is zero then the label has been deleted.
1009 // Any other value indicates the label has been deleted by is mapped to
1011 std::vector<unsigned> LabelIDList;
1013 // ScopeMap - Tracks the scopes in the current function.
1014 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
1016 // RootScope - Top level scope for the current function.
1018 DebugScope *RootScope;
1020 // FrameMoves - List of moves done by a function's prolog. Used to construct
1021 // frame maps by debug and exception handling consumers.
1022 std::vector<MachineMove> FrameMoves;
1024 // LandingPads - List of LandingPadInfo describing the landing pad information
1025 // in the current function.
1026 std::vector<LandingPadInfo> LandingPads;
1028 // TypeInfos - List of C++ TypeInfo used in the current function.
1030 std::vector<GlobalVariable *> TypeInfos;
1032 // FilterIds - List of typeids encoding filters used in the current function.
1034 std::vector<unsigned> FilterIds;
1036 // FilterEnds - List of the indices in FilterIds corresponding to filter
1039 std::vector<unsigned> FilterEnds;
1041 // Personalities - Vector of all personality functions ever seen. Used to emit
1042 // common EH frames.
1043 std::vector<Function *> Personalities;
1045 // UsedFunctions - the functions in the llvm.used list in a more easily
1046 // searchable format.
1047 SmallPtrSet<const Function *, 32> UsedFunctions;
1050 bool CallsUnwindInit;
1052 static char ID; // Pass identification, replacement for typeid
1054 MachineModuleInfo();
1055 ~MachineModuleInfo();
1057 /// doInitialization - Initialize the state for a new module.
1059 bool doInitialization();
1061 /// doFinalization - Tear down the state after completion of a module.
1063 bool doFinalization();
1065 /// BeginFunction - Begin gathering function meta information.
1067 void BeginFunction(MachineFunction *MF);
1069 /// EndFunction - Discard function meta information.
1073 /// getDescFor - Convert a Value to a debug information descriptor.
1075 // FIXME - use new Value type when available.
1076 DebugInfoDesc *getDescFor(Value *V);
1078 /// Verify - Verify that a Value is debug information descriptor.
1080 bool Verify(Value *V) { return VR.Verify(V); }
1082 /// isVerified - Return true if the specified GV has already been
1083 /// verified as a debug information descriptor.
1084 bool isVerified(GlobalVariable *GV) { return VR.isVerified(GV); }
1086 /// AnalyzeModule - Scan the module for global debug information.
1088 void AnalyzeModule(Module &M);
1090 /// hasDebugInfo - Returns true if valid debug info is present.
1092 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1094 bool callsEHReturn() const { return CallsEHReturn; }
1095 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
1097 bool callsUnwindInit() const { return CallsUnwindInit; }
1098 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
1100 /// NextLabelID - Return the next unique label id.
1102 unsigned NextLabelID() {
1103 unsigned ID = (unsigned)LabelIDList.size() + 1;
1104 LabelIDList.push_back(ID);
1108 /// RecordSourceLine - Records location information and associates it with a
1109 /// label. Returns a unique label ID used to generate a label and
1110 /// provide correspondence to the source line list.
1111 unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
1113 /// InvalidateLabel - Inhibit use of the specified label # from
1114 /// MachineModuleInfo, for example because the code was deleted.
1115 void InvalidateLabel(unsigned LabelID) {
1116 // Remap to zero to indicate deletion.
1117 RemapLabel(LabelID, 0);
1120 /// RemapLabel - Indicate that a label has been merged into another.
1122 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1123 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1124 "Old label ID out of range.");
1125 assert(NewLabelID <= LabelIDList.size() &&
1126 "New label ID out of range.");
1127 LabelIDList[OldLabelID - 1] = NewLabelID;
1130 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1131 /// ID != Mapped ID indicates that the label was folded into another label.
1132 unsigned MappedLabel(unsigned LabelID) const {
1133 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1134 return LabelID ? LabelIDList[LabelID - 1] : 0;
1137 /// RecordSource - Register a source file with debug info. Returns an source
1139 unsigned RecordSource(const std::string &Directory,
1140 const std::string &Source);
1141 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1143 /// getDirectories - Return the UniqueVector of std::string representing
1145 const UniqueVector<std::string> &getDirectories() const {
1149 /// getSourceFiles - Return the UniqueVector of source files.
1151 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1155 /// getSourceLines - Return a vector of source lines.
1157 const std::vector<SourceLineInfo> &getSourceLines() const {
1161 /// SetupCompileUnits - Set up the unique vector of compile units.
1163 void SetupCompileUnits(Module &M);
1165 /// getCompileUnits - Return a vector of debug compile units.
1167 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1169 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1170 /// named GlobalVariable.
1171 std::vector<GlobalVariable*>
1172 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1174 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1176 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1178 std::vector<GlobalVariable *> Globals =
1179 getGlobalVariablesUsing(M, Desc.getAnchorString());
1180 std::vector<T *> AnchoredDescs;
1181 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1182 GlobalVariable *GV = Globals[i];
1184 // FIXME - In the short term, changes are too drastic to continue.
1185 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1186 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1187 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1191 return AnchoredDescs;
1194 /// RecordRegionStart - Indicate the start of a region.
1196 unsigned RecordRegionStart(Value *V);
1198 /// RecordRegionEnd - Indicate the end of a region.
1200 unsigned RecordRegionEnd(Value *V);
1202 /// RecordVariable - Indicate the declaration of a local variable.
1204 void RecordVariable(GlobalValue *GV, unsigned FrameIndex);
1206 /// getRootScope - Return current functions root scope.
1208 DebugScope *getRootScope() { return RootScope; }
1210 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1212 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1214 /// getFrameMoves - Returns a reference to a list of moves done in the current
1215 /// function's prologue. Used to construct frame maps for debug and exception
1216 /// handling comsumers.
1217 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1219 //===-EH-----------------------------------------------------------------===//
1221 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1222 /// specified MachineBasicBlock.
1223 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1225 /// addInvoke - Provide the begin and end labels of an invoke style call and
1226 /// associate it with a try landing pad block.
1227 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1230 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1231 /// landing pad entry.
1232 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1234 /// addPersonality - Provide the personality function for the exception
1236 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1238 /// getPersonalityIndex - Get index of the current personality function inside
1239 /// Personalitites array
1240 unsigned getPersonalityIndex() const;
1242 /// getPersonalities - Return array of personality functions ever seen.
1243 const std::vector<Function *>& getPersonalities() const {
1244 return Personalities;
1247 // UsedFunctions - Return set of the functions in the llvm.used list.
1248 const SmallPtrSet<const Function *, 32>& getUsedFunctions() const {
1249 return UsedFunctions;
1252 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1254 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1255 std::vector<GlobalVariable *> &TyInfo);
1257 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
1259 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
1260 std::vector<GlobalVariable *> &TyInfo);
1262 /// addCleanup - Add a cleanup action for a landing pad.
1264 void addCleanup(MachineBasicBlock *LandingPad);
1266 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1268 unsigned getTypeIDFor(GlobalVariable *TI);
1270 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
1272 int getFilterIDFor(std::vector<unsigned> &TyIds);
1274 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1276 void TidyLandingPads();
1278 /// getLandingPads - Return a reference to the landing pad info for the
1279 /// current function.
1280 const std::vector<LandingPadInfo> &getLandingPads() const {
1284 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1286 const std::vector<GlobalVariable *> &getTypeInfos() const {
1290 /// getFilterIds - Return a reference to the typeids encoding filters used in
1291 /// the current function.
1292 const std::vector<unsigned> &getFilterIds() const {
1296 /// getPersonality - Return a personality function if available. The presence
1297 /// of one is required to emit exception handling info.
1298 Function *getPersonality() const;
1300 DIDeserializer *getDIDeserializer() { return &DR; }
1301 }; // End class MachineModuleInfo
1303 } // End llvm namespace