|
21 | 21 | #include "LLVM_Output.h" |
22 | 22 | #include "LLVM_Runtime_Linker.h" |
23 | 23 | #include "Pipeline.h" |
| 24 | +#include "Util.h" |
24 | 25 | #include "WasmExecutor.h" |
25 | 26 |
|
26 | 27 | namespace Halide { |
@@ -295,9 +296,12 @@ JITModule::JITModule(const Module &m, const LoweredFunc &fn, |
295 | 296 | llvm::reportAndResetTimings(); |
296 | 297 | } |
297 | 298 |
|
298 | | -void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &function_name, const Target &target, |
299 | | - const std::vector<JITModule> &dependencies, |
300 | | - const std::vector<std::string> &requested_exports) { |
| 299 | +namespace { |
| 300 | +void compile_module_impl( |
| 301 | + IntrusivePtr<JITModuleContents> &jit_module, |
| 302 | + std::unique_ptr<llvm::Module> m, const string &function_name, const Target &target, |
| 303 | + const std::vector<JITModule> &dependencies, |
| 304 | + const std::vector<std::string> &requested_exports) { |
301 | 305 |
|
302 | 306 | // Ensure that LLVM is initialized |
303 | 307 | CodeGen_LLVM::initialize_llvm(); |
@@ -348,10 +352,10 @@ void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &fu |
348 | 352 | if ((target.arch == Target::Arch::X86 && target.bits == 32) || |
349 | 353 | (target.arch == Target::Arch::ARM && target.bits == 32) || |
350 | 354 | target.os == Target::Windows) { |
351 | | -// Fallback to RTDyld-based linking to workaround errors: |
352 | | -// i386: "JIT session error: Unsupported i386 relocation:4" (R_386_PLT32) |
353 | | -// ARM 32bit: Unsupported target machine architecture in ELF object shared runtime-jitted-objectbuffer |
354 | | -// Windows 64-bit: JIT session error: could not register eh-frame: __register_frame function not found |
| 355 | + // Fallback to RTDyld-based linking to workaround errors: |
| 356 | + // i386: "JIT session error: Unsupported i386 relocation:4" (R_386_PLT32) |
| 357 | + // ARM 32bit: Unsupported target machine architecture in ELF object shared runtime-jitted-objectbuffer |
| 358 | + // Windows 64-bit: JIT session error: could not register eh-frame: __register_frame function not found |
355 | 359 | #if LLVM_VERSION >= 210 |
356 | 360 | linkerBuilder = [&](llvm::orc::ExecutionSession &session) { |
357 | 361 | return std::make_unique<llvm::orc::RTDyldObjectLinkingLayer>(session, [&](const llvm::MemoryBuffer &) { |
@@ -424,6 +428,7 @@ void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &fu |
424 | 428 | debug(1) << "JIT compiling " << module_name |
425 | 429 | << " for " << target.to_string() << "\n"; |
426 | 430 |
|
| 431 | + using Symbol = JITModule::Symbol; |
427 | 432 | std::map<std::string, Symbol> exports; |
428 | 433 |
|
429 | 434 | Symbol entrypoint; |
@@ -451,6 +456,18 @@ void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &fu |
451 | 456 | jit_module->argv_entrypoint = argv_entrypoint; |
452 | 457 | jit_module->name = function_name; |
453 | 458 | } |
| 459 | +} // namespace |
| 460 | + |
| 461 | +void JITModule::compile_module(std::unique_ptr<llvm::Module> m, const string &function_name, const Target &target, |
| 462 | + const std::vector<JITModule> &dependencies, |
| 463 | + const std::vector<std::string> &requested_exports) { |
| 464 | + // LLJIT's SimpleCompiler triggers LLVM's AsmPrinter, which can use a large |
| 465 | + // amount of stack (observed stack overflows on macOS worker threads with |
| 466 | + // 512KB default stacks). Use run_with_large_stack to ensure enough space. |
| 467 | + run_with_large_stack([&]() { |
| 468 | + compile_module_impl(jit_module, std::move(m), function_name, target, dependencies, requested_exports); |
| 469 | + }); |
| 470 | +} |
454 | 471 |
|
455 | 472 | /*static*/ |
456 | 473 | JITModule JITModule::make_trampolines_module(const Target &target_arg, |
|
0 commit comments