2828#include "clang/Basic/SourceManager.h"
2929#include "clang/CodeGen/ConstantInitBuilder.h"
3030#include "llvm/ADT/ArrayRef.h"
31- #include "llvm/ADT/SmallSet.h"
3231#include "llvm/ADT/SmallVector.h"
3332#include "llvm/ADT/StringExtras.h"
3433#include "llvm/Bitcode/BitcodeReader.h"
@@ -7261,9 +7260,6 @@ class MappableExprsHandler {
72617260 /// firstprivate, false otherwise.
72627261 llvm::DenseMap<CanonicalDeclPtr<const VarDecl>, bool> FirstPrivateDecls;
72637262
7264- /// Set of defaultmap clause kinds that use firstprivate behavior.
7265- llvm::SmallSet<OpenMPDefaultmapClauseKind, 4> DefaultmapFirstprivateKinds;
7266-
72677263 /// Map between device pointer declarations and their expression components.
72687264 /// The key value for declarations in 'this' is null.
72697265 llvm::DenseMap<
@@ -9042,10 +9038,6 @@ class MappableExprsHandler {
90429038 FirstPrivateDecls.try_emplace(VD, /*Implicit=*/true);
90439039 }
90449040 }
9045- // Extract defaultmap clause information.
9046- for (const auto *C : Dir.getClausesOfKind<OMPDefaultmapClause>())
9047- if (C->getDefaultmapModifier() == OMPC_DEFAULTMAP_MODIFIER_firstprivate)
9048- DefaultmapFirstprivateKinds.insert(C->getDefaultmapKind());
90499041 // Extract device pointer clause information.
90509042 for (const auto *C : Dir.getClausesOfKind<OMPIsDevicePtrClause>())
90519043 for (auto L : C->component_lists())
@@ -9623,35 +9615,6 @@ class MappableExprsHandler {
96239615 }
96249616 }
96259617
9626- /// Check if a variable should be treated as firstprivate due to explicit
9627- /// firstprivate clause or defaultmap(firstprivate:...).
9628- bool isEffectivelyFirstprivate(const VarDecl *VD, QualType Type) const {
9629- // Check explicit firstprivate clauses
9630- if (FirstPrivateDecls.count(VD))
9631- return true;
9632-
9633- // Check defaultmap(firstprivate:scalar) for scalar types
9634- if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_scalar)) {
9635- if (Type->isScalarType())
9636- return true;
9637- }
9638-
9639- // Check defaultmap(firstprivate:pointer) for pointer types
9640- if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_pointer)) {
9641- if (Type->isAnyPointerType())
9642- return true;
9643- }
9644-
9645- // Check defaultmap(firstprivate:aggregate) for aggregate types
9646- if (DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_aggregate)) {
9647- if (Type->isAggregateType())
9648- return true;
9649- }
9650-
9651- // Check defaultmap(firstprivate:all) for all types
9652- return DefaultmapFirstprivateKinds.count(OMPC_DEFAULTMAP_all);
9653- }
9654-
96559618 /// Generate the default map information for a given capture \a CI,
96569619 /// record field declaration \a RI and captured value \a CV.
96579620 void generateDefaultMapInfo(const CapturedStmt::Capture &CI,
@@ -9679,23 +9642,13 @@ class MappableExprsHandler {
96799642 CombinedInfo.DevicePtrDecls.push_back(nullptr);
96809643 CombinedInfo.DevicePointers.push_back(DeviceInfoTy::None);
96819644 CombinedInfo.Pointers.push_back(CV);
9682- bool IsFirstprivate =
9683- isEffectivelyFirstprivate(VD, RI.getType().getNonReferenceType());
9684-
96859645 if (!RI.getType()->isAnyPointerType()) {
96869646 // We have to signal to the runtime captures passed by value that are
96879647 // not pointers.
96889648 CombinedInfo.Types.push_back(
96899649 OpenMPOffloadMappingFlags::OMP_MAP_LITERAL);
96909650 CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(
96919651 CGF.getTypeSize(RI.getType()), CGF.Int64Ty, /*isSigned=*/true));
9692- } else if (IsFirstprivate) {
9693- // Firstprivate pointers should be passed by value (as literals)
9694- // without performing a present table lookup at runtime.
9695- CombinedInfo.Types.push_back(
9696- OpenMPOffloadMappingFlags::OMP_MAP_LITERAL);
9697- // Use zero size for pointer literals (just passing the pointer value)
9698- CombinedInfo.Sizes.push_back(llvm::Constant::getNullValue(CGF.Int64Ty));
96999652 } else {
97009653 // Pointers are implicitly mapped with a zero size and no flags
97019654 // (other than first map that is added for all implicit maps).
@@ -9709,31 +9662,26 @@ class MappableExprsHandler {
97099662 assert(CI.capturesVariable() && "Expected captured reference.");
97109663 const auto *PtrTy = cast<ReferenceType>(RI.getType().getTypePtr());
97119664 QualType ElementType = PtrTy->getPointeeType();
9665+ CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(
9666+ CGF.getTypeSize(ElementType), CGF.Int64Ty, /*isSigned=*/true));
9667+ // The default map type for a scalar/complex type is 'to' because by
9668+ // default the value doesn't have to be retrieved. For an aggregate
9669+ // type, the default is 'tofrom'.
9670+ CombinedInfo.Types.push_back(getMapModifiersForPrivateClauses(CI));
97129671 const VarDecl *VD = CI.getCapturedVar();
9713- bool IsFirstprivate = isEffectivelyFirstprivate (VD, ElementType );
9672+ auto I = FirstPrivateDecls.find (VD);
97149673 CombinedInfo.Exprs.push_back(VD->getCanonicalDecl());
97159674 CombinedInfo.BasePointers.push_back(CV);
97169675 CombinedInfo.DevicePtrDecls.push_back(nullptr);
97179676 CombinedInfo.DevicePointers.push_back(DeviceInfoTy::None);
9718-
9719- // For firstprivate pointers, pass by value instead of dereferencing
9720- if (IsFirstprivate && ElementType->isAnyPointerType()) {
9721- // Treat as a literal value (pass the pointer value itself)
9722- CombinedInfo.Pointers.push_back(CV);
9723- // Use zero size for pointer literals
9724- CombinedInfo.Sizes.push_back(llvm::Constant::getNullValue(CGF.Int64Ty));
9725- CombinedInfo.Types.push_back(
9726- OpenMPOffloadMappingFlags::OMP_MAP_LITERAL);
9677+ if (I != FirstPrivateDecls.end() && ElementType->isAnyPointerType()) {
9678+ Address PtrAddr = CGF.EmitLoadOfReference(CGF.MakeAddrLValue(
9679+ CV, ElementType, CGF.getContext().getDeclAlign(VD),
9680+ AlignmentSource::Decl));
9681+ CombinedInfo.Pointers.push_back(PtrAddr.emitRawPointer(CGF));
97279682 } else {
9728- CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(
9729- CGF.getTypeSize(ElementType), CGF.Int64Ty, /*isSigned=*/true));
9730- // The default map type for a scalar/complex type is 'to' because by
9731- // default the value doesn't have to be retrieved. For an aggregate
9732- // type, the default is 'tofrom'.
9733- CombinedInfo.Types.push_back(getMapModifiersForPrivateClauses(CI));
97349683 CombinedInfo.Pointers.push_back(CV);
97359684 }
9736- auto I = FirstPrivateDecls.find(VD);
97379685 if (I != FirstPrivateDecls.end())
97389686 IsImplicit = I->getSecond();
97399687 }
0 commit comments