[llvm] [OpenMP][OMPIRBuilder] Add support to omp target parallel (PR #67000)

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 14:52:12 PDT 2023


================
@@ -1137,13 +1318,32 @@ IRBuilder<>::InsertPoint OpenMPIRBuilder::createParallel(
   // Change the location to the outer alloca insertion point to create and
   // initialize the allocas we pass into the parallel region.
   Builder.restoreIP(OuterAllocaIP);
-  AllocaInst *TIDAddr = Builder.CreateAlloca(Int32, nullptr, "tid.addr");
-  AllocaInst *ZeroAddr = Builder.CreateAlloca(Int32, nullptr, "zero.addr");
+  AllocaInst *TIDAddrAlloca = Builder.CreateAlloca(Int32, nullptr, "tid.addr");
+  AllocaInst *ZeroAddrAlloca =
+      Builder.CreateAlloca(Int32, nullptr, "zero.addr");
+  Instruction *TIDAddr = nullptr;
+  Instruction *ZeroAddr = nullptr;
+  if (ArgsInZeroAddressSpace && M.getDataLayout().getAllocaAddrSpace() != 0) {
+    // Add additional casts to enforce pointers in zero address spac
+    TIDAddr = new AddrSpaceCastInst(TIDAddrAlloca,
+                                    TIDAddrAlloca->getType()->getPointerTo(),
+                                    "tid.addr.ascast");
+    TIDAddr->insertAfter(TIDAddrAlloca);
+    ToBeDeleted.push_back(TIDAddr);
+    ZeroAddr = new AddrSpaceCastInst(ZeroAddrAlloca,
+                                     ZeroAddrAlloca->getType()->getPointerTo(),
+                                     "zero.addr.ascast");
+    ZeroAddr->insertAfter(ZeroAddrAlloca);
+    ToBeDeleted.push_back(ZeroAddr);
+  } else {
+    TIDAddr = TIDAddrAlloca;
+    ZeroAddr = ZeroAddrAlloca;
----------------
jdoerfert wrote:

Initialize them directly in line 1324, so you can avoid the else. If you have an else case, put the simpler/shorter one first.

https://github.com/llvm/llvm-project/pull/67000


More information about the llvm-commits mailing list