[PATCH] D16749: [OpenMP] Map clause codegeneration.

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 19 04:43:18 PST 2016


ABataev added inline comments.

================
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);
----------------
sfantao wrote:
> ABataev wrote:
> > 'marr[:][:][:2]' produces contiguous storage, no? Is this allowed? And if it is allowed, how it will be handled? Besides, if 'marr' is a pointer, even 'marr[:2][:3][:4]' may result in contiguous space.
> > 'marr[:][:][:2]' produces contiguous storage, no? Is this allowed? And if it is allowed, how it will be handled?
> That is not contiguous so it is not allowed. `marr[:2][:][:]` is contiguous storage but can be expressed as `marr[:2]` only. Do you think I should create a patch to allow the latter case in Sema? Should it be part of this patch?
> 
> > Besides, if 'marr' is a pointer, even 'marr[:2][:3][:4]' may result in contiguous space.
> This is illegal. This requires multiple memory allocations that are not contiguous on the host.
> That is not contiguous so it is not allowed. marr[:2][:][:] is contiguous storage but can be expressed as marr[:2] only. Do you think I should create a patch to allow the latter case in Sema? Should it be part of this patch?
Yes, I think this must be supported. Also we should support marr[:2][0:size2][0:size3] forms, if they produce contiguous space. No, it should be a separate patch.






http://reviews.llvm.org/D16749





More information about the cfe-commits mailing list