Skip to content

Commit 71052ea

Browse files
[openmp] Apply code change from D109500
1 parent bfcf979 commit 71052ea

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,8 @@ bool OpenMPOpt::rewriteDeviceCodeStateMachine() {
20412041
UndefValue::get(Int8Ty), F->getName() + ".ID");
20422042

20432043
for (Use *U : ToBeReplacedStateMachineUses)
2044-
U->set(ConstantExpr::getBitCast(ID, U->get()->getType()));
2044+
U->set(ConstantExpr::getPointerBitCastOrAddrSpaceCast(
2045+
ID, U->get()->getType()));
20452046

20462047
++NumOpenMPParallelRegionsReplacedInGPUStateMachine;
20472048

@@ -3455,10 +3456,14 @@ struct AAKernelInfoFunction : AAKernelInfo {
34553456
IsWorker->setDebugLoc(DLoc);
34563457
BranchInst::Create(StateMachineBeginBB, UserCodeEntryBB, IsWorker, InitBB);
34573458

3459+
Module &M = *Kernel->getParent();
3460+
34583461
// Create local storage for the work function pointer.
3462+
const DataLayout &DL = M.getDataLayout();
34593463
Type *VoidPtrTy = Type::getInt8PtrTy(Ctx);
3460-
AllocaInst *WorkFnAI = new AllocaInst(VoidPtrTy, 0, "worker.work_fn.addr",
3461-
&Kernel->getEntryBlock().front());
3464+
Instruction *WorkFnAI =
3465+
new AllocaInst(VoidPtrTy, DL.getAllocaAddrSpace(), nullptr,
3466+
"worker.work_fn.addr", &Kernel->getEntryBlock().front());
34623467
WorkFnAI->setDebugLoc(DLoc);
34633468

34643469
auto &OMPInfoCache = static_cast<OMPInformationCache &>(A.getInfoCache());
@@ -3471,13 +3476,23 @@ struct AAKernelInfoFunction : AAKernelInfo {
34713476
Value *Ident = KernelInitCB->getArgOperand(0);
34723477
Value *GTid = KernelInitCB;
34733478

3474-
Module &M = *Kernel->getParent();
34753479
FunctionCallee BarrierFn =
34763480
OMPInfoCache.OMPBuilder.getOrCreateRuntimeFunction(
34773481
M, OMPRTL___kmpc_barrier_simple_spmd);
34783482
CallInst::Create(BarrierFn, {Ident, GTid}, "", StateMachineBeginBB)
34793483
->setDebugLoc(DLoc);
34803484

3485+
if (WorkFnAI->getType()->getPointerAddressSpace() !=
3486+
(unsigned int)AddressSpace::Generic) {
3487+
WorkFnAI = new AddrSpaceCastInst(
3488+
WorkFnAI,
3489+
PointerType::getWithSamePointeeType(
3490+
cast<PointerType>(WorkFnAI->getType()),
3491+
(unsigned int)AddressSpace::Generic),
3492+
WorkFnAI->getName() + ".generic", StateMachineBeginBB);
3493+
WorkFnAI->setDebugLoc(DLoc);
3494+
}
3495+
34813496
FunctionCallee KernelParallelFn =
34823497
OMPInfoCache.OMPBuilder.getOrCreateRuntimeFunction(
34833498
M, OMPRTL___kmpc_kernel_parallel);

0 commit comments

Comments
 (0)