Skip to content

[LLVM][TableGen] Change DXILEmitter to use const Record pointers #110111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions llvm/utils/TableGen/DXILEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ struct DXILOperationDesc {
StringRef OpClass; // name of the opcode class
StringRef Doc; // the documentation description of this instruction
// Vector of operand type records - return type is at index 0
SmallVector<Record *> OpTypes;
SmallVector<Record *> OverloadRecs;
SmallVector<Record *> StageRecs;
SmallVector<Record *> AttrRecs;
SmallVector<const Record *> OpTypes;
SmallVector<const Record *> OverloadRecs;
SmallVector<const Record *> StageRecs;
SmallVector<const Record *> AttrRecs;
StringRef Intrinsic; // The llvm intrinsic map to OpName. Default is "" which
// means no map exists
SmallVector<StringRef, 4>
Expand All @@ -57,8 +57,8 @@ struct DXILOperationDesc {
/// In-place sort TableGen records of class with a field
/// Version dxil_version
/// in the ascending version order.
static void AscendingSortByVersion(std::vector<Record *> &Recs) {
std::sort(Recs.begin(), Recs.end(), [](Record *RecA, Record *RecB) {
static void AscendingSortByVersion(std::vector<const Record *> &Recs) {
sort(Recs, [](const Record *RecA, const Record *RecB) {
unsigned RecAMaj =
RecA->getValueAsDef("dxil_version")->getValueAsInt("Major");
unsigned RecAMin =
Expand All @@ -82,13 +82,12 @@ DXILOperationDesc::DXILOperationDesc(const Record *R) {
OpCode = R->getValueAsInt("OpCode");

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

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

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

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

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

for (Record *CR : Recs) {
for (const Record *CR : Recs) {
OverloadRecs.push_back(CR);
}

// Get stage records
Recs = R->getValueAsListOfDefs("stages");
Recs = R->getValueAsListOfConstDefs("stages");

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

for (Record *CR : Recs) {
for (const Record *CR : Recs) {
StageRecs.push_back(CR);
}

// Get attribute records
Recs = R->getValueAsListOfDefs("attributes");
Recs = R->getValueAsListOfConstDefs("attributes");

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

for (Record *CR : Recs) {
for (const Record *CR : Recs) {
AttrRecs.push_back(CR);
}

Expand Down Expand Up @@ -201,7 +200,7 @@ static StringRef getOverloadKindStr(const Record *R) {
/// \return std::string string representation of overload mask string
/// predicated by DXIL Version. E.g.,
// {{{1, 0}, Mask1}, {{1, 2}, Mask2}, ...}
static std::string getOverloadMaskString(const SmallVector<Record *> Recs) {
static std::string getOverloadMaskString(ArrayRef<const Record *> Recs) {
std::string MaskString = "";
std::string Prefix = "";
MaskString.append("{");
Expand Down Expand Up @@ -247,7 +246,7 @@ static std::string getOverloadMaskString(const SmallVector<Record *> Recs) {
/// \return std::string string representation of stages mask string
/// predicated by DXIL Version. E.g.,
// {{{1, 0}, Mask1}, {{1, 2}, Mask2}, ...}
static std::string getStageMaskString(const SmallVector<Record *> Recs) {
static std::string getStageMaskString(ArrayRef<const Record *> Recs) {
std::string MaskString = "";
std::string Prefix = "";
MaskString.append("{");
Expand Down Expand Up @@ -290,7 +289,7 @@ static std::string getStageMaskString(const SmallVector<Record *> Recs) {
/// \return std::string string representation of stages mask string
/// predicated by DXIL Version. E.g.,
// {{{1, 0}, Mask1}, {{1, 2}, Mask2}, ...}
static std::string getAttributeMaskString(const SmallVector<Record *> Recs) {
static std::string getAttributeMaskString(ArrayRef<const Record *> Recs) {
std::string MaskString = "";
std::string Prefix = "";
MaskString.append("{");
Expand Down
Loading