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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ repos:
hooks:
- id: cargo-fmt
- id: cargo-clippy
args: ["--all-targets", "--all-features", "--", "-W", "clippy::pedantic", "-W", "clippy::nursery"]
args: ["--locked", "--all-targets", "--all-features", "--", "-D", "warnings", "-W", "clippy::pedantic", "-W", "clippy::nursery"]
- id: cargo-test-doc
args: ["--all-features"]
- id: cargo-doc
Expand Down
22 changes: 11 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,13 @@ mod aux {
);
}

pub(crate) struct ModuleFlags {
pub struct ModuleFlags {
Comment thread
qartik marked this conversation as resolved.
values: BTreeMap<String, Vec<String>>,
malformed: BTreeSet<String>,
}

impl ModuleFlags {
pub(crate) fn get(&self, flag_name: &str) -> Option<&[String]> {
pub fn get(&self, flag_name: &str) -> Option<&[String]> {
self.values.get(flag_name).map(Vec::as_slice)
}

Expand All @@ -283,7 +283,7 @@ mod aux {
}
}

pub(crate) fn collect_module_flags(module: &Module) -> ModuleFlags {
pub fn collect_module_flags(module: &Module) -> ModuleFlags {
Comment thread
qartik marked this conversation as resolved.
let mut values = BTreeMap::<String, Vec<String>>::new();
let mut malformed = BTreeSet::new();

Expand Down Expand Up @@ -639,10 +639,10 @@ mod aux {
"",
)
}
.map_err(|e| format!("Failed to build GEP for qubit handle: {e}",))?;
.map_err(|e| format!("Failed to build GEP for qubit handle: {e}"))?;
builder
.build_load(i64_type, elem_ptr, "qbit")
.map_err(|e| format!("Failed to build load for qubit handle: {e}",))?
.map_err(|e| format!("Failed to build load for qubit handle: {e}"))?
};

// Create ___lazy_measure call
Expand All @@ -655,7 +655,7 @@ mod aux {

let call = builder.build_call(meas_func, &[q_handle.into()], "meas");
let call_result =
call.map_err(|e| format!("Failed to build call for lazy measure function: {e}",))?;
call.map_err(|e| format!("Failed to build call for lazy measure function: {e}"))?;
match call_result.try_as_basic_value() {
inkwell::values::ValueKind::Basic(bv) => bv,
inkwell::values::ValueKind::Instruction(_) => {
Expand Down Expand Up @@ -698,7 +698,7 @@ mod aux {
.ok_or_else(|| format!("{LOAD_QUBIT_FN} not found"))?;
let idx_call = builder
.build_call(idx_fn, &[qubit_ptr.into()], "qbit")
.map_err(|e| format!("Failed to build call to {LOAD_QUBIT_FN}: {e}",))?;
.map_err(|e| format!("Failed to build call to {LOAD_QUBIT_FN}: {e}"))?;
let q_handle = match idx_call.try_as_basic_value() {
inkwell::values::ValueKind::Basic(bv) => bv,
inkwell::values::ValueKind::Instruction(_) => {
Expand Down Expand Up @@ -1861,23 +1861,23 @@ attributes #0 = { "entry_point" "qir_profiles"="base_profile" "output_labeling_s

let flags = collect_module_flags(&module);
assert_eq!(
flags.get("qir_major_version").map(|values| values.to_vec()),
flags.get("qir_major_version").map(<[String]>::to_vec),
Some(vec!["i32 2".to_string()])
);
assert_eq!(
flags.get("qir_minor_version").map(|values| values.to_vec()),
flags.get("qir_minor_version").map(<[String]>::to_vec),
Some(vec!["i32 0".to_string()])
);
assert_eq!(
flags
.get("dynamic_qubit_management")
.map(|values| values.to_vec()),
.map(<[String]>::to_vec),
Some(vec!["i1 false".to_string()])
);
assert_eq!(
flags
.get("dynamic_result_management")
.map(|values| values.to_vec()),
.map(<[String]>::to_vec),
Some(vec!["i1 false".to_string()])
);
}
Expand Down
22 changes: 6 additions & 16 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,17 @@ fn get_target_machine(target: &str, opt_level: OptimizationLevel) -> Result<Targ
}
}

#[cfg(windows)]
fn validate_windows_codegen_mode(opt_level: u32, target: &str) -> Result<(), String> {
if opt_level > 0 {
return Err(format!(
"Optimized QIR-to-QIS conversion is currently unavailable on Windows with the LLVM 21 integration. Re-run with `opt_level=0` and preferably `target=\"native\"` (requested opt_level={opt_level}, target=\"{target}\")."
));
}
Ok(())
}

#[cfg(not(windows))]
fn validate_windows_codegen_mode(_opt_level: u32, _target: &str) -> Result<(), String> {
Ok(())
}

/// Optimize the given LLVM module using the specified optimization level and target architecture.
///
/// # Errors
/// Returns an error if module verification fails
pub fn optimize(module: &Module, opt_level: u32, target: &str) -> Result<(), String> {
validate_windows_codegen_mode(opt_level, target)?;
#[cfg(windows)]
if opt_level > 0 {
return Err(format!(
"Optimized QIR-to-QIS conversion is currently unavailable on Windows with the LLVM 21 integration. Re-run with `opt_level=0` and preferably `target=\"native\"` (requested opt_level={opt_level}, target=\"{target}\")."
));
}

// O0 preserves semantics without running transformation passes.
// Avoid creating a TargetMachine in this mode; TargetMachine teardown has
Expand Down
Loading