From 3e7c4ee60e0e3266fca6f16dab0667dee3323aee Mon Sep 17 00:00:00 2001 From: Eric Schweitz Date: Thu, 8 Jun 2023 13:36:40 -0700 Subject: [PATCH] Remove the raise to affine (stub) pass. It is no longer clear that this is our direction. We can bring this back if we decide to lift loops into the affine polyhedral domain. --- include/cudaq/Optimizer/Transforms/Passes.td | 45 -------------- lib/Optimizer/Transforms/CMakeLists.txt | 1 - lib/Optimizer/Transforms/RaiseToAffine.cpp | 65 -------------------- 3 files changed, 111 deletions(-) delete mode 100644 lib/Optimizer/Transforms/RaiseToAffine.cpp diff --git a/include/cudaq/Optimizer/Transforms/Passes.td b/include/cudaq/Optimizer/Transforms/Passes.td index 211a80b83b..d5cee778bf 100644 --- a/include/cudaq/Optimizer/Transforms/Passes.td +++ b/include/cudaq/Optimizer/Transforms/Passes.td @@ -184,51 +184,6 @@ def QuakeObserveAnsatz : Pass<"quake-observe-ansatz", "mlir::func::FuncOp"> { ]; } -def RaiseToAffine : Pass<"raise-to-affine", "mlir::func::FuncOp"> { - let summary = "Convert CLoop ops to affine.for loops when possible."; - let description = [{ - This pass converts quake.CLoop ops to a more structured loop operation, - affine.for. - - For example, a `quake.loop` model of a C `for` loop - ```mlir - quake.scope { - %i0 = constant 0 : index - quake.loop while (%i1 = %i0) -> index { - %c10 = constant 10 : index - %cond = arith.cmpi %i1, %c10 - quake.condition %cond, %i1 - } do { - ^bb1 (%i2 : index): - %19 = quake.qubit_extract %qreg[%i2 : index] : !quake.qubit - %c1 = costant 1 : index - %i2p1 = arith.addi %i2, %c1 : index - %23 = quake.qubit_extract %qreg[%i2p1 : index] : !quake.qubit - quake.x [%19] %23 - quake.continue %i2 : index - } step { - ^bb2 (%i3 : index): - %c1 = constant 1 : index - %incr = arith.addi %i3, %c1 - quake.continue %incr : index - } - } - // exit loop - ``` - would be rewritten to - ```mlir - affine.for %arg1 = #map(%c0) to #map(%c9) { - %19 = quake.qubit_extract %qreg[%arg1 : index] : !quake.qubit - %21 = affine.apply affine_map<(i) -> (i+1)> (%arg1) - %23 = quake.qubit_extract %qreg[%21 : index] : !quake.qubit - quake.x [%19] %23 : !quake.qubit - } - ``` - }]; - let dependentDialects = [ "mlir::AffineDialect" ]; - let constructor = "cudaq::opt::createRaiseToAffinePass()"; -} - def CCMemToReg : Pass<"cc-mem2reg", "mlir::func::FuncOp"> { let summary = "Converts classical compute memory to register SSA form."; let description = [{ diff --git a/lib/Optimizer/Transforms/CMakeLists.txt b/lib/Optimizer/Transforms/CMakeLists.txt index 3a8d3e05a1..6cd4cc08cc 100644 --- a/lib/Optimizer/Transforms/CMakeLists.txt +++ b/lib/Optimizer/Transforms/CMakeLists.txt @@ -29,7 +29,6 @@ add_cudaq_library(OptTransforms QuakeAddMetadata.cpp QuakeObserveAnsatz.cpp QuakeSynthesizer.cpp - RaiseToAffine.cpp DEPENDS OptTransformsPassIncGen diff --git a/lib/Optimizer/Transforms/RaiseToAffine.cpp b/lib/Optimizer/Transforms/RaiseToAffine.cpp deleted file mode 100644 index 207007b8cd..0000000000 --- a/lib/Optimizer/Transforms/RaiseToAffine.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2022 - 2023 NVIDIA Corporation & Affiliates. * - * All rights reserved. * - * * - * This source code and the accompanying materials are made available under * - * the terms of the Apache License 2.0 which accompanies this distribution. * - ******************************************************************************/ - -#include "PassDetails.h" -#include "cudaq/Optimizer/Dialect/CC/CCOps.h" -#include "cudaq/Optimizer/Dialect/Quake/QuakeOps.h" -#include "cudaq/Optimizer/Transforms/Passes.h" -#include "cudaq/Todo.h" -#include "mlir/IR/PatternMatch.h" -#include "mlir/Transforms/DialectConversion.h" -#include "mlir/Transforms/Passes.h" - -#define DEBUG_TYPE "raise-to-affine" - -using namespace mlir; - -namespace { -class RewriteLoop : public OpRewritePattern { -public: - using OpRewritePattern::OpRewritePattern; - - LogicalResult matchAndRewrite(cudaq::cc::LoopOp loopOp, - PatternRewriter &rewriter) const override { - TODO("loop lowering"); - return success(); - } -}; - -class RaiseToAffinePass - : public cudaq::opt::RaiseToAffineBase { -public: - RaiseToAffinePass() = default; - - void runOnOperation() override { - auto op = getOperation(); - auto *ctx = &getContext(); - RewritePatternSet patterns(ctx); - patterns.insert(ctx); - ConversionTarget target(*ctx); - target.addDynamicallyLegalOp( - [](cudaq::cc::ScopeOp x) { return true; }); - target.addDynamicallyLegalOp( - [](cudaq::cc::LoopOp x) { return true; }); - target.addDynamicallyLegalOp( - [](cudaq::cc::IfOp x) { return true; }); - target.addDynamicallyLegalOp( - [](cudaq::cc::ConditionOp x) { return true; }); - target.addDynamicallyLegalOp( - [](cudaq::cc::ContinueOp x) { return true; }); - target.addDynamicallyLegalOp( - [](cudaq::cc::BreakOp x) { return true; }); - if (failed(applyPartialConversion(op, target, std::move(patterns)))) - signalPassFailure(); - } -}; -} // namespace - -std::unique_ptr cudaq::opt::createRaiseToAffinePass() { - return std::make_unique(); -}