xref: /minix3/external/bsd/llvm/dist/llvm/unittests/ExecutionEngine/MCJIT/MCJITMultipleModuleTest.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc //===- MCJITMultipeModuleTest.cpp - Unit tests for the MCJIT---------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc //                     The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This test suite verifies MCJIT for handling multiple modules in a single
11f4a2713aSLionel Sambuc // ExecutionEngine by building multiple modules, making function calls across
12f4a2713aSLionel Sambuc // modules, accessing global variables, etc.
13f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
14f4a2713aSLionel Sambuc 
15f4a2713aSLionel Sambuc #include "llvm/ExecutionEngine/MCJIT.h"
16f4a2713aSLionel Sambuc #include "MCJITTestBase.h"
17f4a2713aSLionel Sambuc #include "gtest/gtest.h"
18f4a2713aSLionel Sambuc 
19f4a2713aSLionel Sambuc using namespace llvm;
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc namespace {
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc class MCJITMultipleModuleTest : public testing::Test, public MCJITTestBase {};
24f4a2713aSLionel Sambuc 
25f4a2713aSLionel Sambuc // FIXME: ExecutionEngine has no support empty modules
26f4a2713aSLionel Sambuc /*
27f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, multiple_empty_modules) {
28f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
29f4a2713aSLionel Sambuc 
30f4a2713aSLionel Sambuc   createJIT(M.take());
31f4a2713aSLionel Sambuc   // JIT-compile
32f4a2713aSLionel Sambuc   EXPECT_NE(0, TheJIT->getObjectImage())
33f4a2713aSLionel Sambuc     << "Unable to generate executable loaded object image";
34f4a2713aSLionel Sambuc 
35f4a2713aSLionel Sambuc   TheJIT->addModule(createEmptyModule("<other module>"));
36f4a2713aSLionel Sambuc   TheJIT->addModule(createEmptyModule("<other other module>"));
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc   // JIT again
39f4a2713aSLionel Sambuc   EXPECT_NE(0, TheJIT->getObjectImage())
40f4a2713aSLionel Sambuc     << "Unable to generate executable loaded object image";
41f4a2713aSLionel Sambuc }
42f4a2713aSLionel Sambuc */
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc // Helper Function to test add operation
checkAdd(uint64_t ptr)45f4a2713aSLionel Sambuc void checkAdd(uint64_t ptr) {
46f4a2713aSLionel Sambuc   ASSERT_TRUE(ptr != 0) << "Unable to get pointer to function.";
47f4a2713aSLionel Sambuc   int (*AddPtr)(int, int) = (int (*)(int, int))ptr;
48f4a2713aSLionel Sambuc   EXPECT_EQ(0, AddPtr(0, 0));
49f4a2713aSLionel Sambuc   EXPECT_EQ(1, AddPtr(1, 0));
50f4a2713aSLionel Sambuc   EXPECT_EQ(3, AddPtr(1, 2));
51f4a2713aSLionel Sambuc   EXPECT_EQ(-5, AddPtr(-2, -3));
52f4a2713aSLionel Sambuc   EXPECT_EQ(30, AddPtr(10, 20));
53f4a2713aSLionel Sambuc   EXPECT_EQ(-30, AddPtr(-10, -20));
54f4a2713aSLionel Sambuc   EXPECT_EQ(-40, AddPtr(-10, -30));
55f4a2713aSLionel Sambuc }
56f4a2713aSLionel Sambuc 
checkAccumulate(uint64_t ptr)57f4a2713aSLionel Sambuc void checkAccumulate(uint64_t ptr) {
58f4a2713aSLionel Sambuc   ASSERT_TRUE(ptr != 0) << "Unable to get pointer to function.";
59f4a2713aSLionel Sambuc   int32_t (*FPtr)(int32_t) = (int32_t (*)(int32_t))(intptr_t)ptr;
60f4a2713aSLionel Sambuc   EXPECT_EQ(0, FPtr(0));
61f4a2713aSLionel Sambuc   EXPECT_EQ(1, FPtr(1));
62f4a2713aSLionel Sambuc   EXPECT_EQ(3, FPtr(2));
63f4a2713aSLionel Sambuc   EXPECT_EQ(6, FPtr(3));
64f4a2713aSLionel Sambuc   EXPECT_EQ(10, FPtr(4));
65f4a2713aSLionel Sambuc   EXPECT_EQ(15, FPtr(5));
66f4a2713aSLionel Sambuc }
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc // FIXME: ExecutionEngine has no support empty modules
69f4a2713aSLionel Sambuc /*
70f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, multiple_empty_modules) {
71f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
72f4a2713aSLionel Sambuc 
73f4a2713aSLionel Sambuc   createJIT(M.take());
74f4a2713aSLionel Sambuc   // JIT-compile
75f4a2713aSLionel Sambuc   EXPECT_NE(0, TheJIT->getObjectImage())
76f4a2713aSLionel Sambuc     << "Unable to generate executable loaded object image";
77f4a2713aSLionel Sambuc 
78f4a2713aSLionel Sambuc   TheJIT->addModule(createEmptyModule("<other module>"));
79f4a2713aSLionel Sambuc   TheJIT->addModule(createEmptyModule("<other other module>"));
80f4a2713aSLionel Sambuc 
81f4a2713aSLionel Sambuc   // JIT again
82f4a2713aSLionel Sambuc   EXPECT_NE(0, TheJIT->getObjectImage())
83f4a2713aSLionel Sambuc     << "Unable to generate executable loaded object image";
84f4a2713aSLionel Sambuc }
85f4a2713aSLionel Sambuc */
86f4a2713aSLionel Sambuc 
87f4a2713aSLionel Sambuc // Module A { Function FA },
88f4a2713aSLionel Sambuc // Module B { Function FB },
89f4a2713aSLionel Sambuc // execute FA then FB
TEST_F(MCJITMultipleModuleTest,two_module_case)90f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, two_module_case) {
91f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
92f4a2713aSLionel Sambuc 
93*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
94f4a2713aSLionel Sambuc   Function *FA, *FB;
95f4a2713aSLionel Sambuc   createTwoModuleCase(A, FA, B, FB);
96f4a2713aSLionel Sambuc 
97*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
98*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
99f4a2713aSLionel Sambuc 
100f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
101f4a2713aSLionel Sambuc   checkAdd(ptr);
102f4a2713aSLionel Sambuc 
103f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB->getName().str());
104f4a2713aSLionel Sambuc   checkAdd(ptr);
105f4a2713aSLionel Sambuc }
106f4a2713aSLionel Sambuc 
107f4a2713aSLionel Sambuc // Module A { Function FA },
108f4a2713aSLionel Sambuc // Module B { Function FB },
109f4a2713aSLionel Sambuc // execute FB then FA
TEST_F(MCJITMultipleModuleTest,two_module_reverse_case)110f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, two_module_reverse_case) {
111f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
112f4a2713aSLionel Sambuc 
113*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
114f4a2713aSLionel Sambuc   Function *FA, *FB;
115f4a2713aSLionel Sambuc   createTwoModuleCase(A, FA, B, FB);
116f4a2713aSLionel Sambuc 
117*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
118*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str());
121f4a2713aSLionel Sambuc   TheJIT->finalizeObject();
122f4a2713aSLionel Sambuc   checkAdd(ptr);
123f4a2713aSLionel Sambuc 
124f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FA->getName().str());
125f4a2713aSLionel Sambuc   checkAdd(ptr);
126f4a2713aSLionel Sambuc }
127f4a2713aSLionel Sambuc 
128f4a2713aSLionel Sambuc // Module A { Function FA },
129f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB which calls FA },
130f4a2713aSLionel Sambuc // execute FB then FA
TEST_F(MCJITMultipleModuleTest,two_module_extern_reverse_case)131f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, two_module_extern_reverse_case) {
132f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
133f4a2713aSLionel Sambuc 
134*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
135f4a2713aSLionel Sambuc   Function *FA, *FB;
136f4a2713aSLionel Sambuc   createTwoModuleExternCase(A, FA, B, FB);
137f4a2713aSLionel Sambuc 
138*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
139*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
140f4a2713aSLionel Sambuc 
141f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str());
142f4a2713aSLionel Sambuc   TheJIT->finalizeObject();
143f4a2713aSLionel Sambuc   checkAdd(ptr);
144f4a2713aSLionel Sambuc 
145f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FA->getName().str());
146f4a2713aSLionel Sambuc   checkAdd(ptr);
147f4a2713aSLionel Sambuc }
148f4a2713aSLionel Sambuc 
149f4a2713aSLionel Sambuc // Module A { Function FA },
150f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB which calls FA },
151f4a2713aSLionel Sambuc // execute FA then FB
TEST_F(MCJITMultipleModuleTest,two_module_extern_case)152f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, two_module_extern_case) {
153f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
154f4a2713aSLionel Sambuc 
155*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
156f4a2713aSLionel Sambuc   Function *FA, *FB;
157f4a2713aSLionel Sambuc   createTwoModuleExternCase(A, FA, B, FB);
158f4a2713aSLionel Sambuc 
159*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
160*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
161f4a2713aSLionel Sambuc 
162f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
163f4a2713aSLionel Sambuc   checkAdd(ptr);
164f4a2713aSLionel Sambuc 
165f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB->getName().str());
166f4a2713aSLionel Sambuc   checkAdd(ptr);
167f4a2713aSLionel Sambuc }
168f4a2713aSLionel Sambuc 
169f4a2713aSLionel Sambuc // Module A { Function FA1, Function FA2 which calls FA1 },
170f4a2713aSLionel Sambuc // Module B { Extern FA1, Function FB which calls FA1 },
171f4a2713aSLionel Sambuc // execute FB then FA2
TEST_F(MCJITMultipleModuleTest,two_module_consecutive_call_case)172f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, two_module_consecutive_call_case) {
173f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
174f4a2713aSLionel Sambuc 
175*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
176f4a2713aSLionel Sambuc   Function *FA1, *FA2, *FB;
177f4a2713aSLionel Sambuc   createTwoModuleExternCase(A, FA1, B, FB);
178f4a2713aSLionel Sambuc   FA2 = insertSimpleCallFunction<int32_t(int32_t, int32_t)>(A.get(), FA1);
179f4a2713aSLionel Sambuc 
180*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
181*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
182f4a2713aSLionel Sambuc 
183f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FB->getName().str());
184f4a2713aSLionel Sambuc   TheJIT->finalizeObject();
185f4a2713aSLionel Sambuc   checkAdd(ptr);
186f4a2713aSLionel Sambuc 
187f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FA2->getName().str());
188f4a2713aSLionel Sambuc   checkAdd(ptr);
189f4a2713aSLionel Sambuc }
190f4a2713aSLionel Sambuc 
191f4a2713aSLionel Sambuc // TODO:
192f4a2713aSLionel Sambuc // Module A { Extern Global GVB, Global Variable GVA, Function FA loads GVB },
193f4a2713aSLionel Sambuc // Module B { Extern Global GVA, Global Variable GVB, Function FB loads GVA },
194f4a2713aSLionel Sambuc 
195f4a2713aSLionel Sambuc 
196f4a2713aSLionel Sambuc // Module A { Global Variable GVA, Function FA loads GVA },
197f4a2713aSLionel Sambuc // Module B { Global Variable GVB, Function FB loads GVB },
198f4a2713aSLionel Sambuc // execute FB then FA
TEST_F(MCJITMultipleModuleTest,two_module_global_variables_case)199f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, two_module_global_variables_case) {
200f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
201f4a2713aSLionel Sambuc 
202*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
203f4a2713aSLionel Sambuc   Function *FA, *FB;
204f4a2713aSLionel Sambuc   GlobalVariable *GVA, *GVB;
205f4a2713aSLionel Sambuc   A.reset(createEmptyModule("A"));
206f4a2713aSLionel Sambuc   B.reset(createEmptyModule("B"));
207f4a2713aSLionel Sambuc 
208f4a2713aSLionel Sambuc   int32_t initialNum = 7;
209f4a2713aSLionel Sambuc   GVA = insertGlobalInt32(A.get(), "GVA", initialNum);
210f4a2713aSLionel Sambuc   GVB = insertGlobalInt32(B.get(), "GVB", initialNum);
211f4a2713aSLionel Sambuc   FA = startFunction<int32_t(void)>(A.get(), "FA");
212f4a2713aSLionel Sambuc   endFunctionWithRet(FA, Builder.CreateLoad(GVA));
213f4a2713aSLionel Sambuc   FB = startFunction<int32_t(void)>(B.get(), "FB");
214f4a2713aSLionel Sambuc   endFunctionWithRet(FB, Builder.CreateLoad(GVB));
215f4a2713aSLionel Sambuc 
216*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
217*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
218f4a2713aSLionel Sambuc 
219f4a2713aSLionel Sambuc   uint64_t FBPtr = TheJIT->getFunctionAddress(FB->getName().str());
220f4a2713aSLionel Sambuc   TheJIT->finalizeObject();
221f4a2713aSLionel Sambuc   EXPECT_TRUE(0 != FBPtr);
222f4a2713aSLionel Sambuc   int32_t(*FuncPtr)(void) = (int32_t(*)(void))FBPtr;
223f4a2713aSLionel Sambuc   EXPECT_EQ(initialNum, FuncPtr())
224f4a2713aSLionel Sambuc     << "Invalid value for global returned from JITted function in module B";
225f4a2713aSLionel Sambuc 
226f4a2713aSLionel Sambuc   uint64_t FAPtr = TheJIT->getFunctionAddress(FA->getName().str());
227f4a2713aSLionel Sambuc   EXPECT_TRUE(0 != FAPtr);
228f4a2713aSLionel Sambuc   FuncPtr = (int32_t(*)(void))FAPtr;
229f4a2713aSLionel Sambuc   EXPECT_EQ(initialNum, FuncPtr())
230f4a2713aSLionel Sambuc     << "Invalid value for global returned from JITted function in module A";
231f4a2713aSLionel Sambuc }
232f4a2713aSLionel Sambuc 
233f4a2713aSLionel Sambuc // Module A { Function FA },
234f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB which calls FA },
235f4a2713aSLionel Sambuc // Module C { Extern FA, Function FC which calls FA },
236f4a2713aSLionel Sambuc // execute FC, FB, FA
TEST_F(MCJITMultipleModuleTest,three_module_case)237f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, three_module_case) {
238f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
239f4a2713aSLionel Sambuc 
240*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B, C;
241f4a2713aSLionel Sambuc   Function *FA, *FB, *FC;
242f4a2713aSLionel Sambuc   createThreeModuleCase(A, FA, B, FB, C, FC);
243f4a2713aSLionel Sambuc 
244*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
245*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
246*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(C));
247f4a2713aSLionel Sambuc 
248f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FC->getName().str());
249f4a2713aSLionel Sambuc   checkAdd(ptr);
250f4a2713aSLionel Sambuc 
251f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB->getName().str());
252f4a2713aSLionel Sambuc   checkAdd(ptr);
253f4a2713aSLionel Sambuc 
254f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FA->getName().str());
255f4a2713aSLionel Sambuc   checkAdd(ptr);
256f4a2713aSLionel Sambuc }
257f4a2713aSLionel Sambuc 
258f4a2713aSLionel Sambuc // Module A { Function FA },
259f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB which calls FA },
260f4a2713aSLionel Sambuc // Module C { Extern FA, Function FC which calls FA },
261f4a2713aSLionel Sambuc // execute FA, FB, FC
TEST_F(MCJITMultipleModuleTest,three_module_case_reverse_order)262f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, three_module_case_reverse_order) {
263f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
264f4a2713aSLionel Sambuc 
265*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B, C;
266f4a2713aSLionel Sambuc   Function *FA, *FB, *FC;
267f4a2713aSLionel Sambuc   createThreeModuleCase(A, FA, B, FB, C, FC);
268f4a2713aSLionel Sambuc 
269*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
270*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
271*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(C));
272f4a2713aSLionel Sambuc 
273f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
274f4a2713aSLionel Sambuc   checkAdd(ptr);
275f4a2713aSLionel Sambuc 
276f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB->getName().str());
277f4a2713aSLionel Sambuc   checkAdd(ptr);
278f4a2713aSLionel Sambuc 
279f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FC->getName().str());
280f4a2713aSLionel Sambuc   checkAdd(ptr);
281f4a2713aSLionel Sambuc }
282f4a2713aSLionel Sambuc 
283f4a2713aSLionel Sambuc // Module A { Function FA },
284f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB which calls FA },
285f4a2713aSLionel Sambuc // Module C { Extern FB, Function FC which calls FB },
286f4a2713aSLionel Sambuc // execute FC, FB, FA
TEST_F(MCJITMultipleModuleTest,three_module_chain_case)287f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, three_module_chain_case) {
288f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
289f4a2713aSLionel Sambuc 
290*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B, C;
291f4a2713aSLionel Sambuc   Function *FA, *FB, *FC;
292f4a2713aSLionel Sambuc   createThreeModuleChainedCallsCase(A, FA, B, FB, C, FC);
293f4a2713aSLionel Sambuc 
294*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
295*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
296*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(C));
297f4a2713aSLionel Sambuc 
298f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FC->getName().str());
299f4a2713aSLionel Sambuc   checkAdd(ptr);
300f4a2713aSLionel Sambuc 
301f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB->getName().str());
302f4a2713aSLionel Sambuc   checkAdd(ptr);
303f4a2713aSLionel Sambuc 
304f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FA->getName().str());
305f4a2713aSLionel Sambuc   checkAdd(ptr);
306f4a2713aSLionel Sambuc }
307f4a2713aSLionel Sambuc 
308f4a2713aSLionel Sambuc // Module A { Function FA },
309f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB which calls FA },
310f4a2713aSLionel Sambuc // Module C { Extern FB, Function FC which calls FB },
311f4a2713aSLionel Sambuc // execute FA, FB, FC
TEST_F(MCJITMultipleModuleTest,three_modules_chain_case_reverse_order)312f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, three_modules_chain_case_reverse_order) {
313f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
314f4a2713aSLionel Sambuc 
315*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B, C;
316f4a2713aSLionel Sambuc   Function *FA, *FB, *FC;
317f4a2713aSLionel Sambuc   createThreeModuleChainedCallsCase(A, FA, B, FB, C, FC);
318f4a2713aSLionel Sambuc 
319*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
320*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
321*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(C));
322f4a2713aSLionel Sambuc 
323f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
324f4a2713aSLionel Sambuc   checkAdd(ptr);
325f4a2713aSLionel Sambuc 
326f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB->getName().str());
327f4a2713aSLionel Sambuc   checkAdd(ptr);
328f4a2713aSLionel Sambuc 
329f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FC->getName().str());
330f4a2713aSLionel Sambuc   checkAdd(ptr);
331f4a2713aSLionel Sambuc }
332f4a2713aSLionel Sambuc 
333f4a2713aSLionel Sambuc // Module A { Extern FB, Function FA which calls FB1 },
334f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB1, Function FB2 which calls FA },
335f4a2713aSLionel Sambuc // execute FA, then FB1
336f4a2713aSLionel Sambuc // FIXME: this test case is not supported by MCJIT
TEST_F(MCJITMultipleModuleTest,cross_module_dependency_case)337f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case) {
338f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
339f4a2713aSLionel Sambuc 
340*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
341f4a2713aSLionel Sambuc   Function *FA, *FB1, *FB2;
342f4a2713aSLionel Sambuc   createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
343f4a2713aSLionel Sambuc 
344*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
345*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
346f4a2713aSLionel Sambuc 
347f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FA->getName().str());
348f4a2713aSLionel Sambuc   checkAccumulate(ptr);
349f4a2713aSLionel Sambuc 
350f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB1->getName().str());
351f4a2713aSLionel Sambuc   checkAccumulate(ptr);
352f4a2713aSLionel Sambuc }
353f4a2713aSLionel Sambuc 
354f4a2713aSLionel Sambuc // Module A { Extern FB, Function FA which calls FB1 },
355f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB1, Function FB2 which calls FA },
356f4a2713aSLionel Sambuc // execute FB1 then FA
357f4a2713aSLionel Sambuc // FIXME: this test case is not supported by MCJIT
TEST_F(MCJITMultipleModuleTest,cross_module_dependency_case_reverse_order)358f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case_reverse_order) {
359f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
360f4a2713aSLionel Sambuc 
361*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
362f4a2713aSLionel Sambuc   Function *FA, *FB1, *FB2;
363f4a2713aSLionel Sambuc   createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
364f4a2713aSLionel Sambuc 
365*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
366*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
367f4a2713aSLionel Sambuc 
368f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FB1->getName().str());
369f4a2713aSLionel Sambuc   checkAccumulate(ptr);
370f4a2713aSLionel Sambuc 
371f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FA->getName().str());
372f4a2713aSLionel Sambuc   checkAccumulate(ptr);
373f4a2713aSLionel Sambuc }
374f4a2713aSLionel Sambuc 
375f4a2713aSLionel Sambuc // Module A { Extern FB1, Function FA which calls FB1 },
376f4a2713aSLionel Sambuc // Module B { Extern FA, Function FB1, Function FB2 which calls FA },
377f4a2713aSLionel Sambuc // execute FB1 then FB2
378f4a2713aSLionel Sambuc // FIXME: this test case is not supported by MCJIT
TEST_F(MCJITMultipleModuleTest,cross_module_dependency_case3)379f4a2713aSLionel Sambuc TEST_F(MCJITMultipleModuleTest, cross_module_dependency_case3) {
380f4a2713aSLionel Sambuc   SKIP_UNSUPPORTED_PLATFORM;
381f4a2713aSLionel Sambuc 
382*0a6a1f1dSLionel Sambuc   std::unique_ptr<Module> A, B;
383f4a2713aSLionel Sambuc   Function *FA, *FB1, *FB2;
384f4a2713aSLionel Sambuc   createCrossModuleRecursiveCase(A, FA, B, FB1, FB2);
385f4a2713aSLionel Sambuc 
386*0a6a1f1dSLionel Sambuc   createJIT(std::move(A));
387*0a6a1f1dSLionel Sambuc   TheJIT->addModule(std::move(B));
388f4a2713aSLionel Sambuc 
389f4a2713aSLionel Sambuc   uint64_t ptr = TheJIT->getFunctionAddress(FB1->getName().str());
390f4a2713aSLionel Sambuc   checkAccumulate(ptr);
391f4a2713aSLionel Sambuc 
392f4a2713aSLionel Sambuc   ptr = TheJIT->getFunctionAddress(FB2->getName().str());
393f4a2713aSLionel Sambuc   checkAccumulate(ptr);
394f4a2713aSLionel Sambuc }
395f4a2713aSLionel Sambuc }
396