Skip to content

Conversation

@RitanyaB
Copy link
Owner

No description provided.

Comment on lines 14478 to 14481
if (D && D->hasAttr<OMPDeclareTargetDeclAttr>() && isa<VarDecl>(D)) {
if ((cast<VarDecl>(D))->hasGlobalStorage())
ActOnOpenMPImplicitDeclareTarget(D);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);
}

Comment on lines 23099 to 23105
if (DeclRef) {
Decl *DeclVar = (Decl *)DeclRef->getDecl();
DeclVar->addAttr(TargetDecl->getAttr<OMPDeclareTargetDeclAttr>());
return DeclVar;
} else
return nullptr;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

TargetDecl = AddOMPDeclareTargetDeclAttr(DeclRef, TargetDecl);
}
} else
break;
Copy link
Collaborator

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.

}
} else
break;
} else
Copy link
Collaborator

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.

Suggested change
} else
} else {
...
}

if (isa<Expr>(*it))
VisitMyExpr(dyn_cast<Expr>(*it));
if (isa<DeclRefExpr>(*it))
Visit(*it);
Copy link
Collaborator

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> {
Copy link
Collaborator

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

Comment on lines +14478 to +14482
if (auto *VD = dyn_cast_or_null<VarDecl>(D);
LangOpts.OpenMP && VD && VD->hasAttr<OMPDeclareTargetDeclAttr>() &&
VD->hasGlobalStorage()) {
ActOnOpenMPImplicitDeclareTarget(D);
}
Copy link
Collaborator

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
Copy link
Collaborator

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.

RitanyaB pushed a commit that referenced this pull request Jan 4, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants