File: llvm-21.diff

package info (click to toggle)
wasmedge 0.14.1%2Bdfsg-3.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,872 kB
  • sloc: cpp: 133,470; asm: 26,333; ansic: 12,397; java: 2,553; sh: 2,086; javascript: 1,440; python: 1,330; pascal: 897; xml: 681; makefile: 100
file content (118 lines) | stat: -rw-r--r-- 4,346 bytes parent folder | download
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
diff --git a/lib/llvm/codegen.cpp b/lib/llvm/codegen.cpp
index 43b33cc7..2de0bdab 100644
--- a/lib/llvm/codegen.cpp
+++ b/lib/llvm/codegen.cpp
@@ -505,7 +505,7 @@ namespace WasmEdge::LLVM {
 
 Expect<void> CodeGen::codegen(Span<const Byte> WasmData, Data D,
                               std::filesystem::path OutputPath) noexcept {
-  auto LLContext = D.extract().LLContext();
+  auto LLContext = D.extract().getLLContext();
   auto &LLModule = D.extract().LLModule;
   auto &TM = D.extract().TM;
   std::filesystem::path LLPath(OutputPath);
diff --git a/lib/llvm/compiler.cpp b/lib/llvm/compiler.cpp
index ff564ff3..2441c8df 100644
--- a/lib/llvm/compiler.cpp
+++ b/lib/llvm/compiler.cpp
@@ -5826,7 +5826,7 @@ Expect<Data> Compiler::compile(const AST::Module &Module) noexcept {
   LLVM::Core::init();
 
   LLVM::Data D;
-  auto LLContext = D.extract().LLContext();
+  auto LLContext = D.extract().getLLContext();
   auto &LLModule = D.extract().LLModule;
   LLModule.setTarget(LLVM::getDefaultTargetTriple().unwrap());
   LLModule.addFlag(LLVMModuleFlagBehaviorError, "PIC Level"sv, 2);
diff --git a/lib/llvm/data.h b/lib/llvm/data.h
index 9ab1a525..c79585c0 100644
--- a/lib/llvm/data.h
+++ b/lib/llvm/data.h
@@ -6,9 +6,20 @@
 #include "llvm/data.h"
 
 struct WasmEdge::LLVM::Data::DataContext {
+#if LLVM_VERSION_MAJOR >= 21
+  LLVM::Context LLContext = LLVM::Context::create();
+  LLVM::Context getLLContext() noexcept { return LLContext; }
+  LLVM::OrcThreadSafeContext getTSContext() noexcept {
+    return LLVM::OrcThreadSafeContext(LLContext);
+  }
+#else
   LLVM::OrcThreadSafeContext TSContext;
+  LLVM::Context getLLContext() noexcept { return TSContext.getContext(); }
+  LLVM::OrcThreadSafeContext getTSContext() noexcept {
+    return std::move(TSContext);
+  }
+#endif
   LLVM::Module LLModule;
   LLVM::TargetMachine TM;
-  DataContext() noexcept : TSContext(), LLModule(LLContext(), "wasm") {}
-  LLVM::Context LLContext() noexcept { return TSContext.getContext(); }
+  DataContext() noexcept : LLModule(getLLContext(), "wasm") {}
 };
diff --git a/lib/llvm/jit.cpp b/lib/llvm/jit.cpp
index 9add6b51..4bf3cc80 100644
--- a/lib/llvm/jit.cpp
+++ b/lib/llvm/jit.cpp
@@ -73,6 +73,7 @@ Expect<std::shared_ptr<Executable>> JIT::load(Data D) noexcept {
   }
 
   auto &LLModule = D.extract().LLModule;
+  auto TSContext = D.extract().getTSContext();
 
   if (Conf.getCompilerConfigure().isDumpIR()) {
     if (auto ErrorMessage = LLModule.printModuleToFile("wasm-jit.ll")) {
@@ -82,8 +83,7 @@ Expect<std::shared_ptr<Executable>> JIT::load(Data D) noexcept {
 
   auto MainJD = J.getMainJITDylib();
   if (auto Err = J.addLLVMIRModule(
-          MainJD,
-          OrcThreadSafeModule(LLModule.release(), D.extract().TSContext))) {
+          MainJD, OrcThreadSafeModule(LLModule.release(), TSContext))) {
     spdlog::error("{}"sv, Err.message().string_view());
     return Unexpect(ErrCode::Value::HostFuncError);
   }
diff --git a/lib/llvm/llvm.h b/lib/llvm/llvm.h
index a327b850..9498a22f 100644
--- a/lib/llvm/llvm.h
+++ b/lib/llvm/llvm.h
@@ -266,9 +266,12 @@ public:
   Context(const Context &) = default;
   Context &operator=(const Context &) = default;
 
+  static Context create() noexcept { return Context(LLVMContextCreate()); }
+
   constexpr operator bool() const noexcept { return Ref != nullptr; }
   constexpr auto &unwrap() const noexcept { return Ref; }
   constexpr auto &unwrap() noexcept { return Ref; }
+  LLVMContextRef release() noexcept { return std::exchange(Ref, nullptr); }
   friend void swap(Context &LHS, Context &RHS) noexcept {
     using std::swap;
     swap(LHS.Ref, RHS.Ref);
@@ -2062,6 +2065,14 @@ public:
     swap(*this, B);
     return *this;
   }
+#if LLVM_VERSION_MAJOR >= 21
+  OrcThreadSafeContext(Context &C) noexcept
+      : Ref(LLVMOrcCreateNewThreadSafeContextFromLLVMContext(C.release())) {}
+#else
+  Context getContext() noexcept {
+    return LLVMOrcThreadSafeContextGetContext(Ref);
+  }
+#endif
 
   OrcThreadSafeContext() noexcept : Ref(LLVMOrcCreateNewThreadSafeContext()) {}
   ~OrcThreadSafeContext() noexcept { LLVMOrcDisposeThreadSafeContext(Ref); }
@@ -2078,10 +2089,6 @@ public:
     swap(LHS.Ref, RHS.Ref);
   }
 
-  Context getContext() noexcept {
-    return LLVMOrcThreadSafeContextGetContext(Ref);
-  }
-
 private:
   LLVMOrcThreadSafeContextRef Ref = nullptr;
 };