[cfe-commits] r69987 - in /cfe/trunk: include/clang/Frontend/PCHBitCodes.h include/clang/Lex/HeaderSearch.h lib/Frontend/PCHReader.cpp lib/Frontend/PCHWriter.cpp lib/Lex/HeaderSearch.cpp lib/Lex/PPLexerChange.cpp test/PCH/objc_import.h test/PCH/objc_import.m

Douglas Gregor dgregor at apple.com
Fri Apr 24 13:05:43 PDT 2009


On Apr 24, 2009, at 1:03 PM, Steve Naroff wrote:

> Author: snaroff
> Date: Fri Apr 24 15:03:17 2009
> New Revision: 69987
>
> URL: http://llvm.org/viewvc/llvm-project?rev=69987&view=rev
> Log:
> Add PCH support for #import.

Cool.

> Added:
>    cfe/trunk/test/PCH/objc_import.h
>    cfe/trunk/test/PCH/objc_import.m
> Modified:
>    cfe/trunk/include/clang/Frontend/PCHBitCodes.h
>    cfe/trunk/include/clang/Lex/HeaderSearch.h
>    cfe/trunk/lib/Frontend/PCHReader.cpp
>    cfe/trunk/lib/Frontend/PCHWriter.cpp
>    cfe/trunk/lib/Lex/HeaderSearch.cpp
>    cfe/trunk/lib/Lex/PPLexerChange.cpp
>
> Modified: cfe/trunk/include/clang/Frontend/PCHBitCodes.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/PCHBitCodes.h?rev=69987&r1=69986&r2=69987&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- cfe/trunk/include/clang/Frontend/PCHBitCodes.h (original)
> +++ cfe/trunk/include/clang/Frontend/PCHBitCodes.h Fri Apr 24  
> 15:03:17 2009
> @@ -211,7 +211,11 @@
>
>       /// \brief The value of the next __COUNTER__ to dispense.
>       /// [PP_COUNTER_VALUE, Val]
> -      PP_COUNTER_VALUE = 4
> +      PP_COUNTER_VALUE = 4,
> +
> +      /// \brief Describes one header file info [isImport, DirInfo,  
> NumIncludes]
> +      /// ControlloingMacro is optional.
> +      PP_HEADER_FILE_INFO = 5
>     };
>
>     /// \defgroup PCHAST Precompiled header AST constants
>
> Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=69987&r1=69986&r2=69987&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
> +++ cfe/trunk/include/clang/Lex/HeaderSearch.h Fri Apr 24 15:03:17  
> 2009
> @@ -23,7 +23,31 @@
> class FileManager;
> class IdentifierInfo;
>
> +/// HeaderFileInfo - The preprocessor keeps track of this  
> information for each
> +/// file that is #included.
> +struct HeaderFileInfo {
> +  /// isImport - True if this is a #import'd or #pragma once file.
> +  bool isImport : 1;
> +
> +  /// DirInfo - Keep track of whether this is a system header, and  
> if so,
> +  /// whether it is C++ clean or not.  This can be set by the  
> include paths or
> +  /// by #pragma gcc system_header.  This is an instance of
> +  /// SrcMgr::CharacteristicKind.
> +  unsigned DirInfo : 2;
> +
> +  /// NumIncludes - This is the number of times the file has been  
> included
> +  /// already.
> +  unsigned short NumIncludes;
> +
> +  /// ControllingMacro - If this file has a #ifndef XXX (or  
> equivalent) guard
> +  /// that protects the entire contents of the file, this is the  
> identifier
> +  /// for the macro that controls whether or not it has any effect.
> +  const IdentifierInfo *ControllingMacro;
>
> +  HeaderFileInfo() : isImport(false), DirInfo(SrcMgr::C_User),
> +    NumIncludes(0), ControllingMacro(0) {}
> +};
> +
> /// HeaderSearch - This class encapsulates the information needed to  
> find the
> /// file referenced by a #include or #include_next, (sub-)framework  
> lookup, etc.
> class HeaderSearch {
> @@ -39,35 +63,10 @@
>   unsigned SystemDirIdx;
>   bool NoCurDirSearch;
>
> -  /// PreFileInfo - The preprocessor keeps track of this  
> information for each
> -  /// file that is #included.
> -  struct PerFileInfo {
> -    /// isImport - True if this is a #import'd or #pragma once file.
> -    bool isImport : 1;
> -
> -    /// DirInfo - Keep track of whether this is a system header,  
> and if so,
> -    /// whether it is C++ clean or not.  This can be set by the  
> include paths or
> -    /// by #pragma gcc system_header.  This is an instance of
> -    /// SrcMgr::CharacteristicKind.
> -    unsigned DirInfo : 2;
> -
> -    /// NumIncludes - This is the number of times the file has been  
> included
> -    /// already.
> -    unsigned short NumIncludes;
> -
> -    /// ControllingMacro - If this file has a #ifndef XXX (or  
> equivalent) guard
> -    /// that protects the entire contents of the file, this is the  
> identifier
> -    /// for the macro that controls whether or not it has any effect.
> -    const IdentifierInfo *ControllingMacro;
> -
> -    PerFileInfo() : isImport(false), DirInfo(SrcMgr::C_User),
> -      NumIncludes(0), ControllingMacro(0) {}
> -  };
> -
>   /// FileInfo - This contains all of the preprocessor-specific data  
> about files
>   /// that are included.  The vector is indexed by the FileEntry's  
> UID.
>   ///
> -  std::vector<PerFileInfo> FileInfo;
> +  std::vector<HeaderFileInfo> FileInfo;
>
>   /// LookupFileCache - This is keeps track of each lookup performed  
> by
>   /// LookupFile.  The first part of the value is the starting index  
> in
> @@ -190,13 +189,20 @@
>   const HeaderMap *CreateHeaderMap(const FileEntry *FE);
>
>   void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
> +
> +  typedef std::vector<HeaderFileInfo>::iterator header_file_iterator;
> +  header_file_iterator header_file_begin() { return FileInfo.begin 
> (); }
> +  header_file_iterator header_file_end() { return FileInfo.end(); }
> +
> +  // Used by PCHReader.
> +  void setHeaderFileInfoForUID(HeaderFileInfo HFI, unsigned UID);
>
>   void PrintStats();
> private:
>
> -  /// getFileInfo - Return the PerFileInfo structure for the  
> specified
> +  /// getFileInfo - Return the HeaderFileInfo structure for the  
> specified
>   /// FileEntry.
> -  PerFileInfo &getFileInfo(const FileEntry *FE);
> +  HeaderFileInfo &getFileInfo(const FileEntry *FE);
> };
>
> }  // end namespace clang
>
> Modified: cfe/trunk/lib/Frontend/PCHReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PCHReader.cpp?rev=69987&r1=69986&r2=69987&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- cfe/trunk/lib/Frontend/PCHReader.cpp (original)
> +++ cfe/trunk/lib/Frontend/PCHReader.cpp Fri Apr 24 15:03:17 2009
> @@ -23,6 +23,7 @@
> #include "clang/AST/Type.h"
> #include "clang/Lex/MacroInfo.h"
> #include "clang/Lex/Preprocessor.h"
> +#include "clang/Lex/HeaderSearch.h"
> #include "clang/Basic/OnDiskHashTable.h"
> #include "clang/Basic/SourceManager.h"
> #include "clang/Basic/SourceManagerInternals.h"
> @@ -1444,6 +1445,7 @@
>   RecordData Record;
>   llvm::SmallVector<IdentifierInfo*, 16> MacroArgs;
>   MacroInfo *Macro = 0;
> +
>   while (true) {
>     unsigned Code = Stream.ReadCode();
>     switch (Code) {
> @@ -1536,7 +1538,9 @@
>       Macro->AddTokenToBody(Tok);
>       break;
>     }
> -    }
> +    case pch::PP_HEADER_FILE_INFO:
> +      break; // Already processed by ReadPreprocessorBlock().
> +  }
>   }
> }
>
> @@ -1545,6 +1549,7 @@
>     return Error("Malformed preprocessor block record");
>
>   RecordData Record;
> +  unsigned NumHeaderInfos = 0;
>   while (true) {
>     unsigned Code = Stream.ReadCode();
>     switch (Code) {
> @@ -1581,8 +1586,16 @@
>     case pch::PP_MACRO_OBJECT_LIKE:
>     case pch::PP_MACRO_FUNCTION_LIKE:
>     case pch::PP_TOKEN:
> -      // Once we've hit a macro definition or a token, we're done.
> -      return false;
> +      break;
> +    case pch::PP_HEADER_FILE_INFO: {
> +      HeaderFileInfo HFI;
> +      HFI.isImport = Record[0];
> +      HFI.DirInfo = Record[1];
> +      HFI.NumIncludes = Record[2];
> +      HFI.ControllingMacro = DecodeIdentifierInfo(Record[3]);

If there are a lot of these controlling macros, we're going to be  
deserializing a bunch of macro definitions when we bring in the header  
information. Did you look to see how this affects the macro statistics  
on, e.g., Carbon.h PCH (using -print-stats)?

	- Doug



More information about the cfe-commits mailing list