]> granicus.if.org Git - clang/commitdiff
PTH:
authorTed Kremenek <kremenek@apple.com>
Tue, 13 Jan 2009 23:19:12 +0000 (23:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 13 Jan 2009 23:19:12 +0000 (23:19 +0000)
- 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%.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62193 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Lex/Preprocessor.h
lib/Lex/PTHLexer.cpp
lib/Lex/Preprocessor.cpp
lib/Sema/SemaExpr.cpp

index 54dc1b62df0d65a743f86e630dc8ab169341b9b1..5ee8378d52dd0381fe34154bfe74e4cbab39ed03 100644 (file)
@@ -449,6 +449,20 @@ public:
   /// 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
index c5fc6f3da795a0fb5ee82d82a7a4cdfc046a39dc..8d04736ced80623a62760d7afe50d46cece1067a 100644 (file)
@@ -423,7 +423,7 @@ unsigned PTHSpellingSearch::getSpellingBinarySearch(unsigned fpos,
 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)
index a815265e7c9a6ea755f66fe823773ff2c13f49c3..e09ce1312de953c50bc8b2494bcd58d0f386c7bb 100644 (file)
@@ -199,7 +199,7 @@ std::string Preprocessor::getSpelling(const Token &Tok) const {
   
   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 @@ unsigned Preprocessor::getSpelling(const Token &Tok,
     }
     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);      
     }
index 41881a2e5bb35ec518b68e6b32f7f239e17c8903..d7a041d0ecf9d2d20b6c9bacf2fa4438dac90e12 100644 (file)
@@ -846,13 +846,13 @@ Action::ExprResult Sema::ActOnNumericConstant(const Token &Tok) {
   // 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);