[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:57:03 PST 2024
https://github.com/wangpc-pp updated https://github.com/llvm/llvm-project/pull/116594
>From dcad454a8695839917e18c0231573f76e08e147c 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 | 3 ++-
3 files changed, 14 insertions(+), 6 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..dcaed6001310a0 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..59c373e9201a00 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -1902,8 +1902,9 @@ 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
More information about the llvm-commits
mailing list