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.
963 bool IsFilter; // Indicate if the landing pad is a
966 LandingPadInfo(MachineBasicBlock *MBB)
967 : LandingPadBlock(MBB)
976 //===----------------------------------------------------------------------===//
977 /// MachineModuleInfo - This class contains meta information specific to a
978 /// module. Queries can be made by different debugging and exception handling
979 /// schemes and reformated for specific use.
981 class MachineModuleInfo : public ImmutablePass {
983 // Use the same deserializer/verifier for the module.
987 // CompileUnits - Uniquing vector for compile units.
988 UniqueVector<CompileUnitDesc *> CompileUnits;
990 // Directories - Uniquing vector for directories.
991 UniqueVector<std::string> Directories;
993 // SourceFiles - Uniquing vector for source files.
994 UniqueVector<SourceFileInfo> SourceFiles;
996 // Lines - List of of source line correspondence.
997 std::vector<SourceLineInfo> Lines;
999 // LabelIDList - One entry per assigned label. Normally the entry is equal to
1000 // the list index(+1). If the entry is zero then the label has been deleted.
1001 // Any other value indicates the label has been deleted by is mapped to
1003 std::vector<unsigned> LabelIDList;
1005 // ScopeMap - Tracks the scopes in the current function.
1006 std::map<DebugInfoDesc *, DebugScope *> ScopeMap;
1008 // RootScope - Top level scope for the current function.
1010 DebugScope *RootScope;
1012 // FrameMoves - List of moves done by a function's prolog. Used to construct
1013 // frame maps by debug and exception handling consumers.
1014 std::vector<MachineMove> FrameMoves;
1016 // LandingPads - List of LandingPadInfo describing the landing pad information
1017 // in the current function.
1018 std::vector<LandingPadInfo> LandingPads;
1020 // TypeInfos - List of C++ TypeInfo used in the current function.
1022 std::vector<GlobalVariable *> TypeInfos;
1025 MachineModuleInfo();
1026 ~MachineModuleInfo();
1028 /// doInitialization - Initialize the state for a new module.
1030 bool doInitialization();
1032 /// doFinalization - Tear down the state after completion of a module.
1034 bool doFinalization();
1036 /// BeginFunction - Begin gathering function meta information.
1038 void BeginFunction(MachineFunction *MF);
1040 /// EndFunction - Discard function meta information.
1044 /// getDescFor - Convert a Value to a debug information descriptor.
1046 // FIXME - use new Value type when available.
1047 DebugInfoDesc *getDescFor(Value *V);
1049 /// Verify - Verify that a Value is debug information descriptor.
1051 bool Verify(Value *V);
1053 /// AnalyzeModule - Scan the module for global debug information.
1055 void AnalyzeModule(Module &M);
1057 /// hasDebugInfo - Returns true if valid debug info is present.
1059 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1061 /// needsFrameInfo - Returns true if we need to gather callee-saved register
1062 /// move info for the frame.
1063 bool needsFrameInfo() const;
1065 /// NextLabelID - Return the next unique label id.
1067 unsigned NextLabelID() {
1068 unsigned ID = LabelIDList.size() + 1;
1069 LabelIDList.push_back(ID);
1073 /// RecordLabel - Records location information and associates it with a
1074 /// label. Returns a unique label ID used to generate a label and
1075 /// provide correspondence to the source line list.
1076 unsigned RecordLabel(unsigned Line, unsigned Column, unsigned Source);
1078 /// InvalidateLabel - Inhibit use of the specified label # from
1079 /// MachineModuleInfo, for example because the code was deleted.
1080 void InvalidateLabel(unsigned LabelID) {
1081 // Remap to zero to indicate deletion.
1082 RemapLabel(LabelID, 0);
1085 /// RemapLabel - Indicate that a label has been merged into another.
1087 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1088 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1089 "Old label ID out of range.");
1090 assert(NewLabelID <= LabelIDList.size() &&
1091 "New label ID out of range.");
1092 LabelIDList[OldLabelID - 1] = NewLabelID;
1095 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1096 /// ID != Mapped ID indicates that the label was folded into another label.
1097 unsigned MappedLabel(unsigned LabelID) const {
1098 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1099 return LabelID ? LabelIDList[LabelID - 1] : 0;
1102 /// RecordSource - Register a source file with debug info. Returns an source
1104 unsigned RecordSource(const std::string &Directory,
1105 const std::string &Source);
1106 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1108 /// getDirectories - Return the UniqueVector of std::string representing
1110 const UniqueVector<std::string> &getDirectories() const {
1114 /// getSourceFiles - Return the UniqueVector of source files.
1116 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1120 /// getSourceLines - Return a vector of source lines.
1122 const std::vector<SourceLineInfo> &getSourceLines() const {
1126 /// SetupCompileUnits - Set up the unique vector of compile units.
1128 void SetupCompileUnits(Module &M);
1130 /// getCompileUnits - Return a vector of debug compile units.
1132 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1134 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1135 /// named GlobalVariable.
1136 std::vector<GlobalVariable*>
1137 getGlobalVariablesUsing(Module &M, const std::string &RootName);
1139 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1141 template <class T>std::vector<T *> getAnchoredDescriptors(Module &M) {
1143 std::vector<GlobalVariable *> Globals =
1144 getGlobalVariablesUsing(M, Desc.getAnchorString());
1145 std::vector<T *> AnchoredDescs;
1146 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1147 GlobalVariable *GV = Globals[i];
1149 // FIXME - In the short term, changes are too drastic to continue.
1150 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1151 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1152 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1156 return AnchoredDescs;
1159 /// RecordRegionStart - Indicate the start of a region.
1161 unsigned RecordRegionStart(Value *V);
1163 /// RecordRegionEnd - Indicate the end of a region.
1165 unsigned RecordRegionEnd(Value *V);
1167 /// RecordVariable - Indicate the declaration of a local variable.
1169 void RecordVariable(Value *V, unsigned FrameIndex);
1171 /// getRootScope - Return current functions root scope.
1173 DebugScope *getRootScope() { return RootScope; }
1175 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1177 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1179 /// getFrameMoves - Returns a reference to a list of moves done in the current
1180 /// function's prologue. Used to construct frame maps for debug and exception
1181 /// handling comsumers.
1182 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1184 //===-EH-----------------------------------------------------------------===//
1186 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1187 /// specified MachineBasicBlock.
1188 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1190 /// addInvoke - Provide the begin and end labels of an invoke style call and
1191 /// associate it with a try landing pad block.
1192 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1195 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1196 /// landing pad entry.
1197 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1199 /// addPersonality - Provide the personality function for the exception
1201 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1203 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1205 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1206 std::vector<GlobalVariable *> &TyInfo);
1208 /// setIsFilterLandingPad - Indicates that the landing pad is a throw filter.
1210 void setIsFilterLandingPad(MachineBasicBlock *LandingPad);
1212 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1214 unsigned getTypeIDFor(GlobalVariable *TI);
1216 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1218 void TidyLandingPads();
1220 /// getLandingPadInfos - Return a reference to the landing pad info for the
1221 /// current function.
1222 const std::vector<LandingPadInfo> &getLandingPads() const {
1226 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1228 const std::vector<GlobalVariable *> &getTypeInfos() const {
1232 /// getPersonality - Return a personality function if available. The presence
1233 /// of one is required to emit exception handling info.
1234 Function *getPersonality() const;
1236 }; // End class MachineModuleInfo
1238 } // End llvm namespace