Skip to content

Commit

Permalink
Fix for llvm trunk: Force-include more runtime types (#8045)
Browse files Browse the repository at this point in the history
* Fix for llvm trunk: Force-include more runtime types

* Include the force-include-types module first

* Fix comment

* Expand comment
  • Loading branch information
abadams authored Jan 26, 2024
1 parent c1923f3 commit 4590a09
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/LLVM_Runtime_Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,7 @@ std::unique_ptr<llvm::Module> link_with_wasm_jit_runtime(llvm::LLVMContext *c, c
// things that are 'alwaysinline' can be included here but are unnecessary.
vector<std::unique_ptr<llvm::Module>> modules;
modules.push_back(std::move(extra_module));
modules.push_back(get_initmod_force_include_types(c, bits_64, debug));
modules.push_back(get_initmod_fake_thread_pool(c, bits_64, debug));
modules.push_back(get_initmod_posix_aligned_alloc(c, bits_64, debug));
modules.push_back(get_initmod_posix_allocator(c, bits_64, debug));
Expand All @@ -796,7 +797,6 @@ std::unique_ptr<llvm::Module> link_with_wasm_jit_runtime(llvm::LLVMContext *c, c
modules.push_back(get_initmod_alignment_32(c, bits_64, debug));
modules.push_back(get_initmod_fopen(c, bits_64, debug));
modules.push_back(get_initmod_device_interface(c, bits_64, debug));
modules.push_back(get_initmod_force_include_types(c, bits_64, debug));
modules.push_back(get_initmod_float16_t(c, bits_64, debug));
modules.push_back(get_initmod_errors(c, bits_64, debug));
modules.push_back(get_initmod_msan_stubs(c, bits_64, debug));
Expand Down Expand Up @@ -843,6 +843,17 @@ std::unique_ptr<llvm::Module> get_initial_module_for_target(Target t, llvm::LLVM

vector<std::unique_ptr<llvm::Module>> modules;

// Start with the module that defines our struct types. This must be
// included first, because when parsing modules, if two structs are
// encountered with the same fields, they are deduped, and the first name
// wins.
//
// If in the future these names become unpredictable, an alternative
// strategy is to make this module include a global variable of each type we
// care about, recover the struct types from those named globals, and then
// delete the globals in link_modules.
modules.push_back(get_initmod_force_include_types(c, bits_64, debug));

const auto add_allocator = [&]() {
modules.push_back(get_initmod_posix_aligned_alloc(c, bits_64, debug));
modules.push_back(get_initmod_posix_allocator(c, bits_64, debug));
Expand Down Expand Up @@ -1277,8 +1288,6 @@ std::unique_ptr<llvm::Module> get_initial_module_for_target(Target t, llvm::LLVM
modules.push_back(get_initmod_runtime_api(c, bits_64, debug));
}

modules.push_back(get_initmod_force_include_types(c, bits_64, debug));

link_modules(modules, t);

if (t.os == Target::Windows &&
Expand Down
17 changes: 13 additions & 4 deletions src/runtime/force_include_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ namespace Runtime {
namespace Internal {

struct AllTheTypes {
halide_filter_metadata_t a;
halide_filter_argument_t b;
halide_scalar_value_t c;
halide_semaphore_t d;
halide_buffer_t a;
halide_device_interface_t b;
halide_dimension_t c;
halide_filter_argument_t d;
halide_filter_metadata_t e;
halide_parallel_task_t f;
halide_pseudostack_slot_t g;
halide_scalar_value_t h;
halide_semaphore_acquire_t i;
halide_semaphore_t j;
halide_trace_event_t k;
halide_trace_packet_t l;
halide_type_t m;
};

WEAK void halide_unused_force_include_types() {
Expand Down

0 comments on commit 4590a09

Please sign in to comment.