@@ -394,20 +394,28 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
394394// This function creates a fake integer value and a fake use for the integer
395395// value. It returns the fake value created. This is useful in modeling the
396396// extra arguments to the outlined functions.
397- Value *createFakeIntVal (IRBuilderBase &Builder,
397+ Value *createFakeIntVal (IRBuilderBase &Builder, Module &M,
398398 OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
399399 llvm::SmallVectorImpl<Instruction *> &ToBeDeleted,
400400 OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
401401 const Twine &Name = " " , bool AsPtr = true ) {
402402 Builder.restoreIP (OuterAllocaIP);
403403 Instruction *FakeVal;
404404 AllocaInst *FakeValAddr =
405- Builder.CreateAlloca (Builder.getInt32Ty (), 0 , nullptr , Name + " .addr" );
405+ Builder.CreateAlloca (Builder.getInt32Ty (), nullptr , Name + " .addr" );
406+ FakeVal = FakeValAddr;
407+
408+ if (M.getDataLayout ().getAllocaAddrSpace () != 0 ) {
409+ // Add additional casts to enforce pointers in zero address space
410+ FakeVal = new AddrSpaceCastInst (
411+ FakeValAddr, PointerType ::get (M.getContext (), 0 ), " tid.addr.ascast" );
412+ FakeVal->insertAfter (FakeValAddr->getIterator ());
413+ ToBeDeleted.push_back (FakeVal);
414+ }
415+
406416 ToBeDeleted.push_back (FakeValAddr);
407417
408- if (AsPtr) {
409- FakeVal = FakeValAddr;
410- } else {
418+ if (!AsPtr) {
411419 FakeVal =
412420 Builder.CreateLoad (Builder.getInt32Ty (), FakeValAddr, Name + " .val" );
413421 ToBeDeleted.push_back (FakeVal);
@@ -1941,7 +1949,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
19411949 // Add the thread ID argument.
19421950 SmallVector<Instruction *, 4 > ToBeDeleted;
19431951 OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
1944- Builder, AllocaIP, ToBeDeleted, TaskAllocaIP, " global.tid" , false ));
1952+ Builder, M, AllocaIP, ToBeDeleted, TaskAllocaIP, " global.tid" , false ));
19451953
19461954 OI.PostOutlineCB = [this , Ident, Tied, Final, IfCondition, Dependencies,
19471955 Mergeable, Priority, EventHandle, TaskAllocaBB,
@@ -7541,8 +7549,9 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
75417549
75427550 // Add the thread ID argument.
75437551 SmallVector<Instruction *, 4 > ToBeDeleted;
7544- OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
7545- Builder, AllocaIP, ToBeDeleted, TargetTaskAllocaIP, " global.tid" , false ));
7552+ OI.ExcludeArgsFromAggregate .push_back (
7553+ createFakeIntVal (Builder, M, AllocaIP, ToBeDeleted, TargetTaskAllocaIP,
7554+ " global.tid" , false ));
75467555
75477556 // Generate the task body which will subsequently be outlined.
75487557 Builder.restoreIP (TargetTaskBodyIP);
@@ -9532,9 +9541,9 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
95329541 SmallVector<Instruction *, 8 > ToBeDeleted;
95339542 InsertPointTy OuterAllocaIP (&OuterAllocaBB, OuterAllocaBB.begin ());
95349543 OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
9535- Builder, OuterAllocaIP, ToBeDeleted, AllocaIP, " gid" , true ));
9544+ Builder, M, OuterAllocaIP, ToBeDeleted, AllocaIP, " gid" , true ));
95369545 OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
9537- Builder, OuterAllocaIP, ToBeDeleted, AllocaIP, " tid" , true ));
9546+ Builder, M, OuterAllocaIP, ToBeDeleted, AllocaIP, " tid" , true ));
95389547
95399548 auto HostPostOutlineCB = [this , Ident,
95409549 ToBeDeleted](Function &OutlinedFn) mutable {
0 commit comments