1 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source 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/UniqueVector.h"
37 #include "llvm/GlobalValue.h"
38 #include "llvm/Pass.h"
42 //===----------------------------------------------------------------------===//
43 // Forward declarations.
47 class MachineFunction;
53 //===----------------------------------------------------------------------===//
54 // Debug info constants.
57 LLVMDebugVersion = (6 << 16), // Current version of debug information.
58 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
59 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
60 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
63 //===----------------------------------------------------------------------===//
64 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
65 /// the supplied DebugInfoDesc.
69 virtual ~DIVisitor() {}
71 /// ApplyToFields - Target the visitor to each field of the debug information
73 void ApplyToFields(DebugInfoDesc *DD);
75 /// Apply - Subclasses override each of these methods to perform the
76 /// appropriate action for the type of field.
77 virtual void Apply(int &Field) = 0;
78 virtual void Apply(unsigned &Field) = 0;
79 virtual void Apply(int64_t &Field) = 0;
80 virtual void Apply(uint64_t &Field) = 0;
81 virtual void Apply(bool &Field) = 0;
82 virtual void Apply(std::string &Field) = 0;
83 virtual void Apply(DebugInfoDesc *&Field) = 0;
84 virtual void Apply(GlobalVariable *&Field) = 0;
85 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
88 //===----------------------------------------------------------------------===//
89 /// DebugInfoDesc - This class is the base class for debug info descriptors.
93 unsigned Tag; // Content indicator. Dwarf values are
94 // used but that does not limit use to
98 DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
101 virtual ~DebugInfoDesc() {}
104 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
105 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
106 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
108 /// TagFromGlobal - Returns the tag number from a debug info descriptor
109 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
110 static unsigned TagFromGlobal(GlobalVariable *GV);
112 /// VersionFromGlobal - Returns the version number from a debug info
113 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
115 static unsigned VersionFromGlobal(GlobalVariable *GV);
117 /// DescFactory - Create an instance of debug info descriptor based on Tag.
118 /// Return NULL if not a recognized Tag.
119 static DebugInfoDesc *DescFactory(unsigned Tag);
121 /// getLinkage - get linkage appropriate for this type of descriptor.
123 virtual GlobalValue::LinkageTypes getLinkage() const;
125 //===--------------------------------------------------------------------===//
126 // Subclasses should supply the following static methods.
128 // Implement isa/cast/dyncast.
129 static bool classof(const DebugInfoDesc *) { return true; }
131 //===--------------------------------------------------------------------===//
132 // Subclasses should supply the following virtual methods.
134 /// ApplyToFields - Target the vistor to the fields of the descriptor.
136 virtual void ApplyToFields(DIVisitor *Visitor);
138 /// getDescString - Return a string used to compose global names and labels.
140 virtual const char *getDescString() const = 0;
142 /// getTypeString - Return a string used to label this descriptor's type.
144 virtual const char *getTypeString() const = 0;
147 virtual void dump() = 0;
151 //===----------------------------------------------------------------------===//
152 /// AnchorDesc - Descriptors of this class act as markers for identifying
153 /// descriptors of certain groups.
155 class AnchorDesc : public DebugInfoDesc {
157 unsigned AnchorTag; // Tag number of descriptors anchored
162 AnchorDesc(AnchoredDesc *D);
165 unsigned getAnchorTag() const { return AnchorTag; }
167 // Implement isa/cast/dyncast.
168 static bool classof(const AnchorDesc *) { return true; }
169 static bool classof(const DebugInfoDesc *D);
171 /// getLinkage - get linkage appropriate for this type of descriptor.
173 virtual GlobalValue::LinkageTypes getLinkage() const;
175 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
177 virtual void ApplyToFields(DIVisitor *Visitor);
179 /// getDescString - Return a string used to compose global names and labels.
181 virtual const char *getDescString() const;
183 /// getTypeString - Return a string used to label this descriptor's type.
185 virtual const char *getTypeString() const;
192 //===----------------------------------------------------------------------===//
193 /// AnchoredDesc - This class manages anchors for a variety of top level
195 class AnchoredDesc : public DebugInfoDesc {
197 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
202 AnchoredDesc(unsigned T);
206 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
207 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
209 //===--------------------------------------------------------------------===//
210 // Subclasses should supply the following virtual methods.
212 /// getAnchorString - Return a string used to label descriptor's anchor.
214 virtual const char *getAnchorString() const = 0;
216 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
218 virtual void ApplyToFields(DIVisitor *Visitor);
221 //===----------------------------------------------------------------------===//
222 /// CompileUnitDesc - This class packages debug information associated with a
223 /// source/header file.
224 class CompileUnitDesc : public AnchoredDesc {
226 unsigned Language; // Language number (ex. DW_LANG_C89.)
227 std::string FileName; // Source file name.
228 std::string Directory; // Source file directory.
229 std::string Producer; // Compiler string.
236 unsigned getLanguage() const { return Language; }
237 const std::string &getFileName() const { return FileName; }
238 const std::string &getDirectory() const { return Directory; }
239 const std::string &getProducer() const { return Producer; }
240 void setLanguage(unsigned L) { Language = L; }
241 void setFileName(const std::string &FN) { FileName = FN; }
242 void setDirectory(const std::string &D) { Directory = D; }
243 void setProducer(const std::string &P) { Producer = P; }
245 // FIXME - Need translation unit getter/setter.
247 // Implement isa/cast/dyncast.
248 static bool classof(const CompileUnitDesc *) { return true; }
249 static bool classof(const DebugInfoDesc *D);
251 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
253 virtual void ApplyToFields(DIVisitor *Visitor);
255 /// getDescString - Return a string used to compose global names and labels.
257 virtual const char *getDescString() const;
259 /// getTypeString - Return a string used to label this descriptor's type.
261 virtual const char *getTypeString() const;
263 /// getAnchorString - Return a string used to label this descriptor's anchor.
265 static const char *AnchorString;
266 virtual const char *getAnchorString() const;
273 //===----------------------------------------------------------------------===//
274 /// TypeDesc - This class packages debug information associated with a type.
276 class TypeDesc : public DebugInfoDesc {
279 FlagPrivate = 1 << 0,
280 FlagProtected = 1 << 1
282 DebugInfoDesc *Context; // Context debug descriptor.
283 std::string Name; // Type name (may be empty.)
284 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
285 unsigned Line; // Defined line# (may be zero.)
286 uint64_t Size; // Type bit size (may be zero.)
287 uint64_t Align; // Type bit alignment (may be zero.)
288 uint64_t Offset; // Type bit offset (may be zero.)
289 unsigned Flags; // Miscellaneous flags.
292 TypeDesc(unsigned T);
295 DebugInfoDesc *getContext() const { return Context; }
296 const std::string &getName() const { return Name; }
297 CompileUnitDesc *getFile() const {
298 return static_cast<CompileUnitDesc *>(File);
300 unsigned getLine() const { return Line; }
301 uint64_t getSize() const { return Size; }
302 uint64_t getAlign() const { return Align; }
303 uint64_t getOffset() const { return Offset; }
304 bool isPrivate() const {
305 return (Flags & FlagPrivate) != 0;
307 bool isProtected() const {
308 return (Flags & FlagProtected) != 0;
310 void setContext(DebugInfoDesc *C) { Context = C; }
311 void setName(const std::string &N) { Name = N; }
312 void setFile(CompileUnitDesc *U) {
313 File = static_cast<DebugInfoDesc *>(U);
315 void setLine(unsigned L) { Line = L; }
316 void setSize(uint64_t S) { Size = S; }
317 void setAlign(uint64_t A) { Align = A; }
318 void setOffset(uint64_t O) { Offset = O; }
319 void setIsPrivate() { Flags |= FlagPrivate; }
320 void setIsProtected() { Flags |= FlagProtected; }
322 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
324 virtual void ApplyToFields(DIVisitor *Visitor);
326 /// getDescString - Return a string used to compose global names and labels.
328 virtual const char *getDescString() const;
330 /// getTypeString - Return a string used to label this descriptor's type.
332 virtual const char *getTypeString() const;
339 //===----------------------------------------------------------------------===//
340 /// BasicTypeDesc - This class packages debug information associated with a
341 /// basic type (eg. int, bool, double.)
342 class BasicTypeDesc : public TypeDesc {
344 unsigned Encoding; // Type encoding.
350 unsigned getEncoding() const { return Encoding; }
351 void setEncoding(unsigned E) { Encoding = E; }
353 // Implement isa/cast/dyncast.
354 static bool classof(const BasicTypeDesc *) { return true; }
355 static bool classof(const DebugInfoDesc *D);
357 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
359 virtual void ApplyToFields(DIVisitor *Visitor);
361 /// getDescString - Return a string used to compose global names and labels.
363 virtual const char *getDescString() const;
365 /// getTypeString - Return a string used to label this descriptor's type.
367 virtual const char *getTypeString() const;
375 //===----------------------------------------------------------------------===//
376 /// DerivedTypeDesc - This class packages debug information associated with a
377 /// derived types (eg., typedef, pointer, reference.)
378 class DerivedTypeDesc : public TypeDesc {
380 DebugInfoDesc *FromType; // Type derived from.
383 DerivedTypeDesc(unsigned T);
386 TypeDesc *getFromType() const {
387 return static_cast<TypeDesc *>(FromType);
389 void setFromType(TypeDesc *F) {
390 FromType = static_cast<DebugInfoDesc *>(F);
393 // Implement isa/cast/dyncast.
394 static bool classof(const DerivedTypeDesc *) { return true; }
395 static bool classof(const DebugInfoDesc *D);
397 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
399 virtual void ApplyToFields(DIVisitor *Visitor);
401 /// getDescString - Return a string used to compose global names and labels.
403 virtual const char *getDescString() const;
405 /// getTypeString - Return a string used to label this descriptor's type.
407 virtual const char *getTypeString() const;
414 //===----------------------------------------------------------------------===//
415 /// CompositeTypeDesc - This class packages debug information associated with a
416 /// array/struct types (eg., arrays, struct, union, enums.)
417 class CompositeTypeDesc : public DerivedTypeDesc {
419 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
422 CompositeTypeDesc(unsigned T);
425 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
427 // Implement isa/cast/dyncast.
428 static bool classof(const CompositeTypeDesc *) { return true; }
429 static bool classof(const DebugInfoDesc *D);
431 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
433 virtual void ApplyToFields(DIVisitor *Visitor);
435 /// getDescString - Return a string used to compose global names and labels.
437 virtual const char *getDescString() const;
439 /// getTypeString - Return a string used to label this descriptor's type.
441 virtual const char *getTypeString() const;
448 //===----------------------------------------------------------------------===//
449 /// SubrangeDesc - This class packages debug information associated with integer
451 class SubrangeDesc : public DebugInfoDesc {
453 int64_t Lo; // Low value of range.
454 int64_t Hi; // High value of range.
460 int64_t getLo() const { return Lo; }
461 int64_t getHi() const { return Hi; }
462 void setLo(int64_t L) { Lo = L; }
463 void setHi(int64_t H) { Hi = H; }
465 // Implement isa/cast/dyncast.
466 static bool classof(const SubrangeDesc *) { return true; }
467 static bool classof(const DebugInfoDesc *D);
469 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
471 virtual void ApplyToFields(DIVisitor *Visitor);
473 /// getDescString - Return a string used to compose global names and labels.
475 virtual const char *getDescString() const;
477 /// getTypeString - Return a string used to label this descriptor's type.
479 virtual const char *getTypeString() const;
486 //===----------------------------------------------------------------------===//
487 /// EnumeratorDesc - This class packages debug information associated with
488 /// named integer constants.
489 class EnumeratorDesc : public DebugInfoDesc {
491 std::string Name; // Enumerator name.
492 int64_t Value; // Enumerator value.
498 const std::string &getName() const { return Name; }
499 int64_t getValue() const { return Value; }
500 void setName(const std::string &N) { Name = N; }
501 void setValue(int64_t V) { Value = V; }
503 // Implement isa/cast/dyncast.
504 static bool classof(const EnumeratorDesc *) { return true; }
505 static bool classof(const DebugInfoDesc *D);
507 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
509 virtual void ApplyToFields(DIVisitor *Visitor);
511 /// getDescString - Return a string used to compose global names and labels.
513 virtual const char *getDescString() const;
515 /// getTypeString - Return a string used to label this descriptor's type.
517 virtual const char *getTypeString() const;
524 //===----------------------------------------------------------------------===//
525 /// VariableDesc - This class packages debug information associated with a
526 /// subprogram variable.
528 class VariableDesc : public DebugInfoDesc {
530 DebugInfoDesc *Context; // Context debug descriptor.
531 std::string Name; // Type name (may be empty.)
532 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
533 unsigned Line; // Defined line# (may be zero.)
534 DebugInfoDesc *TyDesc; // Type of variable.
537 VariableDesc(unsigned T);
540 DebugInfoDesc *getContext() const { return Context; }
541 const std::string &getName() const { return Name; }
542 CompileUnitDesc *getFile() const {
543 return static_cast<CompileUnitDesc *>(File);
545 unsigned getLine() const { return Line; }
546 TypeDesc *getType() const {
547 return static_cast<TypeDesc *>(TyDesc);
549 void setContext(DebugInfoDesc *C) { Context = C; }
550 void setName(const std::string &N) { Name = N; }
551 void setFile(CompileUnitDesc *U) {
552 File = static_cast<DebugInfoDesc *>(U);
554 void setLine(unsigned L) { Line = L; }
555 void setType(TypeDesc *T) {
556 TyDesc = static_cast<DebugInfoDesc *>(T);
559 // Implement isa/cast/dyncast.
560 static bool classof(const VariableDesc *) { return true; }
561 static bool classof(const DebugInfoDesc *D);
563 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
565 virtual void ApplyToFields(DIVisitor *Visitor);
567 /// getDescString - Return a string used to compose global names and labels.
569 virtual const char *getDescString() const;
571 /// getTypeString - Return a string used to label this descriptor's type.
573 virtual const char *getTypeString() const;
580 //===----------------------------------------------------------------------===//
581 /// GlobalDesc - This class is the base descriptor for global functions and
583 class GlobalDesc : public AnchoredDesc {
585 DebugInfoDesc *Context; // Context debug descriptor.
586 std::string Name; // Global name.
587 std::string FullName; // Fully qualified name.
588 std::string LinkageName; // Name for binding to MIPS linkage.
589 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
590 unsigned Line; // Defined line# (may be zero.)
591 DebugInfoDesc *TyDesc; // Type debug descriptor.
592 bool IsStatic; // Is the global a static.
593 bool IsDefinition; // Is the global defined in context.
596 GlobalDesc(unsigned T);
600 DebugInfoDesc *getContext() const { return Context; }
601 const std::string &getName() const { return Name; }
602 const std::string &getFullName() const { return FullName; }
603 const std::string &getLinkageName() const { return LinkageName; }
604 CompileUnitDesc *getFile() const {
605 return static_cast<CompileUnitDesc *>(File);
607 unsigned getLine() const { return Line; }
608 TypeDesc *getType() const {
609 return static_cast<TypeDesc *>(TyDesc);
611 bool isStatic() const { return IsStatic; }
612 bool isDefinition() const { return IsDefinition; }
613 void setContext(DebugInfoDesc *C) { Context = C; }
614 void setName(const std::string &N) { Name = N; }
615 void setFullName(const std::string &N) { FullName = N; }
616 void setLinkageName(const std::string &N) { LinkageName = N; }
617 void setFile(CompileUnitDesc *U) {
618 File = static_cast<DebugInfoDesc *>(U);
620 void setLine(unsigned L) { Line = L; }
621 void setType(TypeDesc *T) {
622 TyDesc = static_cast<DebugInfoDesc *>(T);
624 void setIsStatic(bool IS) { IsStatic = IS; }
625 void setIsDefinition(bool ID) { IsDefinition = ID; }
627 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
629 virtual void ApplyToFields(DIVisitor *Visitor);
632 //===----------------------------------------------------------------------===//
633 /// GlobalVariableDesc - This class packages debug information associated with a
635 class GlobalVariableDesc : public GlobalDesc {
637 GlobalVariable *Global; // llvm global.
640 GlobalVariableDesc();
643 GlobalVariable *getGlobalVariable() const { return Global; }
644 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
646 // Implement isa/cast/dyncast.
647 static bool classof(const GlobalVariableDesc *) { return true; }
648 static bool classof(const DebugInfoDesc *D);
650 /// ApplyToFields - Target the visitor to the fields of the
651 /// GlobalVariableDesc.
652 virtual void ApplyToFields(DIVisitor *Visitor);
654 /// getDescString - Return a string used to compose global names and labels.
656 virtual const char *getDescString() const;
658 /// getTypeString - Return a string used to label this descriptor's type.
660 virtual const char *getTypeString() const;
662 /// getAnchorString - Return a string used to label this descriptor's anchor.
664 static const char *AnchorString;
665 virtual const char *getAnchorString() const;
672 //===----------------------------------------------------------------------===//
673 /// SubprogramDesc - This class packages debug information associated with a
674 /// subprogram/function.
675 class SubprogramDesc : public GlobalDesc {
683 // Implement isa/cast/dyncast.
684 static bool classof(const SubprogramDesc *) { return true; }
685 static bool classof(const DebugInfoDesc *D);
687 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
689 virtual void ApplyToFields(DIVisitor *Visitor);
691 /// getDescString - Return a string used to compose global names and labels.
693 virtual const char *getDescString() const;
695 /// getTypeString - Return a string used to label this descriptor's type.
697 virtual const char *getTypeString() const;
699 /// getAnchorString - Return a string used to label this descriptor's anchor.
701 static const char *AnchorString;
702 virtual const char *getAnchorString() const;
709 //===----------------------------------------------------------------------===//
710 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
712 class BlockDesc : public DebugInfoDesc {
714 DebugInfoDesc *Context; // Context debug descriptor.
720 DebugInfoDesc *getContext() const { return Context; }
721 void setContext(DebugInfoDesc *C) { Context = C; }
723 // Implement isa/cast/dyncast.
724 static bool classof(const BlockDesc *) { return true; }
725 static bool classof(const DebugInfoDesc *D);
727 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
729 virtual void ApplyToFields(DIVisitor *Visitor);
731 /// getDescString - Return a string used to compose global names and labels.
733 virtual const char *getDescString() const;
735 /// getTypeString - Return a string used to label this descriptor's type.
737 virtual const char *getTypeString() const;
744 //===----------------------------------------------------------------------===//
745 /// DIDeserializer - This class is responsible for casting GlobalVariables
746 /// into DebugInfoDesc objects.
747 class DIDeserializer {
749 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
750 // Previously defined gloabls.
756 /// Deserialize - Reconstitute a GlobalVariable into it's component
757 /// DebugInfoDesc objects.
758 DebugInfoDesc *Deserialize(Value *V);
759 DebugInfoDesc *Deserialize(GlobalVariable *GV);
762 //===----------------------------------------------------------------------===//
763 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
764 /// into GlobalVariables.
767 Module *M; // Definition space module.
768 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
769 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
770 std::map<unsigned, StructType *> TagTypes;
771 // Types per Tag. Created lazily.
772 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
773 // Previously defined descriptors.
774 std::map<const std::string, Constant *> StringCache;
775 // Previously defined strings.
781 , EmptyStructPtrTy(NULL)
789 Module *getModule() const { return M; };
790 void setModule(Module *module) { M = module; }
792 /// getStrPtrType - Return a "sbyte *" type.
794 const PointerType *getStrPtrType();
796 /// getEmptyStructPtrType - Return a "{ }*" type.
798 const PointerType *getEmptyStructPtrType();
800 /// getTagType - Return the type describing the specified descriptor (via
802 const StructType *getTagType(DebugInfoDesc *DD);
804 /// getString - Construct the string as constant string global.
806 Constant *getString(const std::string &String);
808 /// Serialize - Recursively cast the specified descriptor into a
809 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
810 GlobalVariable *Serialize(DebugInfoDesc *DD);
813 //===----------------------------------------------------------------------===//
814 /// DIVerifier - This class is responsible for verifying the given network of
815 /// GlobalVariables are valid as DebugInfoDesc objects.
823 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
824 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
833 /// Verify - Return true if the GlobalVariable appears to be a valid
834 /// serialization of a DebugInfoDesc.
835 bool Verify(Value *V);
836 bool Verify(GlobalVariable *GV);
839 //===----------------------------------------------------------------------===//
840 /// SourceLineInfo - This class is used to record source line correspondence.
842 class SourceLineInfo {
844 unsigned Line; // Source line number.
845 unsigned Column; // Source column.
846 unsigned SourceID; // Source ID number.
847 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 {
865 unsigned DirectoryID; // Directory ID number.
866 std::string Name; // File name (not including directory.)
869 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
872 unsigned getDirectoryID() const { return DirectoryID; }
873 const std::string &getName() const { return Name; }
875 /// operator== - Used by UniqueVector to locate entry.
877 bool operator==(const SourceFileInfo &SI) const {
878 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
881 /// operator< - Used by UniqueVector to locate entry.
883 bool operator<(const SourceFileInfo &SI) const {
884 return getDirectoryID() < SI.getDirectoryID() ||
885 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
889 //===----------------------------------------------------------------------===//
890 /// DebugVariable - This class is used to track local variable information.
892 class DebugVariable {
894 VariableDesc *Desc; // Variable Descriptor.
895 unsigned FrameIndex; // Variable frame index.
898 DebugVariable(VariableDesc *D, unsigned I)
904 VariableDesc *getDesc() const { return Desc; }
905 unsigned getFrameIndex() const { return FrameIndex; }
908 //===----------------------------------------------------------------------===//
909 /// DebugScope - This class is used to track scope information.
913 DebugScope *Parent; // Parent to this scope.
914 DebugInfoDesc *Desc; // Debug info descriptor for scope.
915 // Either subprogram or block.
916 unsigned StartLabelID; // Label ID of the beginning of scope.
917 unsigned EndLabelID; // Label ID of the end of scope.
918 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
919 std::vector<DebugVariable *> Variables;// Variables declared in scope.
922 DebugScope(DebugScope *P, DebugInfoDesc *D)
933 DebugScope *getParent() const { return Parent; }
934 DebugInfoDesc *getDesc() const { return Desc; }
935 unsigned getStartLabelID() const { return StartLabelID; }
936 unsigned getEndLabelID() const { return EndLabelID; }
937 std::vector<DebugScope *> &getScopes() { return Scopes; }
938 std::vector<DebugVariable *> &getVariables() { return Variables; }
939 void setStartLabelID(unsigned S) { StartLabelID = S; }
940 void setEndLabelID(unsigned E) { EndLabelID = E; }
942 /// AddScope - Add a scope to the scope.
944 void AddScope(DebugScope *S) { Scopes.push_back(S); }
946 /// AddVariable - Add a variable to the scope.
948 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
951 //===----------------------------------------------------------------------===//
952 /// MachineModuleInfo - This class contains meta information specific to a
953 /// module. Queries can be made by different debugging and exception handling
954 /// schemes and reformated for specific use.
956 class MachineModuleInfo : public ImmutablePass {
958 // Use the same deserializer/verifier for the module.
962 // CompileUnits - Uniquing vector for compile units.
963 UniqueVector<CompileUnitDesc *> CompileUnits;
965 // Directories - Uniquing vector for directories.
966 UniqueVector<std::string> Directories;
968 // SourceFiles - Uniquing vector for source files.
969 UniqueVector<SourceFileInfo> SourceFiles;
971 // Lines - List of of source line correspondence.
972 std::vector<SourceLineInfo> Lines;
974 // LabelIDList - One entry per assigned label. Normally the entry is equal to
975 // the list index(+1). If the entry is zero then the label has been deleted.
976 // Any other value indicates the label has been deleted by is mapped to
978 std::vector<unsigned> LabelIDList;
980 // ScopeMap - Tracks the scopes in the current function.
981 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
983 // RootScope - Top level scope for the current function.
985 DebugScope *RootScope;
987 // FrameMoves - List of moves done by a function's prolog. Used to construct
988 // frame maps by debug and exception handling consumers.
989 std::vector<MachineMove> FrameMoves;
993 ~MachineModuleInfo();
995 /// doInitialization - Initialize the state for a new module.
997 bool doInitialization();
999 /// doFinalization - Tear down the state after completion of a module.
1001 bool doFinalization();
1003 /// BeginFunction - Begin gathering function meta information.
1005 void BeginFunction(MachineFunction *MF);
1007 /// EndFunction - Discard function meta information.
1011 /// getDescFor - Convert a Value to a debug information descriptor.
1013 // FIXME - use new Value type when available.
1014 DebugInfoDesc *getDescFor(Value *V);
1016 /// Verify - Verify that a Value is debug information descriptor.
1018 bool Verify(Value *V);
1020 /// AnalyzeModule - Scan the module for global debug information.
1022 void AnalyzeModule(Module &M);
1024 /// hasDebugInfo - Returns true if valid debug info is present.
1026 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1028 /// NextLabelID - Return the next unique label id.
1030 unsigned NextLabelID() {
1031 unsigned ID = LabelIDList.size() + 1;
1032 LabelIDList.push_back(ID);
1036 /// RecordLabel - Records location information and associates it with a
1037 /// label. Returns a unique label ID used to generate a label and
1038 /// provide correspondence to the source line list.
1039 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1041 /// InvalidateLabel - Inhibit use of the specified label # from
1042 /// MachineModuleInfo, for example because the code was deleted.
1043 void InvalidateLabel(unsigned LabelID) {
1044 // Remap to zero to indicate deletion.
1045 RemapLabel(LabelID, 0);
1048 /// RemapLabel - Indicate that a label has been merged into another.
1050 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1051 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1052 "Old label ID out of range.");
1053 assert(NewLabelID <= LabelIDList.size() &&
1054 "New label ID out of range.");
1055 LabelIDList[OldLabelID - 1] = NewLabelID;
1058 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1059 /// ID != Mapped ID indicates that the label was folded into another label.
1060 unsigned MappedLabel(unsigned LabelID) const {
1061 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1062 return LabelID ? LabelIDList[LabelID - 1] : 0;
1065 /// RecordSource - Register a source file with debug info. Returns an source
1067 unsigned RecordSource(const std::string &Directory,
1068 const std::string &Source);
1069 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1071 /// getDirectories - Return the UniqueVector of std::string representing
1073 const UniqueVector<std::string> &getDirectories() const {
1077 /// getSourceFiles - Return the UniqueVector of source files.
1079 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1083 /// getSourceLines - Return a vector of source lines.
1085 const std::vector<SourceLineInfo> &getSourceLines() const {
1089 // FIXME: nuke this.
1090 void ClearLineInfo() {
1094 /// SetupCompileUnits - Set up the unique vector of compile units.
1096 void SetupCompileUnits(Module &M);
1098 /// getCompileUnits - Return a vector of debug compile units.
1100 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1102 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1103 /// named GlobalVariable.
1104 std::vector<GlobalVariable*>
1105 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1107 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1109 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1111 std::vector<GlobalVariable *> Globals =
1112 getGlobalVariablesUsing(M, Desc.getAnchorString());
1113 std::vector<T *> AnchoredDescs;
1114 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1115 GlobalVariable *GV = Globals[i];
1117 // FIXME - In the short term, changes are too drastic to continue.
1118 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1119 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1120 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1124 return AnchoredDescs;
1127 /// RecordRegionStart - Indicate the start of a region.
1129 unsigned RecordRegionStart(Value *V);
1131 /// RecordRegionEnd - Indicate the end of a region.
1133 unsigned RecordRegionEnd(Value *V);
1135 /// RecordVariable - Indicate the declaration of a local variable.
1137 void RecordVariable(Value *V, unsigned FrameIndex);
1139 /// getRootScope - Return current functions root scope.
1141 DebugScope *getRootScope() { return RootScope; }
1143 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1145 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1147 /// getFrameMoves - Returns a reference to a list of moves done in the current
1148 /// function's prologue. Used to construct frame maps for debug and exception
1149 /// handling comsumers.
1150 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1152 }; // End class MachineModuleInfo
1154 } // End llvm namespace