llvm.org GIT mirror llvm / 22af148
Revert "[ExecutionEngine] Use std::function rather than a function pointer for the LazyFunctionCreator." This reverts commit r241962, as it was breaking all ARM buildbots. It also reverts the two subsequent related commits: r241974: "[ExecutionEngine] Add a static cast to the unittest for r241962 to suppress a warning." r241973: "[ExecutionEngine] Remove cruft and fix a couple of warnings in the test case for r241962." git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241983 91177308-0d34-0410-b5e6-96231b3b80d8 Renato Golin 5 years ago
2 changed file(s) with 4 addition(s) and 71 deletion(s). Raw diff Collapse all Expand all
3030 #include
3131 #include
3232 #include
33 #include
3433
3534 namespace llvm {
3635
8988 uint64_t RemoveMapping(StringRef Name);
9089 };
9190
92 using FunctionCreator = std::function;
93
9491 /// \brief Abstract interface for implementation execution of LLVM modules,
9592 /// designed to support both interpreter and just-in-time (JIT) compiler
9693 /// implementations.
149146 /// LazyFunctionCreator - If an unknown function is needed, this function
150147 /// pointer is invoked to create it. If this returns null, the JIT will
151148 /// abort.
152 FunctionCreator LazyFunctionCreator;
149 void *(*LazyFunctionCreator)(const std::string &);
153150
154151 /// getMangledName - Get mangled name.
155152 std::string getMangledName(const GlobalValue *GV);
472469 /// InstallLazyFunctionCreator - If an unknown function is needed, the
473470 /// specified function pointer is invoked to create it. If it returns null,
474471 /// the JIT will abort.
475 void InstallLazyFunctionCreator(FunctionCreator C) {
476 LazyFunctionCreator = C;
472 void InstallLazyFunctionCreator(void* (*P)(const std::string &)) {
473 LazyFunctionCreator = P;
477474 }
478475
479476 protected:
198198 EXPECT_EQ(A, B) << "Repeat calls to getPointerToFunction fail.";
199199 }
200200
201 typedef void * (*FunctionHandlerPtr)(const std::string &str);
202
203 TEST_F(MCJITTest, lazy_function_creator_pointer) {
204 SKIP_UNSUPPORTED_PLATFORM;
205
206 Function *Foo = insertExternalReferenceToFunction(M.get(),
207 "\1Foo");
208 startFunction(M.get(), "Parent");
209 CallInst *Call = Builder.CreateCall(Foo, {});
210 Builder.CreateRet(Call);
211
212 createJIT(std::move(M));
213
214 // Set up the lazy function creator that records the name of the last
215 // unresolved external function found in the module. Using a function pointer
216 // prevents us from capturing local variables, which is why this is static.
217 static std::string UnresolvedExternal;
218 FunctionHandlerPtr UnresolvedHandler = [] (const std::string &str) {
219 UnresolvedExternal = str;
220 return (void *)(uintptr_t)-1;
221 };
222 TheJIT->InstallLazyFunctionCreator(UnresolvedHandler);
223
224 // JIT the module.
225 TheJIT->finalizeObject();
226
227 // Verify that our handler was called.
228 EXPECT_EQ(UnresolvedExternal, "Foo");
229 }
230
231 TEST_F(MCJITTest, lazy_function_creator_lambda) {
232 SKIP_UNSUPPORTED_PLATFORM;
233
234 Function *Foo1 = insertExternalReferenceToFunction(M.get(),
235 "\1Foo1");
236 Function *Foo2 = insertExternalReferenceToFunction(M.get(),
237 "\1Foo2");
238 startFunction(M.get(), "Parent");
239 CallInst *Call1 = Builder.CreateCall(Foo1, {});
240 CallInst *Call2 = Builder.CreateCall(Foo2, {});
241 Value *Result = Builder.CreateAdd(Call1, Call2);
242 Builder.CreateRet(Result);
243
244 createJIT(std::move(M));
245
246 // Set up the lazy function creator that records the name of unresolved
247 // external functions in the module.
248 std::vector UnresolvedExternals;
249 auto UnresolvedHandler = [&UnresolvedExternals] (const std::string &str) {
250 UnresolvedExternals.push_back(str);
251 return (void *)(uintptr_t)-1;
252 };
253 TheJIT->InstallLazyFunctionCreator(UnresolvedHandler);
254
255 // JIT the module.
256 TheJIT->finalizeObject();
257
258 // Verify that our handler was called for each unresolved function.
259 auto I = UnresolvedExternals.begin(), E = UnresolvedExternals.end();
260 EXPECT_EQ(UnresolvedExternals.size(), static_cast(2));
261 EXPECT_FALSE(std::find(I, E, "Foo1") == E);
262 EXPECT_FALSE(std::find(I, E, "Foo2") == E);
263 }
264
265 }
201 }