@@ -394,20 +394,28 @@ BasicBlock *llvm::splitBBWithSuffix(IRBuilderBase &Builder, bool CreateBranch,
394
394
// This function creates a fake integer value and a fake use for the integer
395
395
// value. It returns the fake value created. This is useful in modeling the
396
396
// extra arguments to the outlined functions.
397
- Value *createFakeIntVal (IRBuilderBase &Builder,
397
+ Value *createFakeIntVal (IRBuilderBase &Builder, Module &M,
398
398
OpenMPIRBuilder::InsertPointTy OuterAllocaIP,
399
399
llvm::SmallVectorImpl<Instruction *> &ToBeDeleted,
400
400
OpenMPIRBuilder::InsertPointTy InnerAllocaIP,
401
401
const Twine &Name = " " , bool AsPtr = true ) {
402
402
Builder.restoreIP (OuterAllocaIP);
403
403
Instruction *FakeVal;
404
404
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
+
406
416
ToBeDeleted.push_back (FakeValAddr);
407
417
408
- if (AsPtr) {
409
- FakeVal = FakeValAddr;
410
- } else {
418
+ if (!AsPtr) {
411
419
FakeVal =
412
420
Builder.CreateLoad (Builder.getInt32Ty (), FakeValAddr, Name + " .val" );
413
421
ToBeDeleted.push_back (FakeVal);
@@ -1941,7 +1949,7 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createTask(
1941
1949
// Add the thread ID argument.
1942
1950
SmallVector<Instruction *, 4 > ToBeDeleted;
1943
1951
OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
1944
- Builder, AllocaIP, ToBeDeleted, TaskAllocaIP, " global.tid" , false ));
1952
+ Builder, M, AllocaIP, ToBeDeleted, TaskAllocaIP, " global.tid" , false ));
1945
1953
1946
1954
OI.PostOutlineCB = [this , Ident, Tied, Final, IfCondition, Dependencies,
1947
1955
Mergeable, Priority, EventHandle, TaskAllocaBB,
@@ -7541,8 +7549,9 @@ OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::emitTargetTask(
7541
7549
7542
7550
// Add the thread ID argument.
7543
7551
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 ));
7546
7555
7547
7556
// Generate the task body which will subsequently be outlined.
7548
7557
Builder.restoreIP (TargetTaskBodyIP);
@@ -9532,9 +9541,9 @@ OpenMPIRBuilder::createTeams(const LocationDescription &Loc,
9532
9541
SmallVector<Instruction *, 8 > ToBeDeleted;
9533
9542
InsertPointTy OuterAllocaIP (&OuterAllocaBB, OuterAllocaBB.begin ());
9534
9543
OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
9535
- Builder, OuterAllocaIP, ToBeDeleted, AllocaIP, " gid" , true ));
9544
+ Builder, M, OuterAllocaIP, ToBeDeleted, AllocaIP, " gid" , true ));
9536
9545
OI.ExcludeArgsFromAggregate .push_back (createFakeIntVal (
9537
- Builder, OuterAllocaIP, ToBeDeleted, AllocaIP, " tid" , true ));
9546
+ Builder, M, OuterAllocaIP, ToBeDeleted, AllocaIP, " tid" , true ));
9538
9547
9539
9548
auto HostPostOutlineCB = [this , Ident,
9540
9549
ToBeDeleted](Function &OutlinedFn) mutable {
0 commit comments