[cfe-commits] r59725 - /cfe/trunk/include/clang/Lex/Token.h

Daniel Dunbar daniel at zuster.org
Thu Nov 20 00:01:39 PST 2008


Author: ddunbar
Date: Thu Nov 20 02:01:39 2008
New Revision: 59725

URL: http://llvm.org/viewvc/llvm-project?rev=59725&view=rev
Log:
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%.

Modified:
    cfe/trunk/include/clang/Lex/Token.h

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

==============================================================================
--- cfe/trunk/include/clang/Lex/Token.h (original)
+++ cfe/trunk/include/clang/Lex/Token.h Thu Nov 20 02:01:39 2008
@@ -34,22 +34,22 @@
   /// 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 @@
   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 @@
   ///
   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.





More information about the cfe-commits mailing list