This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP] Parsing and sema support for #pragma omp target data" directive.
ClosedPublic

Authored by kkwli0 on Jun 26 2015, 3:42 AM.

Details

Summary

Parsing and sema support for #pragma omp target data

Diff Detail

Event Timeline

kkwli0 updated this revision to Diff 28530.Jun 26 2015, 3:42 AM
kkwli0 retitled this revision from to [OPENMP] Parsing and sema support for #pragma omp target data" directive..
kkwli0 updated this object.
kkwli0 edited the test plan for this revision. (Show Details)
kkwli0 added a subscriber: Unknown Object (MLST).
ABataev added inline comments.Jun 27 2015, 12:06 AM
include/clang/AST/OpenMPClause.h
21 ↗(On Diff #28530)

Header file is not required, remove

131 ↗(On Diff #28530)

Method is not used, so it must be removed

include/clang/AST/StmtOpenMP.h
1821

Some of your changes are not formatted, use clang-format tool.

include/clang/Sema/Sema.h
7860–7862

Format

lib/CodeGen/CGStmtOpenMP.cpp
2103

I think all target related directives should just emit original code at first, so the user could use them.

lib/Parse/ParseOpenMP.cpp
46–58

This code is copied from clang-omp, we're using another solution in official clang. See the patch for 'declare simd' construct (http://reviews.llvm.org/D10599)

kkwli0 added inline comments.Jul 1 2015, 8:03 AM
lib/Parse/ParseOpenMP.cpp
46–58

Perhaps I misunderstand it. The issue of the suggested approach is that it treats 'data' as a directive in order to have { OMPD_target, OMPD_data, OMPD_target_data }. Creating a fake OMPD_data may be confusing. That is why I took this approach.

ABataev edited edge metadata.Jul 1 2015, 8:20 PM

Kelvin, you don't need fake OMPD_data, instead mark it as OMPD_unknown
and check explicitly that 'data' identifier is expected

Best regards,

Alexey Bataev

Software Engineer
Intel Compiler Team

01.07.2015 18:03, Kelvin Li пишет:

Comment at: lib/Parse/ParseOpenMP.cpp:43-55
@@ -42,2 +42,15 @@

: getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));

+
+ switch (DKind) {
+ case OMPD_target: {
+ auto SavedToken = P.getPreprocessor().LookAhead(0);
+ if (!SavedToken.isAnnotation()) {
+ if (P.getPreprocessor().getSpelling(SavedToken) == "data") {
+ DKind = OMPD_target_data;
+ P.ConsumeToken();
+ }
+ }
+ break;
+ }
+ default:

for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {

ABataev wrote:

This code is copied from clang-omp, we're using another solution in official clang. See the patch for 'declare simd' construct (http://reviews.llvm.org/D10599)

Perhaps I misunderstand it. The issue of the suggested approach is that it treats 'data' as a directive in order to have { OMPD_target, OMPD_data, OMPD_target_data }. Creating a fake OMPD_data may be confusing. That is why I took this approach.

http://reviews.llvm.org/D10765

EMAIL PREFERENCES

http://reviews.llvm.org/settings/panel/emailpreferences/
kkwli0 updated this revision to Diff 29206.Jul 7 2015, 1:05 PM
kkwli0 edited edge metadata.

Revised based on comments.

  • Fixed format
  • Added code not to assert in EmitOMPTargetDataDirective
  • Incorporated 'target data' parsing in the current framework
ABataev added a comment.EditedJul 7 2015, 10:16 PM

Seems to me, the updated patch is not correct. It is missing a lot of required things. Besides, new tests were removed from updated patch

include/clang-c/Index.h
2230

Add a cursor for TargetData directive

include/clang/AST/DataRecursiveASTVisitor.h
2407–2410

Add recursive visitor for the new directive

include/clang/AST/RecursiveASTVisitor.h
2439–2442

Add recursive visitor for the new directive

include/clang/Basic/OpenMPKinds.def
95

Add definition of the target data directive

274

There is support for if clause, but macro OPENMP_TARGET_DATA_CLAUSE() is not defined and if clause is not associated with target data directive

include/clang/Basic/StmtNodes.td
206–207

Add a node for target data directive

include/clang/Serialization/ASTBitCodes.h
1399–1400

Add a serialization code for target data directive

lib/CodeGen/CGExpr.cpp
1961 ↗(On Diff #29206)

Bad solution, restore original code. Instead you should capture variables used in the target data directive

lib/CodeGen/CGStmtOpenMP.cpp
2103–2105

Remove braces

2104–2121

In general, this a bad solution. Look at static void emitOMPIfClause() in CGOpenMPRuntime.cpp for better codegen. Your solution won't work with cleanups and exceptions.

lib/CodeGen/CodeGenFunction.h
2218

This one may be just a static function in CGStmtOpenMP.cpp

lib/Parse/ParseOpenMP.cpp
34

Move it to the beginning of the array.

76

Update your patch to the latest revision and sync it with it

kkwli0 updated this revision to Diff 29959.Jul 16 2015, 3:56 PM
  • this is the full diff
  • sync up the code in ParseOpenMPDirectiveKind
  • use the existing infrastructure for generating if clause on target data

Thanks.

ABataev added inline comments.Jul 16 2015, 9:53 PM
lib/CodeGen/CGExpr.cpp
1963 ↗(On Diff #29959)

Restore original file

lib/CodeGen/CGOpenMPRuntime.cpp
1099 ↗(On Diff #29959)
  1. If EmitOMPIfClause is now a part of CodeGenFunction, it must be moved to CGStmtOpenmp.cpp.
  2. The first argument CGF is not required, so remove it and use '*this' instead.
  3. This changes must be committed in a separate patch (for codegen).
lib/CodeGen/CGStmtOpenMP.cpp
2124–2152

As the first commit we can ignore all clauses, just call EmitStmt(cast<CapturedStmt>(S.getAssociateStmt())->getCapturedStmt());

lib/Parse/ParseOpenMP.cpp
65

SDKind == OMPD_unknown

68–69
TokenMatched =
    (i == 0) && !P.getPreprocessor().getSpelling(Tok).compare("point") ||
    (i == 1) && !P.getPreprocessor().getSpelling(Tok).compare("data");
kkwli0 marked 9 inline comments as done.Jul 17 2015, 1:45 PM
kkwli0 added inline comments.
lib/CodeGen/CGOpenMPRuntime.cpp
1099 ↗(On Diff #29959)

Ok. I will leave the changes for the codegen patch.

kkwli0 updated this revision to Diff 30034.Jul 17 2015, 2:01 PM
kkwli0 marked an inline comment as done.
  • excluded the codegen code in EmitOMPTargetDataDirective, it currently just emits the code inside the construct
  • updated ParseOpenMPDirectiveKind for handling "target data"
ABataev accepted this revision.Jul 19 2015, 9:55 PM
ABataev edited edge metadata.
This revision is now accepted and ready to land.Jul 19 2015, 9:55 PM

This has been committed for Kelvin Li.

Command: Commit
Modified: D:\llvmtrunk\tools\clang\include\clang\AST\DataRecursiveASTVisitor.h
Modified: D:\llvmtrunk\tools\clang\include\clang\AST\RecursiveASTVisitor.h
Modified: D:\llvmtrunk\tools\clang\include\clang\AST\StmtOpenMP.h
Modified: D:\llvmtrunk\tools\clang\include\clang\Basic\OpenMPKinds.def
Modified: D:\llvmtrunk\tools\clang\include\clang\Basic\StmtNodes.td
Modified: D:\llvmtrunk\tools\clang\include\clang\Sema\Sema.h
Modified: D:\llvmtrunk\tools\clang\include\clang\Serialization\ASTBitCodes.h
Modified: D:\llvmtrunk\tools\clang\include\clang-c\Index.h
Modified: D:\llvmtrunk\tools\clang\lib\AST\Stmt.cpp
Modified: D:\llvmtrunk\tools\clang\lib\AST\StmtPrinter.cpp
Modified: D:\llvmtrunk\tools\clang\lib\AST\StmtProfile.cpp
Modified: D:\llvmtrunk\tools\clang\lib\Basic\OpenMPKinds.cpp
Modified: D:\llvmtrunk\tools\clang\lib\CodeGen\CGStmt.cpp
Modified: D:\llvmtrunk\tools\clang\lib\CodeGen\CGStmtOpenMP.cpp
Modified: D:\llvmtrunk\tools\clang\lib\CodeGen\CodeGenFunction.h
Modified: D:\llvmtrunk\tools\clang\lib\Parse\ParseOpenMP.cpp
Modified: D:\llvmtrunk\tools\clang\lib\Sema\SemaOpenMP.cpp
Modified: D:\llvmtrunk\tools\clang\lib\Sema\TreeTransform.h
Modified: D:\llvmtrunk\tools\clang\lib\Serialization\ASTReaderStmt.cpp
Modified: D:\llvmtrunk\tools\clang\lib\Serialization\ASTWriterStmt.cpp
Modified: D:\llvmtrunk\tools\clang\lib\StaticAnalyzer\Core\ExprEngine.cpp
Adding: D:\llvmtrunk\tools\clang\test\OpenMP\target_data_ast_print.cpp
Adding: D:\llvmtrunk\tools\clang\test\OpenMP\target_data_if_messages.cpp
Adding: D:\llvmtrunk\tools\clang\test\OpenMP\target_data_messages.c
Modified: D:\llvmtrunk\tools\clang\tools\libclang\CIndex.cpp
Modified: D:\llvmtrunk\tools\clang\tools\libclang\CXCursor.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\AST\StmtPrinter.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\CodeGen\CodeGenFunction.h
Sending content: D:\llvmtrunk\tools\clang\lib\CodeGen\CGStmtOpenMP.cpp
Sending content: D:\llvmtrunk\tools\clang\include\clang\Basic\OpenMPKinds.def
Sending content: D:\llvmtrunk\tools\clang\lib\Sema\TreeTransform.h
Sending content: D:\llvmtrunk\tools\clang\include\clang\AST\DataRecursiveASTVisitor.h
Sending content: D:\llvmtrunk\tools\clang\include\clang\Serialization\ASTBitCodes.h
Sending content: D:\llvmtrunk\tools\clang\include\clang\Basic\StmtNodes.td
Sending content: D:\llvmtrunk\tools\clang\lib\Sema\SemaOpenMP.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\StaticAnalyzer\Core\ExprEngine.cpp
Sending content: D:\llvmtrunk\tools\clang\test\OpenMP\target_data_if_messages.cpp
Sending content: D:\llvmtrunk\tools\clang\include\clang\AST\RecursiveASTVisitor.h
Sending content: D:\llvmtrunk\tools\clang\include\clang-c\Index.h
Sending content: D:\llvmtrunk\tools\clang\lib\AST\StmtProfile.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\Serialization\ASTReaderStmt.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\Parse\ParseOpenMP.cpp
Sending content: D:\llvmtrunk\tools\clang\include\clang\AST\StmtOpenMP.h
Sending content: D:\llvmtrunk\tools\clang\lib\CodeGen\CGStmt.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\Basic\OpenMPKinds.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\Serialization\ASTWriterStmt.cpp
Sending content: D:\llvmtrunk\tools\clang\test\OpenMP\target_data_ast_print.cpp
Sending content: D:\llvmtrunk\tools\clang\test\OpenMP\target_data_messages.c
Sending content: D:\llvmtrunk\tools\clang\tools\libclang\CXCursor.cpp
Sending content: D:\llvmtrunk\tools\clang\lib\AST\Stmt.cpp
Sending content: D:\llvmtrunk\tools\clang\tools\libclang\CIndex.cpp
Sending content: D:\llvmtrunk\tools\clang\include\clang\Sema\Sema.h
Completed: At revision: 242785

ABataev closed this revision.Jul 21 2015, 8:10 PM