Skip to content

Commit 01477a7

Browse files
committed
Do not serialize the input Twine more than once
1 parent 90eff5f commit 01477a7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

llvm/include/llvm/TableGen/CodeGenHelpers.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace llvm {
2222
// Simple RAII helper for emitting ifdef-undef-endif scope.
2323
class IfDefEmitter {
2424
public:
25-
IfDefEmitter(raw_ostream &OS, const Twine &Name) : Name(Name.str()), OS(OS) {
25+
IfDefEmitter(raw_ostream &OS, const Twine &NameTwine)
26+
: Name(NameTwine.str()), OS(OS) {
2627
OS << "#ifdef " << Name << "\n"
2728
<< "#undef " << Name << "\n\n";
2829
}
@@ -36,8 +37,8 @@ class IfDefEmitter {
3637
// Simple RAII helper for emitting header include guard (ifndef-define-endif).
3738
class IncludeGuardEmitter {
3839
public:
39-
IncludeGuardEmitter(raw_ostream &OS, const Twine &Name)
40-
: Name(Name.str()), OS(OS) {
40+
IncludeGuardEmitter(raw_ostream &OS, const Twine &NameTwine)
41+
: Name(NameTwine.str()), OS(OS) {
4142
OS << "#ifndef " << Name << "\n"
4243
<< "#define " << Name << "\n\n";
4344
}
@@ -53,8 +54,8 @@ class IncludeGuardEmitter {
5354
// namespace scope.
5455
class NamespaceEmitter {
5556
public:
56-
NamespaceEmitter(raw_ostream &OS, const Twine &NameUntrimmed)
57-
: Name(trim(NameUntrimmed)), OS(OS) {
57+
NamespaceEmitter(raw_ostream &OS, const Twine &NameTwine)
58+
: Name(trim(NameTwine)), OS(OS) {
5859
if (!Name.empty())
5960
OS << "namespace " << Name << " {\n";
6061
}
@@ -76,8 +77,8 @@ class NamespaceEmitter {
7677
// }
7778
//
7879
// and cannot use "namespace ::mlir::toy".
79-
static std::string trim(const Twine &NameUntrimmed) {
80-
std::string Name = NameUntrimmed.str();
80+
static std::string trim(const Twine &NameTwine) {
81+
std::string Name = NameTwine.str();
8182
StringRef StrRef = Name;
8283
StrRef.consume_front("::");
8384
return StrRef.str();

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4938,7 +4938,7 @@ static void emitOpDefShard(const RecordKeeper &records,
49384938
ArrayRef<const Record *> defs,
49394939
const Dialect &dialect, unsigned shardIndex,
49404940
unsigned shardCount, raw_ostream &os) {
4941-
IfDefEmitter scope(os, Twine("GET_OP_DEFS_") + Twine(shardIndex));
4941+
IfDefEmitter scope(os, "GET_OP_DEFS_" + Twine(shardIndex));
49424942

49434943
// Emit the op registration hook in the first shard.
49444944
const char *const opRegistrationHook =

0 commit comments

Comments
 (0)