[clang] [CodeGen] Don't use CreateRuntimeFunction() for intrinsics (PR #224329)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 17 07:54:52 PDT 2026
https://github.com/nikic created https://github.com/llvm/llvm-project/pull/224329
These should just use getIntrinsic().
>From d143bb8966239ecbf6a8d00512192d0d85e9878f Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 17 Sep 2026 16:39:12 +0200
Subject: [PATCH 1/2] [CodeGen] Don't use CreateRuntimeFunction for intrinsics
These should just use getIntrinsic().
---
clang/lib/CodeGen/CGCleanup.cpp | 16 ++++------------
clang/lib/CodeGen/CGException.cpp | 12 ++++--------
2 files changed, 8 insertions(+), 20 deletions(-)
diff --git a/clang/lib/CodeGen/CGCleanup.cpp b/clang/lib/CodeGen/CGCleanup.cpp
index 977f81a641ff3e..41a812ff59691e 100644
--- a/clang/lib/CodeGen/CGCleanup.cpp
+++ b/clang/lib/CodeGen/CGCleanup.cpp
@@ -1348,10 +1348,8 @@ static void EmitSehScope(CodeGenFunction &CGF,
// Invoke a llvm.seh.scope.begin at the beginning of a CPP scope for -EHa
void CodeGenFunction::EmitSehCppScopeBegin() {
assert(getLangOpts().EHAsynch);
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
llvm::FunctionCallee SehCppScope =
- CGM.CreateRuntimeFunction(FTy, "llvm.seh.scope.begin");
+ CGM.getIntrinsic(llvm::Intrinsic::seh_scope_begin);
EmitSehScope(*this, SehCppScope);
}
@@ -1359,29 +1357,23 @@ void CodeGenFunction::EmitSehCppScopeBegin() {
// llvm.seh.scope.end is emitted before popCleanup, so it's "invoked"
void CodeGenFunction::EmitSehCppScopeEnd() {
assert(getLangOpts().EHAsynch);
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
llvm::FunctionCallee SehCppScope =
- CGM.CreateRuntimeFunction(FTy, "llvm.seh.scope.end");
+ CGM.getIntrinsic(llvm::Intrinsic::seh_scope_end);
EmitSehScope(*this, SehCppScope);
}
// Invoke a llvm.seh.try.begin at the beginning of a SEH scope for -EHa
void CodeGenFunction::EmitSehTryScopeBegin() {
assert(getLangOpts().EHAsynch);
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
llvm::FunctionCallee SehCppScope =
- CGM.CreateRuntimeFunction(FTy, "llvm.seh.try.begin");
+ CGM.getIntrinsic(llvm::Intrinsic::seh_try_begin);
EmitSehScope(*this, SehCppScope);
}
// Invoke a llvm.seh.try.end at the end of a SEH scope for -EHa
void CodeGenFunction::EmitSehTryScopeEnd() {
assert(getLangOpts().EHAsynch);
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
llvm::FunctionCallee SehCppScope =
- CGM.CreateRuntimeFunction(FTy, "llvm.seh.try.end");
+ CGM.getIntrinsic(llvm::Intrinsic::seh_try_end);
EmitSehScope(*this, SehCppScope);
}
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 2785c224cf4034..40f7476638c887 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -40,15 +40,11 @@ static llvm::FunctionCallee getFreeExceptionFn(CodeGenModule &CGM) {
}
static llvm::FunctionCallee getSehTryBeginFn(CodeGenModule &CGM) {
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
- return CGM.CreateRuntimeFunction(FTy, "llvm.seh.try.begin");
+ return CGM.getIntrinsic(llvm::Intrinsic::seh_try_begin);
}
static llvm::FunctionCallee getSehTryEndFn(CodeGenModule &CGM) {
- llvm::FunctionType *FTy =
- llvm::FunctionType::get(CGM.VoidTy, /*isVarArg=*/false);
- return CGM.CreateRuntimeFunction(FTy, "llvm.seh.try.end");
+ return CGM.getIntrinsic(llvm::Intrinsic::seh_try_end);
}
static llvm::FunctionCallee getUnexpectedFn(CodeGenModule &CGM) {
@@ -1683,7 +1679,7 @@ void CodeGenFunction::EmitSEHTryStmt(const SEHTryStmt &S) {
llvm::BasicBlock *TryBB = nullptr;
// IsEHa: emit an invoke to _seh_try_begin() runtime for -EHa
if (getLangOpts().EHAsynch) {
- EmitRuntimeCallOrInvoke(getSehTryBeginFn(CGM));
+ EmitCallOrInvoke(getSehTryBeginFn(CGM), {});
if (SEHTryEpilogueStack.size() == 1) // outermost only
TryBB = Builder.GetInsertBlock();
}
@@ -2251,7 +2247,7 @@ void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) {
// IsEHa: emit an invoke _seh_try_end() to mark end of FT flow
if (getLangOpts().EHAsynch && Builder.GetInsertBlock()) {
llvm::FunctionCallee SehTryEnd = getSehTryEndFn(CGM);
- EmitRuntimeCallOrInvoke(SehTryEnd);
+ EmitCallOrInvoke(SehTryEnd, {});
}
// Otherwise, we must have an __except block.
>From 4ed37858ed7f851a0f061d0f6956d699bd718e7d Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Thu, 17 Sep 2026 16:42:04 +0200
Subject: [PATCH 2/2] inline trivial functions
---
clang/lib/CodeGen/CGException.cpp | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 40f7476638c887..f06edde9739b4a 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -39,14 +39,6 @@ static llvm::FunctionCallee getFreeExceptionFn(CodeGenModule &CGM) {
return CGM.CreateRuntimeFunction(FTy, "__cxa_free_exception");
}
-static llvm::FunctionCallee getSehTryBeginFn(CodeGenModule &CGM) {
- return CGM.getIntrinsic(llvm::Intrinsic::seh_try_begin);
-}
-
-static llvm::FunctionCallee getSehTryEndFn(CodeGenModule &CGM) {
- return CGM.getIntrinsic(llvm::Intrinsic::seh_try_end);
-}
-
static llvm::FunctionCallee getUnexpectedFn(CodeGenModule &CGM) {
// void __cxa_call_unexpected(void *thrown_exception);
@@ -1679,7 +1671,7 @@ void CodeGenFunction::EmitSEHTryStmt(const SEHTryStmt &S) {
llvm::BasicBlock *TryBB = nullptr;
// IsEHa: emit an invoke to _seh_try_begin() runtime for -EHa
if (getLangOpts().EHAsynch) {
- EmitCallOrInvoke(getSehTryBeginFn(CGM), {});
+ EmitCallOrInvoke(CGM.getIntrinsic(llvm::Intrinsic::seh_try_begin), {});
if (SEHTryEpilogueStack.size() == 1) // outermost only
TryBB = Builder.GetInsertBlock();
}
@@ -2246,8 +2238,7 @@ void CodeGenFunction::ExitSEHTryStmt(const SEHTryStmt &S) {
// IsEHa: emit an invoke _seh_try_end() to mark end of FT flow
if (getLangOpts().EHAsynch && Builder.GetInsertBlock()) {
- llvm::FunctionCallee SehTryEnd = getSehTryEndFn(CGM);
- EmitCallOrInvoke(SehTryEnd, {});
+ EmitCallOrInvoke(CGM.getIntrinsic(llvm::Intrinsic::seh_try_end), {});
}
// Otherwise, we must have an __except block.
More information about the cfe-commits
mailing list