@@ -615,7 +615,6 @@ void prepareCacheControlsTranslation(Metadata *MD, Instruction *Inst) {
615615// / Remove entities not representable by SPIR-V
616616bool SPIRVRegularizeLLVMBase::regularize () {
617617 eraseUselessFunctions (M);
618- addKernelEntryPoint (M);
619618 expandSYCLTypeUsing (M);
620619 cleanupConversionToNonStdIntegers (M);
621620 replacePrivateConstGlobalsWithAllocas (M);
@@ -808,69 +807,6 @@ bool SPIRVRegularizeLLVMBase::regularize() {
808807 return true ;
809808}
810809
811- void SPIRVRegularizeLLVMBase::addKernelEntryPoint (Module *M) {
812- std::vector<Function *> Work;
813-
814- // Get a list of all functions that have SPIR kernel calling conv
815- for (auto &F : *M) {
816- if (F.getCallingConv () == CallingConv::SPIR_KERNEL)
817- Work.push_back (&F);
818- }
819- for (auto &F : Work) {
820- // for declarations just make them into SPIR functions.
821- F->setCallingConv (CallingConv::SPIR_FUNC);
822- if (F->isDeclaration ())
823- continue ;
824-
825- // Otherwise add a wrapper around the function to act as an entry point.
826- FunctionType *FType = F->getFunctionType ();
827- std::string WrapName =
828- kSPIRVName ::EntrypointPrefix + static_cast <std::string>(F->getName ());
829- Function *WrapFn =
830- getOrCreateFunction (M, F->getReturnType (), FType->params (), WrapName);
831-
832- auto *CallBB = BasicBlock::Create (M->getContext (), " " , WrapFn);
833- IRBuilder<> Builder (CallBB);
834-
835- Function::arg_iterator DestI = WrapFn->arg_begin ();
836- for (const Argument &I : F->args ()) {
837- DestI->setName (I.getName ());
838- DestI++;
839- }
840- SmallVector<Value *, 1 > Args;
841- for (Argument &I : WrapFn->args ()) {
842- Args.emplace_back (&I);
843- }
844- auto *CI = CallInst::Create (F, ArrayRef<Value *>(Args), " " , CallBB);
845- CI->setCallingConv (F->getCallingConv ());
846- CI->setAttributes (F->getAttributes ());
847-
848- // copy over all the metadata (should it be removed from F?)
849- SmallVector<std::pair<unsigned , MDNode *>> MDs;
850- F->getAllMetadata (MDs);
851- WrapFn->setAttributes (F->getAttributes ());
852- for (auto MD = MDs.begin (), End = MDs.end (); MD != End; ++MD) {
853- WrapFn->addMetadata (MD->first , *MD->second );
854- }
855- WrapFn->setCallingConv (CallingConv::SPIR_KERNEL);
856- WrapFn->setLinkage (llvm::GlobalValue::InternalLinkage);
857-
858- Builder.CreateRet (F->getReturnType ()->isVoidTy () ? nullptr : CI);
859-
860- // Have to find the spir-v metadata for execution mode and transfer it to
861- // the wrapper.
862- if (auto NMD = SPIRVMDWalker (*M).getNamedMD (kSPIRVMD ::ExecutionMode)) {
863- while (!NMD.atEnd ()) {
864- Function *MDF = nullptr ;
865- auto N = NMD.nextOp (); /* execution mode MDNode */
866- N.get (MDF);
867- if (MDF == F)
868- N.M ->replaceOperandWith (0 , ValueAsMetadata::get (WrapFn));
869- }
870- }
871- }
872- }
873-
874810} // namespace SPIRV
875811
876812INITIALIZE_PASS (SPIRVRegularizeLLVMLegacy, " spvregular" ,
0 commit comments