blob: 8b4e3347265bf535308248a6ae2893b4215134ce [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"
Benjamin Kramer391be792016-01-27 19:29:56 +000019#include "llvm/IR/Metadata.h"
David Blaikie85f80d72014-04-23 18:54:00 +000020#include "llvm/Support/Allocator.h"
David Blaikie85f80d72014-04-23 18:54:00 +000021#include <memory>
Chandler Carruthd9903882015-01-14 11:23:27 +000022#include <string>
23#include <vector>
David Blaikie85f80d72014-04-23 18:54:00 +000024
25namespace llvm {
26class AsmPrinter;
David Blaikief2999472014-10-23 00:16:05 +000027class DbgVariable;
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000028class DwarfCompileUnit;
David Blaikie85f80d72014-04-23 18:54:00 +000029class DwarfUnit;
30class DIEAbbrev;
31class MCSymbol;
32class DIE;
David Blaikief2999472014-10-23 00:16:05 +000033class LexicalScope;
David Blaikie85f80d72014-04-23 18:54:00 +000034class StringRef;
35class DwarfDebug;
36class MCSection;
Duncan P. N. Exon Smith9d50e822015-05-24 16:54:59 +000037class MDNode;
David Blaikie85f80d72014-04-23 18:54:00 +000038class DwarfFile {
39 // Target of Dwarf emission, used for sizing of abbreviations.
40 AsmPrinter *Asm;
41
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +000042 BumpPtrAllocator AbbrevAllocator;
43
David Blaikie85f80d72014-04-23 18:54:00 +000044 // Used to uniquely define abbreviations.
45 FoldingSet<DIEAbbrev> AbbreviationsSet;
46
47 // A list of all the unique abbreviations in use.
48 std::vector<DIEAbbrev *> Abbreviations;
49
50 // A pointer to all units in the section.
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000051 SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;
David Blaikie85f80d72014-04-23 18:54:00 +000052
David Blaikiedaefdbf2014-04-25 21:34:35 +000053 DwarfStringPool StrPool;
David Blaikie85f80d72014-04-23 18:54:00 +000054
David Blaikie80e5b1e2014-10-24 17:57:34 +000055 // Collection of dbg variables of a scope.
56 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
57
David Blaikief6dac292014-11-01 17:21:26 +000058 // Collection of abstract subprogram DIEs.
59 DenseMap<const MDNode *, DIE *> AbstractSPDies;
60
David Blaikie9bfd7a92014-11-04 22:12:18 +000061 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
62 /// be shared across CUs, that is why we keep the map here instead
63 /// of in DwarfCompileUnit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000064 DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
David Blaikie9bfd7a92014-11-04 22:12:18 +000065
David Blaikie85f80d72014-04-23 18:54:00 +000066public:
Frederic Riss9412d632015-03-04 02:30:17 +000067 DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
David Blaikie85f80d72014-04-23 18:54:00 +000068
69 ~DwarfFile();
70
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000071 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
72 return CUs;
73 }
David Blaikie85f80d72014-04-23 18:54:00 +000074
75 /// \brief Compute the size and offset of a DIE given an incoming Offset.
76 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
77
78 /// \brief Compute the size and offset of all the DIEs.
79 void computeSizeAndOffsets();
80
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000081 /// \brief Compute the size and offset of all the DIEs in the given unit.
82 /// \returns The size of the root DIE.
83 unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
84
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +000085 /// Define a unique number for the abbreviation.
86 ///
87 /// Compute the abbreviation for \c Die, look up its unique number, and
88 /// return a reference to it in the uniquing table.
89 DIEAbbrev &assignAbbrevNumber(DIE &Die);
David Blaikie85f80d72014-04-23 18:54:00 +000090
91 /// \brief Add a unit to the list of CUs.
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000092 void addUnit(std::unique_ptr<DwarfCompileUnit> U);
David Blaikie85f80d72014-04-23 18:54:00 +000093
94 /// \brief Emit all of the units to the section listed with the given
95 /// abbreviation section.
Rafael Espindola063d7252015-03-10 16:58:10 +000096 void emitUnits(bool UseOffsets);
David Blaikie85f80d72014-04-23 18:54:00 +000097
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000098 /// \brief Emit the given unit to its section.
99 void emitUnit(DwarfUnit *U, bool UseOffsets);
100
David Blaikie85f80d72014-04-23 18:54:00 +0000101 /// \brief Emit a set of abbreviations to the specific section.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000102 void emitAbbrevs(MCSection *);
David Blaikie85f80d72014-04-23 18:54:00 +0000103
104 /// \brief Emit all of the strings to the section given.
Rafael Espindola0709a7b2015-05-21 19:20:38 +0000105 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
David Blaikie85f80d72014-04-23 18:54:00 +0000106
David Blaikie85f80d72014-04-23 18:54:00 +0000107 /// \brief Returns the string pool.
David Blaikiedaefdbf2014-04-25 21:34:35 +0000108 DwarfStringPool &getStringPool() { return StrPool; }
David Blaikief2999472014-10-23 00:16:05 +0000109
Adrian Prantlca7e4702015-02-10 23:18:28 +0000110 /// \returns false if the variable was merged with a previous one.
111 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
David Blaikie80e5b1e2014-10-24 17:57:34 +0000112
113 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
114 return ScopeVariables;
115 }
David Blaikief6dac292014-11-01 17:21:26 +0000116
117 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
118 return AbstractSPDies;
119 }
David Blaikie9bfd7a92014-11-04 22:12:18 +0000120
121 void insertDIE(const MDNode *TypeMD, DIE *Die) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000122 DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
David Blaikie9bfd7a92014-11-04 22:12:18 +0000123 }
124 DIE *getDIE(const MDNode *TypeMD) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000125 return DITypeNodeToDieMap.lookup(TypeMD);
David Blaikie9bfd7a92014-11-04 22:12:18 +0000126 }
David Blaikie85f80d72014-04-23 18:54:00 +0000127};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000128}
David Blaikie85f80d72014-04-23 18:54:00 +0000129#endif