DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D) { DSAVarData DVar; // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced // in a Construct, C/C++, predetermined, p.1] // Variables appearing in threadprivate directives are threadprivate. if (D->getTLSKind() != VarDecl::TLS_None) { DVar.CKind = OMPC_threadprivate; return DVar; } if (Stack[0].SharingMap.count(D)) { DVar.RefExpr = Stack[0].SharingMap[D].RefExpr; DVar.CKind = OMPC_threadprivate; return DVar; } // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced // in a Construct, C/C++, predetermined, p.1] // Variables with automatic storage duration that are declared in a scope // inside the construct are private. OpenMPDirectiveKind Kind = getCurrentDirective(); if (Kind != OMPD_parallel) { if (isOpenMPLocal(D, llvm::next(Stack.rbegin())) && D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) DVar.CKind = OMPC_private; return DVar; } // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced // in a Construct, C/C++, predetermined, p.4] // Static data memebers are shared. if (D->isStaticDataMember()) { // Variables with const-qualified type having no mutable member may be listed // in a firstprivate clause, even if they are static data members. DSAVarData DVarTemp = hasDSA(D, OMPC_firstprivate); if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) return DVar; DVar.CKind = OMPC_shared; return DVar; } QualType Type = D->getType().getNonReferenceType().getCanonicalType(); bool IsConstant = Type.isConstant(Actions.getASTContext()); while (Type->isArrayType()) { QualType ElemType = cast<ArrayType>(Type.getTypePtr())->getElementType(); Type = ElemType.getNonReferenceType().getCanonicalType(); } // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced // in a Construct, C/C++, predetermined, p.6] // Variables with const qualified type having no mutable member are // shared. CXXRecordDecl *RD = Actions.getLangOpts().CPlusPlus ? Type->getAsCXXRecordDecl() : 0; if (IsConstant && !(Actions.getLangOpts().CPlusPlus && RD && RD->hasMutableFields())) { // Variables with const-qualified type having no mutable member may be // listed in a firstprivate clause, even if they are static data members. DSAVarData DVarTemp = hasDSA(D, OMPC_firstprivate); if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr) return DVar; DVar.CKind = OMPC_shared; return DVar; } // OpenMP [2.9.1.1, Data-sharing Attribute Rules for Variables Referenced // in a Construct, C/C++, predetermined, p.7] // Variables with static storage duration that are declared in a scope // inside the construct are shared. if (D->isStaticLocal()) { DVar.CKind = OMPC_shared; return DVar; } // Explicitly specified attributes and local variables with predetermined // attributes. if (Stack.back().SharingMap.count(D)) { DVar.RefExpr = Stack.back().SharingMap[D].RefExpr; DVar.CKind = Stack.back().SharingMap[D].Attributes; } return DVar; }