@@ -1262,65 +1262,6 @@ Value *SPIRVToLLVM::oclTransConstantPipeStorage(
1262
1262
GlobalValue::NotThreadLocal, SPIRAS_Global);
1263
1263
}
1264
1264
1265
- namespace {
1266
-
1267
- // A pointer annotation may have been generated for the operand. If the operand
1268
- // is used further in IR, it should be replaced with the intrinsic call result.
1269
- // Otherwise, the generated pointer annotation call is left unused.
1270
- static void replaceOperandWithAnnotationIntrinsicCallResult (Function *F,
1271
- Value *&V) {
1272
-
1273
- SPIRVDBG (spvdbgs () << " \n "
1274
- << " -------- REPLACE --------" << ' \n ' ;)
1275
- SPIRVDBG (dbgs () << " value: " << *V << ' \n ' );
1276
-
1277
- Value *BaseValue = nullptr ;
1278
- IntrinsicInst *CallResult = nullptr ;
1279
-
1280
- auto SearchPtrAnn = [=](Value *BV, IntrinsicInst *&CR) {
1281
- CR = nullptr ;
1282
- for (auto *Use : BV->users ()) {
1283
- if (auto *II = dyn_cast<IntrinsicInst>(Use)) {
1284
- if (II->getIntrinsicID () == Intrinsic::ptr_annotation &&
1285
- II->getType () == BV->getType ())
1286
- CR = II;
1287
- }
1288
- }
1289
- return CR ? true : false ;
1290
- };
1291
-
1292
- if (SearchPtrAnn (V, CallResult)) {
1293
- BaseValue = V;
1294
- } else {
1295
- // scan def-use chain, skip bitcast and addrspacecast
1296
- // search for the closest floating ptr.annotation
1297
- auto *Inst = dyn_cast<Instruction>(V);
1298
- while (Inst && (isa<BitCastInst>(Inst) || isa<AddrSpaceCastInst>(Inst))) {
1299
- if ((Inst = dyn_cast<Instruction>(Inst->getOperand (0 ))) &&
1300
- SearchPtrAnn (Inst, CallResult)) {
1301
- BaseValue = Inst;
1302
- break ;
1303
- }
1304
- }
1305
- }
1306
-
1307
- // overwrite operand with intrinsic call result
1308
- if (CallResult) {
1309
- SPIRVDBG (dbgs () << " BaseValue: " << *BaseValue << ' \n '
1310
- << " CallResult: " << *CallResult << ' \n ' );
1311
- DominatorTree DT (*F);
1312
- BaseValue->replaceUsesWithIf (CallResult, [&DT, &CallResult](Use &U) {
1313
- return DT.dominates (CallResult, U);
1314
- });
1315
-
1316
- // overwrite V
1317
- if (V == BaseValue)
1318
- V = CallResult;
1319
- }
1320
- }
1321
-
1322
- } // namespace
1323
-
1324
1265
// Translate aliasing memory access masks for SPIRVLoad and SPIRVStore
1325
1266
// instructions. These masks are mapped on alias.scope and noalias
1326
1267
// metadata in LLVM. Translation of optional string operand isn't yet supported
@@ -1798,10 +1739,6 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
1798
1739
StoreInst *SI = nullptr ;
1799
1740
auto *Src = transValue (BS->getSrc (), F, BB);
1800
1741
auto *Dst = transValue (BS->getDst (), F, BB);
1801
- // A ptr.annotation may have been generated for the source variable.
1802
- replaceOperandWithAnnotationIntrinsicCallResult (F, Src);
1803
- // A ptr.annotation may have been generated for the destination variable.
1804
- replaceOperandWithAnnotationIntrinsicCallResult (F, Dst);
1805
1742
1806
1743
bool isVolatile = BS->SPIRVMemoryAccess ::isVolatile ();
1807
1744
uint64_t AlignValue = BS->SPIRVMemoryAccess ::getAlignment ();
@@ -1818,8 +1755,6 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
1818
1755
case OpLoad: {
1819
1756
SPIRVLoad *BL = static_cast <SPIRVLoad *>(BV);
1820
1757
auto *V = transValue (BL->getSrc (), F, BB);
1821
- // A ptr.annotation may have been generated for the source variable.
1822
- replaceOperandWithAnnotationIntrinsicCallResult (F, V);
1823
1758
1824
1759
Type *Ty = transType (BL->getType ());
1825
1760
LoadInst *LI = nullptr ;
@@ -1847,14 +1782,8 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
1847
1782
bool IsVolatile = BC->SPIRVMemoryAccess ::isVolatile ();
1848
1783
IRBuilder<> Builder (BB);
1849
1784
1850
- // A ptr.annotation may have been generated for the destination variable.
1851
- replaceOperandWithAnnotationIntrinsicCallResult (F, Dst);
1852
-
1853
1785
if (!CI) {
1854
1786
llvm::Value *Src = transValue (BC->getSource (), F, BB);
1855
-
1856
- // A ptr.annotation may have been generated for the source variable.
1857
- replaceOperandWithAnnotationIntrinsicCallResult (F, Src);
1858
1787
CI = Builder.CreateMemCpy (Dst, Align, Src, Align, Size, IsVolatile);
1859
1788
}
1860
1789
if (isFuncNoUnwind ())
@@ -2401,9 +2330,6 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
2401
2330
std::vector<Value *> Args = transValue (BC->getArgumentValues (), F, BB);
2402
2331
auto *Call = CallInst::Create (transFunction (BC->getFunction ()), Args,
2403
2332
BC->getName (), BB);
2404
- for (auto *Arg : Args)
2405
- if (Arg->getType ()->isPointerTy ())
2406
- replaceOperandWithAnnotationIntrinsicCallResult (F, Arg);
2407
2333
setCallingConv (Call);
2408
2334
setAttrByCalledFunc (Call);
2409
2335
return mapValue (BV, Call);
@@ -3693,6 +3619,7 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3693
3619
for (SPIRVWord I = 0 ; I < STS->getMemberCount (); ++I) {
3694
3620
std::vector<SmallString<256 >> AnnotStrVec;
3695
3621
generateIntelFPGAAnnotationForStructMember (ST, I, AnnotStrVec);
3622
+ CallInst *AnnotationCall = nullptr ;
3696
3623
for (const auto &AnnotStr : AnnotStrVec) {
3697
3624
auto *GS = Builder.CreateGlobalStringPtr (AnnotStr);
3698
3625
@@ -3727,14 +3654,17 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3727
3654
PtrAnnFirstArg->getName ()),
3728
3655
Builder.CreateBitCast (GS, Int8PtrTyPrivate), UndefInt8Ptr,
3729
3656
UndefInt32, UndefInt8Ptr};
3730
- auto *PtrAnnotationCall = Builder.CreateCall (AnnotationFn, Args);
3731
- GEPOrUseMap[AL][I] = PtrAnnotationCall ;
3657
+ AnnotationCall = Builder.CreateCall (AnnotationFn, Args);
3658
+ GEPOrUseMap[AL][I] = AnnotationCall ;
3732
3659
}
3660
+ if (AnnotationCall)
3661
+ ValueMap[BV] = AnnotationCall;
3733
3662
}
3734
3663
}
3735
3664
3736
3665
std::vector<SmallString<256 >> AnnotStrVec;
3737
3666
generateIntelFPGAAnnotation (BV, AnnotStrVec);
3667
+ CallInst *AnnotationCall = nullptr ;
3738
3668
for (const auto &AnnotStr : AnnotStrVec) {
3739
3669
Constant *GS = nullptr ;
3740
3670
const auto StringAnnotStr = static_cast <std::string>(AnnotStr);
@@ -3746,8 +3676,12 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3746
3676
AnnotationsMap.emplace (std::move (StringAnnotStr), GS);
3747
3677
}
3748
3678
3749
- Value *BaseInst =
3750
- AL ? Builder.CreateBitCast (V, Int8PtrTyPrivate, V->getName ()) : Inst;
3679
+ Value *BaseInst = nullptr ;
3680
+ if (AnnotationCall && !AnnotationCall->getType ()->isVoidTy ())
3681
+ BaseInst = AnnotationCall;
3682
+ else
3683
+ BaseInst = AL ? Builder.CreateBitCast (V, Int8PtrTyPrivate, V->getName ())
3684
+ : Inst;
3751
3685
3752
3686
// Try to find alloca instruction for statically allocated variables.
3753
3687
// Alloca might be hidden by a couple of casts.
@@ -3766,8 +3700,10 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3766
3700
llvm::Value *Args[] = {BaseInst,
3767
3701
Builder.CreateBitCast (GS, Int8PtrTyPrivate),
3768
3702
UndefInt8Ptr, UndefInt32, UndefInt8Ptr};
3769
- Builder.CreateCall (AnnotationFn, Args);
3703
+ AnnotationCall = Builder.CreateCall (AnnotationFn, Args);
3770
3704
}
3705
+ if (AnnotationCall && !AnnotationCall->getType ()->isVoidTy ())
3706
+ ValueMap[BV] = AnnotationCall;
3771
3707
} else if (auto *GV = dyn_cast<GlobalVariable>(V)) {
3772
3708
std::vector<SmallString<256 >> AnnotStrVec;
3773
3709
generateIntelFPGAAnnotation (BV, AnnotStrVec);
0 commit comments