Add tests to the passes
@@ -4,6 +4,11 @@ use self::inkwell::OptimizationLevel::Aggressive;
use self::inkwell::context::Context;
use self::inkwell::passes::{PassManagerBuilder, PassManager, PassRegistry};
+#[llvm_versions(13.0..=latest)]
+use self::inkwell::passes::PassBuilderOptions;
+use self::inkwell::targets::{RelocMode, CodeModel, Target, TargetMachine, InitializationConfig};
+use self::inkwell::OptimizationLevel;
+
#[test]
fn test_init_all_passes_for_module() {
let context = Context::create();
@@ -179,3 +184,69 @@ fn test_pass_registry() {
feature = "llvm4-0", feature = "llvm5-0", feature = "llvm6-0")))]
pass_registry.initialize_aggressive_inst_combiner();
}
+
+#[llvm_versions(13.0..=latest)]
+#[test]
+fn test_run_passes() {
+ let pass_options = PassBuilderOptions::create();
+ pass_options.set_verify_each(true);
+ pass_options.set_debug_logging(true);
+ pass_options.set_loop_interleaving(true);
+ pass_options.set_loop_vectorization(true);
+ pass_options.set_loop_slp_vectorization(true);
+ pass_options.set_loop_unrolling(true);
+ pass_options.set_forget_all_scev_in_loop_unroll(true);
+ pass_options.set_licm_mssa_opt_cap(1);
+ pass_options.set_licm_mssa_no_acc_for_promotion_cap(10);
+ pass_options.set_call_graph_profile(true);
+ pass_options.set_merge_functions(true);
+
+ let initialization_config = &inkwell::targets::InitializationConfig::default();
+ inkwell::targets::Target::initialize_all(initialization_config);
+ let context = Context::create();
+ let module = context.create_module("my_module");
+ let triple = inkwell::targets::TargetMachine::get_default_triple();
+ let target = inkwell::targets::Target::from_triple(&triple).unwrap();
+ let machine = target
+ .create_target_machine(
+ &triple,
+ //TODO : Add cpu features as optionals
+ "generic", //TargetMachine::get_host_cpu_name().to_string().as_str(),
+ "", //TargetMachine::get_host_cpu_features().to_string().as_str(),
+ inkwell::OptimizationLevel::Default,
+ inkwell::targets::RelocMode::Default,
+ inkwell::targets::CodeModel::Default,
+ )
+ .unwrap();
+
+ module.run_passes("default<O2>", &machine, pass_options).unwrap();
+}
+
+#[llvm_versions(13.0..=latest)]
+#[test]
+fn test_run_passes_invalid() {
+ let pass_options = PassBuilderOptions::create();
+
+ let initialization_config = &InitializationConfig::default();
+ Target::initialize_all(initialization_config);
+ let context = Context::create();
+ let module = context.create_module("my_module");
+ let triple = TargetMachine::get_default_triple();
+ let target = Target::from_triple(&triple).unwrap();
+ let machine = target
+ .create_target_machine(
+ &triple,
+ //TODO : Add cpu features as optionals
+ TargetMachine::get_host_cpu_name().to_string().as_str(),
+ TargetMachine::get_host_cpu_features().to_string().as_str(),
+ OptimizationLevel::Default,
+ RelocMode::Default,
+ CodeModel::Default,
+ )
+ .unwrap();
+
+ let res = module.run_passes("invalid_pass", &machine, pass_options);
+ assert!(res.is_err());
+ assert_eq!(res.unwrap_err().to_str().unwrap(), "unknown pass name 'invalid_pass'");
+
+}
