[cfe-commits] r40393 - /cfe/trunk/Lex/Lexer.cpp
Chris Lattner
sabre at nondot.org
Sun Jul 22 11:38:26 PDT 2007
Author: lattner
Date: Sun Jul 22 13:38:25 2007
New Revision: 40393
URL: http://llvm.org/viewvc/llvm-project?rev=40393&view=rev
Log:
split the slow path out of Lexer::getSourceLocation and do not let the
compiler inline it. This speeds up -Eonly on 483.xalancbmk by about 1%
Modified:
cfe/trunk/Lex/Lexer.cpp
Modified: cfe/trunk/Lex/Lexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Lex/Lexer.cpp?rev=40393&r1=40392&r2=40393&view=diff
==============================================================================
--- cfe/trunk/Lex/Lexer.cpp (original)
+++ cfe/trunk/Lex/Lexer.cpp Sun Jul 22 13:38:25 2007
@@ -28,6 +28,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cctype>
using namespace clang;
@@ -150,6 +151,29 @@
// Diagnostics forwarding code.
//===----------------------------------------------------------------------===//
+/// GetMappedTokenLoc - If lexing out of a 'mapped buffer', where we pretend the
+/// lexer buffer was all instantiated at a single point, perform the mapping.
+/// This is currently only used for _Pragma implementation, so it is the slow
+/// path of the hot getSourceLocation method. Do not allow it to be inlined.
+static SourceLocation GetMappedTokenLoc(Preprocessor &PP,
+ SourceLocation FileLoc,
+ unsigned CharNo) DISABLE_INLINE;
+static SourceLocation GetMappedTokenLoc(Preprocessor &PP,
+ SourceLocation FileLoc,
+ unsigned CharNo) {
+ // Otherwise, we're lexing "mapped tokens". This is used for things like
+ // _Pragma handling. Combine the instantiation location of FileLoc with the
+ // physical location.
+ SourceManager &SourceMgr = PP.getSourceManager();
+
+ // Create a new SLoc which is expanded from logical(FileLoc) but whose
+ // characters come from phys(FileLoc)+Offset.
+ SourceLocation VirtLoc = SourceMgr.getLogicalLoc(FileLoc);
+ SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(FileLoc);
+ PhysLoc = SourceLocation::getFileLoc(PhysLoc.getFileID(), CharNo);
+ return SourceMgr.getInstantiationLoc(PhysLoc, VirtLoc);
+}
+
/// getSourceLocation - Return a source location identifier for the specified
/// offset in the current file.
SourceLocation Lexer::getSourceLocation(const char *Loc) const {
@@ -162,20 +186,9 @@
if (FileLoc.isFileID())
return SourceLocation::getFileLoc(FileLoc.getFileID(), CharNo);
- // Otherwise, we're lexing "mapped tokens". This is used for things like
- // _Pragma handling. Combine the instantiation location of FileLoc with the
- // physical location.
- SourceManager &SourceMgr = PP.getSourceManager();
-
- // Create a new SLoc which is expanded from logical(FileLoc) but whose
- // characters come from phys(FileLoc)+Offset.
- SourceLocation VirtLoc = SourceMgr.getLogicalLoc(FileLoc);
- SourceLocation PhysLoc = SourceMgr.getPhysicalLoc(FileLoc);
- PhysLoc = SourceLocation::getFileLoc(PhysLoc.getFileID(), CharNo);
- return SourceMgr.getInstantiationLoc(PhysLoc, VirtLoc);
+ return GetMappedTokenLoc(PP, FileLoc, CharNo);
}
-
/// Diag - Forwarding function for diagnostics. This translate a source
/// position in the current buffer into a SourceLocation object for rendering.
void Lexer::Diag(const char *Loc, unsigned DiagID,
@@ -1302,8 +1315,8 @@
if (Char == '/') { // BCPL comment.
if (SkipBCPLComment(Result, ConsumeChar(CurPtr, SizeTmp, Result))) {
// It is common for the tokens immediately after a // comment to be
- // whitespace (indentation for the next line). Instead of going through the
- // big switch, handle it efficiently now.
+ // whitespace (indentation for the next line). Instead of going through
+ // the big switch, handle it efficiently now.
goto SkipIgnoredUnits;
}
return; // KeepCommentMode
More information about the cfe-commits
mailing list