-
Notifications
You must be signed in to change notification settings - Fork 0
Support for declare target initializers #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
clang/lib/Sema/SemaDecl.cpp
Outdated
| if (D && D->hasAttr<OMPDeclareTargetDeclAttr>() && isa<VarDecl>(D)) { | ||
| if ((cast<VarDecl>(D))->hasGlobalStorage()) | ||
| ActOnOpenMPImplicitDeclareTarget(D); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (D && D->hasAttr<OMPDeclareTargetDeclAttr>() && isa<VarDecl>(D)) { | |
| if ((cast<VarDecl>(D))->hasGlobalStorage()) | |
| ActOnOpenMPImplicitDeclareTarget(D); | |
| } | |
| if (D && D->hasAttr<OMPDeclareTargetDeclAttr>() && | |
| isa<VarDecl>(D) && cast<VarDecl>(D))->hasGlobalStorage()) { | |
| ActOnOpenMPImplicitDeclareTarget(D); | |
| } |
clang/lib/Sema/SemaOpenMP.cpp
Outdated
| if (DeclRef) { | ||
| Decl *DeclVar = (Decl *)DeclRef->getDecl(); | ||
| DeclVar->addAttr(TargetDecl->getAttr<OMPDeclareTargetDeclAttr>()); | ||
| return DeclVar; | ||
| } else | ||
| return nullptr; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (DeclRef) { | |
| Decl *DeclVar = (Decl *)DeclRef->getDecl(); | |
| DeclVar->addAttr(TargetDecl->getAttr<OMPDeclareTargetDeclAttr>()); | |
| return DeclVar; | |
| } else | |
| return nullptr; | |
| } | |
| Decl *DeclVar = nullptr; | |
| if (DeclRef) { | |
| DeclVar = (Decl *)DeclRef->getDecl(); | |
| DeclVar->addAttr(TargetDecl->getAttr<OMPDeclareTargetDeclAttr>()); | |
| } | |
| return DeclVar; |
Also, correct the alignment.
clang/lib/Sema/SemaOpenMP.cpp
Outdated
| TargetDecl = AddOMPDeclareTargetDeclAttr(DeclRef, TargetDecl); | ||
| } | ||
| } else | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add explicit comments against each break stating that the rest of the elements will not be processed along with the reason.
clang/lib/Sema/SemaOpenMP.cpp
Outdated
| } | ||
| } else | ||
| break; | ||
| } else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always use braces in such complex statements to help readability.
| } else | |
| } else { | |
| ... | |
| } |
| if (isa<Expr>(*it)) | ||
| VisitMyExpr(dyn_cast<Expr>(*it)); | ||
| if (isa<DeclRefExpr>(*it)) | ||
| Visit(*it); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am assuming this Visit() calls the MyStmtVisitor::VisitDeclRefExpr() indirectly via overriding, as *it is a DeclRefExpr. Why not call MyStmtVisitor::VisitDeclRefExpr() yourself, if you know that *it is a DeclRefExpr ?
| checkDeclInTargetContext(E->getExprLoc(), E->getSourceRange(), *this, D); | ||
| } | ||
|
|
||
| class MyStmtVisitor final : public ConstStmtVisitor<MyStmtVisitor> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggesting not to use My in the class and method names
| if (auto *VD = dyn_cast_or_null<VarDecl>(D); | ||
| LangOpts.OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() && | ||
| VD->hasGlobalStorage()) { | ||
| ActOnOpenMPImplicitDeclareTarget(D); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you run git-clang-format on all your changes ?
| checkDeclIsAllowedInOpenMPTarget(Expr *E, Decl *D, | ||
| SourceLocation IdLoc = SourceLocation()); | ||
|
|
||
| /// Adds OMPDeclareTargetDeclAttr to referenced variables in declare target |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of explaining what the function does literally, a comment describing the goal of the function would be easier to understand.
When shl is folded in compare instruction, a miscompilation occurs when the CMP instruction is also sign-extended. For the following IR: %op3 = shl i8 %op2, 3 %tmp3 = icmp eq i8 %tmp2, %op3 It used to generate cmp w8, w9, sxtb #3 which means sign extend w9, shift left by 3, and then compare with the value in w8. However, the original intention of the IR would require `%op2` to first shift left before extending the operands in the comparison operation . Moreover, if sign extension is used instead of zero extension, the sample test would miscompile. This PR creates a fix for the issue, more specifically to not fold the left shift into the CMP instruction, and to create a zero-extended value rather than a sign-extended value.
No description provided.