Skip to content

Commit 0950078

Browse files
authored
[LLVM][TableGen] Change DXILEmitter to use const Record pointers (#110111)
Change DXILEmitter to use const Record pointers. This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089
1 parent 9483ff9 commit 0950078

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

llvm/utils/TableGen/DXILEmitter.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ struct DXILOperationDesc {
3939
StringRef OpClass; // name of the opcode class
4040
StringRef Doc; // the documentation description of this instruction
4141
// Vector of operand type records - return type is at index 0
42-
SmallVector<Record *> OpTypes;
43-
SmallVector<Record *> OverloadRecs;
44-
SmallVector<Record *> StageRecs;
45-
SmallVector<Record *> AttrRecs;
42+
SmallVector<const Record *> OpTypes;
43+
SmallVector<const Record *> OverloadRecs;
44+
SmallVector<const Record *> StageRecs;
45+
SmallVector<const Record *> AttrRecs;
4646
StringRef Intrinsic; // The llvm intrinsic map to OpName. Default is "" which
4747
// means no map exists
4848
SmallVector<StringRef, 4>
@@ -57,8 +57,8 @@ struct DXILOperationDesc {
5757
/// In-place sort TableGen records of class with a field
5858
/// Version dxil_version
5959
/// in the ascending version order.
60-
static void AscendingSortByVersion(std::vector<Record *> &Recs) {
61-
std::sort(Recs.begin(), Recs.end(), [](Record *RecA, Record *RecB) {
60+
static void AscendingSortByVersion(std::vector<const Record *> &Recs) {
61+
sort(Recs, [](const Record *RecA, const Record *RecB) {
6262
unsigned RecAMaj =
6363
RecA->getValueAsDef("dxil_version")->getValueAsInt("Major");
6464
unsigned RecAMin =
@@ -82,13 +82,12 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
8282
OpCode = R->getValueAsInt("OpCode");
8383

8484
Doc = R->getValueAsString("Doc");
85-
SmallVector<Record *> ParamTypeRecs;
85+
SmallVector<const Record *> ParamTypeRecs;
8686

8787
ParamTypeRecs.push_back(R->getValueAsDef("result"));
8888

89-
std::vector<Record *> ArgTys = R->getValueAsListOfDefs("arguments");
90-
for (auto Ty : ArgTys) {
91-
ParamTypeRecs.push_back(Ty);
89+
for (const Record *ArgTy : R->getValueAsListOfDefs("arguments")) {
90+
ParamTypeRecs.push_back(ArgTy);
9291
}
9392
size_t ParamTypeRecsSize = ParamTypeRecs.size();
9493
// Populate OpTypes with return type and parameter types
@@ -100,7 +99,7 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
10099
// llvm/IR/Intrinsics.td
101100
OverloadParamIndex = -1; // A sigil meaning none.
102101
for (unsigned i = 0; i < ParamTypeRecsSize; i++) {
103-
Record *TR = ParamTypeRecs[i];
102+
const Record *TR = ParamTypeRecs[i];
104103
// Track operation parameter indices of any overload types
105104
if (TR->getValueAsInt("isOverload")) {
106105
if (OverloadParamIndex != -1) {
@@ -117,17 +116,17 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
117116
}
118117

119118
// Get overload records
120-
std::vector<Record *> Recs = R->getValueAsListOfDefs("overloads");
119+
std::vector<const Record *> Recs = R->getValueAsListOfConstDefs("overloads");
121120

122121
// Sort records in ascending order of DXIL version
123122
AscendingSortByVersion(Recs);
124123

125-
for (Record *CR : Recs) {
124+
for (const Record *CR : Recs) {
126125
OverloadRecs.push_back(CR);
127126
}
128127

129128
// Get stage records
130-
Recs = R->getValueAsListOfDefs("stages");
129+
Recs = R->getValueAsListOfConstDefs("stages");
131130

132131
if (Recs.empty()) {
133132
PrintFatalError(R, Twine("Atleast one specification of valid stage for ") +
@@ -137,17 +136,17 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
137136
// Sort records in ascending order of DXIL version
138137
AscendingSortByVersion(Recs);
139138

140-
for (Record *CR : Recs) {
139+
for (const Record *CR : Recs) {
141140
StageRecs.push_back(CR);
142141
}
143142

144143
// Get attribute records
145-
Recs = R->getValueAsListOfDefs("attributes");
144+
Recs = R->getValueAsListOfConstDefs("attributes");
146145

147146
// Sort records in ascending order of DXIL version
148147
AscendingSortByVersion(Recs);
149148

150-
for (Record *CR : Recs) {
149+
for (const Record *CR : Recs) {
151150
AttrRecs.push_back(CR);
152151
}
153152

@@ -201,7 +200,7 @@ static StringRef getOverloadKindStr(const Record *R) {
201200
/// \return std::string string representation of overload mask string
202201
/// predicated by DXIL Version. E.g.,
203202
// {{{1, 0}, Mask1}, {{1, 2}, Mask2}, ...}
204-
static std::string getOverloadMaskString(const SmallVector<Record *> Recs) {
203+
static std::string getOverloadMaskString(ArrayRef<const Record *> Recs) {
205204
std::string MaskString = "";
206205
std::string Prefix = "";
207206
MaskString.append("{");
@@ -247,7 +246,7 @@ static std::string getOverloadMaskString(const SmallVector<Record *> Recs) {
247246
/// \return std::string string representation of stages mask string
248247
/// predicated by DXIL Version. E.g.,
249248
// {{{1, 0}, Mask1}, {{1, 2}, Mask2}, ...}
250-
static std::string getStageMaskString(const SmallVector<Record *> Recs) {
249+
static std::string getStageMaskString(ArrayRef<const Record *> Recs) {
251250
std::string MaskString = "";
252251
std::string Prefix = "";
253252
MaskString.append("{");
@@ -290,7 +289,7 @@ static std::string getStageMaskString(const SmallVector<Record *> Recs) {
290289
/// \return std::string string representation of stages mask string
291290
/// predicated by DXIL Version. E.g.,
292291
// {{{1, 0}, Mask1}, {{1, 2}, Mask2}, ...}
293-
static std::string getAttributeMaskString(const SmallVector<Record *> Recs) {
292+
static std::string getAttributeMaskString(ArrayRef<const Record *> Recs) {
294293
std::string MaskString = "";
295294
std::string Prefix = "";
296295
MaskString.append("{");

0 commit comments

Comments
 (0)