r338639 - [AST][3/4] Move the bit-fields from BlockDecl, LinkageSpecDecl and OMPDeclareReductionDecl into DeclContext

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 1 14:16:54 PDT 2018


Author: erichkeane
Date: Wed Aug  1 14:16:54 2018
New Revision: 338639

URL: http://llvm.org/viewvc/llvm-project?rev=338639&view=rev
Log:
[AST][3/4] Move the bit-fields from BlockDecl, LinkageSpecDecl and OMPDeclareReductionDecl into DeclContext

This patch follows https://reviews.llvm.org/D49729
and https://reviews.llvm.org/D49732, and is
followed by https://reviews.llvm.org/D49734.

Move the bits from BlockDecl, LinkageSpecDecl and
OMPDeclareReductionDecl into DeclContext.

Differential Revision: https://reviews.llvm.org/D49733

Patch By: bricci

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/include/clang/AST/DeclOpenMP.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/AST/DeclOpenMP.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=338639&r1=338638&r2=338639&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Aug  1 14:16:54 2018
@@ -3823,6 +3823,8 @@ public:
 /// unnamed FunctionDecl.  For example:
 /// ^{ statement-body }   or   ^(int arg1, float arg2){ statement-body }
 class BlockDecl : public Decl, public DeclContext {
+  // This class stores some data in DeclContext::BlockDeclBits
+  // to save some space. Use the provided accessors to access it.
 public:
   /// A class which contains all the information about a particular
   /// captured value.
@@ -3863,16 +3865,6 @@ public:
   };
 
 private:
-  // FIXME: This can be packed into the bitfields in Decl.
-  bool IsVariadic : 1;
-  bool CapturesCXXThis : 1;
-  bool BlockMissingReturnType : 1;
-  bool IsConversionFromLambda : 1;
-
-  /// A bit that indicates this block is passed directly to a function as a
-  /// non-escaping parameter.
-  bool DoesNotEscape : 1;
-
   /// A new[]'d array of pointers to ParmVarDecls for the formal
   /// parameters of this function.  This is null if a prototype or if there are
   /// no formals.
@@ -3889,10 +3881,7 @@ private:
   Decl *ManglingContextDecl = nullptr;
 
 protected:
-  BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
-      : Decl(Block, DC, CaretLoc), DeclContext(Block), IsVariadic(false),
-        CapturesCXXThis(false), BlockMissingReturnType(true),
-        IsConversionFromLambda(false), DoesNotEscape(false) {}
+  BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
 
 public:
   static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
@@ -3900,8 +3889,8 @@ public:
 
   SourceLocation getCaretLocation() const { return getLocation(); }
 
-  bool isVariadic() const { return IsVariadic; }
-  void setIsVariadic(bool value) { IsVariadic = value; }
+  bool isVariadic() const { return BlockDeclBits.IsVariadic; }
+  void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
 
   CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
   Stmt *getBody() const override { return (Stmt*) Body; }
@@ -3944,7 +3933,7 @@ public:
 
   /// True if this block (or its nested blocks) captures
   /// anything of local storage from its enclosing scopes.
-  bool hasCaptures() const { return NumCaptures != 0 || CapturesCXXThis; }
+  bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
 
   /// Returns the number of captured variables.
   /// Does not include an entry for 'this'.
@@ -3957,15 +3946,27 @@ public:
   capture_const_iterator capture_begin() const { return captures().begin(); }
   capture_const_iterator capture_end() const { return captures().end(); }
 
-  bool capturesCXXThis() const { return CapturesCXXThis; }
-  bool blockMissingReturnType() const { return BlockMissingReturnType; }
-  void setBlockMissingReturnType(bool val) { BlockMissingReturnType = val; }
+  bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
+  void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
+
+  bool blockMissingReturnType() const {
+    return BlockDeclBits.BlockMissingReturnType;
+  }
+
+  void setBlockMissingReturnType(bool val = true) {
+    BlockDeclBits.BlockMissingReturnType = val;
+  }
+
+  bool isConversionFromLambda() const {
+    return BlockDeclBits.IsConversionFromLambda;
+  }
 
-  bool isConversionFromLambda() const { return IsConversionFromLambda; }
-  void setIsConversionFromLambda(bool val) { IsConversionFromLambda = val; }
+  void setIsConversionFromLambda(bool val = true) {
+    BlockDeclBits.IsConversionFromLambda = val;
+  }
 
-  bool doesNotEscape() const { return DoesNotEscape; }
-  void setDoesNotEscape() { DoesNotEscape = true; }
+  bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
+  void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
 
   bool capturesVariable(const VarDecl *var) const;
 

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=338639&r1=338638&r2=338639&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Wed Aug  1 14:16:54 2018
@@ -2816,7 +2816,8 @@ public:
 /// \endcode
 class LinkageSpecDecl : public Decl, public DeclContext {
   virtual void anchor();
-
+  // This class stores some data in DeclContext::LinkageSpecDeclBits to save
+  // some space. Use the provided accessors to access it.
 public:
   /// Represents the language in a linkage specification.
   ///
@@ -2830,16 +2831,6 @@ public:
   };
 
 private:
-  /// The language for this linkage specification.
-  unsigned Language : 3;
-
-  /// True if this linkage spec has braces.
-  ///
-  /// This is needed so that hasBraces() returns the correct result while the
-  /// linkage spec body is being parsed.  Once RBraceLoc has been set this is
-  /// not used, so it doesn't need to be serialized.
-  unsigned HasBraces : 1;
-
   /// The source location for the extern keyword.
   SourceLocation ExternLoc;
 
@@ -2847,10 +2838,7 @@ private:
   SourceLocation RBraceLoc;
 
   LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
-                  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces)
-      : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
-        Language(lang), HasBraces(HasBraces), ExternLoc(ExternLoc),
-        RBraceLoc(SourceLocation()) {}
+                  SourceLocation LangLoc, LanguageIDs lang, bool HasBraces);
 
 public:
   static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
@@ -2860,16 +2848,18 @@ public:
   static LinkageSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
   /// Return the language specified by this linkage specification.
-  LanguageIDs getLanguage() const { return LanguageIDs(Language); }
+  LanguageIDs getLanguage() const {
+    return static_cast<LanguageIDs>(LinkageSpecDeclBits.Language);
+  }
 
   /// Set the language specified by this linkage specification.
-  void setLanguage(LanguageIDs L) { Language = L; }
+  void setLanguage(LanguageIDs L) { LinkageSpecDeclBits.Language = L; }
 
   /// Determines whether this linkage specification had braces in
   /// its syntactic form.
   bool hasBraces() const {
-    assert(!RBraceLoc.isValid() || HasBraces);
-    return HasBraces;
+    assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
+    return LinkageSpecDeclBits.HasBraces;
   }
 
   SourceLocation getExternLoc() const { return ExternLoc; }
@@ -2877,7 +2867,7 @@ public:
   void setExternLoc(SourceLocation L) { ExternLoc = L; }
   void setRBraceLoc(SourceLocation L) {
     RBraceLoc = L;
-    HasBraces = RBraceLoc.isValid();
+    LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
   }
 
   SourceLocation getLocEnd() const LLVM_READONLY {

Modified: cfe/trunk/include/clang/AST/DeclOpenMP.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclOpenMP.h?rev=338639&r1=338638&r2=338639&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/DeclOpenMP.h Wed Aug  1 14:16:54 2018
@@ -100,6 +100,8 @@ public:
 ///
 /// Here 'omp_out += omp_in' is a combiner and 'omp_priv = 0' is an initializer.
 class OMPDeclareReductionDecl final : public ValueDecl, public DeclContext {
+  // This class stores some data in DeclContext::OMPDeclareReductionDeclBits
+  // to save some space. Use the provided accessors to access it.
 public:
   enum InitKind {
     CallInit,   // Initialized by function call.
@@ -113,8 +115,6 @@ private:
   Expr *Combiner;
   /// Initializer for declare reduction construct.
   Expr *Initializer;
-  /// Kind of initializer - function call or omp_priv<init_expr> initializtion.
-  InitKind InitializerKind = CallInit;
 
   /// Reference to the previous declare reduction construct in the same
   /// scope with the same name. Required for proper templates instantiation if
@@ -125,10 +125,7 @@ private:
 
   OMPDeclareReductionDecl(Kind DK, DeclContext *DC, SourceLocation L,
                           DeclarationName Name, QualType Ty,
-                          OMPDeclareReductionDecl *PrevDeclInScope)
-      : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
-        Initializer(nullptr), InitializerKind(CallInit),
-        PrevDeclInScope(PrevDeclInScope) {}
+                          OMPDeclareReductionDecl *PrevDeclInScope);
 
   void setPrevDeclInScope(OMPDeclareReductionDecl *Prev) {
     PrevDeclInScope = Prev;
@@ -154,11 +151,13 @@ public:
   Expr *getInitializer() { return Initializer; }
   const Expr *getInitializer() const { return Initializer; }
   /// Get initializer kind.
-  InitKind getInitializerKind() const { return InitializerKind; }
+  InitKind getInitializerKind() const {
+    return static_cast<InitKind>(OMPDeclareReductionDeclBits.InitializerKind);
+  }
   /// Set initializer expression for the declare reduction construct.
   void setInitializer(Expr *E, InitKind IK) {
     Initializer = E;
-    InitializerKind = IK;
+    OMPDeclareReductionDeclBits.InitializerKind = IK;
   }
 
   /// Get reference to previous declare reduction construct in the same

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=338639&r1=338638&r2=338639&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Aug  1 14:16:54 2018
@@ -4215,6 +4215,15 @@ const FieldDecl *RecordDecl::findFirstNa
 // BlockDecl Implementation
 //===----------------------------------------------------------------------===//
 
+BlockDecl::BlockDecl(DeclContext *DC, SourceLocation CaretLoc)
+    : Decl(Block, DC, CaretLoc), DeclContext(Block) {
+  setIsVariadic(false);
+  setCapturesCXXThis(false);
+  setBlockMissingReturnType(true);
+  setIsConversionFromLambda(false);
+  setDoesNotEscape(false);
+}
+
 void BlockDecl::setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
   assert(!ParamInfo && "Already has param info!");
 
@@ -4228,7 +4237,7 @@ void BlockDecl::setParams(ArrayRef<ParmV
 
 void BlockDecl::setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
                             bool CapturesCXXThis) {
-  this->CapturesCXXThis = CapturesCXXThis;
+  this->setCapturesCXXThis(CapturesCXXThis);
   this->NumCaptures = Captures.size();
 
   if (Captures.empty()) {

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=338639&r1=338638&r2=338639&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Wed Aug  1 14:16:54 2018
@@ -2466,6 +2466,15 @@ bool CXXConversionDecl::isLambdaToBlockP
          getConversionType()->isBlockPointerType();
 }
 
+LinkageSpecDecl::LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
+                                 SourceLocation LangLoc, LanguageIDs lang,
+                                 bool HasBraces)
+    : Decl(LinkageSpec, DC, LangLoc), DeclContext(LinkageSpec),
+      ExternLoc(ExternLoc), RBraceLoc(SourceLocation()) {
+  setLanguage(lang);
+  LinkageSpecDeclBits.HasBraces = HasBraces;
+}
+
 void LinkageSpecDecl::anchor() {}
 
 LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,

Modified: cfe/trunk/lib/AST/DeclOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclOpenMP.cpp?rev=338639&r1=338638&r2=338639&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclOpenMP.cpp (original)
+++ cfe/trunk/lib/AST/DeclOpenMP.cpp Wed Aug  1 14:16:54 2018
@@ -57,6 +57,14 @@ void OMPThreadPrivateDecl::setVars(Array
 // OMPDeclareReductionDecl Implementation.
 //===----------------------------------------------------------------------===//
 
+OMPDeclareReductionDecl::OMPDeclareReductionDecl(
+    Kind DK, DeclContext *DC, SourceLocation L, DeclarationName Name,
+    QualType Ty, OMPDeclareReductionDecl *PrevDeclInScope)
+    : ValueDecl(DK, DC, L, Name, Ty), DeclContext(DK), Combiner(nullptr),
+      PrevDeclInScope(PrevDeclInScope) {
+  setInitializer(nullptr, CallInit);
+}
+
 void OMPDeclareReductionDecl::anchor() {}
 
 OMPDeclareReductionDecl *OMPDeclareReductionDecl::Create(




More information about the cfe-commits mailing list