@@ -1451,7 +1451,7 @@ SPIRVInstruction *LLVMToSPIRVBase::transCmpInst(CmpInst *Cmp,
1451
1451
1452
1452
SPIRVValue *LLVMToSPIRVBase::transUnaryInst (UnaryInstruction *U,
1453
1453
SPIRVBasicBlock *BB) {
1454
- if (isa<BitCastInst>(U) && U->getType ()->isPointerTy ()) {
1454
+ if (isa<BitCastInst>(U) && U->getType ()->isPtrOrPtrVectorTy ()) {
1455
1455
if (isa<ConstantPointerNull>(U->getOperand (0 ))) {
1456
1456
SPIRVType *ExpectedTy = transScavengedType (U);
1457
1457
return BM->addNullConstant (bcast<SPIRVTypePointer>(ExpectedTy));
@@ -1817,7 +1817,7 @@ SPIRVValue *LLVMToSPIRVBase::transAtomicLoad(LoadInst *LD,
1817
1817
std::vector<SPIRVValue *> SPIRVOps = transValue (Ops, BB);
1818
1818
1819
1819
return mapValue (LD, BM->addInstTemplate (OpAtomicLoad, BM->getIds (SPIRVOps),
1820
- BB, transType (LD-> getType () )));
1820
+ BB, transScavengedType (LD)));
1821
1821
}
1822
1822
1823
1823
// Aliasing list MD contains several scope MD nodes whithin it. Each scope MD
@@ -1896,9 +1896,9 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
1896
1896
// Though variables with common linkage type are initialized by 0,
1897
1897
// they can be represented in SPIR-V as uninitialized variables with
1898
1898
// 'Export' linkage type, just as tentative definitions look in C
1899
- llvm::Value *Init = GV->hasInitializer () && !GV->hasCommonLinkage ()
1900
- ? GV->getInitializer ()
1901
- : nullptr ;
1899
+ llvm::Constant *Init = GV->hasInitializer () && !GV->hasCommonLinkage ()
1900
+ ? GV->getInitializer ()
1901
+ : nullptr ;
1902
1902
SPIRVValue *BVarInit = nullptr ;
1903
1903
StructType *ST = Init ? dyn_cast<StructType>(Init->getType ()) : nullptr ;
1904
1904
if (ST && ST->hasName () && isSPIRVConstantName (ST->getName ())) {
@@ -1945,10 +1945,8 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
1945
1945
}
1946
1946
}
1947
1947
}
1948
- // As global variables define a pointer to their "content" type, we should
1949
- // translate here only pointer without declaration even if it is a
1950
- // function pointer.
1951
- BVarInit = transValue (Init, nullptr , true , FuncTransMode::Pointer);
1948
+ SPIRVType *TransTy = transType (Ty);
1949
+ BVarInit = transConstantUse (Init, TransTy->getPointerElementType ());
1952
1950
}
1953
1951
1954
1952
SPIRVStorageClassKind StorageClass;
@@ -2302,7 +2300,7 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
2302
2300
2303
2301
if (auto Ext = dyn_cast<ExtractValueInst>(V)) {
2304
2302
return mapValue (V, BM->addCompositeExtractInst (
2305
- transType (Ext-> getType () ),
2303
+ transScavengedType (Ext),
2306
2304
transValue (Ext->getAggregateOperand (), BB),
2307
2305
Ext->getIndices (), BB));
2308
2306
}
@@ -2370,7 +2368,7 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
2370
2368
auto Index = Ext->getIndexOperand ();
2371
2369
if (auto Const = dyn_cast<ConstantInt>(Index))
2372
2370
return mapValue (V, BM->addCompositeExtractInst (
2373
- transType (Ext-> getType () ),
2371
+ transScavengedType (Ext),
2374
2372
transValue (Ext->getVectorOperand (), BB),
2375
2373
std::vector<SPIRVWord>(1 , Const->getZExtValue ()),
2376
2374
BB));
@@ -2401,7 +2399,7 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
2401
2399
for (auto &I : SF->getShuffleMask ())
2402
2400
Comp.push_back (I);
2403
2401
return mapValue (V, BM->addVectorShuffleInst (
2404
- transType (SF-> getType () ),
2402
+ transScavengedType (SF),
2405
2403
transValue (SF->getOperand (0 ), BB),
2406
2404
transValue (SF->getOperand (1 ), BB), Comp, BB));
2407
2405
}
@@ -2434,7 +2432,7 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
2434
2432
Operands[3 ] = ARMW->getValOperand ();
2435
2433
std::vector<SPIRVValue *> OpVals = transValue (Operands, BB);
2436
2434
std::vector<SPIRVId> Ops = BM->getIds (OpVals);
2437
- SPIRVType *Ty = transType (ARMW-> getType () );
2435
+ SPIRVType *Ty = transScavengedType (ARMW);
2438
2436
2439
2437
spv::Op OC;
2440
2438
if (Op == AtomicRMWInst::FSub) {
@@ -4082,7 +4080,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
4082
4080
case Intrinsic::dbg_value:
4083
4081
return DbgTran->createDebugValuePlaceholder (cast<DbgValueInst>(II), BB);
4084
4082
case Intrinsic::annotation: {
4085
- SPIRVType *Ty = transType (II-> getType () );
4083
+ SPIRVType *Ty = transScavengedType (II);
4086
4084
4087
4085
GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(II->getArgOperand (1 ));
4088
4086
if (!GEP)
@@ -4149,8 +4147,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
4149
4147
4150
4148
// Translate FPGARegIntel annotations to OpFPGARegINTEL.
4151
4149
if (AnnotationString == kOCLBuiltinName ::FPGARegIntel) {
4152
- // TODO: Check for opaque pointer requirements.
4153
- auto *Ty = transType (II->getType ());
4150
+ auto *Ty = transScavengedType (II);
4154
4151
auto *BI = dyn_cast<BitCastInst>(II->getOperand (0 ));
4155
4152
if (BM->isAllowedToUseExtension (ExtensionID::SPV_INTEL_fpga_reg))
4156
4153
return BM->addFPGARegINTELInst (Ty, transValue (BI, BB), BB);
@@ -4295,7 +4292,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
4295
4292
" -spirv-allow-unknown-intrinsics option." );
4296
4293
return nullptr ;
4297
4294
}
4298
- SPIRVType *Ty = transType (II-> getType () );
4295
+ SPIRVType *Ty = transScavengedType (II);
4299
4296
auto *PtrVector = transValue (II->getArgOperand (0 ), BB);
4300
4297
uint32_t Alignment =
4301
4298
cast<ConstantInt>(II->getArgOperand (1 ))->getZExtValue ();
@@ -5865,7 +5862,7 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
5865
5862
}
5866
5863
default : {
5867
5864
if (isCvtOpCode (OC) && OC != OpGenericCastToPtrExplicit) {
5868
- return BM->addUnaryInst (OC, transType (CI-> getType () ),
5865
+ return BM->addUnaryInst (OC, transScavengedType (CI),
5869
5866
transValue (CI->getArgOperand (0 ), BB), BB);
5870
5867
} else if (isCmpOpCode (OC) || isUnaryPredicateOpCode (OC)) {
5871
5868
auto ResultTy = CI->getType ();
@@ -5895,12 +5892,12 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
5895
5892
return BM->addSelectInst (Res, One, Zero, BB);
5896
5893
} else if (isBinaryOpCode (OC)) {
5897
5894
assert (CI && CI->arg_size () == 2 && " Invalid call inst" );
5898
- return BM->addBinaryInst (OC, transType (CI-> getType () ),
5895
+ return BM->addBinaryInst (OC, transScavengedType (CI),
5899
5896
transValue (CI->getArgOperand (0 ), BB),
5900
5897
transValue (CI->getArgOperand (1 ), BB), BB);
5901
5898
} else if (CI->arg_size () == 1 && !CI->getType ()->isVoidTy () &&
5902
5899
!hasExecScope (OC) && !isAtomicOpCode (OC)) {
5903
- return BM->addUnaryInst (OC, transType (CI-> getType () ),
5900
+ return BM->addUnaryInst (OC, transScavengedType (CI),
5904
5901
transValue (CI->getArgOperand (0 ), BB), BB);
5905
5902
} else {
5906
5903
auto Args = getArguments (CI);
0 commit comments