Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/CodeGen_ARM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,10 +2086,13 @@ void CodeGen_ARM::visit(const Shuffle *op) {

#if LLVM_VERSION >= 240
// LLVM 24 folds slices into deinterleave shuffles, obscuring the
// interleaved-load pattern. Load one native-width result at a time.
// interleaved-load pattern, and removed InterleavedAccessPass lowering
// of multi-vector SVE deinterleave intrinsics (whose post-legalize DAG
// combine fails to match consecutive loads under vscale_range). Load
// one native-width result at a time.
const Ramp *ramp = load->index.as<Ramp>();
internal_assert(ramp && is_const_one(ramp->stride));
const int native_lanes = target_vscale() == 0 ? native_vector_bits() / op->type.bits() : op->type.lanes();
const int native_lanes = native_vector_bits() / op->type.bits();
vector<Value *> slices;
for (int i = 0; i < op->type.lanes(); i += native_lanes) {
const int slice_lanes = std::min(native_lanes, op->type.lanes() - i);
Expand Down
60 changes: 27 additions & 33 deletions src/CodeGen_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,47 +622,37 @@ const llvm::cl::LibraryOptionsContext *get_arm64e_x1_library_options() {
static std::once_flag init_once;
std::call_once(init_once, []() {
CodeGen_LLVM::initialize_llvm();
std::vector<std::string> env_tokens;
std::string env_args = get_env_variable("HL_LLVM_ARGS");
if (!env_args.empty()) {
env_tokens = split_string(env_args, " ");
}
std::vector<const char *> c_args = {"llc"};
bool next_is_featcpa_value = false;
for (const std::string &tok : env_tokens) {
if (tok.empty()) {
continue;
}
if (next_is_featcpa_value) {
next_is_featcpa_value = false;
if (tok[0] != '-') {
c_args.push_back(tok.c_str());
continue;
}
}
llvm::StringRef stripped(tok);
stripped.consume_front("-");
stripped.consume_front("-");
if (stripped.starts_with("aarch64-use-featcpa-codegen")) {
c_args.push_back(tok.c_str());
next_is_featcpa_value = !stripped.contains('=');
}
}
if (c_args.size() == 1) {
c_args.push_back("-aarch64-use-featcpa-codegen=true");
}
const llvm::cl::LibraryOptionsContext &base = get_llvm_library_options();
// In LLVM 24+, target backend flags migrated from cl::opt to per-context
// TableGen LibraryOptions read from TargetOptions::MCOptions::LibraryOptions.
// Pass &llvm::nulls() so this stays non-fatal if a future LLVM release
// enables CPA codegen unconditionally and removes the flag.
llvm::cl::parseCommandLineOptions(ctx, c_args, "Halide compiler\n", &llvm::nulls());
// Enable aarch64-use-featcpa-codegen first, then replay any LibraryOptions
// parsed from HL_LLVM_ARGS so explicit user overrides still win and other
// HL_LLVM_ARGS flags remain active. Pass &llvm::nulls() so this stays
// non-fatal if a future LLVM release enables CPA codegen unconditionally
// and removes the flag.
std::vector<const char *> default_args = {"llc", "-aarch64-use-featcpa-codegen=true"};
llvm::cl::parseCommandLineOptions(ctx, default_args, "Halide compiler\n", &llvm::nulls());
if (!base.args().empty()) {
std::vector<const char *> replay_args;
replay_args.reserve(base.args().size() + 1);
replay_args.push_back("llc");
replay_args.insert(replay_args.end(), base.args().begin(), base.args().end());
llvm::cl::parseCommandLineOptions(ctx, replay_args, "Halide compiler\n", &llvm::nulls());
}
});
return &ctx;
}
#endif

} // namespace

#if LLVM_VERSION >= 240
llvm::cl::LibraryOptionsContext &get_llvm_library_options() {
static llvm::cl::LibraryOptionsContext ctx;
return ctx;
}
#endif

void get_target_options(const llvm::Module &module, llvm::TargetOptions &options) {
std::string mabi = get_modflag_string(module, "halide_mabi");

Expand All @@ -685,11 +675,15 @@ void get_target_options(const llvm::Module &module, llvm::TargetOptions &options
options.UseInitArray = true;
options.MCOptions.X86RelaxRelocations = false;
options.MCOptions.ABIName = mabi;
#if defined(WITH_AARCH64) && LLVM_VERSION >= 240
#if LLVM_VERSION >= 240
CodeGen_LLVM::initialize_llvm();
options.MCOptions.LibraryOptions = &get_llvm_library_options();
#ifdef WITH_AARCH64
if (get_modflag_bool(module, "halide_arm64e_x1")) {
options.MCOptions.LibraryOptions = get_arm64e_x1_library_options();
}
#endif
#endif
}

void clone_target_options(const llvm::Module &from, llvm::Module &to) {
Expand Down
11 changes: 11 additions & 0 deletions src/CodeGen_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class Type;
class Value;
template<typename, typename>
class IRBuilder;
#if LLVM_VERSION >= 240
namespace cl {
class LibraryOptionsContext;
} // namespace cl
#endif
} // namespace llvm

namespace Halide {
Expand Down Expand Up @@ -98,6 +103,12 @@ Expr lower_round_half_away_from_zero(const Expr &);
/** Given an llvm::Module, set llvm:TargetOptions information */
void get_target_options(const llvm::Module &module, llvm::TargetOptions &options);

#if LLVM_VERSION >= 240
/** Return the process-wide LLVM LibraryOptionsContext populated from
* HL_LLVM_ARGS during CodeGen_LLVM::initialize_llvm(). */
llvm::cl::LibraryOptionsContext &get_llvm_library_options();
#endif

/** Given two llvm::Modules, clone target options from one to the other */
void clone_target_options(const llvm::Module &from, llvm::Module &to);

Expand Down
7 changes: 7 additions & 0 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ CodeGen_LLVM::CodeGen_LLVM(const Target &t)

void CodeGen_LLVM::set_context(llvm::LLVMContext &context) {
this->context = &context;
#if LLVM_VERSION >= 240
context.getLibraryOptions().assign(get_llvm_library_options());
#endif
set_effective_vscale(target_vscale());
}

Expand Down Expand Up @@ -284,7 +287,11 @@ void CodeGen_LLVM::initialize_llvm() {
c_arg_vec.push_back(s.c_str());
}
}
#if LLVM_VERSION >= 240
cl::parseCommandLineOptions(get_llvm_library_options(), c_arg_vec, "Halide compiler\n");
#else
cl::ParseCommandLineOptions((int)(c_arg_vec.size()), &c_arg_vec[0], "Halide compiler\n");
#endif
}
});
}
Expand Down
3 changes: 3 additions & 0 deletions src/CodeGen_PTX_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ class CodeGen_PTX_Dev : public CodeGen_LLVM, public CodeGen_GPU_Dev {
CodeGen_PTX_Dev::CodeGen_PTX_Dev(const Target &host)
: CodeGen_LLVM(host) {
context = new llvm::LLVMContext();
#if LLVM_VERSION >= 240
context->getLibraryOptions().assign(get_llvm_library_options());
#endif
}

CodeGen_PTX_Dev::~CodeGen_PTX_Dev() {
Expand Down
25 changes: 15 additions & 10 deletions src/JITModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
#include <set>
#include <string>

#ifdef _WIN32
#ifdef _MSC_VER
#define NOMINMAX
#endif
#include <windows.h>
#else
#include <dlfcn.h>
#include <sys/mman.h>
#endif

#include "CodeGen_Internal.h"
#include "CodeGen_LLVM.h"
#include "Debug.h"
Expand All @@ -25,6 +15,18 @@
#include "Util.h"
#include "WasmExecutor.h"

// Must be included after LLVM_Headers.h because <windows.h> defines macros
// (e.g. IMAGE_FILE_MACHINE_UNKNOWN) that conflict with llvm/BinaryFormat/COFF.h.
#ifdef _WIN32
#ifdef _MSC_VER
#define NOMINMAX
#endif
#include <windows.h>
#else
#include <dlfcn.h>
#include <sys/mman.h>
#endif

namespace Halide {
namespace Internal {

Expand Down Expand Up @@ -362,6 +364,9 @@ void compile_module_impl(

// Ensure that LLVM is initialized
CodeGen_LLVM::initialize_llvm();
#if LLVM_VERSION >= 240
m->getContext().getLibraryOptions().assign(get_llvm_library_options());
#endif

if (!WasmModule::can_jit_target(target)) {
auto pac_abi = [](const Target &x) {
Expand Down
20 changes: 10 additions & 10 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading