-//===-- llvm/MC/SubtargetFeature.h - CPU characteristics --------*- C++ -*-===//
+//===- llvm/MC/SubtargetFeature.h - CPU characteristics ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#ifndef LLVM_MC_SUBTARGETFEATURE_H
#define LLVM_MC_SUBTARGETFEATURE_H
-#include "llvm/ADT/Triple.h"
-#include "llvm/Support/DataTypes.h"
+#include "llvm/ADT/StringRef.h"
#include <bitset>
+#include <initializer_list>
+#include <string>
#include <vector>
namespace llvm {
+
template <typename T> class ArrayRef;
- class raw_ostream;
- class StringRef;
+class raw_ostream;
+class Triple;
// A container class for subtarget features.
// This is convenient because std::bitset does not have a constructor
class FeatureBitset : public std::bitset<MAX_SUBTARGET_FEATURES> {
public:
// Cannot inherit constructors because it's not supported by VC++..
- FeatureBitset() : bitset() {}
+ FeatureBitset() = default;
FeatureBitset(const bitset<MAX_SUBTARGET_FEATURES>& B) : bitset(B) {}
- FeatureBitset(std::initializer_list<unsigned> Init) : bitset() {
+ FeatureBitset(std::initializer_list<unsigned> Init) {
for (auto I : Init)
set(I);
}
class SubtargetFeatures {
std::vector<std::string> Features; // Subtarget features as a vector
+
public:
explicit SubtargetFeatures(StringRef Initial = "");
void getDefaultSubtargetFeatures(const Triple& Triple);
};
-} // End namespace llvm
+} // end namespace llvm
-#endif
+#endif // LLVM_MC_SUBTARGETFEATURE_H
#ifndef LLVM_OBJECT_WASM_H
#define LLVM_OBJECT_WASM_H
+#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Wasm.h"
+#include <cstddef>
+#include <cstdint>
+#include <vector>
namespace llvm {
namespace object {
class WasmObjectFile : public ObjectFile {
public:
WasmObjectFile(MemoryBufferRef Object, Error &Err);
+
const wasm::WasmObjectHeader &getHeader() const;
const wasm::WasmSection *getWasmSection(const SectionRef &Section) const;
+
static bool classof(const Binary *v) { return v->isWasm(); }
protected:
wasm::WasmObjectHeader Header;
std::vector<wasm::WasmSection> Sections;
};
-}
-}
-#endif
+} // end namespace object
+} // end namespace llvm
+
+#endif // LLVM_OBJECT_WASM_H
-//===- InstrumentationMap.h - XRay Instrumentation Map --------------------===//
+//===- InstrumentationMap.h - XRay Instrumentation Map ----------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#ifndef LLVM_XRAY_INSTRUMENTATION_MAP_H
#define LLVM_XRAY_INSTRUMENTATION_MAP_H
-#include <vector>
-#include <string>
-#include <unordered_map>
-
#include "llvm/ADT/Optional.h"
-#include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/YAMLTraits.h"
-#include "llvm/Support/raw_ostream.h"
+#include <cstdint>
+#include <unordered_map>
+#include <vector>
namespace llvm {
+
namespace xray {
// Forward declare to make a friend.
/// Represents an XRay instrumentation sled entry from an object file.
struct SledEntry {
-
/// Each entry here represents the kinds of supported instrumentation map
/// entries.
enum class FunctionKinds { ENTRY, EXIT, TAIL };
const SledContainer &sleds() const { return Sleds; };
};
-} // namespace xray
-} // namespace llvm
+} // end namespace xray
-namespace llvm {
namespace yaml {
template <> struct ScalarEnumerationTraits<xray::SledEntry::FunctionKinds> {
static constexpr bool flow = true;
};
-} // namespace yaml
-} // namespace llvm
+
+} // end namespace yaml
+
+} // end namespace llvm
LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRaySledEntry)
-//===-- SymbolizableObjectFile.cpp ----------------------------------------===//
+//===- SymbolizableObjectFile.cpp -----------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
//===----------------------------------------------------------------------===//
#include "SymbolizableObjectFile.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/DebugInfo/DWARF/DWARFContext.h"
+#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
#include "llvm/Object/COFF.h"
+#include "llvm/Object/ObjectFile.h"
#include "llvm/Object/SymbolSize.h"
+#include "llvm/Support/COFF.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/DataExtractor.h"
-#include "llvm/DebugInfo/DWARF/DWARFContext.h"
-
-namespace llvm {
-namespace symbolize {
+#include "llvm/Support/Error.h"
+#include <algorithm>
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <system_error>
+#include <utility>
+#include <vector>
+using namespace llvm;
using namespace object;
+using namespace symbolize;
static DILineInfoSpecifier
getDILineInfoSpecifier(FunctionNameKind FNKind) {
: Module(Obj), DebugInfoContext(std::move(DICtx)) {}
namespace {
+
struct OffsetNamePair {
uint32_t Offset;
StringRef Name;
+
bool operator<(const OffsetNamePair &R) const {
return Offset < R.Offset;
}
};
-}
+
+} // end anonymous namespace
std::error_code SymbolizableObjectFile::addCoffExportSymbols(
const COFFObjectFile *CoffObj) {
return errorToErrorCode(SymbolNameOrErr.takeError());
StringRef SymbolName = *SymbolNameOrErr;
// Mach-O symbol table names have leading underscore, skip it.
- if (Module->isMachO() && SymbolName.size() > 0 && SymbolName[0] == '_')
+ if (Module->isMachO() && !SymbolName.empty() && SymbolName[0] == '_')
SymbolName = SymbolName.drop_front();
// FIXME: If a function has alias, there are two entries in symbol table
// with same address size. Make sure we choose the correct one.
Res.Size);
return Res;
}
-
-} // namespace symbolize
-} // namespace llvm
-
-//===-- SymbolizableObjectFile.h -------------------------------- C++ -----===//
+//===- SymbolizableObjectFile.h ---------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
#ifndef LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
#define LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
+#include "llvm/ADT/StringRef.h"
+#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
+#include "llvm/Support/ErrorOr.h"
+#include <cstdint>
#include <map>
+#include <memory>
+#include <string>
+#include <system_error>
namespace llvm {
+
class DataExtractor;
-}
-namespace llvm {
namespace symbolize {
class SymbolizableObjectFile : public SymbolizableModule {
// If size is 0, assume that symbol occupies the whole memory range up to
// the following symbol.
uint64_t Size;
+
friend bool operator<(const SymbolDesc &s1, const SymbolDesc &s2) {
return s1.Addr < s2.Addr;
}
std::unique_ptr<DIContext> DICtx);
};
-} // namespace symbolize
-} // namespace llvm
+} // end namespace symbolize
+
+} // end namespace llvm
-#endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
+#endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H
//
//===----------------------------------------------------------------------===//
-#include "llvm/MC/SubtargetFeature.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/MC/SubtargetFeature.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cassert>
-#include <cctype>
-#include <cstdlib>
+#include <cstddef>
+#include <cstring>
+#include <iterator>
+#include <string>
+#include <vector>
+
using namespace llvm;
//===----------------------------------------------------------------------===//
Split(Features, Initial);
}
-
std::string SubtargetFeatures::getString() const {
return join(Features.begin(), Features.end(), ",");
}
void
SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
-
// Find feature in table.
const SubtargetFeatureKV *FeatureEntry =
Find(StripFlag(Feature), FeatureTable);
void SubtargetFeatures::ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
-
assert(hasFlag(Feature));
// Find feature in table.
}
}
-
/// getFeatureBits - Get feature bits a CPU.
///
FeatureBitset
SubtargetFeatures::getFeatureBits(StringRef CPU,
ArrayRef<SubtargetFeatureKV> CPUTable,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
-
if (CPUTable.empty() || FeatureTable.empty())
return FeatureBitset();
-//===- WasmObjectFile.cpp - Wasm object file implementation -----*- C++ -*-===//
+//===- WasmObjectFile.cpp - Wasm object file implementation ---------------===//
//
// The LLVM Compiler Infrastructure
//
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Object/Binary.h"
+#include "llvm/Object/Error.h"
+#include "llvm/Object/ObjectFile.h"
+#include "llvm/Object/SymbolicFile.h"
#include "llvm/Object/Wasm.h"
#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/LEB128.h"
+#include "llvm/Support/Wasm.h"
+#include <algorithm>
+#include <cstdint>
+#include <system_error>
-namespace llvm {
-namespace object {
+using namespace llvm;
+using namespace object;
Expected<std::unique_ptr<WasmObjectFile>>
ObjectFile::createWasmObjectFile(MemoryBufferRef Buffer) {
return std::move(ObjectFile);
}
-namespace {
-
-uint32_t readUint32(const uint8_t *&Ptr) {
+static uint32_t readUint32(const uint8_t *&Ptr) {
uint32_t Result = support::endian::read32le(Ptr);
Ptr += sizeof(Result);
return Result;
}
-uint64_t readULEB128(const uint8_t *&Ptr) {
+static uint64_t readULEB128(const uint8_t *&Ptr) {
unsigned Count;
uint64_t Result = decodeULEB128(Ptr, &Count);
Ptr += Count;
return Result;
}
-StringRef readString(const uint8_t *&Ptr) {
+static StringRef readString(const uint8_t *&Ptr) {
uint32_t StringLen = readULEB128(Ptr);
StringRef Return = StringRef(reinterpret_cast<const char *>(Ptr), StringLen);
Ptr += StringLen;
return Return;
}
-Error readSection(wasm::WasmSection &Section, const uint8_t *&Ptr,
- const uint8_t *Start) {
+static Error readSection(wasm::WasmSection &Section, const uint8_t *&Ptr,
+ const uint8_t *Start) {
// TODO(sbc): Avoid reading past EOF in the case of malformed files.
Section.Offset = Ptr - Start;
Section.Type = readULEB128(Ptr);
Ptr += Size;
return Error::success();
}
-}
WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err)
: ObjectFile(Binary::ID_Wasm, Buffer) {
WasmObjectFile::getWasmSection(const SectionRef &Section) const {
return &Sections[Section.getRawDataRefImpl().d.a];
}
-
-} // end namespace object
-} // end namespace llvm
//
//===----------------------------------------------------------------------===//
-#ifndef XRAY_INSTRUMENTATIONMAP_H
-#define XRAY_INSTRUMENTATIONMAP_H
-
-#include "llvm/XRay/InstrumentationMap.h"
-
+#include "llvm/ADT/None.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Object/Binary.h"
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/DataExtractor.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/XRay/XRayRecord.h"
+#include "llvm/Support/YAMLTraits.h"
+#include "llvm/XRay/InstrumentationMap.h"
+#include <algorithm>
+#include <cstddef>
+#include <cstdint>
#include <system_error>
+#include <vector>
-namespace llvm {
-namespace xray {
+using namespace llvm;
+using namespace xray;
Optional<int32_t> InstrumentationMap::getFunctionId(uint64_t Addr) const {
auto I = FunctionIds.find(Addr);
return None;
}
-namespace {
-Error loadELF64(StringRef Filename,
- object::OwningBinary<object::ObjectFile> &ObjFile,
- InstrumentationMap::SledContainer &Sleds,
- InstrumentationMap::FunctionAddressMap &FunctionAddresses,
- InstrumentationMap::FunctionAddressReverseMap &FunctionIds) {
+static Error
+loadELF64(StringRef Filename, object::OwningBinary<object::ObjectFile> &ObjFile,
+ InstrumentationMap::SledContainer &Sleds,
+ InstrumentationMap::FunctionAddressMap &FunctionAddresses,
+ InstrumentationMap::FunctionAddressReverseMap &FunctionIds) {
InstrumentationMap Map;
// Find the section named "xray_instr_map".
StringRef Contents = "";
const auto &Sections = ObjFile.getBinary()->sections();
- auto I = find_if(Sections, [&](object::SectionRef Section) {
+ auto I = llvm::find_if(Sections, [&](object::SectionRef Section) {
StringRef Name = "";
if (Section.getName(Name))
return false;
return Error::success();
}
-Error loadYAML(int Fd, size_t FileSize, StringRef Filename,
- InstrumentationMap::SledContainer &Sleds,
- InstrumentationMap::FunctionAddressMap &FunctionAddresses,
- InstrumentationMap::FunctionAddressReverseMap &FunctionIds) {
+static Error
+loadYAML(int Fd, size_t FileSize, StringRef Filename,
+ InstrumentationMap::SledContainer &Sleds,
+ InstrumentationMap::FunctionAddressMap &FunctionAddresses,
+ InstrumentationMap::FunctionAddressReverseMap &FunctionIds) {
std::error_code EC;
sys::fs::mapped_file_region MappedFile(
Fd, sys::fs::mapped_file_region::mapmode::readonly, FileSize, 0, EC);
}
return Error::success();
}
-} // namespace
// FIXME: Create error types that encapsulate a bit more information than what
// StringError instances contain.
-Expected<InstrumentationMap> loadInstrumentationMap(StringRef Filename) {
+Expected<InstrumentationMap>
+llvm::xray::loadInstrumentationMap(StringRef Filename) {
// At this point we assume the file is an object file -- and if that doesn't
// work, we treat it as YAML.
// FIXME: Extend to support non-ELF and non-x86_64 binaries.
}
return Map;
}
-}
-}
-
-#endif // XRAY_INSTRUMENTATIONMAP_H
//===----------------------------------------------------------------------===//
#include "DwarfGenerator.h"
-#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
-#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
+#include "llvm/Object/ObjectFile.h"
#include "llvm/ObjectYAML/DWARFYAML.h"
#include "llvm/ObjectYAML/DWARFEmitter.h"
#include "llvm/Support/Dwarf.h"
-#include "llvm/Support/Host.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/TargetSelect.h"
#include "gtest/gtest.h"
#include <climits>
+#include <cstdint>
+#include <cstring>
+#include <string>
using namespace llvm;
using namespace dwarf;
template <typename T>
static bool HandleExpectedError(T &Expected) {
std::string ErrorMsg;
- handleAllErrors(Expected.takeError(), [&](const llvm::ErrorInfoBase &EI) {
+ handleAllErrors(Expected.takeError(), [&](const ErrorInfoBase &EI) {
ErrorMsg = EI.message();
});
if (!ErrorMsg.empty()) {
OptU64 = SubprogramDieNoPC.getHighPC(ActualLowPC);
EXPECT_FALSE((bool)OptU64);
EXPECT_FALSE(SubprogramDieNoPC.getLowAndHighPC(LowPC, HighPC));
-
-
+
// Verify the that our subprogram with only a low PC value succeeds when
// we ask for the Low PC, but fails appropriately when asked for the high PC
// or both low and high PC values.
EXPECT_FALSE((bool)OptU64);
EXPECT_FALSE(SubprogramDieLowPC.getLowAndHighPC(LowPC, HighPC));
-
// Verify the that our subprogram with only a low PC value succeeds when
// we ask for the Low PC, but fails appropriately when asked for the high PC
// or both low and high PC values.
}
TEST(DWARFDebugInfo, TestDWARFDie) {
-
// Make sure a default constructed DWARFDie doesn't have any parent, sibling
// or child;
DWARFDie DefaultDie;
EXPECT_EQ(InvalidU64, toSectionOffset(FormValOpt, InvalidU64));
EXPECT_EQ(InvalidS64, toSigned(FormValOpt, InvalidS64));
-
// Test successful and unsuccessful address decoding.
uint64_t Address = 0x100000000ULL;
FormVal.setForm(DW_FORM_addr);
auto NameOpt = FuncDie.findRecursively(Attrs);
EXPECT_TRUE(NameOpt.hasValue());
EXPECT_EQ(DieMangled, toString(NameOpt, ""));
-
}
} // end anonymous namespace