@@ -417,8 +417,8 @@ SPIRVType *LLVMToSPIRVBase::transType(Type *T) {
417417  //  A pointer to image or pipe type in LLVM is translated to a SPIRV
418418  //  (non-pointer) image or pipe type.
419419  if  (T->isPointerTy ()) {
420-     auto  AddrSpc = T->getPointerAddressSpace ();
421420    auto  *ET = Type::getInt8Ty (T->getContext ());
421+     auto  AddrSpc = T->getPointerAddressSpace ();
422422    return  transPointerType (ET, AddrSpc);
423423  }
424424
@@ -720,6 +720,7 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(Type *ET, unsigned AddrSpc) {
720720          transType (ET)));
721721    }
722722  } else  {
723+     SPIRVType *ElementType = transType (ET);
723724    //  ET, as a recursive type, may contain exactly the same pointer T, so it
724725    //  may happen that after translation of ET we already have translated T,
725726    //  added the translated pointer to the SPIR-V module and mapped T to this
@@ -728,17 +729,7 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(Type *ET, unsigned AddrSpc) {
728729    if  (Loc != PointeeTypeMap.end ()) {
729730      return  Loc->second ;
730731    }
731- 
732-     SPIRVType *ElementType = nullptr ;
733-     SPIRVType *TranslatedTy = nullptr ;
734-     if  (ET->isPointerTy () &&
735-         BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers)) {
736-       TranslatedTy = BM->addUntypedPointerKHRType (
737-           SPIRSPIRVAddrSpaceMap::map (static_cast <SPIRAddressSpace>(AddrSpc)));
738-     } else  {
739-       ElementType = transType (ET);
740-       TranslatedTy = transPointerType (ElementType, AddrSpc);
741-     }
732+     SPIRVType *TranslatedTy = transPointerType (ElementType, AddrSpc);
742733    PointeeTypeMap[TypeKey] = TranslatedTy;
743734    return  TranslatedTy;
744735  }
@@ -753,16 +744,8 @@ SPIRVType *LLVMToSPIRVBase::transPointerType(SPIRVType *ET, unsigned AddrSpc) {
753744  if  (Loc != PointeeTypeMap.end ())
754745    return  Loc->second ;
755746
756-   SPIRVType *TranslatedTy = nullptr ;
757-   if  (BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers) &&
758-       !(ET->isTypeArray () || ET->isTypeVector () || ET->isTypeImage () ||
759-         ET->isTypeSampler () || ET->isTypePipe ())) {
760-     TranslatedTy = BM->addUntypedPointerKHRType (
761-         SPIRSPIRVAddrSpaceMap::map (static_cast <SPIRAddressSpace>(AddrSpc)));
762-   } else  {
763-     TranslatedTy = BM->addPointerType (
764-         SPIRSPIRVAddrSpaceMap::map (static_cast <SPIRAddressSpace>(AddrSpc)), ET);
765-   }
747+   SPIRVType *TranslatedTy = BM->addPointerType (
748+       SPIRSPIRVAddrSpaceMap::map (static_cast <SPIRAddressSpace>(AddrSpc)), ET);
766749  PointeeTypeMap[TypeKey] = TranslatedTy;
767750  return  TranslatedTy;
768751}
@@ -2213,13 +2196,8 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
22132196                             MemoryAccessNoAliasINTELMaskMask);
22142197    if  (MemoryAccess.front () == 0 )
22152198      MemoryAccess.clear ();
2216-     return  mapValue (
2217-         V,
2218-         BM->addLoadInst (
2219-             transValue (LD->getPointerOperand (), BB), MemoryAccess, BB,
2220-             BM->isAllowedToUseExtension (ExtensionID::SPV_KHR_untyped_pointers)
2221-                 ? transType (LD->getType ())
2222-                 : nullptr ));
2199+     return  mapValue (V, BM->addLoadInst (transValue (LD->getPointerOperand (), BB),
2200+                                        MemoryAccess, BB));
22232201  }
22242202
22252203  if  (BinaryOperator *B = dyn_cast<BinaryOperator>(V)) {
@@ -2429,17 +2407,14 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
24292407
24302408  if  (auto  *Phi = dyn_cast<PHINode>(V)) {
24312409    std::vector<SPIRVValue *> IncomingPairs;
2432-     SPIRVType *Ty = transScavengedType (Phi);
24332410
24342411    for  (size_t  I = 0 , E = Phi->getNumIncomingValues (); I != E; ++I) {
2435-       SPIRVValue *Val = transValue (Phi->getIncomingValue (I), BB, true ,
2436-                                    FuncTransMode::Pointer);
2437-       if  (Val->getType () != Ty)
2438-         Val = BM->addUnaryInst (OpBitcast, Ty, Val, BB);
2439-       IncomingPairs.push_back (Val);
2412+       IncomingPairs.push_back (transValue (Phi->getIncomingValue (I), BB, true ,
2413+                                          FuncTransMode::Pointer));
24402414      IncomingPairs.push_back (transValue (Phi->getIncomingBlock (I), nullptr ));
24412415    }
2442-     return  mapValue (V, BM->addPhiInst (Ty, IncomingPairs, BB));
2416+     return  mapValue (V,
2417+                     BM->addPhiInst (transScavengedType (Phi), IncomingPairs, BB));
24432418  }
24442419
24452420  if  (auto  *Ext = dyn_cast<ExtractValueInst>(V)) {
@@ -6696,12 +6671,9 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
66966671          assert ((Pointee == Args[I] || !isa<Function>(Pointee)) &&
66976672                 " Illegal use of a function pointer type"  );
66986673        }
6699-         if  (!SPI->isOperandLiteral (I)) {
6700-           SPIRVValue *Val = transValue (Args[I], BB);
6701-           SPArgs.push_back (Val->getId ());
6702-         } else  {
6703-           SPArgs.push_back (cast<ConstantInt>(Args[I])->getZExtValue ());
6704-         }
6674+         SPArgs.push_back (SPI->isOperandLiteral (I)
6675+                              ? cast<ConstantInt>(Args[I])->getZExtValue ()
6676+                              : transValue (Args[I], BB)->getId ());
67056677      }
67066678      BM->addInstTemplate (SPI, SPArgs, BB, SPRetTy);
67076679      if  (!SPRetTy || !SPRetTy->isTypeStruct ())
0 commit comments