Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit vscale_range() fn attribute in correct syntax #8457

Merged
merged 1 commit into from
Nov 6, 2024
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
24 changes: 17 additions & 7 deletions src/CodeGen_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ Expr lower_round_to_nearest_ties_to_even(const Expr &x) {
}

namespace {
bool get_md_bool(llvm::Metadata *value, bool &result) {
bool get_md_int(llvm::Metadata *value, int64_t &result) {
if (!value) {
return false;
}
Expand All @@ -572,10 +572,16 @@ bool get_md_bool(llvm::Metadata *value, bool &result) {
if (!c) {
return false;
}
result = !c->isZero();
result = c->getSExtValue();
return true;
}

bool get_md_bool(llvm::Metadata *value, bool &result) {
int64_t r;
if (!get_md_int(value, r)) {
return false;
}
return r != 0;
}
bool get_md_string(llvm::Metadata *value, std::string &result) {
if (!value) {
result = "";
Expand Down Expand Up @@ -698,11 +704,14 @@ std::unique_ptr<llvm::TargetMachine> make_target_machine(const llvm::Module &mod
void set_function_attributes_from_halide_target_options(llvm::Function &fn) {
llvm::Module &module = *fn.getParent();

std::string mcpu_target, mcpu_tune, mattrs, vscale_range;
std::string mcpu_target, mcpu_tune, mattrs;
get_md_string(module.getModuleFlag("halide_mcpu_target"), mcpu_target);
get_md_string(module.getModuleFlag("halide_mcpu_tune"), mcpu_tune);
get_md_string(module.getModuleFlag("halide_mattrs"), mattrs);
get_md_string(module.getModuleFlag("halide_vscale_range"), vscale_range);
int64_t vscale_range;
if (!get_md_int(module.getModuleFlag("halide_effective_vscale"), vscale_range)) {
vscale_range = 0;
}

fn.addFnAttr("target-cpu", mcpu_target);
fn.addFnAttr("tune-cpu", mcpu_tune);
Expand All @@ -723,8 +732,9 @@ void set_function_attributes_from_halide_target_options(llvm::Function &fn) {
fn.addFnAttr("reciprocal-estimates", "none");

// If a fixed vscale is asserted, add it as an attribute on the function.
if (!vscale_range.empty()) {
fn.addFnAttr("vscale_range", vscale_range);
if (vscale_range != 0) {
fn.addFnAttr(llvm::Attribute::getWithVScaleRangeArgs(
module.getContext(), vscale_range, vscale_range));
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,7 @@ void CodeGen_LLVM::init_codegen(const std::string &name, bool any_strict_float)
module->addModuleFlag(llvm::Module::Warning, "halide_use_large_code_model", llvm_large_code_model ? 1 : 0);
module->addModuleFlag(llvm::Module::Warning, "halide_per_instruction_fast_math_flags", any_strict_float);
if (effective_vscale != 0) {
module->addModuleFlag(llvm::Module::Warning, "halide_vscale_range",
MDString::get(*context, std::to_string(effective_vscale) + ", " + std::to_string(effective_vscale)));
module->addModuleFlag(llvm::Module::Warning, "halide_effective_vscale", effective_vscale);
}

// Ensure some types we need are defined
Expand Down
Loading