diff options
Diffstat (limited to 'llvm/tools/llvm-mc/llvm-mc.cpp')
-rw-r--r-- | llvm/tools/llvm-mc/llvm-mc.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp index da89af7..f69f7c7 100644 --- a/llvm/tools/llvm-mc/llvm-mc.cpp +++ b/llvm/tools/llvm-mc/llvm-mc.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "Disassembler.h" +#include "llvm/ADT/ScopeExit.h" #include "llvm/DWARFCFIChecker/DWARFCFIFunctionFrameAnalyzer.h" #include "llvm/DWARFCFIChecker/DWARFCFIFunctionFrameStreamer.h" #include "llvm/MC/MCAsmBackend.h" @@ -37,6 +38,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TargetSelect.h" +#include "llvm/Support/TimeProfiler.h" #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/WithColor.h" #include "llvm/TargetParser/Host.h" @@ -240,6 +242,23 @@ static cl::opt<ActionType> Action( "Colored disassembly of strings of hex bytes")), cl::cat(MCCategory)); +static cl::opt<unsigned> + NumBenchmarkRuns("runs", cl::desc("Number of runs for benchmarking"), + cl::cat(MCCategory)); + +static cl::opt<bool> TimeTrace("time-trace", cl::desc("Record time trace")); + +static cl::opt<unsigned> TimeTraceGranularity( + "time-trace-granularity", + cl::desc( + "Minimum time granularity (in microseconds) traced by time profiler"), + cl::init(500), cl::Hidden); + +static cl::opt<std::string> + TimeTraceFile("time-trace-file", + cl::desc("Specify time trace file destination"), + cl::value_desc("filename")); + static const Target *GetTarget(const char *ProgName) { // Figure out the target triple. if (TripleName.empty()) @@ -371,6 +390,20 @@ int main(int argc, char **argv) { cl::HideUnrelatedOptions({&MCCategory, &getColorCategory()}); cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); + + if (TimeTrace) + timeTraceProfilerInitialize(TimeTraceGranularity, argv[0]); + + auto TimeTraceScopeExit = make_scope_exit([]() { + if (!TimeTrace) + return; + if (auto E = timeTraceProfilerWrite(TimeTraceFile, OutputFilename)) { + logAllUnhandledErrors(std::move(E), errs()); + return; + } + timeTraceProfilerCleanup(); + }); + MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags(); MCOptions.CompressDebugSections = CompressDebugSections.getValue(); MCOptions.ShowMCInst = ShowInst; @@ -620,7 +653,8 @@ int main(int argc, char **argv) { } if (disassemble) Res = Disassembler::disassemble(*TheTarget, TripleName, *STI, *Str, *Buffer, - SrcMgr, Ctx, MCOptions, HexBytes); + SrcMgr, Ctx, MCOptions, HexBytes, + NumBenchmarkRuns); // Keep output if no errors. if (Res == 0) { @@ -628,5 +662,6 @@ int main(int argc, char **argv) { if (DwoOut) DwoOut->keep(); } + return Res; } |