[PATCH] D16749: [OpenMP] Map clause codegeneration.
Samuel Antao via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 17 07:55:38 PST 2016
sfantao marked an inline comment as done.
sfantao added a comment.
Hi Alexey,
================
Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3901-3932
@@ +3900,34 @@
+ // Reference types are ignored for mapping purposes.
+ if (auto *RefTy = ExprTy->getAs<ReferenceType>())
+ ExprTy = RefTy->getPointeeType().getCanonicalType();
+
+ // Given that an array section is considered a built-in type, we need to
+ // do the calculation based on the length of the section instead of relying
+ // on CGF.getTypeSize(E->getType()).
+ if (const auto *OAE = dyn_cast<OMPArraySectionExpr>(E)) {
+ auto BaseTy =
+ OAE->getBase()->IgnoreParenImpCasts()->getType().getCanonicalType();
+ // Reference types are ignored for mapping purposes.
+ if (auto *RefTy = BaseTy->getAs<ReferenceType>())
+ BaseTy = RefTy->getPointeeType().getCanonicalType();
+
+ // If there is no length associated with the expression, that means we
+ // are using the whole length of the base.
+ if (!OAE->getLength())
+ return CGF.getTypeSize(BaseTy);
+
+ llvm::Value *ElemSize;
+ if (auto *PTy = BaseTy->getAs<PointerType>()) {
+ ElemSize = CGF.getTypeSize(PTy->getPointeeType().getCanonicalType());
+ } else {
+ auto *ATy = cast<ArrayType>(BaseTy.getTypePtr());
+ assert(ATy && "Expecting array type if not a pointer type.");
+ ElemSize = CGF.getTypeSize(ATy->getElementType().getCanonicalType());
+ }
+
+ auto *LengthVal = CGF.EmitScalarExpr(OAE->getLength());
+ LengthVal =
+ CGF.Builder.CreateIntCast(LengthVal, CGF.SizeTy, /*isSigned=*/false);
+ return CGF.Builder.CreateNUWMul(LengthVal, ElemSize);
+ }
+ return CGF.getTypeSize(ExprTy);
----------------
ABataev wrote:
> What if the base is OMPArraySectionExpr? Will it work in this case?
Yes, it will work. There are a few regression tests for that in this patch already.
http://reviews.llvm.org/D16749
More information about the cfe-commits
mailing list