Skip to content

Commit

Permalink
code format
Browse files Browse the repository at this point in the history
  • Loading branch information
VyacheslavLevytskyy committed Oct 11, 2024
1 parent fb8928d commit 91b9add
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 47 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ void SPIRVAsmPrinter::outputOpFunctionEnd() {
// Emit OpFunctionEnd at the end of MF and clear BBNumToRegMap.
void SPIRVAsmPrinter::emitFunctionBodyEnd() {
// Do not emit anything if it's an internal service function.
if (MF->getFunction().getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME).isValid())
if (MF->getFunction()
.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
.isValid())
return;

outputOpFunctionEnd();
Expand Down
92 changes: 46 additions & 46 deletions llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,52 @@ void SPIRVEmitIntrinsics::processParamTypes(Function *F, IRBuilder<> &B) {
}
}

bool SPIRVEmitIntrinsics::processFunctionPointers(Module &M) {
bool IsExt = false;
SmallVector<Function *> Worklist;
for (auto &F : M) {
if (!IsExt) {
if (!TM->getSubtarget<SPIRVSubtarget>(F).canUseExtension(
SPIRV::Extension::SPV_INTEL_function_pointers))
return false;
IsExt = true;
}
if (!F.isDeclaration() || F.isIntrinsic())
continue;
for (User *U : F.users()) {
CallInst *CI = dyn_cast<CallInst>(U);
if (!CI || CI->getCalledFunction() != &F) {
Worklist.push_back(&F);
break;
}
}
}
if (Worklist.empty())
return false;

std::string ServiceFunName = SPIRV_BACKEND_SERVICE_FUN_NAME;
if (!getVacantFunctionName(M, ServiceFunName))
report_fatal_error(
"cannot allocate a name for the internal service function");
LLVMContext &Ctx = M.getContext();
Function *SF =
Function::Create(FunctionType::get(Type::getVoidTy(Ctx), {}, false),
GlobalValue::PrivateLinkage, ServiceFunName, M);
SF->addFnAttr(SPIRV_BACKEND_SERVICE_FUN_NAME, "");
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", SF);
IRBuilder<> IRB(BB);

for (Function *F : Worklist) {
SmallVector<Value *> Args;
for (const auto &Arg : F->args())
Args.push_back(PoisonValue::get(Arg.getType()));
IRB.CreateCall(F, Args);
}
IRB.CreateRetVoid();

return true;
}

bool SPIRVEmitIntrinsics::runOnFunction(Function &Func) {
if (Func.isDeclaration())
return false;
Expand Down Expand Up @@ -1832,52 +1878,6 @@ bool SPIRVEmitIntrinsics::runOnModule(Module &M) {
return Changed;
}

bool SPIRVEmitIntrinsics::processFunctionPointers(Module &M) {
bool IsExt = false;
SmallVector<Function*> Worklist;
for (auto &F : M) {
if (!IsExt) {
if (!TM->getSubtarget<SPIRVSubtarget>(F).canUseExtension(
SPIRV::Extension::SPV_INTEL_function_pointers))
return false;
IsExt = true;
}
if (!F.isDeclaration() || F.isIntrinsic())
continue;
for (User *U : F.users()) {
CallInst *CI = dyn_cast<CallInst>(U);
if (!CI || CI->getCalledFunction() != &F) {
Worklist.push_back(&F);
break;
}
}
}
if (Worklist.empty())
return false;

std::string ServiceFunName = SPIRV_BACKEND_SERVICE_FUN_NAME;
if (!getVacantFunctionName(M, ServiceFunName))
report_fatal_error(
"cannot allocate a name for the internal service function");
LLVMContext &Ctx = M.getContext();
Function *SF =
Function::Create(FunctionType::get(Type::getVoidTy(Ctx), {}, false),
GlobalValue::PrivateLinkage, ServiceFunName, M);
SF->addFnAttr(SPIRV_BACKEND_SERVICE_FUN_NAME, "");
BasicBlock *BB = BasicBlock::Create(Ctx, "entry", SF);
IRBuilder<> IRB(BB);

for (Function *F : Worklist) {
SmallVector<Value *> Args;
for (const auto &Arg : F->args())
Args.push_back(PoisonValue::get(Arg.getType()));
IRB.CreateCall(F, Args);
}
IRB.CreateRetVoid();

return true;
}

ModulePass *llvm::createSPIRVEmitIntrinsicsPass(SPIRVTargetMachine *TM) {
return new SPIRVEmitIntrinsics(TM);
}

0 comments on commit 91b9add

Please sign in to comment.