llvm.org GIT mirror llvm / 18b1618
[tablegen] Avoid creating temporary strings If a method / function returns a StringRef but the variable is of type const std::string& a temporary string is created (StringRef has a cast operator to std::string), which is a suboptimal behavior. Differential revision: https://reviews.llvm.org/D34994 Test plan: make check-all git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307195 91177308-0d34-0410-b5e6-96231b3b80d8 Alexander Shaposhnikov 2 years ago
4 changed file(s) with 10 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
16901690 dumpStack(errs(), "\t\t");
16911691
16921692 for (unsigned i = 0; i < Opcodes.size(); ++i) {
1693 const std::string &Name = nameWithID(Opcodes[i]);
1694
1695 errs() << '\t' << Name << " ";
1693 errs() << '\t' << nameWithID(Opcodes[i]) << " ";
16961694 dumpBits(errs(),
16971695 getBitsField(*AllInstructions[Opcodes[i]]->TheDef, "Inst"));
16981696 errs() << '\n';
229229
230230 void SearchableTableEmitter::emitMapping(Record *InstanceClass,
231231 raw_ostream &OS) {
232 const std::string &TableName = InstanceClass->getName();
232 StringRef TableName = InstanceClass->getName();
233233 std::vector Items = Records.getAllDerivedDefinitions(TableName);
234234
235235 // Gather all the records we're going to need for this particular mapping.
264264 ++Idx;
265265 }
266266
267 OS << "#ifdef GET_" << StringRef(TableName).upper() << "_DECL\n";
268 OS << "#undef GET_" << StringRef(TableName).upper() << "_DECL\n";
267 OS << "#ifdef GET_" << TableName.upper() << "_DECL\n";
268 OS << "#undef GET_" << TableName.upper() << "_DECL\n";
269269
270270 // Next emit the enum containing the top-level names for use in C++ code if
271271 // requested
280280
281281 OS << "#endif\n\n";
282282
283 OS << "#ifdef GET_" << StringRef(TableName).upper() << "_IMPL\n";
284 OS << "#undef GET_" << StringRef(TableName).upper() << "_IMPL\n";
283 OS << "#ifdef GET_" << TableName.upper() << "_IMPL\n";
284 OS << "#undef GET_" << TableName.upper() << "_IMPL\n";
285285
286286 // The primary data table contains all the fields defined for this map.
287287 emitPrimaryTable(TableName, FieldNames, SearchFieldNames, SearchTables, Items,
374374 if (FUs.empty())
375375 continue;
376376
377 const std::string &Name = ProcModel.ItinsDef->getName();
377 StringRef Name = ProcModel.ItinsDef->getName();
378378 OS << "\n// Functional units for \"" << Name << "\"\n"
379379 << "namespace " << Name << "FU {\n";
380380
428428 if (!ProcModel.hasItineraries())
429429 continue;
430430
431 const std::string &Name = ProcModel.ItinsDef->getName();
431 StringRef Name = ProcModel.ItinsDef->getName();
432432
433433 ItinList.resize(SchedModels.numInstrSchedClasses());
434434 assert(ProcModel.ItinDefList.size() == ItinList.size() && "bad Itins");
545545 if (!ItinsDefSet.insert(ItinsDef).second)
546546 continue;
547547
548 // Get processor itinerary name
549 const std::string &Name = ItinsDef->getName();
550
551548 // Get the itinerary list for the processor.
552549 assert(ProcItinListsIter != ProcItinLists.end() && "bad iterator");
553550 std::vector &ItinList = *ProcItinListsIter;
561558 OS << "static const llvm::InstrItinerary ";
562559
563560 // Begin processor itinerary table
564 OS << Name << "[] = {\n";
561 OS << ItinsDef->getName() << "[] = {\n";
565562
566563 // For each itinerary class in CodeGenSchedClass::Index order.
567564 for (unsigned j = 0, M = ItinList.size(); j < M; ++j) {
366366 ++operandIndex;
367367 }
368368
369 const std::string &typeName = (*Operands)[operandIndex].Rec->getName();
369 StringRef typeName = (*Operands)[operandIndex].Rec->getName();
370370
371371 OperandEncoding encoding = encodingFromString(typeName, OpSize);
372372 // Adjust the encoding type for an operand based on the instruction.