[llvm] [TableGen] Handle pointer types based on the hardware mode in tablegen (PR #67049)

Nitin John Raj via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 11:47:08 PDT 2023


https://github.com/nitinjohnraj created https://github.com/llvm/llvm-project/pull/67049

The `PtrValueType` class allows us to match pointers in tablegen; however, it doesn't allow us to change the underlying size of the pointer types based on the hardware mode. This patch adds support for choosing the size of the pointer type based on the hardware mode.

Authored by: Craig Topper

>From e99b423011c9a06e09176827e4aa49e34f9d2d96 Mon Sep 17 00:00:00 2001
From: Nitin John Raj <nitin.raj at sifive.com>
Date: Thu, 21 Sep 2023 08:30:57 -0700
Subject: [PATCH] [TableGen] Handle pointer types based on the hardware mode in
 tablegen

---
 llvm/include/llvm/Target/Target.td   | 5 +++++
 llvm/utils/TableGen/InfoByHwMode.cpp | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/llvm/include/llvm/Target/Target.td b/llvm/include/llvm/Target/Target.td
index 94a57e5c0f6cffa..e4678d777f1359a 100644
--- a/llvm/include/llvm/Target/Target.td
+++ b/llvm/include/llvm/Target/Target.td
@@ -58,6 +58,11 @@ class ValueTypeByHwMode<list<HwMode> Ms, list<ValueType> Ts>
   list<ValueType> Objects = Ts;
 }
 
+class PtrValueTypeByHwMode<ValueTypeByHwMode scalar, int addrspace>
+    : HwModeSelect<scalar.Modes>, PtrValueType<ValueType<0, 0>, addrspace> {
+  list<ValueType> Objects = scalar.Objects;
+}
+
 // A class representing the register size, spill size and spill alignment
 // in bits of a register.
 class RegInfo<int RS, int SS, int SA> {
diff --git a/llvm/utils/TableGen/InfoByHwMode.cpp b/llvm/utils/TableGen/InfoByHwMode.cpp
index 4e9136e936af72f..7e4ab5346621879 100644
--- a/llvm/utils/TableGen/InfoByHwMode.cpp
+++ b/llvm/utils/TableGen/InfoByHwMode.cpp
@@ -35,6 +35,8 @@ ValueTypeByHwMode::ValueTypeByHwMode(Record *R, const CodeGenHwModes &CGH) {
     assert(I.second && "Duplicate entry?");
     (void)I;
   }
+  if (R->isSubClassOf("PtrValueType"))
+    PtrAddrSpace = R->getValueAsInt("AddrSpace");
 }
 
 ValueTypeByHwMode::ValueTypeByHwMode(Record *R, MVT T) : ValueTypeByHwMode(T) {



More information about the llvm-commits mailing list