This patch fixes a bug in code generation of the correct OpenMP runtime library call in presence of target and teams, when target is separated by teams with multiple curly brackets. The current implementation will not be able to see the teams directive inside target and issue a call to tgt_target instead of the correct one tgt_target_teams.
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks for the fix!
lib/CodeGen/CGOpenMPRuntime.cpp | ||
---|---|---|
4265 | I think that this can be simplified to: while (auto *S = dyn_cast<CompoundStmt>(TargetBody)) TargetBody = S->body_front(); return dyn_cast<CompoundStmt>(OMPTeamsDirective); I know that this is currently used only for teams, but I think it would be nice to make this a templated function to look for other possible nests. I suspect this will very useful for other cases like 'target teams parallel distribute'. |
lib/CodeGen/CGOpenMPRuntime.cpp | ||
---|---|---|
4265 | Thanks! I agree that having this as a template will help with combined directives. I will produce a new version of the patch with that support. About your new loop: this would crash if S->body_front() is nullptr. This may happen if you have something like this: #target { } A solution may be while (auto *S = dyn_cast_or_null<CompoundStmt>(TargetBody)) TargetBody = S->body_front(); return dyn_cast_or_null<CompoundStmt>(OMPTeamsDirective); Thoughts? |
lib/CodeGen/CGOpenMPRuntime.cpp | ||
---|---|---|
4265 | You're totally right, dyn_cast_or_null is the right cast to use in the return statement. |
lib/CodeGen/CGOpenMPRuntime.cpp | ||
---|---|---|
4265 | You don't need SK, because body_front() member function exists only in CompoundStmt. |
Alexey
Thanks for the review. I addressed your comment in a new version of the revision.
Samuel already reviewed the patch, as you can see in the message exchange. I am very happy to apply any design change you can think of.
- Carlo
lib/CodeGen/CGOpenMPRuntime.cpp | ||
---|---|---|
4260–4273 | I don't like this function at all. We need to add a template function. Each instantiation will produce a new function with almost the same body. MI prepfer to see another solution, like: static const Stmt *ignoreCompoundStmts(const Stmt *Body) { while (auto *CS = dyn_cast_or_null<CompoundStmt>(Body)) Body = CS->body_front(); return Body; } ... if (auto *TeamsDir = dyn_cast<OMPTeamsDirective>(ignoreCompoundStmts(CS.getCapturedStmt()))) { ... |
Great, thanks for the hint. I do much prefer your version of the function. I am updating the diff.
LG, except for the small comment
lib/CodeGen/CGOpenMPRuntime.cpp | ||
---|---|---|
4260 | \brief tag is not required anymore, just a brief description is required. |
\brief tag is not required anymore, just a brief description is required.