r205048 - Revert "OnDiskHashTable: Use Endian.h to read little endian ostreams"

Justin Bogner mail at justinbogner.com
Fri Mar 28 13:32:17 PDT 2014


Author: bogner
Date: Fri Mar 28 15:32:17 2014
New Revision: 205048

URL: http://llvm.org/viewvc/llvm-project?rev=205048&view=rev
Log:
Revert "OnDiskHashTable: Use Endian.h to read little endian ostreams"

This reverts commit r205045.

Modified:
    cfe/trunk/include/clang/Basic/OnDiskHashTable.h
    cfe/trunk/lib/Lex/PTHLexer.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp

Modified: cfe/trunk/include/clang/Basic/OnDiskHashTable.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/OnDiskHashTable.h?rev=205048&r1=205047&r2=205048&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/OnDiskHashTable.h (original)
+++ cfe/trunk/include/clang/Basic/OnDiskHashTable.h Fri Mar 28 15:32:17 2014
@@ -70,6 +70,45 @@ inline void Pad(raw_ostream& Out, unsign
     Emit8(Out, 0);
 }
 
+inline uint16_t ReadUnalignedLE16(const unsigned char *&Data) {
+  uint16_t V = ((uint16_t)Data[0]) |
+               ((uint16_t)Data[1] <<  8);
+  Data += 2;
+  return V;
+}
+
+inline uint32_t ReadUnalignedLE32(const unsigned char *&Data) {
+  uint32_t V = ((uint32_t)Data[0])  |
+               ((uint32_t)Data[1] << 8)  |
+               ((uint32_t)Data[2] << 16) |
+               ((uint32_t)Data[3] << 24);
+  Data += 4;
+  return V;
+}
+
+inline uint64_t ReadUnalignedLE64(const unsigned char *&Data) {
+  uint64_t V = ((uint64_t)Data[0])  |
+    ((uint64_t)Data[1] << 8)  |
+    ((uint64_t)Data[2] << 16) |
+    ((uint64_t)Data[3] << 24) |
+    ((uint64_t)Data[4] << 32) |
+    ((uint64_t)Data[5] << 40) |
+    ((uint64_t)Data[6] << 48) |
+    ((uint64_t)Data[7] << 56);
+  Data += 8;
+  return V;
+}
+
+inline uint32_t ReadLE32(const unsigned char *&Data) {
+  // Hosts that directly support little-endian 32-bit loads can just
+  // use them.  Big-endian hosts need a bswap.
+  uint32_t V = *((const uint32_t*)Data);
+  if (llvm::sys::IsBigEndianHost)
+    V = llvm::ByteSwap_32(V);
+  Data += 4;
+  return V;
+}
+
 } // end namespace io
 
 template<typename Info>
@@ -247,7 +286,7 @@ public:
     if (!InfoPtr)
       InfoPtr = &InfoObj;
 
-    using namespace llvm::support;
+    using namespace io;
     const internal_key_type& iKey = InfoObj.GetInternalKey(eKey);
     unsigned key_hash = InfoObj.ComputeHash(iKey);
 
@@ -255,17 +294,17 @@ public:
     unsigned idx = key_hash & (NumBuckets - 1);
     const unsigned char* Bucket = Buckets + sizeof(uint32_t)*idx;
 
-    unsigned offset = endian::readNext<uint32_t, little, aligned>(Bucket);
+    unsigned offset = ReadLE32(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<uint16_t, little, unaligned>(Items);
+    unsigned len = ReadUnalignedLE16(Items);
 
     for (unsigned i = 0; i < len; ++i) {
       // Read the hash.
-      uint32_t item_hash = endian::readNext<uint32_t, little, unaligned>(Items);
+      uint32_t item_hash = ReadUnalignedLE32(Items);
 
       // Determine the length of the key and the data.
       const std::pair<unsigned, unsigned>& L = Info::ReadKeyDataLength(Items);
@@ -320,12 +359,10 @@ public:
     }
 
     key_iterator& operator++() {  // Preincrement
-      using namespace llvm::support;
       if (!NumItemsInBucketLeft) {
         // 'Items' starts with a 16-bit unsigned integer representing the
         // number of items in this bucket.
-        NumItemsInBucketLeft =
-            endian::readNext<uint16_t, little, unaligned>(Ptr);
+        NumItemsInBucketLeft = io::ReadUnalignedLE16(Ptr);
       }
       Ptr += 4; // Skip the hash.
       // Determine the length of the key and the data.
@@ -386,12 +423,10 @@ public:
     }
 
     data_iterator& operator++() {  // Preincrement
-      using namespace llvm::support;
       if (!NumItemsInBucketLeft) {
         // 'Items' starts with a 16-bit unsigned integer representing the
         // number of items in this bucket.
-        NumItemsInBucketLeft =
-            endian::readNext<uint16_t, little, unaligned>(Ptr);
+        NumItemsInBucketLeft = io::ReadUnalignedLE16(Ptr);
       }
       Ptr += 4; // Skip the hash.
       // Determine the length of the key and the data.
@@ -433,13 +468,13 @@ public:
   static OnDiskChainedHashTable* Create(const unsigned char* buckets,
                                         const unsigned char* const base,
                                         const Info &InfoObj = Info()) {
-    using namespace llvm::support;
+    using namespace io;
     assert(buckets > base);
     assert((reinterpret_cast<uintptr_t>(buckets) & 0x3) == 0 &&
            "buckets should be 4-byte aligned.");
 
-    unsigned numBuckets = endian::readNext<uint32_t, little, aligned>(buckets);
-    unsigned numEntries = endian::readNext<uint32_t, little, aligned>(buckets);
+    unsigned numBuckets = ReadLE32(buckets);
+    unsigned numEntries = ReadLE32(buckets);
     return new OnDiskChainedHashTable<Info>(numBuckets, numEntries, buckets,
                                             base, InfoObj);
   }

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=205048&r1=205047&r2=205048&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Fri Mar 28 15:32:17 2014
@@ -47,17 +47,14 @@ bool PTHLexer::Lex(Token& Tok) {
   //===--------------------------------------==//
   // Read the raw token data.
   //===--------------------------------------==//
-  using namespace llvm::support;
 
   // Shadow CurPtr into an automatic variable.
   const unsigned char *CurPtrShadow = CurPtr;
 
   // Read in the data for the token.
-  unsigned Word0 = endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
-  uint32_t IdentifierID =
-      endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
-  uint32_t FileOffset =
-      endian::readNext<uint32_t, little, aligned>(CurPtrShadow);
+  unsigned Word0 = ReadLE32(CurPtrShadow);
+  uint32_t IdentifierID = ReadLE32(CurPtrShadow);
+  uint32_t FileOffset = ReadLE32(CurPtrShadow);
 
   tok::TokenKind TKind = (tok::TokenKind) (Word0 & 0xFF);
   Token::TokenFlags TFlags = (Token::TokenFlags) ((Word0 >> 8) & 0xFF);
@@ -187,7 +184,6 @@ void PTHLexer::DiscardToEndOfLine() {
 
 /// SkipBlock - Used by Preprocessor to skip the current conditional block.
 bool PTHLexer::SkipBlock() {
-  using namespace llvm::support;
   assert(CurPPCondPtr && "No cached PP conditional information.");
   assert(LastHashTokPtr && "No known '#' token.");
 
@@ -196,10 +192,10 @@ bool PTHLexer::SkipBlock() {
 
   do {
     // Read the token offset from the side-table.
-    uint32_t Offset = endian::readNext<uint32_t, little, aligned>(CurPPCondPtr);
+    uint32_t Offset = ReadLE32(CurPPCondPtr);
 
     // Read the target table index from the side-table.
-    TableIdx = endian::readNext<uint32_t, little, aligned>(CurPPCondPtr);
+    TableIdx = ReadLE32(CurPPCondPtr);
 
     // Compute the actual memory address of the '#' token data for this entry.
     HashEntryI = TokBuf + Offset;
@@ -216,13 +212,12 @@ bool PTHLexer::SkipBlock() {
         PPCond + TableIdx*(sizeof(uint32_t)*2);
       assert(NextPPCondPtr >= CurPPCondPtr);
       // Read where we should jump to.
-      const unsigned char *HashEntryJ =
-          TokBuf + endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
+      const unsigned char* HashEntryJ = TokBuf + ReadLE32(NextPPCondPtr);
 
       if (HashEntryJ <= LastHashTokPtr) {
         // Jump directly to the next entry in the side table.
         HashEntryI = HashEntryJ;
-        TableIdx = endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
+        TableIdx = ReadLE32(NextPPCondPtr);
         CurPPCondPtr = NextPPCondPtr;
       }
     }
@@ -237,9 +232,8 @@ bool PTHLexer::SkipBlock() {
   CurPPCondPtr = NextPPCondPtr;
 
   // Read where we should jump to.
-  HashEntryI =
-      TokBuf + endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
-  uint32_t NextIdx = endian::readNext<uint32_t, little, aligned>(NextPPCondPtr);
+  HashEntryI = TokBuf + ReadLE32(NextPPCondPtr);
+  uint32_t NextIdx = ReadLE32(NextPPCondPtr);
 
   // By construction NextIdx will be zero if this is a #endif.  This is useful
   // to know to obviate lexing another token.
@@ -288,10 +282,8 @@ SourceLocation PTHLexer::getSourceLocati
   // handling a #included file.  Just read the necessary data from the token
   // data buffer to construct the SourceLocation object.
   // NOTE: This is a virtual function; hence it is defined out-of-line.
-  using namespace llvm::support;
-
   const unsigned char *OffsetPtr = CurPtr + (DISK_TOKEN_SIZE - 4);
-  uint32_t Offset = endian::readNext<uint32_t, little, aligned>(OffsetPtr);
+  uint32_t Offset = ReadLE32(OffsetPtr);
   return FileStartLoc.getLocWithOffset(Offset);
 }
 
@@ -325,9 +317,7 @@ public:
 
   static std::pair<unsigned, unsigned>
   ReadKeyDataLength(const unsigned char*& d) {
-    using namespace llvm::support;
-    unsigned keyLen =
-        (unsigned)endian::readNext<uint16_t, little, unaligned>(d);
+    unsigned keyLen = (unsigned) ReadUnalignedLE16(d);
     unsigned dataLen = (unsigned) *(d++);
     return std::make_pair(keyLen, dataLen);
   }
@@ -354,9 +344,8 @@ public:
   static PTHFileData ReadData(const internal_key_type& k,
                               const unsigned char* d, unsigned) {
     assert(k.first == 0x1 && "Only file lookups can match!");
-    using namespace llvm::support;
-    uint32_t x = endian::readNext<uint32_t, little, unaligned>(d);
-    uint32_t y = endian::readNext<uint32_t, little, unaligned>(d);
+    uint32_t x = ::ReadUnalignedLE32(d);
+    uint32_t y = ::ReadUnalignedLE32(d);
     return PTHFileData(x, y);
   }
 };
@@ -387,10 +376,7 @@ public:
 
   static std::pair<unsigned, unsigned>
   ReadKeyDataLength(const unsigned char*& d) {
-    using namespace llvm::support;
-    return std::make_pair(
-        (unsigned)endian::readNext<uint16_t, little, unaligned>(d),
-        sizeof(uint32_t));
+    return std::make_pair((unsigned) ReadUnalignedLE16(d), sizeof(uint32_t));
   }
 
   static std::pair<const char*, unsigned>
@@ -401,8 +387,7 @@ public:
 
   static uint32_t ReadData(const internal_key_type& k, const unsigned char* d,
                            unsigned) {
-    using namespace llvm::support;
-    return endian::readNext<uint32_t, little, unaligned>(d);
+    return ::ReadUnalignedLE32(d);
   }
 };
 
@@ -448,8 +433,6 @@ PTHManager *PTHManager::Create(const std
     return 0;
   }
 
-  using namespace llvm::support;
-
   // Get the buffer ranges and check if there are at least three 32-bit
   // words at the end of the file.
   const unsigned char *BufBeg = (const unsigned char*)File->getBufferStart();
@@ -464,7 +447,7 @@ PTHManager *PTHManager::Create(const std
 
   // Read the PTH version.
   const unsigned char *p = BufBeg + (sizeof("cfe-pth"));
-  unsigned Version = endian::readNext<uint32_t, little, aligned>(p);
+  unsigned Version = ReadLE32(p);
 
   if (Version < PTHManager::Version) {
     InvalidPTH(Diags,
@@ -485,8 +468,7 @@ PTHManager *PTHManager::Create(const std
   // Construct the file lookup table.  This will be used for mapping from
   // FileEntry*'s to cached tokens.
   const unsigned char* FileTableOffset = PrologueOffset + sizeof(uint32_t)*2;
-  const unsigned char *FileTable =
-      BufBeg + endian::readNext<uint32_t, little, aligned>(FileTableOffset);
+  const unsigned char* FileTable = BufBeg + ReadLE32(FileTableOffset);
 
   if (!(FileTable > BufBeg && FileTable < BufEnd)) {
     Diags.Report(diag::err_invalid_pth_file) << file;
@@ -503,8 +485,7 @@ PTHManager *PTHManager::Create(const std
   // Get the location of the table mapping from persistent ids to the
   // data needed to reconstruct identifiers.
   const unsigned char* IDTableOffset = PrologueOffset + sizeof(uint32_t)*0;
-  const unsigned char *IData =
-      BufBeg + endian::readNext<uint32_t, little, aligned>(IDTableOffset);
+  const unsigned char* IData = BufBeg + ReadLE32(IDTableOffset);
 
   if (!(IData >= BufBeg && IData < BufEnd)) {
     Diags.Report(diag::err_invalid_pth_file) << file;
@@ -514,8 +495,7 @@ PTHManager *PTHManager::Create(const std
   // Get the location of the hashtable mapping between strings and
   // persistent IDs.
   const unsigned char* StringIdTableOffset = PrologueOffset + sizeof(uint32_t)*1;
-  const unsigned char *StringIdTable =
-      BufBeg + endian::readNext<uint32_t, little, aligned>(StringIdTableOffset);
+  const unsigned char* StringIdTable = BufBeg + ReadLE32(StringIdTableOffset);
   if (!(StringIdTable >= BufBeg && StringIdTable < BufEnd)) {
     Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
@@ -526,15 +506,14 @@ PTHManager *PTHManager::Create(const std
 
   // Get the location of the spelling cache.
   const unsigned char* spellingBaseOffset = PrologueOffset + sizeof(uint32_t)*3;
-  const unsigned char *spellingBase =
-      BufBeg + endian::readNext<uint32_t, little, aligned>(spellingBaseOffset);
+  const unsigned char* spellingBase = BufBeg + ReadLE32(spellingBaseOffset);
   if (!(spellingBase >= BufBeg && spellingBase < BufEnd)) {
     Diags.Report(diag::err_invalid_pth_file) << file;
     return 0;
   }
 
   // Get the number of IdentifierInfos and pre-allocate the identifier cache.
-  uint32_t NumIds = endian::readNext<uint32_t, little, aligned>(IData);
+  uint32_t NumIds = ReadLE32(IData);
 
   // Pre-allocate the persistent ID -> IdentifierInfo* cache.  We use calloc()
   // so that we in the best case only zero out memory once when the OS returns
@@ -551,8 +530,7 @@ PTHManager *PTHManager::Create(const std
 
   // Compute the address of the original source file.
   const unsigned char* originalSourceBase = PrologueOffset + sizeof(uint32_t)*4;
-  unsigned len =
-      endian::readNext<uint16_t, little, unaligned>(originalSourceBase);
+  unsigned len = ReadUnalignedLE16(originalSourceBase);
   if (!len) originalSourceBase = 0;
 
   // Create the new PTHManager.
@@ -562,12 +540,10 @@ PTHManager *PTHManager::Create(const std
 }
 
 IdentifierInfo* PTHManager::LazilyCreateIdentifierInfo(unsigned PersistentID) {
-  using namespace llvm::support;
   // Look in the PTH file for the string data for the IdentifierInfo object.
   const unsigned char* TableEntry = IdDataTable + sizeof(uint32_t)*PersistentID;
-  const unsigned char *IDData =
-      (const unsigned char *)Buf->getBufferStart() +
-      endian::readNext<uint32_t, little, aligned>(TableEntry);
+  const unsigned char* IDData =
+    (const unsigned char*)Buf->getBufferStart() + ReadLE32(TableEntry);
   assert(IDData < (const unsigned char*)Buf->getBufferEnd());
 
   // Allocate the object.
@@ -603,8 +579,6 @@ PTHLexer *PTHManager::CreateLexer(FileID
   if (!FE)
     return 0;
 
-  using namespace llvm::support;
-
   // Lookup the FileEntry object in our file lookup data structure.  It will
   // return a variant that indicates whether or not there is an offset within
   // the PTH file that contains cached tokens.
@@ -622,7 +596,7 @@ PTHLexer *PTHManager::CreateLexer(FileID
 
   // Get the location of pp-conditional table.
   const unsigned char* ppcond = BufStart + FileData.getPPCondOffset();
-  uint32_t Len = endian::readNext<uint32_t, little, aligned>(ppcond);
+  uint32_t Len = ReadLE32(ppcond);
   if (Len == 0) ppcond = 0;
 
   assert(PP && "No preprocessor set yet!");
@@ -676,13 +650,11 @@ public:
         d += 4 * 2; // Skip the first 2 words.
       }
 
-      using namespace llvm::support;
-
-      uint64_t File = endian::readNext<uint64_t, little, unaligned>(d);
-      uint64_t Device = endian::readNext<uint64_t, little, unaligned>(d);
+      uint64_t File = ReadUnalignedLE64(d);
+      uint64_t Device = ReadUnalignedLE64(d);
       llvm::sys::fs::UniqueID UniqueID(File, Device);
-      time_t ModTime = endian::readNext<uint64_t, little, unaligned>(d);
-      uint64_t Size = endian::readNext<uint64_t, little, unaligned>(d);
+      time_t ModTime = ReadUnalignedLE64(d);
+      uint64_t Size = ReadUnalignedLE64(d);
       return data_type(Size, ModTime, UniqueID, IsDirectory);
     }
 

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=205048&r1=205047&r2=205048&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Mar 28 15:32:17 2014
@@ -470,19 +470,19 @@ unsigned ASTSelectorLookupTrait::Compute
 
 std::pair<unsigned, unsigned>
 ASTSelectorLookupTrait::ReadKeyDataLength(const unsigned char*& d) {
-  using namespace llvm::support;
-  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
-  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
+  using namespace clang::io;
+  unsigned KeyLen = ReadUnalignedLE16(d);
+  unsigned DataLen = ReadUnalignedLE16(d);
   return std::make_pair(KeyLen, DataLen);
 }
 
 ASTSelectorLookupTrait::internal_key_type 
 ASTSelectorLookupTrait::ReadKey(const unsigned char* d, unsigned) {
-  using namespace llvm::support;
+  using namespace clang::io;
   SelectorTable &SelTable = Reader.getContext().Selectors;
-  unsigned N = endian::readNext<uint16_t, little, unaligned>(d);
-  IdentifierInfo *FirstII = Reader.getLocalIdentifier(
-      F, endian::readNext<uint32_t, little, unaligned>(d));
+  unsigned N = ReadUnalignedLE16(d);
+  IdentifierInfo *FirstII
+    = Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
   if (N == 0)
     return SelTable.getNullarySelector(FirstII);
   else if (N == 1)
@@ -491,8 +491,7 @@ ASTSelectorLookupTrait::ReadKey(const un
   SmallVector<IdentifierInfo *, 16> Args;
   Args.push_back(FirstII);
   for (unsigned I = 1; I != N; ++I)
-    Args.push_back(Reader.getLocalIdentifier(
-        F, endian::readNext<uint32_t, little, unaligned>(d)));
+    Args.push_back(Reader.getLocalIdentifier(F, ReadUnalignedLE32(d)));
 
   return SelTable.getSelector(N, Args.data());
 }
@@ -500,16 +499,13 @@ ASTSelectorLookupTrait::ReadKey(const un
 ASTSelectorLookupTrait::data_type 
 ASTSelectorLookupTrait::ReadData(Selector, const unsigned char* d, 
                                  unsigned DataLen) {
-  using namespace llvm::support;
+  using namespace clang::io;
 
   data_type Result;
 
-  Result.ID = Reader.getGlobalSelectorID(
-      F, endian::readNext<uint32_t, little, unaligned>(d));
-  unsigned NumInstanceMethodsAndBits =
-      endian::readNext<uint16_t, little, unaligned>(d);
-  unsigned NumFactoryMethodsAndBits =
-      endian::readNext<uint16_t, little, unaligned>(d);
+  Result.ID = Reader.getGlobalSelectorID(F, ReadUnalignedLE32(d));
+  unsigned NumInstanceMethodsAndBits = ReadUnalignedLE16(d);
+  unsigned NumFactoryMethodsAndBits = ReadUnalignedLE16(d);
   Result.InstanceBits = NumInstanceMethodsAndBits & 0x3;
   Result.FactoryBits = NumFactoryMethodsAndBits & 0x3;
   unsigned NumInstanceMethods = NumInstanceMethodsAndBits >> 2;
@@ -517,15 +513,15 @@ ASTSelectorLookupTrait::ReadData(Selecto
 
   // Load instance methods
   for (unsigned I = 0; I != NumInstanceMethods; ++I) {
-    if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
-            F, endian::readNext<uint32_t, little, unaligned>(d)))
+    if (ObjCMethodDecl *Method
+          = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d)))
       Result.Instance.push_back(Method);
   }
 
   // Load factory methods
   for (unsigned I = 0; I != NumFactoryMethods; ++I) {
-    if (ObjCMethodDecl *Method = Reader.GetLocalDeclAs<ObjCMethodDecl>(
-            F, endian::readNext<uint32_t, little, unaligned>(d)))
+    if (ObjCMethodDecl *Method
+          = Reader.GetLocalDeclAs<ObjCMethodDecl>(F, ReadUnalignedLE32(d)))
       Result.Factory.push_back(Method);
   }
 
@@ -538,9 +534,9 @@ unsigned ASTIdentifierLookupTraitBase::C
 
 std::pair<unsigned, unsigned>
 ASTIdentifierLookupTraitBase::ReadKeyDataLength(const unsigned char*& d) {
-  using namespace llvm::support;
-  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
-  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
+  using namespace clang::io;
+  unsigned DataLen = ReadUnalignedLE16(d);
+  unsigned KeyLen = ReadUnalignedLE16(d);
   return std::make_pair(KeyLen, DataLen);
 }
 
@@ -563,8 +559,8 @@ static bool isInterestingIdentifier(Iden
 IdentifierInfo *ASTIdentifierLookupTrait::ReadData(const internal_key_type& k,
                                                    const unsigned char* d,
                                                    unsigned DataLen) {
-  using namespace llvm::support;
-  unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
+  using namespace clang::io;
+  unsigned RawID = ReadUnalignedLE32(d);
   bool IsInteresting = RawID & 0x01;
 
   // Wipe out the "is interesting" bit.
@@ -590,8 +586,8 @@ IdentifierInfo *ASTIdentifierLookupTrait
     return II;
   }
 
-  unsigned ObjCOrBuiltinID = endian::readNext<uint16_t, little, unaligned>(d);
-  unsigned Bits = endian::readNext<uint16_t, little, unaligned>(d);
+  unsigned ObjCOrBuiltinID = ReadUnalignedLE16(d);
+  unsigned Bits = ReadUnalignedLE16(d);
   bool CPlusPlusOperatorKeyword = Bits & 0x01;
   Bits >>= 1;
   bool HasRevertedTokenIDToIdentifier = Bits & 0x01;
@@ -640,13 +636,11 @@ IdentifierInfo *ASTIdentifierLookupTrait
   // If this identifier is a macro, deserialize the macro
   // definition.
   if (hadMacroDefinition) {
-    uint32_t MacroDirectivesOffset =
-        endian::readNext<uint32_t, little, unaligned>(d);
+    uint32_t MacroDirectivesOffset = ReadUnalignedLE32(d);
     DataLen -= 4;
     SmallVector<uint32_t, 8> LocalMacroIDs;
     if (hasSubmoduleMacros) {
-      while (uint32_t LocalMacroID =
-                 endian::readNext<uint32_t, little, unaligned>(d)) {
+      while (uint32_t LocalMacroID = ReadUnalignedLE32(d)) {
         DataLen -= 4;
         LocalMacroIDs.push_back(LocalMacroID);
       }
@@ -694,8 +688,7 @@ IdentifierInfo *ASTIdentifierLookupTrait
   if (DataLen > 0) {
     SmallVector<uint32_t, 4> DeclIDs;
     for (; DataLen > 0; DataLen -= 4)
-      DeclIDs.push_back(Reader.getGlobalDeclID(
-          F, endian::readNext<uint32_t, little, unaligned>(d)));
+      DeclIDs.push_back(Reader.getGlobalDeclID(F, ReadUnalignedLE32(d)));
     Reader.SetGloballyVisibleDecls(II, DeclIDs);
   }
 
@@ -763,37 +756,34 @@ ASTDeclContextNameLookupTrait::GetIntern
 
 std::pair<unsigned, unsigned>
 ASTDeclContextNameLookupTrait::ReadKeyDataLength(const unsigned char*& d) {
-  using namespace llvm::support;
-  unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
-  unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
+  using namespace clang::io;
+  unsigned KeyLen = ReadUnalignedLE16(d);
+  unsigned DataLen = ReadUnalignedLE16(d);
   return std::make_pair(KeyLen, DataLen);
 }
 
 ASTDeclContextNameLookupTrait::internal_key_type 
 ASTDeclContextNameLookupTrait::ReadKey(const unsigned char* d, unsigned) {
-  using namespace llvm::support;
+  using namespace clang::io;
 
   DeclNameKey Key;
   Key.Kind = (DeclarationName::NameKind)*d++;
   switch (Key.Kind) {
   case DeclarationName::Identifier:
-    Key.Data = (uint64_t)Reader.getLocalIdentifier(
-        F, endian::readNext<uint32_t, little, unaligned>(d));
+    Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
     break;
   case DeclarationName::ObjCZeroArgSelector:
   case DeclarationName::ObjCOneArgSelector:
   case DeclarationName::ObjCMultiArgSelector:
     Key.Data =
-        (uint64_t)Reader.getLocalSelector(
-                             F, endian::readNext<uint32_t, little, unaligned>(
-                                    d)).getAsOpaquePtr();
+       (uint64_t)Reader.getLocalSelector(F, ReadUnalignedLE32(d))
+                   .getAsOpaquePtr();
     break;
   case DeclarationName::CXXOperatorName:
     Key.Data = *d++; // OverloadedOperatorKind
     break;
   case DeclarationName::CXXLiteralOperatorName:
-    Key.Data = (uint64_t)Reader.getLocalIdentifier(
-        F, endian::readNext<uint32_t, little, unaligned>(d));
+    Key.Data = (uint64_t)Reader.getLocalIdentifier(F, ReadUnalignedLE32(d));
     break;
   case DeclarationName::CXXConstructorName:
   case DeclarationName::CXXDestructorName:
@@ -810,8 +800,8 @@ ASTDeclContextNameLookupTrait::data_type
 ASTDeclContextNameLookupTrait::ReadData(internal_key_type, 
                                         const unsigned char* d,
                                         unsigned DataLen) {
-  using namespace llvm::support;
-  unsigned NumDecls = endian::readNext<uint16_t, little, unaligned>(d);
+  using namespace clang::io;
+  unsigned NumDecls = ReadUnalignedLE16(d);
   LE32DeclID *Start = reinterpret_cast<LE32DeclID *>(
                         const_cast<unsigned char *>(d));
   return std::make_pair(Start, Start + NumDecls);
@@ -1364,18 +1354,16 @@ bool HeaderFileInfoTrait::EqualKey(inter
     
 std::pair<unsigned, unsigned>
 HeaderFileInfoTrait::ReadKeyDataLength(const unsigned char*& d) {
-  using namespace llvm::support;
-  unsigned KeyLen = (unsigned) endian::readNext<uint16_t, little, unaligned>(d);
+  unsigned KeyLen = (unsigned) clang::io::ReadUnalignedLE16(d);
   unsigned DataLen = (unsigned) *d++;
   return std::make_pair(KeyLen, DataLen);
 }
 
 HeaderFileInfoTrait::internal_key_type
 HeaderFileInfoTrait::ReadKey(const unsigned char *d, unsigned) {
-  using namespace llvm::support;
   internal_key_type ikey;
-  ikey.Size = off_t(endian::readNext<uint64_t, little, unaligned>(d));
-  ikey.ModTime = time_t(endian::readNext<uint64_t, little, unaligned>(d));
+  ikey.Size = off_t(clang::io::ReadUnalignedLE64(d));
+  ikey.ModTime = time_t(clang::io::ReadUnalignedLE64(d));
   ikey.Filename = (const char *)d;
   return ikey;
 }
@@ -1384,7 +1372,7 @@ HeaderFileInfoTrait::data_type
 HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d,
                               unsigned DataLen) {
   const unsigned char *End = d + DataLen;
-  using namespace llvm::support;
+  using namespace clang::io;
   HeaderFileInfo HFI;
   unsigned Flags = *d++;
   HFI.HeaderRole = static_cast<ModuleMap::ModuleHeaderRole>
@@ -1394,11 +1382,10 @@ HeaderFileInfoTrait::ReadData(internal_k
   HFI.DirInfo = (Flags >> 2) & 0x03;
   HFI.Resolved = (Flags >> 1) & 0x01;
   HFI.IndexHeaderMapHeader = Flags & 0x01;
-  HFI.NumIncludes = endian::readNext<uint16_t, little, unaligned>(d);
-  HFI.ControllingMacroID = Reader.getGlobalIdentifierID(
-      M, endian::readNext<uint32_t, little, unaligned>(d));
-  if (unsigned FrameworkOffset =
-          endian::readNext<uint32_t, little, unaligned>(d)) {
+  HFI.NumIncludes = ReadUnalignedLE16(d);
+  HFI.ControllingMacroID = Reader.getGlobalIdentifierID(M, 
+                                                        ReadUnalignedLE32(d));
+  if (unsigned FrameworkOffset = ReadUnalignedLE32(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);
@@ -1406,7 +1393,7 @@ HeaderFileInfoTrait::ReadData(internal_k
   }
   
   if (d != End) {
-    uint32_t LocalSMID = endian::readNext<uint32_t, little, unaligned>(d);
+    uint32_t LocalSMID = ReadUnalignedLE32(d);
     if (LocalSMID) {
       // This header is part of a module. Associate it with the module to enable
       // implicit module import.
@@ -2750,8 +2737,7 @@ bool ASTReader::ReadASTBlock(ModuleFile
       ContinuousRangeMap<uint32_t, int, 2>::Builder TypeRemap(F.TypeRemap);
 
       while(Data < DataEnd) {
-        using namespace llvm::support;
-        uint16_t Len = endian::readNext<uint16_t, little, unaligned>(Data);
+        uint16_t Len = io::ReadUnalignedLE16(Data);
         StringRef Name = StringRef((const char*)Data, Len);
         Data += Len;
         ModuleFile *OM = ModuleMgr.lookup(Name);
@@ -2760,23 +2746,15 @@ bool ASTReader::ReadASTBlock(ModuleFile
           return true;
         }
 
-        uint32_t SLocOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t IdentifierIDOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t MacroIDOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t PreprocessedEntityIDOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t SubmoduleIDOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t SelectorIDOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t DeclIDOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-        uint32_t TypeIndexOffset =
-            endian::readNext<uint32_t, little, unaligned>(Data);
-
+        uint32_t SLocOffset = io::ReadUnalignedLE32(Data);
+        uint32_t IdentifierIDOffset = io::ReadUnalignedLE32(Data);
+        uint32_t MacroIDOffset = io::ReadUnalignedLE32(Data);
+        uint32_t PreprocessedEntityIDOffset = io::ReadUnalignedLE32(Data);
+        uint32_t SubmoduleIDOffset = io::ReadUnalignedLE32(Data);
+        uint32_t SelectorIDOffset = io::ReadUnalignedLE32(Data);
+        uint32_t DeclIDOffset = io::ReadUnalignedLE32(Data);
+        uint32_t TypeIndexOffset = io::ReadUnalignedLE32(Data);
+        
         // Source location offset is mapped to OM->SLocEntryBaseOffset.
         SLocRemap.insert(std::make_pair(SLocOffset,
           static_cast<int>(OM->SLocEntryBaseOffset - SLocOffset)));

Modified: cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp?rev=205048&r1=205047&r2=205048&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp (original)
+++ cfe/trunk/lib/Serialization/GlobalModuleIndex.cpp Fri Mar 28 15:32:17 2014
@@ -82,9 +82,9 @@ public:
 
   static std::pair<unsigned, unsigned>
   ReadKeyDataLength(const unsigned char*& d) {
-    using namespace llvm::support;
-    unsigned KeyLen = endian::readNext<uint16_t, little, unaligned>(d);
-    unsigned DataLen = endian::readNext<uint16_t, little, unaligned>(d);
+    using namespace clang::io;
+    unsigned KeyLen = ReadUnalignedLE16(d);
+    unsigned DataLen = ReadUnalignedLE16(d);
     return std::make_pair(KeyLen, DataLen);
   }
 
@@ -101,11 +101,11 @@ public:
   static data_type ReadData(const internal_key_type& k,
                             const unsigned char* d,
                             unsigned DataLen) {
-    using namespace llvm::support;
+    using namespace clang::io;
 
     data_type Result;
     while (DataLen > 0) {
-      unsigned ID = endian::readNext<uint32_t, little, unaligned>(d);
+      unsigned ID = ReadUnalignedLE32(d);
       Result.push_back(ID);
       DataLen -= 4;
     }
@@ -459,8 +459,8 @@ namespace {
                        unsigned DataLen) {
       // The first bit indicates whether this identifier is interesting.
       // That's all we care about.
-      using namespace llvm::support;
-      unsigned RawID = endian::readNext<uint32_t, little, unaligned>(d);
+      using namespace clang::io;
+      unsigned RawID = ReadUnalignedLE32(d);
       bool IsInteresting = RawID & 0x01;
       return std::make_pair(k, IsInteresting);
     }





More information about the cfe-commits mailing list