[llvm] [LLVM][Intrinsics] Refactor IIT encoding generation (PR #189790)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 1 05:44:22 PDT 2026


================
@@ -243,52 +243,40 @@ def ArgKind {
   int MatchType  = 7;
 }
 
-// Encode placeholder.
-// [15:8] is the ID used how to resolve ArgCode.
-
-// (ACIdx << 3) | ArgCode
-class EncAnyType<int ArgCode=0> {
+// Placeholder to encode the overload index of the current type. We encode bit
+// 8 = 1 to indicate that this entry needs to be patched up with the overload
+// index (to prevent conflict with any valid not-to-be-patched IIT enccoding
+// byte, whose value will be <= 255). The ArgKind itself is in the lower bits.
+// Note that this is just a transient representation till its gets processed
+// by `DoPatchOverloadIndex` below, so this is *not* the encoding of the
+// final type signature.
+class PatchOverloadIndex<int ArgKindVal> {
   int ID = 0x100;
-  int ret = !or(ID, ArgCode);
-}
-
-// (Num << 3) | AK.MatchType
-class EncMatchType<int Num=0> {
-  int ID = 0x200;
-  int ret = !or(ID, Num);
-}
-
-// (Num << 3) | ArgCodes[Num]
-class EncSameWidth<int Num=0> {
-  int ID = 0x300;
-  int ret = !or(ID, Num);
+  int ret = !or(ID, ArgKindVal);
 }
 
-// ACIdx
-class EncNextArgA<int dummy=0> {
-  int ID = 0x400;
-  int ret = !or(ID, dummy);
+// This class defines how the overload index and the arg kind are actually
+// packed into a single byte for the final IIT table encoding. Overload index is
+// packed in low 5 bits, argument kind is packed in upper 3 bits. This enables
+// us to use the same packing for llvm_any* types, which use a argument kind
+// and for partially dependent types like `LLVMVectorOfAnyPointersToElt` which
+// do not use the argument kind and expect the overload index in the lower bits.
+class PackOverloadIndex<int OverloadIndex, int ArgKindVal> {
+  assert !lt(OverloadIndex, 32), "Cannot support more than 32 overload types";
+  assert !lt(ArgKindVal, 8), "Cannot support more than 8 argument kinds";
+  int ret = !or(!shl(ArgKindVal, 5), OverloadIndex);
 }
 
-// Num
-class EncNextArgN<int Num=0> {
-  int ID = 0x500;
-  int ret = !or(ID, Num);
-}
-
-class ResolveArgCode<
-    list<int> ArgCodes,
-    int ACIdx,
-    int ax> {
-  int ah = !and(ax, 0xFF00);
-  int al = !and(ax, 0x00FF);
+// This class handles the actual patching of the overload index into a component
+// value in the type signature. If its > 255, its a value generated by
----------------
jurahul wrote:

Done.

https://github.com/llvm/llvm-project/pull/189790


More information about the llvm-commits mailing list