From e592104cf05d7f80d0d0ca83f67b36bb029bbb89 Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Wed, 16 May 2018 18:16:01 +0000 Subject: [PATCH] [Timers] TimerGroup: add constructor from StringMap Summary: This is needed for the continuation of D46504, to be able to store the timings. Reviewers: george.karpenkov, NoQ, alexfh, sbenza Reviewed By: alexfh Subscribers: llvm-commits, cfe-commits Differential Revision: https://reviews.llvm.org/D46939 llvm-svn: 332506 --- llvm/include/llvm/Support/Timer.h | 5 +++++ llvm/lib/Support/Timer.cpp | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/llvm/include/llvm/Support/Timer.h b/llvm/include/llvm/Support/Timer.h index 41f1b81a8049..bfffbc3157b1 100644 --- a/llvm/include/llvm/Support/Timer.h +++ b/llvm/include/llvm/Support/Timer.h @@ -10,6 +10,7 @@ #ifndef LLVM_SUPPORT_TIMER_H #define LLVM_SUPPORT_TIMER_H +#include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/DataTypes.h" #include @@ -194,6 +195,10 @@ class TimerGroup { public: explicit TimerGroup(StringRef Name, StringRef Description); + + explicit TimerGroup(StringRef Name, StringRef Description, + const StringMap &Records); + ~TimerGroup(); void setName(StringRef NewName, StringRef NewDescription) { diff --git a/llvm/lib/Support/Timer.cpp b/llvm/lib/Support/Timer.cpp index fd587fb80bbc..61d3b6c6e319 100644 --- a/llvm/lib/Support/Timer.cpp +++ b/llvm/lib/Support/Timer.cpp @@ -236,6 +236,15 @@ TimerGroup::TimerGroup(StringRef Name, StringRef Description) TimerGroupList = this; } +TimerGroup::TimerGroup(StringRef Name, StringRef Description, + const StringMap &Records) + : TimerGroup(Name, Description) { + TimersToPrint.reserve(Records.size()); + for (const auto &P : Records) + TimersToPrint.emplace_back(P.getValue(), P.getKey(), P.getKey()); + assert(TimersToPrint.size() == Records.size() && "Size mismatch"); +} + TimerGroup::~TimerGroup() { // If the timer group is destroyed before the timers it owns, accumulate and // print the timing data.