[cfe-commits] r70240 - in /cfe/trunk: include/clang/Frontend/PCHBitCodes.h include/clang/Frontend/PCHReader.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp test/PCH/ext_vector.c test/PCH/ext_vector.h

Douglas Gregor dgregor at apple.com
Mon Apr 27 13:06:05 PDT 2009


Author: dgregor
Date: Mon Apr 27 15:06:05 2009
New Revision: 70240

URL: http://llvm.org/viewvc/llvm-project?rev=70240&view=rev
Log:
Add Sema::ExtVectorDecls and Sema::ObjCCategoryImpls to the PCH file. Since these vectors are very, very rarely used and, when used in headers, and even when used are relatively small, we load them eagerly.

Added:
    cfe/trunk/test/PCH/ext_vector.c
    cfe/trunk/test/PCH/ext_vector.h
Modified:
    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
    cfe/trunk/include/clang/Frontend/PCHReader.h
    cfe/trunk/lib/Frontend/PCHReader.cpp
    cfe/trunk/lib/Frontend/PCHWriter.cpp

Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=70240&r1=70239&r2=70240&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Mon Apr 27 15:06:05 2009
@@ -188,7 +188,14 @@
       SOURCE_LOCATION_PRELOADS = 16,
 
       /// \brief Record code for the stat() cache.
-      STAT_CACHE = 17
+      STAT_CACHE = 17,
+
+      /// \brief Record code for the set of ext_vector type names.
+      EXT_VECTOR_DECLS = 18,
+
+      /// \brief Record code for the set of Objective-C category
+      /// implementations.
+      OBJC_CATEGORY_IMPLEMENTATIONS = 19
     };
 
     /// \brief Record types used within a source manager block.

Modified: cfe/trunk/include/clang/Frontend/PCHReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHReader.h?rev=70240&r1=70239&r2=70240&view=diff

==============================================================================
--- cfe/trunk/include/clang/Frontend/PCHReader.h (original)
+++ cfe/trunk/include/clang/Frontend/PCHReader.h Mon Apr 27 15:06:05 2009
@@ -208,6 +208,14 @@
   /// the the PCH file.
   llvm::SmallVector<uint64_t, 16> LocallyScopedExternalDecls;
 
+  /// \brief The set of ext_vector type declarations stored in the the
+  /// PCH file.
+  llvm::SmallVector<uint64_t, 4> ExtVectorDecls;
+
+  /// \brief The set of Objective-C category definitions stored in the
+  /// the PCH file.
+  llvm::SmallVector<uint64_t, 4> ObjCCategoryImpls;
+
   /// \brief Mapping from switch-case IDs in the PCH file to
   /// switch-case statements.
   std::map<unsigned, SwitchCase *> SwitchCaseStmts;

Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=70240&r1=70239&r2=70240&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHReader.cpp Mon Apr 27 15:06:05 2009
@@ -1038,6 +1038,22 @@
                                    (const unsigned char *)BlobStart,
                                    NumStatHits, NumStatMisses));
       break;
+
+    case pch::EXT_VECTOR_DECLS:
+      if (!ExtVectorDecls.empty()) {
+        Error("Duplicate EXT_VECTOR_DECLS record in PCH file");
+        return Failure;
+      }
+      ExtVectorDecls.swap(Record);
+      break;
+
+    case pch::OBJC_CATEGORY_IMPLEMENTATIONS:
+      if (!ObjCCategoryImpls.empty()) {
+        Error("Duplicate OBJC_CATEGORY_IMPLEMENTATIONS record in PCH file");
+        return Failure;
+      }
+      ObjCCategoryImpls.swap(Record);
+      break;
     }
   }
   Error("Premature end of bitstream");
@@ -1703,6 +1719,19 @@
     NamedDecl *D = cast<NamedDecl>(GetDecl(LocallyScopedExternalDecls[I]));
     SemaObj->LocallyScopedExternalDecls[D->getDeclName()] = D;
   }
+
+  // If there were any ext_vector type declarations, deserialize them
+  // and add them to Sema's vector of such declarations.
+  for (unsigned I = 0, N = ExtVectorDecls.size(); I != N; ++I)
+    SemaObj->ExtVectorDecls.push_back(
+                               cast<TypedefDecl>(GetDecl(ExtVectorDecls[I])));
+
+  // If there were any Objective-C category implementations,
+  // deserialize them and add them to Sema's vector of such
+  // definitions.
+  for (unsigned I = 0, N = ObjCCategoryImpls.size(); I != N; ++I)
+    SemaObj->ObjCCategoryImpls.push_back(
+                cast<ObjCCategoryImplDecl>(GetDecl(ObjCCategoryImpls[I])));
 }
 
 IdentifierInfo* PCHReader::get(const char *NameStart, const char *NameEnd) {

Modified: cfe/trunk/lib/Frontend/PCHWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHWriter.cpp?rev=70240&r1=70239&r2=70240&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/PCHWriter.cpp (original)
+++ cfe/trunk/lib/Frontend/PCHWriter.cpp Mon Apr 27 15:06:05 2009
@@ -355,6 +355,8 @@
   RECORD(SOURCE_LOCATION_OFFSETS);
   RECORD(SOURCE_LOCATION_PRELOADS);
   RECORD(STAT_CACHE);
+  RECORD(EXT_VECTOR_DECLS);
+  RECORD(OBJC_CATEGORY_IMPLEMENTATIONS);
 
   // SourceManager Block.
   BLOCK(SOURCE_MANAGER_BLOCK);
@@ -1656,6 +1658,17 @@
        TD != TDEnd; ++TD)
     AddDeclRef(TD->second, LocallyScopedExternalDecls);
 
+  // Build a record containing all of the ext_vector declarations.
+  RecordData ExtVectorDecls;
+  for (unsigned I = 0, N = SemaRef.ExtVectorDecls.size(); I != N; ++I)
+    AddDeclRef(SemaRef.ExtVectorDecls[I], ExtVectorDecls);
+
+  // Build a record containing all of the Objective-C category
+  // implementations.
+  RecordData ObjCCategoryImpls;
+  for (unsigned I = 0, N = SemaRef.ObjCCategoryImpls.size(); I != N; ++I)
+    AddDeclRef(SemaRef.ObjCCategoryImpls[I], ObjCCategoryImpls);
+
   // Write the remaining PCH contents.
   RecordData Record;
   Stream.EnterSubblock(pch::PCH_BLOCK_ID, 4);
@@ -1727,6 +1740,14 @@
   if (!LocallyScopedExternalDecls.empty())
     Stream.EmitRecord(pch::LOCALLY_SCOPED_EXTERNAL_DECLS, 
                       LocallyScopedExternalDecls);
+
+  // Write the record containing ext_vector type names.
+  if (!ExtVectorDecls.empty())
+    Stream.EmitRecord(pch::EXT_VECTOR_DECLS, ExtVectorDecls);
+
+  // Write the record containing Objective-C category implementations.
+  if (!ObjCCategoryImpls.empty())
+    Stream.EmitRecord(pch::OBJC_CATEGORY_IMPLEMENTATIONS, ObjCCategoryImpls);
   
   // Some simple statistics
   Record.clear();

Added: cfe/trunk/test/PCH/ext_vector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/ext_vector.c?rev=70240&view=auto

==============================================================================
--- cfe/trunk/test/PCH/ext_vector.c (added)
+++ cfe/trunk/test/PCH/ext_vector.c Mon Apr 27 15:06:05 2009
@@ -0,0 +1,10 @@
+// Test this without pch.
+// RUN: clang-cc -include %S/ext_vector.h -fsyntax-only -verify %s &&
+
+// Test with pch.
+// RUN: clang-cc -emit-pch -o %t %S/ext_vector.h &&
+// RUN: clang-cc -include-pch %t -fsyntax-only -verify %s 
+
+int test(float4 f4) {
+  return f4.xy; // expected-error{{float2}}
+}

Added: cfe/trunk/test/PCH/ext_vector.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/ext_vector.h?rev=70240&view=auto

==============================================================================
--- cfe/trunk/test/PCH/ext_vector.h (added)
+++ cfe/trunk/test/PCH/ext_vector.h Mon Apr 27 15:06:05 2009
@@ -0,0 +1,4 @@
+// Header file for ext_vector.c PCH test
+
+typedef __attribute__((ext_vector_type(2))) float float2;
+typedef __attribute__((ext_vector_type(4))) float float4;





More information about the cfe-commits mailing list