3535#include < mlir/IR/Region.h>
3636#include < mlir/Pass/PassManager.h>
3737#include < mlir/Support/LogicalResult.h>
38- #include < mlir/Support/WalkResult.h>
3938#include < mlir/Transforms/DialectConversion.h>
4039
4140#include < cassert>
@@ -84,9 +83,6 @@ struct ConvertMemRefAllocOp final
8483 }
8584
8685 auto & state = getState ();
87- state.useDynamicQubit = true ;
88- state.useArrays = true ;
89-
9086 auto * ctx = getContext ();
9187 auto ptrType = LLVM::LLVMPointerType::get (ctx);
9288
@@ -235,7 +231,6 @@ struct ConvertQCAllocOp final : StatefulOpConversionPattern<AllocOp> {
235231 op.getOperation ()))) {
236232 return failure ();
237233 }
238- state.useDynamicQubit = true ;
239234
240235 auto * ctx = getContext ();
241236 auto ptrType = LLVM::LLVMPointerType::get (ctx);
@@ -363,8 +358,6 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern<MeasureOp> {
363358 matchAndRewrite (MeasureOp op, OpAdaptor adaptor,
364359 ConversionPatternRewriter& rewriter) const override {
365360 auto & state = getState ();
366- state.useDynamicResult = true ;
367-
368361 auto & resultArrays = state.resultArrays ;
369362 auto & loadedResults = state.loadedResults ;
370363 auto & resultPtrs = state.resultPtrs ;
@@ -381,7 +374,6 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern<MeasureOp> {
381374 // Get result pointer
382375 Value result;
383376 if (op.getRegisterName () && op.getRegisterSize () && op.getRegisterIndex ()) {
384- state.useArrays = true ;
385377 const auto registerName = op.getRegisterName ().value ();
386378 const auto registerSize =
387379 static_cast <int64_t >(op.getRegisterSize ().value ());
@@ -425,7 +417,6 @@ struct ConvertQCMeasureOp final : StatefulOpConversionPattern<MeasureOp> {
425417 rewriter.setInsertionPoint (state.entryBlock ->getTerminator ());
426418 result = createPointerFromIndex (rewriter, op.getLoc (), resultPtrs.size ());
427419 resultPtrs.try_emplace (resultPtrs.size (), result);
428- state.numResults ++;
429420 }
430421
431422 rewriter.restoreInsertionPoint (savedInsertionPoint);
@@ -573,22 +564,6 @@ struct QCToQIRAdaptive final : impl::QCToQIRAdaptiveBase<QCToQIRAdaptive> {
573564 }
574565 }
575566
576- /* *
577- * @brief Iterates through the module to find any scf.while or scf.for
578- * operation to set the backward branching flag before they are converted to
579- * cf operations.
580- */
581- static void setSCFFlags (Operation* op, LoweringState* state) {
582- op->walk ([&](scf::ForOp) {
583- state->backwardsBranching += 1 ;
584- return WalkResult::interrupt ();
585- });
586- op->walk ([&](scf::WhileOp) {
587- state->backwardsBranching += 2 ;
588- return WalkResult::interrupt ();
589- });
590- }
591-
592567protected:
593568 /* *
594569 * @brief Executes the QC to QIR conversion pass
@@ -614,15 +589,11 @@ struct QCToQIRAdaptive final : impl::QCToQIRAdaptiveBase<QCToQIRAdaptive> {
614589 * Convert QC dialect operations and memref operations to QIR calls and add
615590 * output recording to the output block.
616591 *
617- * **Stage 6: QIR Attributes**
618- * Add QIR Profile metadata to the main function, including qubit/result
619- * counts and version information.
620- *
621- * **Stage 7: Standard dialects to LLVM**
592+ * **Stage 6: Standard dialects to LLVM**
622593 * Convert arith and control flow dialects to LLVM (for index arithmetic and
623594 * function control flow).
624595 *
625- * **Stage 8 : Reconcile casts**
596+ * **Stage 7 : Reconcile casts**
626597 * Clean up any unrealized cast operations introduced during type
627598 * conversion.
628599 */
@@ -632,15 +603,11 @@ struct QCToQIRAdaptive final : impl::QCToQIRAdaptiveBase<QCToQIRAdaptive> {
632603 ConversionTarget target (*ctx);
633604 QCToQIRTypeConverter typeConverter (ctx);
634605 LoweringState state;
635- state.useAdaptive = true ;
636606
637607 target.addLegalDialect <LLVM ::LLVMDialect>();
638608
639609 // Stage 1: Convert scf dialect to cf
640610 {
641- // Find the required flags before the scf operations are converted
642- setSCFFlags (moduleOp, &state);
643-
644611 RewritePatternSet scfPatterns (ctx);
645612 target.addIllegalDialect <scf::SCFDialect>();
646613 target.addLegalDialect <cf::ControlFlowDialect>();
@@ -696,10 +663,7 @@ struct QCToQIRAdaptive final : impl::QCToQIRAdaptiveBase<QCToQIRAdaptive> {
696663 releaseResults (main, ctx, &state);
697664 }
698665
699- // Stage 6: Set QIR metadata attributes
700- setQIRAttributes (main, state);
701-
702- // Stage 7: Convert standard dialects to LLVM
666+ // Stage 6: Convert standard dialects to LLVM
703667 {
704668 RewritePatternSet stdPatterns (ctx);
705669 target.addIllegalDialect <arith::ArithDialect>();
@@ -716,7 +680,7 @@ struct QCToQIRAdaptive final : impl::QCToQIRAdaptiveBase<QCToQIRAdaptive> {
716680 }
717681 }
718682
719- // Stage 8 : Reconcile unrealized casts
683+ // Stage 7 : Reconcile unrealized casts
720684 PassManager passManager (ctx);
721685 passManager.addPass (createReconcileUnrealizedCastsPass ());
722686 if (passManager.run (moduleOp).failed ()) {
0 commit comments