[cfe-commits] r40394 - in /cfe/trunk: Lex/Lexer.cpp include/clang/Lex/Lexer.h

Chris Lattner sabre at nondot.org
Sun Jul 22 11:44:36 PDT 2007


Author: lattner
Date: Sun Jul 22 13:44:36 2007
New Revision: 40394

URL: http://llvm.org/viewvc/llvm-project?rev=40394&view=rev
Log:
Change hte lexer to start a start pointer to the underlying 
memorybuffer instead of a pointer to the memorybuffer itself.  This
reduces coupling and eliminates a pointer dereference on a hot path.
This speeds up -Eonly on 483.xalancbmk by 2.1%

Modified:
    cfe/trunk/Lex/Lexer.cpp
    cfe/trunk/include/clang/Lex/Lexer.h

Modified: cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Lexer.cpp?rev=40394&r1=40393&r2=40394&view=diff

==============================================================================
--- cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/trunk/Lex/Lexer.cpp Sun Jul 22 13:44:36 2007
@@ -40,13 +40,19 @@
   : FileLoc(fileloc), PP(pp), Features(PP.getLangOptions()) {
       
   SourceManager &SourceMgr = PP.getSourceManager();
-  InputFile =SourceMgr.getBuffer(SourceMgr.getPhysicalLoc(FileLoc).getFileID());
+  unsigned InputFileID = SourceMgr.getPhysicalLoc(FileLoc).getFileID();
+  const llvm::MemoryBuffer *InputFile = SourceMgr.getBuffer(InputFileID);
       
   Is_PragmaLexer = false;
   IsMainFile = false;
   InitCharacterInfo();
-      
-  BufferPtr = BufStart ? BufStart : InputFile->getBufferStart();
+  
+  // BufferStart must always be InputFile->getBufferStart().
+  BufferStart = InputFile->getBufferStart();
+  
+  // BufferPtr and BufferEnd can start out somewhere inside the current buffer.
+  // If unspecified, they starts at the start/end of the buffer.
+  BufferPtr = BufStart ? BufStart : BufferStart;
   BufferEnd = BufEnd ? BufEnd : InputFile->getBufferEnd();
 
   assert(BufferEnd[0] == 0 &&
@@ -177,12 +183,12 @@
 /// getSourceLocation - Return a source location identifier for the specified
 /// offset in the current file.
 SourceLocation Lexer::getSourceLocation(const char *Loc) const {
-  assert(Loc >= InputFile->getBufferStart() && Loc <= BufferEnd &&
+  assert(Loc >= BufferStart && Loc <= BufferEnd &&
          "Location out of range for this buffer!");
 
   // In the normal case, we're just lexing from a simple file buffer, return
   // the file id from FileLoc with the offset specified.
-  unsigned CharNo = Loc-InputFile->getBufferStart();
+  unsigned CharNo = Loc-BufferStart;
   if (FileLoc.isFileID())
     return SourceLocation::getFileLoc(FileLoc.getFileID(), CharNo);
   

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Lexer.h (original)
+++ cfe/trunk/include/clang/Lex/Lexer.h Sun Jul 22 13:44:36 2007
@@ -21,10 +21,6 @@
 #include <vector>
 #include <cassert>
 
-namespace llvm {
-  class MemoryBuffer;
-}
-  
 namespace clang {
 class Diagnostic;
 class Preprocessor;
@@ -36,8 +32,8 @@
 class Lexer {
   //===--------------------------------------------------------------------===//
   // Constant configuration values for this lexer.
+  const char *BufferStart;       // Start of the buffer.
   const char *BufferEnd;         // End of the buffer.
-  const llvm::MemoryBuffer *InputFile; // The file we are reading from.
   SourceLocation FileLoc;        // Location for start of file.
   Preprocessor &PP;              // Preprocessor object controlling lexing.
   LangOptions Features;          // Features enabled by this language (cache).





More information about the cfe-commits mailing list