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

[core] Move the QIR peephole patterns out of tablegen. #2480

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading