[llvm] [TableGen] Add mapping from processor ID to resource index for packetizer (PR #158182)

via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 15 19:05:19 PDT 2025


================
@@ -0,0 +1,40 @@
+// RUN: llvm-tblgen -gen-dfa-packetizer -I %p/../../include %s | FileCheck %s
+
+include "llvm/Target/Target.td"
+
+def TestTarget : Target;
+
+def TestSchedModel : SchedMachineModel {
+  let CompleteModel = 0;
+}
+
+def TestProcessor1 : ProcessorModel<"testprocessor1", TestSchedModel, []>;
+
+def FU0 : FuncUnit;
+def FU1 : FuncUnit;
+
+def OP0 : InstrItinClass;
+def OP1 : InstrItinClass;
+
+def Itin {
+  list<InstrItinData> ItinList = [
+    InstrItinData<OP0, [InstrStage<1, [FU0]>]>,
+    InstrItinData<OP1, [InstrStage<1, [FU1]>]>,
+  ];
+}
+
+// CHECK:      int TestTargetGetResourceIndex(unsigned ProcID) {
+// CHECK-NEXT:   static const unsigned TestTargetProcIdToProcResourceIdxTable[][2] = {
----------------
LuoYuanke wrote:

I got compiling error with below code. I'd like keep this code in this patch and revise it when there is a better way to call lower_bound() for `unsigned arr[][]`.
```
#include <algorithm>
#include <utility>
#include <vector>
#include <stdio.h>
#include <assert.h>

int TestTargetGetResourceIndex(unsigned ProcID) {
  static const unsigned TestTargetProcIdToProcResourceIdxTable[][2] = {
    { 2,  1 },
    { 4,  2 },
    { 8,  3 },
    { 9,  4 },
  };
  auto It = std::lower_bound(
      std::begin(TestTargetProcIdToProcResourceIdxTable),
      std::end(TestTargetProcIdToProcResourceIdxTable), ProcID);

  // auto It = std::lower_bound(
  //     std::begin(TestTargetProcIdToProcResourceIdxTable),
  //     std::end(TestTargetProcIdToProcResourceIdxTable), ProcID,
  //     [](const unsigned LHS[], unsigned Val) { return LHS[0] < Val; });
  assert(*It[0] == ProcID);
  return (*It)[1];
}

int main() {
  printf("2 : %d\n", TestTargetGetResourceIndex(2));
  printf("9 : %d\n", TestTargetGetResourceIndex(9));
}
```

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


More information about the llvm-commits mailing list