[PATCH] D12871: [OpenMP] Target directive host codegen - rebased
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 16 02:21:13 PDT 2015
ABataev added inline comments.
================
Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3044-3054
@@ +3043,13 @@
+
+ if (auto *VAT = dyn_cast<VariableArrayType>(ElementType.getTypePtr())) {
+ auto VATInfo = CGF.getVLASize(VAT);
+ Size = llvm::ConstantInt::get(
+ CGM.SizeTy,
+ CGM.getContext().getTypeSizeInChars(VATInfo.second).getQuantity());
+ Size = CGF.Builder.CreateNUWMul(Size, VATInfo.first);
+ } else {
+ uint64_t ElementTypeSize =
+ CGM.getContext().getTypeSizeInChars(ElementType).getQuantity();
+ Size = llvm::ConstantInt::get(CGM.SizeTy, ElementTypeSize);
+ }
+
----------------
Use `getTypeSize(CGF, ElementType)` instead
================
Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:3082-3128
@@ +3081,49 @@
+
+ // Generate the code to launch the target region. The pattern is the
+ // following:
+ //
+ // ...
+ // br IfCond (if any), omp_offload, omp_offload_fail
+ //
+ // omp_offload.try:
+ // ; create arrays for offloading
+ // error = __tgt_target(...)
+ // br error, omp_offload_fail, omp_offload_end
+ //
+ // omp_offload.fail:
+ // host_version(...)
+ //
+ // omp_offload.end:
+ // ...
+ //
+
+ auto OffloadTryBlock = CGF.createBasicBlock("omp_offload.try");
+ auto OffloadFailBlock = CGF.createBasicBlock("omp_offload.fail");
+ auto ContBlock = CGF.createBasicBlock("omp_offload.end");
+
+ if (IfCond)
+ CGF.EmitBranchOnBoolExpr(IfCond, OffloadTryBlock, OffloadFailBlock,
+ /*TrueCount=*/0);
+
+ CGF.EmitBlock(OffloadTryBlock);
+
+ unsigned PointerNumVal = BasePointers.size();
+ llvm::Value *PointerNum = CGF.Builder.getInt32(PointerNumVal);
+ llvm::Value *BasePointersArray;
+ llvm::Value *PointersArray;
+ llvm::Value *SizesArray;
+ llvm::Value *MapTypesArray;
+
+ if (PointerNumVal) {
+ llvm::APInt PointerNumAP(32, PointerNumVal, /*isSigned=*/true);
+ QualType PointerArrayType = CGF.getContext().getConstantArrayType(
+ CGF.getContext().VoidPtrTy, PointerNumAP, ArrayType::Normal,
+ /*IndexTypeQuals=*/0);
+
+ BasePointersArray =
+ CGF.CreateMemTemp(PointerArrayType, ".offload_baseptrs").getPointer();
+ PointersArray =
+ CGF.CreateMemTemp(PointerArrayType, ".offload_ptrs").getPointer();
+
+ // If we don't have any VLA types, we can use a constant array for the map
+ // sizes, otherwise we need to fill up the arrays as we do for the pointers.
----------------
Could you use `emitOMPIfClause()` function instead of this long block?
================
Comment at: lib/CodeGen/CGStmtOpenMP.cpp:38
@@ +37,3 @@
+ if (UseOnlyReferences) {
+ LValue LV = MakeNaturalAlignAddrLValue(
+ CreateMemTemp(CurField->getType(), "__vla_size_ref").getPointer(),
----------------
Use `MakeAddrLValue(CreateMemTemp(CurField->getType(), "__vla_size_ref"), CurField->getType())` instead.
================
Comment at: lib/CodeGen/CGStmtOpenMP.cpp:80-81
@@ -67,2 +79,4 @@
II = &getContext().Idents.get("vla");
+ if (UseOnlyReferences)
+ ArgType = getContext().getPointerType(ArgType);
}
----------------
Use `getContext().getLValueReferenceType(ArgType, /*SpelledAsLValue=*/false);`
================
Comment at: lib/CodeGen/CGStmtOpenMP.cpp:117-122
@@ -102,4 +116,8 @@
if (FD->hasCapturedVLAType()) {
auto *ExprArg =
EmitLoadOfLValue(ArgLVal, SourceLocation()).getScalarVal();
+ if (UseOnlyReferences) {
+ auto ExprArgRef = MakeNaturalAlignAddrLValue(ExprArg, FD->getType());
+ ExprArg = EmitLoadOfLValue(ExprArgRef, SourceLocation()).getScalarVal();
+ }
auto VAT = FD->getCapturedVLAType();
----------------
```
if (UseOnlyReferences)
ArgLVal = CGF.EmitLoadOfReferenceLValue(ArgLVal.getAddress(), FD->getType()->casAs<ReferenceType>());
auto *ExprArg = EmitLoadOfLValue(ArgLVal, SourceLocation()).getScalarVal();
```
http://reviews.llvm.org/D12871
More information about the cfe-commits
mailing list