diff --git a/include/llvm/MC/SubtargetFeature.h b/include/llvm/MC/SubtargetFeature.h index ed4abd77282..c3167617b3f 100644 --- a/include/llvm/MC/SubtargetFeature.h +++ b/include/llvm/MC/SubtargetFeature.h @@ -1,4 +1,4 @@ -//===-- llvm/MC/SubtargetFeature.h - CPU characteristics --------*- C++ -*-===// +//===- llvm/MC/SubtargetFeature.h - CPU characteristics ---------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -18,15 +18,17 @@ #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 +#include +#include #include namespace llvm { + template 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 @@ -35,11 +37,11 @@ const unsigned MAX_SUBTARGET_FEATURES = 128; class FeatureBitset : public std::bitset { public: // Cannot inherit constructors because it's not supported by VC++.. - FeatureBitset() : bitset() {} + FeatureBitset() = default; FeatureBitset(const bitset& B) : bitset(B) {} - FeatureBitset(std::initializer_list Init) : bitset() { + FeatureBitset(std::initializer_list Init) { for (auto I : Init) set(I); } @@ -95,6 +97,7 @@ struct SubtargetInfoKV { class SubtargetFeatures { std::vector Features; // Subtarget features as a vector + public: explicit SubtargetFeatures(StringRef Initial = ""); @@ -127,6 +130,6 @@ public: void getDefaultSubtargetFeatures(const Triple& Triple); }; -} // End namespace llvm +} // end namespace llvm -#endif +#endif // LLVM_MC_SUBTARGETFEATURE_H diff --git a/include/llvm/Object/Wasm.h b/include/llvm/Object/Wasm.h index 999d575943b..9cad2a3007c 100644 --- a/include/llvm/Object/Wasm.h +++ b/include/llvm/Object/Wasm.h @@ -17,8 +17,14 @@ #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 +#include +#include namespace llvm { namespace object { @@ -26,8 +32,10 @@ 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: @@ -93,7 +101,8 @@ private: wasm::WasmObjectHeader Header; std::vector Sections; }; -} -} -#endif +} // end namespace object +} // end namespace llvm + +#endif // LLVM_OBJECT_WASM_H diff --git a/include/llvm/XRay/InstrumentationMap.h b/include/llvm/XRay/InstrumentationMap.h index 1e18d438993..f7286c52ff4 100644 --- a/include/llvm/XRay/InstrumentationMap.h +++ b/include/llvm/XRay/InstrumentationMap.h @@ -1,4 +1,4 @@ -//===- InstrumentationMap.h - XRay Instrumentation Map --------------------===// +//===- InstrumentationMap.h - XRay Instrumentation Map ----------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -15,17 +15,16 @@ #ifndef LLVM_XRAY_INSTRUMENTATION_MAP_H #define LLVM_XRAY_INSTRUMENTATION_MAP_H -#include -#include -#include - #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 +#include +#include namespace llvm { + namespace xray { // Forward declare to make a friend. @@ -37,7 +36,6 @@ Expected loadInstrumentationMap(StringRef Filename); /// 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 }; @@ -98,10 +96,8 @@ public: const SledContainer &sleds() const { return Sleds; }; }; -} // namespace xray -} // namespace llvm +} // end namespace xray -namespace llvm { namespace yaml { template <> struct ScalarEnumerationTraits { @@ -123,8 +119,10 @@ template <> struct MappingTraits { static constexpr bool flow = true; }; -} // namespace yaml -} // namespace llvm + +} // end namespace yaml + +} // end namespace llvm LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRaySledEntry) diff --git a/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp b/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp index f6940080089..f672680cb9e 100644 --- a/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp +++ b/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp @@ -1,4 +1,4 @@ -//===-- SymbolizableObjectFile.cpp ----------------------------------------===// +//===- SymbolizableObjectFile.cpp -----------------------------------------===// // // The LLVM Compiler Infrastructure // @@ -12,15 +12,29 @@ //===----------------------------------------------------------------------===// #include "SymbolizableObjectFile.h" -#include "llvm/Object/COFF.h" -#include "llvm/Object/SymbolSize.h" -#include "llvm/Support/DataExtractor.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/Support/Error.h" +#include +#include +#include +#include +#include +#include +#include -namespace llvm { -namespace symbolize { - +using namespace llvm; using namespace object; +using namespace symbolize; static DILineInfoSpecifier getDILineInfoSpecifier(FunctionNameKind FNKind) { @@ -73,14 +87,17 @@ SymbolizableObjectFile::SymbolizableObjectFile(ObjectFile *Obj, : 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) { @@ -147,7 +164,7 @@ std::error_code SymbolizableObjectFile::addSymbol(const SymbolRef &Symbol, 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. @@ -252,7 +269,3 @@ DIGlobal SymbolizableObjectFile::symbolizeData(uint64_t ModuleOffset) const { Res.Size); return Res; } - -} // namespace symbolize -} // namespace llvm - diff --git a/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h b/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h index 8583b6a36e6..216cca8de4f 100644 --- a/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h +++ b/lib/DebugInfo/Symbolize/SymbolizableObjectFile.h @@ -1,4 +1,4 @@ -//===-- SymbolizableObjectFile.h -------------------------------- C++ -----===// +//===- SymbolizableObjectFile.h ---------------------------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -13,14 +13,20 @@ #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 #include +#include +#include +#include namespace llvm { + class DataExtractor; -} -namespace llvm { namespace symbolize { class SymbolizableObjectFile : public SymbolizableModule { @@ -65,6 +71,7 @@ private: // 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; } @@ -76,7 +83,8 @@ private: std::unique_ptr DICtx); }; -} // namespace symbolize -} // namespace llvm +} // end namespace symbolize -#endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H +} // end namespace llvm + +#endif // LLVM_LIB_DEBUGINFO_SYMBOLIZE_SYMBOLIZABLEOBJECTFILE_H diff --git a/lib/MC/SubtargetFeature.cpp b/lib/MC/SubtargetFeature.cpp index a97cd1db693..593414741a9 100644 --- a/lib/MC/SubtargetFeature.cpp +++ b/lib/MC/SubtargetFeature.cpp @@ -11,16 +11,24 @@ // //===----------------------------------------------------------------------===// -#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 #include -#include -#include +#include +#include +#include +#include +#include + using namespace llvm; //===----------------------------------------------------------------------===// @@ -123,7 +131,6 @@ SubtargetFeatures::SubtargetFeatures(StringRef Initial) { Split(Features, Initial); } - std::string SubtargetFeatures::getString() const { return join(Features.begin(), Features.end(), ","); } @@ -165,7 +172,6 @@ void ClearImpliedBits(FeatureBitset &Bits, void SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature, ArrayRef FeatureTable) { - // Find feature in table. const SubtargetFeatureKV *FeatureEntry = Find(StripFlag(Feature), FeatureTable); @@ -190,7 +196,6 @@ SubtargetFeatures::ToggleFeature(FeatureBitset &Bits, StringRef Feature, void SubtargetFeatures::ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, ArrayRef FeatureTable) { - assert(hasFlag(Feature)); // Find feature in table. @@ -217,14 +222,12 @@ void SubtargetFeatures::ApplyFeatureFlag(FeatureBitset &Bits, StringRef Feature, } } - /// getFeatureBits - Get feature bits a CPU. /// FeatureBitset SubtargetFeatures::getFeatureBits(StringRef CPU, ArrayRef CPUTable, ArrayRef FeatureTable) { - if (CPUTable.empty() || FeatureTable.empty()) return FeatureBitset(); diff --git a/lib/Object/WasmObjectFile.cpp b/lib/Object/WasmObjectFile.cpp index e61ae156a74..254347a80c5 100644 --- a/lib/Object/WasmObjectFile.cpp +++ b/lib/Object/WasmObjectFile.cpp @@ -1,4 +1,4 @@ -//===- WasmObjectFile.cpp - Wasm object file implementation -----*- C++ -*-===// +//===- WasmObjectFile.cpp - Wasm object file implementation ---------------===// // // The LLVM Compiler Infrastructure // @@ -7,12 +7,26 @@ // //===----------------------------------------------------------------------===// +#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 +#include +#include -namespace llvm { -namespace object { +using namespace llvm; +using namespace object; Expected> ObjectFile::createWasmObjectFile(MemoryBufferRef Buffer) { @@ -24,30 +38,28 @@ 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(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); @@ -59,7 +71,6 @@ Error readSection(wasm::WasmSection &Section, const uint8_t *&Ptr, Ptr += Size; return Error::success(); } -} WasmObjectFile::WasmObjectFile(MemoryBufferRef Buffer, Error &Err) : ObjectFile(Binary::ID_Wasm, Buffer) { @@ -309,6 +320,3 @@ const wasm::WasmSection * WasmObjectFile::getWasmSection(const SectionRef &Section) const { return &Sections[Section.getRawDataRefImpl().d.a]; } - -} // end namespace object -} // end namespace llvm diff --git a/lib/XRay/InstrumentationMap.cpp b/lib/XRay/InstrumentationMap.cpp index f14ad381578..b3b482f0286 100644 --- a/lib/XRay/InstrumentationMap.cpp +++ b/lib/XRay/InstrumentationMap.cpp @@ -11,19 +11,26 @@ // //===----------------------------------------------------------------------===// -#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 +#include +#include #include +#include -namespace llvm { -namespace xray { +using namespace llvm; +using namespace xray; Optional InstrumentationMap::getFunctionId(uint64_t Addr) const { auto I = FunctionIds.find(Addr); @@ -39,12 +46,11 @@ Optional InstrumentationMap::getFunctionAddr(int32_t FuncId) const { return None; } -namespace { -Error loadELF64(StringRef Filename, - object::OwningBinary &ObjFile, - InstrumentationMap::SledContainer &Sleds, - InstrumentationMap::FunctionAddressMap &FunctionAddresses, - InstrumentationMap::FunctionAddressReverseMap &FunctionIds) { +static Error +loadELF64(StringRef Filename, object::OwningBinary &ObjFile, + InstrumentationMap::SledContainer &Sleds, + InstrumentationMap::FunctionAddressMap &FunctionAddresses, + InstrumentationMap::FunctionAddressReverseMap &FunctionIds) { InstrumentationMap Map; // Find the section named "xray_instr_map". @@ -56,7 +62,7 @@ Error loadELF64(StringRef Filename, 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; @@ -122,10 +128,11 @@ Error loadELF64(StringRef Filename, 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); @@ -150,11 +157,11 @@ Error loadYAML(int Fd, size_t FileSize, StringRef Filename, } return Error::success(); } -} // namespace // FIXME: Create error types that encapsulate a bit more information than what // StringError instances contain. -Expected loadInstrumentationMap(StringRef Filename) { +Expected +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. @@ -188,7 +195,3 @@ Expected loadInstrumentationMap(StringRef Filename) { } return Map; } -} -} - -#endif // XRAY_INSTRUMENTATIONMAP_H diff --git a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index 1adc0aafdc2..dafa77bff16 100644 --- a/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -8,18 +8,27 @@ //===----------------------------------------------------------------------===// #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 +#include +#include +#include using namespace llvm; using namespace dwarf; @@ -54,7 +63,7 @@ Triple getHostTripleForAddrSize(uint8_t AddrSize) { template 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()) { @@ -853,8 +862,7 @@ template void TestAddresses() { 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. @@ -872,7 +880,6 @@ template void TestAddresses() { 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. @@ -1075,7 +1082,6 @@ TEST(DWARFDebugInfo, TestRelations) { } TEST(DWARFDebugInfo, TestDWARFDie) { - // Make sure a default constructed DWARFDie doesn't have any parent, sibling // or child; DWARFDie DefaultDie; @@ -1365,7 +1371,6 @@ TEST(DWARFDebugInfo, TestDwarfToFunctions) { 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); @@ -1536,7 +1541,6 @@ TEST(DWARFDebugInfo, TestFindAttrs) { auto NameOpt = FuncDie.findRecursively(Attrs); EXPECT_TRUE(NameOpt.hasValue()); EXPECT_EQ(DieMangled, toString(NameOpt, "")); - } } // end anonymous namespace