Skip to content

Commit 8db434a

Browse files
[bugpoint] Avoid repeated hash lookups (NFC) (#133616)
1 parent 825ecfe commit 8db434a

File tree

15 files changed

+41
-81
lines changed

15 files changed

+41
-81
lines changed

llvm/tools/bugpoint/CrashDebugger.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,7 @@ bool ReduceCrashingFunctionAttributes::TestFuncAttrs(
390390

391391
// Pass along the set of attributes that caused the crash.
392392
Attrs.clear();
393-
for (Attribute A : NewAttrs.getFnAttrs()) {
394-
Attrs.push_back(A);
395-
}
393+
llvm::append_range(Attrs, NewAttrs.getFnAttrs());
396394
return true;
397395
}
398396
return false;
@@ -800,8 +798,7 @@ bool ReduceCrashingInstructions::TestInsts(
800798
// Make sure to use instruction pointers that point into the now-current
801799
// module, and that they don't include any deleted blocks.
802800
Insts.clear();
803-
for (Instruction *Inst : Instructions)
804-
Insts.push_back(Inst);
801+
llvm::append_range(Insts, Instructions);
805802
return true;
806803
}
807804
// It didn't crash, try something else.
@@ -870,8 +867,7 @@ bool ReduceCrashingMetadata::TestInsts(std::vector<Instruction *> &Insts) {
870867
// Make sure to use instruction pointers that point into the now-current
871868
// module, and that they don't include any deleted blocks.
872869
Insts.clear();
873-
for (Instruction *I : Instructions)
874-
Insts.push_back(I);
870+
llvm::append_range(Insts, Instructions);
875871
return true;
876872
}
877873
// It didn't crash, try something else.
@@ -1211,8 +1207,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) {
12111207
assert(Fn && "Could not find function?");
12121208

12131209
std::vector<Attribute> Attrs;
1214-
for (Attribute A : Fn->getAttributes().getFnAttrs())
1215-
Attrs.push_back(A);
1210+
llvm::append_range(Attrs, Fn->getAttributes().getFnAttrs());
12161211

12171212
OldSize += Attrs.size();
12181213
Expected<bool> Result =
@@ -1319,8 +1314,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) {
13191314
// contribute to the crash, bisect the operands of the remaining ones
13201315
std::vector<const MDNode *> NamedMDOps;
13211316
for (auto &NamedMD : BD.getProgram().named_metadata())
1322-
for (auto *op : NamedMD.operands())
1323-
NamedMDOps.push_back(op);
1317+
llvm::append_range(NamedMDOps, NamedMD.operands());
13241318
Expected<bool> Result =
13251319
ReduceCrashingNamedMDOps(BD, TestFn).reduceList(NamedMDOps);
13261320
if (Error E = Result.takeError())

llvm/tools/bugpoint/OptimizerDriver.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ bool BugDriver::runPasses(Module &Program,
203203
} else
204204
Args.push_back(tool);
205205

206-
for (unsigned i = 0, e = OptArgs.size(); i != e; ++i)
207-
Args.push_back(OptArgs[i]);
206+
llvm::append_range(Args, OptArgs);
208207
// Pin to legacy PM since bugpoint has lots of infra and hacks revolving
209208
// around the legacy PM.
210209
Args.push_back("-bugpoint-enable-legacy-pm");

llvm/tools/bugpoint/ToolRunner.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,11 @@ Expected<int> LLI::ExecuteProgram(const std::string &Bitcode,
181181
}
182182

183183
// Add any extra LLI args.
184-
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
185-
LLIArgs.push_back(ToolArgs[i]);
184+
llvm::append_range(LLIArgs, ToolArgs);
186185

187186
LLIArgs.push_back(Bitcode);
188187
// Add optional parameters to the running program from Argv
189-
for (unsigned i = 0, e = Args.size(); i != e; ++i)
190-
LLIArgs.push_back(Args[i]);
188+
llvm::append_range(LLIArgs, Args);
191189

192190
outs() << "<lli>";
193191
outs().flush();
@@ -268,13 +266,11 @@ Error CustomCompiler::compileProgram(const std::string &Bitcode,
268266
std::vector<StringRef> ProgramArgs;
269267
ProgramArgs.push_back(CompilerCommand);
270268

271-
for (const auto &Arg : CompilerArgs)
272-
ProgramArgs.push_back(Arg);
269+
llvm::append_range(ProgramArgs, CompilerArgs);
273270
ProgramArgs.push_back(Bitcode);
274271

275272
// Add optional parameters to the running program from Argv
276-
for (const auto &Arg : CompilerArgs)
277-
ProgramArgs.push_back(Arg);
273+
llvm::append_range(ProgramArgs, CompilerArgs);
278274

279275
if (RunProgramWithTimeout(CompilerCommand, ProgramArgs, "", "", "", Timeout,
280276
MemoryLimit))
@@ -317,13 +313,11 @@ Expected<int> CustomExecutor::ExecuteProgram(
317313
std::vector<StringRef> ProgramArgs;
318314
ProgramArgs.push_back(ExecutionCommand);
319315

320-
for (std::size_t i = 0; i < ExecutorArgs.size(); ++i)
321-
ProgramArgs.push_back(ExecutorArgs[i]);
316+
llvm::append_range(ProgramArgs, ExecutorArgs);
322317
ProgramArgs.push_back(Bitcode);
323318

324319
// Add optional parameters to the running program from Argv
325-
for (unsigned i = 0, e = Args.size(); i != e; ++i)
326-
ProgramArgs.push_back(Args[i]);
320+
llvm::append_range(ProgramArgs, Args);
327321

328322
return RunProgramWithTimeout(ExecutionCommand, ProgramArgs, InputFile,
329323
OutputFile, OutputFile, Timeout, MemoryLimit);
@@ -447,8 +441,7 @@ Expected<CC::FileType> LLC::OutputCode(const std::string &Bitcode,
447441
LLCArgs.push_back(LLCPath);
448442

449443
// Add any extra LLC args.
450-
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
451-
LLCArgs.push_back(ToolArgs[i]);
444+
llvm::append_range(LLCArgs, ToolArgs);
452445

453446
LLCArgs.push_back("-o");
454447
LLCArgs.push_back(OutputAsmFile); // Output to the Asm file
@@ -563,17 +556,15 @@ Expected<int> JIT::ExecuteProgram(const std::string &Bitcode,
563556
JITArgs.push_back("-force-interpreter=false");
564557

565558
// Add any extra LLI args.
566-
for (unsigned i = 0, e = ToolArgs.size(); i != e; ++i)
567-
JITArgs.push_back(ToolArgs[i]);
559+
llvm::append_range(JITArgs, ToolArgs);
568560

569561
for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
570562
JITArgs.push_back("-load");
571563
JITArgs.push_back(SharedLibs[i]);
572564
}
573565
JITArgs.push_back(Bitcode);
574566
// Add optional parameters to the running program from Argv
575-
for (unsigned i = 0, e = Args.size(); i != e; ++i)
576-
JITArgs.push_back(Args[i]);
567+
llvm::append_range(JITArgs, Args);
577568

578569
outs() << "<jit>";
579570
outs().flush();
@@ -674,8 +665,7 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
674665
// most likely -L and -l options that need to come before other libraries but
675666
// after the source. Other options won't be sensitive to placement on the
676667
// command line, so this should be safe.
677-
for (unsigned i = 0, e = ArgsForCC.size(); i != e; ++i)
678-
CCArgs.push_back(ArgsForCC[i]);
668+
llvm::append_range(CCArgs, ArgsForCC);
679669

680670
CCArgs.push_back("-lm"); // Hard-code the math library...
681671
CCArgs.push_back("-O2"); // Optimize the program a bit...
@@ -725,8 +715,7 @@ Expected<int> CC::ExecuteProgram(const std::string &ProgramFile,
725715
}
726716

727717
// Add optional parameters to the running program from Argv
728-
for (unsigned i = 0, e = Args.size(); i != e; ++i)
729-
ProgramArgs.push_back(Args[i]);
718+
llvm::append_range(ProgramArgs, Args);
730719

731720
// Now that we have a binary, run it!
732721
outs() << "<program>";
@@ -823,8 +812,7 @@ Error CC::MakeSharedObject(const std::string &InputFile, FileType fileType,
823812
// most likely -L and -l options that need to come before other libraries but
824813
// after the source. Other options won't be sensitive to placement on the
825814
// command line, so this should be safe.
826-
for (unsigned i = 0, e = ArgsForCC.size(); i != e; ++i)
827-
CCArgs.push_back(ArgsForCC[i]);
815+
llvm::append_range(CCArgs, ArgsForCC);
828816

829817
outs() << "<CC>";
830818
outs().flush();

llvm/tools/dsymutil/Reproducer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ Reproducer::~Reproducer() = default;
3636
ReproducerGenerate::ReproducerGenerate(std::error_code &EC, int Argc,
3737
char **Argv, bool GenerateOnExit)
3838
: Root(createReproducerDir(EC)), GenerateOnExit(GenerateOnExit) {
39-
for (int I = 0; I < Argc; ++I)
40-
Args.push_back(Argv[I]);
39+
llvm::append_range(Args, ArrayRef(Argv, Argc));
4140
if (!Root.empty())
4241
FC = std::make_shared<FileCollector>(Root, Root);
4342
VFS = FileCollector::createCollectorVFS(vfs::getRealFileSystem(), FC);

llvm/tools/llvm-cov/CodeCoverage.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
588588
// Invoke the demangler.
589589
std::vector<StringRef> ArgsV;
590590
ArgsV.reserve(ViewOpts.DemanglerOpts.size());
591-
for (StringRef Arg : ViewOpts.DemanglerOpts)
592-
ArgsV.push_back(Arg);
591+
llvm::append_range(ArgsV, ViewOpts.DemanglerOpts);
593592
std::optional<StringRef> Redirects[] = {
594593
InputPath.str(), OutputPath.str(), {""}};
595594
std::string ErrMsg;

llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ int llvm_debuginfod_main(int argc, char **argv, const llvm::ToolContext &) {
126126
parseArgs(argc, argv);
127127

128128
SmallVector<StringRef, 1> Paths;
129-
for (const std::string &Path : ScanPaths)
130-
Paths.push_back(Path);
129+
llvm::append_range(Paths, ScanPaths);
131130

132131
DefaultThreadPool Pool(hardware_concurrency(MaxConcurrency));
133132
DebuginfodLog Log;

llvm/tools/llvm-libtool-darwin/DependencyInfo.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ class DependencyInfo {
5050
// Sort the input by its names.
5151
std::vector<llvm::StringRef> InputNames;
5252
InputNames.reserve(Inputs.size());
53-
for (const auto &F : Inputs)
54-
InputNames.push_back(F);
53+
llvm::append_range(InputNames, Inputs);
5554
llvm::sort(InputNames);
5655

5756
for (const auto &In : InputNames)

llvm/tools/llvm-lipo/llvm-lipo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ static Config parseLipoOptions(ArrayRef<const char *> ArgsArr) {
249249

250250
switch (ActionArgs[0]->getOption().getID()) {
251251
case LIPO_verify_arch:
252-
for (auto A : InputArgs.getAllArgValues(LIPO_verify_arch))
253-
C.VerifyArchList.push_back(A);
252+
llvm::append_range(C.VerifyArchList,
253+
InputArgs.getAllArgValues(LIPO_verify_arch));
254254
if (C.VerifyArchList.empty())
255255
reportError(
256256
"verify_arch requires at least one architecture to be specified");

llvm/tools/llvm-lto2/llvm-lto2.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ static int run(int argc, char **argv) {
326326

327327
Conf.OptLevel = OptLevel - '0';
328328
Conf.Freestanding = EnableFreestanding;
329-
for (auto &PluginFN : PassPlugins)
330-
Conf.PassPlugins.push_back(PluginFN);
329+
llvm::append_range(Conf.PassPlugins, PassPlugins);
331330
if (auto Level = CodeGenOpt::parseLevel(CGOptLevel)) {
332331
Conf.CGOptLevel = *Level;
333332
} else {

llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,8 +1538,7 @@ int main(int Argc, const char **Argv) {
15381538

15391539
// Initialize the filters for LinePrinter.
15401540
auto propagate = [&](auto &Target, auto &Reference) {
1541-
for (std::string &Option : Reference)
1542-
Target.push_back(Option);
1541+
llvm::append_range(Target, Reference);
15431542
};
15441543

15451544
propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);

llvm/tools/llvm-rc/llvm-rc.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts,
266266
}
267267
}
268268
}
269-
for (const auto &S : Opts.PreprocessArgs)
270-
Args.push_back(S);
269+
llvm::append_range(Args, Opts.PreprocessArgs);
271270
Args.push_back(Src);
272271
Args.push_back("-o");
273272
Args.push_back(Dst);

llvm/tools/llvm-xray/xray-stacks.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,11 @@ static StackDuration mergeStackDuration(const StackDuration &Left,
267267
Data.IntermediateDurations.reserve(Left.IntermediateDurations.size() +
268268
Right.IntermediateDurations.size());
269269
// Aggregate the durations.
270-
for (auto duration : Left.TerminalDurations)
271-
Data.TerminalDurations.push_back(duration);
272-
for (auto duration : Right.TerminalDurations)
273-
Data.TerminalDurations.push_back(duration);
274-
275-
for (auto duration : Left.IntermediateDurations)
276-
Data.IntermediateDurations.push_back(duration);
277-
for (auto duration : Right.IntermediateDurations)
278-
Data.IntermediateDurations.push_back(duration);
270+
llvm::append_range(Data.TerminalDurations, Left.TerminalDurations);
271+
llvm::append_range(Data.TerminalDurations, Right.TerminalDurations);
272+
273+
llvm::append_range(Data.IntermediateDurations, Left.IntermediateDurations);
274+
llvm::append_range(Data.IntermediateDurations, Right.IntermediateDurations);
279275
return Data;
280276
}
281277

@@ -506,8 +502,7 @@ class StackTrie {
506502
for (const auto &RootNodeRange :
507503
make_range(map_iterator(Roots.begin(), MapValueFn),
508504
map_iterator(Roots.end(), MapValueFn))) {
509-
for (auto *RootNode : RootNodeRange)
510-
RootValues.push_back(RootNode);
505+
llvm::append_range(RootValues, RootNodeRange);
511506
}
512507

513508
print(OS, FN, RootValues);
@@ -565,8 +560,7 @@ class StackTrie {
565560
while (!S.empty()) {
566561
auto *Top = S.pop_back_val();
567562
printSingleStack<AggType>(OS, FN, ReportThread, ThreadId, Top);
568-
for (const auto *C : Top->Callees)
569-
S.push_back(C);
563+
llvm::append_range(S, Top->Callees);
570564
}
571565
}
572566
}
@@ -641,8 +635,7 @@ class StackTrie {
641635
TopStacksByCount.pop_back();
642636
}
643637
}
644-
for (const auto *C : Top->Callees)
645-
S.push_back(C);
638+
llvm::append_range(S, Top->Callees);
646639
}
647640
}
648641

llvm/tools/lto/lto.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,7 @@ void lto_set_debug_options(const char *const *options, int number) {
475475
// Need to put each suboption in a null-terminated string before passing to
476476
// parseCommandLineOptions().
477477
std::vector<std::string> Options;
478-
for (int i = 0; i < number; ++i)
479-
Options.push_back(options[i]);
478+
llvm::append_range(Options, ArrayRef(options, number));
480479

481480
llvm::parseCommandLineOptions(Options);
482481
optionParsingState = OptParsingState::Early;
@@ -498,8 +497,7 @@ void lto_codegen_debug_options_array(lto_code_gen_t cg,
498497
assert(optionParsingState != OptParsingState::Early &&
499498
"early option processing already happened");
500499
SmallVector<StringRef, 4> Options;
501-
for (int i = 0; i < number; ++i)
502-
Options.push_back(options[i]);
500+
llvm::append_range(Options, ArrayRef(options, number));
503501
unwrap(cg)->setCodeGenDebugOptions(ArrayRef(Options));
504502
}
505503

llvm/tools/obj2yaml/elf2yaml.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,7 @@ ELFDumper<ELFT>::dumpSymtabShndxSection(const Elf_Shdr *Shdr) {
12661266
return EntriesOrErr.takeError();
12671267

12681268
S->Entries.emplace();
1269-
for (const Elf_Word &E : *EntriesOrErr)
1270-
S->Entries->push_back(E);
1269+
llvm::append_range(*S->Entries, *EntriesOrErr);
12711270
return S.release();
12721271
}
12731272

@@ -1490,8 +1489,7 @@ ELFDumper<ELFT>::dumpSymverSection(const Elf_Shdr *Shdr) {
14901489
return VersionsOrErr.takeError();
14911490

14921491
S->Entries.emplace();
1493-
for (const Elf_Half &E : *VersionsOrErr)
1494-
S->Entries->push_back(E);
1492+
llvm::append_range(*S->Entries, *VersionsOrErr);
14951493

14961494
return S.release();
14971495
}

llvm/tools/obj2yaml/macho2yaml.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,7 @@ void MachODumper::dumpFunctionStarts(std::unique_ptr<MachOYAML::Object> &Y) {
364364
MachOYAML::LinkEditData &LEData = Y->LinkEdit;
365365

366366
auto FunctionStarts = Obj.getFunctionStarts();
367-
for (auto Addr : FunctionStarts)
368-
LEData.FunctionStarts.push_back(Addr);
367+
llvm::append_range(LEData.FunctionStarts, FunctionStarts);
369368
}
370369

371370
void MachODumper::dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y) {
@@ -637,9 +636,7 @@ void MachODumper::dumpChainedFixups(std::unique_ptr<MachOYAML::Object> &Y) {
637636
assert(DC.dataoff < Obj.getData().size());
638637
assert(DC.dataoff + DC.datasize <= Obj.getData().size());
639638
const char *Bytes = Obj.getData().data() + DC.dataoff;
640-
for (size_t Idx = 0; Idx < DC.datasize; Idx++) {
641-
LEData.ChainedFixups.push_back(Bytes[Idx]);
642-
}
639+
llvm::append_range(LEData.ChainedFixups, ArrayRef(Bytes, DC.datasize));
643640
}
644641
break;
645642
}

0 commit comments

Comments
 (0)