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/DenseMap.h"
38 #include "llvm/ADT/UniqueVector.h"
39 #include "llvm/ADT/SmallPtrSet.h"
40 #include "llvm/GlobalValue.h"
41 #include "llvm/Pass.h"
45 //===----------------------------------------------------------------------===//
46 // Forward declarations.
50 class MachineBasicBlock;
51 class MachineFunction;
57 //===----------------------------------------------------------------------===//
58 // Debug info constants.
61 LLVMDebugVersion = (6 << 16), // Current version of debug information.
62 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
63 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
64 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
67 //===----------------------------------------------------------------------===//
68 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
69 /// the supplied DebugInfoDesc.
73 virtual ~DIVisitor() {}
75 /// ApplyToFields - Target the visitor to each field of the debug information
77 void ApplyToFields(DebugInfoDesc *DD);
79 /// Apply - Subclasses override each of these methods to perform the
80 /// appropriate action for the type of field.
81 virtual void Apply(int &Field) = 0;
82 virtual void Apply(unsigned &Field) = 0;
83 virtual void Apply(int64_t &Field) = 0;
84 virtual void Apply(uint64_t &Field) = 0;
85 virtual void Apply(bool &Field) = 0;
86 virtual void Apply(std::string &Field) = 0;
87 virtual void Apply(DebugInfoDesc *&Field) = 0;
88 virtual void Apply(GlobalVariable *&Field) = 0;
89 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
92 //===----------------------------------------------------------------------===//
93 /// DebugInfoDesc - This class is the base class for debug info descriptors.
97 unsigned Tag; // Content indicator. Dwarf values are
98 // used but that does not limit use to
102 explicit DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
105 virtual ~DebugInfoDesc() {}
108 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
109 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
110 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
112 /// TagFromGlobal - Returns the tag number from a debug info descriptor
113 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
114 static unsigned TagFromGlobal(GlobalVariable *GV);
116 /// VersionFromGlobal - Returns the version number from a debug info
117 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
119 static unsigned VersionFromGlobal(GlobalVariable *GV);
121 /// DescFactory - Create an instance of debug info descriptor based on Tag.
122 /// Return NULL if not a recognized Tag.
123 static DebugInfoDesc *DescFactory(unsigned Tag);
125 /// getLinkage - get linkage appropriate for this type of descriptor.
127 virtual GlobalValue::LinkageTypes getLinkage() const;
129 //===--------------------------------------------------------------------===//
130 // Subclasses should supply the following static methods.
132 // Implement isa/cast/dyncast.
133 static bool classof(const DebugInfoDesc *) { return true; }
135 //===--------------------------------------------------------------------===//
136 // Subclasses should supply the following virtual methods.
138 /// ApplyToFields - Target the vistor to the fields of the descriptor.
140 virtual void ApplyToFields(DIVisitor *Visitor);
142 /// getDescString - Return a string used to compose global names and labels.
144 virtual const char *getDescString() const = 0;
146 /// getTypeString - Return a string used to label this descriptor's type.
148 virtual const char *getTypeString() const = 0;
151 virtual void dump() = 0;
155 //===----------------------------------------------------------------------===//
156 /// AnchorDesc - Descriptors of this class act as markers for identifying
157 /// descriptors of certain groups.
159 class AnchorDesc : public DebugInfoDesc {
161 unsigned AnchorTag; // Tag number of descriptors anchored
166 explicit AnchorDesc(AnchoredDesc *D);
169 unsigned getAnchorTag() const { return AnchorTag; }
171 // Implement isa/cast/dyncast.
172 static bool classof(const AnchorDesc *) { return true; }
173 static bool classof(const DebugInfoDesc *D);
175 /// getLinkage - get linkage appropriate for this type of descriptor.
177 virtual GlobalValue::LinkageTypes getLinkage() const;
179 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
181 virtual void ApplyToFields(DIVisitor *Visitor);
183 /// getDescString - Return a string used to compose global names and labels.
185 virtual const char *getDescString() const;
187 /// getTypeString - Return a string used to label this descriptor's type.
189 virtual const char *getTypeString() const;
196 //===----------------------------------------------------------------------===//
197 /// AnchoredDesc - This class manages anchors for a variety of top level
199 class AnchoredDesc : public DebugInfoDesc {
201 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
206 explicit AnchoredDesc(unsigned T);
210 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
211 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
213 //===--------------------------------------------------------------------===//
214 // Subclasses should supply the following virtual methods.
216 /// getAnchorString - Return a string used to label descriptor's anchor.
218 virtual const char *getAnchorString() const = 0;
220 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
222 virtual void ApplyToFields(DIVisitor *Visitor);
225 //===----------------------------------------------------------------------===//
226 /// CompileUnitDesc - This class packages debug information associated with a
227 /// source/header file.
228 class CompileUnitDesc : public AnchoredDesc {
230 unsigned Language; // Language number (ex. DW_LANG_C89.)
231 std::string FileName; // Source file name.
232 std::string Directory; // Source file directory.
233 std::string Producer; // Compiler string.
240 unsigned getLanguage() const { return Language; }
241 const std::string &getFileName() const { return FileName; }
242 const std::string &getDirectory() const { return Directory; }
243 const std::string &getProducer() const { return Producer; }
244 void setLanguage(unsigned L) { Language = L; }
245 void setFileName(const std::string &FN) { FileName = FN; }
246 void setDirectory(const std::string &D) { Directory = D; }
247 void setProducer(const std::string &P) { Producer = P; }
249 // FIXME - Need translation unit getter/setter.
251 // Implement isa/cast/dyncast.
252 static bool classof(const CompileUnitDesc *) { return true; }
253 static bool classof(const DebugInfoDesc *D);
255 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
257 virtual void ApplyToFields(DIVisitor *Visitor);
259 /// getDescString - Return a string used to compose global names and labels.
261 virtual const char *getDescString() const;
263 /// getTypeString - Return a string used to label this descriptor's type.
265 virtual const char *getTypeString() const;
267 /// getAnchorString - Return a string used to label this descriptor's anchor.
269 static const char *const AnchorString;
270 virtual const char *getAnchorString() const;
277 //===----------------------------------------------------------------------===//
278 /// TypeDesc - This class packages debug information associated with a type.
280 class TypeDesc : public DebugInfoDesc {
283 FlagPrivate = 1 << 0,
284 FlagProtected = 1 << 1
286 DebugInfoDesc *Context; // Context debug descriptor.
287 std::string Name; // Type name (may be empty.)
288 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
289 unsigned Line; // Defined line# (may be zero.)
290 uint64_t Size; // Type bit size (may be zero.)
291 uint64_t Align; // Type bit alignment (may be zero.)
292 uint64_t Offset; // Type bit offset (may be zero.)
293 unsigned Flags; // Miscellaneous flags.
296 explicit TypeDesc(unsigned T);
299 DebugInfoDesc *getContext() const { return Context; }
300 const std::string &getName() const { return Name; }
301 CompileUnitDesc *getFile() const {
302 return static_cast<CompileUnitDesc *>(File);
304 unsigned getLine() const { return Line; }
305 uint64_t getSize() const { return Size; }
306 uint64_t getAlign() const { return Align; }
307 uint64_t getOffset() const { return Offset; }
308 bool isPrivate() const {
309 return (Flags & FlagPrivate) != 0;
311 bool isProtected() const {
312 return (Flags & FlagProtected) != 0;
314 void setContext(DebugInfoDesc *C) { Context = C; }
315 void setName(const std::string &N) { Name = N; }
316 void setFile(CompileUnitDesc *U) {
317 File = static_cast<DebugInfoDesc *>(U);
319 void setLine(unsigned L) { Line = L; }
320 void setSize(uint64_t S) { Size = S; }
321 void setAlign(uint64_t A) { Align = A; }
322 void setOffset(uint64_t O) { Offset = O; }
323 void setIsPrivate() { Flags |= FlagPrivate; }
324 void setIsProtected() { Flags |= FlagProtected; }
326 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
328 virtual void ApplyToFields(DIVisitor *Visitor);
330 /// getDescString - Return a string used to compose global names and labels.
332 virtual const char *getDescString() const;
334 /// getTypeString - Return a string used to label this descriptor's type.
336 virtual const char *getTypeString() const;
343 //===----------------------------------------------------------------------===//
344 /// BasicTypeDesc - This class packages debug information associated with a
345 /// basic type (eg. int, bool, double.)
346 class BasicTypeDesc : public TypeDesc {
348 unsigned Encoding; // Type encoding.
354 unsigned getEncoding() const { return Encoding; }
355 void setEncoding(unsigned E) { Encoding = E; }
357 // Implement isa/cast/dyncast.
358 static bool classof(const BasicTypeDesc *) { return true; }
359 static bool classof(const DebugInfoDesc *D);
361 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
363 virtual void ApplyToFields(DIVisitor *Visitor);
365 /// getDescString - Return a string used to compose global names and labels.
367 virtual const char *getDescString() const;
369 /// getTypeString - Return a string used to label this descriptor's type.
371 virtual const char *getTypeString() const;
379 //===----------------------------------------------------------------------===//
380 /// DerivedTypeDesc - This class packages debug information associated with a
381 /// derived types (eg., typedef, pointer, reference.)
382 class DerivedTypeDesc : public TypeDesc {
384 DebugInfoDesc *FromType; // Type derived from.
387 explicit DerivedTypeDesc(unsigned T);
390 TypeDesc *getFromType() const {
391 return static_cast<TypeDesc *>(FromType);
393 void setFromType(TypeDesc *F) {
394 FromType = static_cast<DebugInfoDesc *>(F);
397 // Implement isa/cast/dyncast.
398 static bool classof(const DerivedTypeDesc *) { return true; }
399 static bool classof(const DebugInfoDesc *D);
401 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
403 virtual void ApplyToFields(DIVisitor *Visitor);
405 /// getDescString - Return a string used to compose global names and labels.
407 virtual const char *getDescString() const;
409 /// getTypeString - Return a string used to label this descriptor's type.
411 virtual const char *getTypeString() const;
418 //===----------------------------------------------------------------------===//
419 /// CompositeTypeDesc - This class packages debug information associated with a
420 /// array/struct types (eg., arrays, struct, union, enums.)
421 class CompositeTypeDesc : public DerivedTypeDesc {
423 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
426 explicit CompositeTypeDesc(unsigned T);
429 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
431 // Implement isa/cast/dyncast.
432 static bool classof(const CompositeTypeDesc *) { return true; }
433 static bool classof(const DebugInfoDesc *D);
435 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
437 virtual void ApplyToFields(DIVisitor *Visitor);
439 /// getDescString - Return a string used to compose global names and labels.
441 virtual const char *getDescString() const;
443 /// getTypeString - Return a string used to label this descriptor's type.
445 virtual const char *getTypeString() const;
452 //===----------------------------------------------------------------------===//
453 /// SubrangeDesc - This class packages debug information associated with integer
455 class SubrangeDesc : public DebugInfoDesc {
457 int64_t Lo; // Low value of range.
458 int64_t Hi; // High value of range.
464 int64_t getLo() const { return Lo; }
465 int64_t getHi() const { return Hi; }
466 void setLo(int64_t L) { Lo = L; }
467 void setHi(int64_t H) { Hi = H; }
469 // Implement isa/cast/dyncast.
470 static bool classof(const SubrangeDesc *) { return true; }
471 static bool classof(const DebugInfoDesc *D);
473 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
475 virtual void ApplyToFields(DIVisitor *Visitor);
477 /// getDescString - Return a string used to compose global names and labels.
479 virtual const char *getDescString() const;
481 /// getTypeString - Return a string used to label this descriptor's type.
483 virtual const char *getTypeString() const;
490 //===----------------------------------------------------------------------===//
491 /// EnumeratorDesc - This class packages debug information associated with
492 /// named integer constants.
493 class EnumeratorDesc : public DebugInfoDesc {
495 std::string Name; // Enumerator name.
496 int64_t Value; // Enumerator value.
502 const std::string &getName() const { return Name; }
503 int64_t getValue() const { return Value; }
504 void setName(const std::string &N) { Name = N; }
505 void setValue(int64_t V) { Value = V; }
507 // Implement isa/cast/dyncast.
508 static bool classof(const EnumeratorDesc *) { return true; }
509 static bool classof(const DebugInfoDesc *D);
511 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
513 virtual void ApplyToFields(DIVisitor *Visitor);
515 /// getDescString - Return a string used to compose global names and labels.
517 virtual const char *getDescString() const;
519 /// getTypeString - Return a string used to label this descriptor's type.
521 virtual const char *getTypeString() const;
528 //===----------------------------------------------------------------------===//
529 /// VariableDesc - This class packages debug information associated with a
530 /// subprogram variable.
532 class VariableDesc : public DebugInfoDesc {
534 DebugInfoDesc *Context; // Context debug descriptor.
535 std::string Name; // Type name (may be empty.)
536 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
537 unsigned Line; // Defined line# (may be zero.)
538 DebugInfoDesc *TyDesc; // Type of variable.
541 explicit VariableDesc(unsigned T);
544 DebugInfoDesc *getContext() const { return Context; }
545 const std::string &getName() const { return Name; }
546 CompileUnitDesc *getFile() const {
547 return static_cast<CompileUnitDesc *>(File);
549 unsigned getLine() const { return Line; }
550 TypeDesc *getType() const {
551 return static_cast<TypeDesc *>(TyDesc);
553 void setContext(DebugInfoDesc *C) { Context = C; }
554 void setName(const std::string &N) { Name = N; }
555 void setFile(CompileUnitDesc *U) {
556 File = static_cast<DebugInfoDesc *>(U);
558 void setLine(unsigned L) { Line = L; }
559 void setType(TypeDesc *T) {
560 TyDesc = static_cast<DebugInfoDesc *>(T);
563 // Implement isa/cast/dyncast.
564 static bool classof(const VariableDesc *) { return true; }
565 static bool classof(const DebugInfoDesc *D);
567 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
569 virtual void ApplyToFields(DIVisitor *Visitor);
571 /// getDescString - Return a string used to compose global names and labels.
573 virtual const char *getDescString() const;
575 /// getTypeString - Return a string used to label this descriptor's type.
577 virtual const char *getTypeString() const;
584 //===----------------------------------------------------------------------===//
585 /// GlobalDesc - This class is the base descriptor for global functions and
587 class GlobalDesc : public AnchoredDesc {
589 DebugInfoDesc *Context; // Context debug descriptor.
590 std::string Name; // Global name.
591 std::string FullName; // Fully qualified name.
592 std::string LinkageName; // Name for binding to MIPS linkage.
593 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
594 unsigned Line; // Defined line# (may be zero.)
595 DebugInfoDesc *TyDesc; // Type debug descriptor.
596 bool IsStatic; // Is the global a static.
597 bool IsDefinition; // Is the global defined in context.
600 explicit GlobalDesc(unsigned T);
604 DebugInfoDesc *getContext() const { return Context; }
605 const std::string &getName() const { return Name; }
606 const std::string &getFullName() const { return FullName; }
607 const std::string &getLinkageName() const { return LinkageName; }
608 CompileUnitDesc *getFile() const {
609 return static_cast<CompileUnitDesc *>(File);
611 unsigned getLine() const { return Line; }
612 TypeDesc *getType() const {
613 return static_cast<TypeDesc *>(TyDesc);
615 bool isStatic() const { return IsStatic; }
616 bool isDefinition() const { return IsDefinition; }
617 void setContext(DebugInfoDesc *C) { Context = C; }
618 void setName(const std::string &N) { Name = N; }
619 void setFullName(const std::string &N) { FullName = N; }
620 void setLinkageName(const std::string &N) { LinkageName = N; }
621 void setFile(CompileUnitDesc *U) {
622 File = static_cast<DebugInfoDesc *>(U);
624 void setLine(unsigned L) { Line = L; }
625 void setType(TypeDesc *T) {
626 TyDesc = static_cast<DebugInfoDesc *>(T);
628 void setIsStatic(bool IS) { IsStatic = IS; }
629 void setIsDefinition(bool ID) { IsDefinition = ID; }
631 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
633 virtual void ApplyToFields(DIVisitor *Visitor);
636 //===----------------------------------------------------------------------===//
637 /// GlobalVariableDesc - This class packages debug information associated with a
639 class GlobalVariableDesc : public GlobalDesc {
641 GlobalVariable *Global; // llvm global.
644 GlobalVariableDesc();
647 GlobalVariable *getGlobalVariable() const { return Global; }
648 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
650 // Implement isa/cast/dyncast.
651 static bool classof(const GlobalVariableDesc *) { return true; }
652 static bool classof(const DebugInfoDesc *D);
654 /// ApplyToFields - Target the visitor to the fields of the
655 /// GlobalVariableDesc.
656 virtual void ApplyToFields(DIVisitor *Visitor);
658 /// getDescString - Return a string used to compose global names and labels.
660 virtual const char *getDescString() const;
662 /// getTypeString - Return a string used to label this descriptor's type.
664 virtual const char *getTypeString() const;
666 /// getAnchorString - Return a string used to label this descriptor's anchor.
668 static const char *const AnchorString;
669 virtual const char *getAnchorString() const;
676 //===----------------------------------------------------------------------===//
677 /// SubprogramDesc - This class packages debug information associated with a
678 /// subprogram/function.
679 class SubprogramDesc : public GlobalDesc {
687 // Implement isa/cast/dyncast.
688 static bool classof(const SubprogramDesc *) { return true; }
689 static bool classof(const DebugInfoDesc *D);
691 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
693 virtual void ApplyToFields(DIVisitor *Visitor);
695 /// getDescString - Return a string used to compose global names and labels.
697 virtual const char *getDescString() const;
699 /// getTypeString - Return a string used to label this descriptor's type.
701 virtual const char *getTypeString() const;
703 /// getAnchorString - Return a string used to label this descriptor's anchor.
705 static const char *const AnchorString;
706 virtual const char *getAnchorString() const;
713 //===----------------------------------------------------------------------===//
714 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
716 class BlockDesc : public DebugInfoDesc {
718 DebugInfoDesc *Context; // Context debug descriptor.
724 DebugInfoDesc *getContext() const { return Context; }
725 void setContext(DebugInfoDesc *C) { Context = C; }
727 // Implement isa/cast/dyncast.
728 static bool classof(const BlockDesc *) { return true; }
729 static bool classof(const DebugInfoDesc *D);
731 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
733 virtual void ApplyToFields(DIVisitor *Visitor);
735 /// getDescString - Return a string used to compose global names and labels.
737 virtual const char *getDescString() const;
739 /// getTypeString - Return a string used to label this descriptor's type.
741 virtual const char *getTypeString() const;
748 //===----------------------------------------------------------------------===//
749 /// DIDeserializer - This class is responsible for casting GlobalVariables
750 /// into DebugInfoDesc objects.
751 class DIDeserializer {
752 // Previously defined gloabls.
753 std::map<GlobalVariable*, DebugInfoDesc*> GlobalDescs;
755 const std::map<GlobalVariable *, DebugInfoDesc *> &getGlobalDescs() const {
759 /// Deserialize - Reconstitute a GlobalVariable into it's component
760 /// DebugInfoDesc objects.
761 DebugInfoDesc *Deserialize(Value *V);
762 DebugInfoDesc *Deserialize(GlobalVariable *GV);
765 //===----------------------------------------------------------------------===//
766 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
767 /// into GlobalVariables.
769 Module *M; // Definition space module.
770 PointerType *StrPtrTy; // A "i8*" type. Created lazily.
771 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
773 // Types per Tag. Created lazily.
774 std::map<unsigned, StructType *> TagTypes;
776 // Previously defined descriptors.
777 DenseMap<DebugInfoDesc *, GlobalVariable *> DescGlobals;
779 // Previously defined strings.
780 DenseMap<const char *, Constant*> StringCache;
783 : M(NULL), StrPtrTy(NULL), EmptyStructPtrTy(NULL), TagTypes(),
784 DescGlobals(), StringCache()
788 Module *getModule() const { return M; };
789 void setModule(Module *module) { M = module; }
791 /// getStrPtrType - Return a "i8*" type.
793 const PointerType *getStrPtrType();
795 /// getEmptyStructPtrType - Return a "{ }*" type.
797 const PointerType *getEmptyStructPtrType();
799 /// getTagType - Return the type describing the specified descriptor (via
801 const StructType *getTagType(DebugInfoDesc *DD);
803 /// getString - Construct the string as constant string global.
805 Constant *getString(const std::string &String);
807 /// Serialize - Recursively cast the specified descriptor into a
808 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
809 GlobalVariable *Serialize(DebugInfoDesc *DD);
811 /// addDescriptor - Directly connect DD with existing GV.
812 void addDescriptor(DebugInfoDesc *DD, GlobalVariable *GV);
815 //===----------------------------------------------------------------------===//
816 /// DIVerifier - This class is responsible for verifying the given network of
817 /// GlobalVariables are valid as DebugInfoDesc objects.
824 DenseMap<GlobalVariable *, unsigned> Validity; // Tracks prior results.
825 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
828 : Validity(), Counts()
831 /// Verify - Return true if the GlobalVariable appears to be a valid
832 /// serialization of a DebugInfoDesc.
833 bool Verify(Value *V);
834 bool Verify(GlobalVariable *GV);
836 /// isVerified - Return true if the specified GV has already been
837 /// verified as a debug information descriptor.
838 bool isVerified(GlobalVariable *GV);
841 //===----------------------------------------------------------------------===//
842 /// SourceLineInfo - This class is used to record source line correspondence.
844 class SourceLineInfo {
845 unsigned Line; // Source line number.
846 unsigned Column; // Source column.
847 unsigned SourceID; // Source ID number.
848 unsigned LabelID; // Label in code ID number.
850 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
851 : Line(L), Column(C), SourceID(S), LabelID(I) {}
854 unsigned getLine() const { return Line; }
855 unsigned getColumn() const { return Column; }
856 unsigned getSourceID() const { return SourceID; }
857 unsigned getLabelID() const { return LabelID; }
860 //===----------------------------------------------------------------------===//
861 /// SourceFileInfo - This class is used to track source information.
863 class SourceFileInfo {
864 unsigned DirectoryID; // Directory ID number.
865 std::string Name; // File name (not including directory.)
867 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
870 unsigned getDirectoryID() const { return DirectoryID; }
871 const std::string &getName() const { return Name; }
873 /// operator== - Used by UniqueVector to locate entry.
875 bool operator==(const SourceFileInfo &SI) const {
876 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
879 /// operator< - Used by UniqueVector to locate entry.
881 bool operator<(const SourceFileInfo &SI) const {
882 return getDirectoryID() < SI.getDirectoryID() ||
883 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
887 //===----------------------------------------------------------------------===//
888 /// DebugVariable - This class is used to track local variable information.
890 class DebugVariable {
892 VariableDesc *Desc; // Variable Descriptor.
893 unsigned FrameIndex; // Variable frame index.
896 DebugVariable(VariableDesc *D, unsigned I)
902 VariableDesc *getDesc() const { return Desc; }
903 unsigned getFrameIndex() const { return FrameIndex; }
906 //===----------------------------------------------------------------------===//
907 /// DebugScope - This class is used to track scope information.
911 DebugScope *Parent; // Parent to this scope.
912 DebugInfoDesc *Desc; // Debug info descriptor for scope.
913 // Either subprogram or block.
914 unsigned StartLabelID; // Label ID of the beginning of scope.
915 unsigned EndLabelID; // Label ID of the end of scope.
916 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
917 std::vector<DebugVariable *> Variables;// Variables declared in scope.
920 DebugScope(DebugScope *P, DebugInfoDesc *D)
931 DebugScope *getParent() const { return Parent; }
932 DebugInfoDesc *getDesc() const { return Desc; }
933 unsigned getStartLabelID() const { return StartLabelID; }
934 unsigned getEndLabelID() const { return EndLabelID; }
935 std::vector<DebugScope *> &getScopes() { return Scopes; }
936 std::vector<DebugVariable *> &getVariables() { return Variables; }
937 void setStartLabelID(unsigned S) { StartLabelID = S; }
938 void setEndLabelID(unsigned E) { EndLabelID = E; }
940 /// AddScope - Add a scope to the scope.
942 void AddScope(DebugScope *S) { Scopes.push_back(S); }
944 /// AddVariable - Add a variable to the scope.
946 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
949 //===----------------------------------------------------------------------===//
950 /// LandingPadInfo - This structure is used to retain landing pad info for
951 /// the current function.
953 struct LandingPadInfo {
954 MachineBasicBlock *LandingPadBlock; // Landing pad block.
955 SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
956 SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
957 unsigned LandingPadLabel; // Label at beginning of landing pad.
958 Function *Personality; // Personality function.
959 std::vector<int> TypeIds; // List of type ids (filters negative)
961 explicit LandingPadInfo(MachineBasicBlock *MBB)
962 : LandingPadBlock(MBB)
968 //===----------------------------------------------------------------------===//
969 /// MachineModuleInfo - This class contains meta information specific to a
970 /// module. Queries can be made by different debugging and exception handling
971 /// schemes and reformated for specific use.
973 class MachineModuleInfo : public ImmutablePass {
975 // Use the same deserializer/verifier for the module.
979 // CompileUnits - Uniquing vector for compile units.
980 UniqueVector<CompileUnitDesc *> CompileUnits;
982 // Directories - Uniquing vector for directories.
983 UniqueVector<std::string> Directories;
985 // SourceFiles - Uniquing vector for source files.
986 UniqueVector<SourceFileInfo> SourceFiles;
988 // Lines - List of of source line correspondence.
989 std::vector<SourceLineInfo> Lines;
991 // LabelIDList - One entry per assigned label. Normally the entry is equal to
992 // the list index(+1). If the entry is zero then the label has been deleted.
993 // Any other value indicates the label has been deleted by is mapped to
995 std::vector<unsigned> LabelIDList;
997 // ScopeMap - Tracks the scopes in the current function.
998 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
1000 // RootScope - Top level scope for the current function.
1002 DebugScope *RootScope;
1004 // FrameMoves - List of moves done by a function's prolog. Used to construct
1005 // frame maps by debug and exception handling consumers.
1006 std::vector<MachineMove> FrameMoves;
1008 // LandingPads - List of LandingPadInfo describing the landing pad information
1009 // in the current function.
1010 std::vector<LandingPadInfo> LandingPads;
1012 // TypeInfos - List of C++ TypeInfo used in the current function.
1014 std::vector<GlobalVariable *> TypeInfos;
1016 // FilterIds - List of typeids encoding filters used in the current function.
1018 std::vector<unsigned> FilterIds;
1020 // FilterEnds - List of the indices in FilterIds corresponding to filter
1023 std::vector<unsigned> FilterEnds;
1025 // Personalities - Vector of all personality functions ever seen. Used to emit
1026 // common EH frames.
1027 std::vector<Function *> Personalities;
1029 // UsedFunctions - the functions in the llvm.used list in a more easily
1030 // searchable format.
1031 SmallPtrSet<const Function *, 32> UsedFunctions;
1034 bool CallsUnwindInit;
1036 static char ID; // Pass identification, replacement for typeid
1038 MachineModuleInfo();
1039 ~MachineModuleInfo();
1041 /// doInitialization - Initialize the state for a new module.
1043 bool doInitialization();
1045 /// doFinalization - Tear down the state after completion of a module.
1047 bool doFinalization();
1049 /// BeginFunction - Begin gathering function meta information.
1051 void BeginFunction(MachineFunction *MF);
1053 /// EndFunction - Discard function meta information.
1057 /// getDescFor - Convert a Value to a debug information descriptor.
1059 // FIXME - use new Value type when available.
1060 DebugInfoDesc *getDescFor(Value *V);
1062 /// Verify - Verify that a Value is debug information descriptor.
1064 bool Verify(Value *V) { return VR.Verify(V); }
1066 /// isVerified - Return true if the specified GV has already been
1067 /// verified as a debug information descriptor.
1068 bool isVerified(GlobalVariable *GV) { return VR.isVerified(GV); }
1070 /// AnalyzeModule - Scan the module for global debug information.
1072 void AnalyzeModule(Module &M);
1074 /// hasDebugInfo - Returns true if valid debug info is present.
1076 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1078 bool callsEHReturn() const { return CallsEHReturn; }
1079 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
1081 bool callsUnwindInit() const { return CallsUnwindInit; }
1082 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
1084 /// NextLabelID - Return the next unique label id.
1086 unsigned NextLabelID() {
1087 unsigned ID = (unsigned)LabelIDList.size() + 1;
1088 LabelIDList.push_back(ID);
1092 /// RecordSourceLine - Records location information and associates it with a
1093 /// label. Returns a unique label ID used to generate a label and
1094 /// provide correspondence to the source line list.
1095 unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
1097 /// InvalidateLabel - Inhibit use of the specified label # from
1098 /// MachineModuleInfo, for example because the code was deleted.
1099 void InvalidateLabel(unsigned LabelID) {
1100 // Remap to zero to indicate deletion.
1101 RemapLabel(LabelID, 0);
1104 /// RemapLabel - Indicate that a label has been merged into another.
1106 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1107 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1108 "Old label ID out of range.");
1109 assert(NewLabelID <= LabelIDList.size() &&
1110 "New label ID out of range.");
1111 LabelIDList[OldLabelID - 1] = NewLabelID;
1114 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1115 /// ID != Mapped ID indicates that the label was folded into another label.
1116 unsigned MappedLabel(unsigned LabelID) const {
1117 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1118 return LabelID ? LabelIDList[LabelID - 1] : 0;
1121 /// RecordSource - Register a source file with debug info. Returns an source
1123 unsigned RecordSource(const std::string &Directory,
1124 const std::string &Source);
1125 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1127 /// getDirectories - Return the UniqueVector of std::string representing
1129 const UniqueVector<std::string> &getDirectories() const {
1133 /// getSourceFiles - Return the UniqueVector of source files.
1135 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1139 /// getSourceLines - Return a vector of source lines.
1141 const std::vector<SourceLineInfo> &getSourceLines() const {
1145 /// SetupCompileUnits - Set up the unique vector of compile units.
1147 void SetupCompileUnits(Module &M);
1149 /// getCompileUnits - Return a vector of debug compile units.
1151 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1153 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1154 /// named GlobalVariable.
1155 std::vector<GlobalVariable*>
1156 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1158 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1160 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1162 std::vector<GlobalVariable *> Globals =
1163 getGlobalVariablesUsing(M, Desc.getAnchorString());
1164 std::vector<T *> AnchoredDescs;
1165 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1166 GlobalVariable *GV = Globals[i];
1168 // FIXME - In the short term, changes are too drastic to continue.
1169 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1170 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1171 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1175 return AnchoredDescs;
1178 /// RecordRegionStart - Indicate the start of a region.
1180 unsigned RecordRegionStart(Value *V);
1182 /// RecordRegionEnd - Indicate the end of a region.
1184 unsigned RecordRegionEnd(Value *V);
1186 /// RecordVariable - Indicate the declaration of a local variable.
1188 void RecordVariable(GlobalValue *GV, unsigned FrameIndex);
1190 /// getRootScope - Return current functions root scope.
1192 DebugScope *getRootScope() { return RootScope; }
1194 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1196 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1198 /// getFrameMoves - Returns a reference to a list of moves done in the current
1199 /// function's prologue. Used to construct frame maps for debug and exception
1200 /// handling comsumers.
1201 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1203 //===-EH-----------------------------------------------------------------===//
1205 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1206 /// specified MachineBasicBlock.
1207 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1209 /// addInvoke - Provide the begin and end labels of an invoke style call and
1210 /// associate it with a try landing pad block.
1211 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1214 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1215 /// landing pad entry.
1216 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1218 /// addPersonality - Provide the personality function for the exception
1220 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1222 /// getPersonalityIndex - Get index of the current personality function inside
1223 /// Personalitites array
1224 unsigned getPersonalityIndex() const;
1226 /// getPersonalities - Return array of personality functions ever seen.
1227 const std::vector<Function *>& getPersonalities() const {
1228 return Personalities;
1231 // UsedFunctions - Return set of the functions in the llvm.used list.
1232 const SmallPtrSet<const Function *, 32>& getUsedFunctions() const {
1233 return UsedFunctions;
1236 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1238 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1239 std::vector<GlobalVariable *> &TyInfo);
1241 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
1243 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
1244 std::vector<GlobalVariable *> &TyInfo);
1246 /// addCleanup - Add a cleanup action for a landing pad.
1248 void addCleanup(MachineBasicBlock *LandingPad);
1250 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1252 unsigned getTypeIDFor(GlobalVariable *TI);
1254 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
1256 int getFilterIDFor(std::vector<unsigned> &TyIds);
1258 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1260 void TidyLandingPads();
1262 /// getLandingPads - Return a reference to the landing pad info for the
1263 /// current function.
1264 const std::vector<LandingPadInfo> &getLandingPads() const {
1268 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1270 const std::vector<GlobalVariable *> &getTypeInfos() const {
1274 /// getFilterIds - Return a reference to the typeids encoding filters used in
1275 /// the current function.
1276 const std::vector<unsigned> &getFilterIds() const {
1280 /// getPersonality - Return a personality function if available. The presence
1281 /// of one is required to emit exception handling info.
1282 Function *getPersonality() const;
1284 DIDeserializer *getDIDeserializer() { return &DR; }
1285 }; // End class MachineModuleInfo
1287 } // End llvm namespace