[llvm] [TableGen] Add an option to SubtargetFeature to disable setting the field to the maximum value (PR #116594)
Pengcheng Wang via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 01:51:54 PST 2024
https://github.com/wangpc-pp created https://github.com/llvm/llvm-project/pull/116594
None
>From 024d60499bd53960105ffe43576d107a72c0e0ca Mon Sep 17 00:00:00 2001
From: Wang Pengcheng <wangpengcheng.pp at bytedance.com>
Date: Mon, 18 Nov 2024 17:09:14 +0800
Subject: [PATCH] [TableGen] Add an option to SubtargetFeature to disable
setting the field to the maximum value
---
llvm/docs/WritingAnLLVMBackend.rst | 4 +++-
llvm/include/llvm/Target/Target.td | 13 +++++++++----
llvm/utils/TableGen/SubtargetEmitter.cpp | 5 +++--
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/llvm/docs/WritingAnLLVMBackend.rst b/llvm/docs/WritingAnLLVMBackend.rst
index 1b9173b1fe139c..7f0a97ccefed13 100644
--- a/llvm/docs/WritingAnLLVMBackend.rst
+++ b/llvm/docs/WritingAnLLVMBackend.rst
@@ -1772,7 +1772,8 @@ is assumed to be a bool and only one SubtargetFeature should refer to it.
Otherwise, it is assumed to be an integer. The integer value may be the name
of an enum constant. If multiple features use the same integer field, the
field will be set to the maximum value of all enabled features that share
-the field.
+the field if `SetMaxValue` are set to true (by default), or we will set the
+field to the last specified value.
.. code-block:: text
@@ -1783,6 +1784,7 @@ the field.
string Value = v;
string Desc = d;
list<SubtargetFeature> Implies = i;
+ bit SetMaxValue = true;
}
In the ``Sparc.td`` file, the ``SubtargetFeature`` is used to define the
diff --git a/llvm/include/llvm/Target/Target.td b/llvm/include/llvm/Target/Target.td
index 3e037affe1cfd2..460e6a6640d94b 100644
--- a/llvm/include/llvm/Target/Target.td
+++ b/llvm/include/llvm/Target/Target.td
@@ -494,12 +494,17 @@ class SubtargetFeature<string n, string f, string v, string d,
//
// A value of "true" or "false" implies the field is a bool. Otherwise,
// it is assumed to be an integer. the integer value may be the name of an
- // enum constant. If multiple features use the same integer field, the
- // field will be set to the maximum value of all enabled features that
- // share the field.
- //
+ // enum constant.
string Value = v;
+ // SetMaxValue - Should we set the maximum value to the integer field.
+ //
+ // If multiple features use the same integer field, the field will be set to
+ // the maximum value of all enabled features that share the field if `SetMaxValue`
+ // are set to true (by default), or we will set the field to the last specified
+ // value.
+ bit SetMaxValue = true;
+
// Desc - Feature description. Used by command line (-mattr=) to display help
// information.
//
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 02c799cb6f1471..e52d4498824a45 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1902,13 +1902,14 @@ void SubtargetEmitter::parseFeaturesFunction(raw_ostream &OS) {
StringRef Instance = R->getName();
StringRef Value = R->getValueAsString("Value");
StringRef FieldName = R->getValueAsString("FieldName");
+ bool SetMaxValue = R->getValueAsBit("SetMaxValue");
- if (Value == "true" || Value == "false")
+ if (Value == "true" || Value == "false" || !SetMaxValue)
OS << " if (Bits[" << Target << "::" << Instance << "]) " << FieldName
<< " = " << Value << ";\n";
else
OS << " if (Bits[" << Target << "::" << Instance << "] && " << FieldName
- << " < " << Value << ") " << FieldName << " = " << Value << ";\n";
+ << " != " << Value << ") " << FieldName << " = " << Value << ";\n";
}
OS << "}\n";
More information about the llvm-commits
mailing list