clangtv: cache TLIImpl and use scopedwatch only when -tv-elapsed-time is set
ADD
tests/clang-tv/elapsed-time.c
+// TEST-ARGS: -mllvm -tv-elapsed-time
+
+int f(int x) {
+ return x + 1 - 1;
+}
+
+// CHECK: f:

MODIFY
tv/tv.cpp
tv/tv.cpp
@@ -251,7 +251,9 @@ struct TVPass final : public llvm::ModulePass {
if (!fnsToVerify.empty() && !fnsToVerify.count(F.getName().str()))
return false;
- ScopedWatch timer([&](const StopWatch &sw) {
+ optional<ScopedWatch> timer;
+ if(opt_elapsed_time)
+ timer.emplace([&](const StopWatch &sw) {
fns_elapsed_time[F.getName().str()] += sw.seconds();
});
@@ -725,13 +727,14 @@ llvmGetPassPluginInfo() {
TVNewPass tv;
tv.print_pass_name = true;
- llvm::TargetLibraryInfoImpl TLIImpl;
+ static optional<llvm::TargetLibraryInfoImpl> TLIImpl;
optional<llvm::TargetLibraryInfo> TLI_holder;
auto get_TLI = [&](llvm::Function &F) {
+ if (!TLIImpl)
TLIImpl = llvm::TargetLibraryInfoImpl(
llvm::Triple(F.getParent()->getTargetTriple()));
- return &TLI_holder.emplace(TLIImpl, &F);
+ return &TLI_holder.emplace(*TLIImpl, &F);
};
tv.run(*const_cast<llvm::Module *>(unwrapModule(IR)), get_TLI);

clangtv: cache TLIImpl and use scopedwatch only when -tv-elapsed-time is set (#637)