Skip to content

[bugpoint] Avoid repeated hash lookups (NFC) #133616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions llvm/tools/bugpoint/CrashDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,7 @@ bool ReduceCrashingFunctionAttributes::TestFuncAttrs(

// Pass along the set of attributes that caused the crash.
Attrs.clear();
for (Attribute A : NewAttrs.getFnAttrs()) {
Attrs.push_back(A);
}
llvm::append_range(Attrs, NewAttrs.getFnAttrs());
return true;
}
return false;
Expand Down Expand Up @@ -800,8 +798,7 @@ bool ReduceCrashingInstructions::TestInsts(
// Make sure to use instruction pointers that point into the now-current
// module, and that they don't include any deleted blocks.
Insts.clear();
for (Instruction *Inst : Instructions)
Insts.push_back(Inst);
llvm::append_range(Insts, Instructions);
return true;
}
// It didn't crash, try something else.
Expand Down Expand Up @@ -870,8 +867,7 @@ bool ReduceCrashingMetadata::TestInsts(std::vector<Instruction *> &Insts) {
// Make sure to use instruction pointers that point into the now-current
// module, and that they don't include any deleted blocks.
Insts.clear();
for (Instruction *I : Instructions)
Insts.push_back(I);
llvm::append_range(Insts, Instructions);
return true;
}
// It didn't crash, try something else.
Expand Down Expand Up @@ -1211,8 +1207,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) {
assert(Fn && "Could not find function?");

std::vector<Attribute> Attrs;
for (Attribute A : Fn->getAttributes().getFnAttrs())
Attrs.push_back(A);
llvm::append_range(Attrs, Fn->getAttributes().getFnAttrs());

OldSize += Attrs.size();
Expected<bool> Result =
Expand Down Expand Up @@ -1319,8 +1314,7 @@ static Error DebugACrash(BugDriver &BD, BugTester TestFn) {
// contribute to the crash, bisect the operands of the remaining ones
std::vector<const MDNode *> NamedMDOps;
for (auto &NamedMD : BD.getProgram().named_metadata())
for (auto *op : NamedMD.operands())
NamedMDOps.push_back(op);
llvm::append_range(NamedMDOps, NamedMD.operands());
Expected<bool> Result =
ReduceCrashingNamedMDOps(BD, TestFn).reduceList(NamedMDOps);
if (Error E = Result.takeError())
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/bugpoint/OptimizerDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ bool BugDriver::runPasses(Module &Program,
} else
Args.push_back(tool);

for (unsigned i = 0, e = OptArgs.size(); i != e; ++i)
Args.push_back(OptArgs[i]);
llvm::append_range(Args, OptArgs);
// Pin to legacy PM since bugpoint has lots of infra and hacks revolving
// around the legacy PM.
Args.push_back("-bugpoint-enable-legacy-pm");
Expand Down
36 changes: 12 additions & 24 deletions llvm/tools/bugpoint/ToolRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,11 @@ Expected<int> LLI::ExecuteProgram(const std::string &Bitcode,
}

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

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

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

for (const auto &Arg : CompilerArgs)
ProgramArgs.push_back(Arg);
llvm::append_range(ProgramArgs, CompilerArgs);
ProgramArgs.push_back(Bitcode);

// Add optional parameters to the running program from Argv
for (const auto &Arg : CompilerArgs)
ProgramArgs.push_back(Arg);
llvm::append_range(ProgramArgs, CompilerArgs);

if (RunProgramWithTimeout(CompilerCommand, ProgramArgs, "", "", "", Timeout,
MemoryLimit))
Expand Down Expand Up @@ -317,13 +313,11 @@ Expected<int> CustomExecutor::ExecuteProgram(
std::vector<StringRef> ProgramArgs;
ProgramArgs.push_back(ExecutionCommand);

for (std::size_t i = 0; i < ExecutorArgs.size(); ++i)
ProgramArgs.push_back(ExecutorArgs[i]);
llvm::append_range(ProgramArgs, ExecutorArgs);
ProgramArgs.push_back(Bitcode);

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

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

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

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

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

for (unsigned i = 0, e = SharedLibs.size(); i != e; ++i) {
JITArgs.push_back("-load");
JITArgs.push_back(SharedLibs[i]);
}
JITArgs.push_back(Bitcode);
// Add optional parameters to the running program from Argv
for (unsigned i = 0, e = Args.size(); i != e; ++i)
JITArgs.push_back(Args[i]);
llvm::append_range(JITArgs, Args);

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

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

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

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

outs() << "<CC>";
outs().flush();
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/dsymutil/Reproducer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ Reproducer::~Reproducer() = default;
ReproducerGenerate::ReproducerGenerate(std::error_code &EC, int Argc,
char **Argv, bool GenerateOnExit)
: Root(createReproducerDir(EC)), GenerateOnExit(GenerateOnExit) {
for (int I = 0; I < Argc; ++I)
Args.push_back(Argv[I]);
llvm::append_range(Args, ArrayRef(Argv, Argc));
if (!Root.empty())
FC = std::make_shared<FileCollector>(Root, Root);
VFS = FileCollector::createCollectorVFS(vfs::getRealFileSystem(), FC);
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-cov/CodeCoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,7 @@ void CodeCoverageTool::demangleSymbols(const CoverageMapping &Coverage) {
// Invoke the demangler.
std::vector<StringRef> ArgsV;
ArgsV.reserve(ViewOpts.DemanglerOpts.size());
for (StringRef Arg : ViewOpts.DemanglerOpts)
ArgsV.push_back(Arg);
llvm::append_range(ArgsV, ViewOpts.DemanglerOpts);
std::optional<StringRef> Redirects[] = {
InputPath.str(), OutputPath.str(), {""}};
std::string ErrMsg;
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-debuginfod/llvm-debuginfod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ int llvm_debuginfod_main(int argc, char **argv, const llvm::ToolContext &) {
parseArgs(argc, argv);

SmallVector<StringRef, 1> Paths;
for (const std::string &Path : ScanPaths)
Paths.push_back(Path);
llvm::append_range(Paths, ScanPaths);

DefaultThreadPool Pool(hardware_concurrency(MaxConcurrency));
DebuginfodLog Log;
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-libtool-darwin/DependencyInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class DependencyInfo {
// Sort the input by its names.
std::vector<llvm::StringRef> InputNames;
InputNames.reserve(Inputs.size());
for (const auto &F : Inputs)
InputNames.push_back(F);
llvm::append_range(InputNames, Inputs);
llvm::sort(InputNames);

for (const auto &In : InputNames)
Expand Down
4 changes: 2 additions & 2 deletions llvm/tools/llvm-lipo/llvm-lipo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ static Config parseLipoOptions(ArrayRef<const char *> ArgsArr) {

switch (ActionArgs[0]->getOption().getID()) {
case LIPO_verify_arch:
for (auto A : InputArgs.getAllArgValues(LIPO_verify_arch))
C.VerifyArchList.push_back(A);
llvm::append_range(C.VerifyArchList,
InputArgs.getAllArgValues(LIPO_verify_arch));
if (C.VerifyArchList.empty())
reportError(
"verify_arch requires at least one architecture to be specified");
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-lto2/llvm-lto2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,7 @@ static int run(int argc, char **argv) {

Conf.OptLevel = OptLevel - '0';
Conf.Freestanding = EnableFreestanding;
for (auto &PluginFN : PassPlugins)
Conf.PassPlugins.push_back(PluginFN);
llvm::append_range(Conf.PassPlugins, PassPlugins);
if (auto Level = CodeGenOpt::parseLevel(CGOptLevel)) {
Conf.CGOptLevel = *Level;
} else {
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-pdbutil/llvm-pdbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1538,8 +1538,7 @@ int main(int Argc, const char **Argv) {

// Initialize the filters for LinePrinter.
auto propagate = [&](auto &Target, auto &Reference) {
for (std::string &Option : Reference)
Target.push_back(Option);
llvm::append_range(Target, Reference);
};

propagate(opts::Filters.ExcludeTypes, opts::pretty::ExcludeTypes);
Expand Down
3 changes: 1 addition & 2 deletions llvm/tools/llvm-rc/llvm-rc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ void preprocess(StringRef Src, StringRef Dst, const RcOptions &Opts,
}
}
}
for (const auto &S : Opts.PreprocessArgs)
Args.push_back(S);
llvm::append_range(Args, Opts.PreprocessArgs);
Args.push_back(Src);
Args.push_back("-o");
Args.push_back(Dst);
Expand Down
23 changes: 8 additions & 15 deletions llvm/tools/llvm-xray/xray-stacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,11 @@ static StackDuration mergeStackDuration(const StackDuration &Left,
Data.IntermediateDurations.reserve(Left.IntermediateDurations.size() +
Right.IntermediateDurations.size());
// Aggregate the durations.
for (auto duration : Left.TerminalDurations)
Data.TerminalDurations.push_back(duration);
for (auto duration : Right.TerminalDurations)
Data.TerminalDurations.push_back(duration);

for (auto duration : Left.IntermediateDurations)
Data.IntermediateDurations.push_back(duration);
for (auto duration : Right.IntermediateDurations)
Data.IntermediateDurations.push_back(duration);
llvm::append_range(Data.TerminalDurations, Left.TerminalDurations);
llvm::append_range(Data.TerminalDurations, Right.TerminalDurations);

llvm::append_range(Data.IntermediateDurations, Left.IntermediateDurations);
llvm::append_range(Data.IntermediateDurations, Right.IntermediateDurations);
return Data;
}

Expand Down Expand Up @@ -506,8 +502,7 @@ class StackTrie {
for (const auto &RootNodeRange :
make_range(map_iterator(Roots.begin(), MapValueFn),
map_iterator(Roots.end(), MapValueFn))) {
for (auto *RootNode : RootNodeRange)
RootValues.push_back(RootNode);
llvm::append_range(RootValues, RootNodeRange);
}

print(OS, FN, RootValues);
Expand Down Expand Up @@ -565,8 +560,7 @@ class StackTrie {
while (!S.empty()) {
auto *Top = S.pop_back_val();
printSingleStack<AggType>(OS, FN, ReportThread, ThreadId, Top);
for (const auto *C : Top->Callees)
S.push_back(C);
llvm::append_range(S, Top->Callees);
}
}
}
Expand Down Expand Up @@ -641,8 +635,7 @@ class StackTrie {
TopStacksByCount.pop_back();
}
}
for (const auto *C : Top->Callees)
S.push_back(C);
llvm::append_range(S, Top->Callees);
}
}

Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/lto/lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ void lto_set_debug_options(const char *const *options, int number) {
// Need to put each suboption in a null-terminated string before passing to
// parseCommandLineOptions().
std::vector<std::string> Options;
for (int i = 0; i < number; ++i)
Options.push_back(options[i]);
llvm::append_range(Options, ArrayRef(options, number));

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

Expand Down
6 changes: 2 additions & 4 deletions llvm/tools/obj2yaml/elf2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1266,8 +1266,7 @@ ELFDumper<ELFT>::dumpSymtabShndxSection(const Elf_Shdr *Shdr) {
return EntriesOrErr.takeError();

S->Entries.emplace();
for (const Elf_Word &E : *EntriesOrErr)
S->Entries->push_back(E);
llvm::append_range(*S->Entries, *EntriesOrErr);
return S.release();
}

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

S->Entries.emplace();
for (const Elf_Half &E : *VersionsOrErr)
S->Entries->push_back(E);
llvm::append_range(*S->Entries, *VersionsOrErr);

return S.release();
}
Expand Down
7 changes: 2 additions & 5 deletions llvm/tools/obj2yaml/macho2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,7 @@ void MachODumper::dumpFunctionStarts(std::unique_ptr<MachOYAML::Object> &Y) {
MachOYAML::LinkEditData &LEData = Y->LinkEdit;

auto FunctionStarts = Obj.getFunctionStarts();
for (auto Addr : FunctionStarts)
LEData.FunctionStarts.push_back(Addr);
llvm::append_range(LEData.FunctionStarts, FunctionStarts);
}

void MachODumper::dumpRebaseOpcodes(std::unique_ptr<MachOYAML::Object> &Y) {
Expand Down Expand Up @@ -637,9 +636,7 @@ void MachODumper::dumpChainedFixups(std::unique_ptr<MachOYAML::Object> &Y) {
assert(DC.dataoff < Obj.getData().size());
assert(DC.dataoff + DC.datasize <= Obj.getData().size());
const char *Bytes = Obj.getData().data() + DC.dataoff;
for (size_t Idx = 0; Idx < DC.datasize; Idx++) {
LEData.ChainedFixups.push_back(Bytes[Idx]);
}
llvm::append_range(LEData.ChainedFixups, ArrayRef(Bytes, DC.datasize));
}
break;
}
Expand Down