[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 { class OMPAtomicDirective : public OMPExecutableDirective {
friend class ASTStmtReader; friend class ASTStmtReader;
friend class OMPExecutableDirective; friend class OMPExecutableDirective;
struct FlagTy {
/// Used for 'atomic update' or 'atomic capture' constructs. They may /// Used for 'atomic update' or 'atomic capture' constructs. They may
/// have atomic expressions of forms /// have atomic expressions of forms:
/// \code /// \code
/// x = x binop expr; /// x = x binop expr;
/// x = expr binop x; /// x = expr binop x;
/// \endcode /// \endcode
/// This field is true for the first form of the expression and false for the /// 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 /// second. Required for correct codegen of non-associative operations (like
/// << or >>). /// << or >>).
bool IsXLHSInRHSPart = false; uint8_t IsXLHSInRHSPart : 1;
/// Used for 'atomic update' or 'atomic capture' constructs. They may /// Used for 'atomic update' or 'atomic capture' constructs. They may
/// have atomic expressions of forms /// have atomic expressions of forms:
/// \code /// \code
/// v = x; <update x>; /// v = x; <update x>;
/// <update x>; v = x; /// <update x>; v = x;
/// \endcode /// \endcode
/// This field is true for the first(postfix) form of the expression and false /// This field is 1 for the first(postfix) form of the expression and 0
/// otherwise. /// otherwise.
bool IsPostfixUpdate = false; uint8_t IsPostfixUpdate : 1;
} Flags;
/// Build directive with the given start and end location. /// Build directive with the given start and end location.
/// ///
@ -2956,10 +2959,10 @@ public:
/// Return true if helper update expression has form /// Return true if helper update expression has form
/// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form /// 'OpaqueValueExpr(x) binop OpaqueValueExpr(expr)' and false if it has form
/// 'OpaqueValueExpr(expr) binop OpaqueValueExpr(x)'. /// '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 /// 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'. /// '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. /// Get 'v' part of the associated expression/statement.
Expr *getV() { Expr *getV() {
return cast_or_null<Expr>(Data->getChildren()[DataPositionTy::POS_V]); 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->setUpdateExpr(Exprs.UE);
Dir->setD(Exprs.D); Dir->setD(Exprs.D);
Dir->setCond(Exprs.Cond); Dir->setCond(Exprs.Cond);
Dir->IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart; Dir->Flags.IsXLHSInRHSPart = Exprs.IsXLHSInRHSPart ? 1 : 0;
Dir->IsPostfixUpdate = Exprs.IsPostfixUpdate; Dir->Flags.IsPostfixUpdate = Exprs.IsPostfixUpdate ? 1 : 0;
return Dir; return Dir;
} }

View File

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