Skip to content

Commit 137619f

Browse files
committed
feat: Add LLVM emission for prelude.noop
1 parent 53d7282 commit 137619f

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

hugr-llvm/src/extension/prelude.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ pub fn add_prelude_extensions<'a, H: HugrView<Node = Node> + 'a>(
309309
Ok(err)
310310
}
311311
})
312+
.extension_op(prelude::PRELUDE_ID, prelude::NOOP_OP_ID, |context, args| {
313+
args.outputs.finish(context.builder(), args.inputs)
314+
})
312315
.simple_extension_op::<TupleOpDef>(|context, args, op| match op {
313316
TupleOpDef::UnpackTuple => {
314317
let unpack_tuple = UnpackTuple::from_extension_op(args.node().as_ref())?;
@@ -399,7 +402,7 @@ pub fn add_prelude_extensions<'a, H: HugrView<Node = Node> + 'a>(
399402
#[cfg(test)]
400403
mod test {
401404
use hugr_core::builder::{Dataflow, DataflowSubContainer};
402-
use hugr_core::extension::prelude::EXIT_OP_ID;
405+
use hugr_core::extension::prelude::{Noop, EXIT_OP_ID};
403406
use hugr_core::extension::PRELUDE;
404407
use hugr_core::types::{Type, TypeArg};
405408
use hugr_core::{type_row, Hugr};
@@ -500,6 +503,23 @@ mod test {
500503
check_emission!(hugr, prelude_llvm_ctx);
501504
}
502505

506+
#[rstest]
507+
fn prelude_noop(prelude_llvm_ctx: TestContext) {
508+
let hugr = SimpleHugrConfig::new()
509+
.with_ins(usize_t())
510+
.with_outs(usize_t())
511+
.with_extensions(prelude::PRELUDE_REGISTRY.to_owned())
512+
.finish(|mut builder| {
513+
let in_wires = builder.input_wires();
514+
let r = builder
515+
.add_dataflow_op(Noop::new(usize_t()), in_wires)
516+
.unwrap()
517+
.outputs();
518+
builder.finish_with_outputs(r).unwrap()
519+
});
520+
check_emission!(hugr, prelude_llvm_ctx);
521+
}
522+
503523
#[rstest]
504524
fn prelude_make_tuple(prelude_llvm_ctx: TestContext) {
505525
let hugr = SimpleHugrConfig::new()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: hugr-llvm/src/extension/prelude.rs
3+
expression: mod_str
4+
---
5+
; ModuleID = 'test_context'
6+
source_filename = "test_context"
7+
8+
define i64 @_hl.main.1(i64 %0) {
9+
alloca_block:
10+
br label %entry_block
11+
12+
entry_block: ; preds = %alloca_block
13+
ret i64 %0
14+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
source: hugr-llvm/src/extension/prelude.rs
3+
expression: mod_str
4+
---
5+
; ModuleID = 'test_context'
6+
source_filename = "test_context"
7+
8+
define i64 @_hl.main.1(i64 %0) {
9+
alloca_block:
10+
%"0" = alloca i64, align 8
11+
%"2_0" = alloca i64, align 8
12+
%"4_0" = alloca i64, align 8
13+
br label %entry_block
14+
15+
entry_block: ; preds = %alloca_block
16+
store i64 %0, i64* %"2_0", align 4
17+
%"2_01" = load i64, i64* %"2_0", align 4
18+
store i64 %"2_01", i64* %"4_0", align 4
19+
%"4_02" = load i64, i64* %"4_0", align 4
20+
store i64 %"4_02", i64* %"0", align 4
21+
%"03" = load i64, i64* %"0", align 4
22+
ret i64 %"03"
23+
}

0 commit comments

Comments
 (0)