Skip to content

Commit 91b9add

Browse files
code format
1 parent fb8928d commit 91b9add

File tree

2 files changed

+49
-47
lines changed

2 files changed

+49
-47
lines changed

llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ void SPIRVAsmPrinter::outputOpFunctionEnd() {
150150
// Emit OpFunctionEnd at the end of MF and clear BBNumToRegMap.
151151
void SPIRVAsmPrinter::emitFunctionBodyEnd() {
152152
// Do not emit anything if it's an internal service function.
153-
if (MF->getFunction().getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME).isValid())
153+
if (MF->getFunction()
154+
.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
155+
.isValid())
154156
return;
155157

156158
outputOpFunctionEnd();

llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,6 +1673,52 @@ void SPIRVEmitIntrinsics::processParamTypes(Function *F, IRBuilder<> &B) {
16731673
}
16741674
}
16751675

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+
16761722
bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
16771723
if (Func.isDeclaration())
16781724
return false;
@@ -1832,52 +1878,6 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
18321878
return Changed;
18331879
}
18341880

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-
18811881
ModulePass *llvm::createSPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM) {
18821882
return new SPIRVEmitIntrinsics(TM);
18831883
}

0 commit comments

Comments
 (0)