Skip to content

Commit

Permalink
[core] Move the QIR peephole patterns out of tablegen.
Browse files Browse the repository at this point in the history
Moves all the peephole patterns to explicit patterns and out of tablegen.

Fix #476.

Signed-off-by: Eric Schweitz <[email protected]>
  • Loading branch information
schweitzpgi committed Dec 13, 2024
1 parent fa63aa2 commit 31bedfa
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 190 deletions.
4 changes: 0 additions & 4 deletions include/cudaq/Optimizer/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@ add_cudaq_dialect_doc(CodeGenDialect codegen)
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name OptCodeGen)
add_public_tablegen_target(OptCodeGenPassIncGen)

set(LLVM_TARGET_DEFINITIONS Peephole.td)
mlir_tablegen(Peephole.inc -gen-rewriters)
add_public_tablegen_target(OptPeepholeIncGen)
9 changes: 2 additions & 7 deletions include/cudaq/Optimizer/CodeGen/Peephole.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ inline bool isIntToPtrOp(mlir::Value operand) {
static constexpr char resultIndexName[] = "result.index";

inline mlir::Value createMeasureCall(mlir::PatternRewriter &builder,
mlir::Location loc, mlir::OpResult result,
mlir::Location loc, mlir::LLVM::CallOp op,
mlir::ValueRange args) {
auto op = cast<mlir::LLVM::CallOp>(result.getDefiningOp());
auto ptrTy = cudaq::opt::getResultType(builder.getContext());
if (auto intAttr =
dyn_cast_or_null<mlir::IntegerAttr>(op->getAttr(resultIndexName))) {
Expand All @@ -57,15 +56,11 @@ inline mlir::Value createMeasureCall(mlir::PatternRewriter &builder,

inline mlir::Value createReadResultCall(mlir::PatternRewriter &builder,
mlir::Location loc,
mlir::OpResult result) {
mlir::Value result) {
auto i1Ty = mlir::IntegerType::get(builder.getContext(), 1);
return builder
.create<mlir::LLVM::CallOp>(loc, mlir::TypeRange{i1Ty},
cudaq::opt::QIRReadResultBody,
mlir::ArrayRef<mlir::Value>{result})
.getResult();
}

namespace {
#include "cudaq/Optimizer/CodeGen/Peephole.inc"
}
177 changes: 0 additions & 177 deletions include/cudaq/Optimizer/CodeGen/Peephole.td

This file was deleted.

1 change: 0 additions & 1 deletion lib/Optimizer/CodeGen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ add_cudaq_library(OptCodeGen
CodeGenOpsIncGen
CodeGenTypesIncGen
OptCodeGenPassIncGen
OptPeepholeIncGen
OptTransformsPassIncGen
QuakeDialect

Expand Down
2 changes: 2 additions & 0 deletions lib/Optimizer/CodeGen/ConvertToQIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ namespace cudaq::opt {

using namespace mlir;

#include "PeepholePatterns.inc"

/// Greedy pass to match subgraphs in the IR and replace them with codegen ops.
/// This step makes converting a DAG of nodes in the conversion step simpler.
static LogicalResult fuseSubgraphPatterns(MLIRContext *ctx, ModuleOp module) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Optimizer/CodeGen/ConvertToQIRProfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

using namespace mlir;

#include "PeepholePatterns.inc"

/// For a call to `__quantum__rt__qubit_allocate_array`, get the number of
/// qubits allocated.
static std::size_t getNumQubits(LLVM::CallOp callOp) {
Expand Down
Loading

0 comments on commit 31bedfa

Please sign in to comment.