#include "llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderPerf.h"
#include "llvm/ExecutionEngine/Orc/Shared/PerfSharedStructs.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Threading.h"
#include <mutex>
#include <optional>
#ifdef __linux__
#include <sys/mman.h>
#include <time.h>
#include <unistd.h>
#define DEBUG_TYPE …
#define JIT_LANG …
#define LLVM_PERF_JIT_MAGIC …
#define LLVM_PERF_JIT_VERSION …
usingnamespacellvm;
usingnamespacellvm::orc;
struct PerfState { … };
static std::mutex Mutex;
static std::optional<PerfState> State;
struct RecHeader { … };
struct DIR { … };
struct DIE { … };
struct CLR { … };
struct UWR { … };
static inline uint64_t timespec_to_ns(const struct timespec *TS) { … }
static inline uint64_t perf_get_timestamp() { … }
static void writeDebugRecord(const PerfJITDebugInfoRecord &DebugRecord) { … }
static void writeCodeRecord(const PerfJITCodeLoadRecord &CodeRecord) { … }
static void
writeUnwindRecord(const PerfJITCodeUnwindingInfoRecord &UnwindRecord) { … }
static Error registerJITLoaderPerfImpl(const PerfJITRecordBatch &Batch) { … }
struct Header { … };
static Error OpenMarker(PerfState &State) { … }
void CloseMarker(PerfState &State) { … }
static Expected<Header> FillMachine(PerfState &State) { … }
static Error InitDebuggingDir(PerfState &State) { … }
static Error registerJITLoaderPerfStartImpl() { … }
static Error registerJITLoaderPerfEndImpl() { … }
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfImpl(const char *Data, uint64_t Size) { … }
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfStart(const char *Data, uint64_t Size) { … }
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfEnd(const char *Data, uint64_t Size) { … }
#else
using namespace llvm;
using namespace llvm::orc;
static Error badOS() {
using namespace llvm;
return llvm::make_error<StringError>(
"unsupported OS (perf support is only available on linux!)",
inconvertibleErrorCode());
}
static Error badOSBatch(PerfJITRecordBatch &Batch) { return badOS(); }
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfImpl(const char *Data, uint64_t Size) {
using namespace shared;
return WrapperFunction<SPSError(SPSPerfJITRecordBatch)>::handle(Data, Size,
badOSBatch)
.release();
}
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfStart(const char *Data, uint64_t Size) {
using namespace shared;
return WrapperFunction<SPSError()>::handle(Data, Size, badOS).release();
}
extern "C" llvm::orc::shared::CWrapperFunctionResult
llvm_orc_registerJITLoaderPerfEnd(const char *Data, uint64_t Size) {
using namespace shared;
return WrapperFunction<SPSError()>::handle(Data, Size, badOS).release();
}
#endif