mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 01:24:30 +00:00
llvmc: Add a '-time' option.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86348 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -25,10 +25,11 @@ extern llvm::cl::opt<std::string> OutputFilename;
|
|||||||
extern llvm::cl::opt<std::string> TempDirname;
|
extern llvm::cl::opt<std::string> TempDirname;
|
||||||
extern llvm::cl::list<std::string> Languages;
|
extern llvm::cl::list<std::string> Languages;
|
||||||
extern llvm::cl::opt<bool> DryRun;
|
extern llvm::cl::opt<bool> DryRun;
|
||||||
|
extern llvm::cl::opt<bool> Time;
|
||||||
extern llvm::cl::opt<bool> VerboseMode;
|
extern llvm::cl::opt<bool> VerboseMode;
|
||||||
extern llvm::cl::opt<bool> CheckGraph;
|
extern llvm::cl::opt<bool> CheckGraph;
|
||||||
extern llvm::cl::opt<bool> WriteGraph;
|
|
||||||
extern llvm::cl::opt<bool> ViewGraph;
|
extern llvm::cl::opt<bool> ViewGraph;
|
||||||
|
extern llvm::cl::opt<bool> WriteGraph;
|
||||||
extern llvm::cl::opt<SaveTempsEnum::Values> SaveTemps;
|
extern llvm::cl::opt<SaveTempsEnum::Values> SaveTemps;
|
||||||
|
|
||||||
#endif // LLVM_INCLUDE_COMPILER_DRIVER_BUILTIN_OPTIONS_H
|
#endif // LLVM_INCLUDE_COMPILER_DRIVER_BUILTIN_OPTIONS_H
|
||||||
|
@ -13,9 +13,13 @@
|
|||||||
|
|
||||||
#include "llvm/CompilerDriver/Action.h"
|
#include "llvm/CompilerDriver/Action.h"
|
||||||
#include "llvm/CompilerDriver/BuiltinOptions.h"
|
#include "llvm/CompilerDriver/BuiltinOptions.h"
|
||||||
|
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/System/Program.h"
|
#include "llvm/System/Program.h"
|
||||||
|
#include "llvm/System/TimeValue.h"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvmc;
|
using namespace llvmc;
|
||||||
@ -60,14 +64,31 @@ namespace {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace llvmc {
|
||||||
|
void AppendToGlobalTimeLog(const std::string& cmd, double time);
|
||||||
|
}
|
||||||
|
|
||||||
int llvmc::Action::Execute() const {
|
int llvmc::Action::Execute() const {
|
||||||
if (DryRun || VerboseMode) {
|
if (DryRun || VerboseMode) {
|
||||||
errs() << Command_ << " ";
|
errs() << Command_ << " ";
|
||||||
std::for_each(Args_.begin(), Args_.end(), print_string);
|
std::for_each(Args_.begin(), Args_.end(), print_string);
|
||||||
errs() << '\n';
|
errs() << '\n';
|
||||||
}
|
}
|
||||||
if (DryRun)
|
if (!DryRun) {
|
||||||
return 0;
|
if (Time) {
|
||||||
else
|
sys::TimeValue now = sys::TimeValue::now();
|
||||||
return ExecuteProgram(Command_, Args_);
|
int ret = ExecuteProgram(Command_, Args_);
|
||||||
|
sys::TimeValue now2 = sys::TimeValue::now();
|
||||||
|
now2 -= now;
|
||||||
|
double elapsed = now2.seconds() + now2.microseconds() / 1000000.0;
|
||||||
|
AppendToGlobalTimeLog(Command_, elapsed);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return ExecuteProgram(Command_, Args_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,10 @@ cl::opt<std::string> TempDirname("temp-dir", cl::desc("Temp dir name"),
|
|||||||
cl::list<std::string> Languages("x",
|
cl::list<std::string> Languages("x",
|
||||||
cl::desc("Specify the language of the following input files"),
|
cl::desc("Specify the language of the following input files"),
|
||||||
cl::ZeroOrMore);
|
cl::ZeroOrMore);
|
||||||
|
|
||||||
cl::opt<bool> DryRun("dry-run",
|
cl::opt<bool> DryRun("dry-run",
|
||||||
cl::desc("Only pretend to run commands"));
|
cl::desc("Only pretend to run commands"));
|
||||||
|
cl::opt<bool> Time("time", cl::desc("Time individual commands"));
|
||||||
cl::opt<bool> VerboseMode("v",
|
cl::opt<bool> VerboseMode("v",
|
||||||
cl::desc("Enable verbose mode"));
|
cl::desc("Enable verbose mode"));
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@ -28,6 +29,8 @@ using namespace llvmc;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
std::stringstream* GlobalTimeLog;
|
||||||
|
|
||||||
sys::Path getTempDir() {
|
sys::Path getTempDir() {
|
||||||
sys::Path tempDir;
|
sys::Path tempDir;
|
||||||
|
|
||||||
@ -81,6 +84,11 @@ namespace {
|
|||||||
|
|
||||||
namespace llvmc {
|
namespace llvmc {
|
||||||
|
|
||||||
|
// Used to implement -time option. External linkage is intentional.
|
||||||
|
void AppendToGlobalTimeLog(const std::string& cmd, double time) {
|
||||||
|
*GlobalTimeLog << "# " << cmd << ' ' << time << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
// Sometimes plugins want to condition on the value in argv[0].
|
// Sometimes plugins want to condition on the value in argv[0].
|
||||||
const char* ProgramName;
|
const char* ProgramName;
|
||||||
|
|
||||||
@ -122,7 +130,19 @@ int Main(int argc, char** argv) {
|
|||||||
throw std::runtime_error("no input files");
|
throw std::runtime_error("no input files");
|
||||||
}
|
}
|
||||||
|
|
||||||
return BuildTargets(graph, langMap);
|
if (Time) {
|
||||||
|
GlobalTimeLog = new std::stringstream;
|
||||||
|
GlobalTimeLog->precision(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = BuildTargets(graph, langMap);
|
||||||
|
|
||||||
|
if (Time) {
|
||||||
|
llvm::errs() << GlobalTimeLog->str();
|
||||||
|
delete GlobalTimeLog;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
catch(llvmc::error_code& ec) {
|
catch(llvmc::error_code& ec) {
|
||||||
return ec.code();
|
return ec.code();
|
||||||
|
Reference in New Issue
Block a user