[cfe-commits] r130671 - in /cfe/trunk: include/clang/AST/Decl.h lib/Sema/SemaDeclObjC.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp
John McCall
rjmccall at apple.com
Sun May 1 17:30:13 PDT 2011
Author: rjmccall
Date: Sun May 1 19:30:12 2011
New Revision: 130671
URL: http://llvm.org/viewvc/llvm-project?rev=130671&view=rev
Log:
Revise the representation of parameter scope data so that the
scope depth overlaps with the ObjCDeclQualifier, dropping
memory usage back to previous levels.
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=130671&r1=130670&r2=130671&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sun May 1 19:30:12 2011
@@ -703,7 +703,7 @@
/// for-range statement.
unsigned CXXForRangeDecl : 1;
};
- enum { NumVarDeclBits = 11 };
+ enum { NumVarDeclBits = 13 }; // two reserved bits for now
friend class ASTDeclReader;
friend class StmtIteratorBase;
@@ -714,9 +714,6 @@
friend class ASTDeclReader;
unsigned : NumVarDeclBits;
-
- /// in, inout, etc. Only meaningful on Objective-C method parameters.
- unsigned ObjCDeclQualifier : 6;
/// Whether this parameter inherits a default argument from a
/// prior declaration.
@@ -724,6 +721,19 @@
/// Whether this parameter undergoes K&R argument promotion.
unsigned IsKNRPromoted : 1;
+
+ /// Whether this parameter is an ObjC method parameter or not.
+ unsigned IsObjCMethodParam : 1;
+
+ /// If IsObjCMethodParam, a Decl::ObjCDeclQualifier.
+ /// Otherwise, the number of function parameter scopes enclosing
+ /// the function parameter scope in which this parameter was
+ /// declared.
+ unsigned ScopeDepthOrObjCQuals : 8;
+
+ /// The number of parameters preceding this parameter in the
+ /// function parameter scope in which it was declared.
+ unsigned ParameterIndex : 8;
};
union {
@@ -1139,28 +1149,19 @@
/// ParmVarDecl - Represents a parameter to a function.
class ParmVarDecl : public VarDecl {
- // FIXME: I'm convinced that there's some reasonable way to encode
- // these that doesn't require extra storage, but I don't know what
- // it is right now.
-
- /// The number of function parameter scopes enclosing the function
- /// parameter scope in which this parameter was declared.
- unsigned FunctionScopeDepth : 16;
-
- /// The number of parameters preceding this parameter in the
- /// function parameter scope in which it was declared.
- unsigned FunctionScopeIndex : 16;
+public:
+ enum { MaxFunctionScopeDepth = 255 };
+ enum { MaxFunctionScopeIndex = 255 };
protected:
ParmVarDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
SourceLocation IdLoc, IdentifierInfo *Id,
QualType T, TypeSourceInfo *TInfo,
StorageClass S, StorageClass SCAsWritten, Expr *DefArg)
- : VarDecl(DK, DC, StartLoc, IdLoc, Id, T, TInfo, S, SCAsWritten),
- FunctionScopeDepth(0), FunctionScopeIndex(0) {
- assert(ParmVarDeclBits.ObjCDeclQualifier == OBJC_TQ_None);
+ : VarDecl(DK, DC, StartLoc, IdLoc, Id, T, TInfo, S, SCAsWritten) {
assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
assert(ParmVarDeclBits.IsKNRPromoted == false);
+ assert(ParmVarDeclBits.IsObjCMethodParam == false);
setDefaultArg(DefArg);
}
@@ -1172,27 +1173,44 @@
StorageClass S, StorageClass SCAsWritten,
Expr *DefArg);
+ void setObjCMethodScopeInfo(unsigned parameterIndex) {
+ ParmVarDeclBits.IsObjCMethodParam = true;
+
+ ParmVarDeclBits.ParameterIndex = parameterIndex;
+ assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
+ }
+
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
- FunctionScopeDepth = scopeDepth;
- assert(FunctionScopeDepth == scopeDepth && "truncation!");
+ assert(!ParmVarDeclBits.IsObjCMethodParam);
+
+ ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
+ assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth && "truncation!");
+
+ ParmVarDeclBits.ParameterIndex = parameterIndex;
+ assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
+ }
- FunctionScopeIndex = parameterIndex;
- assert(FunctionScopeIndex == parameterIndex && "truncation!");
+ bool isObjCMethodParameter() const {
+ return ParmVarDeclBits.IsObjCMethodParam;
}
unsigned getFunctionScopeDepth() const {
- return FunctionScopeDepth;
+ if (ParmVarDeclBits.IsObjCMethodParam) return 0;
+ return ParmVarDeclBits.ScopeDepthOrObjCQuals;
}
+ /// Returns the index of this parameter in its prototype or method scope.
unsigned getFunctionScopeIndex() const {
- return FunctionScopeIndex;
+ return ParmVarDeclBits.ParameterIndex;
}
ObjCDeclQualifier getObjCDeclQualifier() const {
- return ObjCDeclQualifier(ParmVarDeclBits.ObjCDeclQualifier);
+ if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
+ return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
}
void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
- ParmVarDeclBits.ObjCDeclQualifier = QTVal;
+ assert(ParmVarDeclBits.IsObjCMethodParam);
+ ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
}
/// True if the value passed to this parameter must undergo
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=130671&r1=130670&r2=130671&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun May 1 19:30:12 2011
@@ -1793,6 +1793,8 @@
ArgInfo[i].NameLoc, ArgInfo[i].Name,
ArgType, DI, SC_None, SC_None);
+ Param->setObjCMethodScopeInfo(i);
+
Param->setObjCDeclQualifier(
CvtQTToAstBitMask(ArgInfo[i].DeclSpec.getObjCDeclQualifier()));
Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=130671&r1=130670&r2=130671&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sun May 1 19:30:12 2011
@@ -710,9 +710,17 @@
void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
VisitVarDecl(PD);
- unsigned scopeDepth = Record[Idx++], scopeIndex = Record[Idx++];
- PD->setScopeInfo(scopeDepth, scopeIndex);
- PD->ParmVarDeclBits.ObjCDeclQualifier = (Decl::ObjCDeclQualifier)Record[Idx++];
+ unsigned isObjCMethodParam = Record[Idx++];
+ unsigned scopeDepth = Record[Idx++];
+ unsigned scopeIndex = Record[Idx++];
+ unsigned declQualifier = Record[Idx++];
+ if (isObjCMethodParam) {
+ assert(scopeDepth == 0);
+ PD->setObjCMethodScopeInfo(scopeIndex);
+ PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
+ } else {
+ PD->setScopeInfo(scopeDepth, scopeIndex);
+ }
PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=130671&r1=130670&r2=130671&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sun May 1 19:30:12 2011
@@ -587,6 +587,7 @@
void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
VisitVarDecl(D);
+ Record.push_back(D->isObjCMethodParameter());
Record.push_back(D->getFunctionScopeDepth());
Record.push_back(D->getFunctionScopeIndex());
Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
@@ -608,6 +609,7 @@
D->getPCHLevel() == 0 &&
D->getStorageClass() == 0 &&
!D->hasCXXDirectInitializer() && // Can params have this ever?
+ D->getFunctionScopeDepth() == 0 &&
D->getObjCDeclQualifier() == 0 &&
!D->isKNRPromoted() &&
!D->hasInheritedDefaultArg() &&
@@ -1176,6 +1178,7 @@
Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
// ParmVarDecl
+ Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
More information about the cfe-commits
mailing list