Skip to content

Commit 32efd7b

Browse files
committed
[NFC][Clang][OpenMP] Change MEH member of AttachPtrExprComparator from pointer to reference.
Also adds an instance of `AttachPtrExprComparator` to the `MappableExprHandler` class, so that it can be reused for multiple comparisons. This was extracted out of llvm#153683 to make that PR more focused on the functional changes.
1 parent 39ed57c commit 32efd7b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6804,28 +6804,29 @@ class MappableExprsHandler {
68046804
/// they were computed by collectAttachPtrExprInfo(), if they are semantically
68056805
/// different.
68066806
struct AttachPtrExprComparator {
6807-
const MappableExprsHandler *Handler = nullptr;
6807+
const MappableExprsHandler &Handler;
68086808
// Cache of previous equality comparison results.
68096809
mutable llvm::DenseMap<std::pair<const Expr *, const Expr *>, bool>
68106810
CachedEqualityComparisons;
68116811

6812-
AttachPtrExprComparator(const MappableExprsHandler *H) : Handler(H) {}
6812+
AttachPtrExprComparator(const MappableExprsHandler &H) : Handler(H) {}
6813+
AttachPtrExprComparator() = delete;
68136814

68146815
// Return true iff LHS is "less than" RHS.
68156816
bool operator()(const Expr *LHS, const Expr *RHS) const {
68166817
if (LHS == RHS)
68176818
return false;
68186819

68196820
// First, compare by complexity (depth)
6820-
const auto ItLHS = Handler->AttachPtrComponentDepthMap.find(LHS);
6821-
const auto ItRHS = Handler->AttachPtrComponentDepthMap.find(RHS);
6821+
const auto ItLHS = Handler.AttachPtrComponentDepthMap.find(LHS);
6822+
const auto ItRHS = Handler.AttachPtrComponentDepthMap.find(RHS);
68226823

68236824
std::optional<size_t> DepthLHS =
6824-
(ItLHS != Handler->AttachPtrComponentDepthMap.end()) ? ItLHS->second
6825-
: std::nullopt;
6825+
(ItLHS != Handler.AttachPtrComponentDepthMap.end()) ? ItLHS->second
6826+
: std::nullopt;
68266827
std::optional<size_t> DepthRHS =
6827-
(ItRHS != Handler->AttachPtrComponentDepthMap.end()) ? ItRHS->second
6828-
: std::nullopt;
6828+
(ItRHS != Handler.AttachPtrComponentDepthMap.end()) ? ItRHS->second
6829+
: std::nullopt;
68296830

68306831
// std::nullopt (no attach pointer) has lowest complexity
68316832
if (!DepthLHS.has_value() && !DepthRHS.has_value()) {
@@ -6873,8 +6874,8 @@ class MappableExprsHandler {
68736874
/// Returns true iff LHS was computed before RHS by
68746875
/// collectAttachPtrExprInfo().
68756876
bool wasComputedBefore(const Expr *LHS, const Expr *RHS) const {
6876-
const size_t &OrderLHS = Handler->AttachPtrComputationOrderMap.at(LHS);
6877-
const size_t &OrderRHS = Handler->AttachPtrComputationOrderMap.at(RHS);
6877+
const size_t &OrderLHS = Handler.AttachPtrComputationOrderMap.at(LHS);
6878+
const size_t &OrderRHS = Handler.AttachPtrComputationOrderMap.at(RHS);
68786879

68796880
return OrderLHS < OrderRHS;
68806881
}
@@ -6893,7 +6894,7 @@ class MappableExprsHandler {
68936894
if (!LHS || !RHS)
68946895
return false;
68956896

6896-
ASTContext &Ctx = Handler->CGF.getContext();
6897+
ASTContext &Ctx = Handler.CGF.getContext();
68976898
// Strip away parentheses and no-op casts to get to the core expression
68986899
LHS = LHS->IgnoreParenNoopCasts(Ctx);
68996900
RHS = RHS->IgnoreParenNoopCasts(Ctx);
@@ -7242,6 +7243,10 @@ class MappableExprsHandler {
72427243
llvm::DenseMap<const Expr *, size_t> AttachPtrComputationOrderMap = {
72437244
{nullptr, 0}};
72447245

7246+
/// An instance of attach-ptr-expr comparator that can be used throughout the
7247+
/// lifetime of this handler.
7248+
AttachPtrExprComparator AttachPtrComparator;
7249+
72457250
llvm::Value *getExprTypeSize(const Expr *E) const {
72467251
QualType ExprTy = E->getType().getCanonicalType();
72477252

@@ -8959,7 +8964,7 @@ class MappableExprsHandler {
89598964

89608965
public:
89618966
MappableExprsHandler(const OMPExecutableDirective &Dir, CodeGenFunction &CGF)
8962-
: CurDir(&Dir), CGF(CGF) {
8967+
: CurDir(&Dir), CGF(CGF), AttachPtrComparator(*this) {
89638968
// Extract firstprivate clause information.
89648969
for (const auto *C : Dir.getClausesOfKind<OMPFirstprivateClause>())
89658970
for (const auto *D : C->varlist())
@@ -9005,7 +9010,7 @@ class MappableExprsHandler {
90059010

90069011
/// Constructor for the declare mapper directive.
90079012
MappableExprsHandler(const OMPDeclareMapperDecl &Dir, CodeGenFunction &CGF)
9008-
: CurDir(&Dir), CGF(CGF) {}
9013+
: CurDir(&Dir), CGF(CGF), AttachPtrComparator(*this) {}
90099014

90109015
/// Generate code for the combined entry if we have a partially mapped struct
90119016
/// and take care of the mapping flags of the arguments corresponding to

0 commit comments

Comments
 (0)