diff --git a/.gitignore b/.gitignore index 86373a293..55f58243a 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,9 @@ target/ # Failing proptest artifacts proptest-regressions/ +# snaphsot test failures +*.snap.new + # Devenv .devenv* devenv.local.nix diff --git a/hugr-core/src/std_extensions/collections/static_array.rs b/hugr-core/src/std_extensions/collections/static_array.rs index 8220d59ac..bc9fe6cbe 100644 --- a/hugr-core/src/std_extensions/collections/static_array.rs +++ b/hugr-core/src/std_extensions/collections/static_array.rs @@ -14,7 +14,8 @@ //! * `get: [static_array, prelude.usize] -> [[] + [T]]` //! * `len: [static_array] -> [prelude.usize]` use std::{ - hash, iter, + hash::{self, Hash as _}, + iter, sync::{self, Arc}, }; @@ -22,7 +23,10 @@ use crate::{ builder::{BuildError, Dataflow}, extension::{ prelude::{option_type, usize_t}, - resolution::{ExtensionResolutionError, WeakExtensionRegistry}, + resolution::{ + resolve_type_extensions, resolve_value_extensions, ExtensionResolutionError, + WeakExtensionRegistry, + }, simple_op::{ try_from_name, HasConcrete, HasDef, MakeExtensionOp, MakeOpDef, MakeRegisteredOp, OpLoadError, @@ -30,7 +34,7 @@ use crate::{ ExtensionId, ExtensionSet, OpDef, SignatureError, SignatureFunc, TypeDef, }, ops::{ - constant::{CustomConst, TryHash, ValueName}, + constant::{maybe_hash_values, CustomConst, TryHash, ValueName}, ExtensionOp, NamedOp, OpName, Value, }, types::{ @@ -41,9 +45,6 @@ use crate::{ Extension, Wire, }; -use super::array::ArrayValue; - -use delegate::delegate; use lazy_static::lazy_static; /// Reported unique name of the extension @@ -53,22 +54,25 @@ pub const STATIC_ARRAY_TYPENAME: TypeName = TypeName::new_inline("static_array") /// Extension version. pub const VERSION: semver::Version = semver::Version::new(0, 1, 0); -#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, derive_more::From)] +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize, derive_more::From)] /// Statically sized array of values, all of the same [TypeBound::Copyable] /// type. pub struct StaticArrayValue { - /// The contents of the `StaticArrayValue`. - pub value: ArrayValue, + values: Vec, + typ: Type, /// The name of the `StaticArrayValue`. pub name: String, } impl StaticArrayValue { - delegate! { - to self.value { - /// Returns the type of values inside the `[StaticArrayValue]`. - pub fn get_element_type(&self) -> &Type; - } + /// Returns the type of values inside the `[StaticArrayValue]`. + pub fn get_element_type(&self) -> &Type { + &self.typ + } + + /// Returns the values contained inside the `[StaticArrayValue]`. + pub fn get_contents(&self) -> &[Value] { + &self.values } /// Create a new [CustomConst] for an array of values of type `typ`. @@ -85,7 +89,8 @@ impl StaticArrayValue { .into()); } Ok(Self { - value: ArrayValue::new(typ, contents), + typ, + values: contents.into_iter().collect(), name: name.to_string(), }) } @@ -102,9 +107,12 @@ impl StaticArrayValue { } impl TryHash for StaticArrayValue { - fn try_hash(&self, st: &mut dyn hash::Hasher) -> bool { - st.write(self.name.as_bytes()); - self.value.try_hash(st) + fn try_hash(&self, mut st: &mut dyn hash::Hasher) -> bool { + maybe_hash_values(&self.values, &mut st) && { + self.name.hash(&mut st); + self.typ.hash(&mut st); + true + } } } @@ -123,17 +131,18 @@ impl CustomConst for StaticArrayValue { } fn extension_reqs(&self) -> ExtensionSet { - ExtensionSet::union_over(self.value.get_contents().iter().map(Value::extension_reqs)) + ExtensionSet::union_over(self.values.iter().map(Value::extension_reqs)) .union(EXTENSION_ID.into()) } - delegate! { - to self.value { - fn update_extensions( - &mut self, - extensions: &WeakExtensionRegistry, - ) -> Result<(), ExtensionResolutionError>; + fn update_extensions( + &mut self, + extensions: &WeakExtensionRegistry, + ) -> Result<(), ExtensionResolutionError> { + for val in &mut self.values { + resolve_value_extensions(val, extensions)?; } + resolve_type_extensions(&mut self.typ, extensions) } } diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop@pre-mem2reg@llvm14_2.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop@pre-mem2reg@llvm14_2.snap deleted file mode 100644 index 4b5b4ccf4..000000000 --- a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop@pre-mem2reg@llvm14_2.snap +++ /dev/null @@ -1,168 +0,0 @@ ---- -source: hugr-llvm/src/emit/test.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -define { { {} }, i64 } @_hl.main.1(i64 %0, i64 %1) { -alloca_block: - %"0" = alloca { {} }, align 8 - %"1" = alloca i64, align 8 - %"2_0" = alloca i64, align 8 - %"2_1" = alloca i64, align 8 - %"4_0" = alloca { {} }, align 8 - %"4_1" = alloca i64, align 8 - %"5_0" = alloca i64, align 8 - %"5_1" = alloca i64, align 8 - %"12_0" = alloca { i32, { i64 }, { { {} } } }, align 8 - %"12_1" = alloca i64, align 8 - %"8_0" = alloca i64, align 8 - %"10_0" = alloca { i32, { i64 }, { { {} } } }, align 8 - %"08" = alloca { i32, { i64 }, { { {} } } }, align 8 - %"19" = alloca i64, align 8 - %"012" = alloca i64, align 8 - %"113" = alloca i64, align 8 - %"19_0" = alloca i64, align 8 - %"17_0" = alloca i64, align 8 - %"14_0" = alloca i64, align 8 - %"14_1" = alloca i64, align 8 - %"20_0" = alloca i64, align 8 - %"21_0" = alloca i64, align 8 - %"22_0" = alloca { i32, { i64 }, { { {} } } }, align 8 - %"023" = alloca { {} }, align 8 - %"124" = alloca i64, align 8 - %"27_0" = alloca { {} }, align 8 - %"28_0" = alloca { i32, { i64 }, { { {} } } }, align 8 - %"24_0" = alloca { {} }, align 8 - %"24_1" = alloca i64, align 8 - %"9_0" = alloca { i32, {}, {} }, align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i64 %0, i64* %"2_0", align 4 - store i64 %1, i64* %"2_1", align 4 - %"2_01" = load i64, i64* %"2_0", align 4 - %"2_12" = load i64, i64* %"2_1", align 4 - store i64 %"2_01", i64* %"5_0", align 4 - store i64 %"2_12", i64* %"5_1", align 4 - br label %loop_body - -loop_body: ; preds = %20, %entry_block - %"5_03" = load i64, i64* %"5_0", align 4 - %"5_14" = load i64, i64* %"5_1", align 4 - store i64 0, i64* %"8_0", align 4 - store i64 %"5_03", i64* %"5_0", align 4 - store i64 %"5_14", i64* %"5_1", align 4 - %"5_05" = load i64, i64* %"5_0", align 4 - %2 = insertvalue { i64 } undef, i64 %"5_05", 0 - %3 = insertvalue { i32, { i64 }, { { {} } } } { i32 0, { i64 } poison, { { {} } } poison }, { i64 } %2, 1 - store { i32, { i64 }, { { {} } } } %3, { i32, { i64 }, { { {} } } }* %"10_0", align 4 - %"10_06" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"10_0", align 4 - %"5_17" = load i64, i64* %"5_1", align 4 - %4 = extractvalue { i32, { i64 }, { { {} } } } %"10_06", 0 - switch i32 %4, label %5 [ - i32 1, label %8 - ] - -5: ; preds = %loop_body - %6 = extractvalue { i32, { i64 }, { { {} } } } %"10_06", 1 - %7 = extractvalue { i64 } %6, 0 - store i64 %7, i64* %"012", align 4 - store i64 %"5_17", i64* %"113", align 4 - br label %cond_12_case_0 - -8: ; preds = %loop_body - %9 = extractvalue { i32, { i64 }, { { {} } } } %"10_06", 2 - %10 = extractvalue { { {} } } %9, 0 - store { {} } %10, { {} }* %"023", align 1 - store i64 %"5_17", i64* %"124", align 4 - br label %cond_12_case_1 - -loop_out: ; preds = %23 - %"4_036" = load { {} }, { {} }* %"4_0", align 1 - %"4_137" = load i64, i64* %"4_1", align 4 - store { {} } %"4_036", { {} }* %"0", align 1 - store i64 %"4_137", i64* %"1", align 4 - %"038" = load { {} }, { {} }* %"0", align 1 - %"139" = load i64, i64* %"1", align 4 - %mrv = insertvalue { { {} }, i64 } undef, { {} } %"038", 0 - %mrv40 = insertvalue { { {} }, i64 } %mrv, i64 %"139", 1 - ret { { {} }, i64 } %mrv40 - -cond_12_case_0: ; preds = %5 - %"014" = load i64, i64* %"012", align 4 - %"115" = load i64, i64* %"113", align 4 - store i64 2, i64* %"19_0", align 4 - store i64 1, i64* %"17_0", align 4 - store i64 %"014", i64* %"14_0", align 4 - store i64 %"115", i64* %"14_1", align 4 - %"14_116" = load i64, i64* %"14_1", align 4 - %"19_017" = load i64, i64* %"19_0", align 4 - %11 = mul i64 %"14_116", %"19_017" - store i64 %11, i64* %"20_0", align 4 - %"14_018" = load i64, i64* %"14_0", align 4 - %"17_019" = load i64, i64* %"17_0", align 4 - %12 = sub i64 %"14_018", %"17_019" - store i64 %12, i64* %"21_0", align 4 - %"21_020" = load i64, i64* %"21_0", align 4 - %13 = insertvalue { i64 } undef, i64 %"21_020", 0 - %14 = insertvalue { i32, { i64 }, { { {} } } } { i32 0, { i64 } poison, { { {} } } poison }, { i64 } %13, 1 - store { i32, { i64 }, { { {} } } } %14, { i32, { i64 }, { { {} } } }* %"22_0", align 4 - %"22_021" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"22_0", align 4 - %"20_022" = load i64, i64* %"20_0", align 4 - store { i32, { i64 }, { { {} } } } %"22_021", { i32, { i64 }, { { {} } } }* %"08", align 4 - store i64 %"20_022", i64* %"19", align 4 - br label %cond_exit_12 - -cond_12_case_1: ; preds = %8 - %"025" = load { {} }, { {} }* %"023", align 1 - %"126" = load i64, i64* %"124", align 4 - store { {} } undef, { {} }* %"27_0", align 1 - %"27_027" = load { {} }, { {} }* %"27_0", align 1 - %15 = insertvalue { { {} } } undef, { {} } %"27_027", 0 - %16 = insertvalue { i32, { i64 }, { { {} } } } { i32 1, { i64 } poison, { { {} } } poison }, { { {} } } %15, 2 - store { i32, { i64 }, { { {} } } } %16, { i32, { i64 }, { { {} } } }* %"28_0", align 4 - store { {} } %"025", { {} }* %"24_0", align 1 - store i64 %"126", i64* %"24_1", align 4 - %"28_028" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"28_0", align 4 - %"24_129" = load i64, i64* %"24_1", align 4 - store { i32, { i64 }, { { {} } } } %"28_028", { i32, { i64 }, { { {} } } }* %"08", align 4 - store i64 %"24_129", i64* %"19", align 4 - br label %cond_exit_12 - -cond_exit_12: ; preds = %cond_12_case_1, %cond_12_case_0 - %"010" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"08", align 4 - %"111" = load i64, i64* %"19", align 4 - store { i32, { i64 }, { { {} } } } %"010", { i32, { i64 }, { { {} } } }* %"12_0", align 4 - store i64 %"111", i64* %"12_1", align 4 - %"12_030" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"12_0", align 4 - %"12_131" = load i64, i64* %"12_1", align 4 - store { i32, { i64 }, { { {} } } } %"12_030", { i32, { i64 }, { { {} } } }* %"12_0", align 4 - store i64 %"12_131", i64* %"12_1", align 4 - %"5_032" = load i64, i64* %"5_0", align 4 - %"8_033" = load i64, i64* %"8_0", align 4 - %17 = icmp ule i64 %"5_032", %"8_033" - %18 = select i1 %17, { i32, {}, {} } { i32 1, {} poison, {} undef }, { i32, {}, {} } { i32 0, {} undef, {} poison } - store { i32, {}, {} } %18, { i32, {}, {} }* %"9_0", align 4 - %"12_034" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"12_0", align 4 - %"12_135" = load i64, i64* %"12_1", align 4 - %19 = extractvalue { i32, { i64 }, { { {} } } } %"12_034", 0 - switch i32 %19, label %20 [ - i32 1, label %23 - ] - -20: ; preds = %cond_exit_12 - %21 = extractvalue { i32, { i64 }, { { {} } } } %"12_034", 1 - %22 = extractvalue { i64 } %21, 0 - store i64 %22, i64* %"5_0", align 4 - store i64 %"12_135", i64* %"5_1", align 4 - br label %loop_body - -23: ; preds = %cond_exit_12 - %24 = extractvalue { i32, { i64 }, { { {} } } } %"12_034", 2 - %25 = extractvalue { { {} } } %24, 0 - store { {} } %25, { {} }* %"4_0", align 1 - store i64 %"12_135", i64* %"4_1", align 4 - br label %loop_out -} diff --git a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop_simple@pre-mem2reg@llvm14_3.snap b/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop_simple@pre-mem2reg@llvm14_3.snap deleted file mode 100644 index 7c1a36ea0..000000000 --- a/hugr-llvm/src/emit/snapshots/hugr_llvm__emit__test__test_fns__tail_loop_simple@pre-mem2reg@llvm14_3.snap +++ /dev/null @@ -1,55 +0,0 @@ ---- -source: hugr-llvm/src/emit/test.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -define { {} } @_hl.main.1(i64 %0) { -alloca_block: - %"0" = alloca { {} }, align 8 - %"2_0" = alloca i64, align 8 - %"4_0" = alloca { {} }, align 8 - %"5_0" = alloca i64, align 8 - %"7_0" = alloca { i32, { i64 }, { { {} } } }, align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i64 %0, i64* %"2_0", align 4 - %"2_01" = load i64, i64* %"2_0", align 4 - store i64 %"2_01", i64* %"5_0", align 4 - br label %loop_body - -loop_body: ; preds = %4, %entry_block - %"5_02" = load i64, i64* %"5_0", align 4 - store i64 %"5_02", i64* %"5_0", align 4 - %"5_03" = load i64, i64* %"5_0", align 4 - %1 = insertvalue { i64 } undef, i64 %"5_03", 0 - %2 = insertvalue { i32, { i64 }, { { {} } } } { i32 0, { i64 } poison, { { {} } } poison }, { i64 } %1, 1 - store { i32, { i64 }, { { {} } } } %2, { i32, { i64 }, { { {} } } }* %"7_0", align 4 - %"7_04" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"7_0", align 4 - store { i32, { i64 }, { { {} } } } %"7_04", { i32, { i64 }, { { {} } } }* %"7_0", align 4 - %"7_05" = load { i32, { i64 }, { { {} } } }, { i32, { i64 }, { { {} } } }* %"7_0", align 4 - %3 = extractvalue { i32, { i64 }, { { {} } } } %"7_05", 0 - switch i32 %3, label %4 [ - i32 1, label %7 - ] - -4: ; preds = %loop_body - %5 = extractvalue { i32, { i64 }, { { {} } } } %"7_05", 1 - %6 = extractvalue { i64 } %5, 0 - store i64 %6, i64* %"5_0", align 4 - br label %loop_body - -7: ; preds = %loop_body - %8 = extractvalue { i32, { i64 }, { { {} } } } %"7_05", 2 - %9 = extractvalue { { {} } } %8, 0 - store { {} } %9, { {} }* %"4_0", align 1 - br label %loop_out - -loop_out: ; preds = %7 - %"4_06" = load { {} }, { {} }* %"4_0", align 1 - store { {} } %"4_06", { {} }* %"0", align 1 - %"07" = load { {} }, { {} }* %"0", align 1 - ret { {} } %"07" -} diff --git a/hugr-llvm/src/emit/test.rs b/hugr-llvm/src/emit/test.rs index 42dd514c4..3f6977a8c 100644 --- a/hugr-llvm/src/emit/test.rs +++ b/hugr-llvm/src/emit/test.rs @@ -163,6 +163,7 @@ impl SimpleHugrConfig { logic::EXTENSION_ID, collections::array::EXTENSION_ID, collections::list::EXTENSION_ID, + collections::static_array::EXTENSION_ID, ]), ), ) diff --git a/hugr-llvm/src/extension/collections.rs b/hugr-llvm/src/extension/collections.rs index 7ce81b0ee..6c10d3ed1 100644 --- a/hugr-llvm/src/extension/collections.rs +++ b/hugr-llvm/src/extension/collections.rs @@ -2,3 +2,4 @@ pub mod array; pub mod list; +pub mod static_array; diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__emit_static_array_of_static_array@llvm14.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__emit_static_array_of_static_array@llvm14.snap new file mode 100644 index 000000000..1af774422 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__emit_static_array_of_static_array@llvm14.snap @@ -0,0 +1,28 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.inner.6acc1b76.0 = constant { i64, [0 x i64] } zeroinitializer +@sa.inner.e637bb5.0 = constant { i64, [1 x i64] } { i64 1, [1 x i64] [i64 1] } +@sa.inner.2b6593f.0 = constant { i64, [2 x i64] } { i64 2, [2 x i64] [i64 2, i64 2] } +@sa.inner.1b9ad7c.0 = constant { i64, [3 x i64] } { i64 3, [3 x i64] [i64 3, i64 3, i64 3] } +@sa.inner.e67fbfa4.0 = constant { i64, [4 x i64] } { i64 4, [4 x i64] [i64 4, i64 4, i64 4, i64 4] } +@sa.inner.15dc27f6.0 = constant { i64, [5 x i64] } { i64 5, [5 x i64] [i64 5, i64 5, i64 5, i64 5, i64 5] } +@sa.inner.c43a2bb2.0 = constant { i64, [6 x i64] } { i64 6, [6 x i64] [i64 6, i64 6, i64 6, i64 6, i64 6, i64 6] } +@sa.inner.7f5d5e16.0 = constant { i64, [7 x i64] } { i64 7, [7 x i64] [i64 7, i64 7, i64 7, i64 7, i64 7, i64 7, i64 7] } +@sa.inner.a0bc9c53.0 = constant { i64, [8 x i64] } { i64 8, [8 x i64] [i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8] } +@sa.inner.1e8aada3.0 = constant { i64, [9 x i64] } { i64 9, [9 x i64] [i64 9, i64 9, i64 9, i64 9, i64 9, i64 9, i64 9, i64 9, i64 9] } +@sa.outer.c4a5911a.0 = constant { i64, [10 x { i64, [0 x i64] }*] } { i64 10, [10 x { i64, [0 x i64] }*] [{ i64, [0 x i64] }* @sa.inner.6acc1b76.0, { i64, [0 x i64] }* bitcast ({ i64, [1 x i64] }* @sa.inner.e637bb5.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [2 x i64] }* @sa.inner.2b6593f.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [3 x i64] }* @sa.inner.1b9ad7c.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [4 x i64] }* @sa.inner.e67fbfa4.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [5 x i64] }* @sa.inner.15dc27f6.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [6 x i64] }* @sa.inner.c43a2bb2.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [7 x i64] }* @sa.inner.7f5d5e16.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [8 x i64] }* @sa.inner.a0bc9c53.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [9 x i64] }* @sa.inner.1e8aada3.0 to { i64, [0 x i64] }*)] } + +define i64 @_hl.main.1() { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + %0 = getelementptr inbounds { i64, [0 x { i64, [0 x i64] }*] }, { i64, [0 x { i64, [0 x i64] }*] }* bitcast ({ i64, [10 x { i64, [0 x i64] }*] }* @sa.outer.c4a5911a.0 to { i64, [0 x { i64, [0 x i64] }*] }*), i32 0, i32 0 + %1 = load i64, i64* %0, align 4 + ret i64 %1 +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__emit_static_array_of_static_array@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__emit_static_array_of_static_array@pre-mem2reg@llvm14.snap new file mode 100644 index 000000000..be8b63018 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__emit_static_array_of_static_array@pre-mem2reg@llvm14.snap @@ -0,0 +1,37 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.inner.6acc1b76.0 = constant { i64, [0 x i64] } zeroinitializer +@sa.inner.e637bb5.0 = constant { i64, [1 x i64] } { i64 1, [1 x i64] [i64 1] } +@sa.inner.2b6593f.0 = constant { i64, [2 x i64] } { i64 2, [2 x i64] [i64 2, i64 2] } +@sa.inner.1b9ad7c.0 = constant { i64, [3 x i64] } { i64 3, [3 x i64] [i64 3, i64 3, i64 3] } +@sa.inner.e67fbfa4.0 = constant { i64, [4 x i64] } { i64 4, [4 x i64] [i64 4, i64 4, i64 4, i64 4] } +@sa.inner.15dc27f6.0 = constant { i64, [5 x i64] } { i64 5, [5 x i64] [i64 5, i64 5, i64 5, i64 5, i64 5] } +@sa.inner.c43a2bb2.0 = constant { i64, [6 x i64] } { i64 6, [6 x i64] [i64 6, i64 6, i64 6, i64 6, i64 6, i64 6] } +@sa.inner.7f5d5e16.0 = constant { i64, [7 x i64] } { i64 7, [7 x i64] [i64 7, i64 7, i64 7, i64 7, i64 7, i64 7, i64 7] } +@sa.inner.a0bc9c53.0 = constant { i64, [8 x i64] } { i64 8, [8 x i64] [i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8, i64 8] } +@sa.inner.1e8aada3.0 = constant { i64, [9 x i64] } { i64 9, [9 x i64] [i64 9, i64 9, i64 9, i64 9, i64 9, i64 9, i64 9, i64 9, i64 9] } +@sa.outer.c4a5911a.0 = constant { i64, [10 x { i64, [0 x i64] }*] } { i64 10, [10 x { i64, [0 x i64] }*] [{ i64, [0 x i64] }* @sa.inner.6acc1b76.0, { i64, [0 x i64] }* bitcast ({ i64, [1 x i64] }* @sa.inner.e637bb5.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [2 x i64] }* @sa.inner.2b6593f.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [3 x i64] }* @sa.inner.1b9ad7c.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [4 x i64] }* @sa.inner.e67fbfa4.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [5 x i64] }* @sa.inner.15dc27f6.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [6 x i64] }* @sa.inner.c43a2bb2.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [7 x i64] }* @sa.inner.7f5d5e16.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [8 x i64] }* @sa.inner.a0bc9c53.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }* bitcast ({ i64, [9 x i64] }* @sa.inner.1e8aada3.0 to { i64, [0 x i64] }*)] } + +define i64 @_hl.main.1() { +alloca_block: + %"0" = alloca i64, align 8 + %"5_0" = alloca { i64, [0 x { i64, [0 x i64] }*] }*, align 8 + %"6_0" = alloca i64, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x { i64, [0 x i64] }*] }* bitcast ({ i64, [10 x { i64, [0 x i64] }*] }* @sa.outer.c4a5911a.0 to { i64, [0 x { i64, [0 x i64] }*] }*), { i64, [0 x { i64, [0 x i64] }*] }** %"5_0", align 8 + %"5_01" = load { i64, [0 x { i64, [0 x i64] }*] }*, { i64, [0 x { i64, [0 x i64] }*] }** %"5_0", align 8 + %0 = getelementptr inbounds { i64, [0 x { i64, [0 x i64] }*] }, { i64, [0 x { i64, [0 x i64] }*] }* %"5_01", i32 0, i32 0 + %1 = load i64, i64* %0, align 4 + store i64 %1, i64* %"6_0", align 4 + %"6_02" = load i64, i64* %"6_0", align 4 + store i64 %"6_02", i64* %"0", align 4 + %"03" = load i64, i64* %"0", align 4 + ret i64 %"03" +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_0.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_0.snap new file mode 100644 index 000000000..646ab7887 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_0.snap @@ -0,0 +1,16 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.a.97cb22bf.0 = constant { i64, [10 x i64] } { i64 10, [10 x i64] [i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9] } + +define { i64, [0 x i64] }* @_hl.main.1() { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + ret { i64, [0 x i64] }* bitcast ({ i64, [10 x i64] }* @sa.a.97cb22bf.0 to { i64, [0 x i64] }*) +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_1.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_1.snap new file mode 100644 index 000000000..222c9a764 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_1.snap @@ -0,0 +1,16 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.b.150c532c.0 = constant { i64, [10 x double] } { i64 10, [10 x double] [double 0.000000e+00, double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00, double 5.000000e+00, double 6.000000e+00, double 7.000000e+00, double 8.000000e+00, double 9.000000e+00] } + +define { i64, [0 x double] }* @_hl.main.1() { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + ret { i64, [0 x double] }* bitcast ({ i64, [10 x double] }* @sa.b.150c532c.0 to { i64, [0 x double] }*) +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_2.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_2.snap new file mode 100644 index 000000000..7a072e2f1 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_2.snap @@ -0,0 +1,16 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.c.911aa16d.0 = constant { i64, [10 x i1] } { i64 10, [10 x i1] [i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false] } + +define { i64, [0 x i1] }* @_hl.main.1() { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + ret { i64, [0 x i1] }* bitcast ({ i64, [10 x i1] }* @sa.c.911aa16d.0 to { i64, [0 x i1] }*) +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_3.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_3.snap new file mode 100644 index 000000000..acf9d1edd --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@llvm14_3.snap @@ -0,0 +1,16 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.d.4c6da27.0 = constant { i64, [10 x { i1, i64 }] } { i64 10, [10 x { i1, i64 }] [{ i1, i64 } { i1 true, i64 0 }, { i1, i64 } { i1 true, i64 1 }, { i1, i64 } { i1 true, i64 2 }, { i1, i64 } { i1 true, i64 3 }, { i1, i64 } { i1 true, i64 4 }, { i1, i64 } { i1 true, i64 5 }, { i1, i64 } { i1 true, i64 6 }, { i1, i64 } { i1 true, i64 7 }, { i1, i64 } { i1 true, i64 8 }, { i1, i64 } { i1 true, i64 9 }] } + +define { i64, [0 x { i1, i64 }] }* @_hl.main.1() { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + ret { i64, [0 x { i1, i64 }] }* bitcast ({ i64, [10 x { i1, i64 }] }* @sa.d.4c6da27.0 to { i64, [0 x { i1, i64 }] }*) +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_0.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_0.snap new file mode 100644 index 000000000..ec5e3dfe3 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_0.snap @@ -0,0 +1,22 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.a.97cb22bf.0 = constant { i64, [10 x i64] } { i64 10, [10 x i64] [i64 0, i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i64 9] } + +define { i64, [0 x i64] }* @_hl.main.1() { +alloca_block: + %"0" = alloca { i64, [0 x i64] }*, align 8 + %"5_0" = alloca { i64, [0 x i64] }*, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x i64] }* bitcast ({ i64, [10 x i64] }* @sa.a.97cb22bf.0 to { i64, [0 x i64] }*), { i64, [0 x i64] }** %"5_0", align 8 + %"5_01" = load { i64, [0 x i64] }*, { i64, [0 x i64] }** %"5_0", align 8 + store { i64, [0 x i64] }* %"5_01", { i64, [0 x i64] }** %"0", align 8 + %"02" = load { i64, [0 x i64] }*, { i64, [0 x i64] }** %"0", align 8 + ret { i64, [0 x i64] }* %"02" +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_1.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_1.snap new file mode 100644 index 000000000..572cd450f --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_1.snap @@ -0,0 +1,22 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.b.150c532c.0 = constant { i64, [10 x double] } { i64 10, [10 x double] [double 0.000000e+00, double 1.000000e+00, double 2.000000e+00, double 3.000000e+00, double 4.000000e+00, double 5.000000e+00, double 6.000000e+00, double 7.000000e+00, double 8.000000e+00, double 9.000000e+00] } + +define { i64, [0 x double] }* @_hl.main.1() { +alloca_block: + %"0" = alloca { i64, [0 x double] }*, align 8 + %"5_0" = alloca { i64, [0 x double] }*, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x double] }* bitcast ({ i64, [10 x double] }* @sa.b.150c532c.0 to { i64, [0 x double] }*), { i64, [0 x double] }** %"5_0", align 8 + %"5_01" = load { i64, [0 x double] }*, { i64, [0 x double] }** %"5_0", align 8 + store { i64, [0 x double] }* %"5_01", { i64, [0 x double] }** %"0", align 8 + %"02" = load { i64, [0 x double] }*, { i64, [0 x double] }** %"0", align 8 + ret { i64, [0 x double] }* %"02" +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_2.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_2.snap new file mode 100644 index 000000000..608121fc7 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_2.snap @@ -0,0 +1,22 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.c.911aa16d.0 = constant { i64, [10 x i1] } { i64 10, [10 x i1] [i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false] } + +define { i64, [0 x i1] }* @_hl.main.1() { +alloca_block: + %"0" = alloca { i64, [0 x i1] }*, align 8 + %"5_0" = alloca { i64, [0 x i1] }*, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x i1] }* bitcast ({ i64, [10 x i1] }* @sa.c.911aa16d.0 to { i64, [0 x i1] }*), { i64, [0 x i1] }** %"5_0", align 8 + %"5_01" = load { i64, [0 x i1] }*, { i64, [0 x i1] }** %"5_0", align 8 + store { i64, [0 x i1] }* %"5_01", { i64, [0 x i1] }** %"0", align 8 + %"02" = load { i64, [0 x i1] }*, { i64, [0 x i1] }** %"0", align 8 + ret { i64, [0 x i1] }* %"02" +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_3.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_3.snap new file mode 100644 index 000000000..333676499 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_const_codegen@pre-mem2reg@llvm14_3.snap @@ -0,0 +1,22 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +@sa.d.4c6da27.0 = constant { i64, [10 x { i1, i64 }] } { i64 10, [10 x { i1, i64 }] [{ i1, i64 } { i1 true, i64 0 }, { i1, i64 } { i1 true, i64 1 }, { i1, i64 } { i1 true, i64 2 }, { i1, i64 } { i1 true, i64 3 }, { i1, i64 } { i1 true, i64 4 }, { i1, i64 } { i1 true, i64 5 }, { i1, i64 } { i1 true, i64 6 }, { i1, i64 } { i1 true, i64 7 }, { i1, i64 } { i1 true, i64 8 }, { i1, i64 } { i1 true, i64 9 }] } + +define { i64, [0 x { i1, i64 }] }* @_hl.main.1() { +alloca_block: + %"0" = alloca { i64, [0 x { i1, i64 }] }*, align 8 + %"5_0" = alloca { i64, [0 x { i1, i64 }] }*, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x { i1, i64 }] }* bitcast ({ i64, [10 x { i1, i64 }] }* @sa.d.4c6da27.0 to { i64, [0 x { i1, i64 }] }*), { i64, [0 x { i1, i64 }] }** %"5_0", align 8 + %"5_01" = load { i64, [0 x { i1, i64 }] }*, { i64, [0 x { i1, i64 }] }** %"5_0", align 8 + store { i64, [0 x { i1, i64 }] }* %"5_01", { i64, [0 x { i1, i64 }] }** %"0", align 8 + %"02" = load { i64, [0 x { i1, i64 }] }*, { i64, [0 x { i1, i64 }] }** %"0", align 8 + ret { i64, [0 x { i1, i64 }] }* %"02" +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_0.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_0.snap new file mode 100644 index 000000000..92f0b819c --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_0.snap @@ -0,0 +1,30 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define { i1, i64 } @_hl.main.1({ i64, [0 x i64] }* %0, i64 %1) { +alloca_block: + br label %entry_block + +static_array_get_out_of_bounds: ; preds = %entry_block + br label %static_array_get_exit + +static_array_get_in_bounds: ; preds = %entry_block + %2 = getelementptr inbounds { i64, [0 x i64] }, { i64, [0 x i64] }* %0, i32 0, i32 1, i64 %1 + %3 = load i64, i64* %2, align 4 + %4 = insertvalue { i1, i64 } { i1 true, i64 poison }, i64 %3, 1 + br label %static_array_get_exit + +static_array_get_exit: ; preds = %static_array_get_in_bounds, %static_array_get_out_of_bounds + %"03.0" = phi { i1, i64 } [ %4, %static_array_get_in_bounds ], [ { i1 false, i64 poison }, %static_array_get_out_of_bounds ] + ret { i1, i64 } %"03.0" + +entry_block: ; preds = %alloca_block + %5 = getelementptr inbounds { i64, [0 x i64] }, { i64, [0 x i64] }* %0, i32 0, i32 0 + %6 = load i64, i64* %5, align 4 + %7 = icmp ult i64 %1, %6 + br i1 %7, label %static_array_get_in_bounds, label %static_array_get_out_of_bounds +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_1.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_1.snap new file mode 100644 index 000000000..adf63b709 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_1.snap @@ -0,0 +1,30 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define { i1, i1 } @_hl.main.1({ i64, [0 x i1] }* %0, i64 %1) { +alloca_block: + br label %entry_block + +static_array_get_out_of_bounds: ; preds = %entry_block + br label %static_array_get_exit + +static_array_get_in_bounds: ; preds = %entry_block + %2 = getelementptr inbounds { i64, [0 x i1] }, { i64, [0 x i1] }* %0, i32 0, i32 1, i64 %1 + %3 = load i1, i1* %2, align 1 + %4 = insertvalue { i1, i1 } { i1 true, i1 poison }, i1 %3, 1 + br label %static_array_get_exit + +static_array_get_exit: ; preds = %static_array_get_in_bounds, %static_array_get_out_of_bounds + %"03.0" = phi { i1, i1 } [ %4, %static_array_get_in_bounds ], [ { i1 false, i1 poison }, %static_array_get_out_of_bounds ] + ret { i1, i1 } %"03.0" + +entry_block: ; preds = %alloca_block + %5 = getelementptr inbounds { i64, [0 x i1] }, { i64, [0 x i1] }* %0, i32 0, i32 0 + %6 = load i64, i64* %5, align 4 + %7 = icmp ult i64 %1, %6 + br i1 %7, label %static_array_get_in_bounds, label %static_array_get_out_of_bounds +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_2.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_2.snap new file mode 100644 index 000000000..fd98e6d7f --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_2.snap @@ -0,0 +1,16 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define i64 @_hl.main.1({ i64, [0 x i64] }* %0) { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + %1 = getelementptr inbounds { i64, [0 x i64] }, { i64, [0 x i64] }* %0, i32 0, i32 0 + %2 = load i64, i64* %1, align 4 + ret i64 %2 +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_3.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_3.snap new file mode 100644 index 000000000..e1028e2dd --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@llvm14_3.snap @@ -0,0 +1,16 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define i64 @_hl.main.1({ i64, [0 x i1] }* %0) { +alloca_block: + br label %entry_block + +entry_block: ; preds = %alloca_block + %1 = getelementptr inbounds { i64, [0 x i1] }, { i64, [0 x i1] }* %0, i32 0, i32 0 + %2 = load i64, i64* %1, align 4 + ret i64 %2 +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_0.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_0.snap new file mode 100644 index 000000000..5747c36a1 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_0.snap @@ -0,0 +1,45 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define { i1, i64 } @_hl.main.1({ i64, [0 x i64] }* %0, i64 %1) { +alloca_block: + %"0" = alloca { i1, i64 }, align 8 + %"2_0" = alloca { i64, [0 x i64] }*, align 8 + %"2_1" = alloca i64, align 8 + %"4_0" = alloca { i1, i64 }, align 8 + %"03" = alloca { i1, i64 }, align 8 + br label %entry_block + +static_array_get_out_of_bounds: ; preds = %entry_block + store { i1, i64 } { i1 false, i64 poison }, { i1, i64 }* %"03", align 4 + br label %static_array_get_exit + +static_array_get_in_bounds: ; preds = %entry_block + %2 = getelementptr inbounds { i64, [0 x i64] }, { i64, [0 x i64] }* %"2_01", i32 0, i32 1, i64 %"2_12" + %3 = load i64, i64* %2, align 4 + %4 = insertvalue { i1, i64 } { i1 true, i64 poison }, i64 %3, 1 + store { i1, i64 } %4, { i1, i64 }* %"03", align 4 + br label %static_array_get_exit + +static_array_get_exit: ; preds = %static_array_get_in_bounds, %static_array_get_out_of_bounds + %"04" = load { i1, i64 }, { i1, i64 }* %"03", align 4 + store { i1, i64 } %"04", { i1, i64 }* %"4_0", align 4 + %"4_05" = load { i1, i64 }, { i1, i64 }* %"4_0", align 4 + store { i1, i64 } %"4_05", { i1, i64 }* %"0", align 4 + %"06" = load { i1, i64 }, { i1, i64 }* %"0", align 4 + ret { i1, i64 } %"06" + +entry_block: ; preds = %alloca_block + store { i64, [0 x i64] }* %0, { i64, [0 x i64] }** %"2_0", align 8 + store i64 %1, i64* %"2_1", align 4 + %"2_01" = load { i64, [0 x i64] }*, { i64, [0 x i64] }** %"2_0", align 8 + %"2_12" = load i64, i64* %"2_1", align 4 + %5 = getelementptr inbounds { i64, [0 x i64] }, { i64, [0 x i64] }* %"2_01", i32 0, i32 0 + %6 = load i64, i64* %5, align 4 + %7 = icmp ult i64 %"2_12", %6 + br i1 %7, label %static_array_get_in_bounds, label %static_array_get_out_of_bounds +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_1.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_1.snap new file mode 100644 index 000000000..47dac5292 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_1.snap @@ -0,0 +1,45 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define { i1, i1 } @_hl.main.1({ i64, [0 x i1] }* %0, i64 %1) { +alloca_block: + %"0" = alloca { i1, i1 }, align 8 + %"2_0" = alloca { i64, [0 x i1] }*, align 8 + %"2_1" = alloca i64, align 8 + %"4_0" = alloca { i1, i1 }, align 8 + %"03" = alloca { i1, i1 }, align 8 + br label %entry_block + +static_array_get_out_of_bounds: ; preds = %entry_block + store { i1, i1 } { i1 false, i1 poison }, { i1, i1 }* %"03", align 1 + br label %static_array_get_exit + +static_array_get_in_bounds: ; preds = %entry_block + %2 = getelementptr inbounds { i64, [0 x i1] }, { i64, [0 x i1] }* %"2_01", i32 0, i32 1, i64 %"2_12" + %3 = load i1, i1* %2, align 1 + %4 = insertvalue { i1, i1 } { i1 true, i1 poison }, i1 %3, 1 + store { i1, i1 } %4, { i1, i1 }* %"03", align 1 + br label %static_array_get_exit + +static_array_get_exit: ; preds = %static_array_get_in_bounds, %static_array_get_out_of_bounds + %"04" = load { i1, i1 }, { i1, i1 }* %"03", align 1 + store { i1, i1 } %"04", { i1, i1 }* %"4_0", align 1 + %"4_05" = load { i1, i1 }, { i1, i1 }* %"4_0", align 1 + store { i1, i1 } %"4_05", { i1, i1 }* %"0", align 1 + %"06" = load { i1, i1 }, { i1, i1 }* %"0", align 1 + ret { i1, i1 } %"06" + +entry_block: ; preds = %alloca_block + store { i64, [0 x i1] }* %0, { i64, [0 x i1] }** %"2_0", align 8 + store i64 %1, i64* %"2_1", align 4 + %"2_01" = load { i64, [0 x i1] }*, { i64, [0 x i1] }** %"2_0", align 8 + %"2_12" = load i64, i64* %"2_1", align 4 + %5 = getelementptr inbounds { i64, [0 x i1] }, { i64, [0 x i1] }* %"2_01", i32 0, i32 0 + %6 = load i64, i64* %5, align 4 + %7 = icmp ult i64 %"2_12", %6 + br i1 %7, label %static_array_get_in_bounds, label %static_array_get_out_of_bounds +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_2.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_2.snap new file mode 100644 index 000000000..eccc029f9 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_2.snap @@ -0,0 +1,25 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define i64 @_hl.main.1({ i64, [0 x i64] }* %0) { +alloca_block: + %"0" = alloca i64, align 8 + %"2_0" = alloca { i64, [0 x i64] }*, align 8 + %"4_0" = alloca i64, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x i64] }* %0, { i64, [0 x i64] }** %"2_0", align 8 + %"2_01" = load { i64, [0 x i64] }*, { i64, [0 x i64] }** %"2_0", align 8 + %1 = getelementptr inbounds { i64, [0 x i64] }, { i64, [0 x i64] }* %"2_01", i32 0, i32 0 + %2 = load i64, i64* %1, align 4 + store i64 %2, i64* %"4_0", align 4 + %"4_02" = load i64, i64* %"4_0", align 4 + store i64 %"4_02", i64* %"0", align 4 + %"03" = load i64, i64* %"0", align 4 + ret i64 %"03" +} diff --git a/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_3.snap b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_3.snap new file mode 100644 index 000000000..4c4b410f1 --- /dev/null +++ b/hugr-llvm/src/extension/collections/snapshots/hugr_llvm__extension__collections__static_array__test__static_array_op_codegen@pre-mem2reg@llvm14_3.snap @@ -0,0 +1,25 @@ +--- +source: hugr-llvm/src/extension/collections/static_array.rs +expression: mod_str +--- +; ModuleID = 'test_context' +source_filename = "test_context" + +define i64 @_hl.main.1({ i64, [0 x i1] }* %0) { +alloca_block: + %"0" = alloca i64, align 8 + %"2_0" = alloca { i64, [0 x i1] }*, align 8 + %"4_0" = alloca i64, align 8 + br label %entry_block + +entry_block: ; preds = %alloca_block + store { i64, [0 x i1] }* %0, { i64, [0 x i1] }** %"2_0", align 8 + %"2_01" = load { i64, [0 x i1] }*, { i64, [0 x i1] }** %"2_0", align 8 + %1 = getelementptr inbounds { i64, [0 x i1] }, { i64, [0 x i1] }* %"2_01", i32 0, i32 0 + %2 = load i64, i64* %1, align 4 + store i64 %2, i64* %"4_0", align 4 + %"4_02" = load i64, i64* %"4_0", align 4 + store i64 %"4_02", i64* %"0", align 4 + %"03" = load i64, i64* %"0", align 4 + ret i64 %"03" +} diff --git a/hugr-llvm/src/extension/collections/static_array.rs b/hugr-llvm/src/extension/collections/static_array.rs new file mode 100644 index 000000000..7d3ac5f5c --- /dev/null +++ b/hugr-llvm/src/extension/collections/static_array.rs @@ -0,0 +1,572 @@ +use std::hash::Hasher as _; + +use hugr_core::{ + extension::{ + prelude::{option_type, usize_t}, + simple_op::HasConcrete as _, + }, + ops::{constant::TryHash, ExtensionOp}, + std_extensions::collections::static_array::{ + self, StaticArrayOp, StaticArrayOpDef, StaticArrayValue, + }, + HugrView, Node, +}; +use inkwell::{ + builder::Builder, + context::Context, + types::{BasicType, BasicTypeEnum, StructType}, + values::{ArrayValue, BasicValue, BasicValueEnum, IntValue, PointerValue}, + AddressSpace, IntPredicate, +}; +use itertools::Itertools as _; + +use crate::{ + emit::{emit_value, EmitFuncContext, EmitOpArgs}, + types::{HugrType, TypingSession}, + CodegenExtension, CodegenExtsBuilder, +}; + +use anyhow::{bail, Result}; + +#[derive(Debug, Clone, derive_more::From)] +/// A [CodegenExtension] that lowers the +/// [hugr_core::std_extensions::collections::static_array]. +/// +/// All behaviour is delegated to `SACG`. +pub struct StaticArrayCodegenExtension(SACG); + +impl<'a, H: HugrView + 'a> CodegenExtsBuilder<'a, H> { + /// Add a [StaticArrayCodegenExtension] to the given [CodegenExtsBuilder] using `ccg` + /// as the implementation. + pub fn add_static_array_extensions(self, ccg: impl StaticArrayCodegen + 'static) -> Self { + self.add_extension(StaticArrayCodegenExtension::from(ccg)) + } + + /// Add a [StaticArrayCodegenExtension] to the given [CodegenExtsBuilder] using + /// [DefaultStaticArrayCodegen] as the implementation. + pub fn add_default_static_array_extensions(self) -> Self { + self.add_static_array_extensions(DefaultStaticArrayCodegen) + } +} + +// This is not provided by inkwell, it seems like it should be +fn value_is_const<'c>(value: impl BasicValue<'c>) -> bool { + match value.as_basic_value_enum() { + BasicValueEnum::ArrayValue(v) => v.is_const(), + BasicValueEnum::IntValue(v) => v.is_const(), + BasicValueEnum::FloatValue(v) => v.is_const(), + BasicValueEnum::PointerValue(v) => v.is_const(), + BasicValueEnum::StructValue(v) => v.is_const(), + BasicValueEnum::VectorValue(v) => v.is_const(), + } +} + +// This is not provided by inkwell, it seems like it should be +fn const_array<'c>( + ty: impl BasicType<'c>, + values: impl IntoIterator>, +) -> ArrayValue<'c> { + match ty.as_basic_type_enum() { + BasicTypeEnum::ArrayType(t) => t.const_array( + values + .into_iter() + .map(|x| x.as_basic_value_enum().into_array_value()) + .collect_vec() + .as_slice(), + ), + BasicTypeEnum::FloatType(t) => t.const_array( + values + .into_iter() + .map(|x| x.as_basic_value_enum().into_float_value()) + .collect_vec() + .as_slice(), + ), + BasicTypeEnum::IntType(t) => t.const_array( + values + .into_iter() + .map(|x| x.as_basic_value_enum().into_int_value()) + .collect_vec() + .as_slice(), + ), + BasicTypeEnum::PointerType(t) => t.const_array( + values + .into_iter() + .map(|x| x.as_basic_value_enum().into_pointer_value()) + .collect_vec() + .as_slice(), + ), + BasicTypeEnum::StructType(t) => t.const_array( + values + .into_iter() + .map(|x| x.as_basic_value_enum().into_struct_value()) + .collect_vec() + .as_slice(), + ), + BasicTypeEnum::VectorType(t) => t.const_array( + values + .into_iter() + .map(|x| x.as_basic_value_enum().into_vector_value()) + .collect_vec() + .as_slice(), + ), + } +} + +fn static_array_struct_type<'c>( + context: &'c Context, + index_type: impl BasicType<'c>, + element_type: impl BasicType<'c>, + len: u32, +) -> StructType<'c> { + context.struct_type( + &[ + index_type.as_basic_type_enum(), + element_type.array_type(len).into(), + ], + false, + ) +} + +fn build_read_len<'c>( + context: &'c Context, + builder: &Builder<'c>, + struct_ty: StructType<'c>, + mut ptr: PointerValue<'c>, +) -> Result> { + let canonical_ptr_ty = struct_ty.ptr_type(AddressSpace::default()); + if ptr.get_type() != canonical_ptr_ty { + ptr = builder.build_pointer_cast(ptr, canonical_ptr_ty, "")?; + } + let i32_ty = context.i32_type(); + let indices = [i32_ty.const_zero(), i32_ty.const_zero()]; + let len_ptr = unsafe { builder.build_in_bounds_gep(ptr, &indices, "") }?; + Ok(builder.build_load(len_ptr, "")?.into_int_value()) +} + +/// A helper trait for customising the lowering of [hugr_core::std_extensions::collections::static_array] +/// types, [hugr_core::ops::constant::CustomConst]s, and ops. +pub trait StaticArrayCodegen: Clone { + /// Return the llvm type of + /// [hugr_core::std_extensions::collections::static_array::STATIC_ARRAY_TYPENAME]. + /// + /// By default a static array of llvm type `t` and length `l` is stored in a + /// global of type `struct { i64, [t * l] }`` + /// + /// The `i64` stores the length of the array. + /// + /// However a `static_array` `HugrType` is represented by an llvm pointer type + /// `struct {i64, [t * 0]}`; i.e. the array is zero length. This gives all + /// static arrays of the same element type a uniform llvm type. + /// + /// It is legal to index past the end of an array (it is only undefined behaviour + /// to index past the allocation). + fn static_array_type<'c>( + &self, + session: TypingSession<'c, '_>, + element_type: &HugrType, + ) -> Result> { + let index_type = session.llvm_type(&usize_t())?; + let element_type = session.llvm_type(element_type)?; + Ok( + static_array_struct_type(session.iw_context(), index_type, element_type, 0) + .ptr_type(AddressSpace::default()) + .into(), + ) + } + + /// Emit a + /// [hugr_core::std_extensions::collections::static_array::StaticArrayValue]. + /// + /// Note that the type of the return value must match the type returned by + /// [Self::static_array_type]. + /// + /// By default a global is created and we return a pointer to it. + fn static_array_value<'c, H: HugrView>( + &self, + context: &mut EmitFuncContext<'c, '_, H>, + value: &StaticArrayValue, + ) -> Result> { + let element_type = value.get_element_type(); + let llvm_element_type = context.llvm_type(element_type)?; + let index_type = context.llvm_type(&usize_t())?.into_int_type(); + let array_elements = value.get_contents().iter().map(|v| { + let value = emit_value(context, v)?; + if !value_is_const(value) { + anyhow::bail!("Static array value must be constant. HUGR value '{v:?}' was codegened as non-const"); + } + Ok(value) + }).collect::>>()?; + let len = array_elements.len(); + let struct_ty = static_array_struct_type( + context.iw_context(), + index_type, + llvm_element_type, + len as u32, + ); + let array_value = struct_ty.const_named_struct(&[ + index_type.const_int(len as u64, false).into(), + const_array(llvm_element_type, array_elements).into(), + ]); + + let gv = { + let module = context.get_current_module(); + let hash = { + let mut hasher = std::collections::hash_map::DefaultHasher::new(); + let _ = value.try_hash(&mut hasher); + hasher.finish() as u32 // a bit shorter than u64 + }; + let prefix = format!("sa.{}.{hash:x}.", value.name); + (0..) + .find_map(|i| { + let sym = format!("{prefix}{i}"); + if let Some(global) = module.get_global(&sym) { + // Note this comparison may be expensive for large + // values. We could avoid it(and therefore avoid + // creating array_value in this branch) if we had + // https://github.com/CQCL/hugr/issues/2004 + if global.get_initializer().is_some_and(|x| x == array_value) { + Some(global) + } else { + None + } + } else { + let global = module.add_global(struct_ty, None, &sym); + global.set_constant(true); + global.set_initializer(&array_value); + Some(global) + } + }) + .unwrap() + }; + let canonical_type = self + .static_array_type(context.typing_session(), value.get_element_type())? + .into_pointer_type(); + Ok(gv.as_pointer_value().const_cast(canonical_type).into()) + } + + /// Emit a [hugr_core::std_extensions::collections::static_array::StaticArrayOp]. + fn static_array_op<'c, H: HugrView>( + &self, + context: &mut EmitFuncContext<'c, '_, H>, + args: EmitOpArgs<'c, '_, ExtensionOp, H>, + op: StaticArrayOp, + ) -> Result<()> { + match op.def { + StaticArrayOpDef::get => { + let ptr = args.inputs[0].into_pointer_value(); + let index = args.inputs[1].into_int_value(); + let index_ty = index.get_type(); + let element_llvm_ty = context.llvm_type(&op.elem_ty)?; + let struct_ty = + static_array_struct_type(context.iw_context(), index_ty, element_llvm_ty, 0); + + let len = build_read_len(context.iw_context(), context.builder(), struct_ty, ptr)?; + + let result_sum_ty = option_type(op.elem_ty); + let rmb = context.new_row_mail_box([&result_sum_ty.clone().into()], "")?; + let result_llvm_sum_ty = context.llvm_sum_type(result_sum_ty)?; + + let exit_block = context.build_positioned_new_block( + "static_array_get_exit", + context.builder().get_insert_block(), + |context, bb| { + args.outputs + .finish(context.builder(), rmb.read_vec(context.builder(), [])?)?; + anyhow::Ok(bb) + }, + )?; + + let fail_block = context.build_positioned_new_block( + "static_array_get_out_of_bounds", + Some(exit_block), + |context, bb| { + rmb.write( + context.builder(), + [result_llvm_sum_ty + .build_tag(context.builder(), 0, vec![])? + .into()], + )?; + context.builder().build_unconditional_branch(exit_block)?; + anyhow::Ok(bb) + }, + )?; + + let success_block = context.build_positioned_new_block( + "static_array_get_in_bounds", + Some(exit_block), + |context, bb| { + let i32_ty = context.iw_context().i32_type(); + let indices = [i32_ty.const_zero(), i32_ty.const_int(1, false), index]; + let element_ptr = + unsafe { context.builder().build_in_bounds_gep(ptr, &indices, "") }?; + let element = context.builder().build_load(element_ptr, "")?; + rmb.write( + context.builder(), + [result_llvm_sum_ty + .build_tag(context.builder(), 1, vec![element])? + .into()], + )?; + context.builder().build_unconditional_branch(exit_block)?; + anyhow::Ok(bb) + }, + )?; + + let inbounds = + context + .builder() + .build_int_compare(IntPredicate::ULT, index, len, "")?; + context + .builder() + .build_conditional_branch(inbounds, success_block, fail_block)?; + + context.builder().position_at_end(exit_block); + Ok(()) + } + StaticArrayOpDef::len => { + let ptr = args.inputs[0].into_pointer_value(); + let element_llvm_ty = context.llvm_type(&op.elem_ty)?; + let index_ty = args.outputs.get_types().next().unwrap().into_int_type(); + let struct_ty = + static_array_struct_type(context.iw_context(), index_ty, element_llvm_ty, 0); + let len = build_read_len(context.iw_context(), context.builder(), struct_ty, ptr)?; + args.outputs.finish(context.builder(), [len.into()]) + } + op => bail!("StaticArrayCodegen: Unsupported op: {op:?}"), + } + } +} + +#[derive(Debug, Clone)] +/// An implementation of [StaticArrayCodegen] that uses all default +/// implementations. +pub struct DefaultStaticArrayCodegen; + +impl StaticArrayCodegen for DefaultStaticArrayCodegen {} + +impl CodegenExtension for StaticArrayCodegenExtension { + fn add_extension<'a, H: HugrView + 'a>( + self, + builder: CodegenExtsBuilder<'a, H>, + ) -> CodegenExtsBuilder<'a, H> + where + Self: 'a, + { + builder + .custom_type( + ( + static_array::EXTENSION_ID, + static_array::STATIC_ARRAY_TYPENAME, + ), + { + let sac = self.0.clone(); + move |ts, custom_type| { + let element_type = custom_type.args()[0] + .as_type() + .expect("Type argument for static array must be a type"); + sac.static_array_type(ts, &element_type) + } + }, + ) + .custom_const::({ + let sac = self.0.clone(); + move |context, sav| sac.static_array_value(context, sav) + }) + .simple_extension_op::({ + let sac = self.0.clone(); + move |context, args, op| { + let op = op.instantiate(args.node().args())?; + sac.static_array_op(context, args, op) + } + }) + } +} + +#[cfg(test)] +mod test { + use super::*; + use float_types::float64_type; + use hugr_core::extension::prelude::ConstUsize; + use hugr_core::ops::constant::CustomConst; + use hugr_core::ops::OpType; + use hugr_core::ops::Value; + use hugr_core::std_extensions::arithmetic::float_types::{self, ConstF64}; + use rstest::rstest; + + use hugr_core::extension::simple_op::MakeRegisteredOp; + use hugr_core::extension::{prelude::bool_t, ExtensionRegistry}; + use hugr_core::{builder::SubContainer as _, type_row}; + use static_array::StaticArrayOpBuilder as _; + + use crate::check_emission; + use crate::test::single_op_hugr; + use crate::{ + emit::test::SimpleHugrConfig, + test::{exec_ctx, llvm_ctx, TestContext}, + }; + use hugr_core::builder::{Dataflow as _, DataflowSubContainer as _}; + + #[rstest] + #[case(0, StaticArrayOpDef::get, usize_t())] + #[case(1, StaticArrayOpDef::get, bool_t())] + #[case(2, StaticArrayOpDef::len, usize_t())] + #[case(3, StaticArrayOpDef::len, bool_t())] + fn static_array_op_codegen( + #[case] _i: i32, + #[with(_i)] mut llvm_ctx: TestContext, + #[case] op: StaticArrayOpDef, + #[case] ty: HugrType, + ) { + let op = op.instantiate(&[ty.clone().into()]).unwrap(); + let op = OpType::from(op.to_extension_op().unwrap()); + llvm_ctx.add_extensions(|ceb| { + ceb.add_default_static_array_extensions() + .add_default_prelude_extensions() + }); + let hugr = single_op_hugr(op); + check_emission!(hugr, llvm_ctx); + } + + #[rstest] + #[case(0, StaticArrayValue::try_new("a", usize_t(), (0..10).map(|x| ConstUsize::new(x).into())).unwrap())] + #[case(1, StaticArrayValue::try_new("b", float64_type(), (0..10).map(|x| ConstF64::new(x as f64).into())).unwrap())] + #[case(2, StaticArrayValue::try_new("c", bool_t(), (0..10).map(|x| Value::from_bool(x % 2 == 0))).unwrap())] + #[case(3, StaticArrayValue::try_new("d", option_type(usize_t()).into(), (0..10).map(|x| Value::some([ConstUsize::new(x)]))).unwrap())] + fn static_array_const_codegen( + #[case] _i: i32, + #[with(_i)] mut llvm_ctx: TestContext, + #[case] value: StaticArrayValue, + ) { + llvm_ctx.add_extensions(|ceb| { + ceb.add_default_static_array_extensions() + .add_default_prelude_extensions() + .add_float_extensions() + }); + + let hugr = SimpleHugrConfig::new() + .with_outs(value.get_type()) + .with_extensions(ExtensionRegistry::new(vec![ + static_array::EXTENSION.to_owned(), + float_types::EXTENSION.to_owned(), + ])) + .finish(|mut builder| { + let a = builder.add_load_value(value); + builder.finish_with_outputs([a]).unwrap() + }); + check_emission!(hugr, llvm_ctx); + } + + #[rstest] + #[case(0, 0, 999)] + #[case(1, 1, 998)] + #[case(2, 1000, u64::MAX)] + fn static_array_exec( + #[case] _i: i32, + #[with(_i)] mut exec_ctx: TestContext, + #[case] index: u64, + #[case] expected: u64, + ) { + let hugr = SimpleHugrConfig::new() + .with_outs(usize_t()) + .with_extensions(ExtensionRegistry::new(vec![ + static_array::EXTENSION.to_owned() + ])) + .finish(|mut builder| { + let arr = builder.add_load_value( + StaticArrayValue::try_new( + "exec_arr", + usize_t(), + (0..1000) + .map(|x| ConstUsize::new(999 - x).into()) + .collect_vec(), + ) + .unwrap(), + ); + let index = builder.add_load_value(ConstUsize::new(index)); + let get_r = builder.add_static_array_get(usize_t(), arr, index).unwrap(); + let [out] = { + let mut cond = builder + .conditional_builder( + ([type_row!(), usize_t().into()], get_r), + [], + usize_t().into(), + ) + .unwrap(); + { + let mut oob_case = cond.case_builder(0).unwrap(); + let err = oob_case.add_load_value(ConstUsize::new(u64::MAX)); + oob_case.finish_with_outputs([err]).unwrap(); + } + { + let inbounds_case = cond.case_builder(1).unwrap(); + let [out] = inbounds_case.input_wires_arr(); + inbounds_case.finish_with_outputs([out]).unwrap(); + } + cond.finish_sub_container().unwrap().outputs_arr() + }; + builder.finish_with_outputs([out]).unwrap() + }); + + exec_ctx.add_extensions(|ceb| { + ceb.add_default_static_array_extensions() + .add_default_prelude_extensions() + .add_float_extensions() + }); + assert_eq!(expected, exec_ctx.exec_hugr_u64(hugr, "main")); + } + + #[rstest] + fn len_0_array(mut exec_ctx: TestContext) { + let hugr = SimpleHugrConfig::new() + .with_outs(usize_t()) + .with_extensions(ExtensionRegistry::new(vec![ + static_array::EXTENSION.to_owned() + ])) + .finish(|mut builder| { + let arr = builder + .add_load_value(StaticArrayValue::try_new("empty", usize_t(), vec![]).unwrap()); + let len = builder.add_static_array_len(usize_t(), arr).unwrap(); + builder.finish_with_outputs([len]).unwrap() + }); + + exec_ctx.add_extensions(|ceb| { + ceb.add_default_static_array_extensions() + .add_default_prelude_extensions() + }); + assert_eq!(0, exec_ctx.exec_hugr_u64(hugr, "main")); + } + + #[rstest] + fn emit_static_array_of_static_array(mut llvm_ctx: TestContext) { + llvm_ctx.add_extensions(|ceb| { + ceb.add_default_static_array_extensions() + .add_default_prelude_extensions() + }); + let hugr = SimpleHugrConfig::new() + .with_outs(usize_t()) + .with_extensions(ExtensionRegistry::new(vec![ + static_array::EXTENSION.to_owned() + ])) + .finish(|mut builder| { + let inner_arrs: Vec = (0..10) + .map(|i| { + StaticArrayValue::try_new( + "inner", + usize_t(), + vec![Value::from(ConstUsize::new(i)); i as usize], + ) + .unwrap() + .into() + }) + .collect_vec(); + let inner_arr_ty = inner_arrs[0].get_type(); + let outer_arr = builder.add_load_value( + StaticArrayValue::try_new("outer", inner_arr_ty.clone(), inner_arrs).unwrap(), + ); + let len = builder + .add_static_array_len(inner_arr_ty, outer_arr) + .unwrap(); + builder.finish_with_outputs([len]).unwrap() + }); + check_emission!(hugr, llvm_ctx); + } +} diff --git a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_all_ops@llvm14.snap b/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_all_ops@llvm14.snap deleted file mode 100644 index 13e7a0537..000000000 --- a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_all_ops@llvm14.snap +++ /dev/null @@ -1,261 +0,0 @@ ---- -source: src/extension/prelude/array.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@1 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.1 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@2 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.2 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@3 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.3 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@4 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.4 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 - -define void @_hl.main.1() { -alloca_block: - br label %entry_block - -entry_block: ; preds = %alloca_block - %0 = insertvalue [2 x i64] undef, i64 1, 0 - %1 = insertvalue [2 x i64] %0, i64 2, 1 - %2 = icmp ult i64 0, 2 - %3 = icmp ult i64 1, 2 - %4 = and i1 %2, %3 - br i1 %4, label %8, label %5 - -5: ; preds = %entry_block - %6 = insertvalue { [2 x i64] } undef, [2 x i64] %1, 0 - %7 = insertvalue { i32, { [2 x i64] }, { [2 x i64] } } { i32 0, { [2 x i64] } poison, { [2 x i64] } poison }, { [2 x i64] } %6, 1 - br label %19 - -8: ; preds = %entry_block - %9 = alloca i64, i32 2, align 8 - %10 = bitcast i64* %9 to [2 x i64]* - store [2 x i64] %1, [2 x i64]* %10, align 4 - %11 = getelementptr inbounds i64, i64* %9, i64 0 - %12 = load i64, i64* %11, align 4 - %13 = getelementptr inbounds i64, i64* %9, i64 1 - %14 = load i64, i64* %13, align 4 - store i64 %14, i64* %11, align 4 - store i64 %12, i64* %13, align 4 - %15 = bitcast i64* %9 to [2 x i64]* - %16 = load [2 x i64], [2 x i64]* %15, align 4 - %17 = insertvalue { [2 x i64] } undef, [2 x i64] %16, 0 - %18 = insertvalue { i32, { [2 x i64] }, { [2 x i64] } } { i32 1, { [2 x i64] } poison, { [2 x i64] } poison }, { [2 x i64] } %17, 2 - br label %19 - -19: ; preds = %5, %8 - %"0.0" = phi { i32, { [2 x i64] }, { [2 x i64] } } [ %18, %8 ], [ %7, %5 ] - %20 = extractvalue { i32, { [2 x i64] }, { [2 x i64] } } %"0.0", 0 - switch i32 %20, label %21 [ - i32 1, label %24 - ] - -21: ; preds = %19 - %22 = extractvalue { i32, { [2 x i64] }, { [2 x i64] } } %"0.0", 1 - %23 = extractvalue { [2 x i64] } %22, 0 - br label %cond_16_case_0 - -24: ; preds = %19 - %25 = extractvalue { i32, { [2 x i64] }, { [2 x i64] } } %"0.0", 2 - %26 = extractvalue { [2 x i64] } %25, 0 - br label %cond_16_case_1 - -cond_16_case_0: ; preds = %21 - %27 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @0, i32 0, i32 0) }, 0 - %28 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @0, i32 0, i32 0) }, 1 - %29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template, i32 0, i32 0), i32 %27, i8* %28) - call void @abort() - br label %cond_exit_16 - -cond_16_case_1: ; preds = %24 - br label %cond_exit_16 - -cond_exit_16: ; preds = %cond_16_case_1, %cond_16_case_0 - %"08.0" = phi [2 x i64] [ zeroinitializer, %cond_16_case_0 ], [ %26, %cond_16_case_1 ] - %30 = icmp ult i64 0, 2 - br i1 %30, label %32, label %31 - -31: ; preds = %cond_exit_16 - br label %39 - -32: ; preds = %cond_exit_16 - %33 = alloca i64, i32 2, align 8 - %34 = bitcast i64* %33 to [2 x i64]* - store [2 x i64] %"08.0", [2 x i64]* %34, align 4 - %35 = getelementptr inbounds i64, i64* %33, i64 0 - %36 = load i64, i64* %35, align 4 - %37 = insertvalue { i64 } undef, i64 %36, 0 - %38 = insertvalue { i32, {}, { i64 } } { i32 1, {} poison, { i64 } poison }, { i64 } %37, 2 - br label %39 - -39: ; preds = %31, %32 - %"020.0" = phi { i32, {}, { i64 } } [ %38, %32 ], [ { i32 0, {} undef, { i64 } poison }, %31 ] - %40 = extractvalue { i32, {}, { i64 } } %"020.0", 0 - switch i32 %40, label %41 [ - i32 1, label %43 - ] - -41: ; preds = %39 - %42 = extractvalue { i32, {}, { i64 } } %"020.0", 1 - br label %cond_28_case_0 - -43: ; preds = %39 - %44 = extractvalue { i32, {}, { i64 } } %"020.0", 2 - %45 = extractvalue { i64 } %44, 0 - br label %cond_28_case_1 - -cond_28_case_0: ; preds = %41 - %46 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @1, i32 0, i32 0) }, 0 - %47 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @1, i32 0, i32 0) }, 1 - %48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.1, i32 0, i32 0), i32 %46, i8* %47) - call void @abort() - br label %cond_exit_28 - -cond_28_case_1: ; preds = %43 - br label %cond_exit_28 - -cond_exit_28: ; preds = %cond_28_case_1, %cond_28_case_0 - %"023.0" = phi i64 [ 0, %cond_28_case_0 ], [ %45, %cond_28_case_1 ] - %49 = icmp ult i64 1, 2 - br i1 %49, label %54, label %50 - -50: ; preds = %cond_exit_28 - %51 = insertvalue { i64, [2 x i64] } undef, i64 %"023.0", 0 - %52 = insertvalue { i64, [2 x i64] } %51, [2 x i64] %"08.0", 1 - %53 = insertvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } { i32 0, { i64, [2 x i64] } poison, { i64, [2 x i64] } poison }, { i64, [2 x i64] } %52, 1 - br label %64 - -54: ; preds = %cond_exit_28 - %55 = alloca i64, i32 2, align 8 - %56 = bitcast i64* %55 to [2 x i64]* - store [2 x i64] %"08.0", [2 x i64]* %56, align 4 - %57 = getelementptr inbounds i64, i64* %55, i64 1 - %58 = load i64, i64* %57, align 4 - store i64 %"023.0", i64* %57, align 4 - %59 = bitcast i64* %55 to [2 x i64]* - %60 = load [2 x i64], [2 x i64]* %59, align 4 - %61 = insertvalue { i64, [2 x i64] } undef, i64 %58, 0 - %62 = insertvalue { i64, [2 x i64] } %61, [2 x i64] %60, 1 - %63 = insertvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } { i32 1, { i64, [2 x i64] } poison, { i64, [2 x i64] } poison }, { i64, [2 x i64] } %62, 2 - br label %64 - -64: ; preds = %50, %54 - %"033.0" = phi { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } [ %63, %54 ], [ %53, %50 ] - %65 = extractvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"033.0", 0 - switch i32 %65, label %66 [ - i32 1, label %70 - ] - -66: ; preds = %64 - %67 = extractvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"033.0", 1 - %68 = extractvalue { i64, [2 x i64] } %67, 0 - %69 = extractvalue { i64, [2 x i64] } %67, 1 - br label %cond_40_case_0 - -70: ; preds = %64 - %71 = extractvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"033.0", 2 - %72 = extractvalue { i64, [2 x i64] } %71, 0 - %73 = extractvalue { i64, [2 x i64] } %71, 1 - br label %cond_40_case_1 - -cond_40_case_0: ; preds = %66 - %74 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @2, i32 0, i32 0) }, 0 - %75 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @2, i32 0, i32 0) }, 1 - %76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.2, i32 0, i32 0), i32 %74, i8* %75) - call void @abort() - br label %cond_exit_40 - -cond_40_case_1: ; preds = %70 - br label %cond_exit_40 - -cond_exit_40: ; preds = %cond_40_case_1, %cond_40_case_0 - %"036.0" = phi i64 [ 0, %cond_40_case_0 ], [ %72, %cond_40_case_1 ] - %"1.0" = phi [2 x i64] [ zeroinitializer, %cond_40_case_0 ], [ %73, %cond_40_case_1 ] - %77 = alloca i64, i32 2, align 8 - %78 = bitcast i64* %77 to [2 x i64]* - store [2 x i64] %"1.0", [2 x i64]* %78, align 4 - %79 = getelementptr i64, i64* %77, i32 1 - %80 = load i64, i64* %77, align 4 - %81 = bitcast i64* %79 to [1 x i64]* - %82 = load [1 x i64], [1 x i64]* %81, align 4 - %83 = insertvalue { i64, [1 x i64] } undef, i64 %80, 0 - %84 = insertvalue { i64, [1 x i64] } %83, [1 x i64] %82, 1 - %85 = insertvalue { i32, {}, { i64, [1 x i64] } } { i32 1, {} poison, { i64, [1 x i64] } poison }, { i64, [1 x i64] } %84, 2 - %86 = extractvalue { i32, {}, { i64, [1 x i64] } } %85, 0 - switch i32 %86, label %87 [ - i32 1, label %89 - ] - -87: ; preds = %cond_exit_40 - %88 = extractvalue { i32, {}, { i64, [1 x i64] } } %85, 1 - br label %cond_51_case_0 - -89: ; preds = %cond_exit_40 - %90 = extractvalue { i32, {}, { i64, [1 x i64] } } %85, 2 - %91 = extractvalue { i64, [1 x i64] } %90, 0 - %92 = extractvalue { i64, [1 x i64] } %90, 1 - br label %cond_51_case_1 - -cond_51_case_0: ; preds = %87 - %93 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @3, i32 0, i32 0) }, 0 - %94 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @3, i32 0, i32 0) }, 1 - %95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.3, i32 0, i32 0), i32 %93, i8* %94) - call void @abort() - br label %cond_exit_51 - -cond_51_case_1: ; preds = %89 - br label %cond_exit_51 - -cond_exit_51: ; preds = %cond_51_case_1, %cond_51_case_0 - %"056.0" = phi i64 [ 0, %cond_51_case_0 ], [ %91, %cond_51_case_1 ] - %"157.0" = phi [1 x i64] [ zeroinitializer, %cond_51_case_0 ], [ %92, %cond_51_case_1 ] - %96 = alloca i64, align 8 - %97 = bitcast i64* %96 to [1 x i64]* - store [1 x i64] %"157.0", [1 x i64]* %97, align 4 - %98 = getelementptr i64, i64* %96, i32 0 - %99 = load i64, i64* %98, align 4 - %100 = bitcast i64* %96 to [0 x i64]* - %101 = load [0 x i64], [0 x i64]* %100, align 4 - %102 = insertvalue { i64, [0 x i64] } undef, i64 %99, 0 - %103 = insertvalue { i64, [0 x i64] } %102, [0 x i64] %101, 1 - %104 = insertvalue { i32, {}, { i64, [0 x i64] } } { i32 1, {} poison, { i64, [0 x i64] } poison }, { i64, [0 x i64] } %103, 2 - %105 = extractvalue { i32, {}, { i64, [0 x i64] } } %104, 0 - switch i32 %105, label %106 [ - i32 1, label %108 - ] - -106: ; preds = %cond_exit_51 - %107 = extractvalue { i32, {}, { i64, [0 x i64] } } %104, 1 - br label %cond_62_case_0 - -108: ; preds = %cond_exit_51 - %109 = extractvalue { i32, {}, { i64, [0 x i64] } } %104, 2 - %110 = extractvalue { i64, [0 x i64] } %109, 0 - %111 = extractvalue { i64, [0 x i64] } %109, 1 - br label %cond_62_case_1 - -cond_62_case_0: ; preds = %106 - %112 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @4, i32 0, i32 0) }, 0 - %113 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @4, i32 0, i32 0) }, 1 - %114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.4, i32 0, i32 0), i32 %112, i8* %113) - call void @abort() - br label %cond_exit_62 - -cond_62_case_1: ; preds = %108 - br label %cond_exit_62 - -cond_exit_62: ; preds = %cond_62_case_1, %cond_62_case_0 - %"071.0" = phi i64 [ 0, %cond_62_case_0 ], [ %110, %cond_62_case_1 ] - %"172.0" = phi [0 x i64] [ zeroinitializer, %cond_62_case_0 ], [ %111, %cond_62_case_1 ] - ret void -} - -declare i32 @printf(i8*, ...) - -declare void @abort() diff --git a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_all_ops@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_all_ops@pre-mem2reg@llvm14.snap deleted file mode 100644 index 014261c82..000000000 --- a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_all_ops@pre-mem2reg@llvm14.snap +++ /dev/null @@ -1,451 +0,0 @@ ---- -source: src/extension/prelude/array.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@1 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.1 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@2 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.2 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@3 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.3 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@4 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.4 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 - -define void @_hl.main.1() { -alloca_block: - %"12_0" = alloca i64, align 8 - %"10_0" = alloca i64, align 8 - %"13_0" = alloca [2 x i64], align 8 - %"8_0" = alloca i64, align 8 - %"14_0" = alloca { i32, { [2 x i64] }, { [2 x i64] } }, align 8 - %"0" = alloca { i32, { [2 x i64] }, { [2 x i64] } }, align 8 - %"16_0" = alloca [2 x i64], align 8 - %"08" = alloca [2 x i64], align 8 - %"010" = alloca [2 x i64], align 8 - %"21_0" = alloca { i32, i8* }, align 8 - %"18_0" = alloca [2 x i64], align 8 - %"22_0" = alloca [2 x i64], align 8 - %"015" = alloca [2 x i64], align 8 - %"24_0" = alloca [2 x i64], align 8 - %"26_0" = alloca { i32, {}, { i64 } }, align 8 - %"020" = alloca { i32, {}, { i64 } }, align 8 - %"28_0" = alloca i64, align 8 - %"023" = alloca i64, align 8 - %"33_0" = alloca { i32, i8* }, align 8 - %"34_0" = alloca i64, align 8 - %"027" = alloca i64, align 8 - %"36_0" = alloca i64, align 8 - %"38_0" = alloca { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }, align 8 - %"033" = alloca { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }, align 8 - %"40_0" = alloca i64, align 8 - %"40_1" = alloca [2 x i64], align 8 - %"036" = alloca i64, align 8 - %"1" = alloca [2 x i64], align 8 - %"039" = alloca i64, align 8 - %"140" = alloca [2 x i64], align 8 - %"45_0" = alloca { i32, i8* }, align 8 - %"42_0" = alloca i64, align 8 - %"42_1" = alloca [2 x i64], align 8 - %"46_0" = alloca i64, align 8 - %"46_1" = alloca [2 x i64], align 8 - %"048" = alloca i64, align 8 - %"149" = alloca [2 x i64], align 8 - %"48_0" = alloca i64, align 8 - %"48_1" = alloca [2 x i64], align 8 - %"50_0" = alloca { i32, {}, { i64, [1 x i64] } }, align 8 - %"51_0" = alloca i64, align 8 - %"51_1" = alloca [1 x i64], align 8 - %"056" = alloca i64, align 8 - %"157" = alloca [1 x i64], align 8 - %"56_0" = alloca { i32, i8* }, align 8 - %"57_0" = alloca i64, align 8 - %"57_1" = alloca [1 x i64], align 8 - %"063" = alloca i64, align 8 - %"164" = alloca [1 x i64], align 8 - %"59_0" = alloca i64, align 8 - %"59_1" = alloca [1 x i64], align 8 - %"61_0" = alloca { i32, {}, { i64, [0 x i64] } }, align 8 - %"62_0" = alloca i64, align 8 - %"62_1" = alloca [0 x i64], align 8 - %"071" = alloca i64, align 8 - %"172" = alloca [0 x i64], align 8 - %"67_0" = alloca { i32, i8* }, align 8 - %"68_0" = alloca i64, align 8 - %"68_1" = alloca [0 x i64], align 8 - %"078" = alloca i64, align 8 - %"179" = alloca [0 x i64], align 8 - %"70_0" = alloca i64, align 8 - %"70_1" = alloca [0 x i64], align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i64 2, i64* %"12_0", align 4 - store i64 1, i64* %"10_0", align 4 - %"10_01" = load i64, i64* %"10_0", align 4 - %"12_02" = load i64, i64* %"12_0", align 4 - %0 = insertvalue [2 x i64] undef, i64 %"10_01", 0 - %1 = insertvalue [2 x i64] %0, i64 %"12_02", 1 - store [2 x i64] %1, [2 x i64]* %"13_0", align 4 - store i64 0, i64* %"8_0", align 4 - %"13_03" = load [2 x i64], [2 x i64]* %"13_0", align 4 - %"8_04" = load i64, i64* %"8_0", align 4 - %"10_05" = load i64, i64* %"10_0", align 4 - %2 = icmp ult i64 %"8_04", 2 - %3 = icmp ult i64 %"10_05", 2 - %4 = and i1 %2, %3 - br i1 %4, label %8, label %5 - -5: ; preds = %entry_block - %6 = insertvalue { [2 x i64] } undef, [2 x i64] %"13_03", 0 - %7 = insertvalue { i32, { [2 x i64] }, { [2 x i64] } } { i32 0, { [2 x i64] } poison, { [2 x i64] } poison }, { [2 x i64] } %6, 1 - store { i32, { [2 x i64] }, { [2 x i64] } } %7, { i32, { [2 x i64] }, { [2 x i64] } }* %"0", align 4 - br label %19 - -8: ; preds = %entry_block - %9 = alloca i64, i32 2, align 8 - %10 = bitcast i64* %9 to [2 x i64]* - store [2 x i64] %"13_03", [2 x i64]* %10, align 4 - %11 = getelementptr inbounds i64, i64* %9, i64 %"8_04" - %12 = load i64, i64* %11, align 4 - %13 = getelementptr inbounds i64, i64* %9, i64 %"10_05" - %14 = load i64, i64* %13, align 4 - store i64 %14, i64* %11, align 4 - store i64 %12, i64* %13, align 4 - %15 = bitcast i64* %9 to [2 x i64]* - %16 = load [2 x i64], [2 x i64]* %15, align 4 - %17 = insertvalue { [2 x i64] } undef, [2 x i64] %16, 0 - %18 = insertvalue { i32, { [2 x i64] }, { [2 x i64] } } { i32 1, { [2 x i64] } poison, { [2 x i64] } poison }, { [2 x i64] } %17, 2 - store { i32, { [2 x i64] }, { [2 x i64] } } %18, { i32, { [2 x i64] }, { [2 x i64] } }* %"0", align 4 - br label %19 - -19: ; preds = %5, %8 - %"06" = load { i32, { [2 x i64] }, { [2 x i64] } }, { i32, { [2 x i64] }, { [2 x i64] } }* %"0", align 4 - store { i32, { [2 x i64] }, { [2 x i64] } } %"06", { i32, { [2 x i64] }, { [2 x i64] } }* %"14_0", align 4 - %"14_07" = load { i32, { [2 x i64] }, { [2 x i64] } }, { i32, { [2 x i64] }, { [2 x i64] } }* %"14_0", align 4 - %20 = extractvalue { i32, { [2 x i64] }, { [2 x i64] } } %"14_07", 0 - switch i32 %20, label %21 [ - i32 1, label %24 - ] - -21: ; preds = %19 - %22 = extractvalue { i32, { [2 x i64] }, { [2 x i64] } } %"14_07", 1 - %23 = extractvalue { [2 x i64] } %22, 0 - store [2 x i64] %23, [2 x i64]* %"010", align 4 - br label %cond_16_case_0 - -24: ; preds = %19 - %25 = extractvalue { i32, { [2 x i64] }, { [2 x i64] } } %"14_07", 2 - %26 = extractvalue { [2 x i64] } %25, 0 - store [2 x i64] %26, [2 x i64]* %"015", align 4 - br label %cond_16_case_1 - -cond_16_case_0: ; preds = %21 - %"011" = load [2 x i64], [2 x i64]* %"010", align 4 - store { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @0, i32 0, i32 0) }, { i32, i8* }* %"21_0", align 8 - store [2 x i64] %"011", [2 x i64]* %"18_0", align 4 - %"21_012" = load { i32, i8* }, { i32, i8* }* %"21_0", align 8 - %"18_013" = load [2 x i64], [2 x i64]* %"18_0", align 4 - %27 = extractvalue { i32, i8* } %"21_012", 0 - %28 = extractvalue { i32, i8* } %"21_012", 1 - %29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template, i32 0, i32 0), i32 %27, i8* %28) - call void @abort() - store [2 x i64] zeroinitializer, [2 x i64]* %"22_0", align 4 - %"22_014" = load [2 x i64], [2 x i64]* %"22_0", align 4 - store [2 x i64] %"22_014", [2 x i64]* %"08", align 4 - br label %cond_exit_16 - -cond_16_case_1: ; preds = %24 - %"016" = load [2 x i64], [2 x i64]* %"015", align 4 - store [2 x i64] %"016", [2 x i64]* %"24_0", align 4 - %"24_017" = load [2 x i64], [2 x i64]* %"24_0", align 4 - store [2 x i64] %"24_017", [2 x i64]* %"08", align 4 - br label %cond_exit_16 - -cond_exit_16: ; preds = %cond_16_case_1, %cond_16_case_0 - %"09" = load [2 x i64], [2 x i64]* %"08", align 4 - store [2 x i64] %"09", [2 x i64]* %"16_0", align 4 - %"16_018" = load [2 x i64], [2 x i64]* %"16_0", align 4 - %"8_019" = load i64, i64* %"8_0", align 4 - %30 = icmp ult i64 %"8_019", 2 - br i1 %30, label %32, label %31 - -31: ; preds = %cond_exit_16 - store { i32, {}, { i64 } } { i32 0, {} undef, { i64 } poison }, { i32, {}, { i64 } }* %"020", align 4 - br label %39 - -32: ; preds = %cond_exit_16 - %33 = alloca i64, i32 2, align 8 - %34 = bitcast i64* %33 to [2 x i64]* - store [2 x i64] %"16_018", [2 x i64]* %34, align 4 - %35 = getelementptr inbounds i64, i64* %33, i64 %"8_019" - %36 = load i64, i64* %35, align 4 - %37 = insertvalue { i64 } undef, i64 %36, 0 - %38 = insertvalue { i32, {}, { i64 } } { i32 1, {} poison, { i64 } poison }, { i64 } %37, 2 - store { i32, {}, { i64 } } %38, { i32, {}, { i64 } }* %"020", align 4 - br label %39 - -39: ; preds = %31, %32 - %"021" = load { i32, {}, { i64 } }, { i32, {}, { i64 } }* %"020", align 4 - store { i32, {}, { i64 } } %"021", { i32, {}, { i64 } }* %"26_0", align 4 - %"26_022" = load { i32, {}, { i64 } }, { i32, {}, { i64 } }* %"26_0", align 4 - %40 = extractvalue { i32, {}, { i64 } } %"26_022", 0 - switch i32 %40, label %41 [ - i32 1, label %43 - ] - -41: ; preds = %39 - %42 = extractvalue { i32, {}, { i64 } } %"26_022", 1 - br label %cond_28_case_0 - -43: ; preds = %39 - %44 = extractvalue { i32, {}, { i64 } } %"26_022", 2 - %45 = extractvalue { i64 } %44, 0 - store i64 %45, i64* %"027", align 4 - br label %cond_28_case_1 - -cond_28_case_0: ; preds = %41 - store { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @1, i32 0, i32 0) }, { i32, i8* }* %"33_0", align 8 - %"33_025" = load { i32, i8* }, { i32, i8* }* %"33_0", align 8 - %46 = extractvalue { i32, i8* } %"33_025", 0 - %47 = extractvalue { i32, i8* } %"33_025", 1 - %48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.1, i32 0, i32 0), i32 %46, i8* %47) - call void @abort() - store i64 0, i64* %"34_0", align 4 - %"34_026" = load i64, i64* %"34_0", align 4 - store i64 %"34_026", i64* %"023", align 4 - br label %cond_exit_28 - -cond_28_case_1: ; preds = %43 - %"028" = load i64, i64* %"027", align 4 - store i64 %"028", i64* %"36_0", align 4 - %"36_029" = load i64, i64* %"36_0", align 4 - store i64 %"36_029", i64* %"023", align 4 - br label %cond_exit_28 - -cond_exit_28: ; preds = %cond_28_case_1, %cond_28_case_0 - %"024" = load i64, i64* %"023", align 4 - store i64 %"024", i64* %"28_0", align 4 - %"16_030" = load [2 x i64], [2 x i64]* %"16_0", align 4 - %"10_031" = load i64, i64* %"10_0", align 4 - %"28_032" = load i64, i64* %"28_0", align 4 - %49 = icmp ult i64 %"10_031", 2 - br i1 %49, label %54, label %50 - -50: ; preds = %cond_exit_28 - %51 = insertvalue { i64, [2 x i64] } undef, i64 %"28_032", 0 - %52 = insertvalue { i64, [2 x i64] } %51, [2 x i64] %"16_030", 1 - %53 = insertvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } { i32 0, { i64, [2 x i64] } poison, { i64, [2 x i64] } poison }, { i64, [2 x i64] } %52, 1 - store { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %53, { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }* %"033", align 4 - br label %64 - -54: ; preds = %cond_exit_28 - %55 = alloca i64, i32 2, align 8 - %56 = bitcast i64* %55 to [2 x i64]* - store [2 x i64] %"16_030", [2 x i64]* %56, align 4 - %57 = getelementptr inbounds i64, i64* %55, i64 %"10_031" - %58 = load i64, i64* %57, align 4 - store i64 %"28_032", i64* %57, align 4 - %59 = bitcast i64* %55 to [2 x i64]* - %60 = load [2 x i64], [2 x i64]* %59, align 4 - %61 = insertvalue { i64, [2 x i64] } undef, i64 %58, 0 - %62 = insertvalue { i64, [2 x i64] } %61, [2 x i64] %60, 1 - %63 = insertvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } { i32 1, { i64, [2 x i64] } poison, { i64, [2 x i64] } poison }, { i64, [2 x i64] } %62, 2 - store { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %63, { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }* %"033", align 4 - br label %64 - -64: ; preds = %50, %54 - %"034" = load { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }, { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }* %"033", align 4 - store { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"034", { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }* %"38_0", align 4 - %"38_035" = load { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }, { i32, { i64, [2 x i64] }, { i64, [2 x i64] } }* %"38_0", align 4 - %65 = extractvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"38_035", 0 - switch i32 %65, label %66 [ - i32 1, label %70 - ] - -66: ; preds = %64 - %67 = extractvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"38_035", 1 - %68 = extractvalue { i64, [2 x i64] } %67, 0 - %69 = extractvalue { i64, [2 x i64] } %67, 1 - store i64 %68, i64* %"039", align 4 - store [2 x i64] %69, [2 x i64]* %"140", align 4 - br label %cond_40_case_0 - -70: ; preds = %64 - %71 = extractvalue { i32, { i64, [2 x i64] }, { i64, [2 x i64] } } %"38_035", 2 - %72 = extractvalue { i64, [2 x i64] } %71, 0 - %73 = extractvalue { i64, [2 x i64] } %71, 1 - store i64 %72, i64* %"048", align 4 - store [2 x i64] %73, [2 x i64]* %"149", align 4 - br label %cond_40_case_1 - -cond_40_case_0: ; preds = %66 - %"041" = load i64, i64* %"039", align 4 - %"142" = load [2 x i64], [2 x i64]* %"140", align 4 - store { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @2, i32 0, i32 0) }, { i32, i8* }* %"45_0", align 8 - store i64 %"041", i64* %"42_0", align 4 - store [2 x i64] %"142", [2 x i64]* %"42_1", align 4 - %"45_043" = load { i32, i8* }, { i32, i8* }* %"45_0", align 8 - %"42_044" = load i64, i64* %"42_0", align 4 - %"42_145" = load [2 x i64], [2 x i64]* %"42_1", align 4 - %74 = extractvalue { i32, i8* } %"45_043", 0 - %75 = extractvalue { i32, i8* } %"45_043", 1 - %76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.2, i32 0, i32 0), i32 %74, i8* %75) - call void @abort() - store i64 0, i64* %"46_0", align 4 - store [2 x i64] zeroinitializer, [2 x i64]* %"46_1", align 4 - %"46_046" = load i64, i64* %"46_0", align 4 - %"46_147" = load [2 x i64], [2 x i64]* %"46_1", align 4 - store i64 %"46_046", i64* %"036", align 4 - store [2 x i64] %"46_147", [2 x i64]* %"1", align 4 - br label %cond_exit_40 - -cond_40_case_1: ; preds = %70 - %"050" = load i64, i64* %"048", align 4 - %"151" = load [2 x i64], [2 x i64]* %"149", align 4 - store i64 %"050", i64* %"48_0", align 4 - store [2 x i64] %"151", [2 x i64]* %"48_1", align 4 - %"48_052" = load i64, i64* %"48_0", align 4 - %"48_153" = load [2 x i64], [2 x i64]* %"48_1", align 4 - store i64 %"48_052", i64* %"036", align 4 - store [2 x i64] %"48_153", [2 x i64]* %"1", align 4 - br label %cond_exit_40 - -cond_exit_40: ; preds = %cond_40_case_1, %cond_40_case_0 - %"037" = load i64, i64* %"036", align 4 - %"138" = load [2 x i64], [2 x i64]* %"1", align 4 - store i64 %"037", i64* %"40_0", align 4 - store [2 x i64] %"138", [2 x i64]* %"40_1", align 4 - %"40_154" = load [2 x i64], [2 x i64]* %"40_1", align 4 - %77 = alloca i64, i32 2, align 8 - %78 = bitcast i64* %77 to [2 x i64]* - store [2 x i64] %"40_154", [2 x i64]* %78, align 4 - %79 = getelementptr i64, i64* %77, i32 1 - %80 = load i64, i64* %77, align 4 - %81 = bitcast i64* %79 to [1 x i64]* - %82 = load [1 x i64], [1 x i64]* %81, align 4 - %83 = insertvalue { i64, [1 x i64] } undef, i64 %80, 0 - %84 = insertvalue { i64, [1 x i64] } %83, [1 x i64] %82, 1 - %85 = insertvalue { i32, {}, { i64, [1 x i64] } } { i32 1, {} poison, { i64, [1 x i64] } poison }, { i64, [1 x i64] } %84, 2 - store { i32, {}, { i64, [1 x i64] } } %85, { i32, {}, { i64, [1 x i64] } }* %"50_0", align 4 - %"50_055" = load { i32, {}, { i64, [1 x i64] } }, { i32, {}, { i64, [1 x i64] } }* %"50_0", align 4 - %86 = extractvalue { i32, {}, { i64, [1 x i64] } } %"50_055", 0 - switch i32 %86, label %87 [ - i32 1, label %89 - ] - -87: ; preds = %cond_exit_40 - %88 = extractvalue { i32, {}, { i64, [1 x i64] } } %"50_055", 1 - br label %cond_51_case_0 - -89: ; preds = %cond_exit_40 - %90 = extractvalue { i32, {}, { i64, [1 x i64] } } %"50_055", 2 - %91 = extractvalue { i64, [1 x i64] } %90, 0 - %92 = extractvalue { i64, [1 x i64] } %90, 1 - store i64 %91, i64* %"063", align 4 - store [1 x i64] %92, [1 x i64]* %"164", align 4 - br label %cond_51_case_1 - -cond_51_case_0: ; preds = %87 - store { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @3, i32 0, i32 0) }, { i32, i8* }* %"56_0", align 8 - %"56_060" = load { i32, i8* }, { i32, i8* }* %"56_0", align 8 - %93 = extractvalue { i32, i8* } %"56_060", 0 - %94 = extractvalue { i32, i8* } %"56_060", 1 - %95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.3, i32 0, i32 0), i32 %93, i8* %94) - call void @abort() - store i64 0, i64* %"57_0", align 4 - store [1 x i64] zeroinitializer, [1 x i64]* %"57_1", align 4 - %"57_061" = load i64, i64* %"57_0", align 4 - %"57_162" = load [1 x i64], [1 x i64]* %"57_1", align 4 - store i64 %"57_061", i64* %"056", align 4 - store [1 x i64] %"57_162", [1 x i64]* %"157", align 4 - br label %cond_exit_51 - -cond_51_case_1: ; preds = %89 - %"065" = load i64, i64* %"063", align 4 - %"166" = load [1 x i64], [1 x i64]* %"164", align 4 - store i64 %"065", i64* %"59_0", align 4 - store [1 x i64] %"166", [1 x i64]* %"59_1", align 4 - %"59_067" = load i64, i64* %"59_0", align 4 - %"59_168" = load [1 x i64], [1 x i64]* %"59_1", align 4 - store i64 %"59_067", i64* %"056", align 4 - store [1 x i64] %"59_168", [1 x i64]* %"157", align 4 - br label %cond_exit_51 - -cond_exit_51: ; preds = %cond_51_case_1, %cond_51_case_0 - %"058" = load i64, i64* %"056", align 4 - %"159" = load [1 x i64], [1 x i64]* %"157", align 4 - store i64 %"058", i64* %"51_0", align 4 - store [1 x i64] %"159", [1 x i64]* %"51_1", align 4 - %"51_169" = load [1 x i64], [1 x i64]* %"51_1", align 4 - %96 = alloca i64, align 8 - %97 = bitcast i64* %96 to [1 x i64]* - store [1 x i64] %"51_169", [1 x i64]* %97, align 4 - %98 = getelementptr i64, i64* %96, i32 0 - %99 = load i64, i64* %98, align 4 - %100 = bitcast i64* %96 to [0 x i64]* - %101 = load [0 x i64], [0 x i64]* %100, align 4 - %102 = insertvalue { i64, [0 x i64] } undef, i64 %99, 0 - %103 = insertvalue { i64, [0 x i64] } %102, [0 x i64] %101, 1 - %104 = insertvalue { i32, {}, { i64, [0 x i64] } } { i32 1, {} poison, { i64, [0 x i64] } poison }, { i64, [0 x i64] } %103, 2 - store { i32, {}, { i64, [0 x i64] } } %104, { i32, {}, { i64, [0 x i64] } }* %"61_0", align 4 - %"61_070" = load { i32, {}, { i64, [0 x i64] } }, { i32, {}, { i64, [0 x i64] } }* %"61_0", align 4 - %105 = extractvalue { i32, {}, { i64, [0 x i64] } } %"61_070", 0 - switch i32 %105, label %106 [ - i32 1, label %108 - ] - -106: ; preds = %cond_exit_51 - %107 = extractvalue { i32, {}, { i64, [0 x i64] } } %"61_070", 1 - br label %cond_62_case_0 - -108: ; preds = %cond_exit_51 - %109 = extractvalue { i32, {}, { i64, [0 x i64] } } %"61_070", 2 - %110 = extractvalue { i64, [0 x i64] } %109, 0 - %111 = extractvalue { i64, [0 x i64] } %109, 1 - store i64 %110, i64* %"078", align 4 - store [0 x i64] %111, [0 x i64]* %"179", align 4 - br label %cond_62_case_1 - -cond_62_case_0: ; preds = %106 - store { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @4, i32 0, i32 0) }, { i32, i8* }* %"67_0", align 8 - %"67_075" = load { i32, i8* }, { i32, i8* }* %"67_0", align 8 - %112 = extractvalue { i32, i8* } %"67_075", 0 - %113 = extractvalue { i32, i8* } %"67_075", 1 - %114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.4, i32 0, i32 0), i32 %112, i8* %113) - call void @abort() - store i64 0, i64* %"68_0", align 4 - store [0 x i64] zeroinitializer, [0 x i64]* %"68_1", align 4 - %"68_076" = load i64, i64* %"68_0", align 4 - %"68_177" = load [0 x i64], [0 x i64]* %"68_1", align 4 - store i64 %"68_076", i64* %"071", align 4 - store [0 x i64] %"68_177", [0 x i64]* %"172", align 4 - br label %cond_exit_62 - -cond_62_case_1: ; preds = %108 - %"080" = load i64, i64* %"078", align 4 - %"181" = load [0 x i64], [0 x i64]* %"179", align 4 - store i64 %"080", i64* %"70_0", align 4 - store [0 x i64] %"181", [0 x i64]* %"70_1", align 4 - %"70_082" = load i64, i64* %"70_0", align 4 - %"70_183" = load [0 x i64], [0 x i64]* %"70_1", align 4 - store i64 %"70_082", i64* %"071", align 4 - store [0 x i64] %"70_183", [0 x i64]* %"172", align 4 - br label %cond_exit_62 - -cond_exit_62: ; preds = %cond_62_case_1, %cond_62_case_0 - %"073" = load i64, i64* %"071", align 4 - %"174" = load [0 x i64], [0 x i64]* %"172", align 4 - store i64 %"073", i64* %"62_0", align 4 - store [0 x i64] %"174", [0 x i64]* %"62_1", align 4 - %"62_184" = load [0 x i64], [0 x i64]* %"62_1", align 4 - ret void -} - -declare i32 @printf(i8*, ...) - -declare void @abort() diff --git a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_get@llvm14.snap b/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_get@llvm14.snap deleted file mode 100644 index e24958cfe..000000000 --- a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_get@llvm14.snap +++ /dev/null @@ -1,34 +0,0 @@ ---- -source: src/extension/prelude/array.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -define void @_hl.main.1() { -alloca_block: - br label %entry_block - -entry_block: ; preds = %alloca_block - %0 = insertvalue [2 x i64] undef, i64 1, 0 - %1 = insertvalue [2 x i64] %0, i64 2, 1 - %2 = icmp ult i64 1, 2 - br i1 %2, label %4, label %3 - -3: ; preds = %entry_block - br label %11 - -4: ; preds = %entry_block - %5 = alloca i64, i32 2, align 8 - %6 = bitcast i64* %5 to [2 x i64]* - store [2 x i64] %1, [2 x i64]* %6, align 4 - %7 = getelementptr inbounds i64, i64* %5, i64 1 - %8 = load i64, i64* %7, align 4 - %9 = insertvalue { i64 } undef, i64 %8, 0 - %10 = insertvalue { i32, {}, { i64 } } { i32 1, {} poison, { i64 } poison }, { i64 } %9, 2 - br label %11 - -11: ; preds = %3, %4 - %"0.0" = phi { i32, {}, { i64 } } [ %10, %4 ], [ { i32 0, {} undef, { i64 } poison }, %3 ] - ret void -} diff --git a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_get@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_get@pre-mem2reg@llvm14.snap deleted file mode 100644 index a01596c70..000000000 --- a/hugr-llvm/src/extension/prelude/snapshots/hugr_llvm__extension__prelude__array__test__emit_get@pre-mem2reg@llvm14.snap +++ /dev/null @@ -1,49 +0,0 @@ ---- -source: src/extension/prelude/array.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -define void @_hl.main.1() { -alloca_block: - %"7_0" = alloca i64, align 8 - %"5_0" = alloca i64, align 8 - %"8_0" = alloca [2 x i64], align 8 - %"9_0" = alloca { i32, {}, { i64 } }, align 8 - %"0" = alloca { i32, {}, { i64 } }, align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i64 2, i64* %"7_0", align 4 - store i64 1, i64* %"5_0", align 4 - %"5_01" = load i64, i64* %"5_0", align 4 - %"7_02" = load i64, i64* %"7_0", align 4 - %0 = insertvalue [2 x i64] undef, i64 %"5_01", 0 - %1 = insertvalue [2 x i64] %0, i64 %"7_02", 1 - store [2 x i64] %1, [2 x i64]* %"8_0", align 4 - %"8_03" = load [2 x i64], [2 x i64]* %"8_0", align 4 - %"5_04" = load i64, i64* %"5_0", align 4 - %2 = icmp ult i64 %"5_04", 2 - br i1 %2, label %4, label %3 - -3: ; preds = %entry_block - store { i32, {}, { i64 } } { i32 0, {} undef, { i64 } poison }, { i32, {}, { i64 } }* %"0", align 4 - br label %11 - -4: ; preds = %entry_block - %5 = alloca i64, i32 2, align 8 - %6 = bitcast i64* %5 to [2 x i64]* - store [2 x i64] %"8_03", [2 x i64]* %6, align 4 - %7 = getelementptr inbounds i64, i64* %5, i64 %"5_04" - %8 = load i64, i64* %7, align 4 - %9 = insertvalue { i64 } undef, i64 %8, 0 - %10 = insertvalue { i32, {}, { i64 } } { i32 1, {} poison, { i64 } poison }, { i64 } %9, 2 - store { i32, {}, { i64 } } %10, { i32, {}, { i64 } }* %"0", align 4 - br label %11 - -11: ; preds = %3, %4 - %"05" = load { i32, {}, { i64 } }, { i32, {}, { i64 } }* %"0", align 4 - store { i32, {}, { i64 } } %"05", { i32, {}, { i64 } }* %"9_0", align 4 - ret void -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_s@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_s@llvm14.snap deleted file mode 100644 index 19f280953..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_s@llvm14.snap +++ /dev/null @@ -1,19 +0,0 @@ ---- -source: hugr-llvm/src/extension/int.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [25 x i8] c"Can't narrow into bounds\00", align 1 - -define { i1, { i32, i8* }, i8 } @_hl.main.1(i8 %0) { -alloca_block: - br label %entry_block - -entry_block: ; preds = %alloca_block - %bounds_check = icmp sgt i8 %0, 7 - %1 = insertvalue { i1, { i32, i8* }, i8 } { i1 true, { i32, i8* } poison, i8 poison }, i8 %0, 2 - %2 = select i1 %bounds_check, { i1, { i32, i8* }, i8 } { i1 false, { i32, i8* } { i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @0, i32 0, i32 0) }, i8 poison }, { i1, { i32, i8* }, i8 } %1 - ret { i1, { i32, i8* }, i8 } %2 -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_s@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_s@pre-mem2reg@llvm14.snap deleted file mode 100644 index 5ab734c17..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_s@pre-mem2reg@llvm14.snap +++ /dev/null @@ -1,28 +0,0 @@ ---- -source: hugr-llvm/src/extension/int.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [25 x i8] c"Can't narrow into bounds\00", align 1 - -define { i1, { i32, i8* }, i8 } @_hl.main.1(i8 %0) { -alloca_block: - %"0" = alloca { i1, { i32, i8* }, i8 }, align 8 - %"2_0" = alloca i8, align 1 - %"4_0" = alloca { i1, { i32, i8* }, i8 }, align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i8 %0, i8* %"2_0", align 1 - %"2_01" = load i8, i8* %"2_0", align 1 - %bounds_check = icmp sgt i8 %"2_01", 7 - %1 = insertvalue { i1, { i32, i8* }, i8 } { i1 true, { i32, i8* } poison, i8 poison }, i8 %"2_01", 2 - %2 = select i1 %bounds_check, { i1, { i32, i8* }, i8 } { i1 false, { i32, i8* } { i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @0, i32 0, i32 0) }, i8 poison }, { i1, { i32, i8* }, i8 } %1 - store { i1, { i32, i8* }, i8 } %2, { i1, { i32, i8* }, i8 }* %"4_0", align 8 - %"4_02" = load { i1, { i32, i8* }, i8 }, { i1, { i32, i8* }, i8 }* %"4_0", align 8 - store { i1, { i32, i8* }, i8 } %"4_02", { i1, { i32, i8* }, i8 }* %"0", align 8 - %"03" = load { i1, { i32, i8* }, i8 }, { i1, { i32, i8* }, i8 }* %"0", align 8 - ret { i1, { i32, i8* }, i8 } %"03" -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_u@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_u@llvm14.snap deleted file mode 100644 index 5a920e1d6..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_u@llvm14.snap +++ /dev/null @@ -1,20 +0,0 @@ ---- -source: hugr-llvm/src/extension/int.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [25 x i8] c"Can't narrow into bounds\00", align 1 - -define { i1, { i32, i8* }, i16 } @_hl.main.1(i64 %0) { -alloca_block: - br label %entry_block - -entry_block: ; preds = %alloca_block - %bounds_check = icmp ugt i64 %0, 65535 - %1 = trunc i64 %0 to i16 - %2 = insertvalue { i1, { i32, i8* }, i16 } { i1 true, { i32, i8* } poison, i16 poison }, i16 %1, 2 - %3 = select i1 %bounds_check, { i1, { i32, i8* }, i16 } { i1 false, { i32, i8* } { i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @0, i32 0, i32 0) }, i16 poison }, { i1, { i32, i8* }, i16 } %2 - ret { i1, { i32, i8* }, i16 } %3 -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_u@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_u@pre-mem2reg@llvm14.snap deleted file mode 100644 index 4c398fe2c..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__inarrow_u@pre-mem2reg@llvm14.snap +++ /dev/null @@ -1,29 +0,0 @@ ---- -source: hugr-llvm/src/extension/int.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [25 x i8] c"Can't narrow into bounds\00", align 1 - -define { i1, { i32, i8* }, i16 } @_hl.main.1(i64 %0) { -alloca_block: - %"0" = alloca { i1, { i32, i8* }, i16 }, align 8 - %"2_0" = alloca i64, align 8 - %"4_0" = alloca { i1, { i32, i8* }, i16 }, align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i64 %0, i64* %"2_0", align 4 - %"2_01" = load i64, i64* %"2_0", align 4 - %bounds_check = icmp ugt i64 %"2_01", 65535 - %1 = trunc i64 %"2_01" to i16 - %2 = insertvalue { i1, { i32, i8* }, i16 } { i1 true, { i32, i8* } poison, i16 poison }, i16 %1, 2 - %3 = select i1 %bounds_check, { i1, { i32, i8* }, i16 } { i1 false, { i32, i8* } { i32 2, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @0, i32 0, i32 0) }, i16 poison }, { i1, { i32, i8* }, i16 } %2 - store { i1, { i32, i8* }, i16 } %3, { i1, { i32, i8* }, i16 }* %"4_0", align 8 - %"4_02" = load { i1, { i32, i8* }, i16 }, { i1, { i32, i8* }, i16 }* %"4_0", align 8 - store { i1, { i32, i8* }, i16 } %"4_02", { i1, { i32, i8* }, i16 }* %"0", align 8 - %"03" = load { i1, { i32, i8* }, i16 }, { i1, { i32, i8* }, i16 }* %"0", align 8 - ret { i1, { i32, i8* }, i16 } %"03" -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ineg@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ineg@llvm14.snap deleted file mode 100644 index cae1b5ba6..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ineg@llvm14.snap +++ /dev/null @@ -1,15 +0,0 @@ ---- -source: src/extension/int.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -define i8 @_hl.main.1(i8 %0) { -alloca_block: - br label %entry_block - -entry_block: ; preds = %alloca_block - %1 = sub i8 0, %0 - ret i8 %1 -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ineg@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ineg@pre-mem2reg@llvm14.snap deleted file mode 100644 index d203a8a1b..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__int__test__ineg@pre-mem2reg@llvm14.snap +++ /dev/null @@ -1,24 +0,0 @@ ---- -source: src/extension/int.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -define i8 @_hl.main.1(i8 %0) { -alloca_block: - %"0" = alloca i8, align 1 - %"2_0" = alloca i8, align 1 - %"4_0" = alloca i8, align 1 - br label %entry_block - -entry_block: ; preds = %alloca_block - store i8 %0, i8* %"2_0", align 1 - %"2_01" = load i8, i8* %"2_0", align 1 - %1 = sub i8 0, %"2_01" - store i8 %1, i8* %"4_0", align 1 - %"4_02" = load i8, i8* %"4_0", align 1 - store i8 %"4_02", i8* %"0", align 1 - %"03" = load i8, i8* %"0", align 1 - ret i8 %"03" -} diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__rotation__test__emit_all_ops@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__rotation__test__emit_all_ops@llvm14.snap deleted file mode 100644 index 95481fb3f..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__rotation__test__emit_all_ops@llvm14.snap +++ /dev/null @@ -1,73 +0,0 @@ ---- -source: src/extension/rotation.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [47 x i8] c"tket2.rotation.from_halfturns_unchecked failed\00", align 1 -@prelude.panic_template = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@1 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.1 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 - -define void @_hl.main.1(double %0) { -alloca_block: - br label %entry_block - -entry_block: ; preds = %alloca_block - %1 = fcmp oeq double %0, 0x7FF0000000000000 - %2 = fcmp oeq double %0, 0xFFF0000000000000 - %3 = fcmp uno double %0, 0.000000e+00 - %4 = or i1 %1, %2 - %5 = or i1 %4, %3 - %6 = xor i1 %5, true - br i1 %6, label %9, label %7 - -7: ; preds = %entry_block - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template, i32 0, i32 0), i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @0, i32 0, i32 0)) - call void @abort() - unreachable - -9: ; preds = %entry_block - %10 = fcmp oeq double %0, 0x7FF0000000000000 - %11 = fcmp oeq double %0, 0xFFF0000000000000 - %12 = fcmp uno double %0, 0.000000e+00 - %13 = or i1 %10, %11 - %14 = or i1 %13, %12 - %15 = xor i1 %14, true - %16 = insertvalue { double } undef, double %0, 0 - %17 = insertvalue { i32, {}, { double } } { i32 1, {} poison, { double } poison }, { double } %16, 2 - %18 = select i1 %15, { i32, {}, { double } } %17, { i32, {}, { double } } { i32 0, {} undef, { double } poison } - %19 = extractvalue { i32, {}, { double } } %18, 0 - switch i32 %19, label %20 [ - i32 1, label %22 - ] - -20: ; preds = %9 - %21 = extractvalue { i32, {}, { double } } %18, 1 - br label %cond_7_case_0 - -22: ; preds = %9 - %23 = extractvalue { i32, {}, { double } } %18, 2 - %24 = extractvalue { double } %23, 0 - br label %cond_7_case_1 - -cond_7_case_0: ; preds = %20 - %25 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @1, i32 0, i32 0) }, 0 - %26 = extractvalue { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @1, i32 0, i32 0) }, 1 - %27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.1, i32 0, i32 0), i32 %25, i8* %26) - call void @abort() - br label %cond_exit_7 - -cond_7_case_1: ; preds = %22 - br label %cond_exit_7 - -cond_exit_7: ; preds = %cond_7_case_1, %cond_7_case_0 - %"0.0" = phi double [ 0.000000e+00, %cond_7_case_0 ], [ %24, %cond_7_case_1 ] - %28 = fadd double %0, %"0.0" - ret void -} - -declare i32 @printf(i8*, ...) - -declare void @abort() diff --git a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__rotation__test__emit_all_ops@pre-mem2reg@llvm14.snap b/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__rotation__test__emit_all_ops@pre-mem2reg@llvm14.snap deleted file mode 100644 index 02ef0aa71..000000000 --- a/hugr-llvm/src/extension/snapshots/hugr_llvm__extension__rotation__test__emit_all_ops@pre-mem2reg@llvm14.snap +++ /dev/null @@ -1,106 +0,0 @@ ---- -source: src/extension/rotation.rs -expression: mod_str ---- -; ModuleID = 'test_context' -source_filename = "test_context" - -@0 = private unnamed_addr constant [47 x i8] c"tket2.rotation.from_halfturns_unchecked failed\00", align 1 -@prelude.panic_template = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 -@1 = private unnamed_addr constant [37 x i8] c"Expected variant 1 but got variant 0\00", align 1 -@prelude.panic_template.1 = private unnamed_addr constant [34 x i8] c"Program panicked (signal %i): %s\0A\00", align 1 - -define void @_hl.main.1(double %0) { -alloca_block: - %"2_0" = alloca double, align 8 - %"4_0" = alloca double, align 8 - %"5_0" = alloca double, align 8 - %"6_0" = alloca { i32, {}, { double } }, align 8 - %"7_0" = alloca double, align 8 - %"0" = alloca double, align 8 - %"12_0" = alloca { i32, i8* }, align 8 - %"13_0" = alloca double, align 8 - %"08" = alloca double, align 8 - %"15_0" = alloca double, align 8 - %"17_0" = alloca double, align 8 - br label %entry_block - -entry_block: ; preds = %alloca_block - store double %0, double* %"2_0", align 8 - %"2_01" = load double, double* %"2_0", align 8 - %1 = fcmp oeq double %"2_01", 0x7FF0000000000000 - %2 = fcmp oeq double %"2_01", 0xFFF0000000000000 - %3 = fcmp uno double %"2_01", 0.000000e+00 - %4 = or i1 %1, %2 - %5 = or i1 %4, %3 - %6 = xor i1 %5, true - br i1 %6, label %9, label %7 - -7: ; preds = %entry_block - %8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template, i32 0, i32 0), i32 1, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @0, i32 0, i32 0)) - call void @abort() - unreachable - -9: ; preds = %entry_block - store double %"2_01", double* %"4_0", align 8 - %"4_02" = load double, double* %"4_0", align 8 - store double %"4_02", double* %"5_0", align 8 - %"5_03" = load double, double* %"5_0", align 8 - %10 = fcmp oeq double %"5_03", 0x7FF0000000000000 - %11 = fcmp oeq double %"5_03", 0xFFF0000000000000 - %12 = fcmp uno double %"5_03", 0.000000e+00 - %13 = or i1 %10, %11 - %14 = or i1 %13, %12 - %15 = xor i1 %14, true - %16 = insertvalue { double } undef, double %"5_03", 0 - %17 = insertvalue { i32, {}, { double } } { i32 1, {} poison, { double } poison }, { double } %16, 2 - %18 = select i1 %15, { i32, {}, { double } } %17, { i32, {}, { double } } { i32 0, {} undef, { double } poison } - store { i32, {}, { double } } %18, { i32, {}, { double } }* %"6_0", align 8 - %"6_04" = load { i32, {}, { double } }, { i32, {}, { double } }* %"6_0", align 8 - %19 = extractvalue { i32, {}, { double } } %"6_04", 0 - switch i32 %19, label %20 [ - i32 1, label %22 - ] - -20: ; preds = %9 - %21 = extractvalue { i32, {}, { double } } %"6_04", 1 - br label %cond_7_case_0 - -22: ; preds = %9 - %23 = extractvalue { i32, {}, { double } } %"6_04", 2 - %24 = extractvalue { double } %23, 0 - store double %24, double* %"08", align 8 - br label %cond_7_case_1 - -cond_7_case_0: ; preds = %20 - store { i32, i8* } { i32 1, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @1, i32 0, i32 0) }, { i32, i8* }* %"12_0", align 8 - %"12_06" = load { i32, i8* }, { i32, i8* }* %"12_0", align 8 - %25 = extractvalue { i32, i8* } %"12_06", 0 - %26 = extractvalue { i32, i8* } %"12_06", 1 - %27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @prelude.panic_template.1, i32 0, i32 0), i32 %25, i8* %26) - call void @abort() - store double 0.000000e+00, double* %"13_0", align 8 - %"13_07" = load double, double* %"13_0", align 8 - store double %"13_07", double* %"0", align 8 - br label %cond_exit_7 - -cond_7_case_1: ; preds = %22 - %"09" = load double, double* %"08", align 8 - store double %"09", double* %"15_0", align 8 - %"15_010" = load double, double* %"15_0", align 8 - store double %"15_010", double* %"0", align 8 - br label %cond_exit_7 - -cond_exit_7: ; preds = %cond_7_case_1, %cond_7_case_0 - %"05" = load double, double* %"0", align 8 - store double %"05", double* %"7_0", align 8 - %"4_011" = load double, double* %"4_0", align 8 - %"7_012" = load double, double* %"7_0", align 8 - %28 = fadd double %"4_011", %"7_012" - store double %28, double* %"17_0", align 8 - ret void -} - -declare i32 @printf(i8*, ...) - -declare void @abort() diff --git a/hugr-py/src/hugr/std/collections/static_array.py b/hugr-py/src/hugr/std/collections/static_array.py index f44589ff8..93253e771 100644 --- a/hugr-py/src/hugr/std/collections/static_array.py +++ b/hugr-py/src/hugr/std/collections/static_array.py @@ -41,7 +41,7 @@ class StaticArrayVal(val.ExtensionValue): """Constant value for a statically sized immutable array of elements.""" v: list[val.Value] - ty: tys.Type + ty: StaticArray name: str def __init__(self, v: list[val.Value], elem_ty: tys.Type, name: str) -> None: @@ -53,7 +53,8 @@ def to_value(self) -> val.Extension: # The value list must be serialized at this point, otherwise the # `Extension` value would not be serializable. vs = [v._to_serial_root() for v in self.v] - serial_val = {"values": vs, "name": self.name} + element_ty = self.ty.ty._to_serial_root() + serial_val = {"values": vs, "name": self.name, "typ": element_ty} return val.Extension( "StaticArrayValue", typ=self.ty, val=serial_val, extensions=[EXTENSION.name] )