mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 05:24:01 +00:00
stringref'ize Timer apis
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99877 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
#define LLVM_SUPPORT_TIMER_H
|
#define LLVM_SUPPORT_TIMER_H
|
||||||
|
|
||||||
#include "llvm/System/DataTypes.h"
|
#include "llvm/System/DataTypes.h"
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -88,8 +89,8 @@ class Timer {
|
|||||||
|
|
||||||
Timer **Prev, *Next; // Doubly linked list of timers in the group.
|
Timer **Prev, *Next; // Doubly linked list of timers in the group.
|
||||||
public:
|
public:
|
||||||
explicit Timer(const std::string &N) : TG(0) { init(N); }
|
explicit Timer(StringRef N) : TG(0) { init(N); }
|
||||||
Timer(const std::string &N, TimerGroup &tg) : TG(0) { init(N, tg); }
|
Timer(StringRef N, TimerGroup &tg) : TG(0) { init(N, tg); }
|
||||||
Timer(const Timer &RHS) : TG(0) {
|
Timer(const Timer &RHS) : TG(0) {
|
||||||
assert(RHS.TG == 0 && "Can only copy uninitialized timers");
|
assert(RHS.TG == 0 && "Can only copy uninitialized timers");
|
||||||
}
|
}
|
||||||
@ -101,8 +102,8 @@ public:
|
|||||||
|
|
||||||
// Create an uninitialized timer, client must use 'init'.
|
// Create an uninitialized timer, client must use 'init'.
|
||||||
explicit Timer() : TG(0) {}
|
explicit Timer() : TG(0) {}
|
||||||
void init(const std::string &N);
|
void init(StringRef N);
|
||||||
void init(const std::string &N, TimerGroup &tg);
|
void init(StringRef N, TimerGroup &tg);
|
||||||
|
|
||||||
const std::string &getName() const { return Name; }
|
const std::string &getName() const { return Name; }
|
||||||
bool isInitialized() const { return TG != 0; }
|
bool isInitialized() const { return TG != 0; }
|
||||||
@ -149,9 +150,8 @@ public:
|
|||||||
/// is primarily used for debugging and for hunting performance problems.
|
/// is primarily used for debugging and for hunting performance problems.
|
||||||
///
|
///
|
||||||
struct NamedRegionTimer : public TimeRegion {
|
struct NamedRegionTimer : public TimeRegion {
|
||||||
explicit NamedRegionTimer(const std::string &Name);
|
explicit NamedRegionTimer(StringRef Name);
|
||||||
explicit NamedRegionTimer(const std::string &Name,
|
explicit NamedRegionTimer(StringRef Name, StringRef GroupName);
|
||||||
const std::string &GroupName);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -169,10 +169,10 @@ class TimerGroup {
|
|||||||
TimerGroup(const TimerGroup &TG); // DO NOT IMPLEMENT
|
TimerGroup(const TimerGroup &TG); // DO NOT IMPLEMENT
|
||||||
void operator=(const TimerGroup &TG); // DO NOT IMPLEMENT
|
void operator=(const TimerGroup &TG); // DO NOT IMPLEMENT
|
||||||
public:
|
public:
|
||||||
explicit TimerGroup(const std::string &name);
|
explicit TimerGroup(StringRef name);
|
||||||
~TimerGroup();
|
~TimerGroup();
|
||||||
|
|
||||||
void setName(const std::string &name) { Name = name; }
|
void setName(StringRef name) { Name.assign(name.begin(), name.end()); }
|
||||||
|
|
||||||
/// print - Print any started timers in this group and zero them.
|
/// print - Print any started timers in this group and zero them.
|
||||||
void print(raw_ostream &OS);
|
void print(raw_ostream &OS);
|
||||||
|
@ -55,20 +55,20 @@ namespace {
|
|||||||
|
|
||||||
// CreateInfoOutputFile - Return a file stream to print our output on.
|
// CreateInfoOutputFile - Return a file stream to print our output on.
|
||||||
raw_ostream *llvm::CreateInfoOutputFile() {
|
raw_ostream *llvm::CreateInfoOutputFile() {
|
||||||
std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
|
const std::string &OutputFilename = getLibSupportInfoOutputFilename();
|
||||||
if (LibSupportInfoOutputFilename.empty())
|
if (OutputFilename.empty())
|
||||||
return new raw_fd_ostream(2, false); // stderr.
|
return new raw_fd_ostream(2, false); // stderr.
|
||||||
if (LibSupportInfoOutputFilename == "-")
|
if (OutputFilename == "-")
|
||||||
return new raw_fd_ostream(1, false); // stdout.
|
return new raw_fd_ostream(1, false); // stdout.
|
||||||
|
|
||||||
std::string Error;
|
std::string Error;
|
||||||
raw_ostream *Result = new raw_fd_ostream(LibSupportInfoOutputFilename.c_str(),
|
raw_ostream *Result = new raw_fd_ostream(OutputFilename.c_str(),
|
||||||
Error, raw_fd_ostream::F_Append);
|
Error, raw_fd_ostream::F_Append);
|
||||||
if (Error.empty())
|
if (Error.empty())
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
errs() << "Error opening info-output-file '"
|
errs() << "Error opening info-output-file '"
|
||||||
<< LibSupportInfoOutputFilename << " for appending!\n";
|
<< OutputFilename << " for appending!\n";
|
||||||
delete Result;
|
delete Result;
|
||||||
return new raw_fd_ostream(2, false); // stderr.
|
return new raw_fd_ostream(2, false); // stderr.
|
||||||
}
|
}
|
||||||
@ -96,17 +96,17 @@ static TimerGroup *getDefaultTimerGroup() {
|
|||||||
// Timer Implementation
|
// Timer Implementation
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
void Timer::init(const std::string &N) {
|
void Timer::init(StringRef N) {
|
||||||
assert(TG == 0 && "Timer already initialized");
|
assert(TG == 0 && "Timer already initialized");
|
||||||
Name = N;
|
Name.assign(N.begin(), N.end());
|
||||||
Started = false;
|
Started = false;
|
||||||
TG = getDefaultTimerGroup();
|
TG = getDefaultTimerGroup();
|
||||||
TG->addTimer(*this);
|
TG->addTimer(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timer::init(const std::string &N, TimerGroup &tg) {
|
void Timer::init(StringRef N, TimerGroup &tg) {
|
||||||
assert(TG == 0 && "Timer already initialized");
|
assert(TG == 0 && "Timer already initialized");
|
||||||
Name = N;
|
Name.assign(N.begin(), N.end());
|
||||||
Started = false;
|
Started = false;
|
||||||
TG = &tg;
|
TG = &tg;
|
||||||
TG->addTimer(*this);
|
TG->addTimer(*this);
|
||||||
@ -201,7 +201,7 @@ public:
|
|||||||
delete I->second.first;
|
delete I->second.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer &get(const std::string &Name, const std::string &GroupName) {
|
Timer &get(StringRef Name, StringRef GroupName) {
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
sys::SmartScopedLock<true> L(*TimerLock);
|
||||||
|
|
||||||
std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
|
std::pair<TimerGroup*, Name2TimerMap> &GroupEntry = Map[GroupName];
|
||||||
@ -219,7 +219,7 @@ public:
|
|||||||
static ManagedStatic<Name2TimerMap> NamedTimers;
|
static ManagedStatic<Name2TimerMap> NamedTimers;
|
||||||
static ManagedStatic<Name2PairMap> NamedGroupedTimers;
|
static ManagedStatic<Name2PairMap> NamedGroupedTimers;
|
||||||
|
|
||||||
static Timer &getNamedRegionTimer(const std::string &Name) {
|
static Timer &getNamedRegionTimer(StringRef Name) {
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
sys::SmartScopedLock<true> L(*TimerLock);
|
||||||
|
|
||||||
Timer &T = (*NamedTimers)[Name];
|
Timer &T = (*NamedTimers)[Name];
|
||||||
@ -228,11 +228,10 @@ static Timer &getNamedRegionTimer(const std::string &Name) {
|
|||||||
return T;
|
return T;
|
||||||
}
|
}
|
||||||
|
|
||||||
NamedRegionTimer::NamedRegionTimer(const std::string &Name)
|
NamedRegionTimer::NamedRegionTimer(StringRef Name)
|
||||||
: TimeRegion(getNamedRegionTimer(Name)) {}
|
: TimeRegion(getNamedRegionTimer(Name)) {}
|
||||||
|
|
||||||
NamedRegionTimer::NamedRegionTimer(const std::string &Name,
|
NamedRegionTimer::NamedRegionTimer(StringRef Name, StringRef GroupName)
|
||||||
const std::string &GroupName)
|
|
||||||
: TimeRegion(NamedGroupedTimers->get(Name, GroupName)) {}
|
: TimeRegion(NamedGroupedTimers->get(Name, GroupName)) {}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
@ -243,8 +242,8 @@ NamedRegionTimer::NamedRegionTimer(const std::string &Name,
|
|||||||
/// TimerGroup ctor/dtor and is protected by the TimerLock lock.
|
/// TimerGroup ctor/dtor and is protected by the TimerLock lock.
|
||||||
static TimerGroup *TimerGroupList = 0;
|
static TimerGroup *TimerGroupList = 0;
|
||||||
|
|
||||||
TimerGroup::TimerGroup(const std::string &name)
|
TimerGroup::TimerGroup(StringRef name)
|
||||||
: Name(name), FirstTimer(0) {
|
: Name(name.begin(), name.end()), FirstTimer(0) {
|
||||||
|
|
||||||
// Add the group to TimerGroupList.
|
// Add the group to TimerGroupList.
|
||||||
sys::SmartScopedLock<true> L(*TimerLock);
|
sys::SmartScopedLock<true> L(*TimerLock);
|
||||||
|
Reference in New Issue
Block a user