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/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 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 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 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 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 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 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 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 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 /// Deserialize - Reconstitute a GlobalVariable into it's component
759 /// DebugInfoDesc objects.
760 DebugInfoDesc *Deserialize(Value *V);
761 DebugInfoDesc *Deserialize(GlobalVariable *GV);
764 //===----------------------------------------------------------------------===//
765 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
766 /// into GlobalVariables.
769 Module *M; // Definition space module.
770 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
771 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
772 std::map<unsigned, StructType *> TagTypes;
773 // Types per Tag. Created lazily.
774 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
775 // Previously defined descriptors.
776 std::map<const std::string, Constant *> StringCache;
777 // Previously defined strings.
783 , EmptyStructPtrTy(NULL)
791 Module *getModule() const { return M; };
792 void setModule(Module *module) { M = module; }
794 /// getStrPtrType - Return a "sbyte *" type.
796 const PointerType *getStrPtrType();
798 /// getEmptyStructPtrType - Return a "{ }*" type.
800 const PointerType *getEmptyStructPtrType();
802 /// getTagType - Return the type describing the specified descriptor (via
804 const StructType *getTagType(DebugInfoDesc *DD);
806 /// getString - Construct the string as constant string global.
808 Constant *getString(const std::string &String);
810 /// Serialize - Recursively cast the specified descriptor into a
811 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
812 GlobalVariable *Serialize(DebugInfoDesc *DD);
815 //===----------------------------------------------------------------------===//
816 /// DIVerifier - This class is responsible for verifying the given network of
817 /// GlobalVariables are valid as DebugInfoDesc objects.
825 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
826 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
835 /// Verify - Return true if the GlobalVariable appears to be a valid
836 /// serialization of a DebugInfoDesc.
837 bool Verify(Value *V);
838 bool Verify(GlobalVariable *GV);
841 //===----------------------------------------------------------------------===//
842 /// SourceLineInfo - This class is used to record source line correspondence.
844 class SourceLineInfo {
846 unsigned Line; // Source line number.
847 unsigned Column; // Source column.
848 unsigned SourceID; // Source ID number.
849 unsigned LabelID; // Label in code ID number.
852 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
853 : Line(L), Column(C), SourceID(S), LabelID(I) {}
856 unsigned getLine() const { return Line; }
857 unsigned getColumn() const { return Column; }
858 unsigned getSourceID() const { return SourceID; }
859 unsigned getLabelID() const { return LabelID; }
862 //===----------------------------------------------------------------------===//
863 /// SourceFileInfo - This class is used to track source information.
865 class SourceFileInfo {
867 unsigned DirectoryID; // Directory ID number.
868 std::string Name; // File name (not including directory.)
871 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
874 unsigned getDirectoryID() const { return DirectoryID; }
875 const std::string &getName() const { return Name; }
877 /// operator== - Used by UniqueVector to locate entry.
879 bool operator==(const SourceFileInfo &SI) const {
880 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
883 /// operator< - Used by UniqueVector to locate entry.
885 bool operator<(const SourceFileInfo &SI) const {
886 return getDirectoryID() < SI.getDirectoryID() ||
887 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
891 //===----------------------------------------------------------------------===//
892 /// DebugVariable - This class is used to track local variable information.
894 class DebugVariable {
896 VariableDesc *Desc; // Variable Descriptor.
897 unsigned FrameIndex; // Variable frame index.
900 DebugVariable(VariableDesc *D, unsigned I)
906 VariableDesc *getDesc() const { return Desc; }
907 unsigned getFrameIndex() const { return FrameIndex; }
910 //===----------------------------------------------------------------------===//
911 /// DebugScope - This class is used to track scope information.
915 DebugScope *Parent; // Parent to this scope.
916 DebugInfoDesc *Desc; // Debug info descriptor for scope.
917 // Either subprogram or block.
918 unsigned StartLabelID; // Label ID of the beginning of scope.
919 unsigned EndLabelID; // Label ID of the end of scope.
920 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
921 std::vector<DebugVariable *> Variables;// Variables declared in scope.
924 DebugScope(DebugScope *P, DebugInfoDesc *D)
935 DebugScope *getParent() const { return Parent; }
936 DebugInfoDesc *getDesc() const { return Desc; }
937 unsigned getStartLabelID() const { return StartLabelID; }
938 unsigned getEndLabelID() const { return EndLabelID; }
939 std::vector<DebugScope *> &getScopes() { return Scopes; }
940 std::vector<DebugVariable *> &getVariables() { return Variables; }
941 void setStartLabelID(unsigned S) { StartLabelID = S; }
942 void setEndLabelID(unsigned E) { EndLabelID = E; }
944 /// AddScope - Add a scope to the scope.
946 void AddScope(DebugScope *S) { Scopes.push_back(S); }
948 /// AddVariable - Add a variable to the scope.
950 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
953 //===----------------------------------------------------------------------===//
954 /// LandingPadInfo - This structure is used to retain landing pad info for
955 /// the current function.
957 struct LandingPadInfo {
958 MachineBasicBlock *LandingPadBlock; // Landing pad block.
959 SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
960 SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
961 unsigned LandingPadLabel; // Label at beginning of landing pad.
962 Function *Personality; // Personality function.
963 std::vector<int> TypeIds; // List of type ids (filters negative)
965 LandingPadInfo(MachineBasicBlock *MBB)
966 : LandingPadBlock(MBB)
969 , TypeIds(1, 0) // Always have cleanups
973 //===----------------------------------------------------------------------===//
974 /// MachineModuleInfo - This class contains meta information specific to a
975 /// module. Queries can be made by different debugging and exception handling
976 /// schemes and reformated for specific use.
978 class MachineModuleInfo : public ImmutablePass {
980 // Use the same deserializer/verifier for the module.
984 // CompileUnits - Uniquing vector for compile units.
985 UniqueVector<CompileUnitDesc *> CompileUnits;
987 // Directories - Uniquing vector for directories.
988 UniqueVector<std::string> Directories;
990 // SourceFiles - Uniquing vector for source files.
991 UniqueVector<SourceFileInfo> SourceFiles;
993 // Lines - List of of source line correspondence.
994 std::vector<SourceLineInfo> Lines;
996 // LabelIDList - One entry per assigned label. Normally the entry is equal to
997 // the list index(+1). If the entry is zero then the label has been deleted.
998 // Any other value indicates the label has been deleted by is mapped to
1000 std::vector<unsigned> LabelIDList;
1002 // ScopeMap - Tracks the scopes in the current function.
1003 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
1005 // RootScope - Top level scope for the current function.
1007 DebugScope *RootScope;
1009 // FrameMoves - List of moves done by a function's prolog. Used to construct
1010 // frame maps by debug and exception handling consumers.
1011 std::vector<MachineMove> FrameMoves;
1013 // LandingPads - List of LandingPadInfo describing the landing pad information
1014 // in the current function.
1015 std::vector<LandingPadInfo> LandingPads;
1017 // TypeInfos - List of C++ TypeInfo used in the current function.
1019 std::vector<GlobalVariable *> TypeInfos;
1021 // FilterIds - List of typeids encoding filters used in the current function.
1023 std::vector<unsigned> FilterIds;
1025 // Personalities - Vector of all personality functions ever seen. Used to emit
1026 // common EH frames.
1027 std::vector<Function *> Personalities;
1029 static char ID; // Pass identification, replacement for typeid
1031 MachineModuleInfo();
1032 ~MachineModuleInfo();
1034 /// doInitialization - Initialize the state for a new module.
1036 bool doInitialization();
1038 /// doFinalization - Tear down the state after completion of a module.
1040 bool doFinalization();
1042 /// BeginFunction - Begin gathering function meta information.
1044 void BeginFunction(MachineFunction *MF);
1046 /// EndFunction - Discard function meta information.
1050 /// getDescFor - Convert a Value to a debug information descriptor.
1052 // FIXME - use new Value type when available.
1053 DebugInfoDesc *getDescFor(Value *V);
1055 /// Verify - Verify that a Value is debug information descriptor.
1057 bool Verify(Value *V);
1059 /// AnalyzeModule - Scan the module for global debug information.
1061 void AnalyzeModule(Module &M);
1063 /// hasDebugInfo - Returns true if valid debug info is present.
1065 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1067 /// needsFrameInfo - Returns true if we need to gather callee-saved register
1068 /// move info for the frame.
1069 bool needsFrameInfo() const;
1071 /// NextLabelID - Return the next unique label id.
1073 unsigned NextLabelID() {
1074 unsigned ID = LabelIDList.size() + 1;
1075 LabelIDList.push_back(ID);
1079 /// RecordLabel - Records location information and associates it with a
1080 /// label. Returns a unique label ID used to generate a label and
1081 /// provide correspondence to the source line list.
1082 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1084 /// InvalidateLabel - Inhibit use of the specified label # from
1085 /// MachineModuleInfo, for example because the code was deleted.
1086 void InvalidateLabel(unsigned LabelID) {
1087 // Remap to zero to indicate deletion.
1088 RemapLabel(LabelID, 0);
1091 /// RemapLabel - Indicate that a label has been merged into another.
1093 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1094 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1095 "Old label ID out of range.");
1096 assert(NewLabelID <= LabelIDList.size() &&
1097 "New label ID out of range.");
1098 LabelIDList[OldLabelID - 1] = NewLabelID;
1101 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1102 /// ID != Mapped ID indicates that the label was folded into another label.
1103 unsigned MappedLabel(unsigned LabelID) const {
1104 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1105 return LabelID ? LabelIDList[LabelID - 1] : 0;
1108 /// RecordSource - Register a source file with debug info. Returns an source
1110 unsigned RecordSource(const std::string &Directory,
1111 const std::string &Source);
1112 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1114 /// getDirectories - Return the UniqueVector of std::string representing
1116 const UniqueVector<std::string> &getDirectories() const {
1120 /// getSourceFiles - Return the UniqueVector of source files.
1122 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1126 /// getSourceLines - Return a vector of source lines.
1128 const std::vector<SourceLineInfo> &getSourceLines() const {
1132 /// SetupCompileUnits - Set up the unique vector of compile units.
1134 void SetupCompileUnits(Module &M);
1136 /// getCompileUnits - Return a vector of debug compile units.
1138 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1140 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1141 /// named GlobalVariable.
1142 std::vector<GlobalVariable*>
1143 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1145 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1147 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1149 std::vector<GlobalVariable *> Globals =
1150 getGlobalVariablesUsing(M, Desc.getAnchorString());
1151 std::vector<T *> AnchoredDescs;
1152 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1153 GlobalVariable *GV = Globals[i];
1155 // FIXME - In the short term, changes are too drastic to continue.
1156 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1157 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1158 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1162 return AnchoredDescs;
1165 /// RecordRegionStart - Indicate the start of a region.
1167 unsigned RecordRegionStart(Value *V);
1169 /// RecordRegionEnd - Indicate the end of a region.
1171 unsigned RecordRegionEnd(Value *V);
1173 /// RecordVariable - Indicate the declaration of a local variable.
1175 void RecordVariable(Value *V, unsigned FrameIndex);
1177 /// getRootScope - Return current functions root scope.
1179 DebugScope *getRootScope() { return RootScope; }
1181 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1183 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1185 /// getFrameMoves - Returns a reference to a list of moves done in the current
1186 /// function's prologue. Used to construct frame maps for debug and exception
1187 /// handling comsumers.
1188 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1190 //===-EH-----------------------------------------------------------------===//
1192 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1193 /// specified MachineBasicBlock.
1194 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1196 /// addInvoke - Provide the begin and end labels of an invoke style call and
1197 /// associate it with a try landing pad block.
1198 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1201 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1202 /// landing pad entry.
1203 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1205 /// addPersonality - Provide the personality function for the exception
1207 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1209 /// getPersonalityIndex - Get index of the current personality function inside
1210 /// Personalitites array
1211 unsigned getPersonalityIndex() const;
1213 /// getPersonalities - Return array of personality functions ever seen.
1214 const std::vector<Function *>& getPersonalities() const {
1215 return Personalities;
1218 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1220 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1221 std::vector<GlobalVariable *> &TyInfo);
1223 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
1225 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
1226 std::vector<GlobalVariable *> &TyInfo);
1228 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1230 unsigned getTypeIDFor(GlobalVariable *TI);
1232 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
1234 int getFilterIDFor(std::vector<unsigned> &TyIds);
1236 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1238 void TidyLandingPads();
1240 /// getLandingPads - Return a reference to the landing pad info for the
1241 /// current function.
1242 const std::vector<LandingPadInfo> &getLandingPads() const {
1246 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1248 const std::vector<GlobalVariable *> &getTypeInfos() const {
1252 /// getFilterIds - Return a reference to the typeids encoding filters used in
1253 /// the current function.
1254 const std::vector<unsigned> &getFilterIds() const {
1258 /// getPersonality - Return a personality function if available. The presence
1259 /// of one is required to emit exception handling info.
1260 Function *getPersonality() const;
1262 }; // End class MachineModuleInfo
1264 } // End llvm namespace