diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index df6c76cde95f..63cdd0a047bc 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -755,7 +755,8 @@ void PGOHash::combine(HashType Type) { // Pass through MD5 if enough work has built up. if (Count && Count % NumTypesPerWord == 0) { using namespace llvm::support; - uint64_t Swapped = endian::byte_swap(Working); + uint64_t Swapped = + endian::byte_swap(Working); MD5.update(llvm::ArrayRef((uint8_t *)&Swapped, sizeof(Swapped))); Working = 0; } @@ -781,7 +782,8 @@ uint64_t PGOHash::finalize() { MD5.update({(uint8_t)Working}); } else { using namespace llvm::support; - uint64_t Swapped = endian::byte_swap(Working); + uint64_t Swapped = + endian::byte_swap(Working); MD5.update(llvm::ArrayRef((uint8_t *)&Swapped, sizeof(Swapped))); } } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 9ea8c8eacaa9..cce403d7c6c4 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -912,9 +912,10 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { using namespace llvm::support; SelectorTable &SelTable = Reader.getContext().Selectors; - unsigned N = endian::readNext(d); + unsigned N = + endian::readNext(d); IdentifierInfo *FirstII = Reader.getLocalIdentifier( - F, endian::readNext(d)); + F, endian::readNext(d)); if (N == 0) return SelTable.getNullarySelector(FirstII); else if (N == 1) @@ -924,7 +925,7 @@ ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) { Args.push_back(FirstII); for (unsigned I = 1; I != N; ++I) Args.push_back(Reader.getLocalIdentifier( - F, endian::readNext(d))); + F, endian::readNext(d))); return SelTable.getSelector(N, Args.data()); } @@ -937,9 +938,11 @@ ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, data_type Result; Result.ID = Reader.getGlobalSelectorID( - F, endian::readNext(d)); - unsigned FullInstanceBits = endian::readNext(d); - unsigned FullFactoryBits = endian::readNext(d); + F, endian::readNext(d)); + unsigned FullInstanceBits = + endian::readNext(d); + unsigned FullFactoryBits = + endian::readNext(d); Result.InstanceBits = FullInstanceBits & 0x3; Result.InstanceHasMoreThanOneDecl = (FullInstanceBits >> 2) & 0x1; Result.FactoryBits = FullFactoryBits & 0x3; @@ -950,14 +953,16 @@ ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, // Load instance methods for (unsigned I = 0; I != NumInstanceMethods; ++I) { if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs( - F, endian::readNext(d))) + F, + endian::readNext(d))) Result.Instance.push_back(Method); } // Load factory methods for (unsigned I = 0; I != NumFactoryMethods; ++I) { if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs( - F, endian::readNext(d))) + F, + endian::readNext(d))) Result.Factory.push_back(Method); } @@ -998,7 +1003,8 @@ static bool readBit(unsigned &Bits) { IdentID ASTIdentifierLookupTrait::ReadIdentifierID(const unsigned char *d) { using namespace llvm::support; - unsigned RawID = endian::readNext(d); + unsigned RawID = + endian::readNext(d); return Reader.getGlobalIdentifierID(F, RawID >> 1); } @@ -1016,7 +1022,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, unsigned DataLen) { using namespace llvm::support; - unsigned RawID = endian::readNext(d); + unsigned RawID = + endian::readNext(d); bool IsInteresting = RawID & 0x01; // Wipe out the "is interesting" bit. @@ -1039,8 +1046,10 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, return II; } - unsigned ObjCOrBuiltinID = endian::readNext(d); - unsigned Bits = endian::readNext(d); + unsigned ObjCOrBuiltinID = + endian::readNext(d); + unsigned Bits = + endian::readNext(d); bool CPlusPlusOperatorKeyword = readBit(Bits); bool HasRevertedTokenIDToIdentifier = readBit(Bits); bool Poisoned = readBit(Bits); @@ -1069,7 +1078,7 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, // definition. if (HadMacroDefinition) { uint32_t MacroDirectivesOffset = - endian::readNext(d); + endian::readNext(d); DataLen -= 4; Reader.addPendingMacro(II, &F, MacroDirectivesOffset); @@ -1083,7 +1092,8 @@ IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k, SmallVector DeclIDs; for (; DataLen > 0; DataLen -= 4) DeclIDs.push_back(Reader.getGlobalDeclID( - F, endian::readNext(d))); + F, + endian::readNext(d))); Reader.SetGloballyVisibleDecls(II, DeclIDs); } @@ -1152,7 +1162,8 @@ ModuleFile * ASTDeclContextNameLookupTrait::ReadFileRef(const unsigned char *&d) { using namespace llvm::support; - uint32_t ModuleFileID = endian::readNext(d); + uint32_t ModuleFileID = + endian::readNext(d); return Reader.getLocalModuleFile(F, ModuleFileID); } @@ -1172,15 +1183,18 @@ ASTDeclContextNameLookupTrait::ReadKey(const unsigned char *d, unsigned) { case DeclarationName::CXXLiteralOperatorName: case DeclarationName::CXXDeductionGuideName: Data = (uint64_t)Reader.getLocalIdentifier( - F, endian::readNext(d)); + F, endian::readNext(d)); break; case DeclarationName::ObjCZeroArgSelector: case DeclarationName::ObjCOneArgSelector: case DeclarationName::ObjCMultiArgSelector: Data = - (uint64_t)Reader.getLocalSelector( - F, endian::readNext( - d)).getAsOpaquePtr(); + (uint64_t)Reader + .getLocalSelector( + F, + endian::readNext( + d)) + .getAsOpaquePtr(); break; case DeclarationName::CXXOperatorName: Data = *d++; // OverloadedOperatorKind @@ -1203,7 +1217,8 @@ void ASTDeclContextNameLookupTrait::ReadDataInto(internal_key_type, using namespace llvm::support; for (unsigned NumDecls = DataLen / 4; NumDecls; --NumDecls) { - uint32_t LocalID = endian::readNext(d); + uint32_t LocalID = + endian::readNext(d); Val.insert(Reader.getGlobalDeclID(F, LocalID)); } } @@ -2010,8 +2025,10 @@ HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) { using namespace llvm::support; internal_key_type ikey; - ikey.Size = off_t(endian::readNext(d)); - ikey.ModTime = time_t(endian::readNext(d)); + ikey.Size = + off_t(endian::readNext(d)); + ikey.ModTime = time_t( + endian::readNext(d)); ikey.Filename = (const char *)d; ikey.Imported = true; return ikey; @@ -2039,9 +2056,9 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, HFI.DirInfo = (Flags >> 1) & 0x07; HFI.IndexHeaderMapHeader = Flags & 0x01; HFI.ControllingMacroID = Reader.getGlobalIdentifierID( - M, endian::readNext(d)); + M, endian::readNext(d)); if (unsigned FrameworkOffset = - endian::readNext(d)) { + endian::readNext(d)) { // The framework offset is 1 greater than the actual offset, // since 0 is used as an indicator for "no framework name". StringRef FrameworkName(FrameworkStrings + FrameworkOffset - 1); @@ -2051,7 +2068,8 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, assert((End - d) % 4 == 0 && "Wrong data length in HeaderFileInfo deserialization"); while (d != End) { - uint32_t LocalSMID = endian::readNext(d); + uint32_t LocalSMID = + endian::readNext(d); auto HeaderRole = static_cast(LocalSMID & 7); LocalSMID >>= 3; @@ -4030,8 +4048,9 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { // how it goes... using namespace llvm::support; ModuleKind Kind = static_cast( - endian::readNext(Data)); - uint16_t Len = endian::readNext(Data); + endian::readNext(Data)); + uint16_t Len = + endian::readNext(Data); StringRef Name = StringRef((const char*)Data, Len); Data += Len; ModuleFile *OM = (Kind == MK_PrebuiltModule || Kind == MK_ExplicitModule || @@ -4047,21 +4066,21 @@ void ASTReader::ReadModuleOffsetMap(ModuleFile &F) const { } SourceLocation::UIntTy SLocOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t IdentifierIDOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t MacroIDOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t PreprocessedEntityIDOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t SubmoduleIDOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t SelectorIDOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t DeclIDOffset = - endian::readNext(Data); + endian::readNext(Data); uint32_t TypeIndexOffset = - endian::readNext(Data); + endian::readNext(Data); auto mapOffset = [&](uint32_t Offset, uint32_t BaseOffset, RemapBuilder &Remap) { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 27700c711d52..739344b9a128 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1873,7 +1873,7 @@ namespace { void EmitKey(raw_ostream& Out, key_type_ref key, unsigned KeyLen) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); LE.write(key.Size); KeyLen -= 8; LE.write(key.ModTime); @@ -1885,7 +1885,7 @@ namespace { data_type_ref Data, unsigned DataLen) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); uint64_t Start = Out.tell(); (void)Start; unsigned char Flags = (Data.AlreadyIncluded << 6) @@ -2053,7 +2053,7 @@ void ASTWriter::WriteHeaderSearch(const HeaderSearch &HS) { llvm::raw_svector_ostream Out(TableData); // Make sure that no bucket is at offset 0 - endian::write(Out, 0, little); + endian::write(Out, 0, llvm::endianness::little); BucketOffset = Generator.Emit(Out, GeneratorTrait); } @@ -3313,7 +3313,7 @@ public: void EmitKey(raw_ostream& Out, Selector Sel, unsigned) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); uint64_t Start = Out.tell(); assert((Start >> 32) == 0 && "Selector key offset too large"); Writer.SetSelectorOffset(Sel, Start); @@ -3330,7 +3330,7 @@ public: data_type_ref Methods, unsigned DataLen) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); uint64_t Start = Out.tell(); (void)Start; LE.write(Methods.ID); unsigned NumInstanceMethods = 0; @@ -3453,7 +3453,7 @@ void ASTWriter::WriteSelectors(Sema &SemaRef) { ASTMethodPoolTrait Trait(*this); llvm::raw_svector_ostream Out(MethodPool); // Make sure that no bucket is at offset 0 - endian::write(Out, 0, little); + endian::write(Out, 0, llvm::endianness::little); BucketOffset = Generator.Emit(Out, Trait); } @@ -3650,7 +3650,7 @@ public: IdentID ID, unsigned) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); auto MacroOffset = Writer.getMacroDirectivesOffset(II); if (!isInterestingIdentifier(II, MacroOffset)) { @@ -3749,7 +3749,7 @@ void ASTWriter::WriteIdentifierTable(Preprocessor &PP, llvm::raw_svector_ostream Out(IdentifierTable); // Make sure that no bucket is at offset 0 - endian::write(Out, 0, little); + endian::write(Out, 0, llvm::endianness::little); BucketOffset = Generator.Emit(Out, Trait); } @@ -3844,7 +3844,8 @@ public: using namespace llvm::support; - endian::write(Out, Writer.getChain()->getModuleFileID(F), little); + endian::write(Out, Writer.getChain()->getModuleFileID(F), + llvm::endianness::little); } std::pair EmitKeyDataLength(raw_ostream &Out, @@ -3879,7 +3880,7 @@ public: void EmitKey(raw_ostream &Out, DeclarationNameKey Name, unsigned) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); LE.write(Name.getKind()); switch (Name.getKind()) { case DeclarationName::Identifier: @@ -3911,7 +3912,7 @@ public: unsigned DataLen) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); uint64_t Start = Out.tell(); (void)Start; for (unsigned I = Lookup.first, N = Lookup.second; I != N; ++I) LE.write(DeclIDs[I]); @@ -5024,7 +5025,7 @@ ASTFileSignature ASTWriter::WriteASTCore(Sema &SemaRef, StringRef isysroot, for (ModuleFile &M : Chain->ModuleMgr) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); LE.write(static_cast(M.Kind)); StringRef Name = M.isModule() ? M.ModuleName : M.FileName; LE.write(Name.size()); diff --git a/clang/lib/Serialization/GlobalModuleIndex.cpp b/clang/lib/Serialization/GlobalModuleIndex.cpp index b4a49972ace2..fb80a1998d0e 100644 --- a/clang/lib/Serialization/GlobalModuleIndex.cpp +++ b/clang/lib/Serialization/GlobalModuleIndex.cpp @@ -89,8 +89,10 @@ public: static std::pair ReadKeyDataLength(const unsigned char*& d) { using namespace llvm::support; - unsigned KeyLen = endian::readNext(d); - unsigned DataLen = endian::readNext(d); + unsigned KeyLen = + endian::readNext(d); + unsigned DataLen = + endian::readNext(d); return std::make_pair(KeyLen, DataLen); } @@ -111,7 +113,8 @@ public: data_type Result; while (DataLen > 0) { - unsigned ID = endian::readNext(d); + unsigned ID = + endian::readNext(d); Result.push_back(ID); DataLen -= 4; } @@ -511,7 +514,8 @@ namespace { // The first bit indicates whether this identifier is interesting. // That's all we care about. using namespace llvm::support; - unsigned RawID = endian::readNext(d); + unsigned RawID = + endian::readNext(d); bool IsInteresting = RawID & 0x01; return std::make_pair(k, IsInteresting); } @@ -729,7 +733,7 @@ public: std::pair EmitKeyDataLength(raw_ostream& Out, key_type_ref Key, data_type_ref Data) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); unsigned KeyLen = Key.size(); unsigned DataLen = Data.size() * 4; LE.write(KeyLen); @@ -745,7 +749,7 @@ public: unsigned DataLen) { using namespace llvm::support; for (unsigned I = 0, N = Data.size(); I != N; ++I) - endian::write(Out, Data[I], little); + endian::write(Out, Data[I], llvm::endianness::little); } }; @@ -824,7 +828,7 @@ bool GlobalModuleIndexBuilder::writeIndex(llvm::BitstreamWriter &Stream) { using namespace llvm::support; llvm::raw_svector_ostream Out(IdentifierTable); // Make sure that no bucket is at offset 0 - endian::write(Out, 0, little); + endian::write(Out, 0, llvm::endianness::little); BucketOffset = Generator.Emit(Out, Trait); } diff --git a/clang/lib/Serialization/MultiOnDiskHashTable.h b/clang/lib/Serialization/MultiOnDiskHashTable.h index adc97d57e0ac..2402a628b512 100644 --- a/clang/lib/Serialization/MultiOnDiskHashTable.h +++ b/clang/lib/Serialization/MultiOnDiskHashTable.h @@ -199,10 +199,12 @@ public: storage_type Ptr = Data; - uint32_t BucketOffset = endian::readNext(Ptr); + uint32_t BucketOffset = + endian::readNext(Ptr); // Read the list of overridden files. - uint32_t NumFiles = endian::readNext(Ptr); + uint32_t NumFiles = + endian::readNext(Ptr); // FIXME: Add a reserve() to TinyPtrVector so that we don't need to make // an additional copy. llvm::SmallVector OverriddenFiles; @@ -311,7 +313,7 @@ public: // Write our header information. { - endian::Writer Writer(OutStream, little); + endian::Writer Writer(OutStream, llvm::endianness::little); // Reserve four bytes for the bucket offset. Writer.write(0); diff --git a/llvm/include/llvm/Bitstream/BitstreamWriter.h b/llvm/include/llvm/Bitstream/BitstreamWriter.h index 8a59d0444e36..f7d362b5d70c 100644 --- a/llvm/include/llvm/Bitstream/BitstreamWriter.h +++ b/llvm/include/llvm/Bitstream/BitstreamWriter.h @@ -139,10 +139,11 @@ public: uint64_t NumOfFlushedBytes = GetNumOfFlushedBytes(); if (ByteNo >= NumOfFlushedBytes) { - assert((!endian::readAtBitAlignment( + assert((!endian::readAtBitAlignment( &Out[ByteNo - NumOfFlushedBytes], StartBit)) && "Expected to be patching over 0-value placeholders"); - endian::writeAtBitAlignment( + endian::writeAtBitAlignment( &Out[ByteNo - NumOfFlushedBytes], NewByte, StartBit); return; } @@ -171,14 +172,14 @@ public: assert(BytesRead >= 0 && static_cast(BytesRead) == BytesFromDisk); for (size_t i = 0; i < BytesFromBuffer; ++i) Bytes[BytesFromDisk + i] = Out[i]; - assert((!endian::readAtBitAlignment( - Bytes, StartBit)) && + assert((!endian::readAtBitAlignment(Bytes, StartBit)) && "Expected to be patching over 0-value placeholders"); } // Update Bytes in terms of bit offset and value. - endian::writeAtBitAlignment(Bytes, NewByte, - StartBit); + endian::writeAtBitAlignment( + Bytes, NewByte, StartBit); // Copy updated data back to the file FS and the buffer Out. FS->seek(ByteNo); diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h index 172b4c9f6187..5f54cbeb1b01 100644 --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -500,8 +500,10 @@ public: ReadKeyDataLength(const unsigned char *&D) { using namespace support; - offset_type KeyLen = endian::readNext(D); - offset_type DataLen = endian::readNext(D); + offset_type KeyLen = + endian::readNext(D); + offset_type DataLen = + endian::readNext(D); return std::make_pair(KeyLen, DataLen); } diff --git a/llvm/include/llvm/ProfileData/MemProf.h b/llvm/include/llvm/ProfileData/MemProf.h index d0ba5b10be02..1a066c10c136 100644 --- a/llvm/include/llvm/ProfileData/MemProf.h +++ b/llvm/include/llvm/ProfileData/MemProf.h @@ -50,7 +50,7 @@ struct PortableMemInfoBlock { switch (Id) { #define MIBEntryDef(NameTag, Name, Type) \ case Meta::Name: { \ - Name = endian::readNext(Ptr); \ + Name = endian::readNext(Ptr); \ } break; #include "llvm/ProfileData/MIBEntryDef.inc" #undef MIBEntryDef @@ -66,7 +66,7 @@ struct PortableMemInfoBlock { void serialize(const MemProfSchema &Schema, raw_ostream &OS) const { using namespace support; - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); for (const Meta Id : Schema) { switch (Id) { #define MIBEntryDef(NameTag, Name, Type) \ @@ -187,7 +187,7 @@ struct Frame { void serialize(raw_ostream &OS) const { using namespace support; - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); // If the type of the GlobalValue::GUID changes, then we need to update // the reader and the writer. @@ -204,10 +204,14 @@ struct Frame { static Frame deserialize(const unsigned char *Ptr) { using namespace support; - const uint64_t F = endian::readNext(Ptr); - const uint32_t L = endian::readNext(Ptr); - const uint32_t C = endian::readNext(Ptr); - const bool I = endian::readNext(Ptr); + const uint64_t F = + endian::readNext(Ptr); + const uint32_t L = + endian::readNext(Ptr); + const uint32_t C = + endian::readNext(Ptr); + const bool I = + endian::readNext(Ptr); return Frame(/*Function=*/F, /*LineOffset=*/L, /*Column=*/C, /*IsInlineFrame=*/I); } @@ -466,14 +470,17 @@ public: ReadKeyDataLength(const unsigned char *&D) { using namespace support; - offset_type KeyLen = endian::readNext(D); - offset_type DataLen = endian::readNext(D); + offset_type KeyLen = + endian::readNext(D); + offset_type DataLen = + endian::readNext(D); return std::make_pair(KeyLen, DataLen); } uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) { using namespace support; - return endian::readNext(D); + return endian::readNext(D); } data_type ReadData(uint64_t K, const unsigned char *D, @@ -514,7 +521,7 @@ public: EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); offset_type N = sizeof(K); LE.write(N); offset_type M = V.serializedSize(); @@ -524,7 +531,7 @@ public: void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); LE.write(K); } @@ -552,7 +559,7 @@ public: static std::pair EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); offset_type N = sizeof(K); LE.write(N); offset_type M = V.serializedSize(); @@ -562,7 +569,7 @@ public: void EmitKey(raw_ostream &Out, key_type_ref K, offset_type /*Unused*/) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); LE.write(K); } @@ -593,14 +600,17 @@ public: ReadKeyDataLength(const unsigned char *&D) { using namespace support; - offset_type KeyLen = endian::readNext(D); - offset_type DataLen = endian::readNext(D); + offset_type KeyLen = + endian::readNext(D); + offset_type DataLen = + endian::readNext(D); return std::make_pair(KeyLen, DataLen); } uint64_t ReadKey(const unsigned char *D, offset_type /*Unused*/) { using namespace support; - return endian::readNext(D); + return endian::readNext(D); } data_type ReadData(uint64_t K, const unsigned char *D, diff --git a/llvm/include/llvm/Support/Endian.h b/llvm/include/llvm/Support/Endian.h index 808446e61545..d4fc6b59e252 100644 --- a/llvm/include/llvm/Support/Endian.h +++ b/llvm/include/llvm/Support/Endian.h @@ -53,7 +53,7 @@ constexpr endianness system_endianness() { return llvm::endianness::native; } template [[nodiscard]] inline value_type byte_swap(value_type value, endianness endian) { - if (endian != native) + if (endian != llvm::endianness::native) sys::swapByteOrder(value); return value; } @@ -273,85 +273,120 @@ public: } // end namespace detail using ulittle16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ulittle32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ulittle64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using little16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using little32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using little64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ulittle16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ulittle32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ulittle64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_little16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_little32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_little64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ubig16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ubig32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using ubig64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using big16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using big32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using big64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ubig16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ubig32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_ubig64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_big16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_big32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using aligned_big64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_uint16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_uint32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_uint64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_int16_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_int32_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; using unaligned_int64_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; template -using little_t = detail::packed_endian_specific_integral; +using little_t = + detail::packed_endian_specific_integral; template -using big_t = detail::packed_endian_specific_integral; +using big_t = detail::packed_endian_specific_integral; template using aligned_little_t = - detail::packed_endian_specific_integral; + detail::packed_endian_specific_integral; template -using aligned_big_t = detail::packed_endian_specific_integral; +using aligned_big_t = + detail::packed_endian_specific_integral; namespace endian { @@ -380,17 +415,23 @@ template [[nodiscard]] inline uint64_t read64(const void *P) { } [[nodiscard]] inline uint16_t read16le(const void *P) { - return read16(P); + return read16(P); } [[nodiscard]] inline uint32_t read32le(const void *P) { - return read32(P); + return read32(P); } [[nodiscard]] inline uint64_t read64le(const void *P) { - return read64(P); + return read64(P); +} +[[nodiscard]] inline uint16_t read16be(const void *P) { + return read16(P); +} +[[nodiscard]] inline uint32_t read32be(const void *P) { + return read32(P); +} +[[nodiscard]] inline uint64_t read64be(const void *P) { + return read64(P); } -[[nodiscard]] inline uint16_t read16be(const void *P) { return read16(P); } -[[nodiscard]] inline uint32_t read32be(const void *P) { return read32(P); } -[[nodiscard]] inline uint64_t read64be(const void *P) { return read64(P); } template inline void write(void *P, T V) { *(detail::packed_endian_specific_integral *)P = V; @@ -416,12 +457,24 @@ template inline void write64(void *P, uint64_t V) { write(P, V); } -inline void write16le(void *P, uint16_t V) { write16(P, V); } -inline void write32le(void *P, uint32_t V) { write32(P, V); } -inline void write64le(void *P, uint64_t V) { write64(P, V); } -inline void write16be(void *P, uint16_t V) { write16(P, V); } -inline void write32be(void *P, uint32_t V) { write32(P, V); } -inline void write64be(void *P, uint64_t V) { write64(P, V); } +inline void write16le(void *P, uint16_t V) { + write16(P, V); +} +inline void write32le(void *P, uint32_t V) { + write32(P, V); +} +inline void write64le(void *P, uint64_t V) { + write64(P, V); +} +inline void write16be(void *P, uint16_t V) { + write16(P, V); +} +inline void write32be(void *P, uint32_t V) { + write32(P, V); +} +inline void write64be(void *P, uint64_t V) { + write64(P, V); +} } // end namespace endian diff --git a/llvm/include/llvm/Support/MD5.h b/llvm/include/llvm/Support/MD5.h index 61af6002696a..0e9f22d3bfdb 100644 --- a/llvm/include/llvm/Support/MD5.h +++ b/llvm/include/llvm/Support/MD5.h @@ -47,12 +47,12 @@ public: // Our MD5 implementation returns the result in little endian, so the low // word is first. using namespace support; - return endian::read(data()); + return endian::read(data()); } uint64_t high() const { using namespace support; - return endian::read(data() + 8); + return endian::read(data() + 8); } std::pair words() const { using namespace support; diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h index bb90d8fc3ac7..0a8cbbd8b188 100644 --- a/llvm/include/llvm/Support/OnDiskHashTable.h +++ b/llvm/include/llvm/Support/OnDiskHashTable.h @@ -149,7 +149,7 @@ public: /// Uses the provided Info instead of a stack allocated one. offset_type Emit(raw_ostream &Out, Info &InfoObj) { using namespace llvm::support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); // Now we're done adding entries, resize the bucket list if it's // significantly too large. (This only happens if the number of @@ -304,9 +304,11 @@ public: "buckets should be 4-byte aligned."); using namespace llvm::support; offset_type NumBuckets = - endian::readNext(Buckets); + endian::readNext( + Buckets); offset_type NumEntries = - endian::readNext(Buckets); + endian::readNext( + Buckets); return std::make_pair(NumBuckets, NumEntries); } @@ -357,19 +359,23 @@ public: offset_type Idx = KeyHash & (NumBuckets - 1); const unsigned char *Bucket = Buckets + sizeof(offset_type) * Idx; - offset_type Offset = endian::readNext(Bucket); + offset_type Offset = + endian::readNext( + Bucket); if (Offset == 0) return iterator(); // Empty bucket. const unsigned char *Items = Base + Offset; // 'Items' starts with a 16-bit unsigned integer representing the // number of items in this bucket. - unsigned Len = endian::readNext(Items); + unsigned Len = + endian::readNext(Items); for (unsigned i = 0; i < Len; ++i) { // Read the hash. hash_value_type ItemHash = - endian::readNext(Items); + endian::readNext(Items); // Determine the length of the key and the data. const std::pair &L = @@ -467,7 +473,8 @@ private: // 'Items' starts with a 16-bit unsigned integer representing the // number of items in this bucket. NumItemsInBucketLeft = - endian::readNext(Ptr); + endian::readNext( + Ptr); } Ptr += sizeof(hash_value_type); // Skip the hash. // Determine the length of the key and the data. diff --git a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp index 10409b9bdb2a..4aed64966654 100644 --- a/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp +++ b/llvm/lib/ExecutionEngine/JITLink/aarch32.cpp @@ -405,10 +405,10 @@ Error applyFixupData(LinkGraph &G, Block &B, const Edge &E) { auto Write32 = [FixupPtr, Endian = G.getEndianness()](int64_t Value) { assert(isInt<32>(Value) && "Must be in signed 32-bit range"); uint32_t Imm = static_cast(Value); - if (LLVM_LIKELY(Endian == little)) - endian::write32(FixupPtr, Imm); + if (LLVM_LIKELY(Endian == llvm::endianness::little)) + endian::write32(FixupPtr, Imm); else - endian::write32(FixupPtr, Imm); + endian::write32(FixupPtr, Imm); }; Edge::Kind Kind = E.getKind(); diff --git a/llvm/lib/MC/MCPseudoProbe.cpp b/llvm/lib/MC/MCPseudoProbe.cpp index ec9d0865888e..eb3894dbb3c2 100644 --- a/llvm/lib/MC/MCPseudoProbe.cpp +++ b/llvm/lib/MC/MCPseudoProbe.cpp @@ -343,7 +343,7 @@ template ErrorOr MCPseudoProbeDecoder::readUnencodedNumber() { if (Data + sizeof(T) > End) { return std::error_code(); } - T Val = endian::readNext(Data); + T Val = endian::readNext(Data); return ErrorOr(Val); } diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index 237caaaeca5a..ddc11304742d 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -1022,10 +1022,10 @@ template static T swapToHostOrder(const unsigned char *&D, llvm::endianness Orig) { using namespace support; - if (Orig == little) - return endian::readNext(D); + if (Orig == llvm::endianness::little) + return endian::readNext(D); else - return endian::readNext(D); + return endian::readNext(D); } static std::unique_ptr allocValueProfData(uint32_t TotalSize) { @@ -1449,7 +1449,7 @@ static inline uint64_t read(const unsigned char *Buffer, size_t Offset) { uint64_t Header::formatVersion() const { using namespace support; - return endian::byte_swap(Version); + return endian::byte_swap(Version); } Expected
Header::readFromBuffer(const unsigned char *Buffer) { @@ -1461,7 +1461,8 @@ Expected
Header::readFromBuffer(const unsigned char *Buffer) { H.Magic = read(Buffer, offsetOf(&Header::Magic)); // Check the magic number. - uint64_t Magic = endian::byte_swap(H.Magic); + uint64_t Magic = + endian::byte_swap(H.Magic); if (Magic != IndexedInstrProf::Magic) return make_error(instrprof_error::bad_magic); diff --git a/llvm/lib/ProfileData/InstrProfReader.cpp b/llvm/lib/ProfileData/InstrProfReader.cpp index 3800b23843fa..a920a31d0a4b 100644 --- a/llvm/lib/ProfileData/InstrProfReader.cpp +++ b/llvm/lib/ProfileData/InstrProfReader.cpp @@ -112,10 +112,11 @@ readBinaryIdsInternal(const MemoryBuffer &DataBuffer, "not enough data to read binary id length"); uint64_t BILen = 0; - if (Endian == little) - BILen = endian::readNext(BI); + if (Endian == llvm::endianness::little) + BILen = + endian::readNext(BI); else - BILen = endian::readNext(BI); + BILen = endian::readNext(BI); if (BILen == 0) return make_error(instrprof_error::malformed, @@ -800,7 +801,8 @@ data_type InstrProfLookupTrait::ReadData(StringRef K, const unsigned char *D, // Read hash. if (D + sizeof(uint64_t) >= End) return data_type(); - uint64_t Hash = endian::readNext(D); + uint64_t Hash = + endian::readNext(D); // Initialize number of counters for GET_VERSION(FormatVersion) == 1. uint64_t CountsSize = N / sizeof(uint64_t) - 1; @@ -808,7 +810,8 @@ data_type InstrProfLookupTrait::ReadData(StringRef K, const unsigned char *D, if (GET_VERSION(FormatVersion) != IndexedInstrProf::ProfVersion::Version1) { if (D + sizeof(uint64_t) > End) return data_type(); - CountsSize = endian::readNext(D); + CountsSize = + endian::readNext(D); } // Read counter values. if (D + CountsSize * sizeof(uint64_t) > End) @@ -817,7 +820,8 @@ data_type InstrProfLookupTrait::ReadData(StringRef K, const unsigned char *D, CounterBuffer.clear(); CounterBuffer.reserve(CountsSize); for (uint64_t J = 0; J < CountsSize; ++J) - CounterBuffer.push_back(endian::readNext(D)); + CounterBuffer.push_back( + endian::readNext(D)); DataBuffer.emplace_back(K, Hash, std::move(CounterBuffer)); @@ -1001,8 +1005,8 @@ bool IndexedInstrProfReader::hasFormat(const MemoryBuffer &DataBuffer) { if (DataBuffer.getBufferSize() < 8) return false; - uint64_t Magic = - endian::read(DataBuffer.getBufferStart()); + uint64_t Magic = endian::read( + DataBuffer.getBufferStart()); // Verify that it's magical. return Magic == IndexedInstrProf::Magic; } @@ -1016,10 +1020,10 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version, if (Version >= IndexedInstrProf::Version4) { const IndexedInstrProf::Summary *SummaryInLE = reinterpret_cast(Cur); - uint64_t NFields = - endian::byte_swap(SummaryInLE->NumSummaryFields); - uint64_t NEntries = - endian::byte_swap(SummaryInLE->NumCutoffEntries); + uint64_t NFields = endian::byte_swap( + SummaryInLE->NumSummaryFields); + uint64_t NEntries = endian::byte_swap( + SummaryInLE->NumCutoffEntries); uint32_t SummarySize = IndexedInstrProf::Summary::getSize(NFields, NEntries); std::unique_ptr SummaryData = @@ -1028,7 +1032,7 @@ IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version, const uint64_t *Src = reinterpret_cast(SummaryInLE); uint64_t *Dst = reinterpret_cast(SummaryData.get()); for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++) - Dst[I] = endian::byte_swap(Src[I]); + Dst[I] = endian::byte_swap(Src[I]); SummaryEntryVector DetailedSummary; for (unsigned I = 0; I < SummaryData->NumCutoffEntries; I++) { @@ -1085,11 +1089,12 @@ Error IndexedInstrProfReader::readHeader() { /* UseCS */ true); // Read the hash type and start offset. IndexedInstrProf::HashT HashType = static_cast( - endian::byte_swap(Header->HashType)); + endian::byte_swap(Header->HashType)); if (HashType > IndexedInstrProf::HashT::Last) return error(instrprof_error::unsupported_hash_type); - uint64_t HashOffset = endian::byte_swap(Header->HashOffset); + uint64_t HashOffset = + endian::byte_swap(Header->HashOffset); // The hash table with profile counts comes next. auto IndexPtr = std::make_unique>( @@ -1100,19 +1105,23 @@ Error IndexedInstrProfReader::readHeader() { if (GET_VERSION(Header->formatVersion()) >= 8 && Header->formatVersion() & VARIANT_MASK_MEMPROF) { uint64_t MemProfOffset = - endian::byte_swap(Header->MemProfOffset); + endian::byte_swap( + Header->MemProfOffset); const unsigned char *Ptr = Start + MemProfOffset; // The value returned from RecordTableGenerator.Emit. const uint64_t RecordTableOffset = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); // The offset in the stream right before invoking // FrameTableGenerator.Emit. const uint64_t FramePayloadOffset = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); // The value returned from FrameTableGenerator.Emit. const uint64_t FrameTableOffset = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); // Read the schema. auto SchemaOr = memprof::readMemProfSchema(Ptr); @@ -1137,10 +1146,13 @@ Error IndexedInstrProfReader::readHeader() { // is higher than 9 (when it was introduced). if (GET_VERSION(Header->formatVersion()) >= 9) { uint64_t BinaryIdOffset = - endian::byte_swap(Header->BinaryIdOffset); + endian::byte_swap( + Header->BinaryIdOffset); const unsigned char *Ptr = Start + BinaryIdOffset; // Read binary ids size. - BinaryIdsSize = support::endian::readNext(Ptr); + BinaryIdsSize = + support::endian::readNext(Ptr); if (BinaryIdsSize % sizeof(uint64_t)) return error(instrprof_error::bad_header); // Set the binary ids start. @@ -1153,31 +1165,37 @@ Error IndexedInstrProfReader::readHeader() { if (GET_VERSION(Header->formatVersion()) >= 10 && Header->formatVersion() & VARIANT_MASK_TEMPORAL_PROF) { uint64_t TemporalProfTracesOffset = - endian::byte_swap(Header->TemporalProfTracesOffset); + endian::byte_swap( + Header->TemporalProfTracesOffset); const unsigned char *Ptr = Start + TemporalProfTracesOffset; const auto *PtrEnd = (const unsigned char *)DataBuffer->getBufferEnd(); // Expect at least two 64 bit fields: NumTraces, and TraceStreamSize if (Ptr + 2 * sizeof(uint64_t) > PtrEnd) return error(instrprof_error::truncated); const uint64_t NumTraces = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); TemporalProfTraceStreamSize = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); for (unsigned i = 0; i < NumTraces; i++) { // Expect at least two 64 bit fields: Weight and NumFunctions if (Ptr + 2 * sizeof(uint64_t) > PtrEnd) return error(instrprof_error::truncated); TemporalProfTraceTy Trace; Trace.Weight = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); const uint64_t NumFunctions = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); // Expect at least NumFunctions 64 bit fields if (Ptr + NumFunctions * sizeof(uint64_t) > PtrEnd) return error(instrprof_error::truncated); for (unsigned j = 0; j < NumFunctions; j++) { const uint64_t NameRef = - support::endian::readNext(Ptr); + support::endian::readNext(Ptr); Trace.FunctionNameRefs.push_back(NameRef); } TemporalProfTraces.push_back(std::move(Trace)); diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp index 2873e06266e4..6892654b00ea 100644 --- a/llvm/lib/ProfileData/InstrProfWriter.cpp +++ b/llvm/lib/ProfileData/InstrProfWriter.cpp @@ -80,7 +80,8 @@ public: std::string &Data = SOStream.str(); // with flush for (int K = 0; K < NItems; K++) { for (int I = 0; I < P[K].N; I++) { - uint64_t Bytes = endian::byte_swap(P[K].D[I]); + uint64_t Bytes = + endian::byte_swap(P[K].D[I]); Data.replace(P[K].Pos + I * sizeof(uint64_t), sizeof(uint64_t), (const char *)&Bytes, sizeof(uint64_t)); } @@ -120,7 +121,7 @@ public: EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); offset_type N = K.size(); LE.write(N); @@ -147,7 +148,7 @@ public: void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type) { using namespace support; - endian::Writer LE(Out, little); + endian::Writer LE(Out, llvm::endianness::little); for (const auto &ProfileData : *V) { const InstrProfRecord &ProfRecord = ProfileData.second; if (NamedInstrProfRecord::hasCSFlagInHash(ProfileData.first)) diff --git a/llvm/lib/ProfileData/MemProf.cpp b/llvm/lib/ProfileData/MemProf.cpp index 3255cba4dd0c..db34de704a3c 100644 --- a/llvm/lib/ProfileData/MemProf.cpp +++ b/llvm/lib/ProfileData/MemProf.cpp @@ -13,7 +13,7 @@ void IndexedMemProfRecord::serialize(const MemProfSchema &Schema, raw_ostream &OS) { using namespace support; - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write(AllocSites.size()); for (const IndexedAllocationInfo &N : AllocSites) { @@ -40,13 +40,15 @@ IndexedMemProfRecord::deserialize(const MemProfSchema &Schema, IndexedMemProfRecord Record; // Read the meminfo nodes. - const uint64_t NumNodes = endian::readNext(Ptr); + const uint64_t NumNodes = + endian::readNext(Ptr); for (uint64_t I = 0; I < NumNodes; I++) { IndexedAllocationInfo Node; const uint64_t NumFrames = - endian::readNext(Ptr); + endian::readNext(Ptr); for (uint64_t J = 0; J < NumFrames; J++) { - const FrameId Id = endian::readNext(Ptr); + const FrameId Id = + endian::readNext(Ptr); Node.CallStack.push_back(Id); } Node.Info.deserialize(Schema, Ptr); @@ -55,14 +57,16 @@ IndexedMemProfRecord::deserialize(const MemProfSchema &Schema, } // Read the callsite information. - const uint64_t NumCtxs = endian::readNext(Ptr); + const uint64_t NumCtxs = + endian::readNext(Ptr); for (uint64_t J = 0; J < NumCtxs; J++) { const uint64_t NumFrames = - endian::readNext(Ptr); + endian::readNext(Ptr); llvm::SmallVector Frames; Frames.reserve(NumFrames); for (uint64_t K = 0; K < NumFrames; K++) { - const FrameId Id = endian::readNext(Ptr); + const FrameId Id = + endian::readNext(Ptr); Frames.push_back(Id); } Record.CallSites.push_back(Frames); @@ -90,7 +94,7 @@ Expected readMemProfSchema(const unsigned char *&Buffer) { const unsigned char *Ptr = Buffer; const uint64_t NumSchemaIds = - endian::readNext(Ptr); + endian::readNext(Ptr); if (NumSchemaIds > static_cast(Meta::Size)) { return make_error(instrprof_error::malformed, "memprof schema invalid"); @@ -98,7 +102,8 @@ Expected readMemProfSchema(const unsigned char *&Buffer) { MemProfSchema Result; for (size_t I = 0; I < NumSchemaIds; I++) { - const uint64_t Tag = endian::readNext(Ptr); + const uint64_t Tag = + endian::readNext(Ptr); if (Tag >= static_cast(Meta::Size)) { return make_error(instrprof_error::malformed, "memprof schema invalid"); diff --git a/llvm/lib/ProfileData/RawMemProfReader.cpp b/llvm/lib/ProfileData/RawMemProfReader.cpp index 0716ec53ce3f..284e5ec63465 100644 --- a/llvm/lib/ProfileData/RawMemProfReader.cpp +++ b/llvm/lib/ProfileData/RawMemProfReader.cpp @@ -87,7 +87,7 @@ llvm::SmallVector readSegmentEntries(const char *Ptr) { using namespace support; const uint64_t NumItemsToRead = - endian::readNext(Ptr); + endian::readNext(Ptr); llvm::SmallVector Items; for (uint64_t I = 0; I < NumItemsToRead; I++) { Items.push_back(*reinterpret_cast( @@ -101,10 +101,11 @@ readMemInfoBlocks(const char *Ptr) { using namespace support; const uint64_t NumItemsToRead = - endian::readNext(Ptr); + endian::readNext(Ptr); llvm::SmallVector> Items; for (uint64_t I = 0; I < NumItemsToRead; I++) { - const uint64_t Id = endian::readNext(Ptr); + const uint64_t Id = + endian::readNext(Ptr); const MemInfoBlock MIB = *reinterpret_cast(Ptr); Items.push_back({Id, MIB}); // Only increment by size of MIB since readNext implicitly increments. @@ -117,16 +118,19 @@ CallStackMap readStackInfo(const char *Ptr) { using namespace support; const uint64_t NumItemsToRead = - endian::readNext(Ptr); + endian::readNext(Ptr); CallStackMap Items; for (uint64_t I = 0; I < NumItemsToRead; I++) { - const uint64_t StackId = endian::readNext(Ptr); - const uint64_t NumPCs = endian::readNext(Ptr); + const uint64_t StackId = + endian::readNext(Ptr); + const uint64_t NumPCs = + endian::readNext(Ptr); SmallVector CallStack; for (uint64_t J = 0; J < NumPCs; J++) { - CallStack.push_back(endian::readNext(Ptr)); + CallStack.push_back( + endian::readNext(Ptr)); } Items[StackId] = CallStack; diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp index e8e468ed7370..256bdb833a0b 100644 --- a/llvm/lib/ProfileData/SampleProfReader.cpp +++ b/llvm/lib/ProfileData/SampleProfReader.cpp @@ -502,7 +502,7 @@ ErrorOr SampleProfileReaderBinary::readUnencodedNumber() { } using namespace support; - T Val = endian::readNext(Data); + T Val = endian::readNext(Data); return Val; } @@ -531,8 +531,8 @@ SampleProfileReaderBinary::readStringFromTable(size_t *RetIdx) { if (!SR.data()) { assert(MD5NameMemStart); using namespace support; - uint64_t FID = endian::read(MD5NameMemStart + - (*Idx) * sizeof(uint64_t)); + uint64_t FID = endian::read( + MD5NameMemStart + (*Idx) * sizeof(uint64_t)); SR = MD5StringBuf.emplace_back(std::to_string(FID)); } if (RetIdx) diff --git a/llvm/unittests/DebugInfo/MSF/MappedBlockStreamTest.cpp b/llvm/unittests/DebugInfo/MSF/MappedBlockStreamTest.cpp index 3da19b90a28a..d1f04e9b28a3 100644 --- a/llvm/unittests/DebugInfo/MSF/MappedBlockStreamTest.cpp +++ b/llvm/unittests/DebugInfo/MSF/MappedBlockStreamTest.cpp @@ -34,7 +34,9 @@ public: uint32_t block_size() const { return 1; } uint32_t block_count() const { return Blocks.size(); } - endianness getEndian() const override { return little; } + llvm::endianness getEndian() const override { + return llvm::endianness::little; + } Error readBytes(uint64_t Offset, uint64_t Size, ArrayRef &Buffer) override { @@ -412,7 +414,7 @@ TEST(MappedBlockStreamTest, TestWriteContiguousStreamRef) { F.block_size(), F.layout(), F, F.Allocator); // First write "Test Str" into the source stream. - MutableBinaryByteStream SourceStream(SrcData, little); + MutableBinaryByteStream SourceStream(SrcData, llvm::endianness::little); BinaryStreamWriter SourceWriter(SourceStream); EXPECT_THAT_ERROR(SourceWriter.writeCString("Test Str"), Succeeded()); EXPECT_EQ(SrcDataBytes, std::vector( diff --git a/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp b/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp index 57f0dcf23db0..6d17332f4907 100644 --- a/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp +++ b/llvm/unittests/DebugInfo/PDB/HashTableTest.cpp @@ -147,7 +147,7 @@ TEST(HashTableTest, Serialization) { } std::vector Buffer(Table.calculateSerializedLength()); - MutableBinaryByteStream Stream(Buffer, little); + MutableBinaryByteStream Stream(Buffer, llvm::endianness::little); BinaryStreamWriter Writer(Stream); EXPECT_THAT_ERROR(Table.commit(Writer), Succeeded()); // We should have written precisely the number of bytes we calculated earlier. @@ -251,7 +251,7 @@ TEST(HashTableTest, NonTrivialValueType) { } std::vector Buffer(Table.calculateSerializedLength()); - MutableBinaryByteStream Stream(Buffer, little); + MutableBinaryByteStream Stream(Buffer, llvm::endianness::little); BinaryStreamWriter Writer(Stream); EXPECT_THAT_ERROR(Table.commit(Writer), Succeeded()); // We should have written precisely the number of bytes we calculated earlier. diff --git a/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp b/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp index 2f7c06194406..1253f7c7ead7 100644 --- a/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp +++ b/llvm/unittests/DebugInfo/PDB/StringTableBuilderTest.cpp @@ -47,12 +47,12 @@ TEST(StringTableBuilderTest, Simple) { EXPECT_EQ(6U, Distinct.size()); std::vector Buffer(Builder.calculateSerializedSize()); - MutableBinaryByteStream OutStream(Buffer, little); + MutableBinaryByteStream OutStream(Buffer, llvm::endianness::little); BinaryStreamWriter Writer(OutStream); EXPECT_THAT_ERROR(Builder.commit(Writer), Succeeded()); // Reads the contents back. - BinaryByteStream InStream(Buffer, little); + BinaryByteStream InStream(Buffer, llvm::endianness::little); BinaryStreamReader Reader(InStream); PDBStringTable Table; EXPECT_THAT_ERROR(Table.reload(Reader), Succeeded()); diff --git a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp index 3f581445a2d6..dcc8d3b237ff 100644 --- a/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp +++ b/llvm/unittests/ExecutionEngine/JITLink/AArch32Tests.cpp @@ -110,9 +110,11 @@ TEST(AArch32_Relocations, Thumb_Call_J1J2) { constexpr HalfWords ImmMask = FixupInfo::ImmMask; static std::array MemPresets{ - makeHalfWords({0xff, 0xf7, 0xfe, 0xef}), // common - makeHalfWords({0x00, 0x00, 0x00, 0x00}), // zeros - makeHalfWords({0xff, 0xff, 0xff, 0xff}), // ones + makeHalfWords( + {0xff, 0xf7, 0xfe, 0xef}), // common + makeHalfWords( + {0x00, 0x00, 0x00, 0x00}), // zeros + makeHalfWords({0xff, 0xff, 0xff, 0xff}), // ones }; auto EncodeDecode = [ImmMask](int64_t In, MutableHalfWords &Mem) { @@ -146,9 +148,11 @@ TEST(AArch32_Relocations, Thumb_Call_Bare) { constexpr HalfWords ImmMask = FixupInfo::ImmMask; static std::array MemPresets{ - makeHalfWords({0xff, 0xf7, 0xfe, 0xef}), // common - makeHalfWords({0x00, 0x00, 0x00, 0x00}), // zeros - makeHalfWords({0xff, 0xff, 0xff, 0xff}), // ones + makeHalfWords( + {0xff, 0xf7, 0xfe, 0xef}), // common + makeHalfWords( + {0x00, 0x00, 0x00, 0x00}), // zeros + makeHalfWords({0xff, 0xff, 0xff, 0xff}), // ones }; auto EncodeDecode = [ImmMask](int64_t In, MutableHalfWords &Mem) { @@ -217,9 +221,11 @@ TEST(AArch32_Relocations, Thumb_MovtAbs) { static std::array Registers{0, 5, 12}; static std::array MemPresets{ - makeHalfWords({0xff, 0xf7, 0xfe, 0xef}), // common - makeHalfWords({0x00, 0x00, 0x00, 0x00}), // zeros - makeHalfWords({0xff, 0xff, 0xff, 0xff}), // ones + makeHalfWords( + {0xff, 0xf7, 0xfe, 0xef}), // common + makeHalfWords( + {0x00, 0x00, 0x00, 0x00}), // zeros + makeHalfWords({0xff, 0xff, 0xff, 0xff}), // ones }; auto EncodeDecode = [ImmMask](uint32_t In, MutableHalfWords &Mem) { diff --git a/llvm/unittests/Support/BinaryStreamTest.cpp b/llvm/unittests/Support/BinaryStreamTest.cpp index 037aa596e7bb..70cd4036fb2a 100644 --- a/llvm/unittests/Support/BinaryStreamTest.cpp +++ b/llvm/unittests/Support/BinaryStreamTest.cpp @@ -102,7 +102,8 @@ private: BumpPtrAllocator Allocator; }; -constexpr endianness Endians[] = {big, little, native}; +constexpr llvm::endianness Endians[] = { + llvm::endianness::big, llvm::endianness::little, llvm::endianness::native}; constexpr uint32_t NumEndians = std::size(Endians); constexpr uint32_t NumStreams = 2 * NumEndians; @@ -931,7 +932,7 @@ TEST_F(BinaryStreamTest, BinaryItemStream) { Objects.push_back(BinaryItemStreamObject(Buffer)); } - BinaryItemStream ItemStream(big); + BinaryItemStream ItemStream(llvm::endianness::big); ItemStream.setItems(Objects); BinaryStreamReader Reader(ItemStream); diff --git a/llvm/unittests/Support/EndianStreamTest.cpp b/llvm/unittests/Support/EndianStreamTest.cpp index 1e800ff5570b..2bab71c547b1 100644 --- a/llvm/unittests/Support/EndianStreamTest.cpp +++ b/llvm/unittests/Support/EndianStreamTest.cpp @@ -20,7 +20,7 @@ TEST(EndianStream, WriteInt32LE) { { raw_svector_ostream OS(data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write(static_cast(-1362446643)); } @@ -35,7 +35,7 @@ TEST(EndianStream, WriteInt32BE) { { raw_svector_ostream OS(data); - endian::Writer BE(OS, big); + endian::Writer BE(OS, llvm::endianness::big); BE.write(static_cast(-1362446643)); } @@ -51,7 +51,7 @@ TEST(EndianStream, WriteFloatLE) { { raw_svector_ostream OS(data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write(12345.0f); } @@ -66,7 +66,7 @@ TEST(EndianStream, WriteFloatBE) { { raw_svector_ostream OS(data); - endian::Writer BE(OS, big); + endian::Writer BE(OS, llvm::endianness::big); BE.write(12345.0f); } @@ -81,7 +81,7 @@ TEST(EndianStream, WriteInt64LE) { { raw_svector_ostream OS(data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write(static_cast(-136244664332342323)); } @@ -100,7 +100,7 @@ TEST(EndianStream, WriteInt64BE) { { raw_svector_ostream OS(data); - endian::Writer BE(OS, big); + endian::Writer BE(OS, llvm::endianness::big); BE.write(static_cast(-136244664332342323)); } @@ -119,7 +119,7 @@ TEST(EndianStream, WriteDoubleLE) { { raw_svector_ostream OS(data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write(-2349214918.58107); } @@ -138,7 +138,7 @@ TEST(EndianStream, WriteDoubleBE) { { raw_svector_ostream OS(data); - endian::Writer BE(OS, big); + endian::Writer BE(OS, llvm::endianness::big); BE.write(-2349214918.58107); } @@ -157,7 +157,7 @@ TEST(EndianStream, WriteArrayLE) { { raw_svector_ostream OS(Data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write({0x1234, 0x5678}); } @@ -172,7 +172,7 @@ TEST(EndianStream, WriteVectorLE) { { raw_svector_ostream OS(Data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); std::vector Vec{0x1234, 0x5678}; LE.write(Vec); } @@ -188,7 +188,7 @@ TEST(EndianStream, WriteFloatArrayLE) { { raw_svector_ostream OS(Data); - endian::Writer LE(OS, little); + endian::Writer LE(OS, llvm::endianness::little); LE.write({12345.0f, 12346.0f}); } diff --git a/llvm/unittests/Support/EndianTest.cpp b/llvm/unittests/Support/EndianTest.cpp index b5e4a9c8d14a..ab7dfc380069 100644 --- a/llvm/unittests/Support/EndianTest.cpp +++ b/llvm/unittests/Support/EndianTest.cpp @@ -23,12 +23,17 @@ TEST(Endian, Read) { unsigned char bigval[] = {0x00, 0x01, 0x02, 0x03, 0x04}; unsigned char littleval[] = {0x00, 0x04, 0x03, 0x02, 0x01}; int32_t BigAsHost = 0x00010203; - EXPECT_EQ(BigAsHost, (endian::read(bigval))); + EXPECT_EQ(BigAsHost, + (endian::read(bigval))); int32_t LittleAsHost = 0x02030400; - EXPECT_EQ(LittleAsHost,(endian::read(littleval))); + EXPECT_EQ( + LittleAsHost, + (endian::read(littleval))); - EXPECT_EQ((endian::read(bigval + 1)), - (endian::read(littleval + 1))); + EXPECT_EQ( + (endian::read(bigval + 1)), + (endian::read(littleval + + 1))); } TEST(Endian, ReadBitAligned) { @@ -36,35 +41,43 @@ TEST(Endian, ReadBitAligned) { unsigned char littleval[] = {0x3f, 0x00, 0x00, 0x00, 0xc0, 0xff, 0xff, 0xff}; unsigned char bigval[] = {0x00, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xc0}; EXPECT_EQ( - (endian::readAtBitAlignment(&littleval[0], 6)), + (endian::readAtBitAlignment( + &littleval[0], 6)), 0x0); - EXPECT_EQ((endian::readAtBitAlignment(&bigval[0], 6)), + EXPECT_EQ((endian::readAtBitAlignment( + &bigval[0], 6)), 0x0); // Test to make sure that signed right shift of 0xf0000000 is masked // properly. unsigned char littleval2[] = {0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00}; unsigned char bigval2[] = {0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; EXPECT_EQ( - (endian::readAtBitAlignment(&littleval2[0], 4)), + (endian::readAtBitAlignment( + &littleval2[0], 4)), 0x0f000000); - EXPECT_EQ((endian::readAtBitAlignment(&bigval2[0], 4)), + EXPECT_EQ((endian::readAtBitAlignment( + &bigval2[0], 4)), 0x0f000000); // Test to make sure left shift of start bit doesn't overflow. EXPECT_EQ( - (endian::readAtBitAlignment(&littleval2[0], 1)), + (endian::readAtBitAlignment( + &littleval2[0], 1)), 0x78000000); - EXPECT_EQ((endian::readAtBitAlignment(&bigval2[0], 1)), + EXPECT_EQ((endian::readAtBitAlignment( + &bigval2[0], 1)), 0x78000000); // Test to make sure 64-bit int doesn't overflow. unsigned char littleval3[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned char bigval3[] = {0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - EXPECT_EQ((endian::readAtBitAlignment( - &littleval3[0], 4)), - 0x0f00000000000000); EXPECT_EQ( - (endian::readAtBitAlignment(&bigval3[0], 4)), + (endian::readAtBitAlignment( + &littleval3[0], 4)), + 0x0f00000000000000); + EXPECT_EQ( + (endian::readAtBitAlignment( + &bigval3[0], 4)), 0x0f00000000000000); } @@ -72,8 +85,8 @@ TEST(Endian, WriteBitAligned) { // This test ensures that signed right shift of 0xffffaa is masked // properly. unsigned char bigval[8] = {0x00}; - endian::writeAtBitAlignment(bigval, (int)0xffffaaaa, - 4); + endian::writeAtBitAlignment( + bigval, (int)0xffffaaaa, 4); EXPECT_EQ(bigval[0], 0xff); EXPECT_EQ(bigval[1], 0xfa); EXPECT_EQ(bigval[2], 0xaa); @@ -84,8 +97,8 @@ TEST(Endian, WriteBitAligned) { EXPECT_EQ(bigval[7], 0x0f); unsigned char littleval[8] = {0x00}; - endian::writeAtBitAlignment(littleval, - (int)0xffffaaaa, 4); + endian::writeAtBitAlignment( + littleval, (int)0xffffaaaa, 4); EXPECT_EQ(littleval[0], 0xa0); EXPECT_EQ(littleval[1], 0xaa); EXPECT_EQ(littleval[2], 0xfa); @@ -98,8 +111,8 @@ TEST(Endian, WriteBitAligned) { // This test makes sure 1<<31 doesn't overflow. // Test to make sure left shift of start bit doesn't overflow. unsigned char bigval2[8] = {0x00}; - endian::writeAtBitAlignment(bigval2, (int)0xffffffff, - 1); + endian::writeAtBitAlignment( + bigval2, (int)0xffffffff, 1); EXPECT_EQ(bigval2[0], 0xff); EXPECT_EQ(bigval2[1], 0xff); EXPECT_EQ(bigval2[2], 0xff); @@ -110,8 +123,8 @@ TEST(Endian, WriteBitAligned) { EXPECT_EQ(bigval2[7], 0x01); unsigned char littleval2[8] = {0x00}; - endian::writeAtBitAlignment(littleval2, - (int)0xffffffff, 1); + endian::writeAtBitAlignment( + littleval2, (int)0xffffffff, 1); EXPECT_EQ(littleval2[0], 0xfe); EXPECT_EQ(littleval2[1], 0xff); EXPECT_EQ(littleval2[2], 0xff); @@ -123,7 +136,7 @@ TEST(Endian, WriteBitAligned) { // Test to make sure 64-bit int doesn't overflow. unsigned char bigval64[16] = {0x00}; - endian::writeAtBitAlignment( + endian::writeAtBitAlignment( bigval64, (int64_t)0xffffffffffffffff, 1); EXPECT_EQ(bigval64[0], 0xff); EXPECT_EQ(bigval64[1], 0xff); @@ -143,7 +156,7 @@ TEST(Endian, WriteBitAligned) { EXPECT_EQ(bigval64[15], 0x01); unsigned char littleval64[16] = {0x00}; - endian::writeAtBitAlignment( + endian::writeAtBitAlignment( littleval64, (int64_t)0xffffffffffffffff, 1); EXPECT_EQ(littleval64[0], 0xfe); EXPECT_EQ(littleval64[1], 0xff); @@ -165,23 +178,26 @@ TEST(Endian, WriteBitAligned) { TEST(Endian, Write) { unsigned char data[5]; - endian::write(data, -1362446643); + endian::write(data, -1362446643); EXPECT_EQ(data[0], 0xAE); EXPECT_EQ(data[1], 0xCA); EXPECT_EQ(data[2], 0xB6); EXPECT_EQ(data[3], 0xCD); - endian::write(data + 1, -1362446643); + endian::write(data + 1, + -1362446643); EXPECT_EQ(data[1], 0xAE); EXPECT_EQ(data[2], 0xCA); EXPECT_EQ(data[3], 0xB6); EXPECT_EQ(data[4], 0xCD); - endian::write(data, -1362446643); + endian::write(data, + -1362446643); EXPECT_EQ(data[0], 0xCD); EXPECT_EQ(data[1], 0xB6); EXPECT_EQ(data[2], 0xCA); EXPECT_EQ(data[3], 0xAE); - endian::write(data + 1, -1362446643); + endian::write(data + 1, + -1362446643); EXPECT_EQ(data[1], 0xCD); EXPECT_EQ(data[2], 0xB6); EXPECT_EQ(data[3], 0xCA);