@@ -755,8 +755,8 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
755755
756756 SPIRVType *TranslatedTy = nullptr ;
757757 if (BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers) &&
758- !(ET->isTypeArray () || ET->isTypeVector () || ET->isTypeImage () ||
759- ET->isTypeSampler () || ET->isTypePipe ())) {
758+ !(ET->isTypeArray () || ET->isTypeVector () || ET->isTypeStruct () ||
759+ ET->isTypeImage () || ET-> isTypeSampler () || ET->isTypePipe ())) {
760760 TranslatedTy = BM->addUntypedPointerKHRType (
761761 SPIRSPIRVAddrSpaceMap::map (static_cast <SPIRAddressSpace>(AddrSpc)));
762762 } else {
@@ -1317,7 +1317,8 @@ SPIRVValue *LLVMToSPIRVBase::transConstantUse(Constant *C,
13171317 if (Trans->getType () == ExpectedType || Trans->getType ()->isTypePipeStorage ())
13181318 return Trans;
13191319
1320- assert (C->getType ()->isPointerTy () &&
1320+ assert ((C->getType ()->isPointerTy () ||
1321+ ExpectedType->isTypeUntypedPointerKHR ()) &&
13211322 " Only pointer type mismatches should be possible" );
13221323 // In the common case of strings ([N x i8] GVs), see if we can emit a GEP
13231324 // instruction.
@@ -2055,8 +2056,12 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
20552056 }
20562057 }
20572058 }
2058- SPIRVType *TransTy = transType (Ty);
2059- BVarInit = transConstantUse (Init, TransTy->getPointerElementType ());
2059+ if (BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers)) {
2060+ BVarInit = transConstantUse (Init, transType (Init->getType ()));
2061+ } else {
2062+ SPIRVType *TransTy = transType (Ty);
2063+ BVarInit = transConstantUse (Init, TransTy->getPointerElementType ());
2064+ }
20602065 }
20612066
20622067 SPIRVStorageClassKind StorageClass;
@@ -2089,9 +2094,12 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
20892094 }
20902095
20912096 SPIRVType *TranslatedTy = transType (Ty);
2092- auto *BVar = static_cast <SPIRVVariable *>(
2093- BM->addVariable (TranslatedTy, GV->isConstant (), transLinkageType (GV),
2094- BVarInit, GV->getName ().str (), StorageClass, nullptr ));
2097+ auto *BVar = static_cast <SPIRVVariableBase *>(BM->addVariable (
2098+ TranslatedTy,
2099+ TranslatedTy->isTypeUntypedPointerKHR () ? transType (GV->getValueType ())
2100+ : nullptr ,
2101+ GV->isConstant (), transLinkageType (GV), BVarInit, GV->getName ().str (),
2102+ StorageClass, nullptr ));
20952103
20962104 if (IsVectorCompute) {
20972105 BVar->addDecorate (DecorationVectorComputeVariableINTEL);
@@ -2280,8 +2288,9 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22802288 StorageClassFunction,
22812289 BM->addArrayType (transType (Alc->getAllocatedType ()), Length));
22822290 SPIRVValue *Arr = BM->addVariable (
2283- AllocationType, false , spv::internal::LinkageTypeInternal, nullptr ,
2284- Alc->getName ().str () + " _alloca" , StorageClassFunction, BB);
2291+ AllocationType, nullptr , false , spv::internal::LinkageTypeInternal,
2292+ nullptr , Alc->getName ().str () + " _alloca" , StorageClassFunction,
2293+ BB);
22852294 // Manually set alignment. OpBitcast created below will be decorated as
22862295 // that's the SPIR-V value mapped to the original LLVM one.
22872296 transAlign (Alc, Arr);
@@ -2305,7 +2314,10 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
23052314 TranslatedTy->getPointerElementType ())
23062315 : TranslatedTy;
23072316 SPIRVValue *Var = BM->addVariable (
2308- VarTy, false , spv::internal::LinkageTypeInternal, nullptr ,
2317+ VarTy,
2318+ VarTy->isTypeUntypedPointerKHR () ? transType (Alc->getAllocatedType ())
2319+ : nullptr ,
2320+ false , spv::internal::LinkageTypeInternal, nullptr ,
23092321 Alc->getName ().str (), StorageClassFunction, BB);
23102322 if (V->getType ()->getPointerAddressSpace () == SPIRAS_Generic) {
23112323 SPIRVValue *Cast =
@@ -2750,7 +2762,7 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) {
27502762 E->getErrorLog ().checkError (E->isVariable (), SPIRVEC_InvalidModule, ErrStr);
27512763
27522764 auto AddrSpace = SPIRSPIRVAddrSpaceMap::rmap (
2753- static_cast <SPIRVVariable *>(E)->getStorageClass ());
2765+ static_cast <SPIRVVariableBase *>(E)->getStorageClass ());
27542766 ErrStr += " in a global (module) scope" ;
27552767 E->getErrorLog ().checkError (AddrSpace == SPIRAS_Global, SPIRVEC_InvalidModule,
27562768 ErrStr);
@@ -2898,10 +2910,11 @@ static void transMetadataDecorations(Metadata *MD, SPIRVValue *Target) {
28982910 case spv::internal::DecorationInitModeINTEL:
28992911 case DecorationInitModeINTEL: {
29002912 checkIsGlobalVar (Target, DecoKind);
2901- ErrLog.checkError (static_cast <SPIRVVariable *>(Target)->getInitializer (),
2902- SPIRVEC_InvalidLlvmModule,
2903- " InitModeINTEL only be applied to a global (module "
2904- " scope) variable which has an Initializer operand" );
2913+ ErrLog.checkError (
2914+ static_cast <SPIRVVariableBase *>(Target)->getInitializer (),
2915+ SPIRVEC_InvalidLlvmModule,
2916+ " InitModeINTEL only be applied to a global (module "
2917+ " scope) variable which has an Initializer operand" );
29052918
29062919 ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule,
29072920 " InitModeINTEL requires exactly 1 extra operand" );
@@ -4143,14 +4156,18 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
41434156 SPIRVType *FTy = transType (II->getType ()->getStructElementType (0 ));
41444157 SPIRVTypePointer *ITy = static_cast <SPIRVTypePointer *>(transPointerType (
41454158 II->getType ()->getStructElementType (1 ), SPIRAS_Private));
4146-
4147- unsigned BitWidth = ITy->getElementType ()->getBitWidth ();
4148- BM->getErrorLog ().checkError (BitWidth == 32 , SPIRVEC_InvalidBitWidth,
4149- std::to_string (BitWidth));
4150-
4159+ if (!ITy-> isTypeUntypedPointerKHR ()) {
4160+ unsigned BitWidth = ITy->getElementType ()->getBitWidth ();
4161+ BM->getErrorLog ().checkError (BitWidth == 32 , SPIRVEC_InvalidBitWidth,
4162+ std::to_string (BitWidth));
4163+ }
41514164 SPIRVValue *IntVal =
4152- BM->addVariable (ITy, false , spv::internal::LinkageTypeInternal, nullptr ,
4153- " " , ITy->getStorageClass (), BB);
4165+ BM->addVariable (ITy,
4166+ ITy->isTypeUntypedPointerKHR ()
4167+ ? transType (II->getType ()->getStructElementType (1 ))
4168+ : nullptr ,
4169+ false , spv::internal::LinkageTypeInternal, nullptr , " " ,
4170+ ITy->getStorageClass (), BB);
41544171
41554172 std::vector<SPIRVValue *> Ops{transValue (II->getArgOperand (0 ), BB), IntVal};
41564173
@@ -4572,7 +4589,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
45724589 Init = BM->addCompositeConstant (CompositeTy, Elts);
45734590 }
45744591 SPIRVType *VarTy = transPointerType (AT, SPIRV::SPIRAS_Constant);
4575- SPIRVValue *Var = BM->addVariable (VarTy, /* isConstant*/ true ,
4592+ SPIRVValue *Var = BM->addVariable (VarTy, nullptr , /* isConstant*/ true ,
45764593 spv::internal::LinkageTypeInternal, Init,
45774594 " " , StorageClassUniformConstant, nullptr );
45784595 SPIRVType *SourceTy =
0 commit comments