-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[OpenMP][wip] Rework 'containing struct'/overlapped mapping handling #153672
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This reverts commit 4ef6587.
This patch is an early outline for a rework of several mapping features, intended to support 'containing structures' in the middle of expressions as well as at the top level (llvm#141042). Key ideas are: - struct information is gathered as several pre-passes before generateInfoForComponentList. - "PartialStruct" is turned into a map, keyed on the "effective base" of each containing structure in a set of expressions in OpenMP 'map' clauses. - the reverse iterator over component lists (visiting the base decl, then walking out to the full expression) has a new 'ComponentListRefPtrPteeIterator' adapter that (a) visits reference-type list components twice, and (b) provides a few useful utility methods. The current state is that a couple of tests work up to a point, but I'm hitting problems with the runtime that will probably be helped by the in-progress patches to support ATTACH operations.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-codegen Author: Julian Brown (jtb20) ChangesThis patch is an early outline for a rework of several mapping features, intended to support 'containing structures' in the middle of expressions as well as at the top level (#141042). Key ideas are:
The current state is that a couple of tests work up to a point, but I'm hitting problems with the runtime that will probably be helped by the in-progress patches to support ATTACH operations. This is obviously all full of debug code and not at all ready for review! Posting FYI. Patch is 78.86 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/153672.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index f1698a0bec373..3587096f8c6ec 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -18,25 +18,32 @@
#include "CGRecordLayout.h"
#include "CodeGenFunction.h"
#include "TargetInfo.h"
+#include "clang-c/Index.h"
#include "clang/AST/APValue.h"
+#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Decl.h"
+#include "clang/AST/ExprOpenMP.h"
#include "clang/AST/OpenMPClause.h"
#include "clang/AST/StmtOpenMP.h"
#include "clang/AST/StmtVisitor.h"
#include "clang/Basic/OpenMPKinds.h"
#include "clang/Basic/SourceManager.h"
+#include "clang/CodeGen/CodeGenABITypes.h"
#include "clang/CodeGen/ConstantInitBuilder.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Bitcode/BitcodeReader.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/AtomicOrdering.h"
+#include "llvm/Support/TypeSize.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
@@ -6755,6 +6762,51 @@ llvm::Value *CGOpenMPRuntime::emitNumThreadsForTargetDirective(
return NumThreadsVal;
}
+class EffectiveBaseMapKey {
+ llvm::FoldingSetNodeID ID;
+ bool Indirect = false;
+
+public:
+ EffectiveBaseMapKey(ASTContext &Ctx, const Expr *EB, bool Ind) {
+ EB->Profile(ID, Ctx, /*Canonical=*/true);
+ Indirect = Ind;
+ }
+
+ EffectiveBaseMapKey(llvm::FoldingSetNodeID FromID) : ID(FromID) { }
+
+ llvm::FoldingSetNodeID getID() const { return ID; }
+ bool getIndirect() const { return Indirect; }
+};
+
+template <> struct llvm::DenseMapInfo<EffectiveBaseMapKey> {
+
+ static EffectiveBaseMapKey getEmptyKey() {
+ llvm::FoldingSetNodeID ID;
+ ID.AddInteger(std::numeric_limits<unsigned>::max());
+ return EffectiveBaseMapKey(ID);
+ }
+
+ static EffectiveBaseMapKey getTombstoneKey() {
+ llvm::FoldingSetNodeID ID;
+ for (unsigned I = 0; I < sizeof(ID) / sizeof(unsigned); ++I) {
+ ID.AddInteger(std::numeric_limits<unsigned>::max());
+ }
+ return EffectiveBaseMapKey(ID);
+ }
+
+ static unsigned getHashValue(const EffectiveBaseMapKey &Val) {
+ auto ID = Val.getID();
+ ID.AddBoolean(Val.getIndirect());
+ return ID.ComputeHash();
+ }
+
+ static bool isEqual(const EffectiveBaseMapKey &LHS,
+ const EffectiveBaseMapKey &RHS) {
+ return LHS.getID() == RHS.getID() &&
+ LHS.getIndirect() == RHS.getIndirect();
+ }
+};
+
namespace {
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
@@ -6787,7 +6839,6 @@ class MappableExprsHandler {
public:
MappingExprInfo(const ValueDecl *MapDecl, const Expr *MapExpr = nullptr)
: MapDecl(MapDecl), MapExpr(MapExpr) {}
-
const ValueDecl *getMapDecl() const { return MapDecl; }
const Expr *getMapExpr() const { return MapExpr; }
};
@@ -6825,22 +6876,50 @@ class MappableExprsHandler {
}
};
+ struct MappableExprMetadata {
+ OMPClauseMappableExprCommon::MappableExprComponentListRef Components;
+ const MapData *MD = nullptr;
+ bool CompleteExpression = false;
+ Address Base = Address::invalid();
+ Address Pointer = Address::invalid();
+
+ //MappableExprMetadata() {}
+
+ /*MappableExprMetadata(OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
+ const MapData *MD, bool CompleteExpression)
+ : Components(Components), MD(MD),
+ CompleteExpression(CompleteExpression) {}
+
+ MappableExprMetadata(MappableExprMetadata &Other) {
+
+ }*/
+ };
+
+ using ExprComponentMap = llvm::MapVector<EffectiveBaseMapKey, MappableExprMetadata>;
+
/// Map between a struct and the its lowest & highest elements which have been
/// mapped.
/// [ValueDecl *] --> {LE(FieldIndex, Pointer),
/// HE(FieldIndex, Pointer)}
struct StructRangeInfoTy {
- MapCombinedInfoTy PreliminaryMapData;
+ //MapCombinedInfoTy PreliminaryMapData;
+ const Expr *BaseExpr = nullptr;
+ ExprComponentMap ChildComponents;
+ unsigned MemberDepth = -1u;
std::pair<unsigned /*FieldIndex*/, Address /*Pointer*/> LowestElem = {
0, Address::invalid()};
std::pair<unsigned /*FieldIndex*/, Address /*Pointer*/> HighestElem = {
0, Address::invalid()};
Address Base = Address::invalid();
+ Address BaseAddr = Address::invalid();
Address LB = Address::invalid();
bool IsArraySection = false;
- bool HasCompleteRecord = false;
+ const MapData *ContainingStructMap = nullptr;
};
+ // A map from effective base addresses to struct range info for that base.
+ using PartialStructMap = llvm::DenseMap<EffectiveBaseMapKey, StructRangeInfoTy>;
+
private:
/// Kind that defines how a device pointer has to be returned.
struct MapInfo {
@@ -7108,21 +7187,25 @@ class MappableExprsHandler {
Address BP, Address LB, bool IsNonContiguous,
uint64_t DimSize)
: CGF(CGF), CombinedInfo(CombinedInfo), Flags(Flags), MapDecl(MapDecl),
- MapExpr(MapExpr), BP(BP), LB(LB), IsNonContiguous(IsNonContiguous),
- DimSize(DimSize) {}
+ MapExpr(MapExpr), BP(BP), IsNonContiguous(IsNonContiguous),
+ DimSize(DimSize), LB(LB) {}
void processField(
const OMPClauseMappableExprCommon::MappableComponent &MC,
+ llvm::DenseMap<const FieldDecl *, uint64_t> &Layout,
const FieldDecl *FD,
llvm::function_ref<LValue(CodeGenFunction &, const MemberExpr *)>
EmitMemberExprBase) {
- const RecordDecl *RD = FD->getParent();
- const ASTRecordLayout &RL = CGF.getContext().getASTRecordLayout(RD);
- uint64_t FieldOffset = RL.getFieldOffset(FD->getFieldIndex());
+ uint64_t FieldOffset = CGF.getContext().toBits(CharUnits::fromQuantity(Layout[FD]));
uint64_t FieldSize =
CGF.getContext().getTypeSize(FD->getType().getCanonicalType());
Address ComponentLB = Address::invalid();
+ fprintf(stderr, "Process field: ");
+ MC.getAssociatedExpression()->dumpPretty(CGF.getContext());
+ fprintf(stderr, " offset: %d index: %d cursor: %d\n", (int) FieldOffset, (int) FD->getFieldIndex(),
+ (int) Cursor);
+
if (FD->getType()->isLValueReferenceType()) {
const auto *ME = cast<MemberExpr>(MC.getAssociatedExpression());
LValue BaseLVal = EmitMemberExprBase(CGF, ME);
@@ -7133,8 +7216,6 @@ class MappableExprsHandler {
CGF.EmitOMPSharedLValue(MC.getAssociatedExpression()).getAddress();
}
- if (!LastParent)
- LastParent = RD;
if (FD->getParent() == LastParent) {
if (FD->getFieldIndex() != LastIndex + 1)
copyUntilField(FD, ComponentLB);
@@ -7156,13 +7237,11 @@ class MappableExprsHandler {
copySizedChunk(LBPtr, Size);
}
- void copyUntilEnd(Address HB) {
- if (LastParent) {
- const ASTRecordLayout &RL =
- CGF.getContext().getASTRecordLayout(LastParent);
- if ((uint64_t)CGF.getContext().toBits(RL.getSize()) <= Cursor)
- return;
- }
+ void copyUntilEnd(Address HB, CharUnits TypeSize) {
+ fprintf(stderr, "copyUntilEnd: Cursor=%d TypeSize=%d\n",
+ (int) Cursor, (int) CGF.getContext().toBits(TypeSize));
+ if ((uint64_t)CGF.getContext().toBits(TypeSize) <= Cursor)
+ return;
llvm::Value *LBPtr = LB.emitRawPointer(CGF);
llvm::Value *Size = CGF.Builder.CreatePtrDiff(
CGF.Int8Ty, CGF.Builder.CreateConstGEP(HB, 1).emitRawPointer(CGF),
@@ -7184,6 +7263,544 @@ class MappableExprsHandler {
}
};
+ /// Given a MemberExpr \c ME, find the containing structure as understood by
+ /// OpenMP (OpenMP 6.0, "2 Glossary").
+ const Expr *getEffectiveBase(const MemberExpr *ME, const MemberExpr **IME, bool &Ind) const {
+ const Expr *Base = ME->getBase()->IgnoreParenImpCasts();
+
+ Ind = false;
+
+ /*fprintf(stderr, "getEffectiveBase, input=");
+ ME->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\nbase=");
+ Base->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");*/
+
+ // Strip off any outer "." member accesses first
+ while (const auto *MEB = dyn_cast<MemberExpr>(Base)) {
+ if (ME->isArrow() || Base->getType()->isReferenceType()) {
+ break;
+ } else {
+ ME = MEB;
+ if (IME)
+ *IME = ME;
+ Base = ME->getBase()->IgnoreParenImpCasts();
+ }
+ }
+
+ /*fprintf(stderr, "now base=");
+ Base->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");*/
+
+ if (ME->isArrow() || Base->getType()->isReferenceType()) {
+ Ind = true;
+ return Base;
+ }
+
+ return indirectOnce(Base, Ind);
+ }
+
+ // Iterate a component list from the base of an expression to the complete
+ // expression. Components which are references are visited twice: firstly
+ // as the pointer, second as the pointee.
+ struct ComponentListRefPtrPteeIterator {
+ using iterator_category = std::forward_iterator_tag;
+ using value_type = const OMPClauseMappableExprCommon::MappableComponent;
+ using difference_type = std::ptrdiff_t;
+ using pointer = const OMPClauseMappableExprCommon::MappableComponent*;
+ using reference = const OMPClauseMappableExprCommon::MappableComponent&;
+
+ std::reverse_iterator<const OMPClauseMappableExprCommon::MappableComponent *> Pos;
+ bool RefPtee = false;
+ const ValueDecl *BaseDecl = nullptr;
+ // We repeat on references -- this is the position in the underlying list.
+ unsigned ComponentPos = 0;
+
+ ComponentListRefPtrPteeIterator(std::reverse_iterator<const OMPClauseMappableExprCommon::MappableComponent *> From) : Pos(From)
+ { }
+
+ reference operator*() const { return *Pos; }
+ pointer operator->() { return &*Pos; }
+
+ void setBaseDecl(const ValueDecl *Decl) {
+ BaseDecl = Decl;
+ }
+
+ bool isRefPtee() {
+ return RefPtee;
+ }
+
+ bool isRef() {
+ const OMPClauseMappableExprCommon::MappableComponent *Comp = &*Pos;
+ if (isa<MemberExpr>(Pos->getAssociatedExpression())) {
+ const ValueDecl *MapDecl = Comp->getAssociatedDeclaration();
+ assert(MapDecl && "Expected associated declaration for member expr");
+ return MapDecl->getType()->isLValueReferenceType();
+ }
+ return false;
+ }
+
+ bool isPointer(bool AllowDeref) {
+ const OMPClauseMappableExprCommon::MappableComponent *Comp = &*Pos;
+ const Expr *AE = Comp->getAssociatedExpression();
+ const auto *OASE = dyn_cast<ArraySectionExpr>(AE);
+ bool IsPointer =
+ isa<OMPArrayShapingExpr>(AE) ||
+ (OASE && ArraySectionExpr::getBaseOriginalType(OASE).getCanonicalType()->isAnyPointerType()) ||
+ AE->getType()->isAnyPointerType();
+
+ if (AllowDeref)
+ return IsPointer;
+ else if (!IsPointer)
+ return false;
+
+ if (const auto *UO = dyn_cast<UnaryOperator>(AE))
+ return UO->getOpcode() != UO_Deref;
+
+ return !isa<BinaryOperator>(AE);
+ }
+
+ unsigned getComponentPos() {
+ return ComponentPos;
+ }
+
+ ComponentListRefPtrPteeIterator& operator++() {
+ if (isRef()) {
+ if (!RefPtee)
+ RefPtee = true;
+ else {
+ RefPtee = false;
+ ++Pos;
+ }
+ } else {
+ RefPtee = false;
+ // This could skip to outermost MemberExprs (over ".").
+ ++Pos;
+ ++ComponentPos;
+ /*while (auto ME = dyn_cast<MemberExpr>(Pos->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ if (ME->isArrow() || ME->getBase()->getType()->isReferenceType())
+ break;
+ else
+ ++Pos;
+ }*/
+ }
+ return *this;
+ }
+
+ ComponentListRefPtrPteeIterator operator++(int) {
+ ComponentListRefPtrPteeIterator tmp = *this;
+ ++(*this);
+ return tmp;
+ }
+
+ friend bool operator==(const ComponentListRefPtrPteeIterator& a,
+ const ComponentListRefPtrPteeIterator& b) {
+ return a.Pos == b.Pos && a.RefPtee == b.RefPtee;
+ }
+
+ friend bool operator!=(const ComponentListRefPtrPteeIterator &a,
+ const ComponentListRefPtrPteeIterator &b) {
+ return a.Pos != b.Pos || a.RefPtee != b.RefPtee;
+ }
+ };
+
+ bool exprsEqual(Expr *One, Expr *Two) const {
+ if (One == nullptr || Two == nullptr)
+ return One == Two;
+
+ if (One->getStmtClass() != Two->getStmtClass())
+ return false;
+
+ llvm::FoldingSetNodeID ProfOne, ProfTwo;
+ One->Profile(ProfOne, CGF.getContext(), true);
+ Two->Profile(ProfTwo, CGF.getContext(), true);
+
+ return ProfOne == ProfTwo;
+ }
+
+ const Expr *indirectOnce(const Expr *E, bool &Ind) const {
+ Ind = false;
+
+ // Treat (*foo).bar the same as foo->bar
+ if (const auto *UO = dyn_cast<UnaryOperator>(E)) {
+ if (UO->getOpcode() == UO_Deref) {
+ Ind = true;
+ return UO->getSubExpr()->IgnoreParenImpCasts();
+ }
+ }
+
+ // Treat foo[0].bar the same as foo->bar
+ while (const auto *ASE = dyn_cast<ArraySubscriptExpr>(E)) {
+ const Expr *ArrayBase = ASE->getBase()->IgnoreParenImpCasts();
+ const Expr *Index = ASE->getIdx();
+ Expr::EvalResult Result;
+ if (!Index->EvaluateAsInt(Result, CGF.getContext())) {
+ return E;
+ }
+ llvm::APSInt ConstIndex = Result.Val.getInt();
+ if (ConstIndex == 0) {
+ Ind = true;
+ E = ArrayBase;
+ }
+ if (!E->getType()->isArrayType())
+ break;
+ }
+
+ // Treat foo[:1].bar & foo[0:1].bar the same as foo->bar
+ if (const auto *ASecE = dyn_cast<ArraySectionExpr>(E)) {
+ const Expr *ArrayBase = ASecE->getBase()->IgnoreParenImpCasts();
+ const Expr *LB = ASecE->getLowerBound();
+ const Expr *Len = ASecE->getLength();
+ bool LBZero = false, LenOne = false;
+ Expr::EvalResult Result;
+ if (!LB) {
+ LBZero = true;
+ } else if (LB->EvaluateAsInt(Result, CGF.getContext())) {
+ llvm::APSInt ConstLB = Result.Val.getInt();
+ if (ConstLB == 0)
+ LBZero = true;
+ }
+ if (Len && Len->EvaluateAsInt(Result, CGF.getContext())) {
+ llvm::APSInt ConstLen = Result.Val.getInt();
+ if (ConstLen == 1) {
+ LenOne = true;
+ }
+ }
+ if (LBZero && LenOne) {
+ Ind = true;
+ return ArrayBase;
+ }
+ }
+
+ return E;
+ }
+
+ bool componentsEqual(const OMPClauseMappableExprCommon::MappableComponent &One,
+ const OMPClauseMappableExprCommon::MappableComponent &Two) const {
+ if (One.isNonContiguous() != Two.isNonContiguous())
+ return false;
+
+ ValueDecl *DeclOne = One.getAssociatedDeclaration();
+ ValueDecl *DeclTwo = Two.getAssociatedDeclaration();
+
+ if (DeclOne == nullptr || DeclTwo == nullptr)
+ return DeclOne == DeclTwo;
+
+ if (DeclOne->getCanonicalDecl() != DeclTwo->getCanonicalDecl())
+ return false;
+
+ return exprsEqual(One.getAssociatedExpression(),
+ Two.getAssociatedExpression());
+ }
+
+ bool hasMemberExpr(const OMPClauseMappableExprCommon::MappableExprComponentListRef Components) const {
+ return llvm::any_of(Components, [](const OMPClauseMappableExprCommon::MappableComponent &M) {
+ return isa<MemberExpr>(M.getAssociatedExpression());
+ });
+ }
+
+ void gatherStructDataForComponentList(const MapData &MD, OpenMPMapClauseKind MapType, ArrayRef<OpenMPMapModifierKind> MapModifiers,
+ OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
+ MapCombinedInfoTy &CombinedInfo, PartialStructMap &PartialStructs,
+ bool IsImplicit, const ValueDecl *Mapper = nullptr,
+ const ValueDecl *BaseDecl = nullptr, const Expr *MapExpr = nullptr) const {
+ // Scan the components from the base to the complete expression.
+ auto CI = ComponentListRefPtrPteeIterator(Components.rbegin());
+ auto CE = ComponentListRefPtrPteeIterator(Components.rend());
+ auto I = CI;
+
+ I.setBaseDecl(BaseDecl);
+
+ Address BPP = Address::invalid();
+ Address BP = Address::invalid();
+
+ const Expr *AssocExpr = I->getAssociatedExpression();
+ /*const auto *AE = dyn_cast<ArraySubscriptExpr>(AssocExpr);
+ const auto *OASE = dyn_cast<ArraySectionExpr>(AssocExpr);
+ const auto *OAShE = dyn_cast<OMPArrayShapingExpr>(AssocExpr);*/
+
+ auto &&EmitMemberExprBase = [](CodeGenFunction &CGF,
+ const MemberExpr *E) {
+ const Expr *BaseExpr = E->getBase();
+ // If this is s.x, emit s as an lvalue. If it is s->x, emit s as a
+ // scalar.
+ LValue BaseLV;
+ if (E->isArrow()) {
+ LValueBaseInfo BaseInfo;
+ TBAAAccessInfo TBAAInfo;
+ Address Addr =
+ CGF.EmitPointerWithAlignment(BaseExpr, &BaseInfo, &TBAAInfo);
+ QualType PtrTy = BaseExpr->getType()->getPointeeType();
+ BaseLV = CGF.MakeAddrLValue(Addr, PtrTy, BaseInfo, TBAAInfo);
+ } else {
+ BaseLV = CGF.EmitOMPSharedLValue(BaseExpr);
+ }
+ return BaseLV;
+ };
+
+ if (!hasMemberExpr(Components))
+ return;
+
+ /*
+ if (isa<MemberExpr>(AssocExpr)) {
+ // The base is the 'this' pointer. The content of the pointer is going
+ // to be the base of the field being mapped.
+ BP = CGF.LoadCXXThisAddress();
+ } else if ((AE && isa<CXXThisExpr>(AE->getBase()->IgnoreParenImpCasts())) ||
+ (OASE &&
+ isa<CXXThisExpr>(OASE->getBase()->IgnoreParenImpCasts()))) {
+ BP = CGF.EmitOMPSharedLValue(AssocExpr).getAddress();
+ } else if (OAShE &&
+ isa<CXXThisExpr>(OAShE->getBase()->IgnoreParenCasts())) {
+ BP = Address(
+ CGF.EmitScalarExpr(OAShE->getBase()),
+ CGF.ConvertTypeForMem(OAShE->getBase()->getType()->getPointeeType()),
+ CGF.getContext().getTypeAlignInChars(OAShE->getBase()->getType()));
+ } else {*/
+ // The base is the reference to the variable.
+ // BP = &Var.
+ fprintf(stderr, "Init new BP from ");
+ AssocExpr->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");
+ BP = CGF.EmitOMPSharedLValue(AssocExpr).getAddress();
+ BPP = Address::invalid();
+ QualType Ty = CI->getAssociatedDeclaration()->getType().getNonReferenceType();
+ if (Ty->isAnyPointerType()) {
+ BPP = BP;
+ BP = CGF.EmitLoadOfPointer(BP, Ty->castAs<PointerType>());
+ }
+ //}
+
+ bool IsNonContiguous = CombinedInfo.NonContigInfo.IsNonContiguous;
+ // Maybe this needs to be "number of indirections". We want something
+ // similar to topological sort, but simpler.
+ unsigned MemberDepth = 0;
+
+ MemberExpr *FirstMemberExpr = nullptr;
+ MemberExpr *LastMemberExpr = nullptr;
+
+ for (; I != CE; ++I) {
+ StructRangeInfoTy *PartialStruct = nullptr;
+ bool Indirected = false;
+
+ //auto Next = std::next(I);
+ if (auto ME = dyn_cast<MemberExpr>(I->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ /*if (!FirstMemberExpr) {
+ QualType Ty = CI->getAssociatedDeclaration()->getType().getNonReferenceType();
+ if (Ty->isAnyPointerType()) {
+ BP = CGF.EmitLoadOfPointer(BP, Ty->castAs<PointerType>());
+ Indirected = true;
+ }
+ FirstMemberExpr = ME;
+ }*/
+ ++MemberDepth;
+ }
+
+ // Peek at the next outer expression to see if it's a "." member access
+ if (auto ME = dyn_cast<MemberExpr>(I->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ auto Next = std::next(I);
+ if (Next != CE) {
+ if (auto NME = dyn_cast<MemberExpr>(Next->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ if (!NME->isArrow())
+ continue;
+ }
+ }
+ ...
[truncated]
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang/lib/CodeGen/CGOpenMPRuntime.cpp View the diff from clang-format here.diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index e969192c1..18125efb2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -6779,7 +6779,7 @@ public:
Indirect = Ind;
}
- EffectiveBaseMapKey(llvm::FoldingSetNodeID FromID) : ID(FromID) { }
+ EffectiveBaseMapKey(llvm::FoldingSetNodeID FromID) : ID(FromID) {}
llvm::FoldingSetNodeID getID() const { return ID; }
bool getIndirect() const { return Indirect; }
@@ -6809,8 +6809,7 @@ template <> struct llvm::DenseMapInfo<EffectiveBaseMapKey> {
static bool isEqual(const EffectiveBaseMapKey &LHS,
const EffectiveBaseMapKey &RHS) {
- return LHS.getID() == RHS.getID() &&
- LHS.getIndirect() == RHS.getIndirect();
+ return LHS.getID() == RHS.getID() && LHS.getIndirect() == RHS.getIndirect();
}
};
@@ -6889,27 +6888,27 @@ public:
bool CompleteExpression = false;
Address Base = Address::invalid();
Address Pointer = Address::invalid();
-
- //MappableExprMetadata() {}
-
- /*MappableExprMetadata(OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
- const MapData *MD, bool CompleteExpression)
- : Components(Components), MD(MD),
- CompleteExpression(CompleteExpression) {}
-
+
+ // MappableExprMetadata() {}
+
+ /*MappableExprMetadata(OMPClauseMappableExprCommon::MappableExprComponentListRef
+ Components, const MapData *MD, bool CompleteExpression) :
+ Components(Components), MD(MD), CompleteExpression(CompleteExpression) {}
+
MappableExprMetadata(MappableExprMetadata &Other) {
}*/
};
- using ExprComponentMap = llvm::MapVector<EffectiveBaseMapKey, MappableExprMetadata>;
+ using ExprComponentMap =
+ llvm::MapVector<EffectiveBaseMapKey, MappableExprMetadata>;
/// Map between a struct and the its lowest & highest elements which have been
/// mapped.
/// [ValueDecl *] --> {LE(FieldIndex, Pointer),
/// HE(FieldIndex, Pointer)}
struct StructRangeInfoTy {
- //MapCombinedInfoTy PreliminaryMapData;
+ // MapCombinedInfoTy PreliminaryMapData;
const Expr *BaseExpr = nullptr;
ExprComponentMap ChildComponents;
unsigned MemberDepth = -1u;
@@ -6925,7 +6924,8 @@ public:
};
// A map from effective base addresses to struct range info for that base.
- using PartialStructMap = llvm::DenseMap<EffectiveBaseMapKey, StructRangeInfoTy>;
+ using PartialStructMap =
+ llvm::DenseMap<EffectiveBaseMapKey, StructRangeInfoTy>;
private:
/// Kind that defines how a device pointer has to be returned.
@@ -7203,15 +7203,16 @@ private:
const FieldDecl *FD,
llvm::function_ref<LValue(CodeGenFunction &, const MemberExpr *)>
EmitMemberExprBase) {
- uint64_t FieldOffset = CGF.getContext().toBits(CharUnits::fromQuantity(Layout[FD]));
+ uint64_t FieldOffset =
+ CGF.getContext().toBits(CharUnits::fromQuantity(Layout[FD]));
uint64_t FieldSize =
CGF.getContext().getTypeSize(FD->getType().getCanonicalType());
Address ComponentLB = Address::invalid();
fprintf(stderr, "Process field: ");
MC.getAssociatedExpression()->dumpPretty(CGF.getContext());
- fprintf(stderr, " offset: %d index: %d cursor: %d\n", (int) FieldOffset, (int) FD->getFieldIndex(),
- (int) Cursor);
+ fprintf(stderr, " offset: %d index: %d cursor: %d\n", (int)FieldOffset,
+ (int)FD->getFieldIndex(), (int)Cursor);
if (FD->getType()->isLValueReferenceType()) {
const auto *ME = cast<MemberExpr>(MC.getAssociatedExpression());
@@ -7245,8 +7246,8 @@ private:
}
void copyUntilEnd(Address HB, CharUnits TypeSize) {
- fprintf(stderr, "copyUntilEnd: Cursor=%d TypeSize=%d\n",
- (int) Cursor, (int) CGF.getContext().toBits(TypeSize));
+ fprintf(stderr, "copyUntilEnd: Cursor=%d TypeSize=%d\n", (int)Cursor,
+ (int)CGF.getContext().toBits(TypeSize));
if ((uint64_t)CGF.getContext().toBits(TypeSize) <= Cursor)
return;
llvm::Value *LBPtr = LB.emitRawPointer(CGF);
@@ -7272,7 +7273,8 @@ private:
/// Given a MemberExpr \c ME, find the containing structure as understood by
/// OpenMP (OpenMP 6.0, "2 Glossary").
- const Expr *getEffectiveBase(const MemberExpr *ME, const MemberExpr **IME, bool &Ind) const {
+ const Expr *getEffectiveBase(const MemberExpr *ME, const MemberExpr **IME,
+ bool &Ind) const {
const Expr *Base = ME->getBase()->IgnoreParenImpCasts();
Ind = false;
@@ -7314,28 +7316,29 @@ private:
using iterator_category = std::forward_iterator_tag;
using value_type = const OMPClauseMappableExprCommon::MappableComponent;
using difference_type = std::ptrdiff_t;
- using pointer = const OMPClauseMappableExprCommon::MappableComponent*;
- using reference = const OMPClauseMappableExprCommon::MappableComponent&;
+ using pointer = const OMPClauseMappableExprCommon::MappableComponent *;
+ using reference = const OMPClauseMappableExprCommon::MappableComponent &;
- std::reverse_iterator<const OMPClauseMappableExprCommon::MappableComponent *> Pos;
+ std::reverse_iterator<
+ const OMPClauseMappableExprCommon::MappableComponent *>
+ Pos;
bool RefPtee = false;
const ValueDecl *BaseDecl = nullptr;
// We repeat on references -- this is the position in the underlying list.
unsigned ComponentPos = 0;
-
- ComponentListRefPtrPteeIterator(std::reverse_iterator<const OMPClauseMappableExprCommon::MappableComponent *> From) : Pos(From)
- { }
+
+ ComponentListRefPtrPteeIterator(
+ std::reverse_iterator<
+ const OMPClauseMappableExprCommon::MappableComponent *>
+ From)
+ : Pos(From) {}
reference operator*() const { return *Pos; }
pointer operator->() { return &*Pos; }
- void setBaseDecl(const ValueDecl *Decl) {
- BaseDecl = Decl;
- }
+ void setBaseDecl(const ValueDecl *Decl) { BaseDecl = Decl; }
- bool isRefPtee() {
- return RefPtee;
- }
+ bool isRefPtee() { return RefPtee; }
bool isRef() {
const OMPClauseMappableExprCommon::MappableComponent *Comp = &*Pos;
@@ -7351,11 +7354,12 @@ private:
const OMPClauseMappableExprCommon::MappableComponent *Comp = &*Pos;
const Expr *AE = Comp->getAssociatedExpression();
const auto *OASE = dyn_cast<ArraySectionExpr>(AE);
- bool IsPointer =
- isa<OMPArrayShapingExpr>(AE) ||
- (OASE && ArraySectionExpr::getBaseOriginalType(OASE).getCanonicalType()->isAnyPointerType()) ||
- AE->getType()->isAnyPointerType();
-
+ bool IsPointer = isa<OMPArrayShapingExpr>(AE) ||
+ (OASE && ArraySectionExpr::getBaseOriginalType(OASE)
+ .getCanonicalType()
+ ->isAnyPointerType()) ||
+ AE->getType()->isAnyPointerType();
+
if (AllowDeref)
return IsPointer;
else if (!IsPointer)
@@ -7367,11 +7371,9 @@ private:
return !isa<BinaryOperator>(AE);
}
- unsigned getComponentPos() {
- return ComponentPos;
- }
+ unsigned getComponentPos() { return ComponentPos; }
- ComponentListRefPtrPteeIterator& operator++() {
+ ComponentListRefPtrPteeIterator &operator++() {
if (isRef()) {
if (!RefPtee)
RefPtee = true;
@@ -7384,8 +7386,9 @@ private:
// This could skip to outermost MemberExprs (over ".").
++Pos;
++ComponentPos;
- /*while (auto ME = dyn_cast<MemberExpr>(Pos->getAssociatedExpression()->IgnoreParenImpCasts())) {
- if (ME->isArrow() || ME->getBase()->getType()->isReferenceType())
+ /*while (auto ME =
+ dyn_cast<MemberExpr>(Pos->getAssociatedExpression()->IgnoreParenImpCasts()))
+ { if (ME->isArrow() || ME->getBase()->getType()->isReferenceType())
break;
else
++Pos;
@@ -7400,8 +7403,8 @@ private:
return tmp;
}
- friend bool operator==(const ComponentListRefPtrPteeIterator& a,
- const ComponentListRefPtrPteeIterator& b) {
+ friend bool operator==(const ComponentListRefPtrPteeIterator &a,
+ const ComponentListRefPtrPteeIterator &b) {
return a.Pos == b.Pos && a.RefPtee == b.RefPtee;
}
@@ -7482,14 +7485,15 @@ private:
return E;
}
- bool componentsEqual(const OMPClauseMappableExprCommon::MappableComponent &One,
- const OMPClauseMappableExprCommon::MappableComponent &Two) const {
+ bool componentsEqual(
+ const OMPClauseMappableExprCommon::MappableComponent &One,
+ const OMPClauseMappableExprCommon::MappableComponent &Two) const {
if (One.isNonContiguous() != Two.isNonContiguous())
return false;
ValueDecl *DeclOne = One.getAssociatedDeclaration();
ValueDecl *DeclTwo = Two.getAssociatedDeclaration();
-
+
if (DeclOne == nullptr || DeclTwo == nullptr)
return DeclOne == DeclTwo;
@@ -7500,17 +7504,24 @@ private:
Two.getAssociatedExpression());
}
- bool hasMemberExpr(const OMPClauseMappableExprCommon::MappableExprComponentListRef Components) const {
- return llvm::any_of(Components, [](const OMPClauseMappableExprCommon::MappableComponent &M) {
- return isa<MemberExpr>(M.getAssociatedExpression());
- });
+ bool
+ hasMemberExpr(const OMPClauseMappableExprCommon::MappableExprComponentListRef
+ Components) const {
+ return llvm::any_of(
+ Components,
+ [](const OMPClauseMappableExprCommon::MappableComponent &M) {
+ return isa<MemberExpr>(M.getAssociatedExpression());
+ });
}
- void gatherStructDataForComponentList(const MapData &MD, OpenMPMapClauseKind MapType, ArrayRef<OpenMPMapModifierKind> MapModifiers,
- OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
- MapCombinedInfoTy &CombinedInfo, PartialStructMap &PartialStructs,
- bool IsImplicit, const ValueDecl *Mapper = nullptr,
- const ValueDecl *BaseDecl = nullptr, const Expr *MapExpr = nullptr) const {
+ void gatherStructDataForComponentList(
+ const MapData &MD, OpenMPMapClauseKind MapType,
+ ArrayRef<OpenMPMapModifierKind> MapModifiers,
+ OMPClauseMappableExprCommon::MappableExprComponentListRef Components,
+ MapCombinedInfoTy &CombinedInfo, PartialStructMap &PartialStructs,
+ bool IsImplicit, const ValueDecl *Mapper = nullptr,
+ const ValueDecl *BaseDecl = nullptr,
+ const Expr *MapExpr = nullptr) const {
// Scan the components from the base to the complete expression.
auto CI = ComponentListRefPtrPteeIterator(Components.rbegin());
auto CE = ComponentListRefPtrPteeIterator(Components.rend());
@@ -7525,9 +7536,8 @@ private:
/*const auto *AE = dyn_cast<ArraySubscriptExpr>(AssocExpr);
const auto *OASE = dyn_cast<ArraySectionExpr>(AssocExpr);
const auto *OAShE = dyn_cast<OMPArrayShapingExpr>(AssocExpr);*/
-
- auto &&EmitMemberExprBase = [](CodeGenFunction &CGF,
- const MemberExpr *E) {
+
+ auto &&EmitMemberExprBase = [](CodeGenFunction &CGF, const MemberExpr *E) {
const Expr *BaseExpr = E->getBase();
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a
// scalar.
@@ -7564,18 +7574,19 @@ private:
CGF.ConvertTypeForMem(OAShE->getBase()->getType()->getPointeeType()),
CGF.getContext().getTypeAlignInChars(OAShE->getBase()->getType()));
} else {*/
- // The base is the reference to the variable.
- // BP = &Var.
- fprintf(stderr, "Init new BP from ");
- AssocExpr->dumpPretty(CGF.getContext());
- fprintf(stderr, "\n");
- BP = CGF.EmitOMPSharedLValue(AssocExpr).getAddress();
- BPP = Address::invalid();
- QualType Ty = CI->getAssociatedDeclaration()->getType().getNonReferenceType();
- if (Ty->isAnyPointerType()) {
- BPP = BP;
- BP = CGF.EmitLoadOfPointer(BP, Ty->castAs<PointerType>());
- }
+ // The base is the reference to the variable.
+ // BP = &Var.
+ fprintf(stderr, "Init new BP from ");
+ AssocExpr->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");
+ BP = CGF.EmitOMPSharedLValue(AssocExpr).getAddress();
+ BPP = Address::invalid();
+ QualType Ty =
+ CI->getAssociatedDeclaration()->getType().getNonReferenceType();
+ if (Ty->isAnyPointerType()) {
+ BPP = BP;
+ BP = CGF.EmitLoadOfPointer(BP, Ty->castAs<PointerType>());
+ }
//}
bool IsNonContiguous = CombinedInfo.NonContigInfo.IsNonContiguous;
@@ -7590,13 +7601,14 @@ private:
StructRangeInfoTy *PartialStruct = nullptr;
bool Indirected = false;
- //auto Next = std::next(I);
- if (auto ME = dyn_cast<MemberExpr>(I->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ // auto Next = std::next(I);
+ if (auto ME = dyn_cast<MemberExpr>(
+ I->getAssociatedExpression()->IgnoreParenImpCasts())) {
/*if (!FirstMemberExpr) {
- QualType Ty = CI->getAssociatedDeclaration()->getType().getNonReferenceType();
- if (Ty->isAnyPointerType()) {
- BP = CGF.EmitLoadOfPointer(BP, Ty->castAs<PointerType>());
- Indirected = true;
+ QualType Ty =
+ CI->getAssociatedDeclaration()->getType().getNonReferenceType(); if
+ (Ty->isAnyPointerType()) { BP = CGF.EmitLoadOfPointer(BP,
+ Ty->castAs<PointerType>()); Indirected = true;
}
FirstMemberExpr = ME;
}*/
@@ -7604,15 +7616,18 @@ private:
}
// Peek at the next outer expression to see if it's a "." member access
- if (auto ME = dyn_cast<MemberExpr>(I->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ if (auto ME = dyn_cast<MemberExpr>(
+ I->getAssociatedExpression()->IgnoreParenImpCasts())) {
auto Next = std::next(I);
if (Next != CE) {
- if (auto NME = dyn_cast<MemberExpr>(Next->getAssociatedExpression()->IgnoreParenImpCasts())) {
+ if (auto NME = dyn_cast<MemberExpr>(
+ Next->getAssociatedExpression()->IgnoreParenImpCasts())) {
if (!NME->isArrow())
continue;
}
}
- /*QualType Ty = I->getAssociatedDeclaration()->getType().getNonReferenceType();
+ /*QualType Ty =
+ I->getAssociatedDeclaration()->getType().getNonReferenceType();
fprintf(stderr, "expr: ");
I->getAssociatedExpression()->dumpPretty(CGF.getContext());
fprintf(stderr, "\n");
@@ -7629,11 +7644,10 @@ private:
bool LastIter = std::next(I) == CE;
const auto *OASE =
- dyn_cast<ArraySectionExpr>(I->getAssociatedExpression());
+ dyn_cast<ArraySectionExpr>(I->getAssociatedExpression());
const auto *OAShE =
- dyn_cast<OMPArrayShapingExpr>(I->getAssociatedExpression());
- const auto *UO =
- dyn_cast<UnaryOperator>(I->getAssociatedExpression());
+ dyn_cast<OMPArrayShapingExpr>(I->getAssociatedExpression());
+ const auto *UO = dyn_cast<UnaryOperator>(I->getAssociatedExpression());
bool IsDeref = UO && UO->getOpcode() == UO_Deref;
// A final array section, is one whose length can't be proved to be one.
@@ -7643,37 +7657,38 @@ private:
!IsNonContiguous &&
isFinalArraySectionExpression(I->getAssociatedExpression());
- // If we have a declaration for the mapping use that, otherwise use
+ // If we have a declaration for the mapping use that, otherwise use
// the base declaration of the map clause.
const ValueDecl *MapDecl = (I->getAssociatedDeclaration())
? I->getAssociatedDeclaration()
: BaseDecl;
- //if (OASE)
- // ++DimSize;
+ // if (OASE)
+ // ++DimSize;
if (LastIter || I.isRef() || I.isPointer(false) || IsFinalArraySection) {
Address LB = Address::invalid();
- //Address LowestElem = Address::invalid();
+ // Address LowestElem = Address::invalid();
if (OAShE) {
- /*LowestElem = */LB =
+ /*LowestElem = */ LB =
Address(CGF.EmitScalarExpr(OAShE->getBase()),
- CGF.ConvertTypeForMem(OAShE->getBase()->getType()->getPointeeType()),
- CGF.getContext().getTypeAlignInChars(
- OAShE->getBase()->getType()));
+ CGF.ConvertTypeForMem(
+ OAShE->getBase()->getType()->getPointeeType()),
+ CGF.getContext().getTypeAlignInChars(
+ OAShE->getBase()->getType()));
} else if (I.isRef()) {
const auto *ME = cast<MemberExpr>(I->getAssociatedExpression());
LValue BaseLVal = EmitMemberExprBase(CGF, ME);
/*LowestElem =*/
- LB = CGF.EmitLValueForFieldInitialization(
- BaseLVal, cast<FieldDecl>(MapDecl))
- .getAddress();
+ LB = CGF.EmitLValueForFieldInitialization(BaseLVal,
+ cast<FieldDecl>(MapDecl))
+ .getAddress();
if (I.isRefPtee())
LB = CGF.EmitLoadOfReferenceLValue(LB, MapDecl->getType())
- .getAddress();
+ .getAddress();
} else {
- /*LowestElem = */LB =
+ /*LowestElem = */ LB =
CGF.EmitOMPSharedLValue(I->getAssociatedExpression())
.getAddress();
fprintf(stderr, "Calculated LB from: ");
@@ -7681,7 +7696,8 @@ private:
fprintf(stderr, "\n");
}
- if (MemberExpr *ME = dyn_cast<MemberExpr>(I->getAssociatedExpression())) {
+ if (MemberExpr *ME =
+ dyn_cast<MemberExpr>(I->getAssociatedExpression())) {
const MemberExpr *IME = ME;
bool Ind;
const Expr *EB = getEffectiveBase(ME, &IME, Ind);
@@ -7702,24 +7718,24 @@ private:
unsigned FieldIndex = FD->getFieldIndex();
// FIXME: Inadequate.
- //if (MemberDepth > 1) {
+ // if (MemberDepth > 1) {
// QualType Ty = ME->getBase()->getType().getNonReferenceType();
// if (Ty->isAnyPointerType()) {
// fprintf(stderr, "Indirect BP\n");
// BP = CGF.EmitLoadOfPointer(BP, Ty->castAs<PointerType>());
// }
- // }
+ // }
// Update info about the lowest and highest elements for this struct
if (!PartialStruct->Base.isValid()) {
- PartialStruct->LowestElem = {FieldIndex, LB/*LowestElem*/};
+ PartialStruct->LowestElem = {FieldIndex, LB /*LowestElem*/};
if (IsFinalArraySection && OASE) {
Address HB =
- CGF.EmitArraySectionExpr(OASE, /*IsLowerBound=*/false)
- .getAddress();
+ CGF.EmitArraySectionExpr(OASE, /*IsLowerBound=*/false)
+ .getAddress();
PartialStruct->HighestElem = {FieldIndex, HB};
} else {
- PartialStruct->HighestElem = {FieldIndex, LB/*LowestElem*/};
+ PartialStruct->HighestElem = {FieldIndex, LB /*LowestElem*/};
}
// This gets overridden (to the beginning of the struct) in the
// second pass, when we know if we're also mapping the whole struct.
@@ -7729,7 +7745,7 @@ private:
PartialStruct->BaseAddr = BPP;
PartialStruct->BaseExpr = EB;
} else if (FieldIndex < PartialStruct->LowestElem.first) {
- PartialStruct->LowestElem = {FieldIndex, LB/*LowestElem*/};
+ PartialStruct->LowestElem = {FieldIndex, LB /*LowestElem*/};
} else if (FieldIndex > PartialStruct->HighestElem.first) {
if (IsFinalArraySection && OASE) {
Address HB =
@@ -7737,39 +7753,41 @@ private:
.getAddress();
PartialStruct->HighestElem = {FieldIndex, HB};
} else {
- PartialStruct->HighestElem = {FieldIndex, LB/*LowestElem*/};
+ PartialStruct->HighestElem = {FieldIndex, LB /*LowestElem*/};
}
}
LastMemberExpr = ME;
}
- /*auto Next = std::next(I);
- if (Next != CE) {
- const Expr *NE = Next->getAssociatedExpression();
- bool Ind;
- const Expr *INE = indirectOnce(NE, Ind);
- if (Ind) {
- fprintf(stderr, "Indirected once, from: ");
- NE->dumpPretty(CGF.getContext());
- fprintf(stderr, "\nto: ");
- INE->dumpPretty(CGF.getContext());
- fprintf(stderr, "\n");
- if (isa<MemberExpr>(INE) ||
- isa<DeclRefExpr>(INE)) {
- fprintf(stderr, "continuing\n");
- continue;
- } else {
- fprintf(stderr, "breaking\n");
- break;
- }
+ /*auto Next = std::next(I);
+ if (Next != CE) {
+ const Expr *NE = Next->getAssociatedExpression();
+ bool Ind;
+ const Expr *INE = indirectOnce(NE, Ind);
+ if (Ind) {
+ fprintf(stderr, "Indirected once, from: ");
+ NE->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\nto: ");
+ INE->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");
+ if (isa<MemberExpr>(INE) ||
+ isa<DeclRefExpr>(INE)) {
+ fprintf(stderr, "continuing\n");
+ continue;
+ } else {
+ fprintf(stderr, "breaking\n");
+ break;
}
- }*/
+ }
+ }*/
do {
if (isa<MemberExpr>(I->getAssociatedExpression()) || LastIter) {
- EffectiveBaseMapKey IKey(CGF.getContext(), I->getAssociatedExpression(), false);
+ EffectiveBaseMapKey IKey(CGF.getContext(),
+ I->getAssociatedExpression(), false);
if (!PartialStruct) {
- assert(LastIter && "only expected null PartialStruct on last iter");
+ assert(LastIter &&
+ "only expected null PartialStruct on last iter");
if (!LastMemberExpr)
break;
bool Ind;
@@ -7777,10 +7795,11 @@ private:
EffectiveBaseMapKey EBKey(CGF.getContext(), EB, Ind);
PartialStruct = &PartialStructs[EBKey];
}
- if (PartialStruct->ChildComponents.find(IKey) == PartialStruct->ChildComponents.end()) {
+ if (PartialStruct->ChildComponents.find(IKey) ==
+ PartialStruct->ChildComponents.end()) {
int CutElems = Components.size() - I.getComponentPos() - 1;
- ArrayRef<OMPClauseMappableExprCommon::MappableComponent> Tmp =
- Components.drop_front(CutElems);
+ ArrayRef<OMPClauseMappableExprCommon::MappableComponent> Tmp =
+ Components.drop_front(CutElems);
bool CompleteExpr = CutElems == 0;
auto CI = Tmp.rbegin();
auto CE = Tmp.rend();
@@ -7790,14 +7809,16 @@ private:
I->getAssociatedExpression()->dumpPretty(CGF.getContext());
fprintf(stderr, "\n");
}
- PartialStruct->ChildComponents[IKey] = {Tmp, &MD, CompleteExpr, BP, LB};
+ PartialStruct->ChildComponents[IKey] = {Tmp, &MD, CompleteExpr,
+ BP, LB};
}
}
} while (false);
fprintf(stderr, "copy LB to BP\n");
BPP = LB;
- QualType Ty = I->getAssociatedExpression()->getType().getCanonicalType();
+ QualType Ty =
+ I->getAssociatedExpression()->getType().getCanonicalType();
if (Ty->isAnyPointerType()) {
BP = CGF.EmitLoadOfPointer(BPP, Ty->castAs<PointerType>());
} else {
@@ -8027,14 +8048,14 @@ private:
const auto *OAShE = dyn_cast<OMPArrayShapingExpr>(AssocExpr);
fprintf(stderr, "generateInfoForComponentList\n");
- //fprintf(stderr, "Preliminary data length: %d\n",
- // (int) PartialStruct.PreliminaryMapData.Exprs.size());
+ // fprintf(stderr, "Preliminary data length: %d\n",
+ // (int) PartialStruct.PreliminaryMapData.Exprs.size());
fprintf(stderr, "Combined info length: %d\n",
- (int) CombinedInfo.Exprs.size());
+ (int)CombinedInfo.Exprs.size());
- /* fprintf(stderr, "last component list entry:\n");
- std::prev(CE)->getAssociatedExpression()->dumpPretty(CGF.getContext());
- fprintf(stderr, "\n");*/
+ /* fprintf(stderr, "last component list entry:\n");
+ std::prev(CE)->getAssociatedExpression()->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");*/
if (AreBothBasePtrAndPteeMapped && std::next(I) == CE)
return;
@@ -8150,8 +8171,8 @@ private:
bool IsPrevMemberReference = false;
- //bool IsPartialMapped =
- // !PartialStruct.PreliminaryMapData.BasePointers.empty();
+ // bool IsPartialMapped =
+ // !PartialStruct.PreliminaryMapData.BasePointers.empty();
for (; I != CE; ++I) {
// If the current component is member of a struct (parent struct) mark it.
@@ -8295,15 +8316,15 @@ private:
// PartialStruct.PreliminaryMapData.BasePointers has been mapped.
if ((!IsMemberPointerOrAddr /*&& !IsPartialMapped*/) ||
(Next == CE && MapType != OMPC_MAP_unknown)) {
- CombinedInfo.Exprs.emplace_back(MapDecl, MapExpr);
- CombinedInfo.BasePointers.push_back(BP.emitRawPointer(CGF));
- CombinedInfo.DevicePtrDecls.push_back(nullptr);
- CombinedInfo.DevicePointers.push_back(DeviceInfoTy::None);
- CombinedInfo.Pointers.push_back(LB.emitRawPointer(CGF));
- CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(
- Size, CGF.Int64Ty, /*isSigned=*/true));
- CombinedInfo.NonContigInfo.Dims.push_back(IsNonContiguous ? DimSize
- : 1);
+ CombinedInfo.Exprs.emplace_back(MapDecl, MapExpr);
+ CombinedInfo.BasePointers.push_back(BP.emitRawPointer(CGF));
+ CombinedInfo.DevicePtrDecls.push_back(nullptr);
+ CombinedInfo.DevicePointers.push_back(DeviceInfoTy::None);
+ CombinedInfo.Pointers.push_back(LB.emitRawPointer(CGF));
+ CombinedInfo.Sizes.push_back(
+ CGF.Builder.CreateIntCast(Size, CGF.Int64Ty, /*isSigned=*/true));
+ CombinedInfo.NonContigInfo.Dims.push_back(IsNonContiguous ? DimSize
+ : 1);
// If Mapper is valid, the last component inherits the mapper.
bool HasMapper = Mapper && Next == CE;
CombinedInfo.Mappers.push_back(HasMapper ? Mapper : nullptr);
@@ -8380,7 +8401,7 @@ private:
#endif
// Need to emit combined struct for array sections.
- //if (IsFinalArraySection || IsNonContiguous)
+ // if (IsFinalArraySection || IsNonContiguous)
// PartialStruct.IsArraySection = true;
// If we have a final array section, we are done with this expression.
@@ -8406,7 +8427,7 @@ private:
}
// If ran into the whole component - allocate the space for the whole
// record.
- //if (!EncounteredME)
+ // if (!EncounteredME)
// PartialStruct.HasCompleteRecord = true;
if (!IsNonContiguous)
@@ -8685,8 +8706,7 @@ private:
void getFieldOffsets(const CXXRecordDecl *RD,
llvm::DenseMap<const FieldDecl *, uint64_t> &Layout,
llvm::SmallPtrSetImpl<const CXXRecordDecl *> &Processed,
- uint64_t ParentOffset,
- bool AsBase) const {
+ uint64_t ParentOffset, bool AsBase) const {
const CGRecordLayout &RL = CGF.getTypes().getCGRecordLayout(RD);
fprintf(stderr, "Getting field offsets for decl:\n");
@@ -8695,8 +8715,7 @@ private:
llvm::StructType *St =
AsBase ? RL.getBaseSubobjectLLVMType() : RL.getLLVMType();
auto &DL = CGF.CGM.getDataLayout();
- const llvm::StructLayout *SL =
- DL.getStructLayout(St);
+ const llvm::StructLayout *SL = DL.getStructLayout(St);
Processed.insert(RD);
@@ -8734,10 +8753,14 @@ private:
unsigned FieldIndex = RL.getLLVMFieldNo(Field);
RecordLayout[FieldIndex] = Field;
if (Field->getType().getCanonicalType().getTypePtr()->isRecordType()) {
- const CXXRecordDecl *RD2 = Field->getType().getCanonicalType().getTypePtr()->getAsCXXRecordDecl();
+ const CXXRecordDecl *RD2 = Field->getType()
+ .getCanonicalType()
+ .getTypePtr()
+ ->getAsCXXRecordDecl();
if (!Processed.contains(RD2)) {
llvm::TypeSize Offset = SL->getElementOffset(FieldIndex);
- getFieldOffsets(RD2, Layout, Processed, ParentOffset + Offset, /*AsBase=*/true);
+ getFieldOffsets(RD2, Layout, Processed, ParentOffset + Offset,
+ /*AsBase=*/true);
}
}
}
@@ -8756,7 +8779,7 @@ private:
}
} else {
const auto *FD = cast<const FieldDecl *>(Data);
- //const auto *RD = FD->getParent();
+ // const auto *RD = FD->getParent();
unsigned FieldNo = RL.getLLVMFieldNo(FD);
llvm::TypeSize FieldOffset = SL->getElementOffset(FieldNo);
if (Layout.find(FD) == Layout.end()) {
@@ -9122,11 +9145,11 @@ private:
}
// If there is an entry in PartialStruct it means we have a struct with
// individual members mapped. Emit an extra combined entry. FIXME.
- //if (PartialStruct.Base.isValid()) {
+ // if (PartialStruct.Base.isValid()) {
// CurInfo.NonContigInfo.Dims.push_back(0);
// emitCombinedEntry(CombinedInfo, CurInfo.Types, PartialStruct,
// /*IsMapThis*/ !VD, OMPBuilder, VD);
- // }
+ // }
// We need to append the results of this capture to what we already
// have.
@@ -9195,7 +9218,8 @@ public:
llvm::OpenMPIRBuilder &OMPBuilder,
const ValueDecl *VD = nullptr,
unsigned OffsetForMemberOfFlag = 0,
- OpenMPOffloadMappingFlags Flags = OpenMPOffloadMappingFlags::OMP_MAP_NONE) const {
+ OpenMPOffloadMappingFlags Flags =
+ OpenMPOffloadMappingFlags::OMP_MAP_NONE) const {
fprintf(stderr, "emitCombinedEntry\n");
if (CurTypes.size() == 1 &&
((CurTypes.back() & OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF) !=
@@ -9211,9 +9235,11 @@ public:
CombinedInfo.Exprs.push_back(VD);
// Base is the base of the struct
if (Flags == OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ)
- CombinedInfo.BasePointers.push_back(PartialStruct.BaseAddr.emitRawPointer(CGF));
+ CombinedInfo.BasePointers.push_back(
+ PartialStruct.BaseAddr.emitRawPointer(CGF));
else
- CombinedInfo.BasePointers.push_back(PartialStruct.Base.emitRawPointer(CGF));
+ CombinedInfo.BasePointers.push_back(
+ PartialStruct.Base.emitRawPointer(CGF));
CombinedInfo.DevicePtrDecls.push_back(nullptr);
CombinedInfo.DevicePointers.push_back(DeviceInfoTy::None);
// Pointer is the address of the lowest element
@@ -9253,10 +9279,10 @@ public:
CombinedInfo.Mappers.push_back(nullptr);
// Map type is always TARGET_PARAM, if generate info for captures.
CombinedInfo.Types.push_back(Flags);
- //NotTargetParams ? OpenMPOffloadMappingFlags::OMP_MAP_NONE
- //: /*!PartialStruct.PreliminaryMapData.BasePointers.empty()
- // ? OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ
- // :*/ OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM);
+ // NotTargetParams ? OpenMPOffloadMappingFlags::OMP_MAP_NONE
+ //: /*!PartialStruct.PreliminaryMapData.BasePointers.empty()
+ // ? OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ
+ // :*/ OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM);
// If any element has the present modifier, then make sure the runtime
// doesn't attempt to allocate the struct.
if (CurTypes.end() !=
@@ -9437,8 +9463,7 @@ public:
void generateInfoForCaptureFromClauseInfo(
const CapturedStmt::Capture *Cap, llvm::Value *Arg,
MapCombinedInfoTy &CurCaptureVarInfo, PartialStructMap &PartialStructs,
- llvm::OpenMPIRBuilder &OMPBuilder,
- unsigned OffsetForMemberOfFlag) const {
+ llvm::OpenMPIRBuilder &OMPBuilder, unsigned OffsetForMemberOfFlag) const {
assert(!Cap->capturesVariableArrayType() &&
"Not expecting to generate map info for a variable array type!");
@@ -9540,21 +9565,21 @@ public:
return;
generateInfoForCaptureFromComponentLists(
- OMPBuilder, VD, DeclComponentLists, CurInfoForComponentLists, PartialStructs,
- IsEligibleForTargetParamFlag,
+ OMPBuilder, VD, DeclComponentLists, CurInfoForComponentLists,
+ PartialStructs, IsEligibleForTargetParamFlag,
/*AreBothBasePtrAndPteeMapped=*/HasMapBasePtr && HasMapArraySec);
// If there is an entry in PartialStruct it means we have a
// struct with individual members mapped. Emit an extra combined
// entry.
- //if (PartialStruct.Base.isValid()) {
+ // if (PartialStruct.Base.isValid()) {
// CurCaptureVarInfo.append(PartialStruct.PreliminaryMapData);
// emitCombinedEntry(
// CurCaptureVarInfo, CurInfoForComponentLists.Types,
// PartialStruct, Cap->capturesThis(), OMPBuilder, nullptr,
// OffsetForMemberOfFlag,
// /*NotTargetParams*/ !IsEligibleForTargetParamFlag);
- // }
+ // }
// Return if we didn't add any entries.
if (CurInfoForComponentLists.BasePointers.empty())
@@ -9571,7 +9596,8 @@ public:
/// mappers associated to \a DeclComponentLists for a given capture
/// \a VD (all included in \a CurComponentListInfo).
void generateInfoForCaptureFromComponentLists(
- llvm::OpenMPIRBuilder &OMPBuilder, const ValueDecl *VD, ArrayRef<MapData> DeclComponentLists,
+ llvm::OpenMPIRBuilder &OMPBuilder, const ValueDecl *VD,
+ ArrayRef<MapData> DeclComponentLists,
MapCombinedInfoTy &CurComponentListInfo, PartialStructMap &PartialStructs,
bool IsListEligibleForTargetParamFlag,
bool AreBothBasePtrAndPteeMapped = false) const {
@@ -9696,7 +9722,7 @@ public:
return *It == FD1;
});
}
- #endif
+#endif
fprintf(stderr, "Gather structs, pass 1\n");
@@ -9768,8 +9794,7 @@ public:
}
}
if (CheckLength) {
- if (ArrayBase->getType()->isArrayType() &&
- !ASecE->getLength()) {
+ if (ArrayBase->getType()->isArrayType() && !ASecE->getLength()) {
MapExpr = ArrayBase;
} else if (ASecE->getLength()) {
const Expr *Upper = ASecE->getLength();
@@ -9800,15 +9825,17 @@ public:
QualType Ty = PartialStruct->BaseExpr->getType().getCanonicalType();
fprintf(stderr, "BaseExpr Type:\n");
Ty.dump();
- //if (PartialStruct->MemberDepth > 1) {
- // PartialStruct->LB =
- // CGF.EmitLoadOfPointer(PartialStruct->Base, Ty->castAs<PointerType>());
- //} else {
- // The first one is indirected already.
- PartialStruct->LB = CGF.EmitLoadOfPointer(PartialStruct->BaseAddr, Ty->castAs<PointerType>());
- ProcessedMappings.insert(&L);
+ // if (PartialStruct->MemberDepth > 1) {
+ // PartialStruct->LB =
+ // CGF.EmitLoadOfPointer(PartialStruct->Base,
+ // Ty->castAs<PointerType>());
+ // } else {
+ // The first one is indirected already.
+ PartialStruct->LB = CGF.EmitLoadOfPointer(PartialStruct->BaseAddr,
+ Ty->castAs<PointerType>());
+ ProcessedMappings.insert(&L);
//} else {
- // }
+ // }
}
}
@@ -9818,7 +9845,8 @@ public:
llvm::DenseMap<const FieldDecl *, uint64_t> Layout;
- const Type *BaseType = PartialStruct.BaseExpr->getType().getCanonicalType().getTypePtr();
+ const Type *BaseType =
+ PartialStruct.BaseExpr->getType().getCanonicalType().getTypePtr();
const Type *OrigType = BaseType->getPointeeOrArrayElementType();
while (BaseType != OrigType) {
@@ -9833,85 +9861,86 @@ public:
assert(false && "Not CXX record decl");
}
- llvm::stable_sort(PartialStruct.ChildComponents,
- [this, &Layout](auto &a, auto &b) {
- OMPClauseMappableExprCommon::MappableExprComponentListRef First = a.second.Components;
- OMPClauseMappableExprCommon::MappableExprComponentListRef Second = b.second.Components;
-
- auto CI = First.begin();
- auto CE = First.end();
- auto SI = Second.begin();
- auto SE = Second.end();
-
- // We may have a member expression, or an ArraySectionExpr. Find the
- // outermost member expression.
- while (CI != CE) {
- if (isa<MemberExpr>(CI->getAssociatedExpression()))
- break;
- else
- ++CI;
- }
+ llvm::stable_sort(
+ PartialStruct.ChildComponents, [this, &Layout](auto &a, auto &b) {
+ OMPClauseMappableExprCommon::MappableExprComponentListRef First =
+ a.second.Components;
+ OMPClauseMappableExprCommon::MappableExprComponentListRef Second =
+ b.second.Components;
+
+ auto CI = First.begin();
+ auto CE = First.end();
+ auto SI = Second.begin();
+ auto SE = Second.end();
+
+ // We may have a member expression, or an ArraySectionExpr. Find the
+ // outermost member expression.
+ while (CI != CE) {
+ if (isa<MemberExpr>(CI->getAssociatedExpression()))
+ break;
+ else
+ ++CI;
+ }
- if (CI == CE)
- return false;
+ if (CI == CE)
+ return false;
- while (SI != SE) {
- if (isa<MemberExpr>(SI->getAssociatedExpression()))
- break;
- else
- ++SI;
- }
+ while (SI != SE) {
+ if (isa<MemberExpr>(SI->getAssociatedExpression()))
+ break;
+ else
+ ++SI;
+ }
- if (SI == SE)
- return false;
+ if (SI == SE)
+ return false;
- fprintf(stderr, "Compare CI expr: ");
- CI->getAssociatedExpression()->dumpPretty(CGF.getContext());
- fprintf(stderr, "\nwith SI expr: ");
- SI->getAssociatedExpression()->dumpPretty(CGF.getContext());
- fprintf(stderr, "\n");
+ fprintf(stderr, "Compare CI expr: ");
+ CI->getAssociatedExpression()->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\nwith SI expr: ");
+ SI->getAssociatedExpression()->dumpPretty(CGF.getContext());
+ fprintf(stderr, "\n");
- const auto *FD1 = cast<FieldDecl>(CI->getAssociatedDeclaration());
- const auto *FD2 = cast<FieldDecl>(SI->getAssociatedDeclaration());
+ const auto *FD1 = cast<FieldDecl>(CI->getAssociatedDeclaration());
+ const auto *FD2 = cast<FieldDecl>(SI->getAssociatedDeclaration());
- /*while (auto *ME = dyn_cast<MemberExpr>(CI->getAssociatedExpression())) {
- if (ME->isArrow())
- break;
- auto *Next = std::next(CI);
- if (Next == CE)
- break;
- if (isa<MemberExpr>(Next->getAssociatedExpression()))
- ++CI;
- else
- break;
- }
+ /*while (auto *ME =
+ dyn_cast<MemberExpr>(CI->getAssociatedExpression())) { if
+ (ME->isArrow()) break; auto *Next = std::next(CI); if (Next == CE)
+ break;
+ if (isa<MemberExpr>(Next->getAssociatedExpression()))
+ ++CI;
+ else
+ break;
+ }
- while (auto *ME = dyn_cast<MemberExpr>(SI->getAssociatedExpression())) {
- if (ME->isArrow())
- break;
- auto *Next = std::next(SI);
- if (Next == SE)
- break;
- if (isa<MemberExpr>(Next->getAssociatedExpression()))
- ++SI;
- else
- break;
- }
+ while (auto *ME =
+ dyn_cast<MemberExpr>(SI->getAssociatedExpression())) { if
+ (ME->isArrow()) break; auto *Next = std::next(SI); if (Next == SE)
+ break;
+ if (isa<MemberExpr>(Next->getAssociatedExpression()))
+ ++SI;
+ else
+ break;
+ }
- const RecordDecl *RD = FD1->getParent();
- const RecordDecl *RD2 = FD2->getParent();
+ const RecordDecl *RD = FD1->getParent();
+ const RecordDecl *RD2 = FD2->getParent();
- assert(RD == RD2 && "expected the same record decl");
+ assert(RD == RD2 && "expected the same record decl");
- const ASTRecordLayout &RL = CGF.getContext().getASTRecordLayout(RD);*/
- uint64_t FieldOffset1 = Layout[FD1];
- uint64_t FieldOffset2 = Layout[FD2];
+ const ASTRecordLayout &RL =
+ CGF.getContext().getASTRecordLayout(RD);*/
+ uint64_t FieldOffset1 = Layout[FD1];
+ uint64_t FieldOffset2 = Layout[FD2];
- fprintf(stderr, "Field offset 1: %llu\n", (unsigned long long) FieldOffset1);
- fprintf(stderr, "Field offset 2: %llu\n", (unsigned long long) FieldOffset2);
+ fprintf(stderr, "Field offset 1: %llu\n",
+ (unsigned long long)FieldOffset1);
+ fprintf(stderr, "Field offset 2: %llu\n",
+ (unsigned long long)FieldOffset2);
- return FieldOffset2 > FieldOffset1;
- });
+ return FieldOffset2 > FieldOffset1;
+ });
}
// FIXME
@@ -9930,8 +9959,7 @@ public:
return FirstInfo.MemberDepth < SecondInfo.MemberDepth;
});
- auto &&EmitMemberExprBase = [](CodeGenFunction &CGF,
- const MemberExpr *E) {
+ auto &&EmitMemberExprBase = [](CodeGenFunction &CGF, const MemberExpr *E) {
const Expr *BaseExpr = E->getBase();
// If this is s.x, emit s as an lvalue. If it is s->x, emit s as a
// scalar.
@@ -9956,26 +9984,30 @@ public:
auto &PartialStruct = PartialStructs[Ord];
MapCombinedInfoTy CombinedInfo;
- fprintf(stderr, "A partial struct (depth %d):\n", PartialStruct.MemberDepth);
+ fprintf(stderr, "A partial struct (depth %d):\n",
+ PartialStruct.MemberDepth);
if (PartialStruct.Base.isValid()) {
llvm::dbgs() << "Base expr: ";
PartialStruct.BaseExpr->dumpPretty(CGF.getContext());
fprintf(stderr, "\n");
llvm::dbgs() << "Name: " << PartialStruct.Base.getName() << "\n";
- llvm::dbgs() << "Is valid: " << (PartialStruct.Base.isValid() ? "true" : "false") << "\n";
+ llvm::dbgs() << "Is valid: "
+ << (PartialStruct.Base.isValid() ? "true" : "false")
+ << "\n";
} else {
llvm::dbgs() << "(no base set)\n";
}
llvm::dbgs() << "Lo elem: " << PartialStruct.LowestElem.first << "\n";
llvm::dbgs() << "Hi elem: " << PartialStruct.HighestElem.first << "\n";
- //CombinedInfo.append(PartialStruct.PreliminaryMapData);
+ // CombinedInfo.append(PartialStruct.PreliminaryMapData);
fprintf(stderr, "Child components:\n");
for (auto &CC : PartialStruct.ChildComponents) {
auto Comp = CC.second.Components;
Comp[0].getAssociatedExpression()->dumpPretty(CGF.getContext());
fprintf(stderr, "\n");
}
- fprintf(stderr, "Map whole struct: %s\n", PartialStruct.ContainingStructMap ? "yes" : "no");
+ fprintf(stderr, "Map whole struct: %s\n",
+ PartialStruct.ContainingStructMap ? "yes" : "no");
if (PartialStruct.ContainingStructMap) {
OMPClauseMappableExprCommon::MappableExprComponentListRef Components;
@@ -9984,9 +10016,10 @@ public:
bool IsImplicit;
const ValueDecl *Mapper;
const Expr *MapExpr;
- std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper, MapExpr) =
- *PartialStruct.ContainingStructMap;
- const Type *BaseType = PartialStruct.BaseExpr->getType().getCanonicalType().getTypePtr();
+ std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper,
+ MapExpr) = *PartialStruct.ContainingStructMap;
+ const Type *BaseType =
+ PartialStruct.BaseExpr->getType().getCanonicalType().getTypePtr();
const Type *OrigType = BaseType->getPointeeOrArrayElementType();
while (BaseType != OrigType) {
@@ -10003,18 +10036,18 @@ public:
PartialStruct.Base, CGF.VoidPtrTy, CGF.Int8Ty),
TypeSize.getQuantity() - 1);
PartialStruct.HighestElem = {
- std::numeric_limits<decltype(
- PartialStruct.HighestElem.first)>::max(),
+ std::numeric_limits<
+ decltype(PartialStruct.HighestElem.first)>::max(),
HB};
OpenMPOffloadMappingFlags Flags =
OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF |
getMapTypeBits(MapType, MapModifiers, {}, IsImplicit,
- /*AddPtrFlag=*/false,
- /*AddIsTargetParamFlag=*/false, IsNonContiguous);
+ /*AddPtrFlag=*/false,
+ /*AddIsTargetParamFlag=*/false, IsNonContiguous);
fprintf(stderr, "Starting CopyGaps...\n");
- CopyOverlappedEntryGaps CopyGaps(CGF, CombinedInfo, Flags, nullptr,
- PartialStruct.BaseExpr, PartialStruct.Base,
- PartialStruct.LB, IsNonContiguous, DimSize);
+ CopyOverlappedEntryGaps CopyGaps(
+ CGF, CombinedInfo, Flags, nullptr, PartialStruct.BaseExpr,
+ PartialStruct.Base, PartialStruct.LB, IsNonContiguous, DimSize);
llvm::DenseMap<const FieldDecl *, uint64_t> Layout;
@@ -10026,7 +10059,8 @@ public:
}
for (auto &CC : PartialStruct.ChildComponents) {
- const OMPClauseMappableExprCommon::MappableComponent &MC = CC.second.Components.front();
+ const OMPClauseMappableExprCommon::MappableComponent &MC =
+ CC.second.Components.front();
if (const ValueDecl *VD = MC.getAssociatedDeclaration()) {
if (const auto *FD = dyn_cast<FieldDecl>(VD)) {
CopyGaps.processField(MC, Layout, FD, EmitMemberExprBase);
@@ -10039,7 +10073,7 @@ public:
for (auto &CC : PartialStruct.ChildComponents) {
MappableExprMetadata Metadata = CC.second;
auto Field = Metadata.Components.front().getAssociatedExpression();
- // Address Ptr = CGF.EmitOMPSharedLValue(Field).getAddress();
+ // Address Ptr = CGF.EmitOMPSharedLValue(Field).getAddress();
llvm::Value *Size = getExprTypeSize(Field);
fprintf(stderr, "Emitting expr: ");
@@ -10053,47 +10087,50 @@ public:
bool IsImplicit;
const ValueDecl *Mapper;
const Expr *MapExpr;
- //if (PartialStruct.ContainingStructMap) {
- // std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper, MapExpr) =
- // *PartialStruct.ContainingStructMap;
- //} else {
- std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper, MapExpr) =
- *Metadata.MD;
+ // if (PartialStruct.ContainingStructMap) {
+ // std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper,
+ // MapExpr) =
+ // *PartialStruct.ContainingStructMap;
+ // } else {
+ std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper,
+ MapExpr) = *Metadata.MD;
//}
CombinedInfo.Exprs.push_back(nullptr);
- CombinedInfo.BasePointers.push_back(Metadata.Base.emitRawPointer(CGF));
+ CombinedInfo.BasePointers.push_back(
+ Metadata.Base.emitRawPointer(CGF));
CombinedInfo.DevicePtrDecls.push_back(nullptr);
CombinedInfo.DevicePointers.push_back(DeviceInfoTy::None);
CombinedInfo.Pointers.push_back(Metadata.Pointer.emitRawPointer(CGF));
- CombinedInfo.Sizes.push_back(CGF.Builder.CreateIntCast(
- Size, CGF.Int64Ty, /*isSigned=*/true));
- CombinedInfo.NonContigInfo.Dims.push_back(IsNonContiguous ? DimSize : 1);
+ CombinedInfo.Sizes.push_back(
+ CGF.Builder.CreateIntCast(Size, CGF.Int64Ty, /*isSigned=*/true));
+ CombinedInfo.NonContigInfo.Dims.push_back(IsNonContiguous ? DimSize
+ : 1);
CombinedInfo.Mappers.push_back(nullptr);
bool PointerAndObj = false;
- if (isa<ArraySectionExpr>(Field) ||
- isa<ArraySubscriptExpr>(Field) ||
- isa<OMPArrayShapingExpr>(Field) ||
- isa<UnaryOperator>(Field))
+ if (isa<ArraySectionExpr>(Field) || isa<ArraySubscriptExpr>(Field) ||
+ isa<OMPArrayShapingExpr>(Field) || isa<UnaryOperator>(Field))
PointerAndObj = true;
OpenMPOffloadMappingFlags Flags =
- getMapTypeBits(MapType, MapModifiers, {}, IsImplicit, PointerAndObj, false, IsNonContiguous);
+ getMapTypeBits(MapType, MapModifiers, {}, IsImplicit,
+ PointerAndObj, false, IsNonContiguous);
Flags |= OpenMPOffloadMappingFlags::OMP_MAP_MEMBER_OF;
CombinedInfo.Types.push_back(Flags);
- fprintf(stderr, "Marking %p as processed\n", (void*) Metadata.MD);
+ fprintf(stderr, "Marking %p as processed\n", (void *)Metadata.MD);
ProcessedMappings.insert(Metadata.MD);
}
}
if (ParamFlag || !PartialStruct.ContainingStructMap) {
- OpenMPOffloadMappingFlags Flags = ParamFlag ? OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM
- : OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ;
- emitCombinedEntry(CurComponentListInfo, CombinedInfo.Types, PartialStruct,
- false, OMPBuilder, VD, 0, Flags);
+ OpenMPOffloadMappingFlags Flags =
+ ParamFlag ? OpenMPOffloadMappingFlags::OMP_MAP_TARGET_PARAM
+ : OpenMPOffloadMappingFlags::OMP_MAP_PTR_AND_OBJ;
+ emitCombinedEntry(CurComponentListInfo, CombinedInfo.Types,
+ PartialStruct, false, OMPBuilder, VD, 0, Flags);
} else {
OpenMPOffloadMappingFlags MemberOfFlag = OMPBuilder.getMemberOfFlag(
CurComponentListInfo.BasePointers.size() - 1);
@@ -10106,7 +10143,7 @@ public:
}
fprintf(stderr, "That's all\n");
- #if 0
+#if 0
// Associated with a capture, because the mapping flags depend on it.
// Go through all of the elements with the overlapped elements.
bool AddTargetParamFlag = IsListEligibleForTargetParamFlag;
@@ -10130,7 +10167,7 @@ public:
/*ForDeviceAddr=*/false, VD, VarRef, OverlappedComponents);
AddTargetParamFlag = false;
}
- #endif
+#endif
// FIXME: Check this.
bool AddTargetParamFlag = IsListEligibleForTargetParamFlag;
@@ -10139,7 +10176,7 @@ public:
for (const MapData &L : DeclComponentLists) {
if (ProcessedMappings.contains(&L)) {
fprintf(stderr, "Already processed map data for %p, skipping\n",
- (void*) &L);
+ (void *)&L);
continue;
}
@@ -10151,15 +10188,16 @@ public:
const Expr *VarRef;
std::tie(Components, MapType, MapModifiers, IsImplicit, Mapper, VarRef) =
L;
- //auto It = OverlappedData.find(&L);
- //if (It == OverlappedData.end()) {
- fprintf(stderr, "*** From generateInfoForCaptureFromComponentLists (non-overlapped)...\n");
+ // auto It = OverlappedData.find(&L);
+ // if (It == OverlappedData.end()) {
+ fprintf(stderr, "*** From generateInfoForCaptureFromComponentLists "
+ "(non-overlapped)...\n");
#if 1
- generateInfoForComponentList(
- MapType, MapModifiers, {}, Components, CurComponentListInfo,
- PartialStructs, AddTargetParamFlag, IsImplicit, Mapper,
- /*ForDeviceAddr=*/false, VD, VarRef,
- /*OverlappedElements {},*/ AreBothBasePtrAndPteeMapped);
+ generateInfoForComponentList(
+ MapType, MapModifiers, {}, Components, CurComponentListInfo,
+ PartialStructs, AddTargetParamFlag, IsImplicit, Mapper,
+ /*ForDeviceAddr=*/false, VD, VarRef,
+ /*OverlappedElements {},*/ AreBothBasePtrAndPteeMapped);
#endif
//}
AddTargetParamFlag = false;
@@ -10651,10 +10689,18 @@ static void genMapInfoForCaptures(
V->dump();
llvm::dbgs() << "\ncaptured by:\n";
switch (CI->getCaptureKind()) {
- case CapturedStmt::VCK_This: llvm::dbgs() << "this\n"; break;
- case CapturedStmt::VCK_ByRef: llvm::dbgs() << "byref\n"; break;
- case CapturedStmt::VCK_ByCopy: llvm::dbgs() << "bycopy\n"; break;
- case CapturedStmt::VCK_VLAType: llvm::dbgs() << "vlatype\n"; break;
+ case CapturedStmt::VCK_This:
+ llvm::dbgs() << "this\n";
+ break;
+ case CapturedStmt::VCK_ByRef:
+ llvm::dbgs() << "byref\n";
+ break;
+ case CapturedStmt::VCK_ByCopy:
+ llvm::dbgs() << "bycopy\n";
+ break;
+ case CapturedStmt::VCK_VLAType:
+ llvm::dbgs() << "vlatype\n";
+ break;
}
// VLA sizes are passed to the outlined region by copy and do not have map
@@ -10704,7 +10750,7 @@ static void genMapInfoForCaptures(
// If there is an entry in PartialStruct it means we have a struct with
// individual members mapped. Emit an extra combined entry. FIXME.
- //if (PartialStruct.Base.isValid()) {
+ // if (PartialStruct.Base.isValid()) {
// CombinedInfo.append(PartialStruct.PreliminaryMapData);
// MEHandler.emitCombinedEntry(CombinedInfo, CurInfo.Types, PartialStruct,
// CI->capturesThis(), OMPBuilder, nullptr,
|
Thanks for the PR. I haven't been able to look at how it can work along with the pointer-attachment rework. Please look at #153683 when you get a chance. The updates tests have comments showing the current maps being emitted. In that, I'm trying to group maps based on the attach-exprs. It works for most cases, but I am yet to get down to some of the failing tests with use_device_ptr/addr, and target_update. That change is relying on comparing the attach-ptr exprs, so for now, for |
Thank you for the reply! I see that your patch series is tackling some of the same problems as mine, so I hope there's some useful non-overlapping bits here. I'll be able to have a closer look after next week. |
This patch is an early outline for a rework of several mapping features, intended to support 'containing structures' in the middle of expressions as well as at the top level (#141042). Key ideas are:
struct information is gathered using several pre-passes before
generateInfoForComponentList
."PartialStruct" is turned into a map, keyed on the "effective base" of each containing structure in a set of expressions in OpenMP 'map' clauses.
the reverse iterator over component lists (visiting the base decl, then walking out to the full expression) has a new 'ComponentListRefPtrPteeIterator' adapter that (a) visits reference-type list components twice, and (b) provides a few useful utility methods.
The current state is that a couple of tests work up to a point, but I'm hitting problems with the runtime that will probably be helped by the in-progress patches to support ATTACH operations.
This is obviously all full of debug code and not at all ready for review! Posting FYI.