1010
1111#pragma once
1212
13- #include < llvm/ADT/DenseMap.h>
14- #include < llvm/ADT/DenseSet.h>
15- #include < llvm/ADT/STLFunctionalExtras.h>
16- #include < llvm/Support/ErrorHandling.h>
1713#include < mlir/IR/Builders.h>
18- #include < mlir/IR/BuiltinOps.h>
19- #include < mlir/IR/MLIRContext.h>
2014#include < mlir/IR/OwningOpRef.h>
2115#include < mlir/IR/Value.h>
22- #include < mlir/IR/ValueRange.h>
2316#include < mlir/Support/LLVM.h>
2417
2518#include < cstdint>
2619#include < string>
2720#include < utility>
2821#include < variant>
2922
30- namespace mlir ::qco {
23+ namespace mlir {
24+
25+ // Forward declarations
26+ class MLIRContext ;
27+ class ModuleOp ;
28+ class Operation ;
29+ class ValueRange ;
30+
31+ namespace qco {
3132
3233/* *
3334 * @brief Builder API for constructing quantum programs in the QCO dialect
@@ -122,12 +123,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
122123 * @param index The index of the qubit to access
123124 * @return The specified qubit value
124125 */
125- Value& operator [](size_t index) {
126- if (index >= qubits.size ()) {
127- llvm::reportFatalUsageError (" Qubit index out of bounds" );
128- }
129- return qubits[index];
130- }
126+ Value& operator [](size_t index);
131127
132128 /* *
133129 * @brief Conversion to the backing QTensor value
@@ -210,16 +206,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
210206 * @param index The index of the bit to access (must be less than size)
211207 * @return A Bit structure representing the specified bit
212208 */
213- Bit operator [](const int64_t index) const {
214- if (index < 0 || index >= size) {
215- const std::string msg = " Bit index " + std::to_string (index) +
216- " out of bounds for register '" + name +
217- " ' of size " + std::to_string (size);
218- llvm::reportFatalUsageError (msg.c_str ());
219- }
220- return {
221- .registerName = name, .registerSize = size, .registerIndex = index};
222- }
209+ Bit operator [](int64_t index) const ;
223210 };
224211
225212 /* *
@@ -1171,7 +1158,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
11711158 */
11721159 std::pair<ValueRange, ValueRange>
11731160 ctrl (ValueRange controls, ValueRange targets,
1174- llvm:: function_ref<SmallVector<Value>(ValueRange)> body);
1161+ function_ref<SmallVector<Value>(ValueRange)> body);
11751162
11761163 /* *
11771164 * @brief Apply an inverse operation
@@ -1196,7 +1183,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
11961183 * ```
11971184 */
11981185 ValueRange inv (ValueRange qubits,
1199- llvm:: function_ref<SmallVector<Value>(ValueRange)> body);
1186+ function_ref<SmallVector<Value>(ValueRange)> body);
12001187
12011188 // ===--------------------------------------------------------------------===//
12021189 // Deallocation
@@ -1263,8 +1250,8 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
12631250 */
12641251 ValueRange
12651252 qcoIf (const std::variant<bool , Value>& condition, ValueRange qubits,
1266- llvm:: function_ref<SmallVector<Value>(ValueRange)> thenBody,
1267- llvm:: function_ref<SmallVector<Value>(ValueRange)> elseBody = nullptr );
1253+ function_ref<SmallVector<Value>(ValueRange)> thenBody,
1254+ function_ref<SmallVector<Value>(ValueRange)> elseBody = nullptr );
12681255
12691256 // ===--------------------------------------------------------------------===//
12701257 // Finalization
@@ -1294,13 +1281,13 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
12941281 */
12951282 static OwningOpRef<ModuleOp>
12961283 build (MLIRContext* context,
1297- const llvm:: function_ref<void (QCOProgramBuilder&)>& buildFunc);
1284+ const function_ref<void (QCOProgramBuilder&)>& buildFunc);
12981285
12991286private:
13001287 enum class AllocationMode : uint8_t { Unset, Static, Dynamic };
13011288
13021289 MLIRContext* ctx{};
1303- ModuleOp module ;
1290+ Operation* module ;
13041291
13051292 // / Check if the builder has been finalized
13061293 void checkFinalized () const ;
@@ -1340,7 +1327,7 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
13401327 // / Only values present in this map are valid for use in operations.
13411328 // / When an operation consumes a qubit and produces a new one, the old value
13421329 // / is removed and the new output is added.
1343- llvm:: DenseMap<Value, QubitInfo> validQubits;
1330+ DenseMap<Value, QubitInfo> validQubits;
13441331
13451332 /* *
13461333 * @brief Validate that a tensor value is valid and unconsumed. This also
@@ -1370,12 +1357,13 @@ class QCOProgramBuilder final : public ImplicitLocOpBuilder {
13701357 // / Only values present in this map are valid for use in operations.
13711358 // / When an operation consumes a tensor and produces a new one, the old value
13721359 // / is removed and the new output is added.
1373- llvm:: DenseMap<Value, TensorInfo> validTensors;
1360+ DenseMap<Value, TensorInfo> validTensors;
13741361
13751362 // / Track whether static or dynamic qubit allocation is used.
13761363 AllocationMode allocationMode = AllocationMode::Unset;
13771364
13781365 // / Ensure static and dynamic qubit allocation modes are not mixed.
13791366 void ensureAllocationMode (AllocationMode requestedMode);
13801367};
1381- } // namespace mlir::qco
1368+ } // namespace qco
1369+ } // namespace mlir
0 commit comments