deal more gracefully with un-named functions
Before this only worked if there was exactly 1 of these,
now it works for multiple of them, but it won't work if they get
added/removed/reordered between the two files -- but we
handle signature mismatches gracefully so I think this is fine.
MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
@@ -265,6 +265,7 @@ int main(int argc, char **argv) {
llvm::EnableDebugBuffering = true;
llvm::llvm_shutdown_obj llvm_shutdown; // Call llvm_shutdown() on exit.
llvm::LLVMContext Context;
+ unsigned M1_anon_count = 0;
std::string Usage =
R"EOF(Alive2 stand-alone translation validator:
@@ -344,17 +345,25 @@ convenient way to demonstrate an existing optimizer bug.
for (auto &F1 : *M1.get()) {
if (F1.isDeclaration())
continue;
+ if (F1.getName().empty())
+ M1_anon_count++;
if (!func_names.empty() && !func_names.count(F1.getName().str()))
continue;
+ unsigned M2_anon_count = 0;
for (auto &F2 : *M2.get()) {
- if (F2.isDeclaration() || F1.getName() != F2.getName())
+ if (F2.isDeclaration())
continue;
+ if (F2.getName().empty())
+ M2_anon_count++;
+ if ((F1.getName().empty() && (M1_anon_count == M2_anon_count)) ||
+ (F1.getName() == F2.getName())) {
if (!compareFunctions(F1, F2, TLI))
if (opt_error_fatal)
goto end;
break;
}
}
+ }
*out << "Summary:\n"
" " << num_correct << " correct transformations\n"

MODIFY
tv/tv.cpp
tv/tv.cpp
@@ -158,10 +158,12 @@ struct TVLegacyPass final : public llvm::ModulePass {
bool onlyif_src_exists = false; // Verify this pair only if src exists
const function<llvm::TargetLibraryInfo*(llvm::Function&)> *TLI_override
= nullptr;
+ unsigned anon_count;
TVLegacyPass() : ModulePass(ID) {}
bool runOnModule(llvm::Module &M) override {
+ anon_count = 0;
for (auto &F: M)
runOnFunction(F);
return false;
@@ -191,7 +193,10 @@ struct TVLegacyPass final : public llvm::ModulePass {
TLI = &getAnalysis<llvm::TargetLibraryInfoWrapperPass>().getTLI(F);
}
- auto [I, first] = fns.try_emplace(F.getName().str());
+ string name = F.getName().str();
+ if (name.empty())
+ name = "anon$" + std::to_string(++anon_count);
+ auto [I, first] = fns.try_emplace(name);
if (onlyif_src_exists && first) {
// src does not exist; skip this fn
fns.erase(I);

deal more gracefully with un-named functions (#829)

Before this only worked if there was exactly 1 of these,
now it works for multiple of them, but it won't work if they get
added/removed/reordered between the two files -- but we
handle signature mismatches gracefully so I think this is fine.