[Clang][OpenMP] Use bitfields for flags in `OMPAtomicDirective`

As suggested in D120290.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D123862
This commit is contained in:
Shilei Tian 2022-04-15 21:34:19 -04:00
parent 33b604d1c3
commit e8760b51ee
3 changed files with 28 additions and 25 deletions

View File

@ -2827,25 +2827,28 @@ public:
class OMPAtomicDirective : public OMPExecutableDirective {
friend class ASTStmtReader;
friend class OMPExecutableDirective;
/// Used for 'atomic update' or 'atomic capture' constructs. They may
/// have atomic expressions of forms
/// \code
/// x = x binop expr;
/// x = expr binop x;
/// \endcode
/// This field is true for the first form of the expression and false for the
/// second. Required for correct codegen of non-associative operations (like
/// << or >>).
bool IsXLHSInRHSPart = false;
/// Used for 'atomic update' or 'atomic capture' constructs. They may
/// have atomic expressions of forms
/// \code
/// v = x; <update x>;
/// <update x>; v = x;
/// \endcode
/// This field is true for the first(postfix) form of the expression and false
/// otherwise.
bool IsPostfixUpdate = false;
struct FlagTy {
/// Used for 'atomic update' or 'atomic capture' constructs. They may
/// have atomic expressions of forms:
/// \code
/// x = x binop expr;
/// x = expr binop x;
/// \endcode
/// This field is 1 for the first form of the expression and 0 for the
/// second. Required for correct codegen of non-associative operations (like
/// << or >>).
uint8_t IsXLHSInRHSPart : 1;
/// Used for 'atomic update' or 'atomic capture' constructs. They may
/// have atomic expressions of forms:
/// \code
/// v = x; <update x>;
/// <update x>; v = x;
/// \endcode
/// This field is 1 for the first(postfix) form of the expression and 0
/// otherwise.
uint8_t IsPostfixUpdate : 1;
} Flags;
/// Build directive with the given start and end location.
///
@ -2956,10 +2959,10 @@ public:
/// Return true if helper update expression has form
/// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form
/// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'.
bool isXLHSInRHSPart() const { return IsXLHSInRHSPart; }
bool isXLHSInRHSPart() const { return Flags.IsXLHSInRHSPart; }
/// Return true if 'v' expression must be updated to original value of
/// 'x', false if 'v' must be updated to the new value of 'x'.
bool isPostfixUpdate() const { return IsPostfixUpdate; }
bool isPostfixUpdate() const { return Flags.IsPostfixUpdate; }
/// Get 'v' part of the associated expression/statement.
Expr *getV() {
return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_V]);

View File

@ -875,8 +875,8 @@ OMPAtomicDirective::Create(const ASTContext &C, SourceLocation StartLoc,
Dir->setUpdateExpr(Exprs.UE);
Dir->setD(Exprs.D);
Dir->setCond(Exprs.Cond);
Dir->IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart;
Dir->IsPostfixUpdate = Exprs.IsPostfixUpdate;
Dir->Flags.IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart ? 1 : 0;
Dir->Flags.IsPostfixUpdate = Exprs.IsPostfixUpdate ? 1 : 0;
return Dir;
}

View File

@ -2449,8 +2449,8 @@ void ASTStmtReader::VisitOMPOrderedDirective(OMPOrderedDirective *D) {
void ASTStmtReader::VisitOMPAtomicDirective(OMPAtomicDirective *D) {
VisitStmt(D);
VisitOMPExecutableDirective(D);
D->IsXLHSInRHSPart = Record.readBool();
D->IsPostfixUpdate = Record.readBool();
D->Flags.IsXLHSInRHSPart = Record.readBool() ? 1 : 0;
D->Flags.IsPostfixUpdate = Record.readBool() ? 1 : 0;
}
void ASTStmtReader::VisitOMPTargetDirective(OMPTargetDirective *D) {