OBS-URL: https://build.opensuse.org/package/show/devel:tools:statica/klee?expand=0&rev=37
200 lines
5.5 KiB
Diff
200 lines
5.5 KiB
Diff
From: Jiri Slaby <jirislaby@gmail.com>
|
|
Date: Wed, 7 Jun 2017 13:36:28 +0200
|
|
Subject: llvm: use chrono helpers from LLVM 4.0
|
|
Patch-mainline: no
|
|
|
|
LLVM 4.0 removes the old time interface and starts using the C++11's
|
|
chrono. So switch to that in klee for LLVM 4.0 too.
|
|
|
|
Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
|
|
---
|
|
include/klee/Internal/Support/Timer.h | 8 ++++++++
|
|
include/klee/Internal/System/Time.h | 11 +++++++++++
|
|
lib/Core/StatsTracker.cpp | 24 ++++++++++++++++++++++++
|
|
lib/Support/Time.cpp | 32 ++++++++++++++++++++++++++++++++
|
|
lib/Support/Timer.cpp | 16 ++++++++++++++++
|
|
5 files changed, 91 insertions(+)
|
|
|
|
diff --git a/include/klee/Internal/Support/Timer.h b/include/klee/Internal/Support/Timer.h
|
|
index a422abd027f3..d80ccb31f647 100644
|
|
--- a/include/klee/Internal/Support/Timer.h
|
|
+++ b/include/klee/Internal/Support/Timer.h
|
|
@@ -12,9 +12,17 @@
|
|
|
|
#include <stdint.h>
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+#include <llvm/Support/Chrono.h>
|
|
+#endif
|
|
+
|
|
namespace klee {
|
|
class WallTimer {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ llvm::sys::TimePoint<> start;
|
|
+#else
|
|
uint64_t startMicroseconds;
|
|
+#endif
|
|
|
|
public:
|
|
WallTimer();
|
|
diff --git a/include/klee/Internal/System/Time.h b/include/klee/Internal/System/Time.h
|
|
index 14d235364401..feeeed8affa2 100644
|
|
--- a/include/klee/Internal/System/Time.h
|
|
+++ b/include/klee/Internal/System/Time.h
|
|
@@ -10,7 +10,13 @@
|
|
#ifndef KLEE_UTIL_TIME_H
|
|
#define KLEE_UTIL_TIME_H
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+#include <chrono>
|
|
+
|
|
+#include <llvm/Support/Chrono.h>
|
|
+#else
|
|
#include <llvm/Support/TimeValue.h>
|
|
+#endif
|
|
|
|
namespace klee {
|
|
namespace util {
|
|
@@ -22,7 +28,12 @@ namespace klee {
|
|
double getWallTime();
|
|
|
|
/// Wall time as TimeValue object.
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ double durationToDouble(std::chrono::nanoseconds dur);
|
|
+ llvm::sys::TimePoint<> getWallTimeVal();
|
|
+#else
|
|
llvm::sys::TimeValue getWallTimeVal();
|
|
+#endif
|
|
}
|
|
}
|
|
|
|
diff --git a/lib/Core/StatsTracker.cpp b/lib/Core/StatsTracker.cpp
|
|
index e931dcef8b2e..c39c7d5bd7ba 100644
|
|
--- a/lib/Core/StatsTracker.cpp
|
|
+++ b/lib/Core/StatsTracker.cpp
|
|
@@ -282,6 +282,29 @@ void StatsTracker::done() {
|
|
void StatsTracker::stepInstruction(ExecutionState &es) {
|
|
if (OutputIStats) {
|
|
if (TrackInstructionTime) {
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+ static sys::TimePoint<> lastNowTime;
|
|
+ static std::chrono::nanoseconds lastUserTime(0);
|
|
+
|
|
+ if (lastUserTime.count() == 0) {
|
|
+ std::chrono::nanoseconds sys;
|
|
+ sys::Process::GetTimeUsage(lastNowTime, lastUserTime, sys);
|
|
+ } else {
|
|
+ sys::TimePoint<> now;
|
|
+ std::chrono::nanoseconds user, sys;
|
|
+
|
|
+ sys::Process::GetTimeUsage(now, user, sys);
|
|
+
|
|
+ std::chrono::microseconds delta =
|
|
+ std::chrono::duration_cast<std::chrono::microseconds>(user - lastUserTime);
|
|
+ std::chrono::microseconds deltaNow =
|
|
+ std::chrono::duration_cast<std::chrono::microseconds>(now - lastNowTime);
|
|
+ stats::instructionTime += delta.count();
|
|
+ stats::instructionRealTime += deltaNow.count();
|
|
+ lastUserTime = user;
|
|
+ lastNowTime = now;
|
|
+ }
|
|
+#else
|
|
static sys::TimeValue lastNowTime(0,0),lastUserTime(0,0);
|
|
|
|
if (lastUserTime.seconds()==0 && lastUserTime.nanoseconds()==0) {
|
|
@@ -297,6 +320,7 @@ void StatsTracker::stepInstruction(ExecutionState &es) {
|
|
lastUserTime = user;
|
|
lastNowTime = now;
|
|
}
|
|
+#endif
|
|
}
|
|
|
|
Instruction *inst = es.pc->inst;
|
|
diff --git a/lib/Support/Time.cpp b/lib/Support/Time.cpp
|
|
index be5eaf186958..f508e6fa1bcb 100644
|
|
--- a/lib/Support/Time.cpp
|
|
+++ b/lib/Support/Time.cpp
|
|
@@ -10,12 +10,43 @@
|
|
#include "klee/Config/Version.h"
|
|
#include "klee/Internal/System/Time.h"
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+#include <chrono>
|
|
+
|
|
+#include <llvm/Support/Chrono.h>
|
|
+#else
|
|
#include "llvm/Support/TimeValue.h"
|
|
+#endif
|
|
+
|
|
#include "llvm/Support/Process.h"
|
|
|
|
using namespace llvm;
|
|
using namespace klee;
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+double util::durationToDouble(std::chrono::nanoseconds dur)
|
|
+{
|
|
+ return dur.count() / 1e9;
|
|
+}
|
|
+
|
|
+double util::getUserTime() {
|
|
+ sys::TimePoint<> now;
|
|
+ std::chrono::nanoseconds user, sys;
|
|
+
|
|
+ sys::Process::GetTimeUsage(now, user, sys);
|
|
+
|
|
+ return durationToDouble(user);
|
|
+}
|
|
+
|
|
+double util::getWallTime() {
|
|
+ return durationToDouble(getWallTimeVal().time_since_epoch());
|
|
+}
|
|
+
|
|
+sys::TimePoint<> util::getWallTimeVal() {
|
|
+ return std::chrono::system_clock::now();
|
|
+}
|
|
+
|
|
+#else
|
|
double util::getUserTime() {
|
|
sys::TimeValue now(0,0),user(0,0),sys(0,0);
|
|
sys::Process::GetTimeUsage(now,user,sys);
|
|
@@ -30,3 +61,4 @@ double util::getWallTime() {
|
|
sys::TimeValue util::getWallTimeVal() {
|
|
return sys::TimeValue::now();
|
|
}
|
|
+#endif
|
|
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
|
|
index da96981079ae..a223b39ada57 100644
|
|
--- a/lib/Support/Timer.cpp
|
|
+++ b/lib/Support/Timer.cpp
|
|
@@ -15,6 +15,20 @@
|
|
using namespace klee;
|
|
using namespace llvm;
|
|
|
|
+#if LLVM_VERSION_CODE >= LLVM_VERSION(4, 0)
|
|
+
|
|
+WallTimer::WallTimer() {
|
|
+ start = util::getWallTimeVal();
|
|
+}
|
|
+
|
|
+uint64_t WallTimer::check() {
|
|
+ sys::TimePoint<> now = util::getWallTimeVal();
|
|
+ return std::chrono::duration_cast<std::chrono::microseconds>(now -
|
|
+ start).count();
|
|
+}
|
|
+
|
|
+#else
|
|
+
|
|
WallTimer::WallTimer() {
|
|
startMicroseconds = util::getWallTimeVal().usec();
|
|
}
|
|
@@ -22,3 +36,5 @@ WallTimer::WallTimer() {
|
|
uint64_t WallTimer::check() {
|
|
return util::getWallTimeVal().usec() - startMicroseconds;
|
|
}
|
|
+
|
|
+#endif
|
|
--
|
|
2.15.1
|
|
|