From: Alexey Bataev Date: Thu, 31 Mar 2016 09:30:50 +0000 (+0000) Subject: [OPENMP] Support dumping OpenMP specific constructs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4364dc24d8492f0c312d05548acaefdef70b3653;p=clang [OPENMP] Support dumping OpenMP specific constructs. Add proper dumping support for OpenMP declarations, directives and clauses. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265004 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/ASTDumper.cpp b/lib/AST/ASTDumper.cpp index 872420606b..027889747e 100644 --- a/lib/AST/ASTDumper.cpp +++ b/lib/AST/ASTDumper.cpp @@ -18,6 +18,7 @@ #include "clang/AST/DeclCXX.h" #include "clang/AST/DeclLookups.h" #include "clang/AST/DeclObjC.h" +#include "clang/AST/DeclOpenMP.h" #include "clang/AST/DeclVisitor.h" #include "clang/AST/LocInfoType.h" #include "clang/AST/StmtVisitor.h" @@ -428,6 +429,12 @@ namespace { void VisitImportDecl(const ImportDecl *D); void VisitPragmaCommentDecl(const PragmaCommentDecl *D); void VisitPragmaDetectMismatchDecl(const PragmaDetectMismatchDecl *D); + void VisitCapturedDecl(const CapturedDecl *D); + + // OpenMP decls + void VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D); + void VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D); + void VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D); // C++ Decls void VisitNamespaceDecl(const NamespaceDecl *D); @@ -489,6 +496,10 @@ namespace { void VisitLabelStmt(const LabelStmt *Node); void VisitGotoStmt(const GotoStmt *Node); void VisitCXXCatchStmt(const CXXCatchStmt *Node); + void VisitCapturedStmt(const CapturedStmt *Node); + + // OpenMP + void VisitOMPExecutableDirective(const OMPExecutableDirective *Node); // Exprs void VisitExpr(const Expr *Node); @@ -1222,6 +1233,35 @@ void ASTDumper::VisitPragmaDetectMismatchDecl( OS << " \"" << D->getName() << "\" \"" << D->getValue() << "\""; } +void ASTDumper::VisitCapturedDecl(const CapturedDecl *D) { + dumpStmt(D->getBody()); +} + +//===----------------------------------------------------------------------===// +// OpenMP Declarations +//===----------------------------------------------------------------------===// + +void ASTDumper::VisitOMPThreadPrivateDecl(const OMPThreadPrivateDecl *D) { + for (auto *E : D->varlists()) + dumpStmt(E); +} + +void ASTDumper::VisitOMPDeclareReductionDecl(const OMPDeclareReductionDecl *D) { + dumpName(D); + dumpType(D->getType()); + OS << " combiner"; + dumpStmt(D->getCombiner()); + if (auto *Initializer = D->getInitializer()) { + OS << " initializer"; + dumpStmt(Initializer); + } +} + +void ASTDumper::VisitOMPCapturedExprDecl(const OMPCapturedExprDecl *D) { + dumpName(D); + dumpType(D->getType()); + dumpStmt(D->getInit()); +} //===----------------------------------------------------------------------===// // C++ Declarations @@ -1730,6 +1770,41 @@ void ASTDumper::VisitCXXCatchStmt(const CXXCatchStmt *Node) { dumpDecl(Node->getExceptionDecl()); } +void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) { + VisitStmt(Node); + dumpDecl(Node->getCapturedDecl()); +} + +//===----------------------------------------------------------------------===// +// OpenMP dumping methods. +//===----------------------------------------------------------------------===// + +void ASTDumper::VisitOMPExecutableDirective( + const OMPExecutableDirective *Node) { + VisitStmt(Node); + for (auto *C : Node->clauses()) { + dumpChild([=] { + if (!C) { + ColorScope Color(*this, NullColor); + OS << "<<>> OMPClause"; + return; + } + { + ColorScope Color(*this, AttrColor); + StringRef ClauseName(getOpenMPClauseName(C->getClauseKind())); + OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper() + << ClauseName.drop_front() << "Clause"; + } + dumpPointer(C); + dumpSourceRange(SourceRange(C->getLocStart(), C->getLocEnd())); + if (C->isImplicit()) + OS << " "; + for (auto *S : C->children()) + dumpStmt(S); + }); + } +} + //===----------------------------------------------------------------------===// // Expr dumping methods. //===----------------------------------------------------------------------===// diff --git a/test/OpenMP/dump.cpp b/test/OpenMP/dump.cpp new file mode 100644 index 0000000000..5059a04462 --- /dev/null +++ b/test/OpenMP/dump.cpp @@ -0,0 +1,68 @@ +// RUN: %clang_cc1 -verify -fopenmp -ast-dump %s | FileCheck %s +// expected-no-diagnostics + +int ga, gb; +#pragma omp threadprivate(ga, gb) + +// CHECK: |-OMPThreadPrivateDecl {{.+}} col:9 +// CHECK-NEXT: | |-DeclRefExpr {{.+}} 'int' lvalue Var {{.+}} 'ga' 'int' +// CHECK-NEXT: | `-DeclRefExpr {{.+}} 'int' lvalue Var {{.+}} 'gb' 'int' + +#pragma omp declare reduction(+ : int, char : omp_out *= omp_in) + +#pragma omp declare reduction(fun : float : omp_out += omp_in) initializer(omp_priv = omp_orig + 15) + +// CHECK: |-OMPDeclareReductionDecl {{.+}} col:35 operator+ 'int' combiner +// CHECK-NEXT: | |-CompoundAssignOperator {{.+}} 'int' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int' +// CHECK-NEXT: | | |-DeclRefExpr {{.+}} 'int' lvalue Var {{.+}} 'omp_out' 'int' +// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} 'int' +// CHECK-NEXT: | | `-DeclRefExpr {{.+}} 'int' lvalue Var {{.+}} 'omp_in' 'int' +// CHECK-NEXT: | |-VarDecl {{.+}} col:35 implicit used omp_in 'int' +// CHECK-NEXT: | `-VarDecl {{.+}} col:35 implicit used omp_out 'int' +// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}} col:40 operator+ 'char' combiner +// CHECK-NEXT: | |-CompoundAssignOperator {{.+}} 'char' lvalue '*=' ComputeLHSTy='int' ComputeResultTy='int' +// CHECK-NEXT: | | |-DeclRefExpr {{.+}} 'char' lvalue Var {{.+}} 'omp_out' 'char' +// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} 'int' +// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} 'char' +// CHECK-NEXT: | | `-DeclRefExpr {{.+}} 'char' lvalue Var {{.+}} 'omp_in' 'char' +// CHECK-NEXT: | |-VarDecl {{.+}} col:40 implicit used omp_in 'char' +// CHECK-NEXT: | `-VarDecl {{.+}} col:40 implicit used omp_out 'char' +// CHECK-NEXT: |-OMPDeclareReductionDecl {{.+}} col:37 fun 'float' combiner initializer +// CHECK-NEXT: | |-CompoundAssignOperator {{.+}} 'float' lvalue '+=' ComputeLHSTy='float' ComputeResultTy='float' +// CHECK-NEXT: | | |-DeclRefExpr {{.+}} 'float' lvalue Var {{.+}} 'omp_out' 'float' +// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} 'float' +// CHECK-NEXT: | | `-DeclRefExpr {{.+}} 'float' lvalue Var {{.+}} 'omp_in' 'float' + +struct S { + int a, b; + S() { +#pragma omp parallel for default(none) private(a) shared(b) schedule(static, a) + for (int i = 0; i < 0; ++i) + ++a; + } +}; + +// CHECK: | `-OMPParallelForDirective {{.+}} +// CHECK-NEXT: | |-OMPDefaultClause {{.+}} +// CHECK-NEXT: | |-OMPPrivateClause {{.+}} +// CHECK-NEXT: | | `-DeclRefExpr {{.+}} 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &' +// CHECK-NEXT: | |-OMPSharedClause {{.+}} +// CHECK-NEXT: | | `-MemberExpr {{.+}} 'int' lvalue ->b +// CHECK-NEXT: | | `-CXXThisExpr {{.+}} 'struct S *' this +// CHECK-NEXT: | |-OMPScheduleClause {{.+}} +// CHECK-NEXT: | | `-ImplicitCastExpr {{.+}} 'int' +// CHECK-NEXT: | | `-DeclRefExpr {{.+}} 'int' lvalue OMPCapturedExpr {{.+}} '.capture_expr.' 'int' +// CHECK-NEXT: | |-CapturedStmt {{.+}} > +// CHECK-NEXT: | | |-CapturedDecl {{.+}} <> +// CHECK-NEXT: | | | |-ForStmt {{.+}} > +// CHECK: | | | | `-UnaryOperator {{.+}} > 'int' lvalue prefix '++' +// CHECK-NEXT: | | | | `-DeclRefExpr {{.+}} <> 'int' lvalue OMPCapturedExpr {{.+}} 'a' 'int &' + +#pragma omp declare simd +#pragma omp declare simd +void foo(); + +// CHECK: `-FunctionDecl {{.+}} col:6 foo 'void (void)' +// CHECK-NEXT: |-OMPDeclareSimdDeclAttr {{.+}} Implicit +// CHECK-NEXT: `-OMPDeclareSimdDeclAttr {{.+}} Implicit +