[llvm] r370968 - [llvm-rtdyld] Add timers to match llvm-jitlink.
Mikael Holmén via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 10 04:25:21 PDT 2019
Hi Lang,
See comment further down.
On Wed, 2019-09-04 at 20:26 +0000, Lang Hames via llvm-commits wrote:
> Author: lhames
> Date: Wed Sep 4 13:26:25 2019
> New Revision: 370968
>
> URL:
> https://protect2.fireeye.com/url?k=7c987f21-2011d0e8-7c983fba-0cc47ad93e1c-7f00b81ab646ac1b&q=1&u=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%3Frev%3D370968%26view%3Drev
> Log:
> [llvm-rtdyld] Add timers to match llvm-jitlink.
>
> When using llvm-rtdyld to execute code, -show-times will now show the
> time
> taken to load the object files, apply relocations, and execute the
> rtdyld-linked code.
>
> Modified:
> llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp
> llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
>
> Modified: llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp
> URL:
> https://protect2.fireeye.com/url?k=29d8c59b-75516a52-29d88500-0cc47ad93e1c-0fa47a4c39c95913&q=1&u=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fllvm%2Ftrunk%2Ftools%2Fllvm-jitlink%2Fllvm-jitlink.cpp%3Frev%3D370968%26r1%3D370967%26r2%3D370968%26view%3Ddiff
> =====================================================================
> =========
> --- llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp (original)
> +++ llvm/trunk/tools/llvm-jitlink/llvm-jitlink.cpp Wed Sep 4
> 13:26:25 2019
> @@ -612,8 +612,8 @@ Expected<int> runEntryPoint(Session &S,
> struct JITLinkTimers {
> TimerGroup JITLinkTimers{"llvm-jitlink timers",
> "timers for llvm-jitlink phases"};
> - Timer LoadObjectsTimer{
> - "load", "time to load/add object files to llvm-jitlink",
> JITLinkTimers};
> + Timer LoadObjectsTimer{"load", "time to load/add object files",
> + JITLinkTimers};
> Timer LinkTimer{"link", "time to link object files",
> JITLinkTimers};
> Timer RunTimer{"run", "time to execute jitlink'd code",
> JITLinkTimers};
> };
>
> Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp
> URL:
> https://protect2.fireeye.com/url?k=95945ff3-c91df03a-95941f68-0cc47ad93e1c-18960bed0cef89d5&q=1&u=http%3A%2F%2Fllvm.org%2Fviewvc%2Fllvm-project%2Fllvm%2Ftrunk%2Ftools%2Fllvm-rtdyld%2Fllvm-rtdyld.cpp%3Frev%3D370968%26r1%3D370967%26r2%3D370968%26view%3Ddiff
> =====================================================================
> =========
> --- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)
> +++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Wed Sep 4 13:26:25
> 2019
> @@ -27,12 +27,13 @@
> #include "llvm/Support/CommandLine.h"
> #include "llvm/Support/DynamicLibrary.h"
> #include "llvm/Support/InitLLVM.h"
> +#include "llvm/Support/MSVCErrorWorkarounds.h"
> #include "llvm/Support/Memory.h"
> #include "llvm/Support/MemoryBuffer.h"
> -#include "llvm/Support/MSVCErrorWorkarounds.h"
> #include "llvm/Support/Path.h"
> #include "llvm/Support/TargetRegistry.h"
> #include "llvm/Support/TargetSelect.h"
> +#include "llvm/Support/Timer.h"
> #include "llvm/Support/raw_ostream.h"
>
> #include <future>
> @@ -138,8 +139,22 @@ PrintAllocationRequests("print-alloc-req
> "manager by RuntimeDyld"),
> cl::Hidden);
>
> +static cl::opt<bool> ShowTimes("show-times",
> + cl::desc("Show times for llvm-rtdyld
> phases"),
> + cl::init(false));
> +
> ExitOnError ExitOnErr;
>
> +struct RTDyldTimers {
> + TimerGroup RTDyldTimers{"llvm-rtdyld timers",
> + "timers for llvm-rtdyld phases"};
> + Timer LoadObjectsTimer{"load", "time to load/add object files",
> RTDyldTimers};
> + Timer LinkTimer{"link", "time to link object files",
> RTDyldTimers};
> + Timer RunTimer{"run", "time to execute jitlink'd code",
> RTDyldTimers};
> +};
> +
> +std::unique_ptr<RTDyldTimers> Timers;
> +
> /* *** */
>
> using SectionIDMap = StringMap<unsigned>;
> @@ -489,35 +504,41 @@ static int executeInput() {
> // If we don't have any input files, read from stdin.
> if (!InputFileList.size())
> InputFileList.push_back("-");
> - for (auto &File : InputFileList) {
> - // Load the input memory buffer.
> - ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
> - MemoryBuffer::getFileOrSTDIN(File);
> - if (std::error_code EC = InputBuffer.getError())
> - ErrorAndExit("unable to read input: '" + EC.message() + "'");
> - Expected<std::unique_ptr<ObjectFile>> MaybeObj(
> - ObjectFile::createObjectFile((*InputBuffer)-
> >getMemBufferRef()));
> -
> - if (!MaybeObj) {
> - std::string Buf;
> - raw_string_ostream OS(Buf);
> - logAllUnhandledErrors(MaybeObj.takeError(), OS);
> - OS.flush();
> - ErrorAndExit("unable to create object file: '" + Buf + "'");
> - }
> + {
> + TimeRegion TR(Timers ? &Timers->LoadObjectsTimer : nullptr);
> + for (auto &File : InputFileList) {
> + // Load the input memory buffer.
> + ErrorOr<std::unique_ptr<MemoryBuffer>> InputBuffer =
> + MemoryBuffer::getFileOrSTDIN(File);
> + if (std::error_code EC = InputBuffer.getError())
> + ErrorAndExit("unable to read input: '" + EC.message() +
> "'");
> + Expected<std::unique_ptr<ObjectFile>> MaybeObj(
> + ObjectFile::createObjectFile((*InputBuffer)-
> >getMemBufferRef()));
> +
> + if (!MaybeObj) {
> + std::string Buf;
> + raw_string_ostream OS(Buf);
> + logAllUnhandledErrors(MaybeObj.takeError(), OS);
> + OS.flush();
> + ErrorAndExit("unable to create object file: '" + Buf + "'");
> + }
>
> - ObjectFile &Obj = **MaybeObj;
> + ObjectFile &Obj = **MaybeObj;
>
> - // Load the object file
> - Dyld.loadObject(Obj);
> - if (Dyld.hasError()) {
> - ErrorAndExit(Dyld.getErrorString());
> + // Load the object file
> + Dyld.loadObject(Obj);
> + if (Dyld.hasError()) {
> + ErrorAndExit(Dyld.getErrorString());
> + }
> }
> }
>
> - // Resove all the relocations we can.
> - // FIXME: Error out if there are unresolved relocations.
> - Dyld.resolveRelocations();
> + {
> + TimeRegion TR(Timers ? &Timers->LinkTimer : nullptr);
> + // Resove all the relocations we can.
> + // FIXME: Error out if there are unresolved relocations.
> + Dyld.resolveRelocations();
> + }
>
> // Get the address of the entry point (_main by default).
> void *MainAddress = Dyld.getSymbolLocalAddress(EntryPoint);
> @@ -549,7 +570,13 @@ static int executeInput() {
> for (auto &Arg : InputArgv)
> Argv.push_back(Arg.data());
> Argv.push_back(nullptr);
> - return Main(Argv.size() - 1, Argv.data());
> + int Result = 0;
> + {
> + TimeRegion TR(Timers ? &Timers->RunTimer : nullptr);
> + Result = Main(Argv.size() - 1, Argv.data());
> + }
> +
> + return Result;
> }
>
> static int checkAllExpressions(RuntimeDyldChecker &Checker) {
> @@ -935,16 +962,27 @@ int main(int argc, char **argv) {
>
> ExitOnErr.setBanner(std::string(argv[0]) + ": ");
>
> + Timers = ShowTimes ? std::make_unique<RTDyldTimers>() : nullptr;
> +
> + int Result;
> switch (Action) {
> case AC_Execute:
> - return executeInput();
> + Result = executeInput();
> + break;
> case AC_PrintDebugLineInfo:
> - return printLineInfoForInput(/* LoadObjects */ true,/*
> UseDebugObj */ true);
> + Result =
> + printLineInfoForInput(/* LoadObjects */ true, /* UseDebugObj
> */ true);
> + break;
> case AC_PrintLineInfo:
> - return printLineInfoForInput(/* LoadObjects */ true,/*
> UseDebugObj */false);
> + Result =
> + printLineInfoForInput(/* LoadObjects */ true, /* UseDebugObj
> */ false);
> + break;
> case AC_PrintObjectLineInfo:
> - return printLineInfoForInput(/* LoadObjects */false,/*
> UseDebugObj */false);
> + Result =
> + printLineInfoForInput(/* LoadObjects */ false, /*
> UseDebugObj */ false);
> + break;
> case AC_Verify:
> - return linkAndVerify();
> + Result = linkAndVerify();
> + break;
> }
Looks like there's a missing
return Result;
here?
Compiling with gcc I see a warning
../tools/llvm-rtdyld/llvm-rtdyld.cpp: In function 'int main(int,
char**)':
../tools/llvm-rtdyld/llvm-rtdyld.cpp:966:7: warning: variable 'Result'
set but not used [-Wunused-but-set-variable]
int Result;
^~~~~~
(Not sure why it doesn't warn about reaching end of function without
returning any value though.)
Regards,
Mikael
> }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
>
https://protect2.fireeye.com/url?k=989faff6-c416003f-989fef6d-0cc47ad93e1c-0f464c0644c9a3f9&q=1&u=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-commits
More information about the llvm-commits
mailing list