diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2018-03-02 18:07:00 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2018-03-02 18:07:00 +0000 |
commit | 20cf67c233beab21cccbdc23d8b35397fc6cb321 (patch) | |
tree | e58f23db30f2179c58210e9741e3a1582f7706f8 | |
parent | 57feeed3076137da48c43010130eddbb8e81cb54 (diff) | |
download | bcm5719-llvm-20cf67c233beab21cccbdc23d8b35397fc6cb321.tar.gz bcm5719-llvm-20cf67c233beab21cccbdc23d8b35397fc6cb321.zip |
[OPENMP] Scan all redeclarations looking for `declare simd` attribute.
Patch fixes the problem with the functions marked as `declare simd`. If
the canonical declaration does not have associated `declare simd`
construct, we may not generate required code even if other
redeclarations are marked as `declare simd`.
llvm-svn: 326594
-rw-r--r-- | clang/lib/CodeGen/CGOpenMPRuntime.cpp | 134 | ||||
-rw-r--r-- | clang/test/OpenMP/declare_simd_codegen.cpp | 4 |
2 files changed, 73 insertions, 65 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp index a07bed64127..87097cc2cab 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp @@ -7861,7 +7861,7 @@ emitX86DeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn, void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD, llvm::Function *Fn) { ASTContext &C = CGM.getContext(); - FD = FD->getCanonicalDecl(); + FD = FD->getMostRecentDecl(); // Map params to their positions in function decl. llvm::DenseMap<const Decl *, unsigned> ParamPositions; if (isa<CXXMethodDecl>(FD)) @@ -7871,80 +7871,84 @@ void CGOpenMPRuntime::emitDeclareSimdFunction(const FunctionDecl *FD, ParamPositions.insert({P->getCanonicalDecl(), ParamPos}); ++ParamPos; } - for (auto *Attr : FD->specific_attrs<OMPDeclareSimdDeclAttr>()) { - llvm::SmallVector<ParamAttrTy, 8> ParamAttrs(ParamPositions.size()); - // Mark uniform parameters. - for (auto *E : Attr->uniforms()) { - E = E->IgnoreParenImpCasts(); - unsigned Pos; - if (isa<CXXThisExpr>(E)) - Pos = ParamPositions[FD]; - else { - auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl()) - ->getCanonicalDecl(); - Pos = ParamPositions[PVD]; - } - ParamAttrs[Pos].Kind = Uniform; - } - // Get alignment info. - auto NI = Attr->alignments_begin(); - for (auto *E : Attr->aligneds()) { - E = E->IgnoreParenImpCasts(); - unsigned Pos; - QualType ParmTy; - if (isa<CXXThisExpr>(E)) { - Pos = ParamPositions[FD]; - ParmTy = E->getType(); - } else { - auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl()) - ->getCanonicalDecl(); - Pos = ParamPositions[PVD]; - ParmTy = PVD->getType(); + while (FD) { + for (auto *Attr : FD->specific_attrs<OMPDeclareSimdDeclAttr>()) { + llvm::SmallVector<ParamAttrTy, 8> ParamAttrs(ParamPositions.size()); + // Mark uniform parameters. + for (auto *E : Attr->uniforms()) { + E = E->IgnoreParenImpCasts(); + unsigned Pos; + if (isa<CXXThisExpr>(E)) + Pos = ParamPositions[FD]; + else { + auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl()) + ->getCanonicalDecl(); + Pos = ParamPositions[PVD]; + } + ParamAttrs[Pos].Kind = Uniform; } - ParamAttrs[Pos].Alignment = - (*NI) ? (*NI)->EvaluateKnownConstInt(C) + // Get alignment info. + auto NI = Attr->alignments_begin(); + for (auto *E : Attr->aligneds()) { + E = E->IgnoreParenImpCasts(); + unsigned Pos; + QualType ParmTy; + if (isa<CXXThisExpr>(E)) { + Pos = ParamPositions[FD]; + ParmTy = E->getType(); + } else { + auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl()) + ->getCanonicalDecl(); + Pos = ParamPositions[PVD]; + ParmTy = PVD->getType(); + } + ParamAttrs[Pos].Alignment = + (*NI) + ? (*NI)->EvaluateKnownConstInt(C) : llvm::APSInt::getUnsigned( C.toCharUnitsFromBits(C.getOpenMPDefaultSimdAlign(ParmTy)) .getQuantity()); - ++NI; - } - // Mark linear parameters. - auto SI = Attr->steps_begin(); - auto MI = Attr->modifiers_begin(); - for (auto *E : Attr->linears()) { - E = E->IgnoreParenImpCasts(); - unsigned Pos; - if (isa<CXXThisExpr>(E)) - Pos = ParamPositions[FD]; - else { - auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl()) - ->getCanonicalDecl(); - Pos = ParamPositions[PVD]; + ++NI; } - auto &ParamAttr = ParamAttrs[Pos]; - ParamAttr.Kind = Linear; - if (*SI) { - if (!(*SI)->EvaluateAsInt(ParamAttr.StrideOrArg, C, - Expr::SE_AllowSideEffects)) { - if (auto *DRE = cast<DeclRefExpr>((*SI)->IgnoreParenImpCasts())) { - if (auto *StridePVD = cast<ParmVarDecl>(DRE->getDecl())) { - ParamAttr.Kind = LinearWithVarStride; - ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned( - ParamPositions[StridePVD->getCanonicalDecl()]); + // Mark linear parameters. + auto SI = Attr->steps_begin(); + auto MI = Attr->modifiers_begin(); + for (auto *E : Attr->linears()) { + E = E->IgnoreParenImpCasts(); + unsigned Pos; + if (isa<CXXThisExpr>(E)) + Pos = ParamPositions[FD]; + else { + auto *PVD = cast<ParmVarDecl>(cast<DeclRefExpr>(E)->getDecl()) + ->getCanonicalDecl(); + Pos = ParamPositions[PVD]; + } + auto &ParamAttr = ParamAttrs[Pos]; + ParamAttr.Kind = Linear; + if (*SI) { + if (!(*SI)->EvaluateAsInt(ParamAttr.StrideOrArg, C, + Expr::SE_AllowSideEffects)) { + if (auto *DRE = cast<DeclRefExpr>((*SI)->IgnoreParenImpCasts())) { + if (auto *StridePVD = cast<ParmVarDecl>(DRE->getDecl())) { + ParamAttr.Kind = LinearWithVarStride; + ParamAttr.StrideOrArg = llvm::APSInt::getUnsigned( + ParamPositions[StridePVD->getCanonicalDecl()]); + } } } } + ++SI; + ++MI; } - ++SI; - ++MI; + llvm::APSInt VLENVal; + if (const Expr *VLEN = Attr->getSimdlen()) + VLENVal = VLEN->EvaluateKnownConstInt(C); + OMPDeclareSimdDeclAttr::BranchStateTy State = Attr->getBranchState(); + if (CGM.getTriple().getArch() == llvm::Triple::x86 || + CGM.getTriple().getArch() == llvm::Triple::x86_64) + emitX86DeclareSimdFunction(FD, Fn, VLENVal, ParamAttrs, State); } - llvm::APSInt VLENVal; - if (const Expr *VLEN = Attr->getSimdlen()) - VLENVal = VLEN->EvaluateKnownConstInt(C); - OMPDeclareSimdDeclAttr::BranchStateTy State = Attr->getBranchState(); - if (CGM.getTriple().getArch() == llvm::Triple::x86 || - CGM.getTriple().getArch() == llvm::Triple::x86_64) - emitX86DeclareSimdFunction(FD, Fn, VLENVal, ParamAttrs, State); + FD = FD->getPreviousDecl(); } } diff --git a/clang/test/OpenMP/declare_simd_codegen.cpp b/clang/test/OpenMP/declare_simd_codegen.cpp index b5aba2f5e1d..4ac0b7f03a0 100644 --- a/clang/test/OpenMP/declare_simd_codegen.cpp +++ b/clang/test/OpenMP/declare_simd_codegen.cpp @@ -10,6 +10,8 @@ #ifndef HEADER #define HEADER +void add_1(float *d); + #pragma omp declare simd linear(d : 8) #pragma omp declare simd inbranch simdlen(32) #pragma omp declare simd notinbranch @@ -20,6 +22,8 @@ void add_1(float *d); #pragma omp declare simd notinbranch void add_1(float *d) {} +void add_1(float *d); + #pragma omp declare simd linear(d : 8) #pragma omp declare simd inbranch simdlen(32) #pragma omp declare simd notinbranch |