[CodeGen] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

llvm-svn: 311124
This commit is contained in:
Eugene Zelenko 2017-08-17 21:26:39 +00:00
parent 595f95a0c9
commit 9caba155e1
16 changed files with 360 additions and 220 deletions

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---*- C++ -*--===//
//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
//
// The LLVM Compiler Infrastructure
//
@ -8,9 +8,12 @@
//===----------------------------------------------------------------------===//
#include "AddressPool.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include <utility>
using namespace llvm;

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/AddressPool.h - Dwarf Debug Framework -----*- C++ -*--===//
//===- llvm/CodeGen/AddressPool.h - Dwarf Debug Framework -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -11,11 +11,13 @@
#define LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
#include "llvm/ADT/DenseMap.h"
#include "llvm/MC/MCSymbol.h"
namespace llvm {
class MCSection;
class AsmPrinter;
class MCSection;
class MCSymbol;
// Collection of addresses for this unit and assorted labels.
// A Symbol->unsigned mapping of addresses used by indirect
// references.
@ -23,6 +25,7 @@ class AddressPool {
struct AddressPoolEntry {
unsigned Number;
bool TLS;
AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
};
DenseMap<const MCSymbol *, AddressPoolEntry> Pool;
@ -31,10 +34,10 @@ class AddressPool {
/// the last "resetUsedFlag" call. Used to implement type unit fallback - a
/// type that references addresses cannot be placed in a type unit when using
/// fission.
bool HasBeenUsed;
bool HasBeenUsed = false;
public:
AddressPool() : HasBeenUsed(false) {}
AddressPool() = default;
/// \brief Returns the index into the address pool with the given
/// label/symbol.
@ -48,5 +51,7 @@ public:
void resetUsedFlag() { HasBeenUsed = false; }
};
}
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp -------------===//
//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp --------------===//
//
// The LLVM Compiler Infrastructure
//
@ -9,17 +9,24 @@
#include "DbgValueHistoryCalculator.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLowering.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
#include <cassert>
#include <map>
#include <utility>
using namespace llvm;
#define DEBUG_TYPE "dwarfdebug"
@ -72,10 +79,12 @@ unsigned DbgValueHistoryMap::getRegisterForVar(InlinedVariable Var) const {
}
namespace {
// Maps physreg numbers to the variables they describe.
typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
typedef std::map<unsigned, SmallVector<InlinedVariable, 1>> RegDescribedVarsMap;
}
using InlinedVariable = DbgValueHistoryMap::InlinedVariable;
using RegDescribedVarsMap = std::map<unsigned, SmallVector<InlinedVariable, 1>>;
} // end anonymous namespace
// \brief Claim that @Var is not described by @RegNo anymore.
static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
@ -83,7 +92,7 @@ static void dropRegDescribedVar(RegDescribedVarsMap &RegVars, unsigned RegNo,
const auto &I = RegVars.find(RegNo);
assert(RegNo != 0U && I != RegVars.end());
auto &VarSet = I->second;
const auto &VarPos = find(VarSet, Var);
const auto &VarPos = llvm::find(VarSet, Var);
assert(VarPos != VarSet.end());
VarSet.erase(VarPos);
// Don't keep empty sets in a map to keep it as small as possible.

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h ----*- C++ -*--===//
//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -12,10 +12,12 @@
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include <utility>
namespace llvm {
class DILocalVariable;
class DILocation;
class MachineFunction;
class MachineInstr;
class TargetRegisterInfo;
@ -29,11 +31,11 @@ class DbgValueHistoryMap {
// instruction of the next instruction range, or until the end of the
// function.
public:
typedef std::pair<const MachineInstr *, const MachineInstr *> InstrRange;
typedef SmallVector<InstrRange, 4> InstrRanges;
typedef std::pair<const DILocalVariable *, const DILocation *>
InlinedVariable;
typedef MapVector<InlinedVariable, InstrRanges> InstrRangesMap;
using InstrRange = std::pair<const MachineInstr *, const MachineInstr *>;
using InstrRanges = SmallVector<InstrRange, 4>;
using InlinedVariable =
std::pair<const DILocalVariable *, const DILocation *>;
using InstrRangesMap = MapVector<InlinedVariable, InstrRanges>;
private:
InstrRangesMap VarInstrRanges;
@ -41,6 +43,7 @@ private:
public:
void startInstrRange(InlinedVariable Var, const MachineInstr &MI);
void endInstrRange(InlinedVariable Var, const MachineInstr &MI);
// Returns register currently describing @Var. If @Var is currently
// unaccessible or is not described by a register, returns 0.
unsigned getRegisterForVar(InlinedVariable Var) const;
@ -54,6 +57,7 @@ public:
void calculateDbgValueHistory(const MachineFunction *MF,
const TargetRegisterInfo *TRI,
DbgValueHistoryMap &Result);
}
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H

View File

@ -1,4 +1,4 @@
//=-- llvm/CodeGen/DwarfAccelTable.cpp - Dwarf Accelerator Tables -*- C++ -*-=//
//===- llvm/CodeGen/DwarfAccelTable.cpp - Dwarf Accelerator Tables --------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,16 +12,22 @@
//===----------------------------------------------------------------------===//
#include "DwarfAccelTable.h"
#include "DwarfCompileUnit.h"
#include "DwarfDebug.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <limits>
#include <vector>
using namespace llvm;
@ -142,13 +148,13 @@ void DwarfAccelTable::EmitBuckets(AsmPrinter *Asm) {
unsigned index = 0;
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
Asm->OutStreamer->AddComment("Bucket " + Twine(i));
if (Buckets[i].size() != 0)
if (!Buckets[i].empty())
Asm->EmitInt32(index);
else
Asm->EmitInt32(UINT32_MAX);
Asm->EmitInt32(std::numeric_limits<uint32_t>::max());
// Buckets point in the list of hashes, not to the data. Do not
// increment the index multiple times in case of hash collisions.
uint64_t PrevHash = UINT64_MAX;
uint64_t PrevHash = std::numeric_limits<uint64_t>::max();
for (auto *HD : Buckets[i]) {
uint32_t HashValue = HD->HashValue;
if (PrevHash != HashValue)
@ -161,7 +167,7 @@ void DwarfAccelTable::EmitBuckets(AsmPrinter *Asm) {
// Walk through the buckets and emit the individual hashes for each
// bucket.
void DwarfAccelTable::EmitHashes(AsmPrinter *Asm) {
uint64_t PrevHash = UINT64_MAX;
uint64_t PrevHash = std::numeric_limits<uint64_t>::max();
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
for (HashList::const_iterator HI = Buckets[i].begin(),
HE = Buckets[i].end();
@ -181,7 +187,7 @@ void DwarfAccelTable::EmitHashes(AsmPrinter *Asm) {
// beginning of the section. The non-section symbol will be output later
// when we emit the actual data.
void DwarfAccelTable::emitOffsets(AsmPrinter *Asm, const MCSymbol *SecBegin) {
uint64_t PrevHash = UINT64_MAX;
uint64_t PrevHash = std::numeric_limits<uint64_t>::max();
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
for (HashList::const_iterator HI = Buckets[i].begin(),
HE = Buckets[i].end();
@ -205,13 +211,14 @@ void DwarfAccelTable::emitOffsets(AsmPrinter *Asm, const MCSymbol *SecBegin) {
// Terminate each HashData bucket with 0.
void DwarfAccelTable::EmitData(AsmPrinter *Asm, DwarfDebug *D) {
for (size_t i = 0, e = Buckets.size(); i < e; ++i) {
uint64_t PrevHash = UINT64_MAX;
uint64_t PrevHash = std::numeric_limits<uint64_t>::max();
for (HashList::const_iterator HI = Buckets[i].begin(),
HE = Buckets[i].end();
HI != HE; ++HI) {
// Terminate the previous entry if there is no hash collision
// with the current one.
if (PrevHash != UINT64_MAX && PrevHash != (*HI)->HashValue)
if (PrevHash != std::numeric_limits<uint64_t>::max() &&
PrevHash != (*HI)->HashValue)
Asm->EmitInt32(0);
// Remember to emit the label for our offset.
Asm->OutStreamer->EmitLabel((*HI)->Sym);
@ -257,31 +264,30 @@ void DwarfAccelTable::emit(AsmPrinter *Asm, const MCSymbol *SecBegin,
}
#ifndef NDEBUG
void DwarfAccelTable::print(raw_ostream &O) {
void DwarfAccelTable::print(raw_ostream &OS) {
Header.print(OS);
HeaderData.print(OS);
Header.print(O);
HeaderData.print(O);
O << "Entries: \n";
OS << "Entries: \n";
for (StringMap<DataArray>::const_iterator EI = Entries.begin(),
EE = Entries.end();
EI != EE; ++EI) {
O << "Name: " << EI->getKeyData() << "\n";
OS << "Name: " << EI->getKeyData() << "\n";
for (HashDataContents *HD : EI->second.Values)
HD->print(O);
HD->print(OS);
}
O << "Buckets and Hashes: \n";
OS << "Buckets and Hashes: \n";
for (size_t i = 0, e = Buckets.size(); i < e; ++i)
for (HashList::const_iterator HI = Buckets[i].begin(),
HE = Buckets[i].end();
HI != HE; ++HI)
(*HI)->print(O);
(*HI)->print(OS);
O << "Data: \n";
OS << "Data: \n";
for (std::vector<HashData *>::const_iterator DI = Data.begin(),
DE = Data.end();
DI != DE; ++DI)
(*DI)->print(O);
(*DI)->print(OS);
}
#endif

View File

@ -1,4 +1,4 @@
//==-- llvm/CodeGen/DwarfAccelTable.h - Dwarf Accelerator Tables -*- C++ -*-==//
//==- llvm/CodeGen/DwarfAccelTable.h - Dwarf Accelerator Tables --*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
@ -15,16 +15,19 @@
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFACCELTABLE_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
#include <cstddef>
#include <cstdint>
#include <vector>
// The dwarf accelerator tables are an indirect hash table optimized
@ -65,7 +68,6 @@ class AsmPrinter;
class DwarfDebug;
class DwarfAccelTable {
static uint32_t HashDJB(StringRef Str) {
uint32_t h = 5381;
for (unsigned i = 0, e = Str.size(); i != e; ++i)
@ -75,34 +77,33 @@ class DwarfAccelTable {
// Helper function to compute the number of buckets needed based on
// the number of unique hashes.
void ComputeBucketCount(void);
void ComputeBucketCount();
struct TableHeader {
uint32_t magic; // 'HASH' magic value to allow endian detection
uint16_t version; // Version number.
uint16_t hash_function; // The hash function enumeration that was used.
uint32_t bucket_count; // The number of buckets in this hash table.
uint32_t hashes_count; // The total number of unique hash values
// and hash data offsets in this table.
uint32_t header_data_len; // The bytes to skip to get to the hash
// indexes (buckets) for correct alignment.
uint32_t magic = MagicHash; // 'HASH' magic value to allow endian detection
uint16_t version = 1; // Version number.
uint16_t hash_function = dwarf::DW_hash_function_djb;
// The hash function enumeration that was used.
uint32_t bucket_count = 0; // The number of buckets in this hash table.
uint32_t hashes_count = 0; // The total number of unique hash values
// and hash data offsets in this table.
uint32_t header_data_len; // The bytes to skip to get to the hash
// indexes (buckets) for correct alignment.
// Also written to disk is the implementation specific header data.
static const uint32_t MagicHash = 0x48415348;
TableHeader(uint32_t data_len)
: magic(MagicHash), version(1),
hash_function(dwarf::DW_hash_function_djb), bucket_count(0),
hashes_count(0), header_data_len(data_len) {}
TableHeader(uint32_t data_len) : header_data_len(data_len) {}
#ifndef NDEBUG
void print(raw_ostream &O) {
O << "Magic: " << format("0x%x", magic) << "\n"
<< "Version: " << version << "\n"
<< "Hash Function: " << hash_function << "\n"
<< "Bucket Count: " << bucket_count << "\n"
<< "Header Data Length: " << header_data_len << "\n";
void print(raw_ostream &OS) {
OS << "Magic: " << format("0x%x", magic) << "\n"
<< "Version: " << version << "\n"
<< "Hash Function: " << hash_function << "\n"
<< "Bucket Count: " << bucket_count << "\n"
<< "Header Data Length: " << header_data_len << "\n";
}
void dump() { print(dbgs()); }
#endif
};
@ -127,11 +128,13 @@ public:
uint16_t form; // DWARF DW_FORM_ defines
constexpr Atom(uint16_t type, uint16_t form) : type(type), form(form) {}
#ifndef NDEBUG
void print(raw_ostream &O) {
O << "Type: " << dwarf::AtomTypeString(type) << "\n"
<< "Form: " << dwarf::FormEncodingString(form) << "\n";
void print(raw_ostream &OS) {
OS << "Type: " << dwarf::AtomTypeString(type) << "\n"
<< "Form: " << dwarf::FormEncodingString(form) << "\n";
}
void dump() { print(dbgs()); }
#endif
};
@ -145,11 +148,12 @@ private:
: die_offset_base(offset), Atoms(AtomList.begin(), AtomList.end()) {}
#ifndef NDEBUG
void print(raw_ostream &O) {
O << "die_offset_base: " << die_offset_base << "\n";
void print(raw_ostream &OS) {
OS << "die_offset_base: " << die_offset_base << "\n";
for (size_t i = 0; i < Atoms.size(); i++)
Atoms[i].print(O);
Atoms[i].print(OS);
}
void dump() { print(dbgs()); }
#endif
};
@ -168,11 +172,12 @@ public:
char Flags; // Specific flags to output
HashDataContents(const DIE *D, char Flags) : Die(D), Flags(Flags) {}
#ifndef NDEBUG
void print(raw_ostream &O) const {
O << " Offset: " << Die->getOffset() << "\n";
O << " Tag: " << dwarf::TagString(Die->getTag()) << "\n";
O << " Flags: " << Flags << "\n";
void print(raw_ostream &OS) const {
OS << " Offset: " << Die->getOffset() << "\n"
<< " Tag: " << dwarf::TagString(Die->getTag()) << "\n"
<< " Flags: " << Flags << "\n";
}
#endif
};
@ -183,39 +188,41 @@ private:
DwarfStringPoolEntryRef Name;
std::vector<HashDataContents *> Values;
};
friend struct HashData;
struct HashData {
StringRef Str;
uint32_t HashValue;
MCSymbol *Sym;
DwarfAccelTable::DataArray &Data; // offsets
HashData(StringRef S, DwarfAccelTable::DataArray &Data)
: Str(S), Data(Data) {
HashValue = DwarfAccelTable::HashDJB(S);
}
#ifndef NDEBUG
void print(raw_ostream &O) {
O << "Name: " << Str << "\n";
O << " Hash Value: " << format("0x%x", HashValue) << "\n";
O << " Symbol: ";
void print(raw_ostream &OS) {
OS << "Name: " << Str << "\n";
OS << " Hash Value: " << format("0x%x", HashValue) << "\n";
OS << " Symbol: ";
if (Sym)
O << *Sym;
OS << *Sym;
else
O << "<none>";
O << "\n";
OS << "<none>";
OS << "\n";
for (HashDataContents *C : Data.Values) {
O << " Offset: " << C->Die->getOffset() << "\n";
O << " Tag: " << dwarf::TagString(C->Die->getTag()) << "\n";
O << " Flags: " << C->Flags << "\n";
OS << " Offset: " << C->Die->getOffset() << "\n";
OS << " Tag: " << dwarf::TagString(C->Die->getTag()) << "\n";
OS << " Flags: " << C->Flags << "\n";
}
}
void dump() { print(dbgs()); }
#endif
};
DwarfAccelTable(const DwarfAccelTable &) = delete;
void operator=(const DwarfAccelTable &) = delete;
// Internal Functions
void EmitHeader(AsmPrinter *);
void EmitBuckets(AsmPrinter *);
@ -231,25 +238,31 @@ private:
TableHeaderData HeaderData;
std::vector<HashData *> Data;
typedef StringMap<DataArray, BumpPtrAllocator &> StringEntries;
using StringEntries = StringMap<DataArray, BumpPtrAllocator &>;
StringEntries Entries;
// Buckets/Hashes/Offsets
typedef std::vector<HashData *> HashList;
typedef std::vector<HashList> BucketList;
using HashList = std::vector<HashData *>;
using BucketList = std::vector<HashList>;
BucketList Buckets;
HashList Hashes;
// Public Implementation
public:
DwarfAccelTable(ArrayRef<DwarfAccelTable::Atom>);
DwarfAccelTable(const DwarfAccelTable &) = delete;
DwarfAccelTable &operator=(const DwarfAccelTable &) = delete;
void AddName(DwarfStringPoolEntryRef Name, const DIE *Die, char Flags = 0);
void FinalizeTable(AsmPrinter *, StringRef);
void emit(AsmPrinter *, const MCSymbol *, DwarfDebug *);
#ifndef NDEBUG
void print(raw_ostream &O);
void print(raw_ostream &OS);
void dump() { print(dbgs()); }
#endif
};
}
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFACCELTABLE_H

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units -----------===//
//===- llvm/CodeGen/DwarfCompileUnit.cpp - Dwarf Compile Units ------------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,39 +12,58 @@
//===----------------------------------------------------------------------===//
#include "DwarfCompileUnit.h"
#include "AddressPool.h"
#include "DwarfDebug.h"
#include "DwarfExpression.h"
#include "DwarfUnit.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/IR/Constants.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/MC/MachineLocation.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/Casting.h"
#include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <utility>
namespace llvm {
using namespace llvm;
DwarfCompileUnit::DwarfCompileUnit(unsigned UID, const DICompileUnit *Node,
AsmPrinter *A, DwarfDebug *DW,
DwarfFile *DWU)
: DwarfUnit(dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), UniqueID(UID),
Skeleton(nullptr), BaseAddress(nullptr) {
: DwarfUnit(dwarf::DW_TAG_compile_unit, Node, A, DW, DWU), UniqueID(UID) {
insertDIE(Node, &getUnitDie());
MacroLabelBegin = Asm->createTempSymbol("cu_macro_begin");
}
/// addLabelAddress - Add a dwarf label attribute data and value using
/// DW_FORM_addr or DW_FORM_GNU_addr_index.
///
void DwarfCompileUnit::addLabelAddress(DIE &Die, dwarf::Attribute Attribute,
const MCSymbol *Label) {
// Don't use the address pool in non-fission or in the skeleton unit itself.
// FIXME: Once GDB supports this, it's probably worthwhile using the address
// pool from the skeleton - maybe even in non-fission (possibly fewer
@ -718,7 +737,7 @@ DbgVariable *DwarfCompileUnit::getExistingAbstractVariable(
void DwarfCompileUnit::createAbstractVariable(const DILocalVariable *Var,
LexicalScope *Scope) {
assert(Scope && Scope->isAbstractScope());
auto AbsDbgVariable = make_unique<DbgVariable>(Var, /* IA */ nullptr);
auto AbsDbgVariable = llvm::make_unique<DbgVariable>(Var, /* IA */ nullptr);
DU->addScopeVariable(Scope, AbsDbgVariable.get());
getAbstractVariables()[Var] = std::move(AbsDbgVariable);
}
@ -879,4 +898,3 @@ bool DwarfCompileUnit::includeMinimalInlineScopes() const {
return getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly ||
(DD->useSplitDwarf() && !Skeleton);
}
} // end llvm namespace

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit ---*- C++ -*--===//
//===- llvm/CodeGen/DwarfCompileUnit.h - Dwarf Compile Unit -----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -14,19 +14,32 @@
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H
#include "DbgValueHistoryCalculator.h"
#include "DwarfDebug.h"
#include "DwarfUnit.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Support/Casting.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <memory>
namespace llvm {
class StringRef;
class AsmPrinter;
class DIE;
class DwarfDebug;
class DwarfFile;
class GlobalVariable;
class MCExpr;
class MCSymbol;
class LexicalScope;
class MDNode;
class DwarfCompileUnit final : public DwarfUnit {
/// A numeric ID unique among all CUs in the module
@ -37,7 +50,7 @@ class DwarfCompileUnit final : public DwarfUnit {
DIE::value_iterator StmtListValue;
/// Skeleton unit associated with this unit.
DwarfCompileUnit *Skeleton;
DwarfCompileUnit *Skeleton = nullptr;
/// The start of the unit within its section.
MCSymbol *LabelBegin;
@ -45,9 +58,8 @@ class DwarfCompileUnit final : public DwarfUnit {
/// The start of the unit macro info within macro section.
MCSymbol *MacroLabelBegin;
typedef llvm::SmallVector<const MDNode *, 8> ImportedEntityList;
typedef llvm::DenseMap<const MDNode *, ImportedEntityList>
ImportedEntityMap;
using ImportedEntityList = SmallVector<const MDNode *, 8>;
using ImportedEntityMap = DenseMap<const MDNode *, ImportedEntityList>;
ImportedEntityMap ImportedEntities;
@ -66,7 +78,7 @@ class DwarfCompileUnit final : public DwarfUnit {
// The base address of this unit, if any. Used for relative references in
// ranges/locs.
const MCSymbol *BaseAddress;
const MCSymbol *BaseAddress = nullptr;
DenseMap<const MDNode *, DIE *> AbstractSPDies;
DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> AbstractVariables;
@ -164,6 +176,7 @@ public:
void attachRangesOrLowHighPC(DIE &D,
const SmallVectorImpl<InsnRange> &Ranges);
/// \brief This scope represents inlined body of a function. Construct
/// DIE to represent this concrete inlined copy of the function.
DIE *constructInlinedScopeDIE(LexicalScope *Scope);
@ -195,8 +208,9 @@ public:
void finishSubprogramDefinition(const DISubprogram *SP);
void finishVariableDefinition(const DbgVariable &Var);
/// Find abstract variable associated with Var.
typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
using InlinedVariable = DbgValueHistoryMap::InlinedVariable;
DbgVariable *getExistingAbstractVariable(InlinedVariable IV,
const DILocalVariable *&Cleansed);
DbgVariable *getExistingAbstractVariable(InlinedVariable IV);
@ -277,6 +291,6 @@ public:
const MCSymbol *getBaseAddress() const { return BaseAddress; }
};
} // end llvm namespace
} // end namespace llvm
#endif
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFCOMPILEUNIT_H

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ---------------===//
//===- llvm/CodeGen/DwarfDebug.cpp - Dwarf Debug Framework ----------------===//
//
// The LLVM Compiler Infrastructure
//
@ -15,43 +15,67 @@
#include "ByteStreamer.h"
#include "DIEHash.h"
#include "DebugLocEntry.h"
#include "DebugLocStream.h"
#include "DwarfAccelTable.h"
#include "DwarfCompileUnit.h"
#include "DwarfExpression.h"
#include "DwarfFile.h"
#include "DwarfUnit.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/MC/MCTargetOptions.h"
#include "llvm/MC/MachineLocation.h"
#include "llvm/MC/SectionKind.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Support/MD5.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetFrameLowering.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <iterator>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
@ -79,9 +103,7 @@ static cl::opt<bool> SplitDwarfCrossCuReferences(
"split-dwarf-cross-cu-references", cl::Hidden,
cl::desc("Enable cross-cu references in DWO files"), cl::init(false));
namespace {
enum DefaultOnOff { Default, Enable, Disable };
}
static cl::opt<DefaultOnOff> UnknownLocations(
"use-unknown-locations", cl::Hidden,
@ -111,6 +133,7 @@ enum LinkageNameOption {
AllLinkageNames,
AbstractLinkageNames
};
static cl::opt<LinkageNameOption>
DwarfLinkageNames("dwarf-linkage-names", cl::Hidden,
cl::desc("Which DWARF linkage-name attributes to emit."),
@ -146,8 +169,6 @@ bool DebugLocDwarfExpression::isFrameRegister(const TargetRegisterInfo &TRI,
return false;
}
//===----------------------------------------------------------------------===//
bool DbgVariable::isBlockByrefVariable() const {
assert(Var && "Invalid complex DbgVariable!");
return Var->getType().resolve()->isBlockByrefStruct();
@ -202,8 +223,10 @@ ArrayRef<DbgVariable::FrameIndexExpr> DbgVariable::getFrameIndexExprs() const {
if (FrameIndexExprs.size() == 1)
return FrameIndexExprs;
assert(all_of(FrameIndexExprs,
[](const FrameIndexExpr &A) { return A.Expr->isFragment(); }) &&
assert(llvm::all_of(FrameIndexExprs,
[](const FrameIndexExpr &A) {
return A.Expr->isFragment();
}) &&
"multiple FI expressions without DW_OP_LLVM_fragment");
std::sort(FrameIndexExprs.begin(), FrameIndexExprs.end(),
[](const FrameIndexExpr &A, const FrameIndexExpr &B) -> bool {
@ -229,9 +252,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
dwarf::DW_FORM_data4)),
AccelNamespace(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset,
dwarf::DW_FORM_data4)),
AccelTypes(TypeAtoms), DebuggerTuning(DebuggerKind::Default) {
CurFn = nullptr;
AccelTypes(TypeAtoms) {
const Triple &TT = Asm->TM.getTargetTriple();
// Make sure we know our "debugger tuning." The target option takes
@ -282,7 +303,7 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
}
// Define out of line so we don't have to include DwarfUnit.h in DwarfDebug.h.
DwarfDebug::~DwarfDebug() { }
DwarfDebug::~DwarfDebug() = default;
static bool isObjCClass(StringRef Name) {
return Name.startswith("+") || Name.startswith("-");
@ -421,7 +442,7 @@ DwarfDebug::getOrCreateDwarfCompileUnit(const DICompileUnit *DIUnit) {
StringRef FN = DIUnit->getFilename();
CompilationDir = DIUnit->getDirectory();
auto OwnedUnit = make_unique<DwarfCompileUnit>(
auto OwnedUnit = llvm::make_unique<DwarfCompileUnit>(
InfoHolder.getUnits().size(), DIUnit, Asm, this, &InfoHolder);
DwarfCompileUnit &NewCU = *OwnedUnit;
DIE &Die = NewCU.getUnitDie();
@ -795,6 +816,7 @@ void DwarfDebug::ensureAbstractVariableIsCreatedIfScoped(DwarfCompileUnit &CU,
LScopes.findAbstractScope(cast_or_null<DILocalScope>(ScopeNode)))
CU.createAbstractVariable(Cleansed, Scope);
}
// Collect variable information from side table maintained by MF.
void DwarfDebug::collectVariableInfoFromMFTable(
DwarfCompileUnit &TheCU, DenseSet<InlinedVariable> &Processed) {
@ -814,7 +836,7 @@ void DwarfDebug::collectVariableInfoFromMFTable(
continue;
ensureAbstractVariableIsCreatedIfScoped(TheCU, Var, Scope->getScopeNode());
auto RegVar = make_unique<DbgVariable>(Var.first, Var.second);
auto RegVar = llvm::make_unique<DbgVariable>(Var.first, Var.second);
RegVar->initializeMMI(VI.Expr, VI.Slot);
if (DbgVariable *DbgVar = MFVars.lookup(Var))
DbgVar->addMMIEntry(*RegVar);
@ -990,7 +1012,8 @@ DbgVariable *DwarfDebug::createConcreteVariable(DwarfCompileUnit &TheCU,
LexicalScope &Scope,
InlinedVariable IV) {
ensureAbstractVariableIsCreatedIfScoped(TheCU, IV, Scope.getScopeNode());
ConcreteVariables.push_back(make_unique<DbgVariable>(IV.first, IV.second));
ConcreteVariables.push_back(
llvm::make_unique<DbgVariable>(IV.first, IV.second));
InfoHolder.addScopeVariable(&Scope, ConcreteVariables.back().get());
return ConcreteVariables.back().get();
}
@ -1464,7 +1487,6 @@ static dwarf::PubIndexEntryDescriptor computeIndexValue(DwarfUnit *CU,
}
/// emitDebugPubNames - Emit visible names into a debug pubnames section.
///
void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
MCSection *PSec = GnuStyle
? Asm->getObjFileLowering().getDwarfGnuPubNamesSection()
@ -1597,7 +1619,7 @@ void DebugLocEntry::finalize(const AsmPrinter &AP,
const DebugLocEntry::Value &Value = Values[0];
if (Value.isFragment()) {
// Emit all fragments that belong to the same variable and range.
assert(all_of(Values, [](DebugLocEntry::Value P) {
assert(llvm::all_of(Values, [](DebugLocEntry::Value P) {
return P.isFragment();
}) && "all values are expected to be fragments");
assert(std::is_sorted(Values.begin(), Values.end()) &&
@ -1992,7 +2014,7 @@ void DwarfDebug::initSkeletonUnit(const DwarfUnit &U, DIE &Die,
// DW_AT_addr_base, DW_AT_ranges_base.
DwarfCompileUnit &DwarfDebug::constructSkeletonCU(const DwarfCompileUnit &CU) {
auto OwnedUnit = make_unique<DwarfCompileUnit>(
auto OwnedUnit = llvm::make_unique<DwarfCompileUnit>(
CU.getUniqueID(), CU.getCUNode(), Asm, this, &SkeletonHolder);
DwarfCompileUnit &NewCU = *OwnedUnit;
NewCU.setSection(Asm->getObjFileLowering().getDwarfInfoSection());
@ -2073,8 +2095,8 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
bool TopLevelType = TypeUnitsUnderConstruction.empty();
AddrPool.resetUsedFlag();
auto OwnedUnit = make_unique<DwarfTypeUnit>(CU, Asm, this, &InfoHolder,
getDwoLineTable(CU));
auto OwnedUnit = llvm::make_unique<DwarfTypeUnit>(CU, Asm, this, &InfoHolder,
getDwoLineTable(CU));
DwarfTypeUnit &NewTU = *OwnedUnit;
DIE &UnitDie = NewTU.getUnitDie();
TypeUnitsUnderConstruction.emplace_back(std::move(OwnedUnit), CTy);

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework ------*- C++ -*--===//
//===- llvm/CodeGen/DwarfDebug.h - Dwarf Debug Framework --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -14,39 +14,52 @@
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H
#include "AddressPool.h"
#include "DbgValueHistoryCalculator.h"
#include "DebugHandlerBase.h"
#include "DebugLocStream.h"
#include "DwarfAccelTable.h"
#include "DwarfFile.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/CodeGen/LexicalScopes.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/Metadata.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Target/TargetOptions.h"
#include <cassert>
#include <cstdint>
#include <limits>
#include <memory>
#include <utility>
#include <vector>
namespace llvm {
class AsmPrinter;
class ByteStreamer;
class ConstantInt;
class ConstantFP;
class DebugLocEntry;
class DIE;
class DwarfCompileUnit;
class DwarfDebug;
class DwarfTypeUnit;
class DwarfUnit;
class MachineModuleInfo;
class LexicalScope;
class MachineFunction;
class MCSection;
class MCSymbol;
class MDNode;
class Module;
//===----------------------------------------------------------------------===//
/// This class is used to track local variable information.
@ -88,7 +101,7 @@ public:
assert(!MInsn && "Already initialized?");
assert((!E || E->isValid()) && "Expected valid expression");
assert(FI != INT_MAX && "Expected valid index");
assert(FI != std::numeric_limits<int>::max() && "Expected valid index");
FrameIndexExprs.push_back({FI, E});
}
@ -110,10 +123,12 @@ public:
// Accessors.
const DILocalVariable *getVariable() const { return Var; }
const DILocation *getInlinedAt() const { return IA; }
const DIExpression *getSingleExpression() const {
assert(MInsn && FrameIndexExprs.size() <= 1);
return FrameIndexExprs.size() ? FrameIndexExprs[0].Expr : nullptr;
}
void setDIE(DIE &D) { TheDIE = &D; }
DIE *getDIE() const { return TheDIE; }
void setDebugLocListIndex(unsigned O) { DebugLocListIndex = O; }
@ -141,10 +156,10 @@ public:
return;
}
FrameIndexExprs.append(V.FrameIndexExprs.begin(), V.FrameIndexExprs.end());
assert(all_of(FrameIndexExprs,
[](FrameIndexExpr &FIE) {
return FIE.Expr && FIE.Expr->isFragment();
}) &&
assert(llvm::all_of(FrameIndexExprs,
[](FrameIndexExpr &FIE) {
return FIE.Expr && FIE.Expr->isFragment();
}) &&
"conflicting locations for variable");
}
@ -156,6 +171,7 @@ public:
return dwarf::DW_TAG_variable;
}
/// Return true if DbgVariable is artificial.
bool isArtificial() const {
if (Var->isArtificial())
@ -181,6 +197,7 @@ public:
"Invalid Expr for DBG_VALUE");
return !FrameIndexExprs.empty();
}
bool isBlockByrefVariable() const;
const DIType *getType() const;
@ -190,10 +207,10 @@ private:
}
};
/// Helper used to pair up a symbol and its DWARF compile unit.
struct SymbolCU {
SymbolCU(DwarfCompileUnit *CU, const MCSymbol *Sym) : Sym(Sym), CU(CU) {}
const MCSymbol *Sym;
DwarfCompileUnit *CU;
};
@ -229,7 +246,7 @@ class DwarfDebug : public DebugHandlerBase {
ProcessedSPNodes;
/// If nonnull, stores the current machine function we're processing.
const MachineFunction *CurFn;
const MachineFunction *CurFn = nullptr;
/// If nonnull, stores the CU in which the previous subprogram was contained.
const DwarfCompileUnit *PrevCU;
@ -295,7 +312,7 @@ class DwarfDebug : public DebugHandlerBase {
DwarfAccelTable AccelTypes;
// Identify a debugger for "tuning" the debug info.
DebuggerKind DebuggerTuning;
DebuggerKind DebuggerTuning = DebuggerKind::Default;
/// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger.
///
@ -313,7 +330,7 @@ class DwarfDebug : public DebugHandlerBase {
return InfoHolder.getUnits();
}
typedef DbgValueHistoryMap::InlinedVariable InlinedVariable;
using InlinedVariable = DbgValueHistoryMap::InlinedVariable;
void ensureAbstractVariableIsCreated(DwarfCompileUnit &CU, InlinedVariable Var,
const MDNode *Scope);
@ -562,6 +579,7 @@ public:
bool hasDwarfPubSections(bool includeMinimalInlineScopes) const;
};
} // End of namespace llvm
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFDEBUG_H

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfExpression.cpp - Dwarf Debug Framework ----------===//
//===- llvm/CodeGen/DwarfExpression.cpp - Dwarf Debug Framework -----------===//
//
// The LLVM Compiler Infrastructure
//
@ -12,13 +12,15 @@
//===----------------------------------------------------------------------===//
#include "DwarfExpression.h"
#include "DwarfDebug.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Target/TargetRegisterInfo.h"
#include "llvm/Target/TargetSubtargetInfo.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
using namespace llvm;
@ -339,7 +341,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
case dwarf::DW_OP_minus:
emitOp(Op->getOp());
break;
case dwarf::DW_OP_deref: {
case dwarf::DW_OP_deref:
assert(LocationKind != Register);
if (LocationKind != Memory && isMemoryLocation(ExprCursor))
// Turning this into a memory location description makes the deref
@ -348,7 +350,6 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor,
else
emitOp(dwarf::DW_OP_deref);
break;
}
case dwarf::DW_OP_constu:
assert(LocationKind != Register);
emitOp(dwarf::DW_OP_constu);
@ -384,7 +385,6 @@ void DwarfExpression::maskSubRegister() {
addAnd(Mask);
}
void DwarfExpression::finalize() {
assert(DwarfRegs.size() == 0 && "dwarf registers not emitted");
// Emit any outstanding DW_OP_piece operations to mask out subregisters.

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfExpression.h - Dwarf Compile Unit ---*- C++ -*--===//
//===- llvm/CodeGen/DwarfExpression.h - Dwarf Compile Unit ------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -14,21 +14,29 @@
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H
#include "llvm/IR/DebugInfo.h"
#include "llvm/Support/DataTypes.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include <cassert>
#include <cstdint>
#include <iterator>
namespace llvm {
class AsmPrinter;
class APInt;
class ByteStreamer;
class TargetRegisterInfo;
class DwarfUnit;
class DIELoc;
class TargetRegisterInfo;
/// Holds a DIExpression and keeps track of how many operands have been consumed
/// so far.
class DIExpressionCursor {
DIExpression::expr_op_iterator Start, End;
public:
DIExpressionCursor(const DIExpression *Expr) {
if (!Expr) {
@ -42,8 +50,7 @@ public:
DIExpressionCursor(ArrayRef<uint64_t> Expr)
: Start(Expr.begin()), End(Expr.end()) {}
DIExpressionCursor(const DIExpressionCursor &C)
: Start(C.Start), End(C.End) {}
DIExpressionCursor(const DIExpressionCursor &) = default;
/// Consume one operation.
Optional<DIExpression::ExprOperand> take() {
@ -73,8 +80,10 @@ public:
return *Next;
}
/// Determine whether there are any operations left in this expression.
operator bool() const { return Start != End; }
DIExpression::expr_op_iterator begin() const { return Start; }
DIExpression::expr_op_iterator end() const { return End; }
@ -122,10 +131,13 @@ protected:
/// Output a dwarf operand and an optional assembler comment.
virtual void emitOp(uint8_t Op, const char *Comment = nullptr) = 0;
/// Emit a raw signed value.
virtual void emitSigned(int64_t Value) = 0;
/// Emit a raw unsigned value.
virtual void emitUnsigned(uint64_t Value) = 0;
/// Return whether the given machine register is the frame register in the
/// current function.
virtual bool isFrameRegister(const TargetRegisterInfo &TRI, unsigned MachineReg) = 0;
@ -133,8 +145,10 @@ protected:
/// Emit a DW_OP_reg operation. Note that this is only legal inside a DWARF
/// register location description.
void addReg(int DwarfReg, const char *Comment = nullptr);
/// Emit a DW_OP_breg operation.
void addBReg(int DwarfReg, int Offset);
/// Emit DW_OP_fbreg <Offset>.
void addFBReg(int Offset);
@ -156,7 +170,6 @@ protected:
bool addMachineReg(const TargetRegisterInfo &TRI, unsigned MachineReg,
unsigned MaxSize = ~1U);
/// Emit a DW_OP_piece or DW_OP_bit_piece operation for a variable fragment.
/// \param OffsetInBits This is an optional offset into the location that
/// is at the top of the DWARF stack.
@ -164,6 +177,7 @@ protected:
/// Emit a shift-right dwarf operation.
void addShr(unsigned ShiftBy);
/// Emit a bitwise and dwarf operation.
void addAnd(unsigned Mask);
@ -181,6 +195,7 @@ protected:
void addStackValue();
~DwarfExpression() = default;
public:
DwarfExpression(unsigned DwarfVersion) : DwarfVersion(DwarfVersion) {}
@ -189,8 +204,10 @@ public:
/// Emit a signed constant.
void addSignedConstant(int64_t Value);
/// Emit an unsigned constant.
void addUnsignedConstant(uint64_t Value);
/// Emit an unsigned constant.
void addUnsignedConstant(const APInt &Value);
@ -213,6 +230,7 @@ public:
bool addMachineRegExpression(const TargetRegisterInfo &TRI,
DIExpressionCursor &Expr, unsigned MachineReg,
unsigned FragmentOffsetInBits = 0);
/// Emit all remaining operations in the DIExpressionCursor.
///
/// \param FragmentOffsetInBits If this is one fragment out of multiple
@ -235,6 +253,7 @@ class DebugLocDwarfExpression final : public DwarfExpression {
void emitUnsigned(uint64_t Value) override;
bool isFrameRegister(const TargetRegisterInfo &TRI,
unsigned MachineReg) override;
public:
DebugLocDwarfExpression(unsigned DwarfVersion, ByteStreamer &BS)
: DwarfExpression(DwarfVersion), BS(BS) {}
@ -253,11 +272,13 @@ const AsmPrinter &AP;
unsigned MachineReg) override;
public:
DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE);
DIELoc *finalize() {
DwarfExpression::finalize();
return &DIE;
}
};
}
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfFile.cpp - Dwarf Debug Framework ----------------===//
//===- llvm/CodeGen/DwarfFile.cpp - Dwarf Debug Framework -----------------===//
//
// The LLVM Compiler Infrastructure
//
@ -11,13 +11,16 @@
#include "DwarfCompileUnit.h"
#include "DwarfDebug.h"
#include "DwarfUnit.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/Support/LEB128.h"
#include "llvm/Target/TargetLoweringObjectFile.h"
#include <algorithm>
#include <cstdint>
using namespace llvm;
namespace llvm {
DwarfFile::DwarfFile(AsmPrinter *AP, StringRef Pref, BumpPtrAllocator &DA)
: Asm(AP), Abbrevs(AbbrevAllocator), StrPool(DA, *Asm, Pref) {}
@ -113,4 +116,3 @@ bool DwarfFile::addScopeVariable(LexicalScope *LS, DbgVariable *Var) {
Vars.push_back(Var);
return true;
}
}

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework -------*- C++ -*--===//
//===- llvm/CodeGen/DwarfFile.h - Dwarf Debug Framework ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -10,30 +10,25 @@
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H
#include "AddressPool.h"
#include "DwarfStringPool.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/DIE.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/Allocator.h"
#include <memory>
#include <utility>
namespace llvm {
class AsmPrinter;
class DbgVariable;
class DwarfCompileUnit;
class DwarfUnit;
class DIEAbbrev;
class MCSymbol;
class DIE;
class LexicalScope;
class StringRef;
class DwarfDebug;
class MCSection;
class MDNode;
class DwarfFile {
// Target of Dwarf emission, used for sizing of abbreviations.
AsmPrinter *Asm;
@ -106,6 +101,7 @@ public:
DenseMap<const MDNode *, DIE *> &getAbstractSPDies() {
return AbstractSPDies;
}
DenseMap<const MDNode *, std::unique_ptr<DbgVariable>> &getAbstractVariables() {
return AbstractVariables;
}
@ -113,9 +109,12 @@ public:
void insertDIE(const MDNode *TypeMD, DIE *Die) {
DITypeNodeToDieMap.insert(std::make_pair(TypeMD, Die));
}
DIE *getDIE(const MDNode *TypeMD) {
return DITypeNodeToDieMap.lookup(TypeMD);
}
};
}
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFFILE_H

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfStringPool.cpp - Dwarf Debug Framework ----------===//
//===- llvm/CodeGen/DwarfStringPool.cpp - Dwarf Debug Framework -----------===//
//
// The LLVM Compiler Infrastructure
//
@ -8,9 +8,14 @@
//===----------------------------------------------------------------------===//
#include "DwarfStringPool.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/CodeGen/AsmPrinter.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCStreamer.h"
#include <cassert>
#include <utility>
using namespace llvm;

View File

@ -1,4 +1,4 @@
//===-- llvm/CodeGen/DwarfStringPool.h - Dwarf Debug Framework -*- C++ -*--===//
//===- llvm/CodeGen/DwarfStringPool.h - Dwarf Debug Framework ---*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -11,29 +11,28 @@
#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
#include "llvm/Support/Allocator.h"
#include <utility>
namespace llvm {
class AsmPrinter;
class MCSymbol;
class MCSection;
class StringRef;
// Collection of strings for this unit and assorted symbols.
// A String->Symbol mapping of strings used by indirect
// references.
class DwarfStringPool {
typedef DwarfStringPoolEntry EntryTy;
using EntryTy = DwarfStringPoolEntry;
StringMap<EntryTy, BumpPtrAllocator &> Pool;
StringRef Prefix;
unsigned NumBytes = 0;
bool ShouldCreateSymbols;
public:
typedef DwarfStringPoolEntryRef EntryRef;
using EntryRef = DwarfStringPoolEntryRef;
DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix);
@ -45,5 +44,7 @@ public:
/// Get a reference to an entry in the string pool.
EntryRef getEntry(AsmPrinter &Asm, StringRef Str);
};
}
#endif
} // end namespace llvm
#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H