-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[NFC][TableGen] Use Twine
for Name argument in CodeGenHelpers
#163581
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
Open
jurahul
wants to merge
1
commit into
llvm:main
Choose a base branch
from
jurahul:nfc_tg_use_twine_cghelpers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+19
−25
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-core Author: Rahul Joshi (jurahul) ChangesFull diff: https://github.com/llvm/llvm-project/pull/163581.diff 4 Files Affected:
diff --git a/llvm/include/llvm/TableGen/CodeGenHelpers.h b/llvm/include/llvm/TableGen/CodeGenHelpers.h
index e22c6d4f6d390..d6fe36c8da4d3 100644
--- a/llvm/include/llvm/TableGen/CodeGenHelpers.h
+++ b/llvm/include/llvm/TableGen/CodeGenHelpers.h
@@ -13,9 +13,8 @@
#ifndef LLVM_TABLEGEN_CODEGENHELPERS_H
#define LLVM_TABLEGEN_CODEGENHELPERS_H
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
@@ -23,7 +22,7 @@ namespace llvm {
// Simple RAII helper for emitting ifdef-undef-endif scope.
class IfDefEmitter {
public:
- IfDefEmitter(raw_ostream &OS, StringRef Name) : Name(Name.str()), OS(OS) {
+ IfDefEmitter(raw_ostream &OS, const Twine &Name) : Name(Name.str()), OS(OS) {
OS << "#ifdef " << Name << "\n"
<< "#undef " << Name << "\n\n";
}
@@ -37,7 +36,7 @@ class IfDefEmitter {
// Simple RAII helper for emitting header include guard (ifndef-define-endif).
class IncludeGuardEmitter {
public:
- IncludeGuardEmitter(raw_ostream &OS, StringRef Name)
+ IncludeGuardEmitter(raw_ostream &OS, const Twine &Name)
: Name(Name.str()), OS(OS) {
OS << "#ifndef " << Name << "\n"
<< "#define " << Name << "\n\n";
@@ -54,8 +53,8 @@ class IncludeGuardEmitter {
// namespace scope.
class NamespaceEmitter {
public:
- NamespaceEmitter(raw_ostream &OS, StringRef NameUntrimmed)
- : Name(trim(NameUntrimmed).str()), OS(OS) {
+ NamespaceEmitter(raw_ostream &OS, const Twine &NameUntrimmed)
+ : Name(trim(NameUntrimmed)), OS(OS) {
if (!Name.empty())
OS << "namespace " << Name << " {\n";
}
@@ -77,9 +76,11 @@ class NamespaceEmitter {
// }
//
// and cannot use "namespace ::mlir::toy".
- static StringRef trim(StringRef Name) {
- Name.consume_front("::");
- return Name;
+ static std::string trim(const Twine &NameUntrimmed) {
+ std::string Name = NameUntrimmed.str();
+ StringRef StrRef = Name;
+ StrRef.consume_front("::");
+ return StrRef.str();
}
std::string Name;
raw_ostream &OS;
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index 3c6ff1132230b..bc9d281f8cbb9 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -266,7 +266,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
return;
StringRef Lang = DirLang.getName();
- IncludeGuardEmitter IncGuard(OS, (Twine("LLVM_") + Lang + "_INC").str());
+ IncludeGuardEmitter IncGuard(OS, Twine("LLVM_") + Lang + "_INC");
OS << "#include \"llvm/ADT/ArrayRef.h\"\n";
@@ -941,10 +941,8 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_SETS";
- IfDefEmitter Scope(OS, IfDefName);
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_SETS");
StringRef Namespace =
getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE);
@@ -985,10 +983,8 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
// allowances (allowed, allowed once, allowed exclusive and required).
static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_MAP";
- IfDefEmitter Scope(OS, IfDefName);
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_MAP");
OS << "{\n";
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index daae3c79ffd43..ff610f46c5aa0 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -4938,10 +4938,7 @@ static void emitOpDefShard(const RecordKeeper &records,
ArrayRef<const Record *> defs,
const Dialect &dialect, unsigned shardIndex,
unsigned shardCount, raw_ostream &os) {
- std::string shardGuard = "GET_OP_DEFS_";
- std::string indexStr = std::to_string(shardIndex);
- shardGuard += indexStr;
- IfDefEmitter scope(os, shardGuard);
+ IfDefEmitter scope(os, Twine("GET_OP_DEFS_") + Twine(shardIndex));
// Emit the op registration hook in the first shard.
const char *const opRegistrationHook =
@@ -4968,7 +4965,7 @@ static void emitOpDefShard(const RecordKeeper &records,
os << "}\n";
// Generate the per-shard op definitions.
- emitOpClassDefs(records, defs, os, indexStr);
+ emitOpClassDefs(records, defs, os, std::to_string(shardIndex));
}
/// Emit op definitions for all op records.
diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
index ab8d534a99f19..f74cc05790042 100644
--- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -442,8 +442,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
}
void InterfaceGenerator::emitInterfaceTraitDecl(const Interface &interface) {
- auto cppNamespace = (interface.getCppNamespace() + "::detail").str();
- llvm::NamespaceEmitter ns(os, cppNamespace);
+ llvm::NamespaceEmitter ns(os,
+ Twine(interface.getCppNamespace()) + "::detail");
StringRef interfaceName = interface.getName();
auto interfaceTraitsName = (interfaceName + "InterfaceTraits").str();
|
@llvm/pr-subscribers-tablegen Author: Rahul Joshi (jurahul) ChangesFull diff: https://github.com/llvm/llvm-project/pull/163581.diff 4 Files Affected:
diff --git a/llvm/include/llvm/TableGen/CodeGenHelpers.h b/llvm/include/llvm/TableGen/CodeGenHelpers.h
index e22c6d4f6d390..d6fe36c8da4d3 100644
--- a/llvm/include/llvm/TableGen/CodeGenHelpers.h
+++ b/llvm/include/llvm/TableGen/CodeGenHelpers.h
@@ -13,9 +13,8 @@
#ifndef LLVM_TABLEGEN_CODEGENHELPERS_H
#define LLVM_TABLEGEN_CODEGENHELPERS_H
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
@@ -23,7 +22,7 @@ namespace llvm {
// Simple RAII helper for emitting ifdef-undef-endif scope.
class IfDefEmitter {
public:
- IfDefEmitter(raw_ostream &OS, StringRef Name) : Name(Name.str()), OS(OS) {
+ IfDefEmitter(raw_ostream &OS, const Twine &Name) : Name(Name.str()), OS(OS) {
OS << "#ifdef " << Name << "\n"
<< "#undef " << Name << "\n\n";
}
@@ -37,7 +36,7 @@ class IfDefEmitter {
// Simple RAII helper for emitting header include guard (ifndef-define-endif).
class IncludeGuardEmitter {
public:
- IncludeGuardEmitter(raw_ostream &OS, StringRef Name)
+ IncludeGuardEmitter(raw_ostream &OS, const Twine &Name)
: Name(Name.str()), OS(OS) {
OS << "#ifndef " << Name << "\n"
<< "#define " << Name << "\n\n";
@@ -54,8 +53,8 @@ class IncludeGuardEmitter {
// namespace scope.
class NamespaceEmitter {
public:
- NamespaceEmitter(raw_ostream &OS, StringRef NameUntrimmed)
- : Name(trim(NameUntrimmed).str()), OS(OS) {
+ NamespaceEmitter(raw_ostream &OS, const Twine &NameUntrimmed)
+ : Name(trim(NameUntrimmed)), OS(OS) {
if (!Name.empty())
OS << "namespace " << Name << " {\n";
}
@@ -77,9 +76,11 @@ class NamespaceEmitter {
// }
//
// and cannot use "namespace ::mlir::toy".
- static StringRef trim(StringRef Name) {
- Name.consume_front("::");
- return Name;
+ static std::string trim(const Twine &NameUntrimmed) {
+ std::string Name = NameUntrimmed.str();
+ StringRef StrRef = Name;
+ StrRef.consume_front("::");
+ return StrRef.str();
}
std::string Name;
raw_ostream &OS;
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index 3c6ff1132230b..bc9d281f8cbb9 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -266,7 +266,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
return;
StringRef Lang = DirLang.getName();
- IncludeGuardEmitter IncGuard(OS, (Twine("LLVM_") + Lang + "_INC").str());
+ IncludeGuardEmitter IncGuard(OS, Twine("LLVM_") + Lang + "_INC");
OS << "#include \"llvm/ADT/ArrayRef.h\"\n";
@@ -941,10 +941,8 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_SETS";
- IfDefEmitter Scope(OS, IfDefName);
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_SETS");
StringRef Namespace =
getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE);
@@ -985,10 +983,8 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
// allowances (allowed, allowed once, allowed exclusive and required).
static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang,
Frontend FE, raw_ostream &OS) {
- std::string IfDefName{"GEN_"};
- IfDefName += getFESpelling(FE).upper();
- IfDefName += "_DIRECTIVE_CLAUSE_MAP";
- IfDefEmitter Scope(OS, IfDefName);
+ IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
+ "_DIRECTIVE_CLAUSE_MAP");
OS << "{\n";
diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
index daae3c79ffd43..ff610f46c5aa0 100644
--- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
@@ -4938,10 +4938,7 @@ static void emitOpDefShard(const RecordKeeper &records,
ArrayRef<const Record *> defs,
const Dialect &dialect, unsigned shardIndex,
unsigned shardCount, raw_ostream &os) {
- std::string shardGuard = "GET_OP_DEFS_";
- std::string indexStr = std::to_string(shardIndex);
- shardGuard += indexStr;
- IfDefEmitter scope(os, shardGuard);
+ IfDefEmitter scope(os, Twine("GET_OP_DEFS_") + Twine(shardIndex));
// Emit the op registration hook in the first shard.
const char *const opRegistrationHook =
@@ -4968,7 +4965,7 @@ static void emitOpDefShard(const RecordKeeper &records,
os << "}\n";
// Generate the per-shard op definitions.
- emitOpClassDefs(records, defs, os, indexStr);
+ emitOpClassDefs(records, defs, os, std::to_string(shardIndex));
}
/// Emit op definitions for all op records.
diff --git a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
index ab8d534a99f19..f74cc05790042 100644
--- a/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp
@@ -442,8 +442,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
}
void InterfaceGenerator::emitInterfaceTraitDecl(const Interface &interface) {
- auto cppNamespace = (interface.getCppNamespace() + "::detail").str();
- llvm::NamespaceEmitter ns(os, cppNamespace);
+ llvm::NamespaceEmitter ns(os,
+ Twine(interface.getCppNamespace()) + "::detail");
StringRef interfaceName = interface.getName();
auto interfaceTraitsName = (interfaceName + "InterfaceTraits").str();
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.