aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2008-11-20 08:01:39 +0000
committerDaniel Dunbar <daniel@zuster.org>2008-11-20 08:01:39 +0000
commitb28d6de75e0cb27ce3106ce6052f87ad0ab276d7 (patch)
treef7345a493ee860b69edae50f1b91f81c40493cee
parentd6f53dc4951aace69014619761760addac9e59ec (diff)
De-unionize fields in Token class.
- This is fairly gross but although the code is conceptually the same, introducting the union causes gcc 4.2 on x86 (darwin, if that matters) to pessimize LexTokenInternal which is critical to our preprocessor performance. This speeds up -Eonly lexing of Cocoa.h by ~4.7% in my timings and reduces the code size of LexTokenInternal by 8.6%. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59725 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Lex/Token.h50
1 files changed, 25 insertions, 25 deletions
diff --git a/include/clang/Lex/Token.h b/include/clang/Lex/Token.h
index 1dd6d7bef3..ce687856f0 100644
--- a/include/clang/Lex/Token.h
+++ b/include/clang/Lex/Token.h
@@ -34,22 +34,22 @@ class Token {
/// The location of the token.
SourceLocation Loc;
- union {
- /// The end of the SourceRange of an annotation token.
- unsigned AnnotEndLocID;
-
- /// The length of the token text itself.
- unsigned Length;
- };
-
- union {
- /// IdentifierInfo - If this was an identifier, this points to the uniqued
- /// information about this identifier.
- IdentifierInfo *IdentInfo;
-
- /// AnnotVal - Information specific to an annotation token.
- void *AnnotVal;
- };
+ // Conceptually these next two fields could be in a union with
+ // access depending on isAnnotationToken(). However, this causes gcc
+ // 4.2 to pessimize LexTokenInternal, a very performance critical
+ // routine. Keeping as separate members with casts until a more
+ // beautiful fix presents itself.
+
+ /// UintData - This holds either the length of the token text, when
+ /// a normal token, or the end of the SourceRange when an annotation
+ /// token.
+ unsigned UintData;
+
+ /// PtrData - For normal tokens, this points to the uniqued
+ /// information for the identifier (if an identifier token) or
+ /// null. For annotation tokens, this points to information specific
+ /// to the annotation token.
+ void *PtrData;
/// Kind - The actual flavor of token this is.
///
@@ -86,19 +86,19 @@ public:
SourceLocation getLocation() const { return Loc; }
unsigned getLength() const {
assert(!isAnnotationToken() && "Used Length on annotation token");
- return Length;
+ return UintData;
}
void setLocation(SourceLocation L) { Loc = L; }
- void setLength(unsigned Len) { Length = Len; }
+ void setLength(unsigned Len) { UintData = Len; }
SourceLocation getAnnotationEndLoc() const {
assert(isAnnotationToken() && "Used AnnotEndLocID on non-annotation token");
- return SourceLocation::getFromRawEncoding(AnnotEndLocID);
+ return SourceLocation::getFromRawEncoding(UintData);
}
void setAnnotationEndLoc(SourceLocation L) {
assert(isAnnotationToken() && "Used AnnotEndLocID on non-annotation token");
- AnnotEndLocID = L.getRawEncoding();
+ UintData = L.getRawEncoding();
}
/// getAnnotationRange - SourceRange of the group of tokens that this
@@ -119,25 +119,25 @@ public:
///
void startToken() {
Flags = 0;
- IdentInfo = 0;
+ PtrData = 0;
Loc = SourceLocation();
}
IdentifierInfo *getIdentifierInfo() const {
assert(!isAnnotationToken() && "Used IdentInfo on annotation token");
- return IdentInfo;
+ return (IdentifierInfo*) PtrData;
}
void setIdentifierInfo(IdentifierInfo *II) {
- IdentInfo = II;
+ PtrData = (void*) II;
}
void *getAnnotationValue() const {
assert(isAnnotationToken() && "Used AnnotVal on non-annotation token");
- return AnnotVal;
+ return PtrData;
}
void setAnnotationValue(void *val) {
assert(isAnnotationToken() && "Used AnnotVal on non-annotation token");
- AnnotVal = val;
+ PtrData = val;
}
/// setFlag - Set the specified flag.