[llvm] [LLVM] Change Intrinsic::ID to encode target and intrinsic index (PR #113576)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 13:40:15 PDT 2024


================
@@ -155,13 +158,13 @@ void IntrinsicEmitter::EmitEnumInfo(const CodeGenIntrinsicTable &Ints,
 
   OS << "// Enum values for intrinsics.\n";
   bool First = true;
-  for (const auto &Int : Ints[*Set]) {
+  for (const auto &Int : Set->getIntrinsics()) {
     OS << "    " << Int.EnumName;
 
     // Assign a value to the first intrinsic in this target set so that all
     // intrinsic ids are distinct.
     if (First) {
-      OS << " = " << Set->Offset + 1;
+      Intrinsic::PrintIntrinsicIDEncoding(OS, Set->TargetIndex, 0);
----------------
jurahul wrote:

The 9 here will be stable independent on which targets are enabled or not. It's basically the index among all possible target prefixes defined in a particular LLVM build. That means that if someone added a new target prefix for say a new target, then its index would be susceptible to change.

I propose the following: get this working first, so the IDs are more stable than before and for the same LLVM build, they will stay the same irrespective of which targets are enabled. As a follow on, we add a new record to the Intrinsics.td file that assigns stable target ID to each target. The record can either be in Intrinsidc.td or in the individual per-backend TD files. Something like:

```
class TargetPrefixIndex<string Name, int Index> {
...
}

and then Intrinsics.td can have a table of these:

```
def x86_target_index : TargetPrefixIndex<"x86", 0>;
def r600_target_index : TargetPrefixIndex<"r600", 8>;
```
and then the IntrinsicEmitter will use that as opposed to the index computed by sorting the present target prefixes.
Let me know if that works, or you prefer doing that change in the current PR directly.

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


More information about the llvm-commits mailing list