@@ -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 {
@@ -1329,7 +1329,8 @@ SPIRVValue *LLVMToSPIRVBase::transConstantUse(Constant *C,
13291329 if (Trans->getType () == ExpectedType || Trans->getType ()->isTypePipeStorage ())
13301330 return Trans;
13311331
1332- assert (C->getType ()->isPointerTy () &&
1332+ assert ((C->getType ()->isPointerTy () ||
1333+ ExpectedType->isTypeUntypedPointerKHR ()) &&
13331334 " Only pointer type mismatches should be possible" );
13341335 // In the common case of strings ([N x i8] GVs), see if we can emit a GEP
13351336 // instruction.
@@ -2067,8 +2068,12 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
20672068 }
20682069 }
20692070 }
2070- SPIRVType *TransTy = transType (Ty);
2071- BVarInit = transConstantUse (Init, TransTy->getPointerElementType ());
2071+ if (BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers)) {
2072+ BVarInit = transConstantUse (Init, transType (Init->getType ()));
2073+ } else {
2074+ SPIRVType *TransTy = transType (Ty);
2075+ BVarInit = transConstantUse (Init, TransTy->getPointerElementType ());
2076+ }
20722077 }
20732078
20742079 SPIRVStorageClassKind StorageClass;
@@ -2101,9 +2106,12 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
21012106 }
21022107
21032108 SPIRVType *TranslatedTy = transType (Ty);
2104- auto *BVar = static_cast <SPIRVVariable *>(
2105- BM->addVariable (TranslatedTy, GV->isConstant (), transLinkageType (GV),
2106- BVarInit, GV->getName ().str (), StorageClass, nullptr ));
2109+ auto *BVar = static_cast <SPIRVVariableBase *>(BM->addVariable (
2110+ TranslatedTy,
2111+ TranslatedTy->isTypeUntypedPointerKHR () ? transType (GV->getValueType ())
2112+ : nullptr ,
2113+ GV->isConstant (), transLinkageType (GV), BVarInit, GV->getName ().str (),
2114+ StorageClass, nullptr ));
21072115
21082116 if (IsVectorCompute) {
21092117 BVar->addDecorate (DecorationVectorComputeVariableINTEL);
@@ -2292,8 +2300,9 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22922300 StorageClassFunction,
22932301 BM->addArrayType (transType (Alc->getAllocatedType ()), Length));
22942302 SPIRVValue *Arr = BM->addVariable (
2295- AllocationType, false , spv::internal::LinkageTypeInternal, nullptr ,
2296- Alc->getName ().str () + " _alloca" , StorageClassFunction, BB);
2303+ AllocationType, nullptr , false , spv::internal::LinkageTypeInternal,
2304+ nullptr , Alc->getName ().str () + " _alloca" , StorageClassFunction,
2305+ BB);
22972306 // Manually set alignment. OpBitcast created below will be decorated as
22982307 // that's the SPIR-V value mapped to the original LLVM one.
22992308 transAlign (Alc, Arr);
@@ -2317,7 +2326,10 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
23172326 TranslatedTy->getPointerElementType ())
23182327 : TranslatedTy;
23192328 SPIRVValue *Var = BM->addVariable (
2320- VarTy, false , spv::internal::LinkageTypeInternal, nullptr ,
2329+ VarTy,
2330+ VarTy->isTypeUntypedPointerKHR () ? transType (Alc->getAllocatedType ())
2331+ : nullptr ,
2332+ false , spv::internal::LinkageTypeInternal, nullptr ,
23212333 Alc->getName ().str (), StorageClassFunction, BB);
23222334 if (V->getType ()->getPointerAddressSpace () == SPIRAS_Generic) {
23232335 SPIRVValue *Cast =
@@ -2762,7 +2774,7 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) {
27622774 E->getErrorLog ().checkError (E->isVariable (), SPIRVEC_InvalidModule, ErrStr);
27632775
27642776 auto AddrSpace = SPIRSPIRVAddrSpaceMap::rmap (
2765- static_cast <SPIRVVariable *>(E)->getStorageClass ());
2777+ static_cast <SPIRVVariableBase *>(E)->getStorageClass ());
27662778 ErrStr += " in a global (module) scope" ;
27672779 E->getErrorLog ().checkError (AddrSpace == SPIRAS_Global, SPIRVEC_InvalidModule,
27682780 ErrStr);
@@ -2910,10 +2922,11 @@ static void transMetadataDecorations(Metadata *MD, SPIRVValue *Target) {
29102922 case spv::internal::DecorationInitModeINTEL:
29112923 case DecorationInitModeINTEL: {
29122924 checkIsGlobalVar (Target, DecoKind);
2913- ErrLog.checkError (static_cast <SPIRVVariable *>(Target)->getInitializer (),
2914- SPIRVEC_InvalidLlvmModule,
2915- " InitModeINTEL only be applied to a global (module "
2916- " scope) variable which has an Initializer operand" );
2925+ ErrLog.checkError (
2926+ static_cast <SPIRVVariableBase *>(Target)->getInitializer (),
2927+ SPIRVEC_InvalidLlvmModule,
2928+ " InitModeINTEL only be applied to a global (module "
2929+ " scope) variable which has an Initializer operand" );
29172930
29182931 ErrLog.checkError (NumOperands == 2 , SPIRVEC_InvalidLlvmModule,
29192932 " InitModeINTEL requires exactly 1 extra operand" );
@@ -4155,14 +4168,18 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
41554168 SPIRVType *FTy = transType (II->getType ()->getStructElementType (0 ));
41564169 SPIRVTypePointer *ITy = static_cast <SPIRVTypePointer *>(transPointerType (
41574170 II->getType ()->getStructElementType (1 ), SPIRAS_Private));
4158-
4159- unsigned BitWidth = ITy->getElementType ()->getBitWidth ();
4160- BM->getErrorLog ().checkError (BitWidth == 32 , SPIRVEC_InvalidBitWidth,
4161- std::to_string (BitWidth));
4162-
4171+ if (!ITy-> isTypeUntypedPointerKHR ()) {
4172+ unsigned BitWidth = ITy->getElementType ()->getBitWidth ();
4173+ BM->getErrorLog ().checkError (BitWidth == 32 , SPIRVEC_InvalidBitWidth,
4174+ std::to_string (BitWidth));
4175+ }
41634176 SPIRVValue *IntVal =
4164- BM->addVariable (ITy, false , spv::internal::LinkageTypeInternal, nullptr ,
4165- " " , ITy->getStorageClass (), BB);
4177+ BM->addVariable (ITy,
4178+ ITy->isTypeUntypedPointerKHR ()
4179+ ? transType (II->getType ()->getStructElementType (1 ))
4180+ : nullptr ,
4181+ false , spv::internal::LinkageTypeInternal, nullptr , " " ,
4182+ ITy->getStorageClass (), BB);
41664183
41674184 std::vector<SPIRVValue *> Ops{transValue (II->getArgOperand (0 ), BB), IntVal};
41684185
@@ -4584,7 +4601,7 @@ SPIRVValue *LLVMToSPIRVBase::transIntrinsicInst(IntrinsicInst *II,
45844601 Init = BM->addCompositeConstant (CompositeTy, Elts);
45854602 }
45864603 SPIRVType *VarTy = transPointerType (AT, SPIRV::SPIRAS_Constant);
4587- SPIRVValue *Var = BM->addVariable (VarTy, /* isConstant*/ true ,
4604+ SPIRVValue *Var = BM->addVariable (VarTy, nullptr , /* isConstant*/ true ,
45884605 spv::internal::LinkageTypeInternal, Init,
45894606 " " , StorageClassUniformConstant, nullptr );
45904607 SPIRVType *SourceTy =
0 commit comments