blob: 6e4625ba4116fcd8c3f026bab9334996057ac988 [file] [log] [blame]
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +00001//===- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework ---------*- C++ -*-===//
David Blaikie85f80d72014-04-23 18:54:00 +00002//
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 "DwarfStringPool.h"
David Blaikie85f80d72014-04-23 18:54:00 +000014#include "llvm/ADT/DenseMap.h"
David Blaikie85f80d72014-04-23 18:54:00 +000015#include "llvm/ADT/SmallVector.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000016#include "llvm/ADT/StringRef.h"
Greg Clayton3462a422016-12-08 01:03:48 +000017#include "llvm/CodeGen/DIE.h"
David Blaikie85f80d72014-04-23 18:54:00 +000018#include "llvm/Support/Allocator.h"
David Blaikie85f80d72014-04-23 18:54:00 +000019#include <memory>
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000020#include <utility>
David Blaikie85f80d72014-04-23 18:54:00 +000021
22namespace llvm {
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000023
David Blaikie85f80d72014-04-23 18:54:00 +000024class AsmPrinter;
David Blaikief2999472014-10-23 00:16:05 +000025class DbgVariable;
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000026class DwarfCompileUnit;
David Blaikie85f80d72014-04-23 18:54:00 +000027class DwarfUnit;
David Blaikief2999472014-10-23 00:16:05 +000028class LexicalScope;
David Blaikie85f80d72014-04-23 18:54:00 +000029class MCSection;
Duncan P. N. Exon Smith9d50e822015-05-24 16:54:59 +000030class MDNode;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000031
David Blaikie85f80d72014-04-23 18:54:00 +000032class DwarfFile {
33 // Target of Dwarf emission, used for sizing of abbreviations.
34 AsmPrinter *Asm;
35
Duncan P. N. Exon Smith815a6eb52015-05-27 22:31:41 +000036 BumpPtrAllocator AbbrevAllocator;
37
David Blaikie85f80d72014-04-23 18:54:00 +000038 // Used to uniquely define abbreviations.
Greg Clayton3462a422016-12-08 01:03:48 +000039 DIEAbbrevSet Abbrevs;
David Blaikie85f80d72014-04-23 18:54:00 +000040
41 // A pointer to all units in the section.
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000042 SmallVector<std::unique_ptr<DwarfCompileUnit>, 1> CUs;
David Blaikie85f80d72014-04-23 18:54:00 +000043
David Blaikiedaefdbf2014-04-25 21:34:35 +000044 DwarfStringPool StrPool;
David Blaikie85f80d72014-04-23 18:54:00 +000045
David Blaikie80e5b1e2014-10-24 17:57:34 +000046 // Collection of dbg variables of a scope.
47 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> ScopeVariables;
48
David Blaikief6dac292014-11-01 17:21:26 +000049 // Collection of abstract subprogram DIEs.
50 DenseMap<const MDNode *, DIE *> AbstractSPDies;
David Blaikie488393f2017-05-12 01:13:45 +000051 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
David Blaikief6dac292014-11-01 17:21:26 +000052
David Blaikie9bfd7a92014-11-04 22:12:18 +000053 /// Maps MDNodes for type system with the corresponding DIEs. These DIEs can
54 /// be shared across CUs, that is why we keep the map here instead
55 /// of in DwarfCompileUnit.
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000056 DenseMap<const MDNode *, DIE *> DITypeNodeToDieMap;
David Blaikie9bfd7a92014-11-04 22:12:18 +000057
David Blaikie85f80d72014-04-23 18:54:00 +000058public:
Frederic Riss9412d632015-03-04 02:30:17 +000059 DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA);
David Blaikie85f80d72014-04-23 18:54:00 +000060
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000061 const SmallVectorImpl<std::unique_ptr<DwarfCompileUnit>> &getUnits() {
62 return CUs;
63 }
David Blaikie85f80d72014-04-23 18:54:00 +000064
65 /// \brief Compute the size and offset of a DIE given an incoming Offset.
66 unsigned computeSizeAndOffset(DIE &Die, unsigned Offset);
67
68 /// \brief Compute the size and offset of all the DIEs.
69 void computeSizeAndOffsets();
70
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000071 /// \brief Compute the size and offset of all the DIEs in the given unit.
72 /// \returns The size of the root DIE.
73 unsigned computeSizeAndOffsetsForUnit(DwarfUnit *TheU);
74
David Blaikie85f80d72014-04-23 18:54:00 +000075 /// \brief Add a unit to the list of CUs.
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000076 void addUnit(std::unique_ptr<DwarfCompileUnit> U);
David Blaikie85f80d72014-04-23 18:54:00 +000077
78 /// \brief Emit all of the units to the section listed with the given
79 /// abbreviation section.
Rafael Espindola063d7252015-03-10 16:58:10 +000080 void emitUnits(bool UseOffsets);
David Blaikie85f80d72014-04-23 18:54:00 +000081
Peter Collingbourne7c384cc2016-02-11 19:57:46 +000082 /// \brief Emit the given unit to its section.
83 void emitUnit(DwarfUnit *U, bool UseOffsets);
84
David Blaikie85f80d72014-04-23 18:54:00 +000085 /// \brief Emit a set of abbreviations to the specific section.
Rafael Espindola0709a7b2015-05-21 19:20:38 +000086 void emitAbbrevs(MCSection *);
David Blaikie85f80d72014-04-23 18:54:00 +000087
88 /// \brief Emit all of the strings to the section given.
Rafael Espindola0709a7b2015-05-21 19:20:38 +000089 void emitStrings(MCSection *StrSection, MCSection *OffsetSection = nullptr);
David Blaikie85f80d72014-04-23 18:54:00 +000090
David Blaikie85f80d72014-04-23 18:54:00 +000091 /// \brief Returns the string pool.
David Blaikiedaefdbf2014-04-25 21:34:35 +000092 DwarfStringPool &getStringPool() { return StrPool; }
David Blaikief2999472014-10-23 00:16:05 +000093
Adrian Prantlca7e4702015-02-10 23:18:28 +000094 /// \returns false if the variable was merged with a previous one.
95 bool addScopeVariable(LexicalScope *LS, DbgVariable *Var);
David Blaikie80e5b1e2014-10-24 17:57:34 +000096
97 DenseMap<LexicalScope *, SmallVector<DbgVariable *, 8>> &getScopeVariables() {
98 return ScopeVariables;
99 }
David Blaikief6dac292014-11-01 17:21:26 +0000100
101 DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
102 return AbstractSPDies;
103 }
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000104
David Blaikie488393f2017-05-12 01:13:45 +0000105 DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> &getAbstractVariables() {
106 return AbstractVariables;
107 }
David Blaikie9bfd7a92014-11-04 22:12:18 +0000108
109 void insertDIE(const MDNode *TypeMD, DIE *Die) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000110 DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
David Blaikie9bfd7a92014-11-04 22:12:18 +0000111 }
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000112
David Blaikie9bfd7a92014-11-04 22:12:18 +0000113 DIE *getDIE(const MDNode *TypeMD) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000114 return DITypeNodeToDieMap.lookup(TypeMD);
David Blaikie9bfd7a92014-11-04 22:12:18 +0000115 }
David Blaikie85f80d72014-04-23 18:54:00 +0000116};
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +0000117
118} // end namespace llvm
119
120#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H