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