Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ExtractCircuitsPass #284

Merged
merged 24 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions include/Dialect/QUIR/Transforms/ExtractCircuits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//===- ExtractCircuits.h - Extract circuits ops -----------------*- C++ -*-===//
//
// (C) Copyright IBM 2024.
//
// This code is part of Qiskit.
//
// This code is licensed under the Apache License, Version 2.0 with LLVM
// Exceptions. You may obtain a copy of this license in the LICENSE.txt
// file in the root directory of this source tree.
//
// Any modifications or derivative works of this code must retain this
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.
//
//===----------------------------------------------------------------------===//
///
/// This file declares the pass for extracting quantum ops into quir.circuits
///
//===----------------------------------------------------------------------===//

#ifndef QUIR_EXTRACT_CIRCUITS_H
#define QUIR_EXTRACT_CIRCUITS_H

#include "Dialect/QUIR/IR/QUIROps.h"

#include "mlir/IR/PatternMatch.h"
#include "mlir/Pass/Pass.h"

#include "llvm/ADT/SmallVector.h"
bcdonovan marked this conversation as resolved.
Show resolved Hide resolved

#include <unordered_map>

namespace mlir::quir {

struct ExtractCircuitsPass
: public PassWrapper<ExtractCircuitsPass, OperationPass<>> {
void runOnOperation() override;

llvm::StringRef getArgument() const override;
llvm::StringRef getDescription() const override;
llvm::StringRef getName() const override;

private:
void processOps(mlir::Operation *currentOp, OpBuilder topLevelBuilder,
OpBuilder circuitBuilder);
OpBuilder startCircuit(mlir::Location location, OpBuilder topLevelBuilder);
void endCircuit(mlir::Operation *firstOp, mlir::Operation *lastOp,
OpBuilder topLevelBuilder, OpBuilder circuitBuilder,
llvm::SmallVector<Operation *> &eraseList);
void addToCircuit(mlir::Operation *currentOp, OpBuilder circuitBuilder,
llvm::SmallVector<Operation *> &eraseList);
uint64_t circuitCount;
llvm::StringMap<Operation *> circuitOpsMap;

mlir::quir::CircuitOp currentCircuitOp;
mlir::quir::CallCircuitOp newCallCircuitOp;

llvm::SmallVector<Type> inputTypes;
llvm::SmallVector<Value> inputValues;
llvm::SmallVector<Type> outputTypes;
llvm::SmallVector<Value> outputValues;
std::vector<int> phyiscalIds;

std::unordered_map<uint32_t, BlockArgument> circuitArguments;
std::unordered_map<Operation *, uint32_t> circuitOperands;
llvm::SmallVector<OpResult> originalResults;

}; // struct ExtractCircuitsPass
} // namespace mlir::quir
#endif // QUIR_EXTRACT_CIRCUITS_H
1 change: 1 addition & 0 deletions include/Dialect/QUIR/Transforms/Passes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "AngleConversion.h"
#include "BreakReset.h"
#include "ConvertDurationUnits.h"
#include "ExtractCircuits.h"
#include "FunctionArgumentSpecialization.h"
#include "LoadElimination.h"
#include "MergeCircuitMeasures.h"
Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/QUIR/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_mlir_dialect_library(MLIRQUIRTransforms
AngleConversion.cpp
BreakReset.cpp
ConvertDurationUnits.cpp
ExtractCircuits.cpp
FunctionArgumentSpecialization.cpp
LoadElimination.cpp
MergeCircuits.cpp
Expand Down
Loading
Loading