Skip to content

Commit 468f3a0

Browse files
committed
Guard 3be16bd
1 parent 28c850a commit 468f3a0

File tree

2 files changed

+153
-1
lines changed

2 files changed

+153
-1
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ class IRBuilderBase {
140140
ClearInsertionPoint();
141141
}
142142

143+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
144+
Value *getCastedInt8PtrValue(Value *Ptr);
145+
#endif
146+
143147
/// Insert and return the specified instruction.
144148
template<typename InstTy>
145149
InstTy *Insert(InstTy *I, const Twine &Name = "") const {

llvm/lib/IR/IRBuilder.cpp

Lines changed: 149 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ Type *IRBuilderBase::getCurrentFunctionReturnType() const {
5959
assert(BB && BB->getParent() && "No current function!");
6060
return BB->getParent()->getReturnType();
6161
}
62+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
63+
Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) {
64+
auto *PT = cast<PointerType>(Ptr->getType());
65+
if (PT->isOpaqueOrPointeeTypeMatches(getInt8Ty()))
66+
return Ptr;
67+
68+
// Otherwise, we need to insert a bitcast.
69+
return CreateBitCast(Ptr, getInt8PtrTy(PT->getAddressSpace()));
70+
}
71+
#endif
6272

6373
DebugLoc IRBuilderBase::getCurrentDebugLocation() const {
6474
for (auto &KV : MetadataToCopy)
@@ -138,6 +148,9 @@ CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size,
138148
MaybeAlign Align, bool isVolatile,
139149
MDNode *TBAATag, MDNode *ScopeTag,
140150
MDNode *NoAliasTag) {
151+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
152+
Ptr = getCastedInt8PtrValue(Ptr);
153+
#endif
141154
Value *Ops[] = {Ptr, Val, Size, getInt1(isVolatile)};
142155
Type *Tys[] = { Ptr->getType(), Size->getType() };
143156
Module *M = BB->getParent()->getParent();
@@ -166,6 +179,9 @@ CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
166179
bool IsVolatile, MDNode *TBAATag,
167180
MDNode *ScopeTag,
168181
MDNode *NoAliasTag) {
182+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
183+
Dst = getCastedInt8PtrValue(Dst);
184+
#endif
169185
Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)};
170186
Type *Tys[] = {Dst->getType(), Size->getType()};
171187
Module *M = BB->getParent()->getParent();
@@ -192,7 +208,9 @@ CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign,
192208
CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemSet(
193209
Value *Ptr, Value *Val, Value *Size, Align Alignment, uint32_t ElementSize,
194210
MDNode *TBAATag, MDNode *ScopeTag, MDNode *NoAliasTag) {
195-
211+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
212+
Ptr = getCastedInt8PtrValue(Ptr);
213+
#endif
196214
Value *Ops[] = {Ptr, Val, Size, getInt32(ElementSize)};
197215
Type *Tys[] = {Ptr->getType(), Size->getType()};
198216
Module *M = BB->getParent()->getParent();
@@ -220,6 +238,11 @@ CallInst *IRBuilderBase::CreateMemTransferInst(
220238
Intrinsic::ID IntrID, Value *Dst, MaybeAlign DstAlign, Value *Src,
221239
MaybeAlign SrcAlign, Value *Size, bool isVolatile, MDNode *TBAATag,
222240
MDNode *TBAAStructTag, MDNode *ScopeTag, MDNode *NoAliasTag) {
241+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
242+
Dst = getCastedInt8PtrValue(Dst);
243+
Src = getCastedInt8PtrValue(Src);
244+
#endif
245+
223246
Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
224247
Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
225248
Module *M = BB->getParent()->getParent();
@@ -254,6 +277,11 @@ CallInst *IRBuilderBase::CreateMemCpyInline(
254277
Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign,
255278
Value *Size, bool IsVolatile, MDNode *TBAATag, MDNode *TBAAStructTag,
256279
MDNode *ScopeTag, MDNode *NoAliasTag) {
280+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
281+
Dst = getCastedInt8PtrValue(Dst);
282+
Src = getCastedInt8PtrValue(Src);
283+
#endif
284+
257285
Value *Ops[] = {Dst, Src, Size, getInt1(IsVolatile)};
258286
Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
259287
Function *F = BB->getParent();
@@ -293,6 +321,11 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemCpy(
293321
"Pointer alignment must be at least element size");
294322
assert(SrcAlign >= ElementSize &&
295323
"Pointer alignment must be at least element size");
324+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
325+
Dst = getCastedInt8PtrValue(Dst);
326+
Src = getCastedInt8PtrValue(Src);
327+
#endif
328+
296329
Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
297330
Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
298331
Module *M = BB->getParent()->getParent();
@@ -328,6 +361,11 @@ CallInst *IRBuilderBase::CreateMemMove(Value *Dst, MaybeAlign DstAlign,
328361
Value *Size, bool isVolatile,
329362
MDNode *TBAATag, MDNode *ScopeTag,
330363
MDNode *NoAliasTag) {
364+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
365+
Dst = getCastedInt8PtrValue(Dst);
366+
Src = getCastedInt8PtrValue(Src);
367+
#endif
368+
331369
Value *Ops[] = {Dst, Src, Size, getInt1(isVolatile)};
332370
Type *Tys[] = { Dst->getType(), Src->getType(), Size->getType() };
333371
Module *M = BB->getParent()->getParent();
@@ -362,6 +400,11 @@ CallInst *IRBuilderBase::CreateElementUnorderedAtomicMemMove(
362400
"Pointer alignment must be at least element size");
363401
assert(SrcAlign >= ElementSize &&
364402
"Pointer alignment must be at least element size");
403+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
404+
Dst = getCastedInt8PtrValue(Dst);
405+
Src = getCastedInt8PtrValue(Src);
406+
#endif
407+
365408
Value *Ops[] = {Dst, Src, Size, getInt32(ElementSize)};
366409
Type *Tys[] = {Dst->getType(), Src->getType(), Size->getType()};
367410
Module *M = BB->getParent()->getParent();
@@ -466,6 +509,9 @@ CallInst *IRBuilderBase::CreateFPMinimumReduce(Value *Src) {
466509
CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
467510
assert(isa<PointerType>(Ptr->getType()) &&
468511
"lifetime.start only applies to pointers.");
512+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
513+
Ptr = getCastedInt8PtrValue(Ptr);
514+
#endif
469515
if (!Size)
470516
Size = getInt64(-1);
471517
else
@@ -481,6 +527,9 @@ CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
481527
CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
482528
assert(isa<PointerType>(Ptr->getType()) &&
483529
"lifetime.end only applies to pointers.");
530+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
531+
Ptr = getCastedInt8PtrValue(Ptr);
532+
#endif
484533
if (!Size)
485534
Size = getInt64(-1);
486535
else
@@ -497,6 +546,9 @@ CallInst *IRBuilderBase::CreateInvariantStart(Value *Ptr, ConstantInt *Size) {
497546

498547
assert(isa<PointerType>(Ptr->getType()) &&
499548
"invariant.start only applies to pointers.");
549+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
550+
Ptr = getCastedInt8PtrValue(Ptr);
551+
#endif
500552
if (!Size)
501553
Size = getInt64(-1);
502554
else
@@ -576,6 +628,9 @@ CallInst *IRBuilderBase::CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment,
576628
const Twine &Name) {
577629
auto *PtrTy = cast<PointerType>(Ptr->getType());
578630
assert(Ty->isVectorTy() && "Type should be vector");
631+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
632+
assert(PtrTy->isOpaqueOrPointeeTypeMatches(Ty) && "Wrong element type");
633+
#endif
579634
assert(Mask && "Mask should not be all-ones (null)");
580635
if (!PassThru)
581636
PassThru = PoisonValue::get(Ty);
@@ -596,6 +651,9 @@ CallInst *IRBuilderBase::CreateMaskedStore(Value *Val, Value *Ptr,
596651
auto *PtrTy = cast<PointerType>(Ptr->getType());
597652
Type *DataTy = Val->getType();
598653
assert(DataTy->isVectorTy() && "Val should be a vector");
654+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
655+
assert(PtrTy->isOpaqueOrPointeeTypeMatches(DataTy) && "Wrong element type");
656+
#endif
599657
assert(Mask && "Mask should not be all-ones (null)");
600658
Type *OverloadedTypes[] = { DataTy, PtrTy };
601659
Value *Ops[] = {Val, Ptr, getInt32(Alignment.value()), Mask};
@@ -630,6 +688,12 @@ CallInst *IRBuilderBase::CreateMaskedGather(Type *Ty, Value *Ptrs,
630688
auto *VecTy = cast<VectorType>(Ty);
631689
ElementCount NumElts = VecTy->getElementCount();
632690
auto *PtrsTy = cast<VectorType>(Ptrs->getType());
691+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
692+
assert(cast<PointerType>(PtrsTy->getElementType())
693+
->isOpaqueOrPointeeTypeMatches(
694+
cast<VectorType>(Ty)->getElementType()) &&
695+
"Element type mismatch");
696+
#endif
633697
assert(NumElts == PtrsTy->getElementCount() && "Element count mismatch");
634698

635699
if (!Mask)
@@ -660,6 +724,15 @@ CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs,
660724
auto *DataTy = cast<VectorType>(Data->getType());
661725
ElementCount NumElts = PtrsTy->getElementCount();
662726

727+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
728+
#ifndef NDEBUG
729+
auto *PtrTy = cast<PointerType>(PtrsTy->getElementType());
730+
assert(NumElts == DataTy->getElementCount() &&
731+
PtrTy->isOpaqueOrPointeeTypeMatches(DataTy->getElementType()) &&
732+
"Incompatible pointer and data types");
733+
#endif
734+
#endif
735+
663736
if (!Mask)
664737
Mask = getAllOnesMask(NumElts);
665738

@@ -682,7 +755,16 @@ CallInst *IRBuilderBase::CreateMaskedScatter(Value *Data, Value *Ptrs,
682755
CallInst *IRBuilderBase::CreateMaskedExpandLoad(Type *Ty, Value *Ptr,
683756
Value *Mask, Value *PassThru,
684757
const Twine &Name) {
758+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
759+
auto *PtrTy = cast<PointerType>(Ptr->getType());
760+
#endif
685761
assert(Ty->isVectorTy() && "Type should be vector");
762+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
763+
assert(PtrTy->isOpaqueOrPointeeTypeMatches(
764+
cast<FixedVectorType>(Ty)->getElementType()) &&
765+
"Wrong element type");
766+
(void)PtrTy;
767+
#endif
686768
assert(Mask && "Mask should not be all-ones (null)");
687769
if (!PassThru)
688770
PassThru = PoisonValue::get(Ty);
@@ -699,8 +781,17 @@ CallInst *IRBuilderBase::CreateMaskedExpandLoad(Type *Ty, Value *Ptr,
699781
/// be accessed in memory
700782
CallInst *IRBuilderBase::CreateMaskedCompressStore(Value *Val, Value *Ptr,
701783
Value *Mask) {
784+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
785+
auto *PtrTy = cast<PointerType>(Ptr->getType());
786+
#endif
702787
Type *DataTy = Val->getType();
703788
assert(DataTy->isVectorTy() && "Val should be a vector");
789+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
790+
assert(PtrTy->isOpaqueOrPointeeTypeMatches(
791+
cast<FixedVectorType>(DataTy)->getElementType()) &&
792+
"Wrong element type");
793+
(void)PtrTy;
794+
#endif
704795
assert(Mask && "Mask should not be all-ones (null)");
705796
Type *OverloadedTypes[] = {DataTy};
706797
Value *Ops[] = {Val, Ptr, Mask};
@@ -1121,6 +1212,11 @@ Value *IRBuilderBase::CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS,
11211212
const Twine &Name) {
11221213
assert(LHS->getType() == RHS->getType() &&
11231214
"Pointer subtraction operand types must match!");
1215+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1216+
assert(cast<PointerType>(LHS->getType())
1217+
->isOpaqueOrPointeeTypeMatches(ElemTy) &&
1218+
"Pointer type must match element type");
1219+
#endif
11241220
Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
11251221
Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
11261222
Value *Difference = CreateSub(LHS_int, RHS_int);
@@ -1131,8 +1227,29 @@ Value *IRBuilderBase::CreatePtrDiff(Type *ElemTy, Value *LHS, Value *RHS,
11311227
Value *IRBuilderBase::CreateLaunderInvariantGroup(Value *Ptr) {
11321228
assert(isa<PointerType>(Ptr->getType()) &&
11331229
"launder.invariant.group only applies to pointers.");
1230+
// FIXME: we could potentially avoid casts to/from i8*.
11341231
auto *PtrType = Ptr->getType();
1232+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1233+
auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
1234+
if (PtrType != Int8PtrTy)
1235+
Ptr = CreateBitCast(Ptr, Int8PtrTy);
1236+
#endif
11351237
Module *M = BB->getParent()->getParent();
1238+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1239+
Function *FnLaunderInvariantGroup = Intrinsic::getDeclaration(
1240+
M, Intrinsic::launder_invariant_group, {Int8PtrTy});
1241+
1242+
assert(FnLaunderInvariantGroup->getReturnType() == Int8PtrTy &&
1243+
FnLaunderInvariantGroup->getFunctionType()->getParamType(0) ==
1244+
Int8PtrTy &&
1245+
"LaunderInvariantGroup should take and return the same type");
1246+
1247+
CallInst *Fn = CreateCall(FnLaunderInvariantGroup, {Ptr});
1248+
1249+
if (PtrType != Int8PtrTy)
1250+
return CreateBitCast(Fn, PtrType);
1251+
return Fn;
1252+
#else
11361253
Function *FnLaunderInvariantGroup = Intrinsic::getDeclaration(
11371254
M, Intrinsic::launder_invariant_group, {PtrType});
11381255

@@ -1142,14 +1259,36 @@ Value *IRBuilderBase::CreateLaunderInvariantGroup(Value *Ptr) {
11421259
"LaunderInvariantGroup should take and return the same type");
11431260

11441261
return CreateCall(FnLaunderInvariantGroup, {Ptr});
1262+
#endif
11451263
}
11461264

11471265
Value *IRBuilderBase::CreateStripInvariantGroup(Value *Ptr) {
11481266
assert(isa<PointerType>(Ptr->getType()) &&
11491267
"strip.invariant.group only applies to pointers.");
11501268

1269+
// FIXME: we could potentially avoid casts to/from i8*.
11511270
auto *PtrType = Ptr->getType();
1271+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1272+
auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
1273+
if (PtrType != Int8PtrTy)
1274+
Ptr = CreateBitCast(Ptr, Int8PtrTy);
1275+
#endif
11521276
Module *M = BB->getParent()->getParent();
1277+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1278+
Function *FnStripInvariantGroup = Intrinsic::getDeclaration(
1279+
M, Intrinsic::strip_invariant_group, {Int8PtrTy});
1280+
1281+
assert(FnStripInvariantGroup->getReturnType() == Int8PtrTy &&
1282+
FnStripInvariantGroup->getFunctionType()->getParamType(0) ==
1283+
Int8PtrTy &&
1284+
"StripInvariantGroup should take and return the same type");
1285+
1286+
CallInst *Fn = CreateCall(FnStripInvariantGroup, {Ptr});
1287+
1288+
if (PtrType != Int8PtrTy)
1289+
return CreateBitCast(Fn, PtrType);
1290+
return Fn;
1291+
#else
11531292
Function *FnStripInvariantGroup = Intrinsic::getDeclaration(
11541293
M, Intrinsic::strip_invariant_group, {PtrType});
11551294

@@ -1159,6 +1298,7 @@ Value *IRBuilderBase::CreateStripInvariantGroup(Value *Ptr) {
11591298
"StripInvariantGroup should take and return the same type");
11601299

11611300
return CreateCall(FnStripInvariantGroup, {Ptr});
1301+
#endif
11621302
}
11631303

11641304
Value *IRBuilderBase::CreateVectorReverse(Value *V, const Twine &Name) {
@@ -1254,6 +1394,10 @@ Value *IRBuilderBase::CreatePreserveArrayAccessIndex(
12541394
auto *BaseType = Base->getType();
12551395
assert(isa<PointerType>(BaseType) &&
12561396
"Invalid Base ptr type for preserve.array.access.index.");
1397+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1398+
assert(cast<PointerType>(BaseType)->isOpaqueOrPointeeTypeMatches(ElTy) &&
1399+
"Pointer element type mismatch");
1400+
#endif
12571401

12581402
Value *LastIndexV = getInt32(LastIndex);
12591403
Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
@@ -1307,6 +1451,10 @@ Value *IRBuilderBase::CreatePreserveStructAccessIndex(
13071451
auto *BaseType = Base->getType();
13081452
assert(isa<PointerType>(BaseType) &&
13091453
"Invalid Base ptr type for preserve.struct.access.index.");
1454+
#ifndef INTEL_SYCL_OPAQUEPOINTER_READY
1455+
assert(cast<PointerType>(BaseType)->isOpaqueOrPointeeTypeMatches(ElTy) &&
1456+
"Pointer element type mismatch");
1457+
#endif
13101458

13111459
Value *GEPIndex = getInt32(Index);
13121460
Constant *Zero = ConstantInt::get(Type::getInt32Ty(Context), 0);

0 commit comments

Comments
 (0)