summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/dsymutil/DwarfLinker.cpp41
-rw-r--r--tools/llvm-config/BuildVariables.inc.in10
-rw-r--r--tools/llvm-config/CMakeLists.txt11
-rw-r--r--tools/llvm-config/llvm-config.cpp14
-rw-r--r--tools/llvm-pdbdump/CMakeLists.txt18
-rw-r--r--tools/llvm-pdbdump/LLVMOutputStyle.cpp37
-rw-r--r--tools/llvm-pdbdump/LLVMOutputStyle.h4
-rw-r--r--tools/llvm-pdbdump/PrettyBuiltinDumper.cpp (renamed from tools/llvm-pdbdump/BuiltinDumper.cpp)4
-rw-r--r--tools/llvm-pdbdump/PrettyBuiltinDumper.h (renamed from tools/llvm-pdbdump/BuiltinDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp (renamed from tools/llvm-pdbdump/ClassDefinitionDumper.cpp)13
-rw-r--r--tools/llvm-pdbdump/PrettyClassDefinitionDumper.h (renamed from tools/llvm-pdbdump/ClassDefinitionDumper.h)8
-rw-r--r--tools/llvm-pdbdump/PrettyCompilandDumper.cpp (renamed from tools/llvm-pdbdump/CompilandDumper.cpp)8
-rw-r--r--tools/llvm-pdbdump/PrettyCompilandDumper.h (renamed from tools/llvm-pdbdump/CompilandDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyEnumDumper.cpp (renamed from tools/llvm-pdbdump/EnumDumper.cpp)6
-rw-r--r--tools/llvm-pdbdump/PrettyEnumDumper.h (renamed from tools/llvm-pdbdump/EnumDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyExternalSymbolDumper.cpp (renamed from tools/llvm-pdbdump/ExternalSymbolDumper.cpp)4
-rw-r--r--tools/llvm-pdbdump/PrettyExternalSymbolDumper.h (renamed from tools/llvm-pdbdump/ExternalSymbolDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyFunctionDumper.cpp (renamed from tools/llvm-pdbdump/FunctionDumper.cpp)6
-rw-r--r--tools/llvm-pdbdump/PrettyFunctionDumper.h (renamed from tools/llvm-pdbdump/FunctionDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyTypeDumper.cpp (renamed from tools/llvm-pdbdump/TypeDumper.cpp)12
-rw-r--r--tools/llvm-pdbdump/PrettyTypeDumper.h (renamed from tools/llvm-pdbdump/TypeDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyTypedefDumper.cpp (renamed from tools/llvm-pdbdump/TypedefDumper.cpp)8
-rw-r--r--tools/llvm-pdbdump/PrettyTypedefDumper.h (renamed from tools/llvm-pdbdump/TypedefDumper.h)6
-rw-r--r--tools/llvm-pdbdump/PrettyVariableDumper.cpp (renamed from tools/llvm-pdbdump/VariableDumper.cpp)10
-rw-r--r--tools/llvm-pdbdump/PrettyVariableDumper.h (renamed from tools/llvm-pdbdump/VariableDumper.h)6
-rw-r--r--tools/llvm-pdbdump/YAMLOutputStyle.h2
-rw-r--r--tools/llvm-pdbdump/llvm-pdbdump.cpp10
-rw-r--r--tools/llvm-readobj/COFFDumper.cpp26
-rw-r--r--tools/llvm-xray/CMakeLists.txt9
-rw-r--r--tools/llvm-xray/func-id-helper.cc60
-rw-r--r--tools/llvm-xray/func-id-helper.h49
-rw-r--r--tools/llvm-xray/xray-account.cc485
-rw-r--r--tools/llvm-xray/xray-account.h109
-rw-r--r--tools/llvm-xray/xray-converter.cc202
-rw-r--r--tools/llvm-xray/xray-converter.h39
-rw-r--r--tools/llvm-xray/xray-extract.cc63
-rw-r--r--tools/llvm-xray/xray-record-yaml.h102
-rw-r--r--tools/obj2yaml/dwarf2yaml.cpp128
-rw-r--r--tools/opt/NewPMDriver.cpp2
-rw-r--r--tools/yaml2obj/yaml2dwarf.cpp95
-rw-r--r--tools/yaml2obj/yaml2macho.cpp2
-rw-r--r--tools/yaml2obj/yaml2obj.h1
42 files changed, 1502 insertions, 144 deletions
diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp
index ecd631c1039c..f1ec8a622671 100644
--- a/tools/dsymutil/DwarfLinker.cpp
+++ b/tools/dsymutil/DwarfLinker.cpp
@@ -205,7 +205,9 @@ public:
Info.resize(OrigUnit.getNumDIEs());
auto CUDie = OrigUnit.getUnitDIE(false);
- unsigned Lang = CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language, 0);
+ unsigned Lang =
+ CUDie.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_language)
+ .getValueOr(0);
HasODR = CanUseODR && (Lang == dwarf::DW_LANG_C_plus_plus ||
Lang == dwarf::DW_LANG_C_plus_plus_03 ||
Lang == dwarf::DW_LANG_C_plus_plus_11 ||
@@ -1556,7 +1558,8 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// Do not unique anything inside CU local functions.
if ((Context.getTag() == dwarf::DW_TAG_namespace ||
Context.getTag() == dwarf::DW_TAG_compile_unit) &&
- !DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external, 0))
+ !DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_external)
+ .getValueOr(0))
return PointerIntPair<DeclContext *, 1>(nullptr);
LLVM_FALLTHROUGH;
case dwarf::DW_TAG_member:
@@ -1570,7 +1573,8 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// created on demand. For example implicitely defined constructors
// are ambiguous because of the way we identify contexts, and they
// won't be generated everytime everywhere.
- if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial, 0))
+ if (DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_artificial)
+ .getValueOr(0))
return PointerIntPair<DeclContext *, 1>(nullptr);
break;
}
@@ -1610,11 +1614,12 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// namespaces, use these additional data points to make the process
// safer. This is disabled for clang modules, because forward
// declarations of module-defined types do not have a file and line.
- ByteSize = DIE.getAttributeValueAsUnsignedConstant(
- dwarf::DW_AT_byte_size, UINT64_MAX);
+ ByteSize = DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_byte_size)
+ .getValueOr(UINT64_MAX);
if (Tag != dwarf::DW_TAG_namespace || !Name) {
- if (unsigned FileNum = DIE.getAttributeValueAsUnsignedConstant(
- dwarf::DW_AT_decl_file, 0)) {
+ if (unsigned FileNum =
+ DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_file)
+ .getValueOr(0)) {
if (const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit(
&U.getOrigUnit())) {
// FIXME: dsymutil-classic compatibility. I'd rather not
@@ -1627,8 +1632,9 @@ PointerIntPair<DeclContext *, 1> DeclContextTree::getChildDeclContext(
// instead of "" would allow more uniquing, but for now, do
// it this way to match dsymutil-classic.
if (LT->hasFileAtIndex(FileNum)) {
- Line = DIE.getAttributeValueAsUnsignedConstant(
- dwarf::DW_AT_decl_line, 0);
+ Line =
+ DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_decl_line)
+ .getValueOr(0);
// Cache the resolved paths, because calling realpath is expansive.
StringRef ResolvedPath = U.getResolvedPath(FileNum);
if (!ResolvedPath.empty()) {
@@ -1803,9 +1809,10 @@ static bool analyzeContextInfo(const DWARFDie &DIE,
// Prune this DIE if it is either a forward declaration inside a
// DW_TAG_module or a DW_TAG_module that contains nothing but
// forward declarations.
- Info.Prune &= (DIE.getTag() == dwarf::DW_TAG_module) ||
- DIE.getAttributeValueAsUnsignedConstant(
- dwarf::DW_AT_declaration, 0);
+ Info.Prune &=
+ (DIE.getTag() == dwarf::DW_TAG_module) ||
+ DIE.getAttributeValueAsUnsignedConstant(dwarf::DW_AT_declaration)
+ .getValueOr(0);
// Don't prune it if there is no definition for the DIE.
Info.Prune &= Info.Ctxt && Info.Ctxt->getCanonicalDIEOffset();
@@ -2740,12 +2747,13 @@ DIE *DwarfLinker::DIECloner::cloneDIE(
// independantly by the linker). The computation of the actual
// high_pc value is done in cloneAddressAttribute().
AttrInfo.OrigHighPc =
- InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc, 0);
+ InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_high_pc).getValueOr(0);
// Also store the low_pc. It might get relocated in an
// inline_subprogram that happens at the beginning of its
// inlining function.
AttrInfo.OrigLowPc =
- InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc, UINT64_MAX);
+ InputDIE.getAttributeValueAsAddress(dwarf::DW_AT_low_pc)
+ .getValueOr(UINT64_MAX);
}
// Reset the Offset to 0 as we will be working on the local copy of
@@ -2864,8 +2872,9 @@ void DwarfLinker::patchRangesForUnit(const CompileUnit &Unit,
auto InvalidRange = FunctionRanges.end(), CurrRange = InvalidRange;
DWARFUnit &OrigUnit = Unit.getOrigUnit();
auto OrigUnitDie = OrigUnit.getUnitDIE(false);
- uint64_t OrigLowPc = OrigUnitDie.getAttributeValueAsAddress(
- dwarf::DW_AT_low_pc, -1ULL);
+ uint64_t OrigLowPc =
+ OrigUnitDie.getAttributeValueAsAddress(dwarf::DW_AT_low_pc)
+ .getValueOr(-1ULL);
// Ranges addresses are based on the unit's low_pc. Compute the
// offset we need to apply to adapt to the new unit's low_pc.
int64_t UnitPcOffset = 0;
diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
index 709ea35044c6..0740c3f9d9f5 100644
--- a/tools/llvm-config/BuildVariables.inc.in
+++ b/tools/llvm-config/BuildVariables.inc.in
@@ -27,10 +27,10 @@
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
#define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
-#define LLVM_HAS_RTTI "@LLVM_HAS_RTTI@"
-#define LLVM_ENABLE_DYLIB "@LLVM_BUILD_LLVM_DYLIB@"
-#define LLVM_LINK_DYLIB "@LLVM_LINK_LLVM_DYLIB@"
-#define LLVM_ENABLE_SHARED "@LLVM_ENABLE_SHARED@"
+#define LLVM_HAS_RTTI @LLVM_HAS_RTTI@
+#define LLVM_ENABLE_DYLIB @LLVM_BUILD_LLVM_DYLIB@
+#define LLVM_LINK_DYLIB @LLVM_LINK_LLVM_DYLIB@
+#define LLVM_ENABLE_SHARED @BUILD_SHARED_LIBS@
#define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"
#define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@"
-#define LLVM_HAS_GLOBAL_ISEL "@LLVM_HAS_GLOBAL_ISEL@"
+#define LLVM_HAS_GLOBAL_ISEL @LLVM_HAS_GLOBAL_ISEL@
diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt
index 1f5db59beb50..5112648ea731 100644
--- a/tools/llvm-config/CMakeLists.txt
+++ b/tools/llvm-config/CMakeLists.txt
@@ -47,12 +47,13 @@ endif()
set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
-if(BUILD_SHARED_LIBS)
- set(LLVM_ENABLE_SHARED ON)
-else()
- set(LLVM_ENABLE_SHARED OFF)
-endif()
string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
+llvm_canonicalize_cmake_booleans(
+ LLVM_BUILD_LLVM_DYLIB
+ LLVM_LINK_LLVM_DYLIB
+ LLVM_HAS_RTTI
+ LLVM_HAS_GLOBAL_ISEL
+ BUILD_SHARED_LIBS)
configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
# Set build-time environment(s).
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
index e8afcbaaf485..25344e4cd011 100644
--- a/tools/llvm-config/llvm-config.cpp
+++ b/tools/llvm-config/llvm-config.cpp
@@ -212,7 +212,7 @@ Options:\n\
--assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
--build-system Print the build system used to build LLVM (always cmake).\n\
--has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\
- --has-global-isel Print whether or not LLVM was built with global-isel support (YES or NO).\n\
+ --has-global-isel Print whether or not LLVM was built with global-isel support (ON or OFF).\n\
--shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\
--link-shared Link the components as shared libraries.\n\
--link-static Link the component libraries statically.\n\
@@ -242,7 +242,7 @@ std::vector<std::string> GetAllDyLibComponents(const bool IsInDevelopmentTree,
size_t Offset = 0;
while (true) {
const size_t NextOffset = DyLibComponentsStr.find(';', Offset);
- DyLibComponents.push_back(DyLibComponentsStr.substr(Offset, NextOffset));
+ DyLibComponents.push_back(DyLibComponentsStr.substr(Offset, NextOffset-Offset));
if (NextOffset == std::string::npos) {
break;
}
@@ -383,10 +383,10 @@ int main(int argc, char **argv) {
StaticPrefix = SharedPrefix = "lib";
}
- const bool BuiltDyLib = (std::strcmp(LLVM_ENABLE_DYLIB, "ON") == 0);
+ const bool BuiltDyLib = !!LLVM_ENABLE_DYLIB;
/// CMake style shared libs, ie each component is in a shared library.
- const bool BuiltSharedLibs = std::strcmp(LLVM_ENABLE_SHARED, "ON") == 0;
+ const bool BuiltSharedLibs = !!LLVM_ENABLE_SHARED;
bool DyLibExists = false;
const std::string DyLibName =
@@ -395,7 +395,7 @@ int main(int argc, char **argv) {
// If LLVM_LINK_DYLIB is ON, the single shared library will be returned
// for "--libs", etc, if they exist. This behaviour can be overridden with
// --link-static or --link-shared.
- bool LinkDyLib = (std::strcmp(LLVM_LINK_DYLIB, "ON") == 0);
+ bool LinkDyLib = !!LLVM_LINK_DYLIB;
if (BuiltDyLib) {
std::string path((SharedDir + DirSep + DyLibName).str());
@@ -549,9 +549,9 @@ int main(int argc, char **argv) {
} else if (Arg == "--build-system") {
OS << LLVM_BUILD_SYSTEM << '\n';
} else if (Arg == "--has-rtti") {
- OS << LLVM_HAS_RTTI << '\n';
+ OS << (LLVM_HAS_RTTI ? "YES" : "NO") << '\n';
} else if (Arg == "--has-global-isel") {
- OS << LLVM_HAS_GLOBAL_ISEL << '\n';
+ OS << (LLVM_HAS_GLOBAL_ISEL ? "ON" : "OFF") << '\n';
} else if (Arg == "--shared-mode") {
PrintSharedMode = true;
} else if (Arg == "--obj-root") {
diff --git a/tools/llvm-pdbdump/CMakeLists.txt b/tools/llvm-pdbdump/CMakeLists.txt
index d929313903da..7c46171941f7 100644
--- a/tools/llvm-pdbdump/CMakeLists.txt
+++ b/tools/llvm-pdbdump/CMakeLists.txt
@@ -8,20 +8,20 @@ set(LLVM_LINK_COMPONENTS
add_llvm_tool(llvm-pdbdump
llvm-pdbdump.cpp
- BuiltinDumper.cpp
- ClassDefinitionDumper.cpp
YamlSymbolDumper.cpp
YamlTypeDumper.cpp
- CompilandDumper.cpp
- EnumDumper.cpp
- ExternalSymbolDumper.cpp
- FunctionDumper.cpp
LinePrinter.cpp
LLVMOutputStyle.cpp
PdbYaml.cpp
- TypeDumper.cpp
- TypedefDumper.cpp
- VariableDumper.cpp
+ PrettyBuiltinDumper.cpp
+ PrettyClassDefinitionDumper.cpp
+ PrettyCompilandDumper.cpp
+ PrettyEnumDumper.cpp
+ PrettyExternalSymbolDumper.cpp
+ PrettyFunctionDumper.cpp
+ PrettyTypeDumper.cpp
+ PrettyTypedefDumper.cpp
+ PrettyVariableDumper.cpp
YAMLOutputStyle.cpp
)
diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.cpp b/tools/llvm-pdbdump/LLVMOutputStyle.cpp
index 98c67ec9ef3b..629ba40b113c 100644
--- a/tools/llvm-pdbdump/LLVMOutputStyle.cpp
+++ b/tools/llvm-pdbdump/LLVMOutputStyle.cpp
@@ -10,9 +10,15 @@
#include "LLVMOutputStyle.h"
#include "llvm-pdbdump.h"
+#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
+#include "llvm/DebugInfo/CodeView/CVTypeVisitor.h"
#include "llvm/DebugInfo/CodeView/EnumTables.h"
#include "llvm/DebugInfo/CodeView/ModuleSubstreamVisitor.h"
#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
+#include "llvm/DebugInfo/CodeView/TypeDatabaseVisitor.h"
+#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
+#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
+#include "llvm/DebugInfo/CodeView/TypeVisitorCallbackPipeline.h"
#include "llvm/DebugInfo/MSF/MappedBlockStream.h"
#include "llvm/DebugInfo/MSF/StreamReader.h"
#include "llvm/DebugInfo/PDB/PDBExtras.h"
@@ -83,8 +89,7 @@ static void printSectionOffset(llvm::raw_ostream &OS,
OS << Off.Off << ", " << Off.Isect;
}
-LLVMOutputStyle::LLVMOutputStyle(PDBFile &File)
- : File(File), P(outs()), Dumper(&P, false) {}
+LLVMOutputStyle::LLVMOutputStyle(PDBFile &File) : File(File), P(outs()) {}
Error LLVMOutputStyle::dump() {
if (auto EC = dumpFileHeaders())
@@ -519,6 +524,7 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
if (!Tpi)
return Tpi.takeError();
+ CVTypeDumper Dumper(TypeDB);
if (DumpRecords || DumpRecordBytes) {
DictScope D(P, Label);
@@ -532,7 +538,8 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
DictScope DD(P, "");
if (DumpRecords) {
- if (auto EC = Dumper.dump(Type))
+ TypeDumpVisitor TDV(TypeDB, &P, false);
+ if (auto EC = Dumper.dump(Type, TDV))
return EC;
}
@@ -545,19 +552,23 @@ Error LLVMOutputStyle::dumpTpiStream(uint32_t StreamIdx) {
"TPI stream contained corrupt record");
} else if (opts::raw::DumpModuleSyms) {
// Even if the user doesn't want to dump type records, we still need to
- // iterate them in order to build the list of types so that we can print
- // them when dumping module symbols. So when they want to dump symbols
- // but not types, use a null output stream.
- ScopedPrinter *OldP = Dumper.getPrinter();
- Dumper.setPrinter(nullptr);
+ // iterate them in order to build the type database. So when they want to
+ // dump symbols but not types, don't stick a dumper on the end, just build
+ // the type database.
+ TypeDatabaseVisitor DBV(TypeDB);
+ TypeDeserializer Deserializer;
+ TypeVisitorCallbackPipeline Pipeline;
+ Pipeline.addCallbackToPipeline(Deserializer);
+ Pipeline.addCallbackToPipeline(DBV);
+
+ CVTypeVisitor Visitor(Pipeline);
bool HadError = false;
- for (auto &Type : Tpi->types(&HadError)) {
- if (auto EC = Dumper.dump(Type))
+ for (auto Type : Tpi->types(&HadError)) {
+ if (auto EC = Visitor.visitTypeRecord(Type))
return EC;
}
- Dumper.setPrinter(OldP);
dumpTpiHash(P, *Tpi);
if (HadError)
return make_error<RawError>(raw_error_code::corrupt_file,
@@ -640,7 +651,7 @@ Error LLVMOutputStyle::dumpDbiStream() {
if (ShouldDumpSymbols) {
ListScope SS(P, "Symbols");
- codeview::CVSymbolDumper SD(P, Dumper, nullptr, false);
+ codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
bool HadError = false;
for (auto S : ModS.symbols(&HadError)) {
DictScope LL(P, "");
@@ -865,7 +876,7 @@ Error LLVMOutputStyle::dumpPublicsStream() {
P.printList("Section Offsets", Publics->getSectionOffsets(),
printSectionOffset);
ListScope L(P, "Symbols");
- codeview::CVSymbolDumper SD(P, Dumper, nullptr, false);
+ codeview::CVSymbolDumper SD(P, TypeDB, nullptr, false);
bool HadError = false;
for (auto S : Publics->getSymbols(&HadError)) {
DictScope DD(P, "");
diff --git a/tools/llvm-pdbdump/LLVMOutputStyle.h b/tools/llvm-pdbdump/LLVMOutputStyle.h
index 72a3fd4aba5c..816d591f08f8 100644
--- a/tools/llvm-pdbdump/LLVMOutputStyle.h
+++ b/tools/llvm-pdbdump/LLVMOutputStyle.h
@@ -12,7 +12,7 @@
#include "OutputStyle.h"
-#include "llvm/DebugInfo/CodeView/TypeDumper.h"
+#include "llvm/DebugInfo/CodeView/TypeDatabase.h"
#include "llvm/Support/ScopedPrinter.h"
namespace llvm {
@@ -49,7 +49,7 @@ private:
PDBFile &File;
ScopedPrinter P;
- codeview::CVTypeDumper Dumper;
+ codeview::TypeDatabase TypeDB;
std::vector<std::string> StreamPurposes;
};
}
diff --git a/tools/llvm-pdbdump/BuiltinDumper.cpp b/tools/llvm-pdbdump/PrettyBuiltinDumper.cpp
index 2ce1a7839110..f866132aa886 100644
--- a/tools/llvm-pdbdump/BuiltinDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyBuiltinDumper.cpp
@@ -1,4 +1,4 @@
-//===- BuiltinDumper.cpp ---------------------------------------- *- C++ *-===//
+//===- PrettyBuiltinDumper.cpp ---------------------------------- *- C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "BuiltinDumper.h"
+#include "PrettyBuiltinDumper.h"
#include "LinePrinter.h"
#include "llvm-pdbdump.h"
diff --git a/tools/llvm-pdbdump/BuiltinDumper.h b/tools/llvm-pdbdump/PrettyBuiltinDumper.h
index 7a2f1438669c..fb6b0b172e6e 100644
--- a/tools/llvm-pdbdump/BuiltinDumper.h
+++ b/tools/llvm-pdbdump/PrettyBuiltinDumper.h
@@ -1,4 +1,4 @@
-//===- BuiltinDumper.h ---------------------------------------- *- C++ --*-===//
+//===- PrettyBuiltinDumper.h ---------------------------------- *- C++ --*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_BUILTINDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_BUILTINDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYBUILTINDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYBUILTINDUMPER_H
#include "llvm/ADT/StringRef.h"
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/ClassDefinitionDumper.cpp b/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
index 553bc0b267c2..b0c534f7c5b1 100644
--- a/tools/llvm-pdbdump/ClassDefinitionDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyClassDefinitionDumper.cpp
@@ -1,4 +1,4 @@
-//===- ClassDefinitionDumper.cpp --------------------------------*- C++ -*-===//
+//===- PrettyClassDefinitionDumper.cpp --------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,13 +7,14 @@
//
//===----------------------------------------------------------------------===//
-#include "ClassDefinitionDumper.h"
-#include "EnumDumper.h"
-#include "FunctionDumper.h"
+#include "PrettyClassDefinitionDumper.h"
+
#include "LinePrinter.h"
+#include "PrettyEnumDumper.h"
+#include "PrettyFunctionDumper.h"
+#include "PrettyTypedefDumper.h"
+#include "PrettyVariableDumper.h"
#include "llvm-pdbdump.h"
-#include "TypedefDumper.h"
-#include "VariableDumper.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDBExtras.h"
diff --git a/tools/llvm-pdbdump/ClassDefinitionDumper.h b/tools/llvm-pdbdump/PrettyClassDefinitionDumper.h
index 304e11dcb6c9..0831f47557ed 100644
--- a/tools/llvm-pdbdump/ClassDefinitionDumper.h
+++ b/tools/llvm-pdbdump/PrettyClassDefinitionDumper.h
@@ -1,4 +1,4 @@
-//===- ClassDefinitionDumper.h - --------------------------------*- C++ -*-===//
+//===- PrettyClassDefinitionDumper.h ----------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,12 +7,12 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_CLASSDEFINITIONDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_CLASSDEFINITIONDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYCLASSDEFINITIONDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYCLASSDEFINITIONDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include <list>
#include <memory>
diff --git a/tools/llvm-pdbdump/CompilandDumper.cpp b/tools/llvm-pdbdump/PrettyCompilandDumper.cpp
index 05141818660e..6257313e3e1a 100644
--- a/tools/llvm-pdbdump/CompilandDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyCompilandDumper.cpp
@@ -1,4 +1,4 @@
-//===- CompilandDumper.cpp - llvm-pdbdump compiland symbol dumper *- C++ *-===//
+//===- PrettyCompilandDumper.cpp - llvm-pdbdump compiland dumper -*- C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,10 @@
//
//===----------------------------------------------------------------------===//
-#include "CompilandDumper.h"
+#include "PrettyCompilandDumper.h"
+
#include "LinePrinter.h"
+#include "PrettyFunctionDumper.h"
#include "llvm-pdbdump.h"
#include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
@@ -30,8 +32,6 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
-#include "FunctionDumper.h"
-
#include <utility>
using namespace llvm;
diff --git a/tools/llvm-pdbdump/CompilandDumper.h b/tools/llvm-pdbdump/PrettyCompilandDumper.h
index 462aaeb2611f..2127e7d1f529 100644
--- a/tools/llvm-pdbdump/CompilandDumper.h
+++ b/tools/llvm-pdbdump/PrettyCompilandDumper.h
@@ -1,4 +1,4 @@
-//===- CompilandDumper.h - llvm-pdbdump compiland symbol dumper *- C++ --*-===//
+//===- PrettyCompilandDumper.h - llvm-pdbdump compiland dumper -*- C++ --*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_COMPILANDDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_COMPILANDDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYCOMPILANDDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYCOMPILANDDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/EnumDumper.cpp b/tools/llvm-pdbdump/PrettyEnumDumper.cpp
index 43b6018ffedf..965ca1b9f989 100644
--- a/tools/llvm-pdbdump/EnumDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyEnumDumper.cpp
@@ -1,4 +1,4 @@
-//===- EnumDumper.cpp -------------------------------------------*- C++ -*-===//
+//===- PrettyEnumDumper.cpp -------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,10 +7,10 @@
//
//===----------------------------------------------------------------------===//
-#include "EnumDumper.h"
+#include "PrettyEnumDumper.h"
-#include "BuiltinDumper.h"
#include "LinePrinter.h"
+#include "PrettyBuiltinDumper.h"
#include "llvm-pdbdump.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
diff --git a/tools/llvm-pdbdump/EnumDumper.h b/tools/llvm-pdbdump/PrettyEnumDumper.h
index 0a34e1f89ada..c6e65a6d1772 100644
--- a/tools/llvm-pdbdump/EnumDumper.h
+++ b/tools/llvm-pdbdump/PrettyEnumDumper.h
@@ -1,4 +1,4 @@
-//===- EnumDumper.h - -------------------------------------------*- C++ -*-===//
+//===- PrettyEnumDumper.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_ENUMDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_ENUMDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYENUMDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYENUMDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/ExternalSymbolDumper.cpp b/tools/llvm-pdbdump/PrettyExternalSymbolDumper.cpp
index 508a2405772e..fc40d90cee96 100644
--- a/tools/llvm-pdbdump/ExternalSymbolDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyExternalSymbolDumper.cpp
@@ -1,4 +1,4 @@
-//===- ExternalSymbolDumper.cpp -------------------------------- *- C++ *-===//
+//===- PrettyExternalSymbolDumper.cpp -------------------------- *- C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,7 +7,7 @@
//
//===----------------------------------------------------------------------===//
-#include "ExternalSymbolDumper.h"
+#include "PrettyExternalSymbolDumper.h"
#include "LinePrinter.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
diff --git a/tools/llvm-pdbdump/ExternalSymbolDumper.h b/tools/llvm-pdbdump/PrettyExternalSymbolDumper.h
index b44b8a6fe98a..6a009862ddd4 100644
--- a/tools/llvm-pdbdump/ExternalSymbolDumper.h
+++ b/tools/llvm-pdbdump/PrettyExternalSymbolDumper.h
@@ -1,4 +1,4 @@
-//===- ExternalSymbolDumper.h --------------------------------- *- C++ --*-===//
+//===- PrettyExternalSymbolDumper.h --------------------------- *- C++ --*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_EXTERNALSYMBOLDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_EXTERNALSYMBOLDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYEXTERNALSYMBOLDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYEXTERNALSYMBOLDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/FunctionDumper.cpp b/tools/llvm-pdbdump/PrettyFunctionDumper.cpp
index 29ba15d521f0..2f6ca894fadf 100644
--- a/tools/llvm-pdbdump/FunctionDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyFunctionDumper.cpp
@@ -1,4 +1,4 @@
-//===- FunctionDumper.cpp ------------------------------------ *- C++ *-===//
+//===- PrettyFunctionDumper.cpp --------------------------------- *- C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,9 +7,9 @@
//
//===----------------------------------------------------------------------===//
-#include "FunctionDumper.h"
-#include "BuiltinDumper.h"
+#include "PrettyFunctionDumper.h"
#include "LinePrinter.h"
+#include "PrettyBuiltinDumper.h"
#include "llvm-pdbdump.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
diff --git a/tools/llvm-pdbdump/FunctionDumper.h b/tools/llvm-pdbdump/PrettyFunctionDumper.h
index c71fafa18ed3..1a6f5430ec5a 100644
--- a/tools/llvm-pdbdump/FunctionDumper.h
+++ b/tools/llvm-pdbdump/PrettyFunctionDumper.h
@@ -1,4 +1,4 @@
-//===- FunctionDumper.h --------------------------------------- *- C++ --*-===//
+//===- PrettyFunctionDumper.h --------------------------------- *- C++ --*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_FUNCTIONDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_FUNCTIONDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYFUNCTIONDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYFUNCTIONDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/TypeDumper.cpp b/tools/llvm-pdbdump/PrettyTypeDumper.cpp
index a49d64045553..4f70c8047337 100644
--- a/tools/llvm-pdbdump/TypeDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyTypeDumper.cpp
@@ -1,4 +1,4 @@
-//===- TypeDumper.cpp - PDBSymDumper implementation for types *----- C++ *-===//
+//===- PrettyTypeDumper.cpp - PDBSymDumper type dumper *------------ C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,14 +7,14 @@
//
//===----------------------------------------------------------------------===//
-#include "TypeDumper.h"
+#include "PrettyTypeDumper.h"
-#include "BuiltinDumper.h"
-#include "ClassDefinitionDumper.h"
-#include "EnumDumper.h"
#include "LinePrinter.h"
+#include "PrettyBuiltinDumper.h"
+#include "PrettyClassDefinitionDumper.h"
+#include "PrettyEnumDumper.h"
+#include "PrettyTypedefDumper.h"
#include "llvm-pdbdump.h"
-#include "TypedefDumper.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
diff --git a/tools/llvm-pdbdump/TypeDumper.h b/tools/llvm-pdbdump/PrettyTypeDumper.h
index 76a477964f1f..f9d8304c3208 100644
--- a/tools/llvm-pdbdump/TypeDumper.h
+++ b/tools/llvm-pdbdump/PrettyTypeDumper.h
@@ -1,4 +1,4 @@
-//===- TypeDumper.h - PDBSymDumper implementation for types *- C++ ------*-===//
+//===- PrettyTypeDumper.h - PDBSymDumper implementation for types *- C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_TYPEDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_TYPEDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYTYPEDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYTYPEDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/TypedefDumper.cpp b/tools/llvm-pdbdump/PrettyTypedefDumper.cpp
index b1e017613ce1..c458755cb780 100644
--- a/tools/llvm-pdbdump/TypedefDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyTypedefDumper.cpp
@@ -1,4 +1,4 @@
-//===- TypedefDumper.cpp - PDBSymDumper impl for typedefs -------- * C++ *-===//
+//===- PrettyTypedefDumper.cpp - PDBSymDumper impl for typedefs -- * C++ *-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,11 +7,11 @@
//
//===----------------------------------------------------------------------===//
-#include "TypedefDumper.h"
+#include "PrettyTypedefDumper.h"
-#include "BuiltinDumper.h"
-#include "FunctionDumper.h"
#include "LinePrinter.h"
+#include "PrettyBuiltinDumper.h"
+#include "PrettyFunctionDumper.h"
#include "llvm-pdbdump.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
diff --git a/tools/llvm-pdbdump/TypedefDumper.h b/tools/llvm-pdbdump/PrettyTypedefDumper.h
index c22b58a7e41e..34c139601301 100644
--- a/tools/llvm-pdbdump/TypedefDumper.h
+++ b/tools/llvm-pdbdump/PrettyTypedefDumper.h
@@ -1,4 +1,4 @@
-//===- TypedefDumper.h - llvm-pdbdump typedef dumper ---------*- C++ ----*-===//
+//===- PrettyTypedefDumper.h - llvm-pdbdump typedef dumper ---*- C++ ----*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_TYPEDEFDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_TYPEDEFDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYTYPEDEFDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYTYPEDEFDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/VariableDumper.cpp b/tools/llvm-pdbdump/PrettyVariableDumper.cpp
index 284d7e9b731f..e1469186ad8b 100644
--- a/tools/llvm-pdbdump/VariableDumper.cpp
+++ b/tools/llvm-pdbdump/PrettyVariableDumper.cpp
@@ -1,4 +1,4 @@
-//===- VariableDumper.cpp - -------------------------------------*- C++ -*-===//
+//===- PrettyVariableDumper.cpp ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,21 +7,21 @@
//
//===----------------------------------------------------------------------===//
-#include "VariableDumper.h"
+#include "PrettyVariableDumper.h"
-#include "BuiltinDumper.h"
#include "LinePrinter.h"
+#include "PrettyBuiltinDumper.h"
+#include "PrettyFunctionDumper.h"
#include "llvm-pdbdump.h"
-#include "FunctionDumper.h"
#include "llvm/DebugInfo/PDB/PDBSymbolData.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
+#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
-#include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
#include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
#include "llvm/Support/Format.h"
diff --git a/tools/llvm-pdbdump/VariableDumper.h b/tools/llvm-pdbdump/PrettyVariableDumper.h
index 4f00358878c9..a122bb86058c 100644
--- a/tools/llvm-pdbdump/VariableDumper.h
+++ b/tools/llvm-pdbdump/PrettyVariableDumper.h
@@ -1,4 +1,4 @@
-//===- VariableDumper.h - PDBSymDumper implementation for types -*- C++ -*-===//
+//===- PrettyVariableDumper.h - PDBSymDumper variable dumper ----*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@@ -7,8 +7,8 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_TOOLS_LLVMPDBDUMP_VARIABLEDUMPER_H
-#define LLVM_TOOLS_LLVMPDBDUMP_VARIABLEDUMPER_H
+#ifndef LLVM_TOOLS_LLVMPDBDUMP_PRETTYVARIABLEDUMPER_H
+#define LLVM_TOOLS_LLVMPDBDUMP_PRETTYVARIABLEDUMPER_H
#include "llvm/DebugInfo/PDB/PDBSymDumper.h"
diff --git a/tools/llvm-pdbdump/YAMLOutputStyle.h b/tools/llvm-pdbdump/YAMLOutputStyle.h
index 540dee4121e6..3cd603a95b6a 100644
--- a/tools/llvm-pdbdump/YAMLOutputStyle.h
+++ b/tools/llvm-pdbdump/YAMLOutputStyle.h
@@ -13,7 +13,7 @@
#include "OutputStyle.h"
#include "PdbYaml.h"
-#include "llvm/DebugInfo/CodeView/TypeDumper.h"
+#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/YAMLTraits.h"
diff --git a/tools/llvm-pdbdump/llvm-pdbdump.cpp b/tools/llvm-pdbdump/llvm-pdbdump.cpp
index b356a28d2189..d3495e524abc 100644
--- a/tools/llvm-pdbdump/llvm-pdbdump.cpp
+++ b/tools/llvm-pdbdump/llvm-pdbdump.cpp
@@ -14,14 +14,14 @@
//===----------------------------------------------------------------------===//
#include "llvm-pdbdump.h"
-#include "CompilandDumper.h"
-#include "ExternalSymbolDumper.h"
-#include "FunctionDumper.h"
#include "LLVMOutputStyle.h"
#include "LinePrinter.h"
#include "OutputStyle.h"
-#include "TypeDumper.h"
-#include "VariableDumper.h"
+#include "PrettyCompilandDumper.h"
+#include "PrettyExternalSymbolDumper.h"
+#include "PrettyFunctionDumper.h"
+#include "PrettyTypeDumper.h"
+#include "PrettyVariableDumper.h"
#include "YAMLOutputStyle.h"
#include "llvm/ADT/ArrayRef.h"
diff --git a/tools/llvm-readobj/COFFDumper.cpp b/tools/llvm-readobj/COFFDumper.cpp
index 0ca186519cd2..c83655fe4d22 100644
--- a/tools/llvm-readobj/COFFDumper.cpp
+++ b/tools/llvm-readobj/COFFDumper.cpp
@@ -22,6 +22,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/DebugInfo/CodeView/CVTypeDumper.h"
#include "llvm/DebugInfo/CodeView/CodeView.h"
#include "llvm/DebugInfo/CodeView/Line.h"
#include "llvm/DebugInfo/CodeView/RecordSerialization.h"
@@ -29,7 +30,7 @@
#include "llvm/DebugInfo/CodeView/SymbolDumpDelegate.h"
#include "llvm/DebugInfo/CodeView/SymbolDumper.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
-#include "llvm/DebugInfo/CodeView/TypeDumper.h"
+#include "llvm/DebugInfo/CodeView/TypeDumpVisitor.h"
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/CodeView/TypeStreamMerger.h"
@@ -64,8 +65,7 @@ class COFFDumper : public ObjDumper {
public:
friend class COFFObjectDumpDelegate;
COFFDumper(const llvm::object::COFFObjectFile *Obj, ScopedPrinter &Writer)
- : ObjDumper(Writer), Obj(Obj),
- CVTD(&Writer, opts::CodeViewSubsectionBytes) {}
+ : ObjDumper(Writer), Obj(Obj), Writer(Writer) {}
void printFileHeaders() override;
void printSections() override;
@@ -99,7 +99,7 @@ private:
void printFileNameForOffset(StringRef Label, uint32_t FileOffset);
void printTypeIndex(StringRef FieldName, TypeIndex TI) {
// Forward to CVTypeDumper for simplicity.
- CVTD.printTypeIndex(FieldName, TI);
+ CVTypeDumper::printTypeIndex(Writer, FieldName, TI, TypeDB);
}
void printCodeViewSymbolsSubsection(StringRef Subsection,
@@ -142,7 +142,8 @@ private:
StringRef CVFileChecksumTable;
StringRef CVStringTable;
- CVTypeDumper CVTD;
+ ScopedPrinter &Writer;
+ TypeDatabase TypeDB;
};
class COFFObjectDumpDelegate : public SymbolDumpDelegate {
@@ -962,7 +963,8 @@ void COFFDumper::printCodeViewSymbolsSubsection(StringRef Subsection,
auto CODD = llvm::make_unique<COFFObjectDumpDelegate>(*this, Section, Obj,
SectionContents);
- CVSymbolDumper CVSD(W, CVTD, std::move(CODD), opts::CodeViewSubsectionBytes);
+ CVSymbolDumper CVSD(W, TypeDB, std::move(CODD),
+ opts::CodeViewSubsectionBytes);
ByteStream Stream(BinaryData);
CVSymbolArray Symbols;
StreamReader Reader(Stream);
@@ -1106,7 +1108,9 @@ void COFFDumper::printCodeViewTypeSection(StringRef SectionName,
if (Magic != COFF::DEBUG_SECTION_MAGIC)
return error(object_error::parse_failed);
- if (auto EC = CVTD.dump({Data.bytes_begin(), Data.bytes_end()})) {
+ CVTypeDumper CVTD(TypeDB);
+ TypeDumpVisitor TDV(TypeDB, &W, opts::CodeViewSubsectionBytes);
+ if (auto EC = CVTD.dump({Data.bytes_begin(), Data.bytes_end()}, TDV)) {
W.flush();
error(llvm::errorToErrorCode(std::move(EC)));
}
@@ -1552,8 +1556,12 @@ void llvm::dumpCodeViewMergedTypes(ScopedPrinter &Writer,
CVTypes.ForEachRecord([&](TypeIndex TI, ArrayRef<uint8_t> Record) {
Buf.append(Record.begin(), Record.end());
});
- CVTypeDumper CVTD(&Writer, opts::CodeViewSubsectionBytes);
- if (auto EC = CVTD.dump({Buf.str().bytes_begin(), Buf.str().bytes_end()})) {
+
+ TypeDatabase TypeDB;
+ CVTypeDumper CVTD(TypeDB);
+ TypeDumpVisitor TDV(TypeDB, &Writer, opts::CodeViewSubsectionBytes);
+ if (auto EC =
+ CVTD.dump({Buf.str().bytes_begin(), Buf.str().bytes_end()}, TDV)) {
Writer.flush();
error(llvm::errorToErrorCode(std::move(EC)));
}
diff --git a/tools/llvm-xray/CMakeLists.txt b/tools/llvm-xray/CMakeLists.txt
index 0084e35c1b0b..abcd7d932110 100644
--- a/tools/llvm-xray/CMakeLists.txt
+++ b/tools/llvm-xray/CMakeLists.txt
@@ -1,9 +1,16 @@
set(LLVM_LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
+ DebugInfoDWARF
+ Object
Support
- Object)
+ Symbolize
+ XRay)
set(LLVM_XRAY_TOOLS
+ func-id-helper.cc
+ xray-account.cc
+ xray-converter.cc
+ xray-extract.cc
xray-extract.cc
xray-registry.cc)
diff --git a/tools/llvm-xray/func-id-helper.cc b/tools/llvm-xray/func-id-helper.cc
new file mode 100644
index 000000000000..3234010695b2
--- /dev/null
+++ b/tools/llvm-xray/func-id-helper.cc
@@ -0,0 +1,60 @@
+//===- xray-fc-account.cc - XRay Function Call Accounting Tool ------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of the helper tools dealing with XRay-generated function ids.
+//
+//===----------------------------------------------------------------------===//
+
+#include "func-id-helper.h"
+#include "llvm/Support/Path.h"
+#include <sstream>
+
+using namespace llvm;
+using namespace xray;
+
+std::string FuncIdConversionHelper::SymbolOrNumber(int32_t FuncId) const {
+ std::ostringstream F;
+ auto It = FunctionAddresses.find(FuncId);
+ if (It == FunctionAddresses.end()) {
+ F << "#" << FuncId;
+ return F.str();
+ }
+
+ if (auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second)) {
+ auto &DI = *ResOrErr;
+ if (DI.FunctionName == "<invalid>")
+ F << "@(" << std::hex << It->second << ")";
+ else
+ F << DI.FunctionName;
+ } else
+ handleAllErrors(ResOrErr.takeError(), [&](const ErrorInfoBase &) {
+ F << "@(" << std::hex << It->second << ")";
+ });
+
+ return F.str();
+}
+
+std::string FuncIdConversionHelper::FileLineAndColumn(int32_t FuncId) const {
+ auto It = FunctionAddresses.find(FuncId);
+ if (It == FunctionAddresses.end())
+ return "(unknown)";
+
+ std::ostringstream F;
+ auto ResOrErr = Symbolizer.symbolizeCode(BinaryInstrMap, It->second);
+ if (!ResOrErr) {
+ consumeError(ResOrErr.takeError());
+ return "(unknown)";
+ }
+
+ auto &DI = *ResOrErr;
+ F << sys::path::filename(DI.FileName).str() << ":" << DI.Line << ":"
+ << DI.Column;
+
+ return F.str();
+}
diff --git a/tools/llvm-xray/func-id-helper.h b/tools/llvm-xray/func-id-helper.h
new file mode 100644
index 000000000000..7348a7100b05
--- /dev/null
+++ b/tools/llvm-xray/func-id-helper.h
@@ -0,0 +1,49 @@
+//===- func-id-helper.h - XRay Function ID Conversion Helpers -------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines helper tools dealing with XRay-generated function ids.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
+#define LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
+
+#include "llvm/DebugInfo/Symbolize/Symbolize.h"
+#include <unordered_map>
+
+namespace llvm {
+namespace xray {
+
+// This class consolidates common operations related to Function IDs.
+class FuncIdConversionHelper {
+public:
+ using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
+
+private:
+ std::string BinaryInstrMap;
+ symbolize::LLVMSymbolizer &Symbolizer;
+ const FunctionAddressMap &FunctionAddresses;
+
+public:
+ FuncIdConversionHelper(std::string BinaryInstrMap,
+ symbolize::LLVMSymbolizer &Symbolizer,
+ const FunctionAddressMap &FunctionAddresses)
+ : BinaryInstrMap(std::move(BinaryInstrMap)), Symbolizer(Symbolizer),
+ FunctionAddresses(FunctionAddresses) {}
+
+ // Returns the symbol or a string representation of the function id.
+ std::string SymbolOrNumber(int32_t FuncId) const;
+
+ // Returns the file and column from debug info for the given function id.
+ std::string FileLineAndColumn(int32_t FuncId) const;
+};
+
+} // namespace xray
+} // namespace llvm
+
+#endif // LLVM_TOOLS_LLVM_XRAY_FUNC_ID_HELPER_H
diff --git a/tools/llvm-xray/xray-account.cc b/tools/llvm-xray/xray-account.cc
new file mode 100644
index 000000000000..671a5a073eec
--- /dev/null
+++ b/tools/llvm-xray/xray-account.cc
@@ -0,0 +1,485 @@
+//===- xray-account.h - XRay Function Call Accounting ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements basic function call accounting from an XRay trace.
+//
+//===----------------------------------------------------------------------===//
+
+#include <algorithm>
+#include <cassert>
+#include <numeric>
+#include <system_error>
+#include <utility>
+
+#include "xray-account.h"
+#include "xray-extract.h"
+#include "xray-registry.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/XRay/Trace.h"
+
+using namespace llvm;
+using namespace llvm::xray;
+
+static cl::SubCommand Account("account", "Function call accounting");
+static cl::opt<std::string> AccountInput(cl::Positional,
+ cl::desc("<xray log file>"),
+ cl::Required, cl::sub(Account));
+static cl::opt<bool>
+ AccountKeepGoing("keep-going", cl::desc("Keep going on errors encountered"),
+ cl::sub(Account), cl::init(false));
+static cl::alias AccountKeepGoing2("k", cl::aliasopt(AccountKeepGoing),
+ cl::desc("Alias for -keep_going"),
+ cl::sub(Account));
+static cl::opt<bool> AccountDeduceSiblingCalls(
+ "deduce-sibling-calls",
+ cl::desc("Deduce sibling calls when unrolling function call stacks"),
+ cl::sub(Account), cl::init(false));
+static cl::alias
+ AccountDeduceSiblingCalls2("d", cl::aliasopt(AccountDeduceSiblingCalls),
+ cl::desc("Alias for -deduce_sibling_calls"),
+ cl::sub(Account));
+static cl::opt<std::string>
+ AccountOutput("output", cl::value_desc("output file"), cl::init("-"),
+ cl::desc("output file; use '-' for stdout"),
+ cl::sub(Account));
+static cl::alias AccountOutput2("o", cl::aliasopt(AccountOutput),
+ cl::desc("Alias for -output"),
+ cl::sub(Account));
+enum class AccountOutputFormats { TEXT, CSV };
+static cl::opt<AccountOutputFormats>
+ AccountOutputFormat("format", cl::desc("output format"),
+ cl::values(clEnumValN(AccountOutputFormats::TEXT,
+ "text", "report stats in text"),
+ clEnumValN(AccountOutputFormats::CSV, "csv",
+ "report stats in csv")),
+ cl::sub(Account));
+static cl::alias AccountOutputFormat2("f", cl::desc("Alias of -format"),
+ cl::aliasopt(AccountOutputFormat),
+ cl::sub(Account));
+
+enum class SortField {
+ FUNCID,
+ COUNT,
+ MIN,
+ MED,
+ PCT90,
+ PCT99,
+ MAX,
+ SUM,
+ FUNC,
+};
+
+static cl::opt<SortField> AccountSortOutput(
+ "sort", cl::desc("sort output by this field"), cl::value_desc("field"),
+ cl::sub(Account), cl::init(SortField::FUNCID),
+ cl::values(clEnumValN(SortField::FUNCID, "funcid", "function id"),
+ clEnumValN(SortField::COUNT, "count", "funciton call counts"),
+ clEnumValN(SortField::MIN, "min", "minimum function durations"),
+ clEnumValN(SortField::MED, "med", "median function durations"),
+ clEnumValN(SortField::PCT90, "90p", "90th percentile durations"),
+ clEnumValN(SortField::PCT99, "99p", "99th percentile durations"),
+ clEnumValN(SortField::MAX, "max", "maximum function durations"),
+ clEnumValN(SortField::SUM, "sum", "sum of call durations"),
+ clEnumValN(SortField::FUNC, "func", "function names")));
+static cl::alias AccountSortOutput2("s", cl::aliasopt(AccountSortOutput),
+ cl::desc("Alias for -sort"),
+ cl::sub(Account));
+
+enum class SortDirection {
+ ASCENDING,
+ DESCENDING,
+};
+static cl::opt<SortDirection> AccountSortOrder(
+ "sortorder", cl::desc("sort ordering"), cl::init(SortDirection::ASCENDING),
+ cl::values(clEnumValN(SortDirection::ASCENDING, "asc", "ascending"),
+ clEnumValN(SortDirection::DESCENDING, "dsc", "descending")),
+ cl::sub(Account));
+static cl::alias AccountSortOrder2("r", cl::aliasopt(AccountSortOrder),
+ cl::desc("Alias for -sortorder"),
+ cl::sub(Account));
+
+static cl::opt<int> AccountTop("top", cl::desc("only show the top N results"),
+ cl::value_desc("N"), cl::sub(Account),
+ cl::init(-1));
+static cl::alias AccountTop2("p", cl::desc("Alias for -top"),
+ cl::aliasopt(AccountTop), cl::sub(Account));
+
+static cl::opt<std::string>
+ AccountInstrMap("instr_map",
+ cl::desc("binary with the instrumentation map, or "
+ "a separate instrumentation map"),
+ cl::value_desc("binary with xray_instr_map"),
+ cl::sub(Account), cl::init(""));
+static cl::alias AccountInstrMap2("m", cl::aliasopt(AccountInstrMap),
+ cl::desc("Alias for -instr_map"),
+ cl::sub(Account));
+static cl::opt<InstrumentationMapExtractor::InputFormats> InstrMapFormat(
+ "instr-map-format", cl::desc("format of instrumentation map"),
+ cl::values(clEnumValN(InstrumentationMapExtractor::InputFormats::ELF, "elf",
+ "instrumentation map in an ELF header"),
+ clEnumValN(InstrumentationMapExtractor::InputFormats::YAML,
+ "yaml", "instrumentation map in YAML")),
+ cl::sub(Account), cl::init(InstrumentationMapExtractor::InputFormats::ELF));
+static cl::alias InstrMapFormat2("t", cl::aliasopt(InstrMapFormat),
+ cl::desc("Alias for -instr-map-format"),
+ cl::sub(Account));
+
+namespace {
+
+template <class T, class U> void setMinMax(std::pair<T, T> &MM, U &&V) {
+ if (MM.first == 0 || MM.second == 0)
+ MM = std::make_pair(std::forward<U>(V), std::forward<U>(V));
+ else
+ MM = std::make_pair(std::min(MM.first, V), std::max(MM.second, V));
+}
+
+template <class T> T diff(T L, T R) { return std::max(L, R) - std::min(L, R); }
+
+} // namespace
+
+bool LatencyAccountant::accountRecord(const XRayRecord &Record) {
+ setMinMax(PerThreadMinMaxTSC[Record.TId], Record.TSC);
+ setMinMax(PerCPUMinMaxTSC[Record.CPU], Record.TSC);
+
+ if (CurrentMaxTSC == 0)
+ CurrentMaxTSC = Record.TSC;
+
+ if (Record.TSC < CurrentMaxTSC)
+ return false;
+
+ auto &ThreadStack = PerThreadFunctionStack[Record.TId];
+ switch (Record.Type) {
+ case RecordTypes::ENTER: {
+ // Function Enter
+ ThreadStack.emplace_back(Record.FuncId, Record.TSC);
+ break;
+ }
+ case RecordTypes::EXIT: {
+ // Function Exit
+ if (ThreadStack.back().first == Record.FuncId) {
+ const auto &Top = ThreadStack.back();
+ recordLatency(Top.first, diff(Top.second, Record.TSC));
+ ThreadStack.pop_back();
+ break;
+ }
+
+ if (!DeduceSiblingCalls)
+ return false;
+
+ // Look for the parent up the stack.
+ auto Parent =
+ std::find_if(ThreadStack.rbegin(), ThreadStack.rend(),
+ [&](const std::pair<const int32_t, uint64_t> &E) {
+ return E.first == Record.FuncId;
+ });
+ if (Parent == ThreadStack.rend())
+ return false;
+
+ // Account time for this apparently sibling call exit up the stack.
+ // Considering the following case:
+ //
+ // f()
+ // g()
+ // h()
+ //
+ // We might only ever see the following entries:
+ //
+ // -> f()
+ // -> g()
+ // -> h()
+ // <- h()
+ // <- f()
+ //
+ // Now we don't see the exit to g() because some older version of the XRay
+ // runtime wasn't instrumenting tail exits. If we don't deduce tail calls,
+ // we may potentially never account time for g() -- and this code would have
+ // already bailed out, because `<- f()` doesn't match the current "top" of
+ // stack where we're waiting for the exit to `g()` instead. This is not
+ // ideal and brittle -- so instead we provide a potentially inaccurate
+ // accounting of g() instead, computing it from the exit of f().
+ //
+ // While it might be better that we account the time between `-> g()` and
+ // `-> h()` as the proper accounting of time for g() here, this introduces
+ // complexity to do correctly (need to backtrack, etc.).
+ //
+ // FIXME: Potentially implement the more complex deduction algorithm?
+ auto I = std::next(Parent).base();
+ for (auto &E : make_range(I, ThreadStack.end())) {
+ recordLatency(E.first, diff(E.second, Record.TSC));
+ }
+ ThreadStack.erase(I, ThreadStack.end());
+ break;
+ }
+ }
+
+ return true;
+}
+
+namespace {
+
+// We consolidate the data into a struct which we can output in various forms.
+struct ResultRow {
+ uint64_t Count;
+ double Min;
+ double Median;
+ double Pct90;
+ double Pct99;
+ double Max;
+ double Sum;
+ std::string DebugInfo;
+ std::string Function;
+};
+
+ResultRow getStats(std::vector<uint64_t> &Timings) {
+ assert(!Timings.empty());
+ ResultRow R;
+ R.Sum = std::accumulate(Timings.begin(), Timings.end(), 0.0);
+ auto MinMax = std::minmax_element(Timings.begin(), Timings.end());
+ R.Min = *MinMax.first;
+ R.Max = *MinMax.second;
+ auto MedianOff = Timings.size() / 2;
+ std::nth_element(Timings.begin(), Timings.begin() + MedianOff, Timings.end());
+ R.Median = Timings[MedianOff];
+ auto Pct90Off = std::floor(Timings.size() * 0.9);
+ std::nth_element(Timings.begin(), Timings.begin() + Pct90Off, Timings.end());
+ R.Pct90 = Timings[Pct90Off];
+ auto Pct99Off = std::floor(Timings.size() * 0.99);
+ std::nth_element(Timings.begin(), Timings.begin() + Pct90Off, Timings.end());
+ R.Pct99 = Timings[Pct99Off];
+ R.Count = Timings.size();
+ return R;
+}
+
+} // namespace
+
+template <class F>
+void LatencyAccountant::exportStats(const XRayFileHeader &Header, F Fn) const {
+ using TupleType = std::tuple<int32_t, uint64_t, ResultRow>;
+ std::vector<TupleType> Results;
+ Results.reserve(FunctionLatencies.size());
+ for (auto FT : FunctionLatencies) {
+ const auto &FuncId = FT.first;
+ auto &Timings = FT.second;
+ Results.emplace_back(FuncId, Timings.size(), getStats(Timings));
+ auto &Row = std::get<2>(Results.back());
+ if (Header.CycleFrequency) {
+ double CycleFrequency = Header.CycleFrequency;
+ Row.Min /= CycleFrequency;
+ Row.Median /= CycleFrequency;
+ Row.Pct90 /= CycleFrequency;
+ Row.Pct99 /= CycleFrequency;
+ Row.Max /= CycleFrequency;
+ Row.Sum /= CycleFrequency;
+ }
+
+ Row.Function = FuncIdHelper.SymbolOrNumber(FuncId);
+ Row.DebugInfo = FuncIdHelper.FileLineAndColumn(FuncId);
+ }
+
+ // Sort the data according to user-provided flags.
+ switch (AccountSortOutput) {
+ case SortField::FUNCID:
+ std::sort(Results.begin(), Results.end(),
+ [](const TupleType &L, const TupleType &R) {
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return std::get<0>(L) < std::get<0>(R);
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return std::get<0>(L) > std::get<0>(R);
+ llvm_unreachable("Unknown sort direction");
+ });
+ break;
+ case SortField::COUNT:
+ std::sort(Results.begin(), Results.end(),
+ [](const TupleType &L, const TupleType &R) {
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return std::get<1>(L) < std::get<1>(R);
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return std::get<1>(L) > std::get<1>(R);
+ llvm_unreachable("Unknown sort direction");
+ });
+ break;
+ default:
+ // Here we need to look into the ResultRow for the rest of the data that
+ // we want to sort by.
+ std::sort(Results.begin(), Results.end(),
+ [&](const TupleType &L, const TupleType &R) {
+ auto &LR = std::get<2>(L);
+ auto &RR = std::get<2>(R);
+ switch (AccountSortOutput) {
+ case SortField::COUNT:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Count < RR.Count;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Count > RR.Count;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::MIN:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Min < RR.Min;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Min > RR.Min;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::MED:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Median < RR.Median;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Median > RR.Median;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::PCT90:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Pct90 < RR.Pct90;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Pct90 > RR.Pct90;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::PCT99:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Pct99 < RR.Pct99;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Pct99 > RR.Pct99;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::MAX:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Max < RR.Max;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Max > RR.Max;
+ llvm_unreachable("Unknown sort direction");
+ case SortField::SUM:
+ if (AccountSortOrder == SortDirection::ASCENDING)
+ return LR.Sum < RR.Sum;
+ if (AccountSortOrder == SortDirection::DESCENDING)
+ return LR.Sum > RR.Sum;
+ llvm_unreachable("Unknown sort direction");
+ default:
+ llvm_unreachable("Unsupported sort order");
+ }
+ });
+ break;
+ }
+
+ if (AccountTop > 0)
+ Results.erase(Results.begin() + AccountTop.getValue(), Results.end());
+
+ for (const auto &R : Results)
+ Fn(std::get<0>(R), std::get<1>(R), std::get<2>(R));
+}
+
+void LatencyAccountant::exportStatsAsText(raw_ostream &OS,
+ const XRayFileHeader &Header) const {
+ OS << "Functions with latencies: " << FunctionLatencies.size() << "\n";
+
+ // We spend some effort to make the text output more readable, so we do the
+ // following formatting decisions for each of the fields:
+ //
+ // - funcid: 32-bit, but we can determine the largest number and be
+ // between
+ // a minimum of 5 characters, up to 9 characters, right aligned.
+ // - count: 64-bit, but we can determine the largest number and be
+ // between
+ // a minimum of 5 characters, up to 9 characters, right aligned.
+ // - min, median, 90pct, 99pct, max: double precision, but we want to keep
+ // the values in seconds, with microsecond precision (0.000'001), so we
+ // have at most 6 significant digits, with the whole number part to be
+ // at
+ // least 1 character. For readability we'll right-align, with full 9
+ // characters each.
+ // - debug info, function name: we format this as a concatenation of the
+ // debug info and the function name.
+ //
+ static constexpr char StatsHeaderFormat[] =
+ "{0,+9} {1,+10} [{2,+9}, {3,+9}, {4,+9}, {5,+9}, {6,+9}] {7,+9}";
+ static constexpr char StatsFormat[] =
+ R"({0,+9} {1,+10} [{2,+9:f6}, {3,+9:f6}, {4,+9:f6}, {5,+9:f6}, {6,+9:f6}] {7,+9:f6})";
+ OS << llvm::formatv(StatsHeaderFormat, "funcid", "count", "min", "med", "90p",
+ "99p", "max", "sum")
+ << llvm::formatv(" {0,-12}\n", "function");
+ exportStats(Header, [&](int32_t FuncId, size_t Count, const ResultRow &Row) {
+ OS << llvm::formatv(StatsFormat, FuncId, Count, Row.Min, Row.Median,
+ Row.Pct90, Row.Pct99, Row.Max, Row.Sum)
+ << " " << Row.DebugInfo << ": " << Row.Function << "\n";
+ });
+}
+
+void LatencyAccountant::exportStatsAsCSV(raw_ostream &OS,
+ const XRayFileHeader &Header) const {
+ OS << "funcid,count,min,median,90%ile,99%ile,max,sum,debug,function\n";
+ exportStats(Header, [&](int32_t FuncId, size_t Count, const ResultRow &Row) {
+ OS << FuncId << ',' << Count << ',' << Row.Min << ',' << Row.Median << ','
+ << Row.Pct90 << ',' << Row.Pct99 << ',' << Row.Max << "," << Row.Sum
+ << ",\"" << Row.DebugInfo << "\",\"" << Row.Function << "\"\n";
+ });
+}
+
+using namespace llvm::xray;
+
+static CommandRegistration Unused(&Account, []() -> Error {
+ int Fd;
+ auto EC = sys::fs::openFileForRead(AccountInput, Fd);
+ if (EC)
+ return make_error<StringError>(
+ Twine("Cannot open file '") + AccountInput + "'", EC);
+
+ Error Err = Error::success();
+ xray::InstrumentationMapExtractor Extractor(AccountInstrMap, InstrMapFormat,
+ Err);
+ if (auto E = handleErrors(
+ std::move(Err), [&](std::unique_ptr<StringError> SE) -> Error {
+ if (SE->convertToErrorCode() == std::errc::no_such_file_or_directory)
+ return Error::success();
+ return Error(std::move(SE));
+ }))
+ return E;
+
+ raw_fd_ostream OS(AccountOutput, EC, sys::fs::OpenFlags::F_Text);
+ if (EC)
+ return make_error<StringError>(
+ Twine("Cannot open file '") + AccountOutput + "' for writing.", EC);
+
+ const auto &FunctionAddresses = Extractor.getFunctionAddresses();
+ symbolize::LLVMSymbolizer::Options Opts(
+ symbolize::FunctionNameKind::LinkageName, true, true, false, "");
+ symbolize::LLVMSymbolizer Symbolizer(Opts);
+ llvm::xray::FuncIdConversionHelper FuncIdHelper(AccountInstrMap, Symbolizer,
+ FunctionAddresses);
+ xray::LatencyAccountant FCA(FuncIdHelper, AccountDeduceSiblingCalls);
+ if (auto TraceOrErr = loadTraceFile(AccountInput)) {
+ auto &T = *TraceOrErr;
+ for (const auto &Record : T) {
+ if (FCA.accountRecord(Record))
+ continue;
+ for (const auto &ThreadStack : FCA.getPerThreadFunctionStack()) {
+ errs() << "Thread ID: " << ThreadStack.first << "\n";
+ auto Level = ThreadStack.second.size();
+ for (const auto &Entry : llvm::reverse(ThreadStack.second))
+ errs() << "#" << Level-- << "\t"
+ << FuncIdHelper.SymbolOrNumber(Entry.first) << '\n';
+ }
+ if (!AccountKeepGoing)
+ return make_error<StringError>(
+ Twine("Failed accounting function calls in file '") + AccountInput +
+ "'.",
+ std::make_error_code(std::errc::executable_format_error));
+ }
+ switch (AccountOutputFormat) {
+ case AccountOutputFormats::TEXT:
+ FCA.exportStatsAsText(OS, T.getFileHeader());
+ break;
+ case AccountOutputFormats::CSV:
+ FCA.exportStatsAsCSV(OS, T.getFileHeader());
+ break;
+ }
+ } else {
+ return joinErrors(
+ make_error<StringError>(
+ Twine("Failed loading input file '") + AccountInput + "'",
+ std::make_error_code(std::errc::executable_format_error)),
+ TraceOrErr.takeError());
+ }
+
+ return Error::success();
+});
diff --git a/tools/llvm-xray/xray-account.h b/tools/llvm-xray/xray-account.h
new file mode 100644
index 000000000000..cc9ba897e537
--- /dev/null
+++ b/tools/llvm-xray/xray-account.h
@@ -0,0 +1,109 @@
+//===- xray-account.h - XRay Function Call Accounting ---------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the interface for performing some basic function call
+// accounting from an XRay trace.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H
+#define LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H
+
+#include <map>
+#include <utility>
+#include <vector>
+
+#include "func-id-helper.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/XRay/XRayRecord.h"
+
+namespace llvm {
+namespace xray {
+
+class LatencyAccountant {
+public:
+ typedef std::map<int32_t, std::vector<uint64_t>> FunctionLatencyMap;
+ typedef std::map<llvm::sys::ProcessInfo::ProcessId,
+ std::pair<uint64_t, uint64_t>>
+ PerThreadMinMaxTSCMap;
+ typedef std::map<uint8_t, std::pair<uint64_t, uint64_t>> PerCPUMinMaxTSCMap;
+ typedef std::vector<std::pair<int32_t, uint64_t>> FunctionStack;
+ typedef std::map<llvm::sys::ProcessInfo::ProcessId, FunctionStack>
+ PerThreadFunctionStackMap;
+
+private:
+ PerThreadFunctionStackMap PerThreadFunctionStack;
+ FunctionLatencyMap FunctionLatencies;
+ PerThreadMinMaxTSCMap PerThreadMinMaxTSC;
+ PerCPUMinMaxTSCMap PerCPUMinMaxTSC;
+ FuncIdConversionHelper &FuncIdHelper;
+
+ bool DeduceSiblingCalls = false;
+ uint64_t CurrentMaxTSC = 0;
+
+ void recordLatency(int32_t FuncId, uint64_t Latency) {
+ FunctionLatencies[FuncId].push_back(Latency);
+ }
+
+public:
+ explicit LatencyAccountant(FuncIdConversionHelper &FuncIdHelper,
+ bool DeduceSiblingCalls)
+ : FuncIdHelper(FuncIdHelper), DeduceSiblingCalls(DeduceSiblingCalls) {}
+
+ const FunctionLatencyMap &getFunctionLatencies() const {
+ return FunctionLatencies;
+ }
+
+ const PerThreadMinMaxTSCMap &getPerThreadMinMaxTSC() const {
+ return PerThreadMinMaxTSC;
+ }
+
+ const PerCPUMinMaxTSCMap &getPerCPUMinMaxTSC() const {
+ return PerCPUMinMaxTSC;
+ }
+
+ /// Returns false in case we fail to account the provided record. This happens
+ /// in the following cases:
+ ///
+ /// - An exit record does not match any entry records for the same function.
+ /// If we've been set to deduce sibling calls, we try walking up the stack
+ /// and recording times for the higher level functions.
+ /// - A record has a TSC that's before the latest TSC that has been
+ /// recorded. We still record the TSC for the min-max.
+ ///
+ bool accountRecord(const XRayRecord &Record);
+
+ const FunctionStack *
+ getThreadFunctionStack(llvm::sys::ProcessInfo::ProcessId TId) const {
+ auto I = PerThreadFunctionStack.find(TId);
+ if (I == PerThreadFunctionStack.end())
+ return nullptr;
+ return &I->second;
+ }
+
+ const PerThreadFunctionStackMap &getPerThreadFunctionStack() const {
+ return PerThreadFunctionStack;
+ }
+
+ // Output Functions
+ // ================
+
+ void exportStatsAsText(raw_ostream &OS, const XRayFileHeader &Header) const;
+ void exportStatsAsCSV(raw_ostream &OS, const XRayFileHeader &Header) const;
+
+private:
+ // Internal helper to implement common parts of the exportStatsAs...
+ // functions.
+ template <class F> void exportStats(const XRayFileHeader &Header, F fn) const;
+};
+
+} // namespace xray
+} // namespace llvm
+
+#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_ACCOUNT_H
diff --git a/tools/llvm-xray/xray-converter.cc b/tools/llvm-xray/xray-converter.cc
new file mode 100644
index 000000000000..31275e2902f2
--- /dev/null
+++ b/tools/llvm-xray/xray-converter.cc
@@ -0,0 +1,202 @@
+//===- xray-converter.cc - XRay Trace Conversion --------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Implements the trace conversion functions.
+//
+//===----------------------------------------------------------------------===//
+#include "xray-converter.h"
+
+#include "xray-extract.h"
+#include "xray-registry.h"
+#include "llvm/DebugInfo/Symbolize/Symbolize.h"
+#include "llvm/Support/EndianStream.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/XRay/Trace.h"
+#include "llvm/XRay/YAMLXRayRecord.h"
+
+using namespace llvm;
+using namespace xray;
+
+// llvm-xray convert
+// ----------------------------------------------------------------------------
+static cl::SubCommand Convert("convert", "Trace Format Conversion");
+static cl::opt<std::string> ConvertInput(cl::Positional,
+ cl::desc("<xray log file>"),
+ cl::Required, cl::sub(Convert));
+enum class ConvertFormats { BINARY, YAML };
+static cl::opt<ConvertFormats> ConvertOutputFormat(
+ "output-format", cl::desc("output format"),
+ cl::values(clEnumValN(ConvertFormats::BINARY, "raw", "output in binary"),
+ clEnumValN(ConvertFormats::YAML, "yaml", "output in yaml")),
+ cl::sub(Convert));
+static cl::alias ConvertOutputFormat2("f", cl::aliasopt(ConvertOutputFormat),
+ cl::desc("Alias for -output-format"),
+ cl::sub(Convert));
+static cl::opt<std::string>
+ ConvertOutput("output", cl::value_desc("output file"), cl::init("-"),
+ cl::desc("output file; use '-' for stdout"),
+ cl::sub(Convert));
+static cl::alias ConvertOutput2("o", cl::aliasopt(ConvertOutput),
+ cl::desc("Alias for -output"),
+ cl::sub(Convert));
+
+static cl::opt<bool>
+ ConvertSymbolize("symbolize",
+ cl::desc("symbolize function ids from the input log"),
+ cl::init(false), cl::sub(Convert));
+static cl::alias ConvertSymbolize2("y", cl::aliasopt(ConvertSymbolize),
+ cl::desc("Alias for -symbolize"),
+ cl::sub(Convert));
+
+static cl::opt<std::string>
+ ConvertInstrMap("instr_map",
+ cl::desc("binary with the instrumentation map, or "
+ "a separate instrumentation map"),
+ cl::value_desc("binary with xray_instr_map"),
+ cl::sub(Convert), cl::init(""));
+static cl::alias ConvertInstrMap2("m", cl::aliasopt(ConvertInstrMap),
+ cl::desc("Alias for -instr_map"),
+ cl::sub(Convert));
+static cl::opt<bool> ConvertSortInput(
+ "sort",
+ cl::desc("determines whether to sort input log records by timestamp"),
+ cl::sub(Convert), cl::init(true));
+static cl::alias ConvertSortInput2("s", cl::aliasopt(ConvertSortInput),
+ cl::desc("Alias for -sort"),
+ cl::sub(Convert));
+static cl::opt<InstrumentationMapExtractor::InputFormats> InstrMapFormat(
+ "instr-map-format", cl::desc("format of instrumentation map"),
+ cl::values(clEnumValN(InstrumentationMapExtractor::InputFormats::ELF, "elf",
+ "instrumentation map in an ELF header"),
+ clEnumValN(InstrumentationMapExtractor::InputFormats::YAML,
+ "yaml", "instrumentation map in YAML")),
+ cl::sub(Convert), cl::init(InstrumentationMapExtractor::InputFormats::ELF));
+static cl::alias InstrMapFormat2("t", cl::aliasopt(InstrMapFormat),
+ cl::desc("Alias for -instr-map-format"),
+ cl::sub(Convert));
+
+using llvm::yaml::IO;
+using llvm::yaml::Output;
+
+void TraceConverter::exportAsYAML(const Trace &Records, raw_ostream &OS) {
+ YAMLXRayTrace Trace;
+ const auto &FH = Records.getFileHeader();
+ Trace.Header = {FH.Version, FH.Type, FH.ConstantTSC, FH.NonstopTSC,
+ FH.CycleFrequency};
+ Trace.Records.reserve(Records.size());
+ for (const auto &R : Records) {
+ Trace.Records.push_back({R.RecordType, R.CPU, R.Type, R.FuncId,
+ Symbolize ? FuncIdHelper.SymbolOrNumber(R.FuncId)
+ : std::to_string(R.FuncId),
+ R.TSC, R.TId});
+ }
+ Output Out(OS);
+ Out << Trace;
+}
+
+void TraceConverter::exportAsRAWv1(const Trace &Records, raw_ostream &OS) {
+ // First write out the file header, in the correct endian-appropriate format
+ // (XRay assumes currently little endian).
+ support::endian::Writer<support::endianness::little> Writer(OS);
+ const auto &FH = Records.getFileHeader();
+ Writer.write(FH.Version);
+ Writer.write(FH.Type);
+ uint32_t Bitfield{0};
+ if (FH.ConstantTSC)
+ Bitfield |= 1uL;
+ if (FH.NonstopTSC)
+ Bitfield |= 1uL << 1;
+ Writer.write(Bitfield);
+ Writer.write(FH.CycleFrequency);
+
+ // There's 16 bytes of padding at the end of the file header.
+ static constexpr uint32_t Padding4B = 0;
+ Writer.write(Padding4B);
+ Writer.write(Padding4B);
+ Writer.write(Padding4B);
+ Writer.write(Padding4B);
+
+ // Then write out the rest of the records, still in an endian-appropriate
+ // format.
+ for (const auto &R : Records) {
+ Writer.write(R.RecordType);
+ Writer.write(R.CPU);
+ switch (R.Type) {
+ case RecordTypes::ENTER:
+ Writer.write(uint8_t{0});
+ break;
+ case RecordTypes::EXIT:
+ Writer.write(uint8_t{1});
+ break;
+ }
+ Writer.write(R.FuncId);
+ Writer.write(R.TSC);
+ Writer.write(R.TId);
+ Writer.write(Padding4B);
+ Writer.write(Padding4B);
+ Writer.write(Padding4B);
+ }
+}
+
+namespace llvm {
+namespace xray {
+
+static CommandRegistration Unused(&Convert, []() -> Error {
+ // FIXME: Support conversion to BINARY when upgrading XRay trace versions.
+ int Fd;
+ auto EC = sys::fs::openFileForRead(ConvertInput, Fd);
+ if (EC)
+ return make_error<StringError>(
+ Twine("Cannot open file '") + ConvertInput + "'", EC);
+
+ Error Err = Error::success();
+ xray::InstrumentationMapExtractor Extractor(ConvertInstrMap, InstrMapFormat,
+ Err);
+ handleAllErrors(std::move(Err),
+ [&](const ErrorInfoBase &E) { E.log(errs()); });
+
+ const auto &FunctionAddresses = Extractor.getFunctionAddresses();
+ symbolize::LLVMSymbolizer::Options Opts(
+ symbolize::FunctionNameKind::LinkageName, true, true, false, "");
+ symbolize::LLVMSymbolizer Symbolizer(Opts);
+ llvm::xray::FuncIdConversionHelper FuncIdHelper(ConvertInstrMap, Symbolizer,
+ FunctionAddresses);
+ llvm::xray::TraceConverter TC(FuncIdHelper, ConvertSymbolize);
+ raw_fd_ostream OS(ConvertOutput, EC,
+ ConvertOutputFormat == ConvertFormats::BINARY
+ ? sys::fs::OpenFlags::F_None
+ : sys::fs::OpenFlags::F_Text);
+ if (EC)
+ return make_error<StringError>(
+ Twine("Cannot open file '") + ConvertOutput + "' for writing.", EC);
+
+ if (auto TraceOrErr = loadTraceFile(ConvertInput, ConvertSortInput)) {
+ auto &T = *TraceOrErr;
+ switch (ConvertOutputFormat) {
+ case ConvertFormats::YAML:
+ TC.exportAsYAML(T, OS);
+ break;
+ case ConvertFormats::BINARY:
+ TC.exportAsRAWv1(T, OS);
+ break;
+ }
+ } else {
+ return joinErrors(
+ make_error<StringError>(
+ Twine("Failed loading input file '") + ConvertInput + "'.",
+ std::make_error_code(std::errc::executable_format_error)),
+ TraceOrErr.takeError());
+ }
+ return Error::success();
+});
+
+} // namespace xray
+} // namespace llvm
diff --git a/tools/llvm-xray/xray-converter.h b/tools/llvm-xray/xray-converter.h
new file mode 100644
index 000000000000..fa0d5e132f14
--- /dev/null
+++ b/tools/llvm-xray/xray-converter.h
@@ -0,0 +1,39 @@
+//===- xray-converter.h - XRay Trace Conversion ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines the TraceConverter class for turning binary traces into
+// human-readable text and vice versa.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_XRAY_XRAY_CONVERTER_H
+#define LLVM_TOOLS_LLVM_XRAY_XRAY_CONVERTER_H
+
+#include "func-id-helper.h"
+#include "llvm/XRay/XRayRecord.h"
+#include "llvm/XRay/Trace.h"
+
+namespace llvm {
+namespace xray {
+
+class TraceConverter {
+ FuncIdConversionHelper &FuncIdHelper;
+ bool Symbolize;
+
+public:
+ TraceConverter(FuncIdConversionHelper &FuncIdHelper, bool Symbolize = false)
+ : FuncIdHelper(FuncIdHelper), Symbolize(Symbolize) {}
+
+ void exportAsYAML(const Trace &Records, raw_ostream &OS);
+ void exportAsRAWv1(const Trace &Records, raw_ostream &OS);
+};
+
+} // namespace xray
+} // namespace llvm
+
+#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_CONVERTER_H
diff --git a/tools/llvm-xray/xray-extract.cc b/tools/llvm-xray/xray-extract.cc
index e51b64c8ad6e..49ecd7421137 100644
--- a/tools/llvm-xray/xray-extract.cc
+++ b/tools/llvm-xray/xray-extract.cc
@@ -162,8 +162,7 @@ llvm::Error LoadBinaryInstrELF(
"'.",
std::make_error_code(std::errc::executable_format_error));
}
- auto AlwaysInstrument = Extractor.getU8(&OffsetPtr);
- Entry.AlwaysInstrument = AlwaysInstrument != 0;
+ Entry.AlwaysInstrument = Extractor.getU8(&OffsetPtr) != 0;
// We replicate the function id generation scheme implemented in the runtime
// here. Ideally we should be able to break it out, or output this map from
@@ -185,30 +184,82 @@ llvm::Error LoadBinaryInstrELF(
return llvm::Error::success();
}
+Error LoadYAMLInstrMap(
+ StringRef Filename, std::deque<SledEntry> &Sleds,
+ InstrumentationMapExtractor::FunctionAddressMap &InstrMap,
+ InstrumentationMapExtractor::FunctionAddressReverseMap &FunctionIds) {
+ int Fd;
+ if (auto EC = sys::fs::openFileForRead(Filename, Fd))
+ return make_error<StringError>(
+ Twine("Failed opening file '") + Filename + "' for reading.", EC);
+
+ uint64_t FileSize;
+ if (auto EC = sys::fs::file_size(Filename, FileSize))
+ return make_error<StringError>(
+ Twine("Failed getting size of file '") + Filename + "'.", EC);
+
+ std::error_code EC;
+ sys::fs::mapped_file_region MappedFile(
+ Fd, sys::fs::mapped_file_region::mapmode::readonly, FileSize, 0, EC);
+ if (EC)
+ return make_error<StringError>(
+ Twine("Failed memory-mapping file '") + Filename + "'.", EC);
+
+ std::vector<YAMLXRaySledEntry> YAMLSleds;
+ Input In(StringRef(MappedFile.data(), MappedFile.size()));
+ In >> YAMLSleds;
+ if (In.error())
+ return make_error<StringError>(
+ Twine("Failed loading YAML document from '") + Filename + "'.",
+ In.error());
+
+ for (const auto &Y : YAMLSleds) {
+ InstrMap[Y.FuncId] = Y.Function;
+ FunctionIds[Y.Function] = Y.FuncId;
+ Sleds.push_back(
+ SledEntry{Y.Address, Y.Function, Y.Kind, Y.AlwaysInstrument});
+ }
+ return Error::success();
+}
+
} // namespace
InstrumentationMapExtractor::InstrumentationMapExtractor(std::string Filename,
InputFormats Format,
Error &EC) {
ErrorAsOutParameter ErrAsOutputParam(&EC);
+ if (Filename.empty()) {
+ EC = Error::success();
+ return;
+ }
switch (Format) {
case InputFormats::ELF: {
EC = handleErrors(
LoadBinaryInstrELF(Filename, Sleds, FunctionAddresses, FunctionIds),
- [](std::unique_ptr<ErrorInfoBase> E) {
+ [&](std::unique_ptr<ErrorInfoBase> E) {
return joinErrors(
make_error<StringError>(
Twine("Cannot extract instrumentation map from '") +
- ExtractInput + "'.",
+ Filename + "'.",
std::make_error_code(std::errc::executable_format_error)),
std::move(E));
});
break;
}
- default:
- llvm_unreachable("Input format type not supported yet.");
+ case InputFormats::YAML: {
+ EC = handleErrors(
+ LoadYAMLInstrMap(Filename, Sleds, FunctionAddresses, FunctionIds),
+ [&](std::unique_ptr<ErrorInfoBase> E) {
+ return joinErrors(
+ make_error<StringError>(
+ Twine("Cannot load YAML instrumentation map from '") +
+ Filename + "'.",
+ std::make_error_code(std::errc::executable_format_error)),
+ std::move(E));
+ });
break;
}
+ }
}
void InstrumentationMapExtractor::exportAsYAML(raw_ostream &OS) {
diff --git a/tools/llvm-xray/xray-record-yaml.h b/tools/llvm-xray/xray-record-yaml.h
new file mode 100644
index 000000000000..abce8ff60a94
--- /dev/null
+++ b/tools/llvm-xray/xray-record-yaml.h
@@ -0,0 +1,102 @@
+//===- xray-record-yaml.h - XRay Record YAML Support Definitions ----------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Types and traits specialisations for YAML I/O of XRay log entries.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_TOOLS_LLVM_XRAY_XRAY_RECORD_YAML_H
+#define LLVM_TOOLS_LLVM_XRAY_XRAY_RECORD_YAML_H
+
+#include <type_traits>
+
+#include "xray-record.h"
+#include "llvm/Support/YAMLTraits.h"
+
+namespace llvm {
+namespace xray {
+
+struct YAMLXRayFileHeader {
+ uint16_t Version;
+ uint16_t Type;
+ bool ConstantTSC;
+ bool NonstopTSC;
+ uint64_t CycleFrequency;
+};
+
+struct YAMLXRayRecord {
+ uint16_t RecordType;
+ uint8_t CPU;
+ RecordTypes Type;
+ int32_t FuncId;
+ std::string Function;
+ uint64_t TSC;
+ uint32_t TId;
+};
+
+struct YAMLXRayTrace {
+ YAMLXRayFileHeader Header;
+ std::vector<YAMLXRayRecord> Records;
+};
+
+using XRayRecordStorage =
+ std::aligned_storage<sizeof(XRayRecord), alignof(XRayRecord)>::type;
+
+} // namespace xray
+
+namespace yaml {
+
+// YAML Traits
+// -----------
+template <> struct ScalarEnumerationTraits<xray::RecordTypes> {
+ static void enumeration(IO &IO, xray::RecordTypes &Type) {
+ IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER);
+ IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT);
+ }
+};
+
+template <> struct MappingTraits<xray::YAMLXRayFileHeader> {
+ static void mapping(IO &IO, xray::YAMLXRayFileHeader &Header) {
+ IO.mapRequired("version", Header.Version);
+ IO.mapRequired("type", Header.Type);
+ IO.mapRequired("constant-tsc", Header.ConstantTSC);
+ IO.mapRequired("nonstop-tsc", Header.NonstopTSC);
+ IO.mapRequired("cycle-frequency", Header.CycleFrequency);
+ }
+};
+
+template <> struct MappingTraits<xray::YAMLXRayRecord> {
+ static void mapping(IO &IO, xray::YAMLXRayRecord &Record) {
+ // FIXME: Make this type actually be descriptive
+ IO.mapRequired("type", Record.RecordType);
+ IO.mapRequired("func-id", Record.FuncId);
+ IO.mapOptional("function", Record.Function);
+ IO.mapRequired("cpu", Record.CPU);
+ IO.mapRequired("thread", Record.TId);
+ IO.mapRequired("kind", Record.Type);
+ IO.mapRequired("tsc", Record.TSC);
+ }
+
+ static constexpr bool flow = true;
+};
+
+template <> struct MappingTraits<xray::YAMLXRayTrace> {
+ static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) {
+ // A trace file contains two parts, the header and the list of all the
+ // trace records.
+ IO.mapRequired("header", Trace.Header);
+ IO.mapRequired("records", Trace.Records);
+ }
+};
+
+} // namespace yaml
+} // namespace llvm
+
+LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRayRecord)
+
+#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_RECORD_YAML_H
diff --git a/tools/obj2yaml/dwarf2yaml.cpp b/tools/obj2yaml/dwarf2yaml.cpp
index cf8b3e5b9273..cbf34ed5388a 100644
--- a/tools/obj2yaml/dwarf2yaml.cpp
+++ b/tools/obj2yaml/dwarf2yaml.cpp
@@ -127,7 +127,7 @@ void dumpDebugInfo(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
NewValue.Value = 0xDEADBEEFDEADBEEF;
DWARFDie DIEWrapper(CU.get(), &DIE);
auto FormValue = DIEWrapper.getAttributeValue(AttrSpec.Attr);
- if(!FormValue)
+ if (!FormValue)
return;
auto Form = FormValue.getValue().getForm();
bool indirect = false;
@@ -211,11 +211,137 @@ void dumpDebugInfo(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
}
}
+bool dumpFileEntry(DataExtractor &Data, uint32_t &Offset,
+ DWARFYAML::File &File) {
+ File.Name = Data.getCStr(&Offset);
+ if (File.Name.empty())
+ return false;
+ File.DirIdx = Data.getULEB128(&Offset);
+ File.ModTime = Data.getULEB128(&Offset);
+ File.Length = Data.getULEB128(&Offset);
+ return true;
+}
+
+void dumpDebugLines(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
+ for (const auto &CU : DCtx.compile_units()) {
+ auto CUDIE = CU->getUnitDIE();
+ if (!CUDIE)
+ continue;
+ if (auto StmtOffset =
+ CUDIE.getAttributeValueAsSectionOffset(dwarf::DW_AT_stmt_list)) {
+ DWARFYAML::LineTable DebugLines;
+ DataExtractor LineData(DCtx.getLineSection().Data, DCtx.isLittleEndian(),
+ CU->getAddressByteSize());
+ uint32_t Offset = *StmtOffset;
+ uint64_t SizeOfPrologueLength = 4;
+ DebugLines.TotalLength = LineData.getU32(&Offset);
+ uint64_t LineTableLength = DebugLines.TotalLength;
+ if (DebugLines.TotalLength == UINT32_MAX) {
+ DebugLines.TotalLength64 = LineData.getU64(&Offset);
+ LineTableLength = DebugLines.TotalLength64;
+ SizeOfPrologueLength = 8;
+ }
+ DebugLines.Version = LineData.getU16(&Offset);
+ DebugLines.PrologueLength =
+ LineData.getUnsigned(&Offset, SizeOfPrologueLength);
+ const uint64_t EndPrologue = DebugLines.PrologueLength + Offset;
+
+ DebugLines.MinInstLength = LineData.getU8(&Offset);
+ if (DebugLines.Version >= 4)
+ DebugLines.MaxOpsPerInst = LineData.getU8(&Offset);
+ DebugLines.DefaultIsStmt = LineData.getU8(&Offset);
+ DebugLines.LineBase = LineData.getU8(&Offset);
+ DebugLines.LineRange = LineData.getU8(&Offset);
+ DebugLines.OpcodeBase = LineData.getU8(&Offset);
+
+ DebugLines.StandardOpcodeLengths.reserve(DebugLines.OpcodeBase - 1);
+ for (uint8_t i = 1; i < DebugLines.OpcodeBase; ++i)
+ DebugLines.StandardOpcodeLengths.push_back(LineData.getU8(&Offset));
+
+ while (Offset < EndPrologue) {
+ StringRef Dir = LineData.getCStr(&Offset);
+ if (!Dir.empty())
+ DebugLines.IncludeDirs.push_back(Dir);
+ else
+ break;
+ }
+
+ while (Offset < EndPrologue) {
+ DWARFYAML::File TmpFile;
+ if (dumpFileEntry(LineData, Offset, TmpFile))
+ DebugLines.Files.push_back(TmpFile);
+ else
+ break;
+ }
+
+ const uint64_t LineEnd =
+ LineTableLength + *StmtOffset + SizeOfPrologueLength;
+ while (Offset < LineEnd) {
+ DWARFYAML::LineTableOpcode NewOp;
+ NewOp.Opcode = (dwarf::LineNumberOps)LineData.getU8(&Offset);
+ if (NewOp.Opcode == 0) {
+ auto StartExt = Offset;
+ NewOp.ExtLen = LineData.getULEB128(&Offset);
+ NewOp.SubOpcode =
+ (dwarf::LineNumberExtendedOps)LineData.getU8(&Offset);
+ switch (NewOp.SubOpcode) {
+ case dwarf::DW_LNE_set_address:
+ case dwarf::DW_LNE_set_discriminator:
+ NewOp.Data = LineData.getAddress(&Offset);
+ break;
+ case dwarf::DW_LNE_define_file:
+ dumpFileEntry(LineData, Offset, NewOp.FileEntry);
+ break;
+ case dwarf::DW_LNE_end_sequence:
+ break;
+ default:
+ while (Offset < StartExt + NewOp.ExtLen)
+ NewOp.UnknownOpcodeData.push_back(LineData.getU8(&Offset));
+ }
+ } else if (NewOp.Opcode < DebugLines.OpcodeBase) {
+ switch (NewOp.Opcode) {
+ case dwarf::DW_LNS_copy:
+ case dwarf::DW_LNS_negate_stmt:
+ case dwarf::DW_LNS_set_basic_block:
+ case dwarf::DW_LNS_const_add_pc:
+ case dwarf::DW_LNS_set_prologue_end:
+ case dwarf::DW_LNS_set_epilogue_begin:
+ break;
+
+ case dwarf::DW_LNS_advance_pc:
+ case dwarf::DW_LNS_set_file:
+ case dwarf::DW_LNS_set_column:
+ case dwarf::DW_LNS_set_isa:
+ NewOp.Data = LineData.getULEB128(&Offset);
+ break;
+
+ case dwarf::DW_LNS_advance_line:
+ NewOp.SData = LineData.getSLEB128(&Offset);
+ break;
+
+ case dwarf::DW_LNS_fixed_advance_pc:
+ NewOp.Data = LineData.getU16(&Offset);
+ break;
+
+ default:
+ for (uint8_t i = 0;
+ i < DebugLines.StandardOpcodeLengths[NewOp.Opcode - 1]; ++i)
+ NewOp.StandardOpcodeData.push_back(LineData.getULEB128(&Offset));
+ }
+ }
+ DebugLines.Opcodes.push_back(NewOp);
+ }
+ Y.DebugLines.push_back(DebugLines);
+ }
+ }
+}
+
std::error_code dwarf2yaml(DWARFContextInMemory &DCtx, DWARFYAML::Data &Y) {
dumpDebugAbbrev(DCtx, Y);
dumpDebugStrings(DCtx, Y);
dumpDebugARanges(DCtx, Y);
dumpDebugPubSections(DCtx, Y);
dumpDebugInfo(DCtx, Y);
+ dumpDebugLines(DCtx, Y);
return obj2yaml_error::success;
}
diff --git a/tools/opt/NewPMDriver.cpp b/tools/opt/NewPMDriver.cpp
index acdf2639b3c7..df467da690e7 100644
--- a/tools/opt/NewPMDriver.cpp
+++ b/tools/opt/NewPMDriver.cpp
@@ -17,7 +17,6 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/CGSCCPassManager.h"
-#include "llvm/Analysis/LoopPassManager.h"
#include "llvm/Bitcode/BitcodeWriterPass.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IRPrintingPasses.h"
@@ -30,6 +29,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar/LoopPassManager.h"
using namespace llvm;
using namespace opt_tool;
diff --git a/tools/yaml2obj/yaml2dwarf.cpp b/tools/yaml2obj/yaml2dwarf.cpp
index 8ba1190c56a7..3ceb7772b969 100644
--- a/tools/yaml2obj/yaml2dwarf.cpp
+++ b/tools/yaml2obj/yaml2dwarf.cpp
@@ -233,3 +233,98 @@ void yaml2debug_info(raw_ostream &OS, const DWARFYAML::Data &DI) {
}
}
}
+
+void yaml2FileEntry(raw_ostream &OS, const DWARFYAML::File &File) {
+ OS.write(File.Name.data(), File.Name.size());
+ OS.write('\0');
+ encodeULEB128(File.DirIdx, OS);
+ encodeULEB128(File.ModTime, OS);
+ encodeULEB128(File.Length, OS);
+}
+
+void yaml2debug_line(raw_ostream &OS, const DWARFYAML::Data &DI) {
+ for (const auto LineTable : DI.DebugLines) {
+ writeInteger((uint32_t)LineTable.TotalLength, OS, DI.IsLittleEndian);
+ uint64_t SizeOfPrologueLength = 4;
+ if (LineTable.TotalLength == UINT32_MAX) {
+ writeInteger((uint64_t)LineTable.TotalLength64, OS, DI.IsLittleEndian);
+ SizeOfPrologueLength = 8;
+ }
+ writeInteger((uint16_t)LineTable.Version, OS, DI.IsLittleEndian);
+ writeVariableSizedInteger(LineTable.PrologueLength, SizeOfPrologueLength,
+ OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)LineTable.MinInstLength, OS, DI.IsLittleEndian);
+ if (LineTable.Version >= 4)
+ writeInteger((uint8_t)LineTable.MaxOpsPerInst, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)LineTable.DefaultIsStmt, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)LineTable.LineBase, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)LineTable.LineRange, OS, DI.IsLittleEndian);
+ writeInteger((uint8_t)LineTable.OpcodeBase, OS, DI.IsLittleEndian);
+
+ for (auto OpcodeLength : LineTable.StandardOpcodeLengths)
+ writeInteger((uint8_t)OpcodeLength, OS, DI.IsLittleEndian);
+
+ for (auto IncludeDir : LineTable.IncludeDirs) {
+ OS.write(IncludeDir.data(), IncludeDir.size());
+ OS.write('\0');
+ }
+ OS.write('\0');
+
+ for (auto File : LineTable.Files)
+ yaml2FileEntry(OS, File);
+ OS.write('\0');
+
+ for (auto Op : LineTable.Opcodes) {
+ writeInteger((uint8_t)Op.Opcode, OS, DI.IsLittleEndian);
+ if (Op.Opcode == 0) {
+ encodeULEB128(Op.ExtLen, OS);
+ writeInteger((uint8_t)Op.SubOpcode, OS, DI.IsLittleEndian);
+ switch (Op.SubOpcode) {
+ case dwarf::DW_LNE_set_address:
+ case dwarf::DW_LNE_set_discriminator:
+ writeVariableSizedInteger(Op.Data, DI.CompileUnits[0].AddrSize, OS,
+ DI.IsLittleEndian);
+ break;
+ case dwarf::DW_LNE_define_file:
+ yaml2FileEntry(OS, Op.FileEntry);
+ break;
+ case dwarf::DW_LNE_end_sequence:
+ break;
+ default:
+ for (auto OpByte : Op.UnknownOpcodeData)
+ writeInteger((uint8_t)OpByte, OS, DI.IsLittleEndian);
+ }
+ } else if (Op.Opcode < LineTable.OpcodeBase) {
+ switch (Op.Opcode) {
+ case dwarf::DW_LNS_copy:
+ case dwarf::DW_LNS_negate_stmt:
+ case dwarf::DW_LNS_set_basic_block:
+ case dwarf::DW_LNS_const_add_pc:
+ case dwarf::DW_LNS_set_prologue_end:
+ case dwarf::DW_LNS_set_epilogue_begin:
+ break;
+
+ case dwarf::DW_LNS_advance_pc:
+ case dwarf::DW_LNS_set_file:
+ case dwarf::DW_LNS_set_column:
+ case dwarf::DW_LNS_set_isa:
+ encodeULEB128(Op.Data, OS);
+ break;
+
+ case dwarf::DW_LNS_advance_line:
+ encodeSLEB128(Op.SData, OS);
+ break;
+
+ case dwarf::DW_LNS_fixed_advance_pc:
+ writeInteger((uint16_t)Op.Data, OS, DI.IsLittleEndian);
+ break;
+
+ default:
+ for (auto OpData : Op.StandardOpcodeData) {
+ encodeULEB128(OpData, OS);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/tools/yaml2obj/yaml2macho.cpp b/tools/yaml2obj/yaml2macho.cpp
index a41ec55d73be..cbc4d7ff50d5 100644
--- a/tools/yaml2obj/yaml2macho.cpp
+++ b/tools/yaml2obj/yaml2macho.cpp
@@ -280,6 +280,8 @@ Error MachOWriter::writeSectionData(raw_ostream &OS) {
yaml2pubsection(OS, Obj.DWARF.PubTypes, Obj.IsLittleEndian);
} else if (0 == strncmp(&Sec.sectname[0], "__debug_info", 16)) {
yaml2debug_info(OS, Obj.DWARF);
+ } else if (0 == strncmp(&Sec.sectname[0], "__debug_line", 16)) {
+ yaml2debug_line(OS, Obj.DWARF);
}
} else {
// Fills section data with 0xDEADBEEF
diff --git a/tools/yaml2obj/yaml2obj.h b/tools/yaml2obj/yaml2obj.h
index 7cad4ca8675f..4a637366e1a1 100644
--- a/tools/yaml2obj/yaml2obj.h
+++ b/tools/yaml2obj/yaml2obj.h
@@ -46,5 +46,6 @@ void yaml2pubsection(llvm::raw_ostream &OS,
const llvm::DWARFYAML::PubSection &Sect,
bool IsLittleEndian);
void yaml2debug_info(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
+void yaml2debug_line(llvm::raw_ostream &OS, const llvm::DWARFYAML::Data &DI);
#endif