1 //===-- llvm/CodeGen/MachineModuleInfo.h ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Collect meta information for a module. This information should be in a
11 // neutral form that can be used by different debugging and exception handling
14 // The organization of information is primarily clustered around the source
15 // compile units. The main exception is source line correspondence where
16 // inlining may interleave code from various compile units.
18 // The following information can be retrieved from the MachineModuleInfo.
20 // -- Source directories - Directories are uniqued based on their canonical
21 // string and assigned a sequential numeric ID (base 1.)
22 // -- Source files - Files are also uniqued based on their name and directory
23 // ID. A file ID is sequential number (base 1.)
24 // -- Source line correspondence - A vector of file ID, line#, column# triples.
25 // A DEBUG_LOCATION instruction is generated by the DAG Legalizer
26 // corresponding to each entry in the source line list. This allows a debug
27 // emitter to generate labels referenced by debug information tables.
29 //===----------------------------------------------------------------------===//
31 #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
32 #define LLVM_CODEGEN_MACHINEMODULEINFO_H
34 #include "llvm/Support/Dwarf.h"
35 #include "llvm/Support/DataTypes.h"
36 #include "llvm/ADT/SmallVector.h"
37 #include "llvm/ADT/DenseMap.h"
38 #include "llvm/ADT/UniqueVector.h"
39 #include "llvm/ADT/SmallPtrSet.h"
40 #include "llvm/ADT/StringMap.h"
41 #include "llvm/CodeGen/MachineLocation.h"
42 #include "llvm/GlobalValue.h"
43 #include "llvm/Pass.h"
47 //===----------------------------------------------------------------------===//
48 // Forward declarations.
52 class MachineBasicBlock;
53 class MachineFunction;
58 //===----------------------------------------------------------------------===//
59 // Debug info constants.
62 LLVMDebugVersion = (6 << 16), // Current version of debug information.
63 LLVMDebugVersion5 = (5 << 16), // Constant for version 5.
64 LLVMDebugVersion4 = (4 << 16), // Constant for version 4.
65 LLVMDebugVersionMask = 0xffff0000 // Mask for version number.
68 //===----------------------------------------------------------------------===//
69 /// DIVisitor - Subclasses of this class apply steps to each of the fields in
70 /// the supplied DebugInfoDesc.
74 virtual ~DIVisitor() {}
76 /// ApplyToFields - Target the visitor to each field of the debug information
78 void ApplyToFields(DebugInfoDesc *DD);
80 /// Apply - Subclasses override each of these methods to perform the
81 /// appropriate action for the type of field.
82 virtual void Apply(int &Field) = 0;
83 virtual void Apply(unsigned &Field) = 0;
84 virtual void Apply(int64_t &Field) = 0;
85 virtual void Apply(uint64_t &Field) = 0;
86 virtual void Apply(bool &Field) = 0;
87 virtual void Apply(std::string &Field) = 0;
88 virtual void Apply(DebugInfoDesc *&Field) = 0;
89 virtual void Apply(GlobalVariable *&Field) = 0;
90 virtual void Apply(std::vector<DebugInfoDesc *> &Field) = 0;
93 //===----------------------------------------------------------------------===//
94 /// DebugInfoDesc - This class is the base class for debug info descriptors.
98 unsigned Tag; // Content indicator. Dwarf values are
99 // used but that does not limit use to
103 explicit DebugInfoDesc(unsigned T) : Tag(T | LLVMDebugVersion) {}
106 virtual ~DebugInfoDesc() {}
109 unsigned getTag() const { return Tag & ~LLVMDebugVersionMask; }
110 unsigned getVersion() const { return Tag & LLVMDebugVersionMask; }
111 void setTag(unsigned T) { Tag = T | LLVMDebugVersion; }
113 /// TagFromGlobal - Returns the tag number from a debug info descriptor
114 /// GlobalVariable. Return DIIValid if operand is not an unsigned int.
115 static unsigned TagFromGlobal(GlobalVariable *GV);
117 /// VersionFromGlobal - Returns the version number from a debug info
118 /// descriptor GlobalVariable. Return DIIValid if operand is not an unsigned
120 static unsigned VersionFromGlobal(GlobalVariable *GV);
122 /// DescFactory - Create an instance of debug info descriptor based on Tag.
123 /// Return NULL if not a recognized Tag.
124 static DebugInfoDesc *DescFactory(unsigned Tag);
126 /// getLinkage - get linkage appropriate for this type of descriptor.
128 virtual GlobalValue::LinkageTypes getLinkage() const;
130 //===--------------------------------------------------------------------===//
131 // Subclasses should supply the following static methods.
133 // Implement isa/cast/dyncast.
134 static bool classof(const DebugInfoDesc *) { return true; }
136 //===--------------------------------------------------------------------===//
137 // Subclasses should supply the following virtual methods.
139 /// ApplyToFields - Target the vistor to the fields of the descriptor.
141 virtual void ApplyToFields(DIVisitor *Visitor);
143 /// getDescString - Return a string used to compose global names and labels.
145 virtual const char *getDescString() const = 0;
147 /// getTypeString - Return a string used to label this descriptor's type.
149 virtual const char *getTypeString() const = 0;
152 virtual void dump() = 0;
156 //===----------------------------------------------------------------------===//
157 /// AnchorDesc - Descriptors of this class act as markers for identifying
158 /// descriptors of certain groups.
160 class AnchorDesc : public DebugInfoDesc {
162 unsigned AnchorTag; // Tag number of descriptors anchored
167 explicit AnchorDesc(AnchoredDesc *D);
170 unsigned getAnchorTag() const { return AnchorTag; }
172 // Implement isa/cast/dyncast.
173 static bool classof(const AnchorDesc *) { return true; }
174 static bool classof(const DebugInfoDesc *D);
176 /// getLinkage - get linkage appropriate for this type of descriptor.
178 virtual GlobalValue::LinkageTypes getLinkage() const;
180 /// ApplyToFields - Target the visitor to the fields of the AnchorDesc.
182 virtual void ApplyToFields(DIVisitor *Visitor);
184 /// getDescString - Return a string used to compose global names and labels.
186 virtual const char *getDescString() const;
188 /// getTypeString - Return a string used to label this descriptor's type.
190 virtual const char *getTypeString() const;
197 //===----------------------------------------------------------------------===//
198 /// AnchoredDesc - This class manages anchors for a variety of top level
200 class AnchoredDesc : public DebugInfoDesc {
202 DebugInfoDesc *Anchor; // Anchor for all descriptors of the
207 explicit AnchoredDesc(unsigned T);
211 AnchorDesc *getAnchor() const { return static_cast<AnchorDesc *>(Anchor); }
212 void setAnchor(AnchorDesc *A) { Anchor = static_cast<DebugInfoDesc *>(A); }
214 //===--------------------------------------------------------------------===//
215 // Subclasses should supply the following virtual methods.
217 /// getAnchorString - Return a string used to label descriptor's anchor.
219 virtual const char *getAnchorString() const = 0;
221 /// ApplyToFields - Target the visitor to the fields of the AnchoredDesc.
223 virtual void ApplyToFields(DIVisitor *Visitor);
226 //===----------------------------------------------------------------------===//
227 /// CompileUnitDesc - This class packages debug information associated with a
228 /// source/header file.
229 class CompileUnitDesc : public AnchoredDesc {
231 unsigned Language; // Language number (ex. DW_LANG_C89.)
232 std::string FileName; // Source file name.
233 std::string Directory; // Source file directory.
234 std::string Producer; // Compiler string.
241 unsigned getLanguage() const { return Language; }
242 const std::string &getFileName() const { return FileName; }
243 const std::string &getDirectory() const { return Directory; }
244 const std::string &getProducer() const { return Producer; }
245 void setLanguage(unsigned L) { Language = L; }
246 void setFileName(const std::string &FN) { FileName = FN; }
247 void setDirectory(const std::string &D) { Directory = D; }
248 void setProducer(const std::string &P) { Producer = P; }
250 // FIXME - Need translation unit getter/setter.
252 // Implement isa/cast/dyncast.
253 static bool classof(const CompileUnitDesc *) { return true; }
254 static bool classof(const DebugInfoDesc *D);
256 /// ApplyToFields - Target the visitor to the fields of the CompileUnitDesc.
258 virtual void ApplyToFields(DIVisitor *Visitor);
260 /// getDescString - Return a string used to compose global names and labels.
262 virtual const char *getDescString() const;
264 /// getTypeString - Return a string used to label this descriptor's type.
266 virtual const char *getTypeString() const;
268 /// getAnchorString - Return a string used to label this descriptor's anchor.
270 static const char *const AnchorString;
271 virtual const char *getAnchorString() const;
278 //===----------------------------------------------------------------------===//
279 /// TypeDesc - This class packages debug information associated with a type.
281 class TypeDesc : public DebugInfoDesc {
284 FlagPrivate = 1 << 0,
285 FlagProtected = 1 << 1,
288 DebugInfoDesc *Context; // Context debug descriptor.
289 std::string Name; // Type name (may be empty.)
290 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
291 unsigned Line; // Defined line# (may be zero.)
292 uint64_t Size; // Type bit size (may be zero.)
293 uint64_t Align; // Type bit alignment (may be zero.)
294 uint64_t Offset; // Type bit offset (may be zero.)
297 unsigned Flags; // Miscellaneous flags.
300 explicit TypeDesc(unsigned T);
303 DebugInfoDesc *getContext() const { return Context; }
304 const std::string &getName() const { return Name; }
305 CompileUnitDesc *getFile() const {
306 return static_cast<CompileUnitDesc *>(File);
308 unsigned getLine() const { return Line; }
309 uint64_t getSize() const { return Size; }
310 uint64_t getAlign() const { return Align; }
311 uint64_t getOffset() const { return Offset; }
312 bool isPrivate() const {
313 return (Flags & FlagPrivate) != 0;
315 bool isProtected() const {
316 return (Flags & FlagProtected) != 0;
318 bool isForwardDecl() const {
319 return (Flags & FlagFwdDecl) != 0;
321 void setContext(DebugInfoDesc *C) { Context = C; }
322 void setName(const std::string &N) { Name = N; }
323 void setFile(CompileUnitDesc *U) {
324 File = static_cast<DebugInfoDesc *>(U);
326 void setLine(unsigned L) { Line = L; }
327 void setSize(uint64_t S) { Size = S; }
328 void setAlign(uint64_t A) { Align = A; }
329 void setOffset(uint64_t O) { Offset = O; }
330 void setIsPrivate() { Flags |= FlagPrivate; }
331 void setIsProtected() { Flags |= FlagProtected; }
332 void setIsForwardDecl() { Flags |= FlagFwdDecl; }
334 /// ApplyToFields - Target the visitor to the fields of the TypeDesc.
336 virtual void ApplyToFields(DIVisitor *Visitor);
338 /// getDescString - Return a string used to compose global names and labels.
340 virtual const char *getDescString() const;
342 /// getTypeString - Return a string used to label this descriptor's type.
344 virtual const char *getTypeString() const;
351 //===----------------------------------------------------------------------===//
352 /// BasicTypeDesc - This class packages debug information associated with a
353 /// basic type (eg. int, bool, double.)
354 class BasicTypeDesc : public TypeDesc {
356 unsigned Encoding; // Type encoding.
362 unsigned getEncoding() const { return Encoding; }
363 void setEncoding(unsigned E) { Encoding = E; }
365 // Implement isa/cast/dyncast.
366 static bool classof(const BasicTypeDesc *) { return true; }
367 static bool classof(const DebugInfoDesc *D);
369 /// ApplyToFields - Target the visitor to the fields of the BasicTypeDesc.
371 virtual void ApplyToFields(DIVisitor *Visitor);
373 /// getDescString - Return a string used to compose global names and labels.
375 virtual const char *getDescString() const;
377 /// getTypeString - Return a string used to label this descriptor's type.
379 virtual const char *getTypeString() const;
387 //===----------------------------------------------------------------------===//
388 /// DerivedTypeDesc - This class packages debug information associated with a
389 /// derived types (eg., typedef, pointer, reference.)
390 class DerivedTypeDesc : public TypeDesc {
392 DebugInfoDesc *FromType; // Type derived from.
395 explicit DerivedTypeDesc(unsigned T);
398 TypeDesc *getFromType() const {
399 return static_cast<TypeDesc *>(FromType);
401 void setFromType(TypeDesc *F) {
402 FromType = static_cast<DebugInfoDesc *>(F);
405 // Implement isa/cast/dyncast.
406 static bool classof(const DerivedTypeDesc *) { return true; }
407 static bool classof(const DebugInfoDesc *D);
409 /// ApplyToFields - Target the visitor to the fields of the DerivedTypeDesc.
411 virtual void ApplyToFields(DIVisitor *Visitor);
413 /// getDescString - Return a string used to compose global names and labels.
415 virtual const char *getDescString() const;
417 /// getTypeString - Return a string used to label this descriptor's type.
419 virtual const char *getTypeString() const;
426 //===----------------------------------------------------------------------===//
427 /// CompositeTypeDesc - This class packages debug information associated with a
428 /// array/struct types (eg., arrays, struct, union, enums.)
429 class CompositeTypeDesc : public DerivedTypeDesc {
431 std::vector<DebugInfoDesc *> Elements;// Information used to compose type.
434 explicit CompositeTypeDesc(unsigned T);
437 std::vector<DebugInfoDesc *> &getElements() { return Elements; }
439 // Implement isa/cast/dyncast.
440 static bool classof(const CompositeTypeDesc *) { return true; }
441 static bool classof(const DebugInfoDesc *D);
443 /// ApplyToFields - Target the visitor to the fields of the CompositeTypeDesc.
445 virtual void ApplyToFields(DIVisitor *Visitor);
447 /// getDescString - Return a string used to compose global names and labels.
449 virtual const char *getDescString() const;
451 /// getTypeString - Return a string used to label this descriptor's type.
453 virtual const char *getTypeString() const;
460 //===----------------------------------------------------------------------===//
461 /// SubrangeDesc - This class packages debug information associated with integer
463 class SubrangeDesc : public DebugInfoDesc {
465 int64_t Lo; // Low value of range.
466 int64_t Hi; // High value of range.
472 int64_t getLo() const { return Lo; }
473 int64_t getHi() const { return Hi; }
474 void setLo(int64_t L) { Lo = L; }
475 void setHi(int64_t H) { Hi = H; }
477 // Implement isa/cast/dyncast.
478 static bool classof(const SubrangeDesc *) { return true; }
479 static bool classof(const DebugInfoDesc *D);
481 /// ApplyToFields - Target the visitor to the fields of the SubrangeDesc.
483 virtual void ApplyToFields(DIVisitor *Visitor);
485 /// getDescString - Return a string used to compose global names and labels.
487 virtual const char *getDescString() const;
489 /// getTypeString - Return a string used to label this descriptor's type.
491 virtual const char *getTypeString() const;
498 //===----------------------------------------------------------------------===//
499 /// EnumeratorDesc - This class packages debug information associated with
500 /// named integer constants.
501 class EnumeratorDesc : public DebugInfoDesc {
503 std::string Name; // Enumerator name.
504 int64_t Value; // Enumerator value.
510 const std::string &getName() const { return Name; }
511 int64_t getValue() const { return Value; }
512 void setName(const std::string &N) { Name = N; }
513 void setValue(int64_t V) { Value = V; }
515 // Implement isa/cast/dyncast.
516 static bool classof(const EnumeratorDesc *) { return true; }
517 static bool classof(const DebugInfoDesc *D);
519 /// ApplyToFields - Target the visitor to the fields of the EnumeratorDesc.
521 virtual void ApplyToFields(DIVisitor *Visitor);
523 /// getDescString - Return a string used to compose global names and labels.
525 virtual const char *getDescString() const;
527 /// getTypeString - Return a string used to label this descriptor's type.
529 virtual const char *getTypeString() const;
536 //===----------------------------------------------------------------------===//
537 /// VariableDesc - This class packages debug information associated with a
538 /// subprogram variable.
540 class VariableDesc : public DebugInfoDesc {
542 DebugInfoDesc *Context; // Context debug descriptor.
543 std::string Name; // Type name (may be empty.)
544 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
545 unsigned Line; // Defined line# (may be zero.)
546 DebugInfoDesc *TyDesc; // Type of variable.
549 explicit VariableDesc(unsigned T);
552 DebugInfoDesc *getContext() const { return Context; }
553 const std::string &getName() const { return Name; }
554 CompileUnitDesc *getFile() const {
555 return static_cast<CompileUnitDesc *>(File);
557 unsigned getLine() const { return Line; }
558 TypeDesc *getType() const {
559 return static_cast<TypeDesc *>(TyDesc);
561 void setContext(DebugInfoDesc *C) { Context = C; }
562 void setName(const std::string &N) { Name = N; }
563 void setFile(CompileUnitDesc *U) {
564 File = static_cast<DebugInfoDesc *>(U);
566 void setLine(unsigned L) { Line = L; }
567 void setType(TypeDesc *T) {
568 TyDesc = static_cast<DebugInfoDesc *>(T);
571 // Implement isa/cast/dyncast.
572 static bool classof(const VariableDesc *) { return true; }
573 static bool classof(const DebugInfoDesc *D);
575 /// ApplyToFields - Target the visitor to the fields of the VariableDesc.
577 virtual void ApplyToFields(DIVisitor *Visitor);
579 /// getDescString - Return a string used to compose global names and labels.
581 virtual const char *getDescString() const;
583 /// getTypeString - Return a string used to label this descriptor's type.
585 virtual const char *getTypeString() const;
592 //===----------------------------------------------------------------------===//
593 /// GlobalDesc - This class is the base descriptor for global functions and
595 class GlobalDesc : public AnchoredDesc {
597 DebugInfoDesc *Context; // Context debug descriptor.
598 std::string Name; // Global name.
599 std::string FullName; // Fully qualified name.
600 std::string LinkageName; // Name for binding to MIPS linkage.
601 DebugInfoDesc *File; // Defined compile unit (may be NULL.)
602 unsigned Line; // Defined line# (may be zero.)
603 DebugInfoDesc *TyDesc; // Type debug descriptor.
604 bool IsStatic; // Is the global a static.
605 bool IsDefinition; // Is the global defined in context.
608 explicit GlobalDesc(unsigned T);
612 DebugInfoDesc *getContext() const { return Context; }
613 const std::string &getName() const { return Name; }
614 const std::string &getFullName() const { return FullName; }
615 const std::string &getLinkageName() const { return LinkageName; }
616 CompileUnitDesc *getFile() const {
617 return static_cast<CompileUnitDesc *>(File);
619 unsigned getLine() const { return Line; }
620 TypeDesc *getType() const {
621 return static_cast<TypeDesc *>(TyDesc);
623 bool isStatic() const { return IsStatic; }
624 bool isDefinition() const { return IsDefinition; }
625 void setContext(DebugInfoDesc *C) { Context = C; }
626 void setName(const std::string &N) { Name = N; }
627 void setFullName(const std::string &N) { FullName = N; }
628 void setLinkageName(const std::string &N) { LinkageName = N; }
629 void setFile(CompileUnitDesc *U) {
630 File = static_cast<DebugInfoDesc *>(U);
632 void setLine(unsigned L) { Line = L; }
633 void setType(TypeDesc *T) {
634 TyDesc = static_cast<DebugInfoDesc *>(T);
636 void setIsStatic(bool IS) { IsStatic = IS; }
637 void setIsDefinition(bool ID) { IsDefinition = ID; }
639 /// ApplyToFields - Target the visitor to the fields of the GlobalDesc.
641 virtual void ApplyToFields(DIVisitor *Visitor);
644 //===----------------------------------------------------------------------===//
645 /// GlobalVariableDesc - This class packages debug information associated with a
647 class GlobalVariableDesc : public GlobalDesc {
649 GlobalVariable *Global; // llvm global.
652 GlobalVariableDesc();
655 GlobalVariable *getGlobalVariable() const { return Global; }
656 void setGlobalVariable(GlobalVariable *GV) { Global = GV; }
658 // Implement isa/cast/dyncast.
659 static bool classof(const GlobalVariableDesc *) { return true; }
660 static bool classof(const DebugInfoDesc *D);
662 /// ApplyToFields - Target the visitor to the fields of the
663 /// GlobalVariableDesc.
664 virtual void ApplyToFields(DIVisitor *Visitor);
666 /// getDescString - Return a string used to compose global names and labels.
668 virtual const char *getDescString() const;
670 /// getTypeString - Return a string used to label this descriptor's type.
672 virtual const char *getTypeString() const;
674 /// getAnchorString - Return a string used to label this descriptor's anchor.
676 static const char *const AnchorString;
677 virtual const char *getAnchorString() const;
684 //===----------------------------------------------------------------------===//
685 /// SubprogramDesc - This class packages debug information associated with a
686 /// subprogram/function.
687 class SubprogramDesc : public GlobalDesc {
695 // Implement isa/cast/dyncast.
696 static bool classof(const SubprogramDesc *) { return true; }
697 static bool classof(const DebugInfoDesc *D);
699 /// ApplyToFields - Target the visitor to the fields of the SubprogramDesc.
701 virtual void ApplyToFields(DIVisitor *Visitor);
703 /// getDescString - Return a string used to compose global names and labels.
705 virtual const char *getDescString() const;
707 /// getTypeString - Return a string used to label this descriptor's type.
709 virtual const char *getTypeString() const;
711 /// getAnchorString - Return a string used to label this descriptor's anchor.
713 static const char *const AnchorString;
714 virtual const char *getAnchorString() const;
721 //===----------------------------------------------------------------------===//
722 /// BlockDesc - This descriptor groups variables and blocks nested in a block.
724 class BlockDesc : public DebugInfoDesc {
726 DebugInfoDesc *Context; // Context debug descriptor.
732 DebugInfoDesc *getContext() const { return Context; }
733 void setContext(DebugInfoDesc *C) { Context = C; }
735 // Implement isa/cast/dyncast.
736 static bool classof(const BlockDesc *) { return true; }
737 static bool classof(const DebugInfoDesc *D);
739 /// ApplyToFields - Target the visitor to the fields of the BlockDesc.
741 virtual void ApplyToFields(DIVisitor *Visitor);
743 /// getDescString - Return a string used to compose global names and labels.
745 virtual const char *getDescString() const;
747 /// getTypeString - Return a string used to label this descriptor's type.
749 virtual const char *getTypeString() const;
756 //===----------------------------------------------------------------------===//
757 /// DIDeserializer - This class is responsible for casting GlobalVariables
758 /// into DebugInfoDesc objects.
759 class DIDeserializer {
760 // Previously defined gloabls.
761 std::map<GlobalVariable*, DebugInfoDesc*> GlobalDescs;
763 const std::map<GlobalVariable *, DebugInfoDesc *> &getGlobalDescs() const {
767 /// Deserialize - Reconstitute a GlobalVariable into it's component
768 /// DebugInfoDesc objects.
769 DebugInfoDesc *Deserialize(Value *V);
770 DebugInfoDesc *Deserialize(GlobalVariable *GV);
773 //===----------------------------------------------------------------------===//
774 /// DISerializer - This class is responsible for casting DebugInfoDesc objects
775 /// into GlobalVariables.
777 Module *M; // Definition space module.
778 PointerType *StrPtrTy; // A "i8*" type. Created lazily.
779 PointerType *EmptyStructPtrTy; // A "{ }*" type. Created lazily.
781 // Types per Tag. Created lazily.
782 std::map<unsigned, StructType *> TagTypes;
784 // Previously defined descriptors.
785 DenseMap<DebugInfoDesc *, GlobalVariable *> DescGlobals;
787 // Previously defined strings.
788 StringMap<Constant*> StringCache;
791 : M(NULL), StrPtrTy(NULL), EmptyStructPtrTy(NULL), TagTypes(),
792 DescGlobals(), StringCache()
796 Module *getModule() const { return M; };
797 void setModule(Module *module) { M = module; }
799 /// getStrPtrType - Return a "i8*" type.
801 const PointerType *getStrPtrType();
803 /// getEmptyStructPtrType - Return a "{ }*" type.
805 const PointerType *getEmptyStructPtrType();
807 /// getTagType - Return the type describing the specified descriptor (via
809 const StructType *getTagType(DebugInfoDesc *DD);
811 /// getString - Construct the string as constant string global.
813 Constant *getString(const std::string &String);
815 /// Serialize - Recursively cast the specified descriptor into a
816 /// GlobalVariable so that it can be serialized to a .bc or .ll file.
817 GlobalVariable *Serialize(DebugInfoDesc *DD);
819 /// addDescriptor - Directly connect DD with existing GV.
820 void addDescriptor(DebugInfoDesc *DD, GlobalVariable *GV);
823 //===----------------------------------------------------------------------===//
824 /// DIVerifier - This class is responsible for verifying the given network of
825 /// GlobalVariables are valid as DebugInfoDesc objects.
832 DenseMap<GlobalVariable *, unsigned> Validity; // Tracks prior results.
833 std::map<unsigned, unsigned> Counts; // Count of fields per Tag type.
836 : Validity(), Counts()
839 /// Verify - Return true if the GlobalVariable appears to be a valid
840 /// serialization of a DebugInfoDesc.
841 bool Verify(Value *V);
842 bool Verify(GlobalVariable *GV);
844 /// isVerified - Return true if the specified GV has already been
845 /// verified as a debug information descriptor.
846 bool isVerified(GlobalVariable *GV);
849 //===----------------------------------------------------------------------===//
850 /// SourceLineInfo - This class is used to record source line correspondence.
852 class SourceLineInfo {
853 unsigned Line; // Source line number.
854 unsigned Column; // Source column.
855 unsigned SourceID; // Source ID number.
856 unsigned LabelID; // Label in code ID number.
858 SourceLineInfo(unsigned L, unsigned C, unsigned S, unsigned I)
859 : Line(L), Column(C), SourceID(S), LabelID(I) {}
862 unsigned getLine() const { return Line; }
863 unsigned getColumn() const { return Column; }
864 unsigned getSourceID() const { return SourceID; }
865 unsigned getLabelID() const { return LabelID; }
868 //===----------------------------------------------------------------------===//
869 /// SourceFileInfo - This class is used to track source information.
871 class SourceFileInfo {
872 unsigned DirectoryID; // Directory ID number.
873 std::string Name; // File name (not including directory.)
875 SourceFileInfo(unsigned D, const std::string &N) : DirectoryID(D), Name(N) {}
878 unsigned getDirectoryID() const { return DirectoryID; }
879 const std::string &getName() const { return Name; }
881 /// operator== - Used by UniqueVector to locate entry.
883 bool operator==(const SourceFileInfo &SI) const {
884 return getDirectoryID() == SI.getDirectoryID() && getName() == SI.getName();
887 /// operator< - Used by UniqueVector to locate entry.
889 bool operator<(const SourceFileInfo &SI) const {
890 return getDirectoryID() < SI.getDirectoryID() ||
891 (getDirectoryID() == SI.getDirectoryID() && getName() < SI.getName());
895 //===----------------------------------------------------------------------===//
896 /// DebugVariable - This class is used to track local variable information.
898 class DebugVariable {
900 VariableDesc *Desc; // Variable Descriptor.
901 unsigned FrameIndex; // Variable frame index.
904 DebugVariable(VariableDesc *D, unsigned I)
910 VariableDesc *getDesc() const { return Desc; }
911 unsigned getFrameIndex() const { return FrameIndex; }
914 //===----------------------------------------------------------------------===//
915 /// DebugScope - This class is used to track scope information.
919 DebugScope *Parent; // Parent to this scope.
920 DebugInfoDesc *Desc; // Debug info descriptor for scope.
921 // Either subprogram or block.
922 unsigned StartLabelID; // Label ID of the beginning of scope.
923 unsigned EndLabelID; // Label ID of the end of scope.
924 std::vector<DebugScope *> Scopes; // Scopes defined in scope.
925 std::vector<DebugVariable *> Variables;// Variables declared in scope.
928 DebugScope(DebugScope *P, DebugInfoDesc *D)
939 DebugScope *getParent() const { return Parent; }
940 DebugInfoDesc *getDesc() const { return Desc; }
941 unsigned getStartLabelID() const { return StartLabelID; }
942 unsigned getEndLabelID() const { return EndLabelID; }
943 std::vector<DebugScope *> &getScopes() { return Scopes; }
944 std::vector<DebugVariable *> &getVariables() { return Variables; }
945 void setStartLabelID(unsigned S) { StartLabelID = S; }
946 void setEndLabelID(unsigned E) { EndLabelID = E; }
948 /// AddScope - Add a scope to the scope.
950 void AddScope(DebugScope *S) { Scopes.push_back(S); }
952 /// AddVariable - Add a variable to the scope.
954 void AddVariable(DebugVariable *V) { Variables.push_back(V); }
957 //===----------------------------------------------------------------------===//
958 /// LandingPadInfo - This structure is used to retain landing pad info for
959 /// the current function.
961 struct LandingPadInfo {
962 MachineBasicBlock *LandingPadBlock; // Landing pad block.
963 SmallVector<unsigned, 1> BeginLabels; // Labels prior to invoke.
964 SmallVector<unsigned, 1> EndLabels; // Labels after invoke.
965 unsigned LandingPadLabel; // Label at beginning of landing pad.
966 Function *Personality; // Personality function.
967 std::vector<int> TypeIds; // List of type ids (filters negative)
969 explicit LandingPadInfo(MachineBasicBlock *MBB)
970 : 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;
1024 // FilterIds - List of typeids encoding filters used in the current function.
1026 std::vector<unsigned> FilterIds;
1028 // FilterEnds - List of the indices in FilterIds corresponding to filter
1031 std::vector<unsigned> FilterEnds;
1033 // Personalities - Vector of all personality functions ever seen. Used to emit
1034 // common EH frames.
1035 std::vector<Function *> Personalities;
1037 // UsedFunctions - the functions in the llvm.used list in a more easily
1038 // searchable format.
1039 SmallPtrSet<const Function *, 32> UsedFunctions;
1042 bool CallsUnwindInit;
1044 static char ID; // Pass identification, replacement for typeid
1046 MachineModuleInfo();
1047 ~MachineModuleInfo();
1049 /// doInitialization - Initialize the state for a new module.
1051 bool doInitialization();
1053 /// doFinalization - Tear down the state after completion of a module.
1055 bool doFinalization();
1057 /// BeginFunction - Begin gathering function meta information.
1059 void BeginFunction(MachineFunction *MF);
1061 /// EndFunction - Discard function meta information.
1065 /// getDescFor - Convert a Value to a debug information descriptor.
1067 // FIXME - use new Value type when available.
1068 DebugInfoDesc *getDescFor(Value *V);
1070 /// Verify - Verify that a Value is debug information descriptor.
1072 bool Verify(Value *V) { return VR.Verify(V); }
1074 /// isVerified - Return true if the specified GV has already been
1075 /// verified as a debug information descriptor.
1076 bool isVerified(GlobalVariable *GV) { return VR.isVerified(GV); }
1078 /// AnalyzeModule - Scan the module for global debug information.
1080 void AnalyzeModule(Module &M);
1082 /// hasDebugInfo - Returns true if valid debug info is present.
1084 bool hasDebugInfo() const { return !CompileUnits.empty(); }
1086 bool callsEHReturn() const { return CallsEHReturn; }
1087 void setCallsEHReturn(bool b) { CallsEHReturn = b; }
1089 bool callsUnwindInit() const { return CallsUnwindInit; }
1090 void setCallsUnwindInit(bool b) { CallsUnwindInit = b; }
1092 /// NextLabelID - Return the next unique label id.
1094 unsigned NextLabelID() {
1095 unsigned ID = (unsigned)LabelIDList.size() + 1;
1096 LabelIDList.push_back(ID);
1100 /// RecordSourceLine - Records location information and associates it with a
1101 /// label. Returns a unique label ID used to generate a label and
1102 /// provide correspondence to the source line list.
1103 unsigned RecordSourceLine(unsigned Line, unsigned Column, unsigned Source);
1105 /// InvalidateLabel - Inhibit use of the specified label # from
1106 /// MachineModuleInfo, for example because the code was deleted.
1107 void InvalidateLabel(unsigned LabelID) {
1108 // Remap to zero to indicate deletion.
1109 RemapLabel(LabelID, 0);
1112 /// RemapLabel - Indicate that a label has been merged into another.
1114 void RemapLabel(unsigned OldLabelID, unsigned NewLabelID) {
1115 assert(0 < OldLabelID && OldLabelID <= LabelIDList.size() &&
1116 "Old label ID out of range.");
1117 assert(NewLabelID <= LabelIDList.size() &&
1118 "New label ID out of range.");
1119 LabelIDList[OldLabelID - 1] = NewLabelID;
1122 /// MappedLabel - Find out the label's final ID. Zero indicates deletion.
1123 /// ID != Mapped ID indicates that the label was folded into another label.
1124 unsigned MappedLabel(unsigned LabelID) const {
1125 assert(LabelID <= LabelIDList.size() && "Debug label ID out of range.");
1126 return LabelID ? LabelIDList[LabelID - 1] : 0;
1129 /// RecordSource - Register a source file with debug info. Returns an source
1131 unsigned RecordSource(const std::string &Directory,
1132 const std::string &Source);
1133 unsigned RecordSource(const CompileUnitDesc *CompileUnit);
1135 /// getDirectories - Return the UniqueVector of std::string representing
1137 const UniqueVector<std::string> &getDirectories() const {
1141 /// getSourceFiles - Return the UniqueVector of source files.
1143 const UniqueVector<SourceFileInfo> &getSourceFiles() const {
1147 /// getSourceLines - Return a vector of source lines.
1149 const std::vector<SourceLineInfo> &getSourceLines() const {
1153 /// SetupCompileUnits - Set up the unique vector of compile units.
1155 void SetupCompileUnits(Module &M);
1157 /// getCompileUnits - Return a vector of debug compile units.
1159 const UniqueVector<CompileUnitDesc *> getCompileUnits() const;
1161 /// getGlobalVariablesUsing - Return all of the GlobalVariables that use the
1162 /// named GlobalVariable.
1163 void getGlobalVariablesUsing(Module &M, const std::string &RootName,
1164 std::vector<GlobalVariable*> &Result);
1166 /// getAnchoredDescriptors - Return a vector of anchored debug descriptors.
1169 void getAnchoredDescriptors(Module &M, std::vector<T*> &AnchoredDescs) {
1171 std::vector<GlobalVariable *> Globals;
1172 getGlobalVariablesUsing(M, Desc.getAnchorString(), Globals);
1174 for (unsigned i = 0, N = Globals.size(); i < N; ++i) {
1175 GlobalVariable *GV = Globals[i];
1177 // FIXME - In the short term, changes are too drastic to continue.
1178 if (DebugInfoDesc::TagFromGlobal(GV) == Desc.getTag() &&
1179 DebugInfoDesc::VersionFromGlobal(GV) == LLVMDebugVersion) {
1180 AnchoredDescs.push_back(cast<T>(DR.Deserialize(GV)));
1185 /// RecordRegionStart - Indicate the start of a region.
1187 unsigned RecordRegionStart(Value *V);
1189 /// RecordRegionEnd - Indicate the end of a region.
1191 unsigned RecordRegionEnd(Value *V);
1193 /// RecordVariable - Indicate the declaration of a local variable.
1195 void RecordVariable(GlobalValue *GV, unsigned FrameIndex);
1197 /// getRootScope - Return current functions root scope.
1199 DebugScope *getRootScope() { return RootScope; }
1201 /// getOrCreateScope - Returns the scope associated with the given descriptor.
1203 DebugScope *getOrCreateScope(DebugInfoDesc *ScopeDesc);
1205 /// getFrameMoves - Returns a reference to a list of moves done in the current
1206 /// function's prologue. Used to construct frame maps for debug and exception
1207 /// handling comsumers.
1208 std::vector<MachineMove> &getFrameMoves() { return FrameMoves; }
1210 //===-EH-----------------------------------------------------------------===//
1212 /// getOrCreateLandingPadInfo - Find or create an LandingPadInfo for the
1213 /// specified MachineBasicBlock.
1214 LandingPadInfo &getOrCreateLandingPadInfo(MachineBasicBlock *LandingPad);
1216 /// addInvoke - Provide the begin and end labels of an invoke style call and
1217 /// associate it with a try landing pad block.
1218 void addInvoke(MachineBasicBlock *LandingPad, unsigned BeginLabel,
1221 /// addLandingPad - Add a new panding pad. Returns the label ID for the
1222 /// landing pad entry.
1223 unsigned addLandingPad(MachineBasicBlock *LandingPad);
1225 /// addPersonality - Provide the personality function for the exception
1227 void addPersonality(MachineBasicBlock *LandingPad, Function *Personality);
1229 /// getPersonalityIndex - Get index of the current personality function inside
1230 /// Personalitites array
1231 unsigned getPersonalityIndex() const;
1233 /// getPersonalities - Return array of personality functions ever seen.
1234 const std::vector<Function *>& getPersonalities() const {
1235 return Personalities;
1238 // UsedFunctions - Return set of the functions in the llvm.used list.
1239 const SmallPtrSet<const Function *, 32>& getUsedFunctions() const {
1240 return UsedFunctions;
1243 /// addCatchTypeInfo - Provide the catch typeinfo for a landing pad.
1245 void addCatchTypeInfo(MachineBasicBlock *LandingPad,
1246 std::vector<GlobalVariable *> &TyInfo);
1248 /// addFilterTypeInfo - Provide the filter typeinfo for a landing pad.
1250 void addFilterTypeInfo(MachineBasicBlock *LandingPad,
1251 std::vector<GlobalVariable *> &TyInfo);
1253 /// addCleanup - Add a cleanup action for a landing pad.
1255 void addCleanup(MachineBasicBlock *LandingPad);
1257 /// getTypeIDFor - Return the type id for the specified typeinfo. This is
1259 unsigned getTypeIDFor(GlobalVariable *TI);
1261 /// getFilterIDFor - Return the id of the filter encoded by TyIds. This is
1263 int getFilterIDFor(std::vector<unsigned> &TyIds);
1265 /// TidyLandingPads - Remap landing pad labels and remove any deleted landing
1267 void TidyLandingPads();
1269 /// getLandingPads - Return a reference to the landing pad info for the
1270 /// current function.
1271 const std::vector<LandingPadInfo> &getLandingPads() const {
1275 /// getTypeInfos - Return a reference to the C++ typeinfo for the current
1277 const std::vector<GlobalVariable *> &getTypeInfos() const {
1281 /// getFilterIds - Return a reference to the typeids encoding filters used in
1282 /// the current function.
1283 const std::vector<unsigned> &getFilterIds() const {
1287 /// getPersonality - Return a personality function if available. The presence
1288 /// of one is required to emit exception handling info.
1289 Function *getPersonality() const;
1291 DIDeserializer *getDIDeserializer() { return &DR; }
1292 }; // End class MachineModuleInfo
1294 } // End llvm namespace