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 MachineBasicBlock;
48 class MachineFunction;
54 //===----------------------------------------------------------------------===//
55 // Debug info constants.
58 LLVMDebugVersion = (6 << 16), // Current version of debug information.
59 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
60 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
61 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
64 //===----------------------------------------------------------------------===//
65 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
66 /// the supplied DebugInfoDesc.
70 virtual ~DIVisitor() {}
72 /// ApplyToFields - Target the visitor to each field of the debug information
74 void ApplyToFields(DebugInfoDesc *DD);
76 /// Apply - Subclasses override each of these methods to perform the
77 /// appropriate action for the type of field.
78 virtual void Apply(int &Field) = 0;
79 virtual void Apply(unsigned &Field) = 0;
80 virtual void Apply(int64_t &Field) = 0;
81 virtual void Apply(uint64_t &Field) = 0;
82 virtual void Apply(bool &Field) = 0;
83 virtual void Apply(std::string &Field) = 0;
84 virtual void Apply(DebugInfoDesc *&Field) = 0;
85 virtual void Apply(GlobalVariable *&Field) = 0;
86 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
89 //===----------------------------------------------------------------------===//
90 /// DebugInfoDesc - This class is the base class for debug info descriptors.
94 unsigned Tag; // Content indicator. Dwarf values are
95 // used but that does not limit use to
99 DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
102 virtual ~DebugInfoDesc() {}
105 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
106 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
107 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
109 /// TagFromGlobal - Returns the tag number from a debug info descriptor
110 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
111 static unsigned TagFromGlobal(GlobalVariable *GV);
113 /// VersionFromGlobal - Returns the version number from a debug info
114 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
116 static unsigned VersionFromGlobal(GlobalVariable *GV);
118 /// DescFactory - Create an instance of debug info descriptor based on Tag.
119 /// Return NULL if not a recognized Tag.
120 static DebugInfoDesc *DescFactory(unsigned Tag);
122 /// getLinkage - get linkage appropriate for this type of descriptor.
124 virtual GlobalValue::LinkageTypes getLinkage() const;
126 //===--------------------------------------------------------------------===//
127 // Subclasses should supply the following static methods.
129 // Implement isa/cast/dyncast.
130 static bool classof(const DebugInfoDesc *) { return true; }
132 //===--------------------------------------------------------------------===//
133 // Subclasses should supply the following virtual methods.
135 /// ApplyToFields - Target the vistor to the fields of the descriptor.
137 virtual void ApplyToFields(DIVisitor *Visitor);
139 /// getDescString - Return a string used to compose global names and labels.
141 virtual const char *getDescString() const = 0;
143 /// getTypeString - Return a string used to label this descriptor's type.
145 virtual const char *getTypeString() const = 0;
148 virtual void dump() = 0;
152 //===----------------------------------------------------------------------===//
153 /// AnchorDesc - Descriptors of this class act as markers for identifying
154 /// descriptors of certain groups.
156 class AnchorDesc : public DebugInfoDesc {
158 unsigned AnchorTag; // Tag number of descriptors anchored
163 AnchorDesc(AnchoredDesc *D);
166 unsigned getAnchorTag() const { return AnchorTag; }
168 // Implement isa/cast/dyncast.
169 static bool classof(const AnchorDesc *) { return true; }
170 static bool classof(const DebugInfoDesc *D);
172 /// getLinkage - get linkage appropriate for this type of descriptor.
174 virtual GlobalValue::LinkageTypes getLinkage() const;
176 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
178 virtual void ApplyToFields(DIVisitor *Visitor);
180 /// getDescString - Return a string used to compose global names and labels.
182 virtual const char *getDescString() const;
184 /// getTypeString - Return a string used to label this descriptor's type.
186 virtual const char *getTypeString() const;
193 //===----------------------------------------------------------------------===//
194 /// AnchoredDesc - This class manages anchors for a variety of top level
196 class AnchoredDesc : public DebugInfoDesc {
198 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
203 AnchoredDesc(unsigned T);
207 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
208 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
210 //===--------------------------------------------------------------------===//
211 // Subclasses should supply the following virtual methods.
213 /// getAnchorString - Return a string used to label descriptor's anchor.
215 virtual const char *getAnchorString() const = 0;
217 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
219 virtual void ApplyToFields(DIVisitor *Visitor);
222 //===----------------------------------------------------------------------===//
223 /// CompileUnitDesc - This class packages debug information associated with a
224 /// source/header file.
225 class CompileUnitDesc : public AnchoredDesc {
227 unsigned Language; // Language number (ex. DW_LANG_C89.)
228 std::string FileName; // Source file name.
229 std::string Directory; // Source file directory.
230 std::string Producer; // Compiler string.
237 unsigned getLanguage() const { return Language; }
238 const std::string &getFileName() const { return FileName; }
239 const std::string &getDirectory() const { return Directory; }
240 const std::string &getProducer() const { return Producer; }
241 void setLanguage(unsigned L) { Language = L; }
242 void setFileName(const std::string &FN) { FileName = FN; }
243 void setDirectory(const std::string &D) { Directory = D; }
244 void setProducer(const std::string &P) { Producer = P; }
246 // FIXME - Need translation unit getter/setter.
248 // Implement isa/cast/dyncast.
249 static bool classof(const CompileUnitDesc *) { return true; }
250 static bool classof(const DebugInfoDesc *D);
252 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
254 virtual void ApplyToFields(DIVisitor *Visitor);
256 /// getDescString - Return a string used to compose global names and labels.
258 virtual const char *getDescString() const;
260 /// getTypeString - Return a string used to label this descriptor's type.
262 virtual const char *getTypeString() const;
264 /// getAnchorString - Return a string used to label this descriptor's anchor.
266 static const char *AnchorString;
267 virtual const char *getAnchorString() const;
274 //===----------------------------------------------------------------------===//
275 /// TypeDesc - This class packages debug information associated with a type.
277 class TypeDesc : public DebugInfoDesc {
280 FlagPrivate = 1 << 0,
281 FlagProtected = 1 << 1
283 DebugInfoDesc *Context; // Context debug descriptor.
284 std::string Name; // Type name (may be empty.)
285 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
286 unsigned Line; // Defined line# (may be zero.)
287 uint64_t Size; // Type bit size (may be zero.)
288 uint64_t Align; // Type bit alignment (may be zero.)
289 uint64_t Offset; // Type bit offset (may be zero.)
290 unsigned Flags; // Miscellaneous flags.
293 TypeDesc(unsigned T);
296 DebugInfoDesc *getContext() const { return Context; }
297 const std::string &getName() const { return Name; }
298 CompileUnitDesc *getFile() const {
299 return static_cast<CompileUnitDesc *>(File);
301 unsigned getLine() const { return Line; }
302 uint64_t getSize() const { return Size; }
303 uint64_t getAlign() const { return Align; }
304 uint64_t getOffset() const { return Offset; }
305 bool isPrivate() const {
306 return (Flags & FlagPrivate) != 0;
308 bool isProtected() const {
309 return (Flags & FlagProtected) != 0;
311 void setContext(DebugInfoDesc *C) { Context = C; }
312 void setName(const std::string &N) { Name = N; }
313 void setFile(CompileUnitDesc *U) {
314 File = static_cast<DebugInfoDesc *>(U);
316 void setLine(unsigned L) { Line = L; }
317 void setSize(uint64_t S) { Size = S; }
318 void setAlign(uint64_t A) { Align = A; }
319 void setOffset(uint64_t O) { Offset = O; }
320 void setIsPrivate() { Flags |= FlagPrivate; }
321 void setIsProtected() { Flags |= FlagProtected; }
323 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
325 virtual void ApplyToFields(DIVisitor *Visitor);
327 /// getDescString - Return a string used to compose global names and labels.
329 virtual const char *getDescString() const;
331 /// getTypeString - Return a string used to label this descriptor's type.
333 virtual const char *getTypeString() const;
340 //===----------------------------------------------------------------------===//
341 /// BasicTypeDesc - This class packages debug information associated with a
342 /// basic type (eg. int, bool, double.)
343 class BasicTypeDesc : public TypeDesc {
345 unsigned Encoding; // Type encoding.
351 unsigned getEncoding() const { return Encoding; }
352 void setEncoding(unsigned E) { Encoding = E; }
354 // Implement isa/cast/dyncast.
355 static bool classof(const BasicTypeDesc *) { return true; }
356 static bool classof(const DebugInfoDesc *D);
358 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
360 virtual void ApplyToFields(DIVisitor *Visitor);
362 /// getDescString - Return a string used to compose global names and labels.
364 virtual const char *getDescString() const;
366 /// getTypeString - Return a string used to label this descriptor's type.
368 virtual const char *getTypeString() const;
376 //===----------------------------------------------------------------------===//
377 /// DerivedTypeDesc - This class packages debug information associated with a
378 /// derived types (eg., typedef, pointer, reference.)
379 class DerivedTypeDesc : public TypeDesc {
381 DebugInfoDesc *FromType; // Type derived from.
384 DerivedTypeDesc(unsigned T);
387 TypeDesc *getFromType() const {
388 return static_cast<TypeDesc *>(FromType);
390 void setFromType(TypeDesc *F) {
391 FromType = static_cast<DebugInfoDesc *>(F);
394 // Implement isa/cast/dyncast.
395 static bool classof(const DerivedTypeDesc *) { return true; }
396 static bool classof(const DebugInfoDesc *D);
398 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
400 virtual void ApplyToFields(DIVisitor *Visitor);
402 /// getDescString - Return a string used to compose global names and labels.
404 virtual const char *getDescString() const;
406 /// getTypeString - Return a string used to label this descriptor's type.
408 virtual const char *getTypeString() const;
415 //===----------------------------------------------------------------------===//
416 /// CompositeTypeDesc - This class packages debug information associated with a
417 /// array/struct types (eg., arrays, struct, union, enums.)
418 class CompositeTypeDesc : public DerivedTypeDesc {
420 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
423 CompositeTypeDesc(unsigned T);
426 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
428 // Implement isa/cast/dyncast.
429 static bool classof(const CompositeTypeDesc *) { return true; }
430 static bool classof(const DebugInfoDesc *D);
432 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
434 virtual void ApplyToFields(DIVisitor *Visitor);
436 /// getDescString - Return a string used to compose global names and labels.
438 virtual const char *getDescString() const;
440 /// getTypeString - Return a string used to label this descriptor's type.
442 virtual const char *getTypeString() const;
449 //===----------------------------------------------------------------------===//
450 /// SubrangeDesc - This class packages debug information associated with integer
452 class SubrangeDesc : public DebugInfoDesc {
454 int64_t Lo; // Low value of range.
455 int64_t Hi; // High value of range.
461 int64_t getLo() const { return Lo; }
462 int64_t getHi() const { return Hi; }
463 void setLo(int64_t L) { Lo = L; }
464 void setHi(int64_t H) { Hi = H; }
466 // Implement isa/cast/dyncast.
467 static bool classof(const SubrangeDesc *) { return true; }
468 static bool classof(const DebugInfoDesc *D);
470 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
472 virtual void ApplyToFields(DIVisitor *Visitor);
474 /// getDescString - Return a string used to compose global names and labels.
476 virtual const char *getDescString() const;
478 /// getTypeString - Return a string used to label this descriptor's type.
480 virtual const char *getTypeString() const;
487 //===----------------------------------------------------------------------===//
488 /// EnumeratorDesc - This class packages debug information associated with
489 /// named integer constants.
490 class EnumeratorDesc : public DebugInfoDesc {
492 std::string Name; // Enumerator name.
493 int64_t Value; // Enumerator value.
499 const std::string &getName() const { return Name; }
500 int64_t getValue() const { return Value; }
501 void setName(const std::string &N) { Name = N; }
502 void setValue(int64_t V) { Value = V; }
504 // Implement isa/cast/dyncast.
505 static bool classof(const EnumeratorDesc *) { return true; }
506 static bool classof(const DebugInfoDesc *D);
508 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
510 virtual void ApplyToFields(DIVisitor *Visitor);
512 /// getDescString - Return a string used to compose global names and labels.
514 virtual const char *getDescString() const;
516 /// getTypeString - Return a string used to label this descriptor's type.
518 virtual const char *getTypeString() const;
525 //===----------------------------------------------------------------------===//
526 /// VariableDesc - This class packages debug information associated with a
527 /// subprogram variable.
529 class VariableDesc : public DebugInfoDesc {
531 DebugInfoDesc *Context; // Context debug descriptor.
532 std::string Name; // Type name (may be empty.)
533 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
534 unsigned Line; // Defined line# (may be zero.)
535 DebugInfoDesc *TyDesc; // Type of variable.
538 VariableDesc(unsigned T);
541 DebugInfoDesc *getContext() const { return Context; }
542 const std::string &getName() const { return Name; }
543 CompileUnitDesc *getFile() const {
544 return static_cast<CompileUnitDesc *>(File);
546 unsigned getLine() const { return Line; }
547 TypeDesc *getType() const {
548 return static_cast<TypeDesc *>(TyDesc);
550 void setContext(DebugInfoDesc *C) { Context = C; }
551 void setName(const std::string &N) { Name = N; }
552 void setFile(CompileUnitDesc *U) {
553 File = static_cast<DebugInfoDesc *>(U);
555 void setLine(unsigned L) { Line = L; }
556 void setType(TypeDesc *T) {
557 TyDesc = static_cast<DebugInfoDesc *>(T);
560 // Implement isa/cast/dyncast.
561 static bool classof(const VariableDesc *) { return true; }
562 static bool classof(const DebugInfoDesc *D);
564 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
566 virtual void ApplyToFields(DIVisitor *Visitor);
568 /// getDescString - Return a string used to compose global names and labels.
570 virtual const char *getDescString() const;
572 /// getTypeString - Return a string used to label this descriptor's type.
574 virtual const char *getTypeString() const;
581 //===----------------------------------------------------------------------===//
582 /// GlobalDesc - This class is the base descriptor for global functions and
584 class GlobalDesc : public AnchoredDesc {
586 DebugInfoDesc *Context; // Context debug descriptor.
587 std::string Name; // Global name.
588 std::string FullName; // Fully qualified name.
589 std::string LinkageName; // Name for binding to MIPS linkage.
590 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
591 unsigned Line; // Defined line# (may be zero.)
592 DebugInfoDesc *TyDesc; // Type debug descriptor.
593 bool IsStatic; // Is the global a static.
594 bool IsDefinition; // Is the global defined in context.
597 GlobalDesc(unsigned T);
601 DebugInfoDesc *getContext() const { return Context; }
602 const std::string &getName() const { return Name; }
603 const std::string &getFullName() const { return FullName; }
604 const std::string &getLinkageName() const { return LinkageName; }
605 CompileUnitDesc *getFile() const {
606 return static_cast<CompileUnitDesc *>(File);
608 unsigned getLine() const { return Line; }
609 TypeDesc *getType() const {
610 return static_cast<TypeDesc *>(TyDesc);
612 bool isStatic() const { return IsStatic; }
613 bool isDefinition() const { return IsDefinition; }
614 void setContext(DebugInfoDesc *C) { Context = C; }
615 void setName(const std::string &N) { Name = N; }
616 void setFullName(const std::string &N) { FullName = N; }
617 void setLinkageName(const std::string &N) { LinkageName = N; }
618 void setFile(CompileUnitDesc *U) {
619 File = static_cast<DebugInfoDesc *>(U);
621 void setLine(unsigned L) { Line = L; }
622 void setType(TypeDesc *T) {
623 TyDesc = static_cast<DebugInfoDesc *>(T);
625 void setIsStatic(bool IS) { IsStatic = IS; }
626 void setIsDefinition(bool ID) { IsDefinition = ID; }
628 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
630 virtual void ApplyToFields(DIVisitor *Visitor);
633 //===----------------------------------------------------------------------===//
634 /// GlobalVariableDesc - This class packages debug information associated with a
636 class GlobalVariableDesc : public GlobalDesc {
638 GlobalVariable *Global; // llvm global.
641 GlobalVariableDesc();
644 GlobalVariable *getGlobalVariable() const { return Global; }
645 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
647 // Implement isa/cast/dyncast.
648 static bool classof(const GlobalVariableDesc *) { return true; }
649 static bool classof(const DebugInfoDesc *D);
651 /// ApplyToFields - Target the visitor to the fields of the
652 /// GlobalVariableDesc.
653 virtual void ApplyToFields(DIVisitor *Visitor);
655 /// getDescString - Return a string used to compose global names and labels.
657 virtual const char *getDescString() const;
659 /// getTypeString - Return a string used to label this descriptor's type.
661 virtual const char *getTypeString() const;
663 /// getAnchorString - Return a string used to label this descriptor's anchor.
665 static const char *AnchorString;
666 virtual const char *getAnchorString() const;
673 //===----------------------------------------------------------------------===//
674 /// SubprogramDesc - This class packages debug information associated with a
675 /// subprogram/function.
676 class SubprogramDesc : public GlobalDesc {
684 // Implement isa/cast/dyncast.
685 static bool classof(const SubprogramDesc *) { return true; }
686 static bool classof(const DebugInfoDesc *D);
688 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
690 virtual void ApplyToFields(DIVisitor *Visitor);
692 /// getDescString - Return a string used to compose global names and labels.
694 virtual const char *getDescString() const;
696 /// getTypeString - Return a string used to label this descriptor's type.
698 virtual const char *getTypeString() const;
700 /// getAnchorString - Return a string used to label this descriptor's anchor.
702 static const char *AnchorString;
703 virtual const char *getAnchorString() const;
710 //===----------------------------------------------------------------------===//
711 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
713 class BlockDesc : public DebugInfoDesc {
715 DebugInfoDesc *Context; // Context debug descriptor.
721 DebugInfoDesc *getContext() const { return Context; }
722 void setContext(DebugInfoDesc *C) { Context = C; }
724 // Implement isa/cast/dyncast.
725 static bool classof(const BlockDesc *) { return true; }
726 static bool classof(const DebugInfoDesc *D);
728 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
730 virtual void ApplyToFields(DIVisitor *Visitor);
732 /// getDescString - Return a string used to compose global names and labels.
734 virtual const char *getDescString() const;
736 /// getTypeString - Return a string used to label this descriptor's type.
738 virtual const char *getTypeString() const;
745 //===----------------------------------------------------------------------===//
746 /// DIDeserializer - This class is responsible for casting GlobalVariables
747 /// into DebugInfoDesc objects.
748 class DIDeserializer {
750 std::map<GlobalVariable *, DebugInfoDesc *> GlobalDescs;
751 // Previously defined gloabls.
757 /// Deserialize - Reconstitute a GlobalVariable into it's component
758 /// DebugInfoDesc objects.
759 DebugInfoDesc *Deserialize(Value *V);
760 DebugInfoDesc *Deserialize(GlobalVariable *GV);
763 //===----------------------------------------------------------------------===//
764 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
765 /// into GlobalVariables.
768 Module *M; // Definition space module.
769 PointerType *StrPtrTy; // A "sbyte *" type. Created lazily.
770 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
771 std::map<unsigned, StructType *> TagTypes;
772 // Types per Tag. Created lazily.
773 std::map<DebugInfoDesc *, GlobalVariable *> DescGlobals;
774 // Previously defined descriptors.
775 std::map<const std::string, Constant *> StringCache;
776 // Previously defined strings.
782 , EmptyStructPtrTy(NULL)
790 Module *getModule() const { return M; };
791 void setModule(Module *module) { M = module; }
793 /// getStrPtrType - Return a "sbyte *" type.
795 const PointerType *getStrPtrType();
797 /// getEmptyStructPtrType - Return a "{ }*" type.
799 const PointerType *getEmptyStructPtrType();
801 /// getTagType - Return the type describing the specified descriptor (via
803 const StructType *getTagType(DebugInfoDesc *DD);
805 /// getString - Construct the string as constant string global.
807 Constant *getString(const std::string &String);
809 /// Serialize - Recursively cast the specified descriptor into a
810 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
811 GlobalVariable *Serialize(DebugInfoDesc *DD);
814 //===----------------------------------------------------------------------===//
815 /// DIVerifier - This class is responsible for verifying the given network of
816 /// GlobalVariables are valid as DebugInfoDesc objects.
824 std::map<GlobalVariable *, unsigned> Validity;// Tracks prior results.
825 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
834 /// Verify - Return true if the GlobalVariable appears to be a valid
835 /// serialization of a DebugInfoDesc.
836 bool Verify(Value *V);
837 bool Verify(GlobalVariable *GV);
840 //===----------------------------------------------------------------------===//
841 /// SourceLineInfo - This class is used to record source line correspondence.
843 class SourceLineInfo {
845 unsigned Line; // Source line number.
846 unsigned Column; // Source column.
847 unsigned SourceID; // Source ID number.
848 unsigned LabelID; // Label in code ID number.
851 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
852 : Line(L), Column(C), SourceID(S), LabelID(I) {}
855 unsigned getLine() const { return Line; }
856 unsigned getColumn() const { return Column; }
857 unsigned getSourceID() const { return SourceID; }
858 unsigned getLabelID() const { return LabelID; }
861 //===----------------------------------------------------------------------===//
862 /// SourceFileInfo - This class is used to track source information.
864 class SourceFileInfo {
866 unsigned DirectoryID; // Directory ID number.
867 std::string Name; // File name (not including directory.)
870 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
873 unsigned getDirectoryID() const { return DirectoryID; }
874 const std::string &getName() const { return Name; }
876 /// operator== - Used by UniqueVector to locate entry.
878 bool operator==(const SourceFileInfo &SI) const {
879 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
882 /// operator< - Used by UniqueVector to locate entry.
884 bool operator<(const SourceFileInfo &SI) const {
885 return getDirectoryID() < SI.getDirectoryID() ||
886 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
890 //===----------------------------------------------------------------------===//
891 /// DebugVariable - This class is used to track local variable information.
893 class DebugVariable {
895 VariableDesc *Desc; // Variable Descriptor.
896 unsigned FrameIndex; // Variable frame index.
899 DebugVariable(VariableDesc *D, unsigned I)
905 VariableDesc *getDesc() const { return Desc; }
906 unsigned getFrameIndex() const { return FrameIndex; }
909 //===----------------------------------------------------------------------===//
910 /// DebugScope - This class is used to track scope information.
914 DebugScope *Parent; // Parent to this scope.
915 DebugInfoDesc *Desc; // Debug info descriptor for scope.
916 // Either subprogram or block.
917 unsigned StartLabelID; // Label ID of the beginning of scope.
918 unsigned EndLabelID; // Label ID of the end of scope.
919 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
920 std::vector<DebugVariable *> Variables;// Variables declared in scope.
923 DebugScope(DebugScope *P, DebugInfoDesc *D)
934 DebugScope *getParent() const { return Parent; }
935 DebugInfoDesc *getDesc() const { return Desc; }
936 unsigned getStartLabelID() const { return StartLabelID; }
937 unsigned getEndLabelID() const { return EndLabelID; }
938 std::vector<DebugScope *> &getScopes() { return Scopes; }
939 std::vector<DebugVariable *> &getVariables() { return Variables; }
940 void setStartLabelID(unsigned S) { StartLabelID = S; }
941 void setEndLabelID(unsigned E) { EndLabelID = E; }
943 /// AddScope - Add a scope to the scope.
945 void AddScope(DebugScope *S) { Scopes.push_back(S); }
947 /// AddVariable - Add a variable to the scope.
949 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
952 //===----------------------------------------------------------------------===//
953 /// LandingPadInfo - This structure is used to retain landing pad info for
954 /// the current function.
956 struct LandingPadInfo {
957 MachineBasicBlock *LandingPadBlock; // Landing pad block.
958 unsigned BeginLabel; // Label prior to invoke.
959 unsigned EndLabel; // Label after invoke.
960 unsigned LandingPadLabel; // Label at beginning of landing pad.
961 Function *Personality; // Personality function.
962 std::vector<unsigned> TypeIds; // List of type ids.
964 LandingPadInfo(MachineBasicBlock *MBB)
965 : LandingPadBlock(MBB)
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;
1022 MachineModuleInfo();
1023 ~MachineModuleInfo();
1025 /// doInitialization - Initialize the state for a new module.
1027 bool doInitialization();
1029 /// doFinalization - Tear down the state after completion of a module.
1031 bool doFinalization();
1033 /// BeginFunction - Begin gathering function meta information.
1035 void BeginFunction(MachineFunction *MF);
1037 /// EndFunction - Discard function meta information.
1041 /// getDescFor - Convert a Value to a debug information descriptor.
1043 // FIXME - use new Value type when available.
1044 DebugInfoDesc *getDescFor(Value *V);
1046 /// Verify - Verify that a Value is debug information descriptor.
1048 bool Verify(Value *V);
1050 /// AnalyzeModule - Scan the module for global debug information.
1052 void AnalyzeModule(Module &M);
1054 /// hasDebugInfo - Returns true if valid debug info is present.
1056 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1058 /// needsFrameInfo - Returns true if we need to gather callee-saved register
1059 /// move info for the frame.
1060 bool needsFrameInfo() const;
1062 /// NextLabelID - Return the next unique label id.
1064 unsigned NextLabelID() {
1065 unsigned ID = LabelIDList.size() + 1;
1066 LabelIDList.push_back(ID);
1070 /// RecordLabel - Records location information and associates it with a
1071 /// label. Returns a unique label ID used to generate a label and
1072 /// provide correspondence to the source line list.
1073 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1075 /// InvalidateLabel - Inhibit use of the specified label # from
1076 /// MachineModuleInfo, for example because the code was deleted.
1077 void InvalidateLabel(unsigned LabelID) {
1078 // Remap to zero to indicate deletion.
1079 RemapLabel(LabelID, 0);
1082 /// RemapLabel - Indicate that a label has been merged into another.
1084 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1085 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1086 "Old label ID out of range.");
1087 assert(NewLabelID <= LabelIDList.size() &&
1088 "New label ID out of range.");
1089 LabelIDList[OldLabelID - 1] = NewLabelID;
1092 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1093 /// ID != Mapped ID indicates that the label was folded into another label.
1094 unsigned MappedLabel(unsigned LabelID) const {
1095 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1096 return LabelID ? LabelIDList[LabelID - 1] : 0;
1099 /// RecordSource - Register a source file with debug info. Returns an source
1101 unsigned RecordSource(const std::string &Directory,
1102 const std::string &Source);
1103 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1105 /// getDirectories - Return the UniqueVector of std::string representing
1107 const UniqueVector<std::string> &getDirectories() const {
1111 /// getSourceFiles - Return the UniqueVector of source files.
1113 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1117 /// getSourceLines - Return a vector of source lines.
1119 const std::vector<SourceLineInfo> &getSourceLines() const {
1123 /// SetupCompileUnits - Set up the unique vector of compile units.
1125 void SetupCompileUnits(Module &M);
1127 /// getCompileUnits - Return a vector of debug compile units.
1129 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1131 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1132 /// named GlobalVariable.
1133 std::vector<GlobalVariable*>
1134 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1136 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1138 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1140 std::vector<GlobalVariable *> Globals =
1141 getGlobalVariablesUsing(M, Desc.getAnchorString());
1142 std::vector<T *> AnchoredDescs;
1143 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1144 GlobalVariable *GV = Globals[i];
1146 // FIXME - In the short term, changes are too drastic to continue.
1147 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1148 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1149 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1153 return AnchoredDescs;
1156 /// RecordRegionStart - Indicate the start of a region.
1158 unsigned RecordRegionStart(Value *V);
1160 /// RecordRegionEnd - Indicate the end of a region.
1162 unsigned RecordRegionEnd(Value *V);
1164 /// RecordVariable - Indicate the declaration of a local variable.
1166 void RecordVariable(Value *V, unsigned FrameIndex);
1168 /// getRootScope - Return current functions root scope.
1170 DebugScope *getRootScope() { return RootScope; }
1172 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1174 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1176 /// getFrameMoves - Returns a reference to a list of moves done in the current
1177 /// function's prologue. Used to construct frame maps for debug and exception
1178 /// handling comsumers.
1179 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1181 //===-EH-----------------------------------------------------------------===//
1183 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1184 /// specified MachineBasicBlock.
1185 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1187 /// addInvoke - Provide the begin and end labels of an invoke style call and
1188 /// associate it with a try landing pad block.
1189 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1192 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1193 /// landing pad entry.
1194 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1196 /// addPersonality - Provide the personality function for the exception
1198 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1200 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1202 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1203 std::vector<GlobalVariable *> &TyInfo);
1205 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1207 unsigned getTypeIDFor(GlobalVariable *TI);
1209 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1211 void TidyLandingPads();
1213 /// getLandingPadInfos - Return a reference to the landing pad info for the
1214 /// current function.
1215 const std::vector<LandingPadInfo> &getLandingPads() const {
1219 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1221 const std::vector<GlobalVariable *> &getTypeInfos() const {
1225 /// getPersonality - Return a personality function if available. The presence
1226 /// of one is required to emit exception handling info.
1227 Function *getPersonality() const;
1229 }; // End class MachineModuleInfo
1231 } // End llvm namespace