@@ -588,17 +588,27 @@ std::optional<std::string> get_md_string(llvm::Metadata *value) {
588
588
}
589
589
return std::nullopt;
590
590
}
591
+
592
+ bool get_modflag_bool (const llvm::Module &mod, const char *flag, bool or_default = false ) {
593
+ return get_md_bool (mod.getModuleFlag (flag)).value_or (or_default);
594
+ }
595
+
596
+ int get_modflag_int (const llvm::Module &mod, const char *flag, int or_default = 0 ) {
597
+ return get_md_int (mod.getModuleFlag (flag)).value_or (or_default);
598
+ }
599
+
600
+ std::string get_modflag_string (const llvm::Module &mod, const char *flag, std::string or_default = {}) {
601
+ return get_md_string (mod.getModuleFlag (flag)).value_or (or_default);
602
+ }
603
+
591
604
} // namespace
592
605
593
606
void get_target_options (const llvm::Module &module , llvm::TargetOptions &options) {
594
- bool use_soft_float_abi =
595
- get_md_bool (module .getModuleFlag (" halide_use_soft_float_abi" )).value_or (false );
596
- std::string mabi =
597
- get_md_string (module .getModuleFlag (" halide_mabi" )).value_or (std::string{});
607
+ bool use_soft_float_abi = get_modflag_bool (module , " halide_use_soft_float_abi" );
608
+ std::string mabi = get_modflag_string (module , " halide_mabi" );
598
609
599
610
// FIXME: can this be migrated into `set_function_attributes_from_halide_target_options()`?
600
- bool per_instruction_fast_math_flags =
601
- get_md_bool (module .getModuleFlag (" halide_per_instruction_fast_math_flags" )).value_or (false );
611
+ bool per_instruction_fast_math_flags = get_modflag_bool (module , " halide_per_instruction_fast_math_flags" );
602
612
603
613
options = llvm::TargetOptions ();
604
614
options.AllowFPOpFusion = per_instruction_fast_math_flags ? llvm::FPOpFusion::Strict : llvm::FPOpFusion::Fast;
@@ -610,8 +620,7 @@ void get_target_options(const llvm::Module &module, llvm::TargetOptions &options
610
620
options.GuaranteedTailCallOpt = false ;
611
621
options.FunctionSections = true ;
612
622
options.UseInitArray = true ;
613
- options.FloatABIType =
614
- use_soft_float_abi ? llvm::FloatABI::Soft : llvm::FloatABI::Hard;
623
+ options.FloatABIType = use_soft_float_abi ? llvm::FloatABI::Soft : llvm::FloatABI::Hard;
615
624
#if LLVM_VERSION >= 190
616
625
options.MCOptions .X86RelaxRelocations = false ;
617
626
#else
@@ -628,7 +637,7 @@ void clone_target_options(const llvm::Module &from, llvm::Module &to) {
628
637
// Clone bool metadata
629
638
for (const char *s : {" halide_use_soft_float_abi" ,
630
639
" halide_use_pic" ,
631
- " halide_keep_frame_pointer " }) {
640
+ " halide_enable_backtraces " }) {
632
641
if (auto md = get_md_bool (from.getModuleFlag (s))) {
633
642
to.addModuleFlag (llvm::Module::Warning, s, *md ? 1 : 0 );
634
643
}
@@ -659,17 +668,12 @@ std::unique_ptr<llvm::TargetMachine> make_target_machine(const llvm::Module &mod
659
668
llvm::TargetOptions options;
660
669
get_target_options (module , options);
661
670
662
- bool use_pic =
663
- get_md_bool (module .getModuleFlag (" halide_use_pic" )).value_or (true );
664
-
665
- bool use_large_code_model =
666
- get_md_bool (module .getModuleFlag (" halide_use_large_code_model" )).value_or (false );
671
+ bool use_pic = get_modflag_bool (module , " halide_use_pic" , true );
672
+ bool use_large_code_model = get_modflag_bool (module , " halide_use_large_code_model" );
667
673
668
674
// Get module mcpu_target and mattrs.
669
- std::string mcpu_target =
670
- get_md_string (module .getModuleFlag (" halide_mcpu_target" )).value_or (std::string{});
671
- std::string mattrs =
672
- get_md_string (module .getModuleFlag (" halide_mattrs" )).value_or (std::string{});
675
+ std::string mcpu_target = get_modflag_string (module , " halide_mcpu_target" );
676
+ std::string mattrs = get_modflag_string (module , " halide_mattrs" );
673
677
674
678
auto *tm = llvm_target->createTargetMachine (
675
679
#if LLVM_VERSION >= 210
@@ -689,17 +693,18 @@ std::unique_ptr<llvm::TargetMachine> make_target_machine(const llvm::Module &mod
689
693
void set_function_attributes_from_halide_target_options (llvm::Function &fn) {
690
694
llvm::Module &module = *fn.getParent ();
691
695
692
- std::string mcpu_target = get_md_string (module . getModuleFlag ( " halide_mcpu_target" )). value_or (std::string{} );
693
- std::string mcpu_tune = get_md_string (module . getModuleFlag ( " halide_mcpu_tune" )). value_or (std::string{} );
694
- std::string mattrs = get_md_string (module . getModuleFlag ( " halide_mattrs" )). value_or (std::string{} );
695
- int64_t vscale_range = get_md_int (module . getModuleFlag ( " halide_effective_vscale" )). value_or ( 0 );
696
- bool keep_fp = get_md_int (module . getModuleFlag ( " halide_keep_frame_pointer " )). value_or ( 0 );
696
+ std::string mcpu_target = get_modflag_string (module , " halide_mcpu_target" );
697
+ std::string mcpu_tune = get_modflag_string (module , " halide_mcpu_tune" );
698
+ std::string mattrs = get_modflag_string (module , " halide_mattrs" );
699
+ int64_t vscale_range = get_modflag_int (module , " halide_effective_vscale" );
700
+ bool enable_bt = get_modflag_int (module , " halide_enable_backtraces " );
697
701
698
702
fn.addFnAttr (" target-cpu" , mcpu_target);
699
703
fn.addFnAttr (" tune-cpu" , mcpu_tune);
700
704
fn.addFnAttr (" target-features" , mattrs);
701
- if (keep_fp ) {
705
+ if (enable_bt ) {
702
706
fn.addFnAttr (" frame-pointer" , " all" );
707
+ fn.setUWTableKind (llvm::UWTableKind::Default);
703
708
}
704
709
705
710
// Halide-generated IR is not exception-safe.
0 commit comments