@@ -1673,6 +1673,52 @@ void SPIRVEmitIntrinsics::processParamTypes(Function *F, IRBuilder<> &B) {
1673
1673
}
1674
1674
}
1675
1675
1676
+ bool SPIRVEmitIntrinsics::processFunctionPointers (Module &M) {
1677
+ bool IsExt = false ;
1678
+ SmallVector<Function *> Worklist;
1679
+ for (auto &F : M) {
1680
+ if (!IsExt) {
1681
+ if (!TM->getSubtarget <SPIRVSubtarget>(F).canUseExtension (
1682
+ SPIRV::Extension::SPV_INTEL_function_pointers))
1683
+ return false ;
1684
+ IsExt = true ;
1685
+ }
1686
+ if (!F.isDeclaration () || F.isIntrinsic ())
1687
+ continue ;
1688
+ for (User *U : F.users ()) {
1689
+ CallInst *CI = dyn_cast<CallInst>(U);
1690
+ if (!CI || CI->getCalledFunction () != &F) {
1691
+ Worklist.push_back (&F);
1692
+ break ;
1693
+ }
1694
+ }
1695
+ }
1696
+ if (Worklist.empty ())
1697
+ return false ;
1698
+
1699
+ std::string ServiceFunName = SPIRV_BACKEND_SERVICE_FUN_NAME;
1700
+ if (!getVacantFunctionName (M, ServiceFunName))
1701
+ report_fatal_error (
1702
+ " cannot allocate a name for the internal service function" );
1703
+ LLVMContext &Ctx = M.getContext ();
1704
+ Function *SF =
1705
+ Function::Create (FunctionType::get (Type::getVoidTy (Ctx), {}, false ),
1706
+ GlobalValue::PrivateLinkage, ServiceFunName, M);
1707
+ SF->addFnAttr (SPIRV_BACKEND_SERVICE_FUN_NAME, " " );
1708
+ BasicBlock *BB = BasicBlock::Create (Ctx, " entry" , SF);
1709
+ IRBuilder<> IRB (BB);
1710
+
1711
+ for (Function *F : Worklist) {
1712
+ SmallVector<Value *> Args;
1713
+ for (const auto &Arg : F->args ())
1714
+ Args.push_back (PoisonValue::get (Arg.getType ()));
1715
+ IRB.CreateCall (F, Args);
1716
+ }
1717
+ IRB.CreateRetVoid ();
1718
+
1719
+ return true ;
1720
+ }
1721
+
1676
1722
bool SPIRVEmitIntrinsics::runOnFunction (Function &Func) {
1677
1723
if (Func.isDeclaration ())
1678
1724
return false ;
@@ -1832,52 +1878,6 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
1832
1878
return Changed;
1833
1879
}
1834
1880
1835
- bool SPIRVEmitIntrinsics::processFunctionPointers (Module &M) {
1836
- bool IsExt = false ;
1837
- SmallVector<Function*> Worklist;
1838
- for (auto &F : M) {
1839
- if (!IsExt) {
1840
- if (!TM->getSubtarget <SPIRVSubtarget>(F).canUseExtension (
1841
- SPIRV::Extension::SPV_INTEL_function_pointers))
1842
- return false ;
1843
- IsExt = true ;
1844
- }
1845
- if (!F.isDeclaration () || F.isIntrinsic ())
1846
- continue ;
1847
- for (User *U : F.users ()) {
1848
- CallInst *CI = dyn_cast<CallInst>(U);
1849
- if (!CI || CI->getCalledFunction () != &F) {
1850
- Worklist.push_back (&F);
1851
- break ;
1852
- }
1853
- }
1854
- }
1855
- if (Worklist.empty ())
1856
- return false ;
1857
-
1858
- std::string ServiceFunName = SPIRV_BACKEND_SERVICE_FUN_NAME;
1859
- if (!getVacantFunctionName (M, ServiceFunName))
1860
- report_fatal_error (
1861
- " cannot allocate a name for the internal service function" );
1862
- LLVMContext &Ctx = M.getContext ();
1863
- Function *SF =
1864
- Function::Create (FunctionType::get (Type::getVoidTy (Ctx), {}, false ),
1865
- GlobalValue::PrivateLinkage, ServiceFunName, M);
1866
- SF->addFnAttr (SPIRV_BACKEND_SERVICE_FUN_NAME, " " );
1867
- BasicBlock *BB = BasicBlock::Create (Ctx, " entry" , SF);
1868
- IRBuilder<> IRB (BB);
1869
-
1870
- for (Function *F : Worklist) {
1871
- SmallVector<Value *> Args;
1872
- for (const auto &Arg : F->args ())
1873
- Args.push_back (PoisonValue::get (Arg.getType ()));
1874
- IRB.CreateCall (F, Args);
1875
- }
1876
- IRB.CreateRetVoid ();
1877
-
1878
- return true ;
1879
- }
1880
-
1881
1881
ModulePass *llvm::createSPIRVEmitIntrinsicsPass (SPIRVTargetMachine *TM) {
1882
1882
return new SPIRVEmitIntrinsics (TM);
1883
1883
}
0 commit comments