r211660 - [OPENMP] Improved code and replaced struct by lambda.

Alexey Bataev a.bataev at hotmail.com
Tue Jun 24 21:09:14 PDT 2014


Author: abataev
Date: Tue Jun 24 23:09:13 2014
New Revision: 211660

URL: http://llvm.org/viewvc/llvm-project?rev=211660&view=rev
Log:
[OPENMP] Improved code and replaced struct by lambda.

Modified:
    cfe/trunk/include/clang/AST/StmtOpenMP.h
    cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=211660&r1=211659&r2=211660&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Tue Jun 24 23:09:13 2014
@@ -94,16 +94,17 @@ public:
   template <class FilterPredicate> class filtered_clause_iterator {
     ArrayRef<OMPClause *>::const_iterator Current;
     ArrayRef<OMPClause *>::const_iterator End;
+    FilterPredicate Pred;
     void SkipToNextClause() {
-      while (Current != End && !FilterPredicate()(*Current))
+      while (Current != End && !Pred(*Current))
         ++Current;
     }
 
   public:
     typedef const OMPClause *value_type;
     filtered_clause_iterator() : Current(), End() {}
-    explicit filtered_clause_iterator(ArrayRef<OMPClause *> Arr)
-        : Current(Arr.begin()), End(Arr.end()) {
+    filtered_clause_iterator(ArrayRef<OMPClause *> Arr, FilterPredicate Pred)
+        : Current(Arr.begin()), End(Arr.end()), Pred(Pred) {
       SkipToNextClause();
     }
     value_type operator*() const { return *Current; }

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=211660&r1=211659&r2=211660&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Tue Jun 24 23:09:13 2014
@@ -182,7 +182,7 @@ public:
 DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,
                                           VarDecl *D) {
   DSAVarData DVar;
-  if (Iter == Stack.rend() - 1) {
+  if (Iter == std::prev(Stack.rend())) {
     // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced
     // in a region but not in construct]
     //  File-scope or namespace-scope variables referenced in called routines
@@ -888,7 +888,7 @@ void Sema::ActOnOpenMPRegionStart(OpenMP
   case OMPD_parallel: {
     QualType KmpInt32Ty = Context.getIntTypeForBitwidth(32, 1);
     QualType KmpInt32PtrTy = Context.getPointerType(KmpInt32Ty);
-    Sema::CapturedParamNameType Params[3] = {
+    Sema::CapturedParamNameType Params[] = {
         std::make_pair(".global_tid.", KmpInt32PtrTy),
         std::make_pair(".bound_tid.", KmpInt32PtrTy),
         std::make_pair(StringRef(), QualType()) // __context with shared vars
@@ -897,14 +897,14 @@ void Sema::ActOnOpenMPRegionStart(OpenMP
     break;
   }
   case OMPD_simd: {
-    Sema::CapturedParamNameType Params[1] = {
+    Sema::CapturedParamNameType Params[] = {
         std::make_pair(StringRef(), QualType()) // __context with shared vars
     };
     ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params);
     break;
   }
   case OMPD_for: {
-    Sema::CapturedParamNameType Params[1] = {
+    Sema::CapturedParamNameType Params[] = {
         std::make_pair(StringRef(), QualType()) // __context with shared vars
     };
     ActOnCapturedRegionStart(Loc, CurScope, CR_OpenMP, Params);
@@ -1414,7 +1414,7 @@ static bool CheckOpenMPIterationSpace(Op
   OpenMPIterationSpaceChecker ISC(SemaRef, For->getForLoc());
 
   // Check init.
-  Stmt *Init = For->getInit();
+  auto Init = For->getInit();
   if (ISC.CheckInit(Init)) {
     return true;
   }
@@ -1422,14 +1422,14 @@ static bool CheckOpenMPIterationSpace(Op
   bool HasErrors = false;
 
   // Check loop variable's type.
-  VarDecl *Var = ISC.GetLoopVar();
+  auto Var = ISC.GetLoopVar();
 
   // OpenMP [2.6, Canonical Loop Form]
   // Var is one of the following:
   //   A variable of signed or unsigned integer type.
   //   For C++, a variable of a random access iterator type.
   //   For C, a variable of a pointer type.
-  QualType VarType = Var->getType();
+  auto VarType = Var->getType();
   if (!VarType->isDependentType() && !VarType->isIntegerType() &&
       !VarType->isPointerType() &&
       !(SemaRef.getLangOpts().CPlusPlus && VarType->isOverloadableType())) {
@@ -1525,18 +1525,12 @@ static bool CheckOpenMPLoop(OpenMPDirect
   return false;
 }
 
-namespace {
-struct OMPCollapseClauseFilter {
-  OMPCollapseClauseFilter() {}
-  bool operator()(const OMPClause *C) {
-    return C->getClauseKind() == OMPC_collapse;
-  }
-};
-} // namespace
-
 static Expr *GetCollapseNumberExpr(ArrayRef<OMPClause *> Clauses) {
-  OMPExecutableDirective::filtered_clause_iterator<OMPCollapseClauseFilter> I(
-      Clauses);
+  auto CollapseFilter = [](const OMPClause *C) -> bool {
+    return C->getClauseKind() == OMPC_collapse;
+  };
+  OMPExecutableDirective::filtered_clause_iterator<decltype(CollapseFilter)> I(
+      Clauses, CollapseFilter);
   if (I)
     return cast<OMPCollapseClause>(*I)->getNumForLoops();
   return nullptr;





More information about the cfe-commits mailing list