Skip to content

Commit 21fdc72

Browse files
authored
[NFC][Clang][OpenMP] Change MEH member of AttachPtrExprComparator from pointer to reference. (#161785)
Also adds an instance of `AttachPtrExprComparator` to the `MappableExprHandler` class, so that it can be reused for multiple comparisons. This was extracted out of #153683 to make that PR more focused on the functional changes.
1 parent 842622b commit 21fdc72

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
@@ -6808,28 +6808,29 @@ class MappableExprsHandler {
68086808
/// they were computed by collectAttachPtrExprInfo(), if they are semantically
68096809
/// different.
68106810
struct AttachPtrExprComparator {
6811-
const MappableExprsHandler *Handler = nullptr;
6811+
const MappableExprsHandler &Handler;
68126812
// Cache of previous equality comparison results.
68136813
mutable llvm::DenseMap<std::pair<const Expr *, const Expr *>, bool>
68146814
CachedEqualityComparisons;
68156815

6816-
AttachPtrExprComparator(const MappableExprsHandler *H) : Handler(H) {}
6816+
AttachPtrExprComparator(const MappableExprsHandler &H) : Handler(H) {}
6817+
AttachPtrExprComparator() = delete;
68176818

68186819
// Return true iff LHS is "less than" RHS.
68196820
bool operator()(const Expr *LHS, const Expr *RHS) const {
68206821
if (LHS == RHS)
68216822
return false;
68226823

68236824
// First, compare by complexity (depth)
6824-
const auto ItLHS = Handler->AttachPtrComponentDepthMap.find(LHS);
6825-
const auto ItRHS = Handler->AttachPtrComponentDepthMap.find(RHS);
6825+
const auto ItLHS = Handler.AttachPtrComponentDepthMap.find(LHS);
6826+
const auto ItRHS = Handler.AttachPtrComponentDepthMap.find(RHS);
68266827

68276828
std::optional<size_t> DepthLHS =
6828-
(ItLHS != Handler->AttachPtrComponentDepthMap.end()) ? ItLHS->second
6829-
: std::nullopt;
6829+
(ItLHS != Handler.AttachPtrComponentDepthMap.end()) ? ItLHS->second
6830+
: std::nullopt;
68306831
std::optional<size_t> DepthRHS =
6831-
(ItRHS != Handler->AttachPtrComponentDepthMap.end()) ? ItRHS->second
6832-
: std::nullopt;
6832+
(ItRHS != Handler.AttachPtrComponentDepthMap.end()) ? ItRHS->second
6833+
: std::nullopt;
68336834

68346835
// std::nullopt (no attach pointer) has lowest complexity
68356836
if (!DepthLHS.has_value() && !DepthRHS.has_value()) {
@@ -6877,8 +6878,8 @@ class MappableExprsHandler {
68776878
/// Returns true iff LHS was computed before RHS by
68786879
/// collectAttachPtrExprInfo().
68796880
bool wasComputedBefore(const Expr *LHS, const Expr *RHS) const {
6880-
const size_t &OrderLHS = Handler->AttachPtrComputationOrderMap.at(LHS);
6881-
const size_t &OrderRHS = Handler->AttachPtrComputationOrderMap.at(RHS);
6881+
const size_t &OrderLHS = Handler.AttachPtrComputationOrderMap.at(LHS);
6882+
const size_t &OrderRHS = Handler.AttachPtrComputationOrderMap.at(RHS);
68826883

68836884
return OrderLHS < OrderRHS;
68846885
}
@@ -6897,7 +6898,7 @@ class MappableExprsHandler {
68976898
if (!LHS || !RHS)
68986899
return false;
68996900

6900-
ASTContext &Ctx = Handler->CGF.getContext();
6901+
ASTContext &Ctx = Handler.CGF.getContext();
69016902
// Strip away parentheses and no-op casts to get to the core expression
69026903
LHS = LHS->IgnoreParenNoopCasts(Ctx);
69036904
RHS = RHS->IgnoreParenNoopCasts(Ctx);
@@ -7246,6 +7247,10 @@ class MappableExprsHandler {
72467247
llvm::DenseMap<const Expr *, size_t> AttachPtrComputationOrderMap = {
72477248
{nullptr, 0}};
72487249

7250+
/// An instance of attach-ptr-expr comparator that can be used throughout the
7251+
/// lifetime of this handler.
7252+
AttachPtrExprComparator AttachPtrComparator;
7253+
72497254
llvm::Value *getExprTypeSize(const Expr *E) const {
72507255
QualType ExprTy = E->getType().getCanonicalType();
72517256

@@ -8963,7 +8968,7 @@ class MappableExprsHandler {
89638968

89648969
public:
89658970
MappableExprsHandler(const OMPExecutableDirective &Dir, CodeGenFunction &CGF)
8966-
: CurDir(&Dir), CGF(CGF) {
8971+
: CurDir(&Dir), CGF(CGF), AttachPtrComparator(*this) {
89678972
// Extract firstprivate clause information.
89688973
for (const auto *C : Dir.getClausesOfKind<OMPFirstprivateClause>())
89698974
for (const auto *D : C->varlist())
@@ -9009,7 +9014,7 @@ class MappableExprsHandler {
90099014

90109015
/// Constructor for the declare mapper directive.
90119016
MappableExprsHandler(const OMPDeclareMapperDecl &Dir, CodeGenFunction &CGF)
9012-
: CurDir(&Dir), CGF(CGF) {}
9017+
: CurDir(&Dir), CGF(CGF), AttachPtrComparator(*this) {}
90139018

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

0 commit comments

Comments
 (0)