Commit 94519a75 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Add ability to inline QuantumDialect



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent fba4f3e5
Loading
Loading
Loading
Loading
+27 −1
Original line number Diff line number Diff line
@@ -2,10 +2,35 @@
#include "Quantum/QuantumDialect.h"
#include "Quantum/QuantumOps.h"
#include "mlir/IR/OpImplementation.h"
#include "mlir/Transforms/InliningUtils.h"

using namespace mlir;
using namespace mlir::quantum;
namespace {
/// Inliner interface
/// This class defines the interface for handling inlining with Quantum
/// operations.
// We simplify inherit from the base interface class and override
/// the necessary methods.
struct QuantumInlinerInterface : public DialectInlinerInterface {
  using DialectInlinerInterface::DialectInlinerInterface;

  /// This hook checks to see if the given callable operation is legal to inline
  /// into the given call. 
  /// Operations in Quantum dialect are always legal to inline.
  bool isLegalToInline(Operation *, Operation *, bool) const final {
    return true;
  }

  /// This hook checks to see if the given operation is legal to inline into the
  /// given region.
  /// Always legal to inline.
  bool isLegalToInline(Operation *, Region *, bool,
                       BlockAndValueMapping &) const final {
    return true;
  }
};
} // namespace
//===----------------------------------------------------------------------===//
// Quantum dialect.
//===----------------------------------------------------------------------===//
@@ -15,6 +40,7 @@ void QuantumDialect::initialize() {
#define GET_OP_LIST
#include "Quantum/QuantumOps.cpp.inc"
      >();
  addInterfaces<QuantumInlinerInterface>();
}

// static void print(mlir::OpAsmPrinter &printer, mlir::quantum::InstOp op) {
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@
// across different use cases of MLIR compilation.
namespace qcor {
void configureOptimizationPasses(mlir::PassManager &passManager) {
  auto inliner = mlir::createInlinerPass(); 
  passManager.addPass(std::move(inliner));
  // TODO: configure the pass pipeline to handle repeated applications of passes.
  // Add passes
  constexpr int N_REPS = 5;