aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/codegen/codegen.h
blob: 4c7e2ab4f12f73c6e6581ba54e74ec186bd72ac4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma once

#include <memory>
#include <util/generic/fwd.h>
#include <util/generic/strbuf.h>

class IOutputStream;

namespace llvm {
    class Module;
    class Function;
    class LLVMContext;
    class ExecutionEngine;
}

namespace NYql {
namespace NCodegen {

enum class ETarget {
    Native, // Run on current processor and OS
    CurrentOS,
    Linux,
    Windows,
    Darwin
};

enum class ESanitize {
    Auto,
    Asan,
    Msan,
    Tsan
};

struct TCodegenStats {
    ui64 TotalFunctions = 0;
    ui64 TotalInstructions = 0;
    ui64 MaxFunctionInstructions = 0;
};

struct TCompileStats {
    ui32 FunctionPassTime = 0;
    ui32 ModulePassTime = 0;
    ui32 FinalizeTime = 0;
    ui64 TotalObjectSize = 0;
};

class ICodegen {
public:
    virtual ~ICodegen() = default;
    virtual ETarget GetEffectiveTarget() const = 0;
    virtual llvm::LLVMContext& GetContext() = 0;
    virtual llvm::Module& GetModule() = 0;
    virtual llvm::ExecutionEngine& GetEngine() = 0;
    virtual void Verify() = 0;
    virtual void GetStats(TCodegenStats& stats) = 0;
    virtual void ExportSymbol(llvm::Function* function) = 0; // to run DCE before Compile
    virtual void Compile(const TStringBuf compileOpts = TStringBuf(), TCompileStats* compileStats = nullptr) = 0;
    virtual void* GetPointerToFunction(llvm::Function* function) = 0;
    virtual ui64 GetFunctionCodeSize(llvm::Function* function) = 0;
    virtual void ShowGeneratedFunctions(IOutputStream* out) = 0;
    virtual void LoadBitCode(TStringBuf bitcode, TStringBuf uniqId) = 0;
    virtual void AddGlobalMapping(TStringBuf name, const void* address) = 0;
    virtual void TogglePerfJITEventListener() = 0;

    using TPtr = std::unique_ptr<ICodegen>;
    static TPtr Make(ETarget target, ESanitize sanitize = ESanitize::Auto);

    using TSharedPtr = std::shared_ptr<ICodegen>;
    static TSharedPtr MakeShared(ETarget target, ESanitize sanitize = ESanitize::Auto);

    static bool IsCodegenAvailable();
};

}
}