Skip to content

[MLIR][TableGen] Minor code cleanup in DirectiveCommonGen #110290

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 30, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion llvm/include/llvm/TableGen/DirectiveEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class VersionedClause {

class ClauseVal : public BaseRecord {
public:
explicit ClauseVal(const Record *Def) : BaseRecord(Def) {}
ClauseVal(const Record *Def) : BaseRecord(Def) {}

int getValue() const { return Def->getValueAsInt("value"); }

Expand Down
6 changes: 2 additions & 4 deletions llvm/utils/TableGen/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ static void GenerateEnumClauseVal(ArrayRef<const Record *> Records,

OS << "\n";
OS << "enum class " << EnumName << " {\n";
for (const auto &CV : ClauseVals) {
ClauseVal CVal(CV);
OS << " " << CV->getName() << "=" << CVal.getValue() << ",\n";
}
for (const ClauseVal CVal : ClauseVals)
OS << " " << CVal.getRecordName() << "=" << CVal.getValue() << ",\n";
OS << "};\n";

if (DirLang.hasMakeEnumAvailableInNamespace()) {
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/mlir-tblgen/directive-common.td
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def TDLC_ClauseA : Clause<"clausea"> {
// CHECK: def AKind: I32EnumAttr<
// CHECK: "ClauseAKind",
// CHECK: "AKind Clause",
// CHECK: [AKindvala,AKindvalb]> {
// CHECK: [AKindvala, AKindvalb]> {
// CHECK: let cppNamespace = "::mlir::tdl";
// CHECK: }
// CHECK: def AKindAttr : EnumAttr<TDL_Dialect, AKind, "akind">;
14 changes: 4 additions & 10 deletions mlir/tools/mlir-tblgen/DirectiveCommonGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ static bool emitDecls(const RecordKeeper &recordKeeper, llvm::StringRef dialect,
recordKeeper.getAllDerivedDefinitions("DirectiveLanguage");
assert(!directiveLanguages.empty() && "DirectiveLanguage missing.");

for (const Record *r : recordKeeper.getAllDerivedDefinitions("Clause")) {
Clause c{r};
for (const Clause c : recordKeeper.getAllDerivedDefinitions("Clause")) {
const auto &clauseVals = c.getClauseVals();
if (clauseVals.empty())
continue;
Expand All @@ -65,14 +64,13 @@ static bool emitDecls(const RecordKeeper &recordKeeper, llvm::StringRef dialect,

std::vector<std::string> cvDefs;
for (const auto &it : llvm::enumerate(clauseVals)) {
ClauseVal cval{it.value()};
const ClauseVal cval{it.value()};
if (!cval.isUserVisible())
continue;

std::string name = cval.getFormattedName();
std::string enumValName(name.length(), ' ');
std::transform(name.begin(), name.end(), enumValName.begin(),
llvm::toLower);
llvm::transform(name, enumValName.begin(), llvm::toLower);
enumValName[0] = llvm::toUpper(enumValName[0]);
std::string cvDef{(enumName + llvm::Twine(name)).str()};
os << "def " << cvDef << " : I32EnumAttrCase<\"" << enumValName << "\", "
Expand All @@ -84,11 +82,7 @@ static bool emitDecls(const RecordKeeper &recordKeeper, llvm::StringRef dialect,
os << " \"Clause" << enumName << "\",\n";
os << " \"" << enumName << " Clause\",\n";
os << " [";
for (unsigned int i = 0; i < cvDefs.size(); i++) {
os << cvDefs[i];
if (i != cvDefs.size() - 1)
os << ",";
}
llvm::interleaveComma(cvDefs, os);
os << "]> {\n";
os << " let cppNamespace = \"::mlir::"
<< directiveLanguages[0]->getValueAsString("cppNamespace") << "\";\n";
Expand Down
Loading