Skip to content
Open
Show file tree
Hide file tree
Changes from 16 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
1 change: 1 addition & 0 deletions mlir/include/RTIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
429 changes: 429 additions & 0 deletions mlir/include/RTIO/Transforms/ARTIQRuntimeBuilder.h

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions mlir/include/RTIO/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(LLVM_TARGET_DEFINITIONS Passes.td)
mlir_tablegen(Passes.h.inc -gen-pass-decls -name RTIO)
add_public_tablegen_target(MLIRRTIOPassIncGen)
add_mlir_doc(Passes RTIOPasses ./ -gen-pass-doc)
29 changes: 29 additions & 0 deletions mlir/include/RTIO/Transforms/Passes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "mlir/Pass/Pass.h"

#include "RTIO/IR/RTIODialect.h"

namespace catalyst {
namespace rtio {

#define GEN_PASS_DECL
#define GEN_PASS_REGISTRATION
#include "RTIO/Transforms/Passes.h.inc"

} // namespace rtio
} // namespace catalyst
44 changes: 44 additions & 0 deletions mlir/include/RTIO/Transforms/Passes.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef RTIO_PASSES
#define RTIO_PASSES

include "mlir/Pass/PassBase.td"

def RTIOEventToARTIQPass : Pass<"convert-rtio-event-to-artiq", "mlir::ModuleOp"> {
let summary = "Convert RTIO event-based operations directly to ARTIQ-compatible LLVM IR";
let description = [{
Mapping:
- rtio.pulse -> at_mu(operand) DDS config + TTL on + delay + TTL off + now_mu()
- rtio.sync -> maximum the timestamp of the input events + at_mu() + now_mu()
- rtio.channel -> channel ID
- rtio.empty -> just return now_mu()

And this pass generates LLVM IR that directly calls ARTIQ runtime functions
}];

let dependentDialects = [
"rtio::RTIODialect",
"mlir::LLVM::LLVMDialect",
"mlir::arith::ArithDialect",
"mlir::math::MathDialect",
"mlir::scf::SCFDialect",
"mlir::func::FuncDialect"
];
}

#endif // RTIO_PASSES


34 changes: 34 additions & 0 deletions mlir/include/RTIO/Transforms/Patterns.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2025 Xanadu Quantum Technologies Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Dialect/Arith/IR/Arith.h"
#include "mlir/IR/Matchers.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Transforms/DialectConversion.h"

#include "RTIO/IR/RTIOOps.h"

namespace catalyst {
namespace rtio {
void populateRTIOToARTIQConversionPatterns(mlir::LLVMTypeConverter &typeConverter,
mlir::RewritePatternSet &patterns);
void populateRTIORewritePatterns(mlir::RewritePatternSet &patterns);
void populateRTIOSyncSimplifyPatterns(mlir::RewritePatternSet &patterns);
void populateRTIOPulseDecomposePatterns(mlir::RewritePatternSet &patterns);

} // namespace rtio
} // namespace catalyst
2 changes: 2 additions & 0 deletions mlir/include/RegisterAllPasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Mitigation/Transforms/Passes.h"
#include "QEC/Transforms/Passes.h"
#include "Quantum/Transforms/Passes.h"
#include "RTIO/Transforms/Passes.h"
#include "Test/Transforms/Passes.h"
#include "hlo-extensions/Transforms/Passes.h"

Expand All @@ -36,6 +37,7 @@ inline void registerAllPasses()
mitigation::registerMitigationPasses();
qec::registerQECPasses();
quantum::registerQuantumPasses();
rtio::registerRTIOPasses();
test::registerTestPasses();
}

Expand Down
1 change: 1 addition & 0 deletions mlir/lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ set(LIBS
MLIRIon
ion-transforms
MLIRRTIO
rtio-transforms
MLIRCatalystTest
${ENZYME_LIB}
)
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/RTIO/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
25 changes: 25 additions & 0 deletions mlir/lib/RTIO/Transforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
set(LIBRARY_NAME rtio-transforms)

file(GLOB SRC
RTIOEventToARTIQ.cpp
RTIOEventToARTIQPatterns.cpp
)

get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS
${dialect_libs}
${conversion_libs}
MLIRRTIO
)

set(DEPENDS
MLIRRTIOPassIncGen
)

add_mlir_library(${LIBRARY_NAME} STATIC ${SRC} LINK_LIBS PRIVATE ${LIBS} DEPENDS ${DEPENDS})
target_compile_features(${LIBRARY_NAME} PUBLIC cxx_std_20)
target_include_directories(${LIBRARY_NAME} PUBLIC
.
${PROJECT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/include)
Loading