1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

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

Same changes in files affected by reduced SubtargetFeature.h dependencies.

llvm-svn: 294548
This commit is contained in:
Eugene Zelenko 2017-02-09 01:09:54 +00:00
parent d9e1b39f5d
commit 347afa6803
9 changed files with 150 additions and 101 deletions

View File

@ -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 <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
@ -35,11 +37,11 @@ const unsigned MAX_SUBTARGET_FEATURES = 128;
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);
}
@ -95,6 +97,7 @@ struct SubtargetInfoKV {
class SubtargetFeatures {
std::vector<std::string> 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

View File

@ -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 <cstddef>
#include <cstdint>
#include <vector>
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<wasm::WasmSection> Sections;
};
}
}
#endif
} // end namespace object
} // end namespace llvm
#endif // LLVM_OBJECT_WASM_H

View File

@ -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 <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.
@ -37,7 +36,6 @@ Expected<InstrumentationMap> 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<xray::SledEntry::FunctionKinds> {
@ -123,8 +119,10 @@ template <> struct MappingTraits<xray::YAMLXRaySledEntry> {
static constexpr bool flow = true;
};
} // namespace yaml
} // namespace llvm
} // end namespace yaml
} // end namespace llvm
LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRaySledEntry)

View File

@ -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 <algorithm>
#include <cstdint>
#include <memory>
#include <string>
#include <system_error>
#include <utility>
#include <vector>
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

View File

@ -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 <cstdint>
#include <map>
#include <memory>
#include <string>
#include <system_error>
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<DIContext> 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

View File

@ -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 <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <string>
#include <vector>
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<SubtargetFeatureKV> 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<SubtargetFeatureKV> 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<SubtargetFeatureKV> CPUTable,
ArrayRef<SubtargetFeatureKV> FeatureTable) {
if (CPUTable.empty() || FeatureTable.empty())
return FeatureBitset();

View File

@ -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 <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) {
@ -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<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);
@ -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

View File

@ -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 <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);
@ -39,12 +46,11 @@ Optional<uint64_t> InstrumentationMap::getFunctionAddr(int32_t FuncId) const {
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".
@ -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<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.
@ -188,7 +195,3 @@ Expected<InstrumentationMap> loadInstrumentationMap(StringRef Filename) {
}
return Map;
}
}
}
#endif // XRAY_INSTRUMENTATIONMAP_H

View File

@ -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 <climits>
#include <cstdint>
#include <cstring>
#include <string>
using namespace llvm;
using namespace dwarf;
@ -54,7 +63,7 @@ Triple getHostTripleForAddrSize(uint8_t AddrSize) {
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()) {
@ -853,8 +862,7 @@ template <uint16_t Version, class AddrType> 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 <uint16_t Version, class AddrType> 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