From 1a4f99ef78964a096a09b82fdecc796e10350806 Mon Sep 17 00:00:00 2001 From: Bruno Schmitt <7152025+boschmitt@users.noreply.github.com> Date: Wed, 18 Dec 2024 23:33:09 +0100 Subject: [PATCH] [nvq++] Removes MLIR's `memref` dialect. (#2438) * [nvq++] Removes MLIR's `scf` dialect We don't use this dialect and its presence is a historical artifact. This change triggered the removal of two tests: * `test/Quake/ghz.qke` * `test/Quake/iqft.qke` Both tests are a reminder of a past when we had to write quantum kernels directly in MLIR because of a lack of frontend. Both no longer test aything useful. The commit modifies `test/Quake/canonical-2.qke`, which was only testing the canonicalization of `cc.scope` operations. The new form is removes the clutter, making the test more precise. `test/Translate/ghz.qke` had to be modified because it uses MLIR's `affined.for` and its conversion to LLVMDialect requires `scf.for`. Signed-off-by: boschmitt <7152025+boschmitt@users.noreply.github.com> * [nvq++] Remove MLIR's `affine` dialect. We don't use this dialect. The removal triggered the removel of one test: * `test/Quake/ccnot.qke` The test was not testing anything useful, only kernel inlining, which is already covered in other tests. Furthermore, the test is misleading because, contrary to what the kernel name might indicate, it is not implementing a `ccnot`. Signed-off-by: boschmitt <7152025+boschmitt@users.noreply.github.com> * [nvq++] Removes MLIR's `memref` dialect. We don't use this dialect. Most changes were to substitute `memref` ops with `cc` ops in tests. Signed-off-by: boschmitt <7152025+boschmitt@users.noreply.github.com> --------- Signed-off-by: boschmitt <7152025+boschmitt@users.noreply.github.com> Signed-off-by: Eric Schweitz Co-authored-by: Eric Schweitz --- include/cudaq/Optimizer/InitAllDialects.h | 2 - test/Quake/lambda_kernel_exec.qke | 12 +- test/Quake/loop.qke | 132 +++++++++++----------- test/Quake/memtoreg-2.qke | 78 ++++++------- test/Quake/observeAnsatz.qke | 6 +- test/Translate/alloca_no_operand.qke | 18 +-- tools/cudaq-quake/CMakeLists.txt | 2 - 7 files changed, 120 insertions(+), 130 deletions(-) diff --git a/include/cudaq/Optimizer/InitAllDialects.h b/include/cudaq/Optimizer/InitAllDialects.h index abe474fe92..54b1ac29f7 100644 --- a/include/cudaq/Optimizer/InitAllDialects.h +++ b/include/cudaq/Optimizer/InitAllDialects.h @@ -16,7 +16,6 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" -#include "mlir/Dialect/MemRef/IR/MemRef.h" namespace cudaq { @@ -31,7 +30,6 @@ inline void registerAllDialects(mlir::DialectRegistry ®istry) { mlir::func::FuncDialect, mlir::LLVM::LLVMDialect, mlir::math::MathDialect, - mlir::memref::MemRefDialect, // CUDA-Q dialects cudaq::cc::CCDialect, diff --git a/test/Quake/lambda_kernel_exec.qke b/test/Quake/lambda_kernel_exec.qke index aedb9564b5..f4076f57cb 100644 --- a/test/Quake/lambda_kernel_exec.qke +++ b/test/Quake/lambda_kernel_exec.qke @@ -27,10 +27,10 @@ module attributes {quake.mangled_name_map = {__nvqpp__mlirgen__lambda.main.canHa %4 = arith.extsi %c0_i32_0 : i32 to i64 %5 = quake.extract_ref %1[%4] : (!quake.veq, i64) -> !quake.ref %16 = quake.mz %5 name "b" : (!quake.ref) -> !quake.measure - %alloca = memref.alloca() : memref + %alloca = cc.alloca i1 %6 = quake.discriminate %16 : (!quake.measure) -> i1 - memref.store %6, %alloca[] : memref - %7 = memref.load %alloca[] : memref + cc.store %6, %alloca : !cc.ptr + %7 = cc.load %alloca : !cc.ptr cc.if(%7) { cc.scope { %c1_i32_1 = arith.constant 1 : i32 @@ -67,9 +67,9 @@ module attributes {quake.mangled_name_map = {__nvqpp__mlirgen__lambda.main.canHa %5 = quake.extract_ref %1[%4] : (!quake.veq,i64) -> !quake.ref %16 = quake.mz %5 name "b" : (!quake.ref) -> !quake.measure %6 = quake.discriminate %16 : (!quake.measure) -> i1 - %alloca = memref.alloca() : memref - memref.store %6, %alloca[] : memref - %7 = memref.load %alloca[] : memref + %alloca = cc.alloca i1 + cc.store %6, %alloca : !cc.ptr + %7 = cc.load %alloca : !cc.ptr cc.if(%7) { cc.scope { %c1_i32_1 = arith.constant 1 : i32 diff --git a/test/Quake/loop.qke b/test/Quake/loop.qke index 3c144eb9ea..2982c517c7 100644 --- a/test/Quake/loop.qke +++ b/test/Quake/loop.qke @@ -9,17 +9,17 @@ // RUN: cudaq-opt %s | cudaq-opt | FileCheck %s func.func @test_old_for() { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.loop while { - %3 = memref.load %1[] : memref + %3 = cc.load %1 : !cc.ptr %ten = arith.constant 10 : i32 %8 = arith.cmpi slt, %3, %ten : i32 cc.condition %8 } do { ^bb0: - %13 = memref.load %1[] : memref + %13 = cc.load %1 : !cc.ptr %five = arith.constant 5 : i32 %18 = arith.cmpi slt, %13, %five : i32 cf.cond_br %18, ^bb1, ^bb2 @@ -29,25 +29,25 @@ func.func @test_old_for() { cc.continue } step { %4 = arith.constant 12 : i32 - %5 = memref.load %1[] : memref + %5 = cc.load %1 : !cc.ptr %6 = arith.addi %4, %5 : i32 - memref.store %6, %1[] : memref + cc.store %6, %1 : !cc.ptr cc.continue } func.return } // CHECK-LABEL: func.func @test_old_for() { -// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_0:.*]] = cc.alloca i32 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_1]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_1]], %[[VAL_0]] : !cc.ptr // CHECK: cc.loop while { -// CHECK: %[[VAL_2:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_2:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_3:.*]] = arith.constant 10 : i32 // CHECK: %[[VAL_4:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_3]] : i32 // CHECK: cc.condition %[[VAL_4]] // CHECK: } do { -// CHECK: %[[VAL_5:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_5:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_6:.*]] = arith.constant 5 : i32 // CHECK: %[[VAL_7:.*]] = arith.cmpi slt, %[[VAL_5]], %[[VAL_6]] : i32 // CHECK: cf.cond_br %[[VAL_7]], ^bb1, ^bb2 @@ -57,26 +57,26 @@ func.func @test_old_for() { // CHECK: cc.continue // CHECK: } step { // CHECK: %[[VAL_8:.*]] = arith.constant 12 : i32 -// CHECK: %[[VAL_9:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_9:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_8]], %[[VAL_9]] : i32 -// CHECK: memref.store %[[VAL_10]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_10]], %[[VAL_0]] : !cc.ptr // CHECK: } // CHECK: return // CHECK: } func.func @test_scoped_for() { cc.scope { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.loop while { - %3 = memref.load %1[] : memref + %3 = cc.load %1 : !cc.ptr %ten = arith.constant 10 : i32 %8 = arith.cmpi slt, %3, %ten : i32 cc.condition %8 } do { ^bb0: - %13 = memref.load %1[] : memref + %13 = cc.load %1 : !cc.ptr %five = arith.constant 5 : i32 %18 = arith.cmpi slt, %13, %five : i32 cf.cond_br %18, ^bb1, ^bb2 @@ -86,9 +86,9 @@ func.func @test_scoped_for() { cc.continue } step { %4 = arith.constant 12 : i32 - %5 = memref.load %1[] : memref + %5 = cc.load %1 : !cc.ptr %6 = arith.addi %4, %5 : i32 - memref.store %6, %1[] : memref + cc.store %6, %1 : !cc.ptr cc.continue } cc.continue @@ -98,16 +98,16 @@ func.func @test_scoped_for() { // CHECK-LABEL: func.func @test_scoped_for() { // CHECK: cc.scope { -// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_0:.*]] = cc.alloca i32 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_1]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_1]], %[[VAL_0]] : !cc.ptr // CHECK: cc.loop while { -// CHECK: %[[VAL_2:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_2:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_3:.*]] = arith.constant 10 : i32 // CHECK: %[[VAL_4:.*]] = arith.cmpi slt, %[[VAL_2]], %[[VAL_3]] : i32 // CHECK: cc.condition %[[VAL_4]] // CHECK: } do { -// CHECK: %[[VAL_5:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_5:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_6:.*]] = arith.constant 5 : i32 // CHECK: %[[VAL_7:.*]] = arith.cmpi slt, %[[VAL_5]], %[[VAL_6]] : i32 // CHECK: cf.cond_br %[[VAL_7]], ^bb1, ^bb2 @@ -117,9 +117,9 @@ func.func @test_scoped_for() { // CHECK: cc.continue // CHECK: } step { // CHECK: %[[VAL_8:.*]] = arith.constant 12 : i32 -// CHECK: %[[VAL_9:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_9:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_10:.*]] = arith.addi %[[VAL_8]], %[[VAL_9]] : i32 -// CHECK: memref.store %[[VAL_10]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_10]], %[[VAL_0]] : !cc.ptr // CHECK: } // CHECK: } // CHECK: return @@ -127,17 +127,17 @@ func.func @test_scoped_for() { func.func @test_scoped_for_with_args() { cc.scope { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr %z2 = cc.loop while ((%xtra = %zero) -> i32) { - %3 = memref.load %1[] : memref + %3 = cc.load %1 : !cc.ptr %ten = arith.constant 10 : i32 %8 = arith.cmpi slt, %3, %ten : i32 cc.condition %8 (%xtra : i32) } do { ^bb0(%x2 : i32): - %13 = memref.load %1[] : memref + %13 = cc.load %1 : !cc.ptr %five = arith.constant 5 : i32 %18 = arith.cmpi slt, %13, %five : i32 cf.cond_br %18, ^bb1, ^bb2 @@ -149,9 +149,9 @@ func.func @test_scoped_for_with_args() { ^bb4 (%x3 : i32): %4 = arith.constant 12 : i32 %16 = arith.addi %x3, %4 : i32 - %5 = memref.load %1[] : memref + %5 = cc.load %1 : !cc.ptr %6 = arith.addi %16, %5 : i32 - memref.store %6, %1[] : memref + cc.store %6, %1 : !cc.ptr cc.continue %x3 : i32 } } @@ -162,17 +162,17 @@ func.func private @getI32() -> i32 // CHECK-LABEL: func.func @test_scoped_for_with_args() { // CHECK: cc.scope { -// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_0:.*]] = cc.alloca i32 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_1]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_1]], %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_2:.*]] = cc.loop while ((%[[VAL_3:.*]] = %[[VAL_1]]) -> (i32)) { -// CHECK: %[[VAL_4:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_4:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_5:.*]] = arith.constant 10 : i32 // CHECK: %[[VAL_6:.*]] = arith.cmpi slt, %[[VAL_4]], %[[VAL_5]] : i32 // CHECK: cc.condition %[[VAL_6]](%[[VAL_3]] : i32) // CHECK: } do { // CHECK: ^bb0(%[[VAL_7:.*]]: i32): -// CHECK: %[[VAL_8:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_8:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_9:.*]] = arith.constant 5 : i32 // CHECK: %[[VAL_10:.*]] = arith.cmpi slt, %[[VAL_8]], %[[VAL_9]] : i32 // CHECK: cf.cond_br %[[VAL_10]], ^bb1, ^bb2 @@ -184,9 +184,9 @@ func.func private @getI32() -> i32 // CHECK: ^bb0(%[[VAL_11:.*]]: i32): // CHECK: %[[VAL_12:.*]] = arith.constant 12 : i32 // CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_11]], %[[VAL_12]] : i32 -// CHECK: %[[VAL_14:.*]] = memref.load %[[VAL_0]][] : memref +// CHECK: %[[VAL_14:.*]] = cc.load %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_15:.*]] = arith.addi %[[VAL_13]], %[[VAL_14]] : i32 -// CHECK: memref.store %[[VAL_15]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_15]], %[[VAL_0]] : !cc.ptr // CHECK: cc.continue %[[VAL_11]] : i32 // CHECK: } // CHECK: } @@ -196,13 +196,13 @@ func.func private @getI32() -> i32 // CHECK-LABEL: func.func private @getI32() -> i32 func.func @test_do_while() { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.loop do { ^bb0: %8 = func.call @getI32() : () -> i32 - memref.store %8, %1[] : memref + cc.store %8, %1 : !cc.ptr cc.continue } while { %3 = arith.constant 1 : i1 @@ -212,12 +212,12 @@ func.func @test_do_while() { } // CHECK-LABEL: func.func @test_do_while() { -// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_0:.*]] = cc.alloca i32 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_1]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_1]], %[[VAL_0]] : !cc.ptr // CHECK: cc.loop do { // CHECK: %[[VAL_2:.*]] = func.call @getI32() : () -> i32 -// CHECK: memref.store %[[VAL_2]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_2]], %[[VAL_0]] : !cc.ptr // CHECK: } while { // CHECK: %[[VAL_3:.*]] = arith.constant true // CHECK: cc.condition %[[VAL_3]] @@ -226,12 +226,12 @@ func.func @test_do_while() { // CHECK: } func.func @test_do_while_with_args() { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.loop do ((%i = %zero) -> i32) { %8 = func.call @getI32() : () -> i32 - memref.store %i, %1[] : memref + cc.store %i, %1 : !cc.ptr cc.continue %i : i32 } while { ^bb9(%arg0 : i32): @@ -245,12 +245,12 @@ func.func @test_do_while_with_args() { } // CHECK-LABEL: func.func @test_do_while_with_args() { -// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_0:.*]] = cc.alloca i32 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_1]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_1]], %[[VAL_0]] : !cc.ptr // CHECK: %[[VAL_2:.*]] = cc.loop do ((%[[VAL_3:.*]] = %[[VAL_1]]) -> (i32)) { // CHECK: %[[VAL_4:.*]] = func.call @getI32() : () -> i32 -// CHECK: memref.store %[[VAL_3]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_3]], %[[VAL_0]] : !cc.ptr // CHECK: cc.continue %[[VAL_3]] : i32 // CHECK: } while { // CHECK: ^bb0(%[[VAL_5:.*]]: i32): @@ -264,40 +264,40 @@ func.func @test_do_while_with_args() { // CHECK: } func.func @test_while() { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.loop while { %3 = arith.constant 1 : i1 cc.condition %3 } do { ^bb0: %8 = func.call @getI32() : () -> i32 - memref.store %8, %1[] : memref + cc.store %8, %1 : !cc.ptr cc.continue } func.return } // CHECK-LABEL: func.func @test_while() { -// CHECK: %[[VAL_0:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_0:.*]] = cc.alloca i32 // CHECK: %[[VAL_1:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_1]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_1]], %[[VAL_0]] : !cc.ptr // CHECK: cc.loop while { // CHECK: %[[VAL_2:.*]] = arith.constant true // CHECK: cc.condition %[[VAL_2]] // CHECK: } do { // CHECK: %[[VAL_3:.*]] = func.call @getI32() : () -> i32 -// CHECK: memref.store %[[VAL_3]], %[[VAL_0]][] : memref +// CHECK: cc.store %[[VAL_3]], %[[VAL_0]] : !cc.ptr // CHECK: cc.continue // CHECK: } // CHECK: return // CHECK: } func.func @test_if_else(%c : i1) { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.if (%c) { ^bb0: %3 = arith.constant 1 : i1 @@ -314,9 +314,9 @@ func.func @test_if_else(%c : i1) { // CHECK-LABEL: func.func @test_if_else( // CHECK-SAME: %[[VAL_0:.*]]: i1) { -// CHECK: %[[VAL_1:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_1:.*]] = cc.alloca i32 // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_2]], %[[VAL_1]][] : memref +// CHECK: cc.store %[[VAL_2]], %[[VAL_1]] : !cc.ptr // CHECK: cc.if(%[[VAL_0]]) { // CHECK: %[[VAL_3:.*]] = arith.constant true // CHECK: } else { @@ -329,9 +329,9 @@ func.func @test_if_else(%c : i1) { // CHECK: } func.func @test_if(%c : i1) { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr cc.if (%c) { ^bb1: %8 = func.call @getI32() : () -> i32 @@ -344,9 +344,9 @@ func.func @test_if(%c : i1) { // CHECK-LABEL: func.func @test_if( // CHECK-SAME: %[[VAL_0:.*]]: i1) { -// CHECK: %[[VAL_1:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_1:.*]] = cc.alloca i32 // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_2]], %[[VAL_1]][] : memref +// CHECK: cc.store %[[VAL_2]], %[[VAL_1]] : !cc.ptr // CHECK: cc.if(%[[VAL_0]]) { // CHECK: %[[VAL_3:.*]] = func.call @getI32() : () -> i32 // CHECK: cf.br ^bb1 @@ -357,9 +357,9 @@ func.func @test_if(%c : i1) { // CHECK: } func.func @test_if_else_thread(%c : i1) -> i32 { - %1 = memref.alloc() : memref + %1 = cc.alloca i32 %zero = arith.constant 0 : i32 - memref.store %zero, %1[] : memref + cc.store %zero, %1 : !cc.ptr %2 = cc.if (%c) -> i32 { %3 = arith.constant 1 : i32 cc.continue %3 : i32 @@ -372,9 +372,9 @@ func.func @test_if_else_thread(%c : i1) -> i32 { // CHECK-LABEL: func.func @test_if_else_thread( // CHECK-SAME: %[[VAL_0:.*]]: i1) -> i32 { -// CHECK: %[[VAL_1:.*]] = memref.alloc() : memref +// CHECK: %[[VAL_1:.*]] = cc.alloca i32 // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i32 -// CHECK: memref.store %[[VAL_2]], %[[VAL_1]][] : memref +// CHECK: cc.store %[[VAL_2]], %[[VAL_1]] : !cc.ptr // CHECK: %[[VAL_3:.*]] = cc.if(%[[VAL_0]]) -> i32 { // CHECK: %[[VAL_4:.*]] = arith.constant 1 : i32 // CHECK: cc.continue %[[VAL_4]] : i32 diff --git a/test/Quake/memtoreg-2.qke b/test/Quake/memtoreg-2.qke index 2878c43c6d..c1e0bd1c50 100644 --- a/test/Quake/memtoreg-2.qke +++ b/test/Quake/memtoreg-2.qke @@ -754,20 +754,19 @@ func.func @simple_loop() { %c1_i64 = arith.constant 1 : i64 %c42_i64 = arith.constant 42 : i64 %q0 = quake.alloca !quake.ref - // memtoreg does not promote memref types. - %alloca = memref.alloca() : memref - memref.store %c0_i64, %alloca[] : memref + %alloca = cc.alloca i64 + cc.store %c0_i64, %alloca : !cc.ptr cc.loop while { - %1 = memref.load %alloca[] : memref + %1 = cc.load %alloca : !cc.ptr %2 = arith.cmpi ult, %1, %c42_i64 : i64 cc.condition %2 } do { quake.x %q0 : (!quake.ref) -> () cc.continue } step { - %1 = memref.load %alloca[] : memref + %1 = cc.load %alloca : !cc.ptr %2 = arith.addi %1, %c1_i64 : i64 - memref.store %2, %alloca[] : memref + cc.store %2, %alloca : !cc.ptr } quake.z %q0 : (!quake.ref) -> () quake.dealloc %q0 : !quake.ref @@ -779,24 +778,21 @@ func.func @simple_loop() { // CHECK: %[[VAL_1:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_2:.*]] = arith.constant 42 : i64 // CHECK: %[[VAL_3:.*]] = quake.null_wire -// CHECK: %[[VAL_4:.*]] = memref.alloca() : memref -// CHECK: memref.store %[[VAL_0]], %[[VAL_4]][] : memref -// CHECK: %[[VAL_5:.*]] = cc.loop while ((%[[VAL_6:.*]] = %[[VAL_3]]) -> (!quake.wire)) { -// CHECK: %[[VAL_7:.*]] = memref.load %[[VAL_4]][] : memref +// CHECK: %[[VAL_4:.*]] = cc.undef i64 +// CHECK: %[[VAL_5:.*]]:2 = cc.loop while ((%[[VAL_6:.*]] = %[[VAL_3]], %[[VAL_7:.*]] = %[[VAL_0]]) -> (!quake.wire, i64)) { // CHECK: %[[VAL_8:.*]] = arith.cmpi ult, %[[VAL_7]], %[[VAL_2]] : i64 -// CHECK: cc.condition %[[VAL_8]](%[[VAL_6]] : !quake.wire) +// CHECK: cc.condition %[[VAL_8]](%[[VAL_6]], %[[VAL_7]] : !quake.wire, i64) // CHECK: } do { -// CHECK: ^bb0(%[[VAL_9:.*]]: !quake.wire): -// CHECK: %[[VAL_10:.*]] = quake.x %[[VAL_9]] : (!quake.wire) -> !quake.wire -// CHECK: cc.continue %[[VAL_10]] : !quake.wire +// CHECK: ^bb0(%[[VAL_9:.*]]: !quake.wire, %[[VAL_10:.*]]: i64): +// CHECK: %[[VAL_11:.*]] = quake.x %[[VAL_9]] : (!quake.wire) -> !quake.wire +// CHECK: cc.continue %[[VAL_11]], %[[VAL_10]] : !quake.wire, i64 // CHECK: } step { -// CHECK: ^bb0(%[[VAL_11:.*]]: !quake.wire): -// CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_4]][] : memref -// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] : i64 -// CHECK: memref.store %[[VAL_13]], %[[VAL_4]][] : memref -// CHECK: cc.continue %[[VAL_11]] : !quake.wire +// CHECK: ^bb0(%[[VAL_12:.*]]: !quake.wire, %[[VAL_13:.*]]: i64): +// CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_13]], %[[VAL_1]] : i64 +// CHECK: cc.continue %[[VAL_12]], %[[VAL_14]] : !quake.wire, i64 // CHECK: } -// CHECK: %[[VAL_14:.*]] = quake.z %[[VAL_15:.*]] : (!quake.wire) -> !quake.wire +// CHECK: %[[VAL_15:.*]] = quake.z %[[VAL_16:.*]]#0 : (!quake.wire) -> !quake.wire +// CHECK: quake.sink %[[VAL_15]] : !quake.wire // CHECK: return // CHECK: } @@ -806,51 +802,49 @@ func.func @floop_with_vector_and_qextract() { %c2_i64 = arith.constant 2 : i64 %veq = quake.alloca !quake.veq<2> %q0 = quake.extract_ref %veq[%c0_i64] : (!quake.veq<2> ,i64) -> !quake.ref - %alloca = memref.alloca() : memref - memref.store %c0_i64, %alloca[] : memref + %alloca = cc.alloca i64 + cc.store %c0_i64, %alloca : !cc.ptr cc.loop while { - %3 = memref.load %alloca[] : memref + %3 = cc.load %alloca : !cc.ptr %4 = arith.cmpi ult, %3, %c2_i64 : i64 cc.condition %4 } do { - %3 = memref.load %alloca[] : memref + %3 = cc.load %alloca : !cc.ptr %4 = quake.extract_ref %veq[%3] : (!quake.veq<2> ,i64) -> !quake.ref cc.continue } step { - %3 = memref.load %alloca[] : memref + %3 = cc.load %alloca : !cc.ptr %4 = arith.addi %3, %c1_i64 : i64 - memref.store %4, %alloca[] : memref + cc.store %4, %alloca : !cc.ptr } %2 = quake.mz %veq : (!quake.veq<2>) -> !cc.stdvec quake.dealloc %veq : !quake.veq<2> return } - // CHECK-LABEL: func.func @floop_with_vector_and_qextract() { // CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64 // CHECK: %[[VAL_1:.*]] = arith.constant 1 : i64 // CHECK: %[[VAL_2:.*]] = arith.constant 2 : i64 // CHECK: %[[VAL_3:.*]] = quake.alloca !quake.veq<2> -// CHECK: %[[VAL_4:.*]] = quake.extract_ref %[[VAL_3]][%[[VAL_0]]] : (!quake.veq<2>, i64) -> !quake.ref +// CHECK: %[[VAL_4:.*]] = quake.extract_ref %[[VAL_3]]{{\[}}%[[VAL_0]]] : (!quake.veq<2>, i64) -> !quake.ref // CHECK: %[[VAL_5:.*]] = quake.unwrap %[[VAL_4]] : (!quake.ref) -> !quake.wire -// CHECK: %[[VAL_6:.*]] = memref.alloca() : memref -// CHECK: memref.store %[[VAL_0]], %[[VAL_6]][] : memref -// CHECK: cc.loop while { -// CHECK: %[[VAL_7:.*]] = memref.load %[[VAL_6]][] : memref -// CHECK: %[[VAL_8:.*]] = arith.cmpi ult, %[[VAL_7]], %[[VAL_2]] : i64 -// CHECK: cc.condition %[[VAL_8]] +// CHECK: %[[VAL_6:.*]] = cc.undef i64 +// CHECK: %[[VAL_7:.*]] = cc.loop while ((%[[VAL_8:.*]] = %[[VAL_0]]) -> (i64)) { +// CHECK: %[[VAL_9:.*]] = arith.cmpi ult, %[[VAL_8]], %[[VAL_2]] : i64 +// CHECK: cc.condition %[[VAL_9]](%[[VAL_8]] : i64) // CHECK: } do { -// CHECK: %[[VAL_9:.*]] = memref.load %[[VAL_6]][] : memref -// CHECK: %[[VAL_10:.*]] = quake.extract_ref %[[VAL_3]][%[[VAL_9]]] : (!quake.veq<2>, i64) -> !quake.ref -// CHECK: %[[VAL_11:.*]] = quake.unwrap %[[VAL_10]] : (!quake.ref) -> !quake.wire -// CHECK: cc.continue +// CHECK: ^bb0(%[[VAL_10:.*]]: i64): +// CHECK: %[[VAL_11:.*]] = quake.extract_ref %[[VAL_3]]{{\[}}%[[VAL_10]]] : (!quake.veq<2>, i64) -> !quake.ref +// CHECK: %[[VAL_12:.*]] = quake.unwrap %[[VAL_11]] : (!quake.ref) -> !quake.wire +// CHECK: cc.continue %[[VAL_10]] : i64 // CHECK: } step { -// CHECK: %[[VAL_12:.*]] = memref.load %[[VAL_6]][] : memref -// CHECK: %[[VAL_13:.*]] = arith.addi %[[VAL_12]], %[[VAL_1]] : i64 -// CHECK: memref.store %[[VAL_13]], %[[VAL_6]][] : memref +// CHECK: ^bb0(%[[VAL_13:.*]]: i64): +// CHECK: %[[VAL_14:.*]] = arith.addi %[[VAL_13]], %[[VAL_1]] : i64 +// CHECK: cc.continue %[[VAL_14]] : i64 // CHECK: } -// CHECK: quake.mz %[[VAL_3]] : (!quake.veq<2>) -> !cc.stdvec +// CHECK: %[[VAL_15:.*]] = quake.mz %[[VAL_3]] : (!quake.veq<2>) -> !cc.stdvec +// CHECK: quake.dealloc %[[VAL_3]] : !quake.veq<2> // CHECK: return // CHECK: } diff --git a/test/Quake/observeAnsatz.qke b/test/Quake/observeAnsatz.qke index ea7eefa157..3c08197d80 100644 --- a/test/Quake/observeAnsatz.qke +++ b/test/Quake/observeAnsatz.qke @@ -11,12 +11,12 @@ func.func @__nvqpp__mlirgen__ansatz(%arg0: f64) { %c0_i64 = arith.constant 0 : i64 %c1_i64 = arith.constant 1 : i64 - %0 = memref.alloca() : memref - memref.store %arg0, %0[] : memref + %0 = cc.alloca f64 + cc.store %arg0, %0 : !cc.ptr %1 = quake.alloca !quake.veq<2> %2 = quake.extract_ref %1[%c0_i64] : (!quake.veq<2>,i64) -> !quake.ref quake.x %2 : (!quake.ref) -> () - %3 = memref.load %0[] : memref + %3 = cc.load %0 : !cc.ptr %4 = quake.extract_ref %1[%c1_i64] : (!quake.veq<2>,i64) -> !quake.ref quake.ry (%3) %4 : (f64, !quake.ref) -> () %5 = quake.extract_ref %1[%c1_i64] : (!quake.veq<2>,i64) -> !quake.ref diff --git a/test/Translate/alloca_no_operand.qke b/test/Translate/alloca_no_operand.qke index a321371a41..af2feccaf5 100644 --- a/test/Translate/alloca_no_operand.qke +++ b/test/Translate/alloca_no_operand.qke @@ -10,7 +10,7 @@ func.func @adder_n4() { %0 = quake.alloca !quake.veq<4> - %1 = memref.alloc() : memref<4xi1> + %1 = cc.alloca !cc.array %c0 = arith.constant 0 : index %2 = quake.extract_ref %0[%c0] : (!quake.veq<4>, index) -> !quake.ref quake.x %2 : (!quake.ref) -> () @@ -44,20 +44,20 @@ func.func @adder_n4() { quake.h %4 : (!quake.ref) -> () %6 = quake.mz %2 : (!quake.ref) -> !quake.measure %61 = quake.discriminate %6 : (!quake.measure) -> i1 - %c0_0 = arith.constant 0 : index - memref.store %61, %1[%c0_0] : memref<4xi1> + %a = cc.compute_ptr %1[0] : (!cc.ptr>) -> !cc.ptr + cc.store %61, %a : !cc.ptr %7 = quake.mz %3 : (!quake.ref) -> !quake.measure %71 = quake.discriminate %7 : (!quake.measure) -> i1 - %c1_1 = arith.constant 1 : index - memref.store %71, %1[%c1_1] : memref<4xi1> + %b = cc.compute_ptr %1[1] : (!cc.ptr>) -> !cc.ptr + cc.store %71, %b : !cc.ptr %8 = quake.mz %5 : (!quake.ref) -> !quake.measure %81 = quake.discriminate %8 : (!quake.measure) -> i1 - %c2_2 = arith.constant 2 : index - memref.store %81, %1[%c2_2] : memref<4xi1> + %c = cc.compute_ptr %1[2] : (!cc.ptr>) -> !cc.ptr + cc.store %81, %c : !cc.ptr %9 = quake.mz %4 : (!quake.ref) -> !quake.measure %91 = quake.discriminate %9 : (!quake.measure) -> i1 - %c3_3 = arith.constant 3 : index - memref.store %91, %1[%c3_3] : memref<4xi1> + %d = cc.compute_ptr %1[3] : (!cc.ptr>) -> !cc.ptr + cc.store %91, %d : !cc.ptr return } diff --git a/tools/cudaq-quake/CMakeLists.txt b/tools/cudaq-quake/CMakeLists.txt index 277df39c22..52e3d92750 100644 --- a/tools/cudaq-quake/CMakeLists.txt +++ b/tools/cudaq-quake/CMakeLists.txt @@ -25,8 +25,6 @@ target_link_libraries(cudaq-quake MLIRLLVMCommonConversion MLIRLLVMToLLVMIRTranslation - MLIRMemRefDialect - clangCodeGen clangFrontendTool clangFrontend