Skip to content

Commit 788e768

Browse files
author
Krzysztof Parzyszek
committed
Subtarget support for parameterized register class information
Implement "checkFeatures" and emitting HW mode check code. Differential Revision: https://reviews.llvm.org/D31959 llvm-svn: 313295
1 parent 26e689f commit 788e768

File tree

5 files changed

+48
-5
lines changed

5 files changed

+48
-5
lines changed

llvm/include/llvm/MC/MCSubtargetInfo.h

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class MCSubtargetInfo {
118118
/// all feature bits implied by the flag.
119119
FeatureBitset ApplyFeatureFlag(StringRef FS);
120120

121+
/// Check whether the subtarget features are enabled/disabled as per
122+
/// the provided string, ignoring all other features.
123+
bool checkFeatures(StringRef FS) const;
124+
121125
/// getSchedModelForCPU - Get the machine model of a CPU.
122126
///
123127
const MCSchedModel &getSchedModelForCPU(StringRef CPU) const;

llvm/include/llvm/MC/SubtargetFeature.h

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class SubtargetFeatures {
115115
ArrayRef<SubtargetFeatureKV> CPUTable,
116116
ArrayRef<SubtargetFeatureKV> FeatureTable);
117117

118+
/// Returns the vector of individual subtarget features.
119+
const std::vector<std::string> &getFeatures() const { return Features; }
120+
118121
/// Prints feature string.
119122
void print(raw_ostream &OS) const;
120123

llvm/include/llvm/Target/TargetSubtargetInfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ class TargetSubtargetInfo : public MCSubtargetInfo {
110110
return nullptr;
111111
}
112112

113+
virtual unsigned getHwMode() const { return 0; }
114+
113115
/// Target can subclass this hook to select a different DAG scheduler.
114116
virtual RegisterScheduler::FunctionPassCtor
115117
getDAGScheduler(CodeGenOpt::Level) const {

llvm/lib/MC/MCSubtargetInfo.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
7575
return FeatureBits;
7676
}
7777

78+
bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
79+
SubtargetFeatures T(FS);
80+
FeatureBitset Set, All;
81+
for (std::string F : T.getFeatures()) {
82+
SubtargetFeatures::ApplyFeatureFlag(Set, F, ProcFeatures);
83+
if (F[0] == '-')
84+
F[0] = '+';
85+
SubtargetFeatures::ApplyFeatureFlag(All, F, ProcFeatures);
86+
}
87+
return (FeatureBits & All) == Set;
88+
}
89+
7890
const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
7991
assert(ProcSchedModels && "Processor machine model not available!");
8092

llvm/utils/TableGen/SubtargetEmitter.cpp

+27-5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class SubtargetEmitter {
6868
}
6969
};
7070

71+
const CodeGenTarget &TGT;
7172
RecordKeeper &Records;
7273
CodeGenSchedModels &SchedModels;
7374
std::string Target;
@@ -106,12 +107,14 @@ class SubtargetEmitter {
106107
void EmitProcessorLookup(raw_ostream &OS);
107108
void EmitSchedModelHelpers(const std::string &ClassName, raw_ostream &OS);
108109
void EmitSchedModel(raw_ostream &OS);
110+
void EmitHwModeCheck(const std::string &ClassName, raw_ostream &OS);
109111
void ParseFeaturesFunction(raw_ostream &OS, unsigned NumFeatures,
110112
unsigned NumProcs);
111113

112114
public:
113-
SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT):
114-
Records(R), SchedModels(TGT.getSchedModels()), Target(TGT.getName()) {}
115+
SubtargetEmitter(RecordKeeper &R, CodeGenTarget &TGT)
116+
: TGT(TGT), Records(R), SchedModels(TGT.getSchedModels()),
117+
Target(TGT.getName()) {}
115118

116119
void run(raw_ostream &o);
117120
};
@@ -1329,6 +1332,22 @@ void SubtargetEmitter::EmitSchedModelHelpers(const std::string &ClassName,
13291332
<< "} // " << ClassName << "::resolveSchedClass\n";
13301333
}
13311334

1335+
void SubtargetEmitter::EmitHwModeCheck(const std::string &ClassName,
1336+
raw_ostream &OS) {
1337+
const CodeGenHwModes &CGH = TGT.getHwModes();
1338+
assert(CGH.getNumModeIds() > 0);
1339+
if (CGH.getNumModeIds() == 1)
1340+
return;
1341+
1342+
OS << "unsigned " << ClassName << "::getHwMode() const {\n";
1343+
for (unsigned M = 1, NumModes = CGH.getNumModeIds(); M != NumModes; ++M) {
1344+
const HwMode &HM = CGH.getMode(M);
1345+
OS << " if (checkFeatures(\"" << HM.Features
1346+
<< "\")) return " << M << ";\n";
1347+
}
1348+
OS << " return 0;\n}\n";
1349+
}
1350+
13321351
//
13331352
// ParseFeaturesFunction - Produces a subtarget specific function for parsing
13341353
// the subtarget features string.
@@ -1462,9 +1481,11 @@ void SubtargetEmitter::run(raw_ostream &OS) {
14621481
<< " const MachineInstr *DefMI,"
14631482
<< " const TargetSchedModel *SchedModel) const override;\n"
14641483
<< " DFAPacketizer *createDFAPacketizer(const InstrItineraryData *IID)"
1465-
<< " const;\n"
1466-
<< "};\n";
1467-
OS << "} // end namespace llvm\n\n";
1484+
<< " const;\n";
1485+
if (TGT.getHwModes().getNumModeIds() > 1)
1486+
OS << " unsigned getHwMode() const override;\n";
1487+
OS << "};\n"
1488+
<< "} // end namespace llvm\n\n";
14681489

14691490
OS << "#endif // GET_SUBTARGETINFO_HEADER\n\n";
14701491

@@ -1515,6 +1536,7 @@ void SubtargetEmitter::run(raw_ostream &OS) {
15151536
OS << ") {}\n\n";
15161537

15171538
EmitSchedModelHelpers(ClassName, OS);
1539+
EmitHwModeCheck(ClassName, OS);
15181540

15191541
OS << "} // end namespace llvm\n\n";
15201542

0 commit comments

Comments
 (0)