Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5731ea6
Boilerplate for Quaternion-Merge-Pass in QCO
J4MMlE Dec 28, 2025
820acaf
🎨 pre-commit fixes
pre-commit-ci[bot] Dec 28, 2025
68888f4
move current state from MQTOpt to QCO
J4MMlE Jan 14, 2026
4572622
UnitaryInterface is now UnitaryOpInterface
J4MMlE Jan 14, 2026
645edd0
dont care about same type merging anymore
J4MMlE Jan 14, 2026
01da456
unify matchAndRewrite and rewriteAdditiveAngle
J4MMlE Jan 14, 2026
d7b23b4
getParams is now getParameters
J4MMlE Jan 14, 2026
98761ba
deleting old stuff is so much fun
J4MMlE Jan 14, 2026
27bc0c5
move datastucts out of namespace scope
J4MMlE Jan 14, 2026
7664064
fix includes
J4MMlE Jan 14, 2026
b121cdc
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 14, 2026
223b918
add cli flag for quaternion merge pass
J4MMlE Jan 15, 2026
64d54e4
boilerplate for tests
J4MMlE Jan 15, 2026
fce43ce
add test class
J4MMlE Jan 20, 2026
a1085ac
add simple 2 gate merge tests
J4MMlE Jan 20, 2026
94ea576
remove redundant checks
J4MMlE Jan 21, 2026
1c61731
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 21, 2026
67c039f
refactor test structure
J4MMlE Jan 21, 2026
045857a
add more tests
J4MMlE Jan 21, 2026
56eb003
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 21, 2026
d8d710c
correctly combine u-gates
J4MMlE Jan 22, 2026
ff1e4f6
tests for numerical correctness
J4MMlE Jan 22, 2026
b9ff907
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 22, 2026
2161b4b
cmake dependencies for tests
J4MMlE Jan 22, 2026
0d3ff52
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 22, 2026
6f69f47
wrap test class into namespace
J4MMlE Jan 22, 2026
05dd82a
docstrings for tests
J4MMlE Jan 22, 2026
ec958ab
improve pass definition
J4MMlE Jan 22, 2026
a732202
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 22, 2026
7b68efb
add enum class for RotationAxis
J4MMlE Jan 22, 2026
3ee6133
check for correct cast of user
J4MMlE Jan 22, 2026
53c2f27
remove verbose getResults()
J4MMlE Jan 22, 2026
2fe5a13
docstrings
J4MMlE Jan 22, 2026
893c41d
use llvm_unreachable instead of std::runime_error
J4MMlE Jan 22, 2026
b25a2cc
🎨 pre-commit fixes
pre-commit-ci[bot] Jan 22, 2026
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
3 changes: 3 additions & 0 deletions mlir/include/mlir/Compiler/CompilerPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ struct QuantumCompilerConfig {

/// Print IR after each stage
bool printIRAfterAllStages = false;

/// Enable quaternion-based rotation gate merging
bool mergeRotationGates = false;
};

/**
Expand Down
1 change: 1 addition & 0 deletions mlir/include/mlir/Dialect/QCO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
# Licensed under the MIT License

add_subdirectory(IR)
add_subdirectory(Transforms)
12 changes: 12 additions & 0 deletions mlir/include/mlir/Dialect/QCO/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name QCO)
add_public_tablegen_target(MLIRQCOTransformsIncGen)
add_mlir_doc(Passes QCOPasses Passes/ -gen-pass-doc)
21 changes: 21 additions & 0 deletions mlir/include/mlir/Dialect/QCO/Transforms/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/

#pragma once

#include <mlir/Pass/Pass.h> // from @llvm-project

namespace mlir::qco {
#define GEN_PASS_DECL
#include "mlir/Dialect/QCO/Transforms/Passes.h.inc" // IWYU pragma: export

#define GEN_PASS_REGISTRATION
#include "mlir/Dialect/QCO/Transforms/Passes.h.inc" // IWYU pragma: export
} // namespace mlir::qco
20 changes: 20 additions & 0 deletions mlir/include/mlir/Dialect/QCO/Transforms/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
// Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
// All rights reserved.
//
// SPDX-License-Identifier: MIT
//
// Licensed under the MIT License

include "mlir/Pass/PassBase.td"

def MergeRotationGates : Pass<"merge-rotation-gates",
"mlir::ModuleOp"> {
let summary = "Merge rotation gates using quaternion-based fusion";
let description = [{
Merges consecutive rotation gates of different types (rx, ry, rz, u)
using quaternion representation and the Hamilton product.
}];

let dependentDialects = ["::mlir::math::MathDialect"];
}
1 change: 1 addition & 0 deletions mlir/lib/Compiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_mlir_library(
QCToQCO
QCOToQC
QCToQIR
MLIRQCOTransforms
MQT::MLIRSupport
MQT::ProjectOptions
DISABLE_INSTALL)
Expand Down
14 changes: 10 additions & 4 deletions mlir/lib/Compiler/CompilerPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mlir/Conversion/QCOToQC/QCOToQC.h"
#include "mlir/Conversion/QCToQCO/QCToQCO.h"
#include "mlir/Conversion/QCToQIR/QCToQIR.h"
#include "mlir/Dialect/QCO/Transforms/Passes.h"
#include "mlir/Support/PrettyPrinting.h"

#include <llvm/ADT/StringRef.h>
Expand Down Expand Up @@ -161,18 +162,23 @@ QuantumCompilerPipeline::runPipeline(ModuleOp module,

// Stage 5: Optimization passes
// TODO: Add optimization passes
addCleanupPasses(pm);
if (failed(pm.run(module))) {
return failure();

// quaternion gate merging pass
if (config_.mergeRotationGates) {
pm.addPass(mlir::qco::createMergeRotationGates());
if (failed(pm.run(module))) {
return failure();
}
pm.clear();
}

if (record != nullptr && config_.recordIntermediates) {
record->afterOptimization = captureIR(module);
if (config_.printIRAfterAllStages) {
prettyPrintStage(module, "Optimization Passes", ++currentStage,
totalStages);
}
}
pm.clear();

// Stage 6: QCO canonicalization
addCleanupPasses(pm);
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/Dialect/QCO/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

add_subdirectory(Builder)
add_subdirectory(IR)
add_subdirectory(Transforms)
40 changes: 40 additions & 0 deletions mlir/lib/Dialect/QCO/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
set(LIBRARIES ${dialect_libs} MQT::CoreIR)
add_compile_options(-fexceptions)

message(STATUS "MLIR_DIALECT_LIBS contains: ${dialect_libs}")

file(GLOB_RECURSE TRANSFORMS_SOURCES *.cpp)

add_mlir_library(MLIRQCOTransforms ${TRANSFORMS_SOURCES} LINK_LIBS ${LIBRARIES} DEPENDS
MLIRQCOTransformsIncGen)

# collect header files
file(GLOB_RECURSE TRANSFORMS_HEADERS_SOURCE
${MQT_MLIR_SOURCE_INCLUDE_DIR}/mlir/Dialect/QCO/Transforms/*.h)
file(GLOB_RECURSE TRANSFORMS_HEADERS_BUILD
${MQT_MLIR_BUILD_INCLUDE_DIR}/mlir/Dialect/QCO/Transforms/*.inc)

# add public headers using file sets
target_sources(
MLIRQCOTransforms
PUBLIC FILE_SET
HEADERS
BASE_DIRS
${MQT_MLIR_SOURCE_INCLUDE_DIR}
FILES
${TRANSFORMS_HEADERS_SOURCE}
FILE_SET
HEADERS
BASE_DIRS
${MQT_MLIR_BUILD_INCLUDE_DIR}
FILES
${TRANSFORMS_HEADERS_BUILD})
Loading
Loading