Coverage Report

Created: 2026-06-30 06:10

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/include/llvm/jit.h
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
4
//===-- wasmedge/llvm/jit.h - JIT Engine class definition -----------------===//
5
//
6
// Part of the WasmEdge Project.
7
//
8
//===----------------------------------------------------------------------===//
9
///
10
/// \file
11
/// This file defines the JIT engine class.
12
///
13
//===----------------------------------------------------------------------===//
14
#pragma once
15
16
#include "ast/module.h"
17
#include "common/configure.h"
18
#include "common/errcode.h"
19
#include "common/executable.h"
20
#include "common/span.h"
21
#include "llvm/data.h"
22
#include <memory>
23
#include <vector>
24
25
namespace WasmEdge::LLVM {
26
27
/// Address of JIT- or AOT-generated machine code for a wasm function. Not a
28
/// typed C++ function pointer; wasm signatures vary and calls go through the
29
/// executor.
30
using WasmFunctionCodeAddress = void *;
31
32
class OrcLLJIT;
33
34
class JITLibrary : public Executable {
35
public:
36
  JITLibrary(std::shared_ptr<OrcLLJIT> JIT, bool IsLazy = false) noexcept;
37
  ~JITLibrary() noexcept override;
38
39
  Symbol<const IntrinsicsTable *> getIntrinsics() noexcept override;
40
41
  std::vector<Symbol<Wrapper>> getTypes(size_t Size) noexcept override;
42
43
  std::vector<Symbol<void>> getCodes(size_t Offset,
44
                                     size_t Size) noexcept override;
45
46
  /// Create a symbol for lazily compiled machine code owned by this library.
47
0
  Symbol<void> createCodeSymbol(void *Address) const noexcept {
48
0
    return createSymbol<void>(Address);
49
0
  }
50
51
private:
52
  std::shared_ptr<OrcLLJIT> J;
53
  bool IsLazy;
54
  friend class JIT;
55
};
56
57
class JIT {
58
public:
59
0
  JIT(const Configure &Conf) noexcept : Conf(Conf) {}
60
  Expect<std::shared_ptr<Executable>> load(Data D) noexcept;
61
62
  /// Load for lazy JIT. The data is kept alive by the caller so following
63
  /// batches can reuse its thread-safe context.
64
  Expect<std::shared_ptr<Executable>> loadLazy(Data &D) noexcept;
65
66
  /// Adds one LLVM IR module and resolves many wasm function symbols.
67
  Expect<std::vector<WasmFunctionCodeAddress>>
68
  add(JITLibrary &Lib, Data &D,
69
      Span<const uint32_t> GlobalFuncIndices) noexcept;
70
71
private:
72
  Expect<std::shared_ptr<Executable>> loadImpl(Data &D, bool IsLazy) noexcept;
73
74
  const Configure Conf;
75
};
76
77
} // namespace WasmEdge::LLVM