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/GlobalValue.h"
39 #include "llvm/Pass.h"
43 //===----------------------------------------------------------------------===//
44 // Forward declarations.
48 class MachineBasicBlock;
49 class MachineFunction;
55 //===----------------------------------------------------------------------===//
56 // Debug info constants.
59 LLVMDebugVersion = (6 << 16), // Current version of debug information.
60 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
61 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
62 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
65 //===----------------------------------------------------------------------===//
66 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
67 /// the supplied DebugInfoDesc.
71 virtual ~DIVisitor() {}
73 /// ApplyToFields - Target the visitor to each field of the debug information
75 void ApplyToFields(DebugInfoDesc *DD);
77 /// Apply - Subclasses override each of these methods to perform the
78 /// appropriate action for the type of field.
79 virtual void Apply(int &Field) = 0;
80 virtual void Apply(unsigned &Field) = 0;
81 virtual void Apply(int64_t &Field) = 0;
82 virtual void Apply(uint64_t &Field) = 0;
83 virtual void Apply(bool &Field) = 0;
84 virtual void Apply(std::string &Field) = 0;
85 virtual void Apply(DebugInfoDesc *&Field) = 0;
86 virtual void Apply(GlobalVariable *&Field) = 0;
87 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
90 //===----------------------------------------------------------------------===//
91 /// DebugInfoDesc - This class is the base class for debug info descriptors.
95 unsigned Tag; // Content indicator. Dwarf values are
96 // used but that does not limit use to
100 explicit DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
103 virtual ~DebugInfoDesc() {}
106 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
107 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
108 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
110 /// TagFromGlobal - Returns the tag number from a debug info descriptor
111 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
112 static unsigned TagFromGlobal(GlobalVariable *GV);
114 /// VersionFromGlobal - Returns the version number from a debug info
115 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
117 static unsigned VersionFromGlobal(GlobalVariable *GV);
119 /// DescFactory - Create an instance of debug info descriptor based on Tag.
120 /// Return NULL if not a recognized Tag.
121 static DebugInfoDesc *DescFactory(unsigned Tag);
123 /// getLinkage - get linkage appropriate for this type of descriptor.
125 virtual GlobalValue::LinkageTypes getLinkage() const;
127 //===--------------------------------------------------------------------===//
128 // Subclasses should supply the following static methods.
130 // Implement isa/cast/dyncast.
131 static bool classof(const DebugInfoDesc *) { return true; }
133 //===--------------------------------------------------------------------===//
134 // Subclasses should supply the following virtual methods.
136 /// ApplyToFields - Target the vistor to the fields of the descriptor.
138 virtual void ApplyToFields(DIVisitor *Visitor);
140 /// getDescString - Return a string used to compose global names and labels.
142 virtual const char *getDescString() const = 0;
144 /// getTypeString - Return a string used to label this descriptor's type.
146 virtual const char *getTypeString() const = 0;
149 virtual void dump() = 0;
153 //===----------------------------------------------------------------------===//
154 /// AnchorDesc - Descriptors of this class act as markers for identifying
155 /// descriptors of certain groups.
157 class AnchorDesc : public DebugInfoDesc {
159 unsigned AnchorTag; // Tag number of descriptors anchored
164 explicit AnchorDesc(AnchoredDesc *D);
167 unsigned getAnchorTag() const { return AnchorTag; }
169 // Implement isa/cast/dyncast.
170 static bool classof(const AnchorDesc *) { return true; }
171 static bool classof(const DebugInfoDesc *D);
173 /// getLinkage - get linkage appropriate for this type of descriptor.
175 virtual GlobalValue::LinkageTypes getLinkage() const;
177 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
179 virtual void ApplyToFields(DIVisitor *Visitor);
181 /// getDescString - Return a string used to compose global names and labels.
183 virtual const char *getDescString() const;
185 /// getTypeString - Return a string used to label this descriptor's type.
187 virtual const char *getTypeString() const;
194 //===----------------------------------------------------------------------===//
195 /// AnchoredDesc - This class manages anchors for a variety of top level
197 class AnchoredDesc : public DebugInfoDesc {
199 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
204 explicit AnchoredDesc(unsigned T);
208 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
209 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
211 //===--------------------------------------------------------------------===//
212 // Subclasses should supply the following virtual methods.
214 /// getAnchorString - Return a string used to label descriptor's anchor.
216 virtual const char *getAnchorString() const = 0;
218 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
220 virtual void ApplyToFields(DIVisitor *Visitor);
223 //===----------------------------------------------------------------------===//
224 /// CompileUnitDesc - This class packages debug information associated with a
225 /// source/header file.
226 class CompileUnitDesc : public AnchoredDesc {
228 unsigned Language; // Language number (ex. DW_LANG_C89.)
229 std::string FileName; // Source file name.
230 std::string Directory; // Source file directory.
231 std::string Producer; // Compiler string.
238 unsigned getLanguage() const { return Language; }
239 const std::string &getFileName() const { return FileName; }
240 const std::string &getDirectory() const { return Directory; }
241 const std::string &getProducer() const { return Producer; }
242 void setLanguage(unsigned L) { Language = L; }
243 void setFileName(const std::string &FN) { FileName = FN; }
244 void setDirectory(const std::string &D) { Directory = D; }
245 void setProducer(const std::string &P) { Producer = P; }
247 // FIXME - Need translation unit getter/setter.
249 // Implement isa/cast/dyncast.
250 static bool classof(const CompileUnitDesc *) { return true; }
251 static bool classof(const DebugInfoDesc *D);
253 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
255 virtual void ApplyToFields(DIVisitor *Visitor);
257 /// getDescString - Return a string used to compose global names and labels.
259 virtual const char *getDescString() const;
261 /// getTypeString - Return a string used to label this descriptor's type.
263 virtual const char *getTypeString() const;
265 /// getAnchorString - Return a string used to label this descriptor's anchor.
267 static const char *AnchorString;
268 virtual const char *getAnchorString() const;
275 //===----------------------------------------------------------------------===//
276 /// TypeDesc - This class packages debug information associated with a type.
278 class TypeDesc : public DebugInfoDesc {
281 FlagPrivate = 1 << 0,
282 FlagProtected = 1 << 1
284 DebugInfoDesc *Context; // Context debug descriptor.
285 std::string Name; // Type name (may be empty.)
286 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
287 unsigned Line; // Defined line# (may be zero.)
288 uint64_t Size; // Type bit size (may be zero.)
289 uint64_t Align; // Type bit alignment (may be zero.)
290 uint64_t Offset; // Type bit offset (may be zero.)
291 unsigned Flags; // Miscellaneous flags.
294 explicit TypeDesc(unsigned T);
297 DebugInfoDesc *getContext() const { return Context; }
298 const std::string &getName() const { return Name; }
299 CompileUnitDesc *getFile() const {
300 return static_cast<CompileUnitDesc *>(File);
302 unsigned getLine() const { return Line; }
303 uint64_t getSize() const { return Size; }
304 uint64_t getAlign() const { return Align; }
305 uint64_t getOffset() const { return Offset; }
306 bool isPrivate() const {
307 return (Flags & FlagPrivate) != 0;
309 bool isProtected() const {
310 return (Flags & FlagProtected) != 0;
312 void setContext(DebugInfoDesc *C) { Context = C; }
313 void setName(const std::string &N) { Name = N; }
314 void setFile(CompileUnitDesc *U) {
315 File = static_cast<DebugInfoDesc *>(U);
317 void setLine(unsigned L) { Line = L; }
318 void setSize(uint64_t S) { Size = S; }
319 void setAlign(uint64_t A) { Align = A; }
320 void setOffset(uint64_t O) { Offset = O; }
321 void setIsPrivate() { Flags |= FlagPrivate; }
322 void setIsProtected() { Flags |= FlagProtected; }
324 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
326 virtual void ApplyToFields(DIVisitor *Visitor);
328 /// getDescString - Return a string used to compose global names and labels.
330 virtual const char *getDescString() const;
332 /// getTypeString - Return a string used to label this descriptor's type.
334 virtual const char *getTypeString() const;
341 //===----------------------------------------------------------------------===//
342 /// BasicTypeDesc - This class packages debug information associated with a
343 /// basic type (eg. int, bool, double.)
344 class BasicTypeDesc : public TypeDesc {
346 unsigned Encoding; // Type encoding.
352 unsigned getEncoding() const { return Encoding; }
353 void setEncoding(unsigned E) { Encoding = E; }
355 // Implement isa/cast/dyncast.
356 static bool classof(const BasicTypeDesc *) { return true; }
357 static bool classof(const DebugInfoDesc *D);
359 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
361 virtual void ApplyToFields(DIVisitor *Visitor);
363 /// getDescString - Return a string used to compose global names and labels.
365 virtual const char *getDescString() const;
367 /// getTypeString - Return a string used to label this descriptor's type.
369 virtual const char *getTypeString() const;
377 //===----------------------------------------------------------------------===//
378 /// DerivedTypeDesc - This class packages debug information associated with a
379 /// derived types (eg., typedef, pointer, reference.)
380 class DerivedTypeDesc : public TypeDesc {
382 DebugInfoDesc *FromType; // Type derived from.
385 explicit DerivedTypeDesc(unsigned T);
388 TypeDesc *getFromType() const {
389 return static_cast<TypeDesc *>(FromType);
391 void setFromType(TypeDesc *F) {
392 FromType = static_cast<DebugInfoDesc *>(F);
395 // Implement isa/cast/dyncast.
396 static bool classof(const DerivedTypeDesc *) { return true; }
397 static bool classof(const DebugInfoDesc *D);
399 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
401 virtual void ApplyToFields(DIVisitor *Visitor);
403 /// getDescString - Return a string used to compose global names and labels.
405 virtual const char *getDescString() const;
407 /// getTypeString - Return a string used to label this descriptor's type.
409 virtual const char *getTypeString() const;
416 //===----------------------------------------------------------------------===//
417 /// CompositeTypeDesc - This class packages debug information associated with a
418 /// array/struct types (eg., arrays, struct, union, enums.)
419 class CompositeTypeDesc : public DerivedTypeDesc {
421 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
424 explicit CompositeTypeDesc(unsigned T);
427 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
429 // Implement isa/cast/dyncast.
430 static bool classof(const CompositeTypeDesc *) { return true; }
431 static bool classof(const DebugInfoDesc *D);
433 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
435 virtual void ApplyToFields(DIVisitor *Visitor);
437 /// getDescString - Return a string used to compose global names and labels.
439 virtual const char *getDescString() const;
441 /// getTypeString - Return a string used to label this descriptor's type.
443 virtual const char *getTypeString() const;
450 //===----------------------------------------------------------------------===//
451 /// SubrangeDesc - This class packages debug information associated with integer
453 class SubrangeDesc : public DebugInfoDesc {
455 int64_t Lo; // Low value of range.
456 int64_t Hi; // High value of range.
462 int64_t getLo() const { return Lo; }
463 int64_t getHi() const { return Hi; }
464 void setLo(int64_t L) { Lo = L; }
465 void setHi(int64_t H) { Hi = H; }
467 // Implement isa/cast/dyncast.
468 static bool classof(const SubrangeDesc *) { return true; }
469 static bool classof(const DebugInfoDesc *D);
471 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
473 virtual void ApplyToFields(DIVisitor *Visitor);
475 /// getDescString - Return a string used to compose global names and labels.
477 virtual const char *getDescString() const;
479 /// getTypeString - Return a string used to label this descriptor's type.
481 virtual const char *getTypeString() const;
488 //===----------------------------------------------------------------------===//
489 /// EnumeratorDesc - This class packages debug information associated with
490 /// named integer constants.
491 class EnumeratorDesc : public DebugInfoDesc {
493 std::string Name; // Enumerator name.
494 int64_t Value; // Enumerator value.
500 const std::string &getName() const { return Name; }
501 int64_t getValue() const { return Value; }
502 void setName(const std::string &N) { Name = N; }
503 void setValue(int64_t V) { Value = V; }
505 // Implement isa/cast/dyncast.
506 static bool classof(const EnumeratorDesc *) { return true; }
507 static bool classof(const DebugInfoDesc *D);
509 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
511 virtual void ApplyToFields(DIVisitor *Visitor);
513 /// getDescString - Return a string used to compose global names and labels.
515 virtual const char *getDescString() const;
517 /// getTypeString - Return a string used to label this descriptor's type.
519 virtual const char *getTypeString() const;
526 //===----------------------------------------------------------------------===//
527 /// VariableDesc - This class packages debug information associated with a
528 /// subprogram variable.
530 class VariableDesc : public DebugInfoDesc {
532 DebugInfoDesc *Context; // Context debug descriptor.
533 std::string Name; // Type name (may be empty.)
534 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
535 unsigned Line; // Defined line# (may be zero.)
536 DebugInfoDesc *TyDesc; // Type of variable.
539 explicit VariableDesc(unsigned T);
542 DebugInfoDesc *getContext() const { return Context; }
543 const std::string &getName() const { return Name; }
544 CompileUnitDesc *getFile() const {
545 return static_cast<CompileUnitDesc *>(File);
547 unsigned getLine() const { return Line; }
548 TypeDesc *getType() const {
549 return static_cast<TypeDesc *>(TyDesc);
551 void setContext(DebugInfoDesc *C) { Context = C; }
552 void setName(const std::string &N) { Name = N; }
553 void setFile(CompileUnitDesc *U) {
554 File = static_cast<DebugInfoDesc *>(U);
556 void setLine(unsigned L) { Line = L; }
557 void setType(TypeDesc *T) {
558 TyDesc = static_cast<DebugInfoDesc *>(T);
561 // Implement isa/cast/dyncast.
562 static bool classof(const VariableDesc *) { return true; }
563 static bool classof(const DebugInfoDesc *D);
565 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
567 virtual void ApplyToFields(DIVisitor *Visitor);
569 /// getDescString - Return a string used to compose global names and labels.
571 virtual const char *getDescString() const;
573 /// getTypeString - Return a string used to label this descriptor's type.
575 virtual const char *getTypeString() const;
582 //===----------------------------------------------------------------------===//
583 /// GlobalDesc - This class is the base descriptor for global functions and
585 class GlobalDesc : public AnchoredDesc {
587 DebugInfoDesc *Context; // Context debug descriptor.
588 std::string Name; // Global name.
589 std::string FullName; // Fully qualified name.
590 std::string LinkageName; // Name for binding to MIPS linkage.
591 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
592 unsigned Line; // Defined line# (may be zero.)
593 DebugInfoDesc *TyDesc; // Type debug descriptor.
594 bool IsStatic; // Is the global a static.
595 bool IsDefinition; // Is the global defined in context.
598 explicit GlobalDesc(unsigned T);
602 DebugInfoDesc *getContext() const { return Context; }
603 const std::string &getName() const { return Name; }
604 const std::string &getFullName() const { return FullName; }
605 const std::string &getLinkageName() const { return LinkageName; }
606 CompileUnitDesc *getFile() const {
607 return static_cast<CompileUnitDesc *>(File);
609 unsigned getLine() const { return Line; }
610 TypeDesc *getType() const {
611 return static_cast<TypeDesc *>(TyDesc);
613 bool isStatic() const { return IsStatic; }
614 bool isDefinition() const { return IsDefinition; }
615 void setContext(DebugInfoDesc *C) { Context = C; }
616 void setName(const std::string &N) { Name = N; }
617 void setFullName(const std::string &N) { FullName = N; }
618 void setLinkageName(const std::string &N) { LinkageName = N; }
619 void setFile(CompileUnitDesc *U) {
620 File = static_cast<DebugInfoDesc *>(U);
622 void setLine(unsigned L) { Line = L; }
623 void setType(TypeDesc *T) {
624 TyDesc = static_cast<DebugInfoDesc *>(T);
626 void setIsStatic(bool IS) { IsStatic = IS; }
627 void setIsDefinition(bool ID) { IsDefinition = ID; }
629 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
631 virtual void ApplyToFields(DIVisitor *Visitor);
634 //===----------------------------------------------------------------------===//
635 /// GlobalVariableDesc - This class packages debug information associated with a
637 class GlobalVariableDesc : public GlobalDesc {
639 GlobalVariable *Global; // llvm global.
642 GlobalVariableDesc();
645 GlobalVariable *getGlobalVariable() const { return Global; }
646 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
648 // Implement isa/cast/dyncast.
649 static bool classof(const GlobalVariableDesc *) { return true; }
650 static bool classof(const DebugInfoDesc *D);
652 /// ApplyToFields - Target the visitor to the fields of the
653 /// GlobalVariableDesc.
654 virtual void ApplyToFields(DIVisitor *Visitor);
656 /// getDescString - Return a string used to compose global names and labels.
658 virtual const char *getDescString() const;
660 /// getTypeString - Return a string used to label this descriptor's type.
662 virtual const char *getTypeString() const;
664 /// getAnchorString - Return a string used to label this descriptor's anchor.
666 static const char *AnchorString;
667 virtual const char *getAnchorString() const;
674 //===----------------------------------------------------------------------===//
675 /// SubprogramDesc - This class packages debug information associated with a
676 /// subprogram/function.
677 class SubprogramDesc : public GlobalDesc {
685 // Implement isa/cast/dyncast.
686 static bool classof(const SubprogramDesc *) { return true; }
687 static bool classof(const DebugInfoDesc *D);
689 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
691 virtual void ApplyToFields(DIVisitor *Visitor);
693 /// getDescString - Return a string used to compose global names and labels.
695 virtual const char *getDescString() const;
697 /// getTypeString - Return a string used to label this descriptor's type.
699 virtual const char *getTypeString() const;
701 /// getAnchorString - Return a string used to label this descriptor's anchor.
703 static const char *AnchorString;
704 virtual const char *getAnchorString() const;
711 //===----------------------------------------------------------------------===//
712 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
714 class BlockDesc : public DebugInfoDesc {
716 DebugInfoDesc *Context; // Context debug descriptor.
722 DebugInfoDesc *getContext() const { return Context; }
723 void setContext(DebugInfoDesc *C) { Context = C; }
725 // Implement isa/cast/dyncast.
726 static bool classof(const BlockDesc *) { return true; }
727 static bool classof(const DebugInfoDesc *D);
729 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
731 virtual void ApplyToFields(DIVisitor *Visitor);
733 /// getDescString - Return a string used to compose global names and labels.
735 virtual const char *getDescString() const;
737 /// getTypeString - Return a string used to label this descriptor's type.
739 virtual const char *getTypeString() const;
746 //===----------------------------------------------------------------------===//
747 /// DIDeserializer - This class is responsible for casting GlobalVariables
748 /// into DebugInfoDesc objects.
749 class DIDeserializer {
751 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
752 // Previously defined gloabls.
758 const std::map<GlobalVariable *, DebugInfoDesc *> &getGlobalDescs() const {
762 /// Deserialize - Reconstitute a GlobalVariable into it's component
763 /// DebugInfoDesc objects.
764 DebugInfoDesc *Deserialize(Value *V);
765 DebugInfoDesc *Deserialize(GlobalVariable *GV);
768 //===----------------------------------------------------------------------===//
769 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
770 /// into GlobalVariables.
773 Module *M; // Definition space module.
774 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
775 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
776 std::map<unsigned, StructType *> TagTypes;
777 // Types per Tag. Created lazily.
778 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
779 // Previously defined descriptors.
780 std::map<const std::string, Constant *> StringCache;
781 // Previously defined strings.
787 , EmptyStructPtrTy(NULL)
795 Module *getModule() const { return M; };
796 void setModule(Module *module) { M = module; }
798 /// getStrPtrType - Return a "sbyte *" type.
800 const PointerType *getStrPtrType();
802 /// getEmptyStructPtrType - Return a "{ }*" type.
804 const PointerType *getEmptyStructPtrType();
806 /// getTagType - Return the type describing the specified descriptor (via
808 const StructType *getTagType(DebugInfoDesc *DD);
810 /// getString - Construct the string as constant string global.
812 Constant *getString(const std::string &String);
814 /// Serialize - Recursively cast the specified descriptor into a
815 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
816 GlobalVariable *Serialize(DebugInfoDesc *DD);
818 /// addDescriptor - Directly connect DD with existing GV.
819 void addDescriptor(DebugInfoDesc *DD, GlobalVariable *GV);
822 //===----------------------------------------------------------------------===//
823 /// DIVerifier - This class is responsible for verifying the given network of
824 /// GlobalVariables are valid as DebugInfoDesc objects.
832 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
833 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
842 /// Verify - Return true if the GlobalVariable appears to be a valid
843 /// serialization of a DebugInfoDesc.
844 bool Verify(Value *V);
845 bool Verify(GlobalVariable *GV);
848 //===----------------------------------------------------------------------===//
849 /// SourceLineInfo - This class is used to record source line correspondence.
851 class SourceLineInfo {
853 unsigned Line; // Source line number.
854 unsigned Column; // Source column.
855 unsigned SourceID; // Source ID number.
856 unsigned LabelID; // Label in code ID number.
859 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
860 : Line(L), Column(C), SourceID(S), LabelID(I) {}
863 unsigned getLine() const { return Line; }
864 unsigned getColumn() const { return Column; }
865 unsigned getSourceID() const { return SourceID; }
866 unsigned getLabelID() const { return LabelID; }
869 //===----------------------------------------------------------------------===//
870 /// SourceFileInfo - This class is used to track source information.
872 class SourceFileInfo {
874 unsigned DirectoryID; // Directory ID number.
875 std::string Name; // File name (not including directory.)
878 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
881 unsigned getDirectoryID() const { return DirectoryID; }
882 const std::string &getName() const { return Name; }
884 /// operator== - Used by UniqueVector to locate entry.
886 bool operator==(const SourceFileInfo &SI) const {
887 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
890 /// operator< - Used by UniqueVector to locate entry.
892 bool operator<(const SourceFileInfo &SI) const {
893 return getDirectoryID() < SI.getDirectoryID() ||
894 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
898 //===----------------------------------------------------------------------===//
899 /// DebugVariable - This class is used to track local variable information.
901 class DebugVariable {
903 VariableDesc *Desc; // Variable Descriptor.
904 unsigned FrameIndex; // Variable frame index.
907 DebugVariable(VariableDesc *D, unsigned I)
913 VariableDesc *getDesc() const { return Desc; }
914 unsigned getFrameIndex() const { return FrameIndex; }
917 //===----------------------------------------------------------------------===//
918 /// DebugScope - This class is used to track scope information.
922 DebugScope *Parent; // Parent to this scope.
923 DebugInfoDesc *Desc; // Debug info descriptor for scope.
924 // Either subprogram or block.
925 unsigned StartLabelID; // Label ID of the beginning of scope.
926 unsigned EndLabelID; // Label ID of the end of scope.
927 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
928 std::vector<DebugVariable *> Variables;// Variables declared in scope.
931 DebugScope(DebugScope *P, DebugInfoDesc *D)
942 DebugScope *getParent() const { return Parent; }
943 DebugInfoDesc *getDesc() const { return Desc; }
944 unsigned getStartLabelID() const { return StartLabelID; }
945 unsigned getEndLabelID() const { return EndLabelID; }
946 std::vector<DebugScope *> &getScopes() { return Scopes; }
947 std::vector<DebugVariable *> &getVariables() { return Variables; }
948 void setStartLabelID(unsigned S) { StartLabelID = S; }
949 void setEndLabelID(unsigned E) { EndLabelID = E; }
951 /// AddScope - Add a scope to the scope.
953 void AddScope(DebugScope *S) { Scopes.push_back(S); }
955 /// AddVariable - Add a variable to the scope.
957 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
960 //===----------------------------------------------------------------------===//
961 /// LandingPadInfo - This structure is used to retain landing pad info for
962 /// the current function.
964 struct LandingPadInfo {
965 MachineBasicBlock *LandingPadBlock; // Landing pad block.
966 SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
967 SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
968 unsigned LandingPadLabel; // Label at beginning of landing pad.
969 Function *Personality; // Personality function.
970 std::vector<int> TypeIds; // List of type ids (filters negative)
972 explicit LandingPadInfo(MachineBasicBlock *MBB)
973 : LandingPadBlock(MBB)
979 //===----------------------------------------------------------------------===//
980 /// MachineModuleInfo - This class contains meta information specific to a
981 /// module. Queries can be made by different debugging and exception handling
982 /// schemes and reformated for specific use.
984 class MachineModuleInfo : public ImmutablePass {
986 // Use the same deserializer/verifier for the module.
990 // CompileUnits - Uniquing vector for compile units.
991 UniqueVector<CompileUnitDesc *> CompileUnits;
993 // Directories - Uniquing vector for directories.
994 UniqueVector<std::string> Directories;
996 // SourceFiles - Uniquing vector for source files.
997 UniqueVector<SourceFileInfo> SourceFiles;
999 // Lines - List of of source line correspondence.
1000 std::vector<SourceLineInfo> Lines;
1002 // LabelIDList - One entry per assigned label. Normally the entry is equal to
1003 // the list index(+1). If the entry is zero then the label has been deleted.
1004 // Any other value indicates the label has been deleted by is mapped to
1006 std::vector<unsigned> LabelIDList;
1008 // ScopeMap - Tracks the scopes in the current function.
1009 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
1011 // RootScope - Top level scope for the current function.
1013 DebugScope *RootScope;
1015 // FrameMoves - List of moves done by a function's prolog. Used to construct
1016 // frame maps by debug and exception handling consumers.
1017 std::vector<MachineMove> FrameMoves;
1019 // LandingPads - List of LandingPadInfo describing the landing pad information
1020 // in the current function.
1021 std::vector<LandingPadInfo> LandingPads;
1023 // TypeInfos - List of C++ TypeInfo used in the current function.
1025 std::vector<GlobalVariable *> TypeInfos;
1027 // FilterIds - List of typeids encoding filters used in the current function.
1029 std::vector<unsigned> FilterIds;
1031 // FilterEnds - List of the indices in FilterIds corresponding to filter
1034 std::vector<unsigned> FilterEnds;
1036 // Personalities - Vector of all personality functions ever seen. Used to emit
1037 // common EH frames.
1038 std::vector<Function *> Personalities;
1041 bool CallsUnwindInit;
1043 static char ID; // Pass identification, replacement for typeid
1045 MachineModuleInfo();
1046 ~MachineModuleInfo();
1048 /// doInitialization - Initialize the state for a new module.
1050 bool doInitialization();
1052 /// doFinalization - Tear down the state after completion of a module.
1054 bool doFinalization();
1056 /// BeginFunction - Begin gathering function meta information.
1058 void BeginFunction(MachineFunction *MF);
1060 /// EndFunction - Discard function meta information.
1064 /// getDescFor - Convert a Value to a debug information descriptor.
1066 // FIXME - use new Value type when available.
1067 DebugInfoDesc *getDescFor(Value *V);
1069 /// Verify - Verify that a Value is debug information descriptor.
1071 bool Verify(Value *V);
1073 /// AnalyzeModule - Scan the module for global debug information.
1075 void AnalyzeModule(Module &M);
1077 /// hasDebugInfo - Returns true if valid debug info is present.
1079 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1081 /// needsFrameInfo - Returns true if we need to gather callee-saved register
1082 /// move info for the frame.
1083 bool needsFrameInfo() const;
1085 bool callsEHReturn() const { return CallsEHReturn; }
1086 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
1088 bool callsUnwindInit() const { return CallsUnwindInit; }
1089 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
1091 /// NextLabelID - Return the next unique label id.
1093 unsigned NextLabelID() {
1094 unsigned ID = LabelIDList.size() + 1;
1095 LabelIDList.push_back(ID);
1099 /// RecordLabel - Records location information and associates it with a
1100 /// label. Returns a unique label ID used to generate a label and
1101 /// provide correspondence to the source line list.
1102 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1104 /// InvalidateLabel - Inhibit use of the specified label # from
1105 /// MachineModuleInfo, for example because the code was deleted.
1106 void InvalidateLabel(unsigned LabelID) {
1107 // Remap to zero to indicate deletion.
1108 RemapLabel(LabelID, 0);
1111 /// RemapLabel - Indicate that a label has been merged into another.
1113 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1114 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1115 "Old label ID out of range.");
1116 assert(NewLabelID <= LabelIDList.size() &&
1117 "New label ID out of range.");
1118 LabelIDList[OldLabelID - 1] = NewLabelID;
1121 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1122 /// ID != Mapped ID indicates that the label was folded into another label.
1123 unsigned MappedLabel(unsigned LabelID) const {
1124 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1125 return LabelID ? LabelIDList[LabelID - 1] : 0;
1128 /// RecordSource - Register a source file with debug info. Returns an source
1130 unsigned RecordSource(const std::string &Directory,
1131 const std::string &Source);
1132 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1134 /// getDirectories - Return the UniqueVector of std::string representing
1136 const UniqueVector<std::string> &getDirectories() const {
1140 /// getSourceFiles - Return the UniqueVector of source files.
1142 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1146 /// getSourceLines - Return a vector of source lines.
1148 const std::vector<SourceLineInfo> &getSourceLines() const {
1152 /// SetupCompileUnits - Set up the unique vector of compile units.
1154 void SetupCompileUnits(Module &M);
1156 /// getCompileUnits - Return a vector of debug compile units.
1158 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1160 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1161 /// named GlobalVariable.
1162 std::vector<GlobalVariable*>
1163 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1165 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1167 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1169 std::vector<GlobalVariable *> Globals =
1170 getGlobalVariablesUsing(M, Desc.getAnchorString());
1171 std::vector<T *> AnchoredDescs;
1172 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1173 GlobalVariable *GV = Globals[i];
1175 // FIXME - In the short term, changes are too drastic to continue.
1176 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1177 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1178 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1182 return AnchoredDescs;
1185 /// RecordRegionStart - Indicate the start of a region.
1187 unsigned RecordRegionStart(Value *V);
1189 /// RecordRegionEnd - Indicate the end of a region.
1191 unsigned RecordRegionEnd(Value *V);
1193 /// RecordVariable - Indicate the declaration of a local variable.
1195 void RecordVariable(Value *V, unsigned FrameIndex);
1197 /// getRootScope - Return current functions root scope.
1199 DebugScope *getRootScope() { return RootScope; }
1201 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1203 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1205 /// getFrameMoves - Returns a reference to a list of moves done in the current
1206 /// function's prologue. Used to construct frame maps for debug and exception
1207 /// handling comsumers.
1208 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1210 //===-EH-----------------------------------------------------------------===//
1212 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1213 /// specified MachineBasicBlock.
1214 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1216 /// addInvoke - Provide the begin and end labels of an invoke style call and
1217 /// associate it with a try landing pad block.
1218 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1221 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1222 /// landing pad entry.
1223 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1225 /// addPersonality - Provide the personality function for the exception
1227 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1229 /// getPersonalityIndex - Get index of the current personality function inside
1230 /// Personalitites array
1231 unsigned getPersonalityIndex() const;
1233 /// getPersonalities - Return array of personality functions ever seen.
1234 const std::vector<Function *>& getPersonalities() const {
1235 return Personalities;
1238 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1240 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1241 std::vector<GlobalVariable *> &TyInfo);
1243 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
1245 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
1246 std::vector<GlobalVariable *> &TyInfo);
1248 /// addCleanup - Add a cleanup action for a landing pad.
1250 void addCleanup(MachineBasicBlock *LandingPad);
1252 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1254 unsigned getTypeIDFor(GlobalVariable *TI);
1256 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
1258 int getFilterIDFor(std::vector<unsigned> &TyIds);
1260 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1262 void TidyLandingPads();
1264 /// getLandingPads - Return a reference to the landing pad info for the
1265 /// current function.
1266 const std::vector<LandingPadInfo> &getLandingPads() const {
1270 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1272 const std::vector<GlobalVariable *> &getTypeInfos() const {
1276 /// getFilterIds - Return a reference to the typeids encoding filters used in
1277 /// the current function.
1278 const std::vector<unsigned> &getFilterIds() const {
1282 /// getPersonality - Return a personality function if available. The presence
1283 /// of one is required to emit exception handling info.
1284 Function *getPersonality() const;
1286 DIDeserializer *getDIDeserializer() { return &DR; }
1287 }; // End class MachineModuleInfo
1289 } // End llvm namespace