Skip to content

Commit

Permalink
Use llvm::endianness::{big,little,native} (NFC)
Browse files Browse the repository at this point in the history
Note that llvm::support::endianness has been renamed to
llvm::endianness while becoming an enum class as opposed to an
enum. This patch replaces support::{big,little,native} with
llvm::endianness::{big,little,native}.
  • Loading branch information
kazutakahirata committed Oct 13, 2023
1 parent 2045cca commit 4a0ccfa
Show file tree
Hide file tree
Showing 142 changed files with 463 additions and 391 deletions.
91 changes: 49 additions & 42 deletions bolt/lib/Core/DebugData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,14 @@ writeAddressRanges(raw_svector_ostream &Stream,
const DebugAddressRangesVector &AddressRanges,
const bool WriteRelativeRanges = false) {
for (const DebugAddressRange &Range : AddressRanges) {
support::endian::write(Stream, Range.LowPC, support::little);
support::endian::write(Stream, Range.LowPC, llvm::endianness::little);
support::endian::write(
Stream, WriteRelativeRanges ? Range.HighPC - Range.LowPC : Range.HighPC,
support::little);
llvm::endianness::little);
}
// Finish with 0 entries.
support::endian::write(Stream, 0ULL, support::little);
support::endian::write(Stream, 0ULL, support::little);
support::endian::write(Stream, 0ULL, llvm::endianness::little);
support::endian::write(Stream, 0ULL, llvm::endianness::little);
return AddressRanges.size() * 16 + 16;
}

Expand Down Expand Up @@ -209,13 +209,15 @@ getDWARF5Header(const LocListsRangelistsHeader &Header) {
getDWARF5RngListLocListHeaderSize() - sizeof(UnitLengthType);

support::endian::write(*HeaderStream, Header.UnitLength + HeaderSize,
support::little);
support::endian::write(*HeaderStream, Header.Version, support::little);
support::endian::write(*HeaderStream, Header.AddressSize, support::little);
llvm::endianness::little);
support::endian::write(*HeaderStream, Header.Version,
llvm::endianness::little);
support::endian::write(*HeaderStream, Header.AddressSize,
llvm::endianness::little);
support::endian::write(*HeaderStream, Header.SegmentSelector,
support::little);
llvm::endianness::little);
support::endian::write(*HeaderStream, Header.OffsetEntryCount,
support::little);
llvm::endianness::little);
return HeaderBuffer;
}

Expand Down Expand Up @@ -254,17 +256,18 @@ static bool emitWithBase(raw_ostream &OS, const DebugVector &Entries,
}

support::endian::write(OS, static_cast<uint8_t>(BaseAddressx),
support::little);
llvm::endianness::little);
uint32_t BaseIndex = AddrWriter.getIndexFromAddress(Base, CU);
encodeULEB128(BaseIndex, OS);
for (auto &OffsetEntry : Offsets) {
support::endian::write(OS, static_cast<uint8_t>(OffsetPair),
support::little);
llvm::endianness::little);
encodeULEB128(OffsetEntry.StartOffset, OS);
encodeULEB128(OffsetEntry.EndOffset, OS);
Func(OffsetEntry.Index);
}
support::endian::write(OS, static_cast<uint8_t>(EndOfList), support::little);
support::endian::write(OS, static_cast<uint8_t>(EndOfList),
llvm::endianness::little);
return true;
}

Expand All @@ -291,7 +294,7 @@ DebugRangeListsSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
const DebugAddressRange &Range = Ranges[I];
support::endian::write(*CUBodyStream,
static_cast<uint8_t>(dwarf::DW_RLE_startx_length),
support::little);
llvm::endianness::little);
uint32_t Index = AddrWriter->getIndexFromAddress(Range.LowPC, *CU);
encodeULEB128(Index, *CUBodyStream);
encodeULEB128(Range.HighPC - Range.LowPC, *CUBodyStream);
Expand All @@ -301,7 +304,7 @@ DebugRangeListsSectionWriter::addRanges(DebugAddressRangesVector &Ranges) {
if (WrittenStartxLength)
support::endian::write(*CUBodyStream,
static_cast<uint8_t>(dwarf::DW_RLE_end_of_list),
support::little);
llvm::endianness::little);
CurrentOffset = CUBodyBuffer->size();
return RangeEntries.size() - 1;
}
Expand All @@ -315,7 +318,7 @@ void DebugRangeListsSectionWriter::finalizeSection() {
const uint32_t SizeOfArraySection = RangeEntries.size() * SizeOfArrayEntry;
for (uint32_t Offset : RangeEntries)
support::endian::write(*CUArrayStream, Offset + SizeOfArraySection,
support::little);
llvm::endianness::little);

std::unique_ptr<DebugBufferVector> Header = getDWARF5Header(
{static_cast<uint32_t>(SizeOfArraySection + CUBodyBuffer.get()->size()),
Expand Down Expand Up @@ -359,17 +362,17 @@ void DebugARangesSectionWriter::writeARangesSection(
uint32_t Size = 8 + 4 + 2 * sizeof(uint64_t) * (AddressRanges.size() + 1);

// Header field #1: set size.
support::endian::write(RangesStream, Size, support::little);
support::endian::write(RangesStream, Size, llvm::endianness::little);

// Header field #2: version number, 2 as per the specification.
support::endian::write(RangesStream, static_cast<uint16_t>(2),
support::little);
llvm::endianness::little);

assert(CUMap.count(Offset) && "Original CU offset is not found in CU Map");
// Header field #3: debug info offset of the correspondent compile unit.
support::endian::write(
RangesStream, static_cast<uint32_t>(CUMap.find(Offset)->second.Offset),
support::little);
llvm::endianness::little);

// Header field #4: address size.
// 8 since we only write ELF64 binaries for now.
Expand All @@ -380,7 +383,7 @@ void DebugARangesSectionWriter::writeARangesSection(

// Padding before address table - 4 bytes in the 64-bit-pointer case.
support::endian::write(RangesStream, static_cast<uint32_t>(0),
support::little);
llvm::endianness::little);

writeAddressRanges(RangesStream, AddressRanges, true);
}
Expand Down Expand Up @@ -473,10 +476,10 @@ void DebugAddrWriter::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
break;
case 4:
support::endian::write(*AddressStream, static_cast<uint32_t>(Address),
support::little);
llvm::endianness::little);
break;
case 8:
support::endian::write(*AddressStream, Address, support::little);
support::endian::write(*AddressStream, Address, llvm::endianness::little);
break;
}
};
Expand All @@ -492,11 +495,12 @@ void DebugAddrWriter::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
void DebugAddrWriterDwarf5::update(DIEBuilder &DIEBlder, DWARFUnit &CU) {
// Need to layout all sections within .debug_addr
// Within each section sort Address by index.
const endianness Endian =
BC->DwCtx->isLittleEndian() ? support::little : support::big;
const endianness Endian = BC->DwCtx->isLittleEndian()
? llvm::endianness::little
: llvm::endianness::big;
const DWARFSection &AddrSec = BC->DwCtx->getDWARFObj().getAddrSection();
DWARFDataExtractor AddrData(BC->DwCtx->getDWARFObj(), AddrSec,
Endian == support::little, 0);
Endian == llvm::endianness::little, 0);
DWARFDebugAddrTable AddrTable;
DIDumpOptions DumpOpts;
constexpr uint32_t HeaderSize = 8;
Expand Down Expand Up @@ -594,11 +598,11 @@ void DebugLocWriter::addList(DIEBuilder &DIEBldr, DIE &Die, DIEValue &AttrInfo,

for (const DebugLocationEntry &Entry : LocList) {
support::endian::write(*LocStream, static_cast<uint64_t>(Entry.LowPC),
support::little);
llvm::endianness::little);
support::endian::write(*LocStream, static_cast<uint64_t>(Entry.HighPC),
support::little);
llvm::endianness::little);
support::endian::write(*LocStream, static_cast<uint16_t>(Entry.Expr.size()),
support::little);
llvm::endianness::little);
*LocStream << StringRef(reinterpret_cast<const char *>(Entry.Expr.data()),
Entry.Expr.size());
LocSectionOffset += 2 * 8 + 2 + Entry.Expr.size();
Expand All @@ -618,15 +622,17 @@ std::unique_ptr<DebugBufferVector> DebugLocWriter::getBuffer() {
void DebugLocWriter::finalize(DIEBuilder &DIEBldr, DIE &Die) {}

static void writeEmptyListDwarf5(raw_svector_ostream &Stream) {
support::endian::write(Stream, static_cast<uint32_t>(4), support::little);
support::endian::write(Stream, static_cast<uint32_t>(4),
llvm::endianness::little);
support::endian::write(Stream, static_cast<uint8_t>(dwarf::DW_LLE_start_end),
support::little);
llvm::endianness::little);

const char Zeroes[16] = {0};
Stream << StringRef(Zeroes, 16);
encodeULEB128(0, Stream);
support::endian::write(
Stream, static_cast<uint8_t>(dwarf::DW_LLE_end_of_list), support::little);
support::endian::write(Stream,
static_cast<uint8_t>(dwarf::DW_LLE_end_of_list),
llvm::endianness::little);
}

static void writeLegacyLocList(DIEValue &AttrInfo,
Expand All @@ -645,21 +651,21 @@ static void writeLegacyLocList(DIEValue &AttrInfo,
for (const DebugLocationEntry &Entry : LocList) {
support::endian::write(LocStream,
static_cast<uint8_t>(dwarf::DW_LLE_startx_length),
support::little);
llvm::endianness::little);
const uint32_t Index = AddrWriter.getIndexFromAddress(Entry.LowPC, CU);
encodeULEB128(Index, LocStream);

support::endian::write(LocStream,
static_cast<uint32_t>(Entry.HighPC - Entry.LowPC),
support::little);
llvm::endianness::little);
support::endian::write(LocStream, static_cast<uint16_t>(Entry.Expr.size()),
support::little);
llvm::endianness::little);
LocStream << StringRef(reinterpret_cast<const char *>(Entry.Expr.data()),
Entry.Expr.size());
}
support::endian::write(LocStream,
static_cast<uint8_t>(dwarf::DW_LLE_end_of_list),
support::little);
llvm::endianness::little);
replaceLocValbyForm(DIEBldr, Die, AttrInfo, AttrInfo.getForm(), EntryOffset);
}

Expand Down Expand Up @@ -701,7 +707,7 @@ static void writeDWARF5LocList(uint32_t &NumberOfEntries, DIEValue &AttrInfo,
const DebugLocationEntry &Entry = LocList[I];
support::endian::write(LocBodyStream,
static_cast<uint8_t>(dwarf::DW_LLE_startx_length),
support::little);
llvm::endianness::little);
const uint32_t Index = AddrWriter.getIndexFromAddress(Entry.LowPC, CU);
encodeULEB128(Index, LocBodyStream);
encodeULEB128(Entry.HighPC - Entry.LowPC, LocBodyStream);
Expand All @@ -713,7 +719,7 @@ static void writeDWARF5LocList(uint32_t &NumberOfEntries, DIEValue &AttrInfo,
if (WrittenStartxLength)
support::endian::write(LocBodyStream,
static_cast<uint8_t>(dwarf::DW_LLE_end_of_list),
support::little);
llvm::endianness::little);
}

void DebugLoclistWriter::addList(DIEBuilder &DIEBldr, DIE &Die,
Expand Down Expand Up @@ -753,7 +759,7 @@ void DebugLoclistWriter::finalizeDWARF5(DIEBuilder &DIEBldr, DIE &Die) {
support::endian::write(
*LocArrayStream,
static_cast<uint32_t>(SizeOfArraySection + RelativeOffset),
support::little);
llvm::endianness::little);

std::unique_ptr<DebugBufferVector> Header = getDWARF5Header(
{static_cast<uint32_t>(SizeOfArraySection + LocBodyBuffer.get()->size()),
Expand Down Expand Up @@ -884,11 +890,11 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
if (RetVal == ProcessedBaseOffsets.end() || StrOffsetSectionWasModified) {
// Writing out the header for each section.
support::endian::write(*StrOffsetsStream, CurrentSectionSize + 4,
support::little);
llvm::endianness::little);
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(5),
support::little);
llvm::endianness::little);
support::endian::write(*StrOffsetsStream, static_cast<uint16_t>(0),
support::little);
llvm::endianness::little);

uint64_t BaseOffset = StrOffsetsBuffer->size();
ProcessedBaseOffsets[*Val] = BaseOffset;
Expand All @@ -897,7 +903,8 @@ void DebugStrOffsetsWriter::finalizeSection(DWARFUnit &Unit,
StrListBaseAttrInfo.getForm(),
DIEInteger(BaseOffset));
for (const auto &Entry : IndexToAddressMap)
support::endian::write(*StrOffsetsStream, Entry.second, support::little);
support::endian::write(*StrOffsetsStream, Entry.second,
llvm::endianness::little);
} else {
DIEBldr.replaceValue(&Die, dwarf::DW_AT_str_offsets_base,
StrListBaseAttrInfo.getForm(),
Expand Down
3 changes: 2 additions & 1 deletion bolt/lib/Rewrite/PseudoProbeRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ void PseudoProbeRewriter::encodePseudoProbes() {
auto EmitInt = [&](uint64_t Value, uint32_t Size) {
const bool IsLittleEndian = BC.AsmInfo->isLittleEndian();
uint64_t Swapped = support::endian::byte_swap(
Value, IsLittleEndian ? support::little : support::big);
Value,
IsLittleEndian ? llvm::endianness::little : llvm::endianness::big);
unsigned Index = IsLittleEndian ? 0 : 8 - Size;
auto Entry = StringRef(reinterpret_cast<char *>(&Swapped) + Index, Size);
Contents.append(Entry.begin(), Entry.end());
Expand Down
4 changes: 2 additions & 2 deletions lld/COFF/DebugTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ Error TpiSource::mergeDebugT(TypeMerger *m) {
"use remapTpiWithGHashes when ghash is enabled");

CVTypeArray types;
BinaryStreamReader reader(file->debugTypes, support::little);
BinaryStreamReader reader(file->debugTypes, llvm::endianness::little);
cantFail(reader.readArray(types, reader.getLength()));

// When dealing with PCH.OBJ, some indices were already merged.
Expand Down Expand Up @@ -588,7 +588,7 @@ void TpiSource::loadGHashes() {
ownedGHashes = false;
} else {
CVTypeArray types;
BinaryStreamReader reader(file->debugTypes, support::little);
BinaryStreamReader reader(file->debugTypes, llvm::endianness::little);
cantFail(reader.readArray(types, reader.getLength()));
assignGHashesFromVector(GloballyHashedType::hashTypes(types));
}
Expand Down
2 changes: 1 addition & 1 deletion lld/COFF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ static void readCallGraphsFromObjectFiles(COFFLinkerContext &ctx) {
ArrayRef<uint8_t> contents;
cantFail(
obj->getCOFFObj()->getSectionContents(obj->callgraphSec, contents));
BinaryStreamReader reader(contents, support::little);
BinaryStreamReader reader(contents, llvm::endianness::little);
while (!reader.empty()) {
uint32_t fromIndex, toIndex;
uint64_t count;
Expand Down
4 changes: 2 additions & 2 deletions lld/COFF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ void ObjFile::initializeFlags() {

DebugSubsectionArray subsections;

BinaryStreamReader reader(data, support::little);
BinaryStreamReader reader(data, llvm::endianness::little);
ExitOnError exitOnErr;
exitOnErr(reader.readArray(subsections, data.size()));

Expand Down Expand Up @@ -775,7 +775,7 @@ void ObjFile::initializeDependencies() {
// Get the first type record. It will indicate if this object uses a type
// server (/Zi) or a PCH file (/Yu).
CVTypeArray types;
BinaryStreamReader reader(data, support::little);
BinaryStreamReader reader(data, llvm::endianness::little);
cantFail(reader.readArray(types, reader.getLength()));
CVTypeArray::Iterator firstType = types.begin();
if (firstType == types.end())
Expand Down
13 changes: 7 additions & 6 deletions lld/COFF/PDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ Error PDBLinker::writeAllModuleSymbolRecords(ObjFile *file,
auto contents =
SectionChunk::consumeDebugMagic(sectionContents, ".debug$S");
DebugSubsectionArray subsections;
BinaryStreamReader reader(contents, support::little);
BinaryStreamReader reader(contents, llvm::endianness::little);
exitOnErr(reader.readArray(subsections, contents.size()));

uint32_t nextRelocIndex = 0;
Expand Down Expand Up @@ -758,7 +758,7 @@ void DebugSHandler::handleDebugS(SectionChunk *debugChunk) {
ArrayRef<uint8_t> contents = debugChunk->getContents();
contents = SectionChunk::consumeDebugMagic(contents, ".debug$S");
DebugSubsectionArray subsections;
BinaryStreamReader reader(contents, support::little);
BinaryStreamReader reader(contents, llvm::endianness::little);
ExitOnError exitOnErr;
exitOnErr(reader.readArray(subsections, contents.size()));
debugChunk->sortRelocations();
Expand Down Expand Up @@ -868,7 +868,7 @@ Error UnrelocatedDebugSubsection::commit(BinaryStreamWriter &writer) const {
debugChunk->file->debugTypesObj) {
TpiSource *source = debugChunk->file->debugTypesObj;
DebugInlineeLinesSubsectionRef inlineeLines;
BinaryStreamReader storageReader(relocatedBytes, support::little);
BinaryStreamReader storageReader(relocatedBytes, llvm::endianness::little);
ExitOnError exitOnErr;
exitOnErr(inlineeLines.initialize(storageReader));
for (const InlineeSourceLine &line : inlineeLines) {
Expand Down Expand Up @@ -962,7 +962,7 @@ void DebugSHandler::finish() {
// Copy each frame data record, add in rvaStart, translate string table
// indices, and add the record to the PDB.
DebugFrameDataSubsectionRef fds;
BinaryStreamReader reader(subsecData, support::little);
BinaryStreamReader reader(subsecData, llvm::endianness::little);
exitOnErr(fds.initialize(reader));
for (codeview::FrameData fd : fds) {
fd.RvaStart += rvaStart;
Expand Down Expand Up @@ -1050,7 +1050,8 @@ void PDBLinker::addDebugSymbols(TpiSource *source) {
ArrayRef<uint8_t> relocatedDebugContents =
relocateDebugChunk(*debugChunk);
FixedStreamArray<object::FpoData> fpoRecords;
BinaryStreamReader reader(relocatedDebugContents, support::little);
BinaryStreamReader reader(relocatedDebugContents,
llvm::endianness::little);
uint32_t count = relocatedDebugContents.size() / sizeof(object::FpoData);
exitOnErr(reader.readArray(fpoRecords, count));

Expand Down Expand Up @@ -1772,7 +1773,7 @@ static bool findLineTable(const SectionChunk *c, uint32_t addr,
ArrayRef<uint8_t> contents =
SectionChunk::consumeDebugMagic(dbgC->getContents(), ".debug$S");
DebugSubsectionArray subsections;
BinaryStreamReader reader(contents, support::little);
BinaryStreamReader reader(contents, llvm::endianness::little);
exitOnErr(reader.readArray(subsections, contents.size()));

for (const DebugSubsectionRecord &ss : subsections) {
Expand Down
6 changes: 3 additions & 3 deletions lld/ELF/Arch/Mips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ template <endianness E> static uint32_t readShuffle(const uint8_t *loc) {
// words in a big-endian order. That is why we have to swap these
// words to get a correct value.
uint32_t v = read32(loc);
if (E == support::little)
if (E == llvm::endianness::little)
return (v << 16) | (v >> 16);
return v;
}
Expand All @@ -237,12 +237,12 @@ static void writeShuffleValue(uint8_t *loc, uint64_t v, uint8_t bitsSize,
uint8_t shift) {
// See comments in readShuffle for purpose of this code.
uint16_t *words = (uint16_t *)loc;
if (E == support::little)
if (E == llvm::endianness::little)
std::swap(words[0], words[1]);

writeValue(loc, v, bitsSize, shift);

if (E == support::little)
if (E == llvm::endianness::little)
std::swap(words[0], words[1]);
}

Expand Down
Loading

0 comments on commit 4a0ccfa

Please sign in to comment.