Skip to content
This repository was archived by the owner on Sep 11, 2026. It is now read-only.

Commit c10eb0b

Browse files
committed
Time JIT compile phase on -run path
1 parent afe47b5 commit c10eb0b

1 file changed

Lines changed: 36 additions & 16 deletions

File tree

compiler/ceramic.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <llvm/Support/DynamicLibrary.h>
88
#include <llvm/Support/FileSystem.h>
9+
#include <llvm/Support/Format.h>
910
#include <llvm/Support/Path.h>
1011
#include <llvm/Support/Signals.h>
1112
#include <llvm/TargetParser/Host.h>
@@ -45,7 +46,9 @@ static bool runModule(llvm::Module *module,
4546
const std::vector<std::string> &argv,
4647
char const *const *envp,
4748
llvm::ArrayRef<std::string> libSearchPaths,
48-
llvm::ArrayRef<std::string> libs) {
49+
llvm::ArrayRef<std::string> libs,
50+
HiResTimer *jitCompileTimer = nullptr,
51+
HiResTimer *execTimer = nullptr) {
4952
auto JIT_expected = llvm::orc::LLJITBuilder().create();
5053
if (!JIT_expected) {
5154
llvm::errs() << "error creating JIT: "
@@ -116,7 +119,11 @@ static bool runModule(llvm::Module *module,
116119
return false;
117120
}
118121

122+
if (jitCompileTimer)
123+
jitCompileTimer->start();
119124
auto mainAddr_expected = jit.lookup("main");
125+
if (jitCompileTimer)
126+
jitCompileTimer->stop();
120127
if (!mainAddr_expected) {
121128
llvm::errs() << "error resolving main: "
122129
<< llvm::toString(mainAddr_expected.takeError()) << "\n";
@@ -134,8 +141,12 @@ static bool runModule(llvm::Module *module,
134141
}
135142
c_argv.push_back(nullptr);
136143

144+
if (execTimer)
145+
execTimer->start();
137146
mainFunc(static_cast<int>(c_argv.size() - 1),
138147
const_cast<char **>(c_argv.data()), const_cast<char **>(envp));
148+
if (execTimer)
149+
execTimer->stop();
139150

140151
return true;
141152
}
@@ -889,6 +900,10 @@ int main2(int argc, char **argv, char const *const *envp) {
889900

890901
std::string moduleName = ceramicScript.empty() ? ceramicFile : "-e";
891902

903+
HiResTimer initTimer, loadTimer, compileTimer, optTimer, outputTimer,
904+
execTimer;
905+
906+
initTimer.start();
892907
llvm::TargetMachine *targetMachine =
893908
initLLVM(targetTriple, targetCPU, targetFeatures, softFloat, moduleName,
894909
"", (sharedLib || genPIC), debug, optLevel);
@@ -900,6 +915,7 @@ int main2(int argc, char **argv, char const *const *envp) {
900915

901916
initTypes();
902917
initExternalTarget(targetTriple);
918+
initTimer.stop();
903919

904920
// Try environment variables first
905921
if (char *libceramicPath = getenv("CERAMIC_PATH")) {
@@ -996,8 +1012,6 @@ int main2(int argc, char **argv, char const *const *envp) {
9961012
llvm::sys::RemoveFileOnSignal(dependenciesOutputFile);
9971013
}
9981014

999-
HiResTimer loadTimer, compileTimer, optTimer, outputTimer;
1000-
10011015
// compiler
10021016

10031017
loadTimer.start();
@@ -1062,7 +1076,8 @@ int main2(int argc, char **argv, char const *const *envp) {
10621076
runArgs.push_back(ceramicFile.empty() ? "-e" : ceramicFile);
10631077
runArgs.insert(runArgs.end(), programArgs.begin(),
10641078
programArgs.end());
1065-
runModule(llvmModule, runArgs, envp, libSearchPath, libraries);
1079+
runModule(llvmModule, runArgs, envp, libSearchPath, libraries,
1080+
&outputTimer, &execTimer);
10661081
} else if (repl) {
10671082
// TODO: future me task
10681083
runInteractive(llvmModule, m);
@@ -1118,18 +1133,23 @@ int main2(int argc, char **argv, char const *const *envp) {
11181133
return 1;
11191134
}
11201135
if (showTiming) {
1121-
llvm::errs() << "load time = "
1122-
<< static_cast<size_t>(loadTimer.elapsedMillis())
1123-
<< " ms\n";
1124-
llvm::errs() << "compile time = "
1125-
<< static_cast<size_t>(compileTimer.elapsedMillis())
1126-
<< " ms\n";
1127-
llvm::errs() << "optimization time = "
1128-
<< static_cast<size_t>(optTimer.elapsedMillis())
1129-
<< " ms\n";
1130-
llvm::errs() << "codegen time = "
1131-
<< static_cast<size_t>(outputTimer.elapsedMillis())
1132-
<< " ms\n";
1136+
auto ms = [](double v) { return llvm::format("%.3f ms", v); };
1137+
double init = initTimer.elapsedMillis();
1138+
double load = loadTimer.elapsedMillis();
1139+
double compile = compileTimer.elapsedMillis();
1140+
double opt = optTimer.elapsedMillis();
1141+
double codegen = outputTimer.elapsedMillis();
1142+
double exec = execTimer.elapsedMillis();
1143+
double total = init + load + compile + opt + codegen;
1144+
1145+
llvm::errs() << "init time = " << ms(init) << "\n";
1146+
llvm::errs() << "load time = " << ms(load) << "\n";
1147+
llvm::errs() << "compile time = " << ms(compile) << "\n";
1148+
llvm::errs() << "optimization time = " << ms(opt) << "\n";
1149+
llvm::errs() << "codegen time = " << ms(codegen) << "\n";
1150+
if (run)
1151+
llvm::errs() << "run time = " << ms(exec) << "\n";
1152+
llvm::errs() << "total time = " << ms(total) << "\n";
11331153
llvm::errs().flush();
11341154
}
11351155

0 commit comments

Comments
 (0)