[clang] [llvm] [LLVM] Extend `getIntrinsicInfoTableEntries` to return number of args (PR #196563)

2026-05-09 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul updated 
https://github.com/llvm/llvm-project/pull/196563

>From 0c97380df99647df1956ace8ae5dffdf3e8e43b5 Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Fri, 8 May 2026 08:58:06 -0700
Subject: [PATCH] [LLVM][Intrinsics] Extend `getIntrinsicInfoTableEntries` to
 return num args

---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 12 +---
 llvm/include/llvm/IR/Intrinsics.h   | 15 +++--
 llvm/lib/IR/Intrinsics.cpp  | 79 -
 3 files changed, 52 insertions(+), 54 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index fe932834e9b55..868bca404949b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -955,21 +955,13 @@ static cir::FuncType getIntrinsicType(CIRGenFunction &cgf,
   using namespace llvm::Intrinsic;
 
   SmallVector table;
-  getIntrinsicInfoTableEntries(id, table);
+  auto [tableRef, _, isVarArg] = getIntrinsicInfoTableEntries(id, table);
 
-  ArrayRef tableRef = table;
   mlir::Type resultTy = decodeFixedType(cgf, tableRef, context);
 
   SmallVector argTypes;
-  bool isVarArg = false;
-  while (!tableRef.empty()) {
-IITDescriptor::IITDescriptorKind kind = tableRef.front().Kind;
-if (kind == IITDescriptor::VarArg) {
-  isVarArg = true;
-  break; // VarArg is last
-}
+  while (!tableRef.empty())
 argTypes.push_back(decodeFixedType(cgf, tableRef, context));
-  }
 
   // CIR convention: no explicit void return type
   if (isa(resultTy))
diff --git a/llvm/include/llvm/IR/Intrinsics.h 
b/llvm/include/llvm/IR/Intrinsics.h
index ae931c7961161..af97285fcee70 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -20,6 +20,7 @@
 #include "llvm/Support/TypeSize.h"
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -259,10 +260,16 @@ struct IITDescriptor {
 /// Returns true if \p id has a struct return type.
 LLVM_ABI bool hasStructReturnType(ID id);
 
-/// Return the IIT table descriptor for the specified intrinsic into an array
-/// of IITDescriptors.
-LLVM_ABI void getIntrinsicInfoTableEntries(ID id,
-   SmallVectorImpl &T);
+/// Fill the IIT table descriptor for the intrinsic \p id into an array
+/// of IITDescriptors. Returns a tuple of 3 values:
+///  - ArrayRef for the descriptor table (for convenience).
+///  - Number of arguments.
+///  - if it's a variable argument intrinsic.
+///
+/// Note that for VarArg intrinsics, the last IIT `VarArg` token will be
+/// consumed and not a part of the returned ArrayRef.
+LLVM_ABI std::tuple, unsigned, bool>
+getIntrinsicInfoTableEntries(ID id, SmallVectorImpl &T);
 
 /// Returns true if \p FT is a valid function type for intrinsic \p ID. If
 /// `ID` is an overloaded intrinsic, the overload types are pushed into the
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index ff57d335c9a13..72fbfabd48987 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -38,10 +38,9 @@
 using namespace llvm;
 
 // Forward declaration of static functions.
-static bool isIntrinsicVarArg(ArrayRef &Infos,
-  bool Consume);
 static bool isSignatureValid(FunctionType *FTy,
  ArrayRef &Infos,
+ bool IsVarArg, unsigned NumArgs,
  SmallVectorImpl &OverloadTys,
  raw_ostream &OS);
 
@@ -398,6 +397,7 @@ DecodeIITType(unsigned &NextElt, ArrayRef 
Infos,
 unsigned OverloadIndex = Infos[NextElt++];
 OutputTable.push_back(
 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
+DecodeIITType(NextElt, Infos, OutputTable);
 return;
   }
   case IIT_VEC_OF_ANYPTRS_TO_ELT: {
@@ -451,8 +451,9 @@ DecodeIITType(unsigned &NextElt, ArrayRef 
Infos,
 #define GET_INTRINSIC_GENERATOR_GLOBAL
 #include "llvm/IR/IntrinsicImpl.inc"
 
-void Intrinsic::getIntrinsicInfoTableEntries(
-ID id, SmallVectorImpl &T) {
+std::tuple, unsigned, bool>
+Intrinsic::getIntrinsicInfoTableEntries(ID id,
+SmallVectorImpl &T) {
   // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc and can be
   // uint16_t or uint32_t based on the the value of `Use16BitFixedEncoding` in
   // IntrinsicEmitter.cpp.
@@ -497,8 +498,21 @@ void Intrinsic::getIntrinsicInfoTableEntries(
 
   // Okay, decode the table into the output vector of IITDescriptors.
   DecodeIITType(NextElt, IITEntries, T);
-  while (IITEntries[NextElt] != IIT_Done)
+  unsigned NumArgs = 0;
+  while (IITEntries[NextElt] != IIT_Done) {
 DecodeIITType(NextElt, IITEntries, T);
+++NumArgs;
+  }
+
+  ArrayRef TableRef = T;
+
+  bool IsVarArg = false;
+  if (TableRef.back().Kind == Intrinsic::IITDescriptor::VarArg) {
+IsVarArg = true;
+TableRef.consume_back();
+--NumArgs;
+  }
+  return {TableRef, NumArgs, IsVarArg};
 }
 
 

[clang] [llvm] [LLVM] Extend `getIntrinsicInfoTableEntries` to return number of args (PR #196563)

2026-05-09 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul edited 
https://github.com/llvm/llvm-project/pull/196563
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [LLVM] Extend `getIntrinsicInfoTableEntries` to return number of args (PR #196563)

2026-05-09 Thread via cfe-commits

github-actions[bot] wrote:


# :penguin: Linux x64 Test Results

* 175469 tests passed
* 2598 tests skipped
* 6 tests failed

## Failed Tests
(click on a test name to see its output)

### Clang

Clang.CIR/CodeGen/delete-array-throwing-dtor.cpp

```
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 1
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++20 -fcxx-exceptions 
-fexceptions -fclangir -emit-cir -mmlir 
-mlir-print-ir-after=cir-cxxabi-lowering -mmlir 
-mlir-print-ir-before=cir-cxxabi-lowering -mmlir 
-mlir-print-ir-after=cir-cxxabi-lowering 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp
 -o 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp.cir
 2> 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp-cxxabi.cir
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/clang -cc1 
-internal-isystem 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/lib/clang/23/include
 -nostdsysteminc -triple x86_64-unknown-linux-gnu -std=c++20 -fcxx-exceptions 
-fexceptions -fclangir -emit-cir -mmlir 
-mlir-print-ir-after=cir-cxxabi-lowering -mmlir 
-mlir-print-ir-before=cir-cxxabi-lowering -mmlir 
-mlir-print-ir-after=cir-cxxabi-lowering 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp
 -o 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp.cir
# note: command had no output on stdout or stderr
# RUN: at line 2
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck 
--input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp-cxxabi.cir
 --check-prefix=CIR-BEFORE-CXXABI 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp
# executed command: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/bin/FileCheck 
--input-file=/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp-cxxabi.cir
 --check-prefix=CIR-BEFORE-CXXABI 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp
# .---command stderr
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp:19:23:
 error: CIR-BEFORE-CXXABI: expected string not found in input
# | // CIR-BEFORE-CXXABI: IR Dump Before CXXABILowering (cir-cxxabi-lowering)
# |   ^
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp-cxxabi.cir:1:1:
 note: scanning from here
# | // -// IR Dump Before CXXABILowering: cir-cxxabi-lowering //- //
# | ^
# | 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp-cxxabi.cir:1:12:
 note: possible intended match here
# | // -// IR Dump Before CXXABILowering: cir-cxxabi-lowering //- //
# |^
# | 
# | Input file: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/build/tools/clang/test/CIR/CodeGen/Output/delete-array-throwing-dtor.cpp.tmp-cxxabi.cir
# | Check file: 
/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp
# | 
# | -dump-input=help explains the following input dump.
# | 
# | Input was:
# | <<
# | 1: // -// IR Dump Before CXXABILowering: 
cir-cxxabi-lowering //- // 
# | check:19'0 
X 
error: no match found
# | check:19'1? 
 possible intended match
# | 2: !s32i = !cir.int 
# | check:19'0 
# | 3: !u64i = !cir.int 
# | check:19'0 
# | 4: !void = !cir.void 
# | check:19'0 ~~
# | 5: !rec_ThrowingDtor = !cir.record 
# | check:19'0 
~~~
# | 6: module 
@"/home/gha/actions-runner/_work/llvm-project/llvm-project/clang/test/CIR/CodeGen/delete-array-throwing-dtor.cpp"
 attributes {cir.lang = #cir.lang, cir.module_asm = [], cir.record_layouts 
= {ThrowingDtor = #cir.record_layout}, cir.triple = 
"x86_64-unknown-linux-gnu", dlti.dl_spe

[clang] [llvm] [LLVM] Extend `getIntrinsicInfoTableEntries` to return number of args (PR #196563)

2026-05-09 Thread Rahul Joshi via cfe-commits

https://github.com/jurahul created 
https://github.com/llvm/llvm-project/pull/196563

None

>From 9913cb86bd86b31c9f8f6bee5b0631d3b8a2fa6b Mon Sep 17 00:00:00 2001
From: Rahul Joshi 
Date: Fri, 8 May 2026 08:58:06 -0700
Subject: [PATCH] [LLVM][Intrinsics] Extend `getIntrinsicInfoTableEntries` to
 return num args

---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 12 +
 llvm/include/llvm/IR/Intrinsics.h   | 15 --
 llvm/lib/IR/Intrinsics.cpp  | 71 -
 3 files changed, 48 insertions(+), 50 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index fe932834e9b55..868bca404949b 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -955,21 +955,13 @@ static cir::FuncType getIntrinsicType(CIRGenFunction &cgf,
   using namespace llvm::Intrinsic;
 
   SmallVector table;
-  getIntrinsicInfoTableEntries(id, table);
+  auto [tableRef, _, isVarArg] = getIntrinsicInfoTableEntries(id, table);
 
-  ArrayRef tableRef = table;
   mlir::Type resultTy = decodeFixedType(cgf, tableRef, context);
 
   SmallVector argTypes;
-  bool isVarArg = false;
-  while (!tableRef.empty()) {
-IITDescriptor::IITDescriptorKind kind = tableRef.front().Kind;
-if (kind == IITDescriptor::VarArg) {
-  isVarArg = true;
-  break; // VarArg is last
-}
+  while (!tableRef.empty())
 argTypes.push_back(decodeFixedType(cgf, tableRef, context));
-  }
 
   // CIR convention: no explicit void return type
   if (isa(resultTy))
diff --git a/llvm/include/llvm/IR/Intrinsics.h 
b/llvm/include/llvm/IR/Intrinsics.h
index ae931c7961161..af97285fcee70 100644
--- a/llvm/include/llvm/IR/Intrinsics.h
+++ b/llvm/include/llvm/IR/Intrinsics.h
@@ -20,6 +20,7 @@
 #include "llvm/Support/TypeSize.h"
 #include 
 #include 
+#include 
 
 namespace llvm {
 
@@ -259,10 +260,16 @@ struct IITDescriptor {
 /// Returns true if \p id has a struct return type.
 LLVM_ABI bool hasStructReturnType(ID id);
 
-/// Return the IIT table descriptor for the specified intrinsic into an array
-/// of IITDescriptors.
-LLVM_ABI void getIntrinsicInfoTableEntries(ID id,
-   SmallVectorImpl &T);
+/// Fill the IIT table descriptor for the intrinsic \p id into an array
+/// of IITDescriptors. Returns a tuple of 3 values:
+///  - ArrayRef for the descriptor table (for convenience).
+///  - Number of arguments.
+///  - if it's a variable argument intrinsic.
+///
+/// Note that for VarArg intrinsics, the last IIT `VarArg` token will be
+/// consumed and not a part of the returned ArrayRef.
+LLVM_ABI std::tuple, unsigned, bool>
+getIntrinsicInfoTableEntries(ID id, SmallVectorImpl &T);
 
 /// Returns true if \p FT is a valid function type for intrinsic \p ID. If
 /// `ID` is an overloaded intrinsic, the overload types are pushed into the
diff --git a/llvm/lib/IR/Intrinsics.cpp b/llvm/lib/IR/Intrinsics.cpp
index ff57d335c9a13..1b0e464c52545 100644
--- a/llvm/lib/IR/Intrinsics.cpp
+++ b/llvm/lib/IR/Intrinsics.cpp
@@ -38,10 +38,9 @@
 using namespace llvm;
 
 // Forward declaration of static functions.
-static bool isIntrinsicVarArg(ArrayRef &Infos,
-  bool Consume);
 static bool isSignatureValid(FunctionType *FTy,
  ArrayRef &Infos,
+ bool IsVarArg, unsigned NumArgs,
  SmallVectorImpl &OverloadTys,
  raw_ostream &OS);
 
@@ -398,6 +397,7 @@ DecodeIITType(unsigned &NextElt, ArrayRef 
Infos,
 unsigned OverloadIndex = Infos[NextElt++];
 OutputTable.push_back(
 IITDescriptor::get(IITDescriptor::SameVecWidth, OverloadIndex));
+DecodeIITType(NextElt, Infos, OutputTable);
 return;
   }
   case IIT_VEC_OF_ANYPTRS_TO_ELT: {
@@ -451,8 +451,9 @@ DecodeIITType(unsigned &NextElt, ArrayRef 
Infos,
 #define GET_INTRINSIC_GENERATOR_GLOBAL
 #include "llvm/IR/IntrinsicImpl.inc"
 
-void Intrinsic::getIntrinsicInfoTableEntries(
-ID id, SmallVectorImpl &T) {
+std::tuple, unsigned, bool>
+Intrinsic::getIntrinsicInfoTableEntries(ID id,
+SmallVectorImpl &T) {
   // Note that `FixedEncodingTy` is defined in IntrinsicImpl.inc and can be
   // uint16_t or uint32_t based on the the value of `Use16BitFixedEncoding` in
   // IntrinsicEmitter.cpp.
@@ -497,8 +498,21 @@ void Intrinsic::getIntrinsicInfoTableEntries(
 
   // Okay, decode the table into the output vector of IITDescriptors.
   DecodeIITType(NextElt, IITEntries, T);
-  while (IITEntries[NextElt] != IIT_Done)
+  unsigned NumArgs = 0;
+  while (IITEntries[NextElt] != IIT_Done) {
 DecodeIITType(NextElt, IITEntries, T);
+++NumArgs;
+  }
+
+  ArrayRef TableRef = T;
+
+  bool IsVarArg = false;
+  if (TableRef.back().Kind == Intrinsic::IITDescriptor::VarArg) {
+IsVarArg = true;
+TableRef.consume_back();
+--NumArgs;
+  }
+  return {TableRef, NumArgs, IsVarArg}