[Mlir-commits] [llvm] [mlir] [NFC][TableGen] Use `Twine` for Name argument in CodeGenHelpers (PR #163581)

Rahul Joshi llvmlistbot at llvm.org
Thu Oct 16 12:50:33 PDT 2025


================
@@ -13,17 +13,16 @@
 #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>
 
 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) {
----------------
jurahul wrote:

I though most IRBuilder API take in a Twine and not a StringRef for this reason, so clients can easily pass concatenated strings as Twines, which do get serialized internally when that IR object is created. TableGen Error.h API also take in a Twine, but there you could argue that the Twine is just emitted to a stream and hence does not get serialized.

Just to be clear String -> Twine -> std::string  (new code) has no pessimization compared to StringRef->std::string (old code).


https://github.com/llvm/llvm-project/pull/163581


More information about the Mlir-commits mailing list