[cfe-commits] r62460 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/MinimalAction.cpp
Chris Lattner
sabre at nondot.org
Sun Jan 18 01:39:50 PST 2009
Author: lattner
Date: Sun Jan 18 03:39:41 2009
New Revision: 62460
URL: http://llvm.org/viewvc/llvm-project?rev=62460&view=rev
Log:
Switch MinimalAction from new/delete'ing its TypeNameInfo to
allocating them from a recycling bump pointer allocator. This
reduces malloc/free traffic of parse-noop (but no other mode),
which makes sharking -parse-noop more meaningful.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/MinimalAction.cpp
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=62460&r1=62459&r2=62460&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Sun Jan 18 03:39:41 2009
@@ -1276,9 +1276,11 @@
Scope *TUScope;
IdentifierTable &Idents;
Preprocessor &PP;
+ void *TypeNameInfoTablePtr;
public:
MinimalAction(Preprocessor &pp);
-
+ ~MinimalAction();
+
/// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
/// determine whether the name is a typedef or not in this scope.
virtual TypeTy *isTypeName(IdentifierInfo &II, Scope *S,
Modified: cfe/trunk/lib/Parse/MinimalAction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/MinimalAction.cpp?rev=62460&r1=62459&r2=62460&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/MinimalAction.cpp (original)
+++ cfe/trunk/lib/Parse/MinimalAction.cpp Sun Jan 18 03:39:41 2009
@@ -14,42 +14,64 @@
#include "clang/Parse/Parser.h"
#include "clang/Parse/DeclSpec.h"
#include "clang/Parse/Scope.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/RecyclingAllocator.h"
using namespace clang;
/// TypeNameInfo - A link exists here for each scope that an identifier is
/// defined.
-struct TypeNameInfo {
- TypeNameInfo *Prev;
- bool isTypeName;
-
- TypeNameInfo(bool istypename, TypeNameInfo *prev) {
- isTypeName = istypename;
- Prev = prev;
- }
-};
+namespace {
+ struct TypeNameInfo {
+ TypeNameInfo *Prev;
+ bool isTypeName;
+
+ TypeNameInfo(bool istypename, TypeNameInfo *prev) {
+ isTypeName = istypename;
+ Prev = prev;
+ }
+ };
+
+ struct TypeNameInfoTable {
+ llvm::RecyclingAllocator<llvm::BumpPtrAllocator, TypeNameInfo> Allocator;
+
+ void AddEntry(bool isTypename, IdentifierInfo *II) {
+ TypeNameInfo *TI = Allocator.Allocate<TypeNameInfo>();
+ new (TI) TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
+ II->setFETokenInfo(TI);
+ }
+
+ void DeleteEntry(TypeNameInfo *Entry) {
+ Entry->~TypeNameInfo();
+ Allocator.Deallocate(Entry);
+ }
+ };
+}
+
+static TypeNameInfoTable *getTable(void *TP) {
+ return static_cast<TypeNameInfoTable*>(TP);
+}
MinimalAction::MinimalAction(Preprocessor &pp)
- : Idents(pp.getIdentifierTable()), PP(pp) {}
+ : Idents(pp.getIdentifierTable()), PP(pp) {
+ TypeNameInfoTablePtr = new TypeNameInfoTable();
+}
+
+MinimalAction::~MinimalAction() {
+ delete getTable(TypeNameInfoTablePtr);
+}
void MinimalAction::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
TUScope = S;
if (!PP.getLangOptions().ObjC1) return;
- // recognize the ObjC built-in type identifiers.
- IdentifierInfo *II;
- TypeNameInfo *TI;
- II = &Idents.get("id");
- TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
- II->setFETokenInfo(TI);
- II = &Idents.get("SEL");
- TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
- II->setFETokenInfo(TI);
- II = &Idents.get("Class");
- TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
- II->setFETokenInfo(TI);
- II = &Idents.get("Protocol");
- TI = new TypeNameInfo(1, II->getFETokenInfo<TypeNameInfo>());
- II->setFETokenInfo(TI);
+
+ TypeNameInfoTable &TNIT = *getTable(TypeNameInfoTablePtr);
+
+ // Recognize the ObjC built-in type identifiers as types.
+ TNIT.AddEntry(true, &Idents.get("id"));
+ TNIT.AddEntry(true, &Idents.get("SEL"));
+ TNIT.AddEntry(true, &Idents.get("Class"));
+ TNIT.AddEntry(true, &Idents.get("Protocol"));
}
/// isTypeName - This looks at the IdentifierInfo::FETokenInfo field to
@@ -101,9 +123,8 @@
// It does need to handle the uncommon case of shadowing a typedef name with a
// non-typedef name. e.g. { typedef int a; a xx; { int a; } }
if (weCurrentlyHaveTypeInfo || isTypeName) {
- TypeNameInfo *TI = new TypeNameInfo(isTypeName, weCurrentlyHaveTypeInfo);
-
- II->setFETokenInfo(TI);
+ // Allocate and add the 'TypeNameInfo' "decl".
+ getTable(TypeNameInfoTablePtr)->AddEntry(isTypeName, II);
// Remember that this needs to be removed when the scope is popped.
S->AddDecl(II);
@@ -121,10 +142,8 @@
unsigned NumProtocols,
SourceLocation EndProtoLoc,
AttributeList *AttrList) {
- TypeNameInfo *TI =
- new TypeNameInfo(1, ClassName->getFETokenInfo<TypeNameInfo>());
-
- ClassName->setFETokenInfo(TI);
+ // Allocate and add the 'TypeNameInfo' "decl".
+ getTable(TypeNameInfoTablePtr)->AddEntry(true, ClassName);
return 0;
}
@@ -134,10 +153,8 @@
MinimalAction::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
IdentifierInfo **IdentList, unsigned NumElts) {
for (unsigned i = 0; i != NumElts; ++i) {
- TypeNameInfo *TI =
- new TypeNameInfo(1, IdentList[i]->getFETokenInfo<TypeNameInfo>());
-
- IdentList[i]->setFETokenInfo(TI);
+ // Allocate and add the 'TypeNameInfo' "decl".
+ getTable(TypeNameInfoTablePtr)->AddEntry(true, IdentList[i]);
// Remember that this needs to be removed when the scope is popped.
TUScope->AddDecl(IdentList[i]);
@@ -148,6 +165,8 @@
/// ActOnPopScope - When a scope is popped, if any typedefs are now
/// out-of-scope, they are removed from the IdentifierInfo::FETokenInfo field.
void MinimalAction::ActOnPopScope(SourceLocation Loc, Scope *S) {
+ TypeNameInfoTable &Table = *getTable(TypeNameInfoTablePtr);
+
for (Scope::decl_iterator I = S->decl_begin(), E = S->decl_end();
I != E; ++I) {
IdentifierInfo &II = *static_cast<IdentifierInfo*>(*I);
@@ -156,7 +175,7 @@
if (TI) {
TypeNameInfo *Next = TI->Prev;
- delete TI;
+ Table.DeleteEntry(TI);
II.setFETokenInfo(Next);
}
More information about the cfe-commits
mailing list