[cfe-commits] r62193 - in /cfe/trunk: include/clang/Lex/Preprocessor.h lib/Lex/PTHLexer.cpp lib/Lex/Preprocessor.cpp lib/Sema/SemaExpr.cpp

Ted Kremenek kremenek at apple.com
Tue Jan 13 15:19:12 PST 2009


Author: kremenek
Date: Tue Jan 13 17:19:12 2009
New Revision: 62193

URL: http://llvm.org/viewvc/llvm-project?rev=62193&view=rev
Log:
PTH:
- Use canonical FileID when using getSpelling() caching.  This
  addresses some cache misses we were seeing with -fsyntax-only on
  Cocoa.h
- Added Preprocessor::getPhysicalCharacterAt() utility method for
  clients to grab the first character at a specified sourcelocation.
  This uses the PTH spelling cache.
- Modified Sema::ActOnNumericConstant() to use
  Preprocessor::getPhysicalCharacterAt() instead of
  SourceManager::getCharacterData() (to get PTH hits).

These changes cause -fsyntax-only to not page in any sources from
Cocoa.h.  We see a speedup of 27%.

Modified:
    cfe/trunk/include/clang/Lex/Preprocessor.h
    cfe/trunk/lib/Lex/PTHLexer.cpp
    cfe/trunk/lib/Lex/Preprocessor.cpp
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/include/clang/Lex/Preprocessor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/Preprocessor.h?rev=62193&r1=62192&r2=62193&view=diff

==============================================================================
--- cfe/trunk/include/clang/Lex/Preprocessor.h (original)
+++ cfe/trunk/include/clang/Lex/Preprocessor.h Tue Jan 13 17:19:12 2009
@@ -449,6 +449,20 @@
   /// if an internal buffer is returned.
   unsigned getSpelling(const Token &Tok, const char *&Buffer) const;
   
+  /// getPhysicalCharacterAt - Return a pointer to the start of the specified
+  ///  location in the appropriate MemoryBuffer.
+  char getPhysicalCharacterAt(SourceLocation SL) const {
+    if (PTH) {
+      SL = SourceMgr.getPhysicalLoc(SL);
+      unsigned fid = SourceMgr.getCanonicalFileID(SL);
+      unsigned fpos = SourceMgr.getFullFilePos(SL);      
+      const char* data;
+      if (PTH->getSpelling(fid, fpos, data))
+        return *data;
+    }
+
+    return *SourceMgr.getCharacterData(SL);
+  }
   
   /// CreateString - Plop the specified string into a scratch buffer and return
   /// a location for it.  If specified, the source location provides a source

Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=62193&r1=62192&r2=62193&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Tue Jan 13 17:19:12 2009
@@ -423,7 +423,7 @@
 unsigned PTHLexer::getSpelling(SourceLocation sloc, const char *&Buffer) {
   SourceManager& SM = PP->getSourceManager();
   sloc = SM.getPhysicalLoc(sloc);
-  unsigned fid = sloc.getFileID();
+  unsigned fid = SM.getCanonicalFileID(sloc);
   unsigned fpos = SM.getFullFilePos(sloc);
   
   return (fid == FileID ) ? MySpellingSrch.getSpellingLinearSearch(fpos, Buffer)

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=62193&r1=62192&r2=62193&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Jan 13 17:19:12 2009
@@ -199,7 +199,7 @@
   
   if (PTH) {
     SourceLocation sloc = SourceMgr.getPhysicalLoc(Tok.getLocation());
-    unsigned fid = sloc.getFileID();
+    unsigned fid = SourceMgr.getCanonicalFileID(sloc);
     unsigned fpos = SourceMgr.getFullFilePos(sloc);
     if (unsigned len = PTH->getSpelling(fid, fpos, TokStart)) {
       assert(!Tok.needsCleaning());
@@ -265,7 +265,7 @@
     }
     else {
       SourceLocation sloc = SourceMgr.getPhysicalLoc(Tok.getLocation());
-      unsigned fid = sloc.getFileID();
+      unsigned fid = SourceMgr.getCanonicalFileID(sloc);
       unsigned fpos = SourceMgr.getFullFilePos(sloc);      
       len = PTH->getSpelling(fid, fpos, Buffer);      
     }

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=62193&r1=62192&r2=62193&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan 13 17:19:12 2009
@@ -846,13 +846,13 @@
   // fast path for a single digit (which is quite common). A single digit 
   // cannot have a trigraph, escaped newline, radix prefix, or type suffix.
   if (Tok.getLength() == 1) {
-    const char *Ty = PP.getSourceManager().getCharacterData(Tok.getLocation());
-    
+    const char Ty = PP.getPhysicalCharacterAt(Tok.getLocation());
     unsigned IntSize =static_cast<unsigned>(Context.getTypeSize(Context.IntTy));
-    return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, *Ty-'0'),
+    return ExprResult(new IntegerLiteral(llvm::APInt(IntSize, Ty-'0'),
                                          Context.IntTy, 
                                          Tok.getLocation()));
   }
+
   llvm::SmallString<512> IntegerBuffer;
   // Add padding so that NumericLiteralParser can overread by one character.
   IntegerBuffer.resize(Tok.getLength()+1);





More information about the cfe-commits mailing list