@@ -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 ())
@@ -2400,9 +2329,6 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
2400
2329
std::vector<Value *> Args = transValue (BC->getArgumentValues (), F, BB);
2401
2330
auto *Call = CallInst::Create (transFunction (BC->getFunction ()), Args,
2402
2331
BC->getName (), BB);
2403
- for (auto *Arg : Args)
2404
- if (Arg->getType ()->isPointerTy ())
2405
- replaceOperandWithAnnotationIntrinsicCallResult (F, Arg);
2406
2332
setCallingConv (Call);
2407
2333
setAttrByCalledFunc (Call);
2408
2334
return mapValue (BV, Call);
@@ -3718,6 +3644,7 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3718
3644
for (SPIRVWord I = 0 ; I < STS->getMemberCount (); ++I) {
3719
3645
std::vector<SmallString<256 >> AnnotStrVec;
3720
3646
generateIntelFPGAAnnotationForStructMember (ST, I, AnnotStrVec);
3647
+ CallInst *AnnotationCall = nullptr ;
3721
3648
for (const auto &AnnotStr : AnnotStrVec) {
3722
3649
auto *GS = Builder.CreateGlobalStringPtr (AnnotStr);
3723
3650
@@ -3752,14 +3679,17 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3752
3679
PtrAnnFirstArg->getName ()),
3753
3680
Builder.CreateBitCast (GS, Int8PtrTyPrivate), UndefInt8Ptr,
3754
3681
UndefInt32, UndefInt8Ptr};
3755
- auto *PtrAnnotationCall = Builder.CreateCall (AnnotationFn, Args);
3756
- GEPOrUseMap[AL][I] = PtrAnnotationCall ;
3682
+ AnnotationCall = Builder.CreateCall (AnnotationFn, Args);
3683
+ GEPOrUseMap[AL][I] = AnnotationCall ;
3757
3684
}
3685
+ if (AnnotationCall)
3686
+ ValueMap[BV] = AnnotationCall;
3758
3687
}
3759
3688
}
3760
3689
3761
3690
std::vector<SmallString<256 >> AnnotStrVec;
3762
3691
generateIntelFPGAAnnotation (BV, AnnotStrVec);
3692
+ CallInst *AnnotationCall = nullptr ;
3763
3693
for (const auto &AnnotStr : AnnotStrVec) {
3764
3694
Constant *GS = nullptr ;
3765
3695
const auto StringAnnotStr = static_cast <std::string>(AnnotStr);
@@ -3771,8 +3701,12 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3771
3701
AnnotationsMap.emplace (std::move (StringAnnotStr), GS);
3772
3702
}
3773
3703
3774
- Value *BaseInst =
3775
- AL ? Builder.CreateBitCast (V, Int8PtrTyPrivate, V->getName ()) : Inst;
3704
+ Value *BaseInst = nullptr ;
3705
+ if (AnnotationCall && !AnnotationCall->getType ()->isVoidTy ())
3706
+ BaseInst = AnnotationCall;
3707
+ else
3708
+ BaseInst = AL ? Builder.CreateBitCast (V, Int8PtrTyPrivate, V->getName ())
3709
+ : Inst;
3776
3710
3777
3711
// Try to find alloca instruction for statically allocated variables.
3778
3712
// Alloca might be hidden by a couple of casts.
@@ -3791,8 +3725,10 @@ void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3791
3725
llvm::Value *Args[] = {BaseInst,
3792
3726
Builder.CreateBitCast (GS, Int8PtrTyPrivate),
3793
3727
UndefInt8Ptr, UndefInt32, UndefInt8Ptr};
3794
- Builder.CreateCall (AnnotationFn, Args);
3728
+ AnnotationCall = Builder.CreateCall (AnnotationFn, Args);
3795
3729
}
3730
+ if (AnnotationCall && !AnnotationCall->getType ()->isVoidTy ())
3731
+ ValueMap[BV] = AnnotationCall;
3796
3732
} else if (auto *GV = dyn_cast<GlobalVariable>(V)) {
3797
3733
std::vector<SmallString<256 >> AnnotStrVec;
3798
3734
generateIntelFPGAAnnotation (BV, AnnotStrVec);
0 commit comments