[llvm] [LLVM][ADT] Add support for `std::string += Twine` operator (PR #140644)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Mon May 19 16:18:30 PDT 2025


https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/140644

TableGen backends have frequence occurrence of code that can use this operator to build strings. 

>From b629af6ba8b25788706f683a1d9e5dd83692ef22 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 17 May 2025 07:18:29 -0700
Subject: [PATCH] [Twine string concat

---
 llvm/include/llvm/ADT/Twine.h                 |  5 ++-
 llvm/lib/Support/Twine.cpp                    |  6 +++
 llvm/utils/TableGen/AsmMatcherEmitter.cpp     |  2 +-
 llvm/utils/TableGen/AsmWriterEmitter.cpp      |  7 +---
 .../utils/TableGen/Basic/DirectiveEmitter.cpp | 17 +++------
 llvm/utils/TableGen/CodeEmitterGen.cpp        | 37 +++++++------------
 llvm/utils/TableGen/CodeGenMapTable.cpp       |  3 +-
 .../TableGen/Common/CodeGenDAGPatterns.cpp    | 31 +++++++---------
 .../TableGen/Common/CodeGenRegisters.cpp      |  6 +--
 llvm/utils/TableGen/DAGISelMatcherGen.cpp     | 14 +++----
 llvm/utils/TableGen/FastISelEmitter.cpp       |  3 +-
 llvm/utils/TableGen/GlobalISelEmitter.cpp     | 31 ++++++----------
 llvm/utils/TableGen/InstrInfoEmitter.cpp      |  7 ++--
 llvm/utils/TableGen/SubtargetEmitter.cpp      | 23 +++++-------
 14 files changed, 79 insertions(+), 113 deletions(-)

diff --git a/llvm/include/llvm/ADT/Twine.h b/llvm/include/llvm/ADT/Twine.h
index 7718150780e3a..db53489b217bc 100644
--- a/llvm/include/llvm/ADT/Twine.h
+++ b/llvm/include/llvm/ADT/Twine.h
@@ -275,8 +275,9 @@ namespace llvm {
       if (Str[0] != '\0') {
         LHS.cString = Str;
         LHSKind = CStringKind;
-      } else
+      } else {
         LHSKind = EmptyKind;
+      }
 
       assert(isValid() && "Invalid twine!");
     }
@@ -578,6 +579,8 @@ namespace llvm {
     return OS;
   }
 
+  std::string &operator+=(std::string &LHS, const Twine &RHS);
+
   /// @}
 
 } // end namespace llvm
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp
index 495b9cf2dbd68..e80319b692089 100644
--- a/llvm/lib/Support/Twine.cpp
+++ b/llvm/lib/Support/Twine.cpp
@@ -183,3 +183,9 @@ LLVM_DUMP_METHOD void Twine::dumpRepr() const {
   printRepr(dbgs());
 }
 #endif
+
+std::string &llvm::operator+=(std::string &LHS, const Twine &RHS) {
+  raw_string_ostream OS(LHS);
+  RHS.print(OS);
+  return LHS;
+}
diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index 2771facb004cc..b87b082f098d3 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -3240,7 +3240,7 @@ static std::string
 getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset) {
   std::string Name = "AMFBS";
   for (const Record *Feature : FeatureBitset)
-    Name += ("_" + Feature->getName()).str();
+    Name += "_" + Feature->getName();
   return Name;
 }
 
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp
index ebf1894b0d216..522060110d7d5 100644
--- a/llvm/utils/TableGen/AsmWriterEmitter.cpp
+++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp
@@ -187,8 +187,7 @@ void AsmWriterEmitter::FindUniqueOperandCommands(
     auto I = llvm::find(UniqueOperandCommands, Command);
     if (I != UniqueOperandCommands.end()) {
       size_t idx = I - UniqueOperandCommands.begin();
-      InstrsForCase[idx] += ", ";
-      InstrsForCase[idx] += Inst.CGI->TheDef->getName();
+      InstrsForCase[idx] += ", " + Inst.CGI->TheDef->getName();
       InstIdxs[idx].push_back(i);
     } else {
       UniqueOperandCommands.push_back(std::move(Command));
@@ -228,10 +227,8 @@ void AsmWriterEmitter::FindUniqueOperandCommands(
 
       // Okay, everything in this command set has the same next operand.  Add it
       // to UniqueOperandCommands and remember that it was consumed.
-      std::string Command =
+      UniqueOperandCommands[CommandIdx] +=
           "    " + FirstInst.Operands[Op].getCode(PassSubtarget) + "\n";
-
-      UniqueOperandCommands[CommandIdx] += Command;
       InstOpsUsed[CommandIdx]++;
     }
   }
diff --git a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
index df37d7005215e..db2aa9d0dfe20 100644
--- a/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
+++ b/llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
@@ -151,14 +151,11 @@ static void generateEnumClauseVal(ArrayRef<const Record *> Records,
            << "llvm::" << DirLang.getCppNamespace() << "::" << EnumName
            << "::" << CV->getName() << ";\n";
       }
-      EnumHelperFuncs += (Twine("LLVM_ABI ") + Twine(EnumName) + Twine(" get") +
-                          Twine(EnumName) + Twine("(StringRef);\n"))
-                             .str();
-
       EnumHelperFuncs +=
-          (Twine("LLVM_ABI llvm::StringRef get") + Twine(DirLang.getName()) +
-           Twine(EnumName) + Twine("Name(") + Twine(EnumName) + Twine(");\n"))
-              .str();
+          "LLVM_ABI " + EnumName + " get" + EnumName + "(StringRef);\n";
+
+      EnumHelperFuncs += "LLVM_ABI llvm::StringRef get" + DirLang.getName() +
+                         EnumName + "Name(" + EnumName + ");\n";
     }
   }
 }
@@ -883,8 +880,7 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
                                         DirectiveClauseFE FE, raw_ostream &OS) {
 
   std::string IfDefName{"GEN_"};
-  IfDefName += getFESpelling(FE).upper();
-  IfDefName += "_DIRECTIVE_CLAUSE_SETS";
+  IfDefName += getFESpelling(FE).upper() + "_DIRECTIVE_CLAUSE_SETS";
   IfDefScope Scope(IfDefName, OS);
 
   OS << "\n";
@@ -927,8 +923,7 @@ static void generateDirectiveClauseSets(const DirectiveLanguage &DirLang,
 static void generateDirectiveClauseMap(const DirectiveLanguage &DirLang,
                                        DirectiveClauseFE FE, raw_ostream &OS) {
   std::string IfDefName{"GEN_"};
-  IfDefName += getFESpelling(FE).upper();
-  IfDefName += "_DIRECTIVE_CLAUSE_MAP";
+  IfDefName += getFESpelling(FE).upper() + "_DIRECTIVE_CLAUSE_MAP";
   IfDefScope Scope(IfDefName, OS);
 
   OS << "\n";
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp
index 83c0330f7d3eb..e4eaa0941974e 100644
--- a/llvm/utils/TableGen/CodeEmitterGen.cpp
+++ b/llvm/utils/TableGen/CodeEmitterGen.cpp
@@ -153,20 +153,19 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
   // If the source operand has a custom encoder, use it.
   if (!EncoderMethodName.empty()) {
     if (UseAPInt) {
-      Case += "      " + EncoderMethodName + "(MI, " + utostr(OpIdx);
+      Case += "      " + EncoderMethodName + "(MI, " + Twine(OpIdx);
       Case += ", op";
     } else {
-      Case += "      op = " + EncoderMethodName + "(MI, " + utostr(OpIdx);
+      Case += "      op = " + EncoderMethodName + "(MI, " + Twine(OpIdx);
     }
     Case += ", Fixups, STI);\n";
   } else {
     if (UseAPInt) {
-      Case +=
-          "      getMachineOpValue(MI, MI.getOperand(" + utostr(OpIdx) + ")";
+      Case += "      getMachineOpValue(MI, MI.getOperand(" + Twine(OpIdx) + ")";
       Case += ", op, Fixups, STI";
     } else {
-      Case += "      op = getMachineOpValue(MI, MI.getOperand(" +
-              utostr(OpIdx) + ")";
+      Case += "      op = getMachineOpValue(MI, MI.getOperand(" + Twine(OpIdx) +
+              ")";
       Case += ", Fixups, STI";
     }
     Case += ");\n";
@@ -228,19 +227,16 @@ bool CodeEmitterGen::addCodeToMergeInOperand(const Record *R,
     unsigned LoBit = BeginVarBit - N + 1;
     unsigned HiBit = LoBit + N;
     unsigned LoInstBit = BeginInstBit - N + 1;
+    int DeltaBits = HiBit - LoBit;
     BitOffset = LoInstBit;
     if (UseAPInt) {
-      std::string ExtractStr;
       if (N >= 64) {
-        ExtractStr = "op.extractBits(" + itostr(HiBit - LoBit) + ", " +
-                     itostr(LoBit) + ")";
-        Case += "      Value.insertBits(" + ExtractStr + ", " +
-                itostr(LoInstBit) + ");\n";
+        Case += "      Value.insertBits(op.extractBits(" + Twine(DeltaBits) +
+                ", " + Twine(LoBit) + "), " + Twine(LoInstBit) + ");\n";
       } else {
-        ExtractStr = "op.extractBitsAsZExtValue(" + itostr(HiBit - LoBit) +
-                     ", " + itostr(LoBit) + ")";
-        Case += "      Value.insertBits(" + ExtractStr + ", " +
-                itostr(LoInstBit) + ", " + itostr(HiBit - LoBit) + ");\n";
+        Case += "      Value.insertBits(op.extractBitsAsZExtValue(" +
+                Twine(DeltaBits) + ", " + Twine(LoBit) + "), " +
+                Twine(LoInstBit) + ", " + Twine(DeltaBits) + ");\n";
       }
     } else {
       uint64_t OpMask = ~(uint64_t)0 >> (64 - N);
@@ -309,7 +305,7 @@ CodeEmitterGen::getInstructionCases(const Record *R,
               "      case " + itostr(DefaultMode) + ": InstBitsByHw = InstBits";
         } else {
           Case += "      case " + itostr(ModeId) +
-                  ": InstBitsByHw = InstBits_" + HWM.getMode(ModeId).Name.str();
+                  ": InstBitsByHw = InstBits_" + HWM.getMode(ModeId).Name;
         }
         Case += "; break;\n";
       }
@@ -380,13 +376,8 @@ void CodeEmitterGen::addInstructionCasesForEncoding(
   }
 
   StringRef PostEmitter = R->getValueAsString("PostEncoderMethod");
-  if (!PostEmitter.empty()) {
-    Case += "      Value = ";
-    Case += PostEmitter;
-    Case += "(MI, Value";
-    Case += ", STI";
-    Case += ");\n";
-  }
+  if (!PostEmitter.empty())
+    Case += "      Value = " + PostEmitter + "(MI, Value, STI);\n";
 }
 
 static void emitInstBits(raw_ostream &OS, const APInt &Bits) {
diff --git a/llvm/utils/TableGen/CodeGenMapTable.cpp b/llvm/utils/TableGen/CodeGenMapTable.cpp
index eccd1aff422d0..3ffbf59c93008 100644
--- a/llvm/utils/TableGen/CodeGenMapTable.cpp
+++ b/llvm/utils/TableGen/CodeGenMapTable.cpp
@@ -377,8 +377,7 @@ unsigned MapTableEmitter::emitBinSearchTable(raw_ostream &OS) {
     for (const Record *ColInstr : ColInstrs) {
       if (ColInstr) {
         RelExists = true;
-        OutStr += ", ";
-        OutStr += ColInstr->getName();
+        OutStr += ", " + ColInstr->getName();
       } else {
         OutStr += ", (uint16_t)-1U";
       }
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index f03cbd9a170e2..604cd98782585 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -1028,16 +1028,13 @@ std::string TreePredicateFn::getPredCode() const {
     }
 
     int64_t MinAlign = getMinAlignment();
-    if (MinAlign > 0) {
-      Code += "if (cast<MemSDNode>(N)->getAlign() < Align(";
-      Code += utostr(MinAlign);
-      Code += "))\nreturn false;\n";
-    }
+    if (MinAlign > 0)
+      Code += "if (cast<MemSDNode>(N)->getAlign() < Align(" + Twine(MinAlign) +
+              "))\nreturn false;\n";
 
     if (const Record *MemoryVT = getMemoryVT())
-      Code += ("if (cast<MemSDNode>(N)->getMemoryVT() != MVT::" +
-               MemoryVT->getName() + ") return false;\n")
-                  .str();
+      Code += "if (cast<MemSDNode>(N)->getMemoryVT() != MVT::" +
+              MemoryVT->getName() + ") return false;\n";
   }
 
   if (isAtomic() && isAtomicOrderingMonotonic())
@@ -1100,10 +1097,9 @@ std::string TreePredicateFn::getPredCode() const {
     StringRef SDNodeName = isLoad() ? "LoadSDNode" : "StoreSDNode";
 
     if (isUnindexed())
-      Code += ("if (cast<" + SDNodeName +
-               ">(N)->getAddressingMode() != ISD::UNINDEXED) "
-               "return false;\n")
-                  .str();
+      Code += "if (cast<" + SDNodeName +
+              ">(N)->getAddressingMode() != ISD::UNINDEXED) "
+              "return false;\n";
 
     if (isLoad()) {
       if ((isNonExtLoad() + isAnyExtLoad() + isSignExtLoad() +
@@ -1137,10 +1133,9 @@ std::string TreePredicateFn::getPredCode() const {
     }
 
     if (const Record *ScalarMemoryVT = getScalarMemoryVT())
-      Code += ("if (cast<" + SDNodeName +
-               ">(N)->getMemoryVT().getScalarType() != MVT::" +
-               ScalarMemoryVT->getName() + ") return false;\n")
-                  .str();
+      Code += "if (cast<" + SDNodeName +
+              ">(N)->getMemoryVT().getScalarType() != MVT::" +
+              ScalarMemoryVT->getName() + ") return false;\n";
   }
 
   if (hasNoUse())
@@ -1148,8 +1143,8 @@ std::string TreePredicateFn::getPredCode() const {
   if (hasOneUse())
     Code += "if (!N->hasNUsesOfValue(1, 0)) return false;\n";
 
-  std::string PredicateCode =
-      PatFragRec->getRecord()->getValueAsString("PredicateCode").str();
+  StringRef PredicateCode =
+      PatFragRec->getRecord()->getValueAsString("PredicateCode");
 
   Code += PredicateCode;
 
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index 0f9cd039b2521..b880c3a6d376d 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -1413,10 +1413,8 @@ CodeGenSubRegIndex *CodeGenRegBank::getConcatSubRegIndex(
   std::string Name = Parts.front()->getName();
   const unsigned UnknownSize = (uint16_t)-1;
 
-  for (const CodeGenSubRegIndex *Part : ArrayRef(Parts).drop_front()) {
-    Name += '_';
-    Name += Part->getName();
-  }
+  for (const CodeGenSubRegIndex *Part : ArrayRef(Parts).drop_front())
+    Name += "_" + Part->getName();
 
   Idx = createSubRegIndex(Name, Parts.front()->getNamespace());
   Idx->ConcatenationOf.assign(Parts.begin(), Parts.end());
diff --git a/llvm/utils/TableGen/DAGISelMatcherGen.cpp b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
index aec9a8796870b..ed9472403893a 100644
--- a/llvm/utils/TableGen/DAGISelMatcherGen.cpp
+++ b/llvm/utils/TableGen/DAGISelMatcherGen.cpp
@@ -307,10 +307,8 @@ void MatcherGen::EmitOperatorMatchCode(const TreePatternNode &N,
     // "MY_PAT:op1:op2". We should already have validated that the uses are
     // consistent.
     std::string PatternName = N.getOperator()->getName().str();
-    for (const TreePatternNode &Child : N.children()) {
-      PatternName += ":";
-      PatternName += Child.getName();
-    }
+    for (const TreePatternNode &Child : N.children())
+      PatternName += ":" + Child.getName();
 
     if (recordUniqueNode(PatternName)) {
       auto NodeAndOpNum = std::pair(&N, NextRecordedOperandNo - 1);
@@ -467,11 +465,9 @@ bool MatcherGen::recordUniqueNode(ArrayRef<std::string> Names) {
   if (Entry == 0) {
     // If it is a named node, we must emit a 'Record' opcode.
     std::string WhatFor;
-    for (const std::string &Name : Names) {
-      if (!WhatFor.empty())
-        WhatFor += ',';
-      WhatFor += "$" + Name;
-    }
+    ListSeparator LS(",");
+    for (const std::string &Name : Names)
+      WhatFor += Twine(LS) + "$" + Name;
     AddMatcher(new RecordMatcher(WhatFor, NextRecordedOperandNo));
     Entry = ++NextRecordedOperandNo;
     NewRecord = true;
diff --git a/llvm/utils/TableGen/FastISelEmitter.cpp b/llvm/utils/TableGen/FastISelEmitter.cpp
index a8b6f79c176a7..14cc19e82a0cd 100644
--- a/llvm/utils/TableGen/FastISelEmitter.cpp
+++ b/llvm/utils/TableGen/FastISelEmitter.cpp
@@ -428,8 +428,7 @@ static std::string PhysRegForNode(const TreePatternNode &Op,
 
   PhysReg += cast<StringInit>(OpLeafRec->getValue("Namespace")->getValue())
                  ->getValue();
-  PhysReg += "::";
-  PhysReg += Target.getRegBank().getReg(OpLeafRec)->getName();
+  PhysReg += "::" + Target.getRegBank().getReg(OpLeafRec)->getName();
   return PhysReg;
 }
 
diff --git a/llvm/utils/TableGen/GlobalISelEmitter.cpp b/llvm/utils/TableGen/GlobalISelEmitter.cpp
index d516879f088d3..cdd779d100cf9 100644
--- a/llvm/utils/TableGen/GlobalISelEmitter.cpp
+++ b/llvm/utils/TableGen/GlobalISelEmitter.cpp
@@ -90,12 +90,10 @@ namespace {
 
 static std::string explainPredicates(const TreePatternNode &N) {
   std::string Explanation;
-  StringRef Separator = "";
+  ListSeparator LS;
   for (const TreePredicateCall &Call : N.getPredicateCalls()) {
     const TreePredicateFn &P = Call.Fn;
-    Explanation +=
-        (Separator + P.getOrigPatFragRecord()->getRecord()->getName()).str();
-    Separator = ", ";
+    Explanation += Twine(LS) + P.getOrigPatFragRecord()->getRecord()->getName();
 
     if (P.isAlwaysTrue())
       Explanation += " always-true";
@@ -120,22 +118,21 @@ static std::string explainPredicates(const TreePatternNode &N) {
       Explanation += " truncstore";
 
     if (const Record *VT = P.getMemoryVT())
-      Explanation += (" MemVT=" + VT->getName()).str();
+      Explanation += " MemVT=" + VT->getName();
     if (const Record *VT = P.getScalarMemoryVT())
-      Explanation += (" ScalarVT(MemVT)=" + VT->getName()).str();
+      Explanation += " ScalarVT(MemVT)=" + VT->getName();
 
     if (const ListInit *AddrSpaces = P.getAddressSpaces()) {
       raw_string_ostream OS(Explanation);
       OS << " AddressSpaces=[";
 
-      StringRef AddrSpaceSeparator;
+      ListSeparator AS;
       for (const Init *Val : AddrSpaces->getElements()) {
         const IntInit *IntVal = dyn_cast<IntInit>(Val);
         if (!IntVal)
           continue;
 
-        OS << AddrSpaceSeparator << IntVal->getValue();
-        AddrSpaceSeparator = ", ";
+        OS << AS << IntVal->getValue();
       }
 
       OS << ']';
@@ -194,7 +191,7 @@ static Error failedImport(const Twine &Reason) {
 
 static Error isTrivialOperatorNode(const TreePatternNode &N) {
   std::string Explanation;
-  std::string Separator;
+  ListSeparator LS;
 
   bool HasUnsupportedPredicate = false;
   for (const TreePredicateCall &Call : N.getPredicateCalls()) {
@@ -255,11 +252,9 @@ static Error isTrivialOperatorNode(const TreePatternNode &N) {
       continue;
 
     HasUnsupportedPredicate = true;
-    Explanation = Separator + "Has a predicate (" + explainPredicates(N) + ")";
-    Separator = ", ";
-    Explanation += (Separator + "first-failing:" +
-                    Predicate.getOrigPatFragRecord()->getRecord()->getName())
-                       .str();
+    Explanation += Twine(LS) + "Has a predicate (" + explainPredicates(N) + ")";
+    Explanation += Twine(LS) + "first-failing:" +
+                   Predicate.getOrigPatFragRecord()->getRecord()->getName();
     break;
   }
 
@@ -996,10 +991,8 @@ Error GlobalISelEmitter::importChildMatcher(
     // The "name" of a non-leaf complex pattern (MY_PAT $op1, $op2) is
     // "MY_PAT:op1:op2" and the ones with same "name" represent same operand.
     std::string PatternName = SrcChild.getOperator()->getName().str();
-    for (const TreePatternNode &Child : SrcChild.children()) {
-      PatternName += ":";
-      PatternName += Child.getName();
-    }
+    for (const TreePatternNode &Child : SrcChild.children())
+      PatternName += ":" + Child.getName();
     SrcChildName = PatternName;
   }
 
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index f240cab040caa..5b91af9776f14 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -173,9 +173,8 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
         Res += "|(1<<MCOI::BranchTarget)";
 
       // Fill in operand type.
-      Res += ", ";
       assert(!Op.OperandType.empty() && "Invalid operand type.");
-      Res += Op.OperandType;
+      Res += ", " + Op.OperandType;
 
       // Fill in constraint info.
       Res += ", ";
@@ -186,7 +185,7 @@ InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
         Res += "MCOI_EARLY_CLOBBER";
       } else {
         assert(Constraint.isTied());
-        Res += "MCOI_TIED_TO(" + utostr(Constraint.getTiedOperand()) + ")";
+        Res += "MCOI_TIED_TO(" + Twine(Constraint.getTiedOperand()) + ")";
       }
 
       Result.push_back(Res);
@@ -616,7 +615,7 @@ static std::string
 getNameForFeatureBitset(ArrayRef<const Record *> FeatureBitset) {
   std::string Name = "CEFBS";
   for (const Record *Feature : FeatureBitset)
-    Name += ("_" + Feature->getName()).str();
+    Name += "_" + Feature->getName();
   return Name;
 }
 
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp
index 9c67424615551..71d573724ab10 100644
--- a/llvm/utils/TableGen/SubtargetEmitter.cpp
+++ b/llvm/utils/TableGen/SubtargetEmitter.cpp
@@ -428,7 +428,7 @@ void SubtargetEmitter::formItineraryStageString(const std::string &Name,
 
     // Form string as ,{ cycles, u1 | u2 | ... | un, timeinc, kind }
     int Cycles = Stage->getValueAsInt("Cycles");
-    ItinString += "  { " + itostr(Cycles) + ", ";
+    ItinString += "  { " + Twine(Cycles) + ", ";
 
     // Get unit list
     ConstRecVec UnitList = Stage->getValueAsListOfDefs("Units");
@@ -436,16 +436,16 @@ void SubtargetEmitter::formItineraryStageString(const std::string &Name,
     // For each unit
     for (unsigned J = 0, M = UnitList.size(); J < M;) {
       // Add name and bitwise or
-      ItinString += Name + "FU::" + UnitList[J]->getName().str();
+      ItinString += Name + "FU::" + UnitList[J]->getName();
       if (++J < M)
         ItinString += " | ";
     }
 
     int TimeInc = Stage->getValueAsInt("TimeInc");
-    ItinString += ", " + itostr(TimeInc);
+    ItinString += ", " + Twine(TimeInc);
 
     int Kind = Stage->getValueAsInt("Kind");
-    ItinString += ", (llvm::InstrStage::ReservationKinds)" + itostr(Kind);
+    ItinString += ", (llvm::InstrStage::ReservationKinds)" + Twine(Kind);
 
     // Close off stage
     ItinString += " }";
@@ -470,8 +470,7 @@ void SubtargetEmitter::formItineraryOperandCycleString(
   ListSeparator LS;
   for (int OCycle : OperandCycleList) {
     // Next operand cycle
-    ItinString += LS;
-    ItinString += "  " + itostr(OCycle);
+    ItinString += Twine(LS) + "  " + itostr(OCycle);
   }
 }
 
@@ -483,14 +482,10 @@ void SubtargetEmitter::formItineraryBypassString(const std::string &Name,
   unsigned N = BypassList.size();
   unsigned I = 0;
   ListSeparator LS;
-  for (; I < N; ++I) {
-    ItinString += LS;
-    ItinString += Name + "Bypass::" + BypassList[I]->getName().str();
-  }
-  for (; I < NOperandCycles; ++I) {
-    ItinString += LS;
-    ItinString += " 0";
-  }
+  for (; I < N; ++I)
+    ItinString += Twine(LS) + Name + "Bypass::" + BypassList[I]->getName();
+  for (; I < NOperandCycles; ++I)
+    ItinString += LS + " 0";
 }
 
 //



More information about the llvm-commits mailing list