[PATCH] D16749: [OpenMP] Map clause codegeneration.
Samuel Antao via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 18 11:03:23 PST 2016
sfantao added a comment.
Hi Alexey,
Thanks for the feedback!
================
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:
> Did not find any with array sections as base. Could please point a test where I can find something like 'marr[:][0:2][0:2]' as a mapped expression?
> Also, it will produce some recalculation for VLAs. Add a test for it, please.
> Did not find any with array sections as base. Could please point a test where I can find something like 'marr[:][0:2][0:2]' as a mapped expression?
Oh, a map that uses an array expression that is not in the rightmost subexpression is illegal because it would correspond to non-contiguous storage. Sema is already taking care of that. I added your specific example to the Sema tests anyway.
> Also, it will produce some recalculation for VLAs. Add a test for it, please.
Added tests for multidimensional VLAs.
http://reviews.llvm.org/D16749
More information about the cfe-commits
mailing list