Skip to content

Commit 97fa195

Browse files
committed
[TableGen][CodeGen] Remove feature string from HwMode
1 parent ee5bc57 commit 97fa195

File tree

12 files changed

+103
-40
lines changed

12 files changed

+103
-40
lines changed

llvm/include/llvm/Target/Target.td

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,28 @@ class Predicate; // Forward def
2020
// Register file description - These classes are used to fill in the target
2121
// description classes.
2222

23-
class HwMode<string FS, list<Predicate> Ps> {
24-
// A string representing subtarget features that turn on this HW mode.
25-
// For example, "+feat1,-feat2" will indicate that the mode is active
26-
// when "feat1" is enabled and "feat2" is disabled at the same time.
27-
// Any other features are not checked.
28-
// When multiple modes are used, they should be mutually exclusive,
29-
// otherwise the results are unpredictable.
30-
string Features = FS;
23+
// Code that will be inserted at the start of the generated
24+
// `*GenSubtargetInfo::getHwModeSet()` method. It is expected to define
25+
// variables used in Predicate::CondString. If this class is never instantiated,
26+
// the default
27+
//
28+
// [[maybe_unused]] const auto *Subtarget =
29+
// static_cast<const <TargetName>Subtarget *>(this);
30+
//
31+
// will be inserted, where <TargetName> is the name of the Target record.
32+
class HwModePredicateProlog<code c> {
33+
code Code = c;
34+
}
3135

36+
class HwMode<list<Predicate> Ps> {
3237
// A list of predicates that turn on this HW mode.
3338
list<Predicate> Predicates = Ps;
3439
}
3540

3641
// A special mode recognized by tablegen. This mode is considered active
3742
// when no other mode is active. For targets that do not use specific hw
3843
// modes, this is the only mode.
39-
def DefaultMode : HwMode<"", []>;
44+
def DefaultMode : HwMode<[]>;
4045

4146
// A class used to associate objects with HW modes. It is only intended to
4247
// be used as a base class, where the derived class should contain a member

llvm/lib/Target/AArch64/AArch64RegisterInfo.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ class ZPRRegOp <string Suffix, AsmOperandClass C, ElementSizeEnum Size,
983983

984984
// Note: This hardware mode is enabled in AArch64Subtarget::getHwModeSet()
985985
// (without the use of the table-gen'd predicates).
986-
def SMEWithZPRPredicateSpills : HwMode<"", [Predicate<"false">]>;
986+
def SMEWithZPRPredicateSpills : HwMode<[Predicate<"false">]>;
987987

988988
def PPRSpillFillRI : RegInfoByHwMode<
989989
[DefaultMode, SMEWithZPRPredicateSpills],

llvm/lib/Target/Hexagon/Hexagon.td

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ def UseSmallData : Predicate<"HST->useSmallData()">;
176176
def UseCabac : Predicate<"HST->useCabac()">,
177177
AssemblerPredicate<(any_of FeatureCabac)>;
178178

179-
def Hvx64: HwMode<"+hvx-length64b", [UseHVX64B]>;
180-
def Hvx128: HwMode<"+hvx-length128b", [UseHVX128B]>;
179+
def : HwModePredicateProlog<[{
180+
const auto *HST = static_cast<const HexagonSubtarget *>(this);
181+
}]>;
182+
def Hvx64: HwMode<[UseHVX64B]>;
183+
def Hvx128: HwMode<[UseHVX128B]>;
181184

182185
//===----------------------------------------------------------------------===//
183186
// Classes used for relation maps.

llvm/lib/Target/LoongArch/LoongArch.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def IsLA32
3939
"LA32 Basic Integer and Privilege Instruction Set">;
4040

4141
defvar LA32 = DefaultMode;
42-
def LA64 : HwMode<"+64bit", [IsLA64]>;
42+
def LA64 : HwMode<[IsLA64]>;
4343

4444
// Single Precision floating point
4545
def FeatureBasicF

llvm/lib/Target/RISCV/RISCVFeatures.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ def IsRV32 : Predicate<"!Subtarget->is64Bit()">,
16821682
"RV32I Base Instruction Set">;
16831683

16841684
defvar RV32 = DefaultMode;
1685-
def RV64 : HwMode<"+64bit", [IsRV64]>;
1685+
def RV64 : HwMode<[IsRV64]>;
16861686

16871687
def FeatureRelax
16881688
: SubtargetFeature<"relax", "EnableLinkerRelax", "true",

llvm/lib/Target/SystemZ/SystemZFeatures.td

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def FeatureVector : SystemZFeature<
196196
>;
197197
def FeatureNoVector : SystemZMissingFeature<"Vector">;
198198

199-
def NoVecHwMode : HwMode<"-vector", [FeatureNoVector]>;
199+
def NoVecHwMode : HwMode<[FeatureNoVector]>;
200200

201201
def Arch11NewFeatures : SystemZFeatureList<[
202202
FeatureLoadAndZeroRightmostByte,
@@ -426,4 +426,3 @@ def Arch9UnsupportedFeatures
426426
: SystemZFeatureAdd<Arch10UnsupportedFeatures.List, Arch10NewFeatures.List>;
427427
def Arch8UnsupportedFeatures
428428
: SystemZFeatureAdd<Arch9UnsupportedFeatures.List, Arch9NewFeatures.List>;
429-

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "CodeGenDAGPatterns.h"
1515
#include "CodeGenInstruction.h"
1616
#include "CodeGenRegisters.h"
17+
#include "SubtargetFeatureInfo.h"
1718
#include "llvm/ADT/DenseSet.h"
1819
#include "llvm/ADT/MapVector.h"
1920
#include "llvm/ADT/STLExtras.h"
@@ -4498,13 +4499,17 @@ void CodeGenDAGPatterns::ExpandHwModeBasedTypes() {
44984499

44994500
// Fill the map entry for this mode.
45004501
const HwMode &HM = CGH.getMode(M);
4501-
AppendPattern(P, M, HM.Predicates);
4502+
4503+
SmallString<128> PredicateCheck;
4504+
raw_svector_ostream PS(PredicateCheck);
4505+
SubtargetFeatureInfo::emitPredicateCheck(PS, HM.Predicates);
4506+
AppendPattern(P, M, PredicateCheck);
45024507

45034508
// Add negations of the HM's predicates to the default predicate.
45044509
if (!DefaultCheck.empty())
45054510
DefaultCheck += " && ";
45064511
DefaultCheck += "!(";
4507-
DefaultCheck += HM.Predicates;
4512+
DefaultCheck.append(PredicateCheck);
45084513
DefaultCheck += ")";
45094514
}
45104515

llvm/utils/TableGen/Common/CodeGenHwModes.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,17 @@ StringRef CodeGenHwModes::DefaultModeName = "DefaultMode";
2020

2121
HwMode::HwMode(const Record *R) {
2222
Name = R->getName();
23-
Features = R->getValueAsString("Features").str();
24-
25-
SmallString<128> PredicateCheck;
26-
raw_svector_ostream OS(PredicateCheck);
27-
ListSeparator LS(" && ");
28-
for (const Record *Pred : R->getValueAsListOfDefs("Predicates")) {
29-
StringRef CondString = Pred->getValueAsString("CondString");
30-
if (CondString.empty())
31-
continue;
32-
OS << LS << '(' << CondString << ')';
33-
}
34-
35-
Predicates = std::string(PredicateCheck);
23+
Predicates = R->getValueAsListOfDefs("Predicates");
3624
}
3725

3826
LLVM_DUMP_METHOD
39-
void HwMode::dump() const { dbgs() << Name << ": " << Features << '\n'; }
27+
void HwMode::dump() const {
28+
dbgs() << Name << ": ";
29+
ListSeparator LS;
30+
for (const Record *R : Predicates)
31+
dbgs() << LS << R->getName();
32+
dbgs() << '\n';
33+
}
4034

4135
HwModeSelect::HwModeSelect(const Record *R, CodeGenHwModes &CGH) {
4236
std::vector<const Record *> Modes = R->getValueAsListOfDefs("Modes");

llvm/utils/TableGen/Common/CodeGenHwModes.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ struct CodeGenHwModes;
3030
struct HwMode {
3131
HwMode(const Record *R);
3232
StringRef Name;
33-
std::string Features;
34-
std::string Predicates;
33+
std::vector<const Record *> Predicates;
3534
void dump() const;
3635
};
3736

llvm/utils/TableGen/Common/SubtargetFeatureInfo.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,38 @@ static bool emitFeaturesAux(StringRef TargetName, const Init &Val,
163163
return true;
164164
}
165165

166+
void SubtargetFeatureInfo::emitPredicateCheck(
167+
raw_ostream &OS, ArrayRef<const Record *> Predicates) {
168+
ListSeparator LS(" && ");
169+
for (const Record *R : Predicates) {
170+
StringRef CondString = R->getValueAsString("CondString");
171+
if (CondString.empty())
172+
continue;
173+
OS << LS << '(' << CondString << ')';
174+
}
175+
}
176+
177+
void SubtargetFeatureInfo::emitMCPredicateCheck(
178+
raw_ostream &OS, StringRef TargetName,
179+
ArrayRef<const Record *> Predicates) {
180+
auto MCPredicates = make_filter_range(Predicates, [](const Record *R) {
181+
return R->getValueAsBit("AssemblerMatcherPredicate");
182+
});
183+
184+
if (MCPredicates.empty()) {
185+
OS << "false";
186+
return;
187+
}
188+
189+
ListSeparator LS(" && ");
190+
bool ParenIfBinOp = range_size(MCPredicates) > 1;
191+
for (const Record *R : MCPredicates) {
192+
OS << LS;
193+
emitFeaturesAux(TargetName, *R->getValueAsDag("AssemblerCondDag"),
194+
ParenIfBinOp, OS);
195+
}
196+
}
197+
166198
void SubtargetFeatureInfo::emitComputeAssemblerAvailableFeatures(
167199
StringRef TargetName, StringRef ClassName, StringRef FuncName,
168200
SubtargetFeatureInfoMap &SubtargetFeatures, raw_ostream &OS) {

0 commit comments

Comments
 (0)