Skip to content

Commit 7662cdc

Browse files
committed
[NFC][TableGen] Use Twine for Name argument in CodeGenHelpers
1 parent 16dfd31 commit 7662cdc

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

llvm/include/llvm/TableGen/CodeGenHelpers.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,16 @@
1313
#ifndef LLVM_TABLEGEN_CODEGENHELPERS_H
1414
#define LLVM_TABLEGEN_CODEGENHELPERS_H
1515

16-
#include "llvm/ADT/STLExtras.h"
17-
#include "llvm/ADT/StringExtras.h"
1816
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/ADT/Twine.h"
1918
#include "llvm/Support/raw_ostream.h"
2019
#include <string>
2120

2221
namespace llvm {
2322
// Simple RAII helper for emitting ifdef-undef-endif scope.
2423
class IfDefEmitter {
2524
public:
26-
IfDefEmitter(raw_ostream &OS, StringRef Name) : Name(Name.str()), OS(OS) {
25+
IfDefEmitter(raw_ostream &OS, const Twine &Name) : Name(Name.str()), OS(OS) {
2726
OS << "#ifdef " << Name << "\n"
2827
<< "#undef " << Name << "\n\n";
2928
}
@@ -37,7 +36,7 @@ class IfDefEmitter {
3736
// Simple RAII helper for emitting header include guard (ifndef-define-endif).
3837
class IncludeGuardEmitter {
3938
public:
40-
IncludeGuardEmitter(raw_ostream &OS, StringRef Name)
39+
IncludeGuardEmitter(raw_ostream &OS, const Twine &Name)
4140
: Name(Name.str()), OS(OS) {
4241
OS << "#ifndef " << Name << "\n"
4342
<< "#define " << Name << "\n\n";
@@ -54,8 +53,8 @@ class IncludeGuardEmitter {
5453
// namespace scope.
5554
class NamespaceEmitter {
5655
public:
57-
NamespaceEmitter(raw_ostream &OS, StringRef NameUntrimmed)
58-
: Name(trim(NameUntrimmed).str()), OS(OS) {
56+
NamespaceEmitter(raw_ostream &OS, const Twine &NameUntrimmed)
57+
: Name(trim(NameUntrimmed)), OS(OS) {
5958
if (!Name.empty())
6059
OS << "namespace " << Name << " {\n";
6160
}
@@ -77,9 +76,11 @@ class NamespaceEmitter {
7776
// }
7877
//
7978
// and cannot use "namespace ::mlir::toy".
80-
static StringRef trim(StringRef Name) {
81-
Name.consume_front("::");
82-
return Name;
79+
static std::string trim(const Twine &NameUntrimmed) {
80+
std::string Name = NameUntrimmed.str();
81+
StringRef StrRef = Name;
82+
StrRef.consume_front("::");
83+
return StrRef.str();
8384
}
8485
std::string Name;
8586
raw_ostream &OS;

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static void emitDirectivesDecl(const RecordKeeper &Records, raw_ostream &OS) {
266266
return;
267267

268268
StringRef Lang = DirLang.getName();
269-
IncludeGuardEmitter IncGuard(OS, (Twine("LLVM_") + Lang + "_INC").str());
269+
IncludeGuardEmitter IncGuard(OS, Twine("LLVM_") + Lang + "_INC");
270270

271271
OS << "#include \"llvm/ADT/ArrayRef.h\"\n";
272272

@@ -941,10 +941,8 @@ static void generateClauseSet(ArrayRef<const Record *> VerClauses,
941941
static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
942942
Frontend FE, raw_ostream &OS) {
943943

944-
std::string IfDefName{"GEN_"};
945-
IfDefName += getFESpelling(FE).upper();
946-
IfDefName += "_DIRECTIVE_CLAUSE_SETS";
947-
IfDefEmitter Scope(OS, IfDefName);
944+
IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
945+
"_DIRECTIVE_CLAUSE_SETS");
948946

949947
StringRef Namespace =
950948
getFESpelling(FE == Frontend::Flang ? Frontend::LLVM : FE);
@@ -985,10 +983,8 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
985983
// allowances (allowed, allowed once, allowed exclusive and required).
986984
static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang,
987985
Frontend FE, raw_ostream &OS) {
988-
std::string IfDefName{"GEN_"};
989-
IfDefName += getFESpelling(FE).upper();
990-
IfDefName += "_DIRECTIVE_CLAUSE_MAP";
991-
IfDefEmitter Scope(OS, IfDefName);
986+
IfDefEmitter Scope(OS, "GEN_" + getFESpelling(FE).upper() +
987+
"_DIRECTIVE_CLAUSE_MAP");
992988

993989
OS << "{\n";
994990

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4938,10 +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-
std::string shardGuard = "GET_OP_DEFS_";
4942-
std::string indexStr = std::to_string(shardIndex);
4943-
shardGuard += indexStr;
4944-
IfDefEmitter scope(os, shardGuard);
4941+
IfDefEmitter scope(os, Twine("GET_OP_DEFS_") + Twine(shardIndex));
49454942

49464943
// Emit the op registration hook in the first shard.
49474944
const char *const opRegistrationHook =
@@ -4968,7 +4965,7 @@ static void emitOpDefShard(const RecordKeeper &records,
49684965
os << "}\n";
49694966

49704967
// Generate the per-shard op definitions.
4971-
emitOpClassDefs(records, defs, os, indexStr);
4968+
emitOpClassDefs(records, defs, os, std::to_string(shardIndex));
49724969
}
49734970

49744971
/// Emit op definitions for all op records.

mlir/tools/mlir-tblgen/OpInterfacesGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,8 @@ void InterfaceGenerator::emitModelMethodsDef(const Interface &interface) {
442442
}
443443

444444
void InterfaceGenerator::emitInterfaceTraitDecl(const Interface &interface) {
445-
auto cppNamespace = (interface.getCppNamespace() + "::detail").str();
446-
llvm::NamespaceEmitter ns(os, cppNamespace);
445+
llvm::NamespaceEmitter ns(os,
446+
Twine(interface.getCppNamespace()) + "::detail");
447447

448448
StringRef interfaceName = interface.getName();
449449
auto interfaceTraitsName = (interfaceName + "InterfaceTraits").str();

0 commit comments

Comments
 (0)