[llvm] [SPIRV] Add support for SPV_KHR_abort extension (PR #193037)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 23 05:12:21 PDT 2026
================
@@ -595,6 +598,62 @@ SPIRVPrepareFunctions::removeAggregateTypesFromSignature(Function *F) {
return NewF;
}
+// Replace OpenCL/SPIR-V style calls to `__spirv_AbortKHR(message)` with calls
+// to the `llvm.spv.abort` target intrinsic, so that they go through the same
+// instruction-selection path as the intrinsic and get lowered to OpAbortKHR.
+bool SPIRVPrepareFunctions::substituteAbortKHRCalls(Function *F) {
+ if (F->isDeclaration())
+ return false;
+
+ SmallVector<CallInst *> Calls;
+ for (Instruction &I : instructions(F)) {
+ auto *CI = dyn_cast<CallInst>(&I);
+ if (!CI)
+ continue;
+ Function *Callee = CI->getCalledFunction();
+ if (!Callee || Callee->isIntrinsic())
+ continue;
+ StringRef Demangled = Callee->getName();
+ std::string DemangledStr = getOclOrSpirvBuiltinDemangledName(Demangled);
+ if (DemangledStr.empty())
+ continue;
+ std::string BuiltinName = SPIRV::lookupBuiltinNameHelper(DemangledStr);
+ if (StringRef(BuiltinName) != "__spirv_AbortKHR")
+ continue;
+ if (CI->arg_size() != 1)
+ continue;
+ Calls.push_back(CI);
+ }
----------------
jmmartinez wrote:
You should do this the other way around, scan the functions in the module looking for `__spirv_AbortKHR`; then do the replacement on its Users.
Otherwise we scan the whole module even if `__spirv_AbortKHR` is not used.
https://github.com/llvm/llvm-project/pull/193037
More information about the llvm-commits
mailing list