blob: 35bf33ab95815c91034be425b947e5367588027a [file] [log] [blame]
David Blaikie85f80d72014-04-23 18:54:00 +00001//===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
11#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
David Blaikie85f80d72014-04-23 18:54:00 +000012
Chandler Carruthd9903882015-01-14 11:23:27 +000013#include "AddressPool.h"
14#include "DwarfStringPool.h"
David Blaikie85f80d72014-04-23 18:54:00 +000015#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/FoldingSet.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringMap.h"
19#include "llvm/Support/Allocator.h"
David Blaikie85f80d72014-04-23 18:54:00 +000020#include <memory>
Chandler Carruthd9903882015-01-14 11:23:27 +000021#include <string>
22#include <vector>
David Blaikie85f80d72014-04-23 18:54:00 +000023
24namespace llvm {
25class AsmPrinter;
David Blaikief2999472014-10-23 00:16:05 +000026class DbgVariable;
David Blaikie85f80d72014-04-23 18:54:00 +000027class DwarfUnit;
28class DIEAbbrev;
29class MCSymbol;
30class DIE;
David Blaikie1d96cc22014-10-31 22:30:30 +000031class DISubprogram;
David Blaikief2999472014-10-23 00:16:05 +000032class LexicalScope;
David Blaikie85f80d72014-04-23 18:54:00 +000033class StringRef;
34class DwarfDebug;
35class MCSection;
36class DwarfFile {
37 // Target of Dwarf emission, used for sizing of abbreviations.
38 AsmPrinter *Asm;
39
David Blaikie2b22b1e2014-10-23 00:16:03 +000040 DwarfDebug &DD;
41
David Blaikie85f80d72014-04-23 18:54:00 +000042 // Used to uniquely define abbreviations.
43 FoldingSet<DIEAbbrev> AbbreviationsSet;
44
45 // A list of all the unique abbreviations in use.
46 std::vector<DIEAbbrev *> Abbreviations;
47
48 // A pointer to all units in the section.
49 SmallVector<std::unique_ptr<DwarfUnit>, 1> CUs;
50
David Blaikiedaefdbf2014-04-25 21:34:35 +000051 DwarfStringPool StrPool;
David Blaikie85f80d72014-04-23 18:54:00 +000052
David Blaikie80e5b1e2014-10-24 17:57:34 +000053 // Collection of dbg variables of a scope.
54 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
55
David Blaikief6dac292014-11-01 17:21:26 +000056 // Collection of abstract subprogram DIEs.
57 DenseMap<const MDNode *, DIE *> AbstractSPDies;
58
David Blaikie9bfd7a92014-11-04 22:12:18 +000059 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
60 /// be shared across CUs, that is why we keep the map here instead
61 /// of in DwarfCompileUnit.
62 DenseMap<const MDNode *, DIE *> MDTypeNodeToDieMap;
63
David Blaikie85f80d72014-04-23 18:54:00 +000064public:
David Blaikie2b22b1e2014-10-23 00:16:03 +000065 DwarfFile(AsmPrinter *AP, DwarfDebug &DD, StringRef Pref,
66 BumpPtrAllocator &DA);
David Blaikie85f80d72014-04-23 18:54:00 +000067
68 ~DwarfFile();
69
70 const SmallVectorImpl<std::unique_ptr<DwarfUnit>> &getUnits() { return CUs; }
71
72 /// \brief Compute the size and offset of a DIE given an incoming Offset.
73 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
74
75 /// \brief Compute the size and offset of all the DIEs.
76 void computeSizeAndOffsets();
77
78 /// \brief Define a unique number for the abbreviation.
79 void assignAbbrevNumber(DIEAbbrev &Abbrev);
80
81 /// \brief Add a unit to the list of CUs.
82 void addUnit(std::unique_ptr<DwarfUnit> U);
83
84 /// \brief Emit all of the units to the section listed with the given
85 /// abbreviation section.
David Blaikie2b22b1e2014-10-23 00:16:03 +000086 void emitUnits(const MCSymbol *ASectionSym);
David Blaikie85f80d72014-04-23 18:54:00 +000087
88 /// \brief Emit a set of abbreviations to the specific section.
89 void emitAbbrevs(const MCSection *);
90
91 /// \brief Emit all of the strings to the section given.
92 void emitStrings(const MCSection *StrSection,
David Blaikie6741bb02014-09-11 21:12:48 +000093 const MCSection *OffsetSection = nullptr);
David Blaikie85f80d72014-04-23 18:54:00 +000094
David Blaikie85f80d72014-04-23 18:54:00 +000095 /// \brief Returns the string pool.
David Blaikiedaefdbf2014-04-25 21:34:35 +000096 DwarfStringPool &getStringPool() { return StrPool; }
David Blaikief2999472014-10-23 00:16:05 +000097
Adrian Prantlca7e4702015-02-10 23:18:28 +000098 /// \returns false if the variable was merged with a previous one.
99 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
David Blaikie80e5b1e2014-10-24 17:57:34 +0000100
101 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
102 return ScopeVariables;
103 }
David Blaikief6dac292014-11-01 17:21:26 +0000104
105 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
106 return AbstractSPDies;
107 }
David Blaikie9bfd7a92014-11-04 22:12:18 +0000108
109 void insertDIE(const MDNode *TypeMD, DIE *Die) {
110 MDTypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
111 }
112 DIE *getDIE(const MDNode *TypeMD) {
113 return MDTypeNodeToDieMap.lookup(TypeMD);
114 }
David Blaikie85f80d72014-04-23 18:54:00 +0000115};
116}
117#endif