Skip to content

Commit a74a7d1

Browse files
committed
drop llvm and mlir scope resolution
1 parent 46cfe0c commit a74a7d1

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

mlir/lib/Dialect/QC/IR/Modifiers/PowOp.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "mlir/Dialect/Utils/Utils.h"
1313

1414
#include <llvm/ADT/STLExtras.h>
15-
#include <llvm/ADT/STLFunctionalExtras.h>
1615
#include <llvm/ADT/TypeSwitch.h>
1716
#include <llvm/Support/ErrorHandling.h>
1817
#include <mlir/Dialect/Arith/IR/Arith.h>
@@ -21,6 +20,7 @@
2120
#include <mlir/IR/Matchers.h>
2221
#include <mlir/IR/OperationSupport.h>
2322
#include <mlir/IR/PatternMatch.h>
23+
#include <mlir/Support/LLVM.h>
2424
#include <mlir/Support/LogicalResult.h>
2525

2626
#include <cmath>
@@ -30,6 +30,8 @@
3030
using namespace mlir;
3131
using namespace mlir::qc;
3232
using namespace mlir::utils;
33+
using llvm::make_early_inc_range;
34+
using llvm::reportFatalUsageError;
3335

3436
/**
3537
* @brief If the computed P-gate angle corresponds to a named gate, emit it
@@ -245,7 +247,7 @@ struct FoldPowIntoGate final : OpRewritePattern<PowOp> {
245247

246248
// Move supporting ops (constants, arithmetic) out of the body so their
247249
// Values are accessible from outside and survive PowOp erasure.
248-
for (auto& bodyOp : llvm::make_early_inc_range(*op.getBody())) {
250+
for (auto& bodyOp : make_early_inc_range(*op.getBody())) {
249251
if (&bodyOp != innerOp && !isa<YieldOp>(&bodyOp)) {
250252
rewriter.moveOpBefore(&bodyOp, op);
251253
}
@@ -487,7 +489,7 @@ struct FoldPowIntoGate final : OpRewritePattern<PowOp> {
487489
double PowOp::getExponentValue() {
488490
FloatAttr attr;
489491
if (!matchPattern(getExponent(), m_Constant(&attr))) {
490-
llvm::reportFatalUsageError("PowOp exponent must be a constant");
492+
reportFatalUsageError("PowOp exponent must be a constant");
491493
}
492494
return attr.getValueAsDouble();
493495
}

mlir/lib/Dialect/QCO/IR/Modifiers/PowOp.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <Eigen/Core>
1616
#include <Eigen/Eigenvalues>
17-
#include <llvm/ADT/STLFunctionalExtras.h>
1817
#include <llvm/ADT/SmallVector.h>
1918
#include <llvm/ADT/TypeSwitch.h>
2019
#include <llvm/Support/ErrorHandling.h>
@@ -37,6 +36,8 @@
3736
using namespace mlir;
3837
using namespace mlir::qco;
3938
using namespace mlir::utils;
39+
using llvm::reportFatalUsageError;
40+
using llvm::to_vector;
4041

4142
/**
4243
* @brief If the computed P-gate angle corresponds to a named gate, emit it
@@ -176,17 +177,17 @@ struct NegPowToInvPow final : OpRewritePattern<PowOp> {
176177
rewriter.replaceOpWithNewOp<PowOp>(
177178
op, op.getQubitsIn(), -exp,
178179
[&](ValueRange powArgs) -> SmallVector<Value> {
179-
return InvOp::create(
180-
rewriter, op.getLoc(), powArgs,
181-
[&](ValueRange invArgs) -> SmallVector<Value> {
182-
auto* invBody = rewriter.getInsertionBlock();
183-
rewriter.inlineBlockBefore(op.getBody(), invBody,
184-
invBody->begin(), invArgs);
185-
auto yieldedValues =
186-
llvm::to_vector(invBody->back().getOperands());
187-
rewriter.eraseOp(&invBody->back());
188-
return yieldedValues;
189-
})
180+
return InvOp::create(rewriter, op.getLoc(), powArgs,
181+
[&](ValueRange invArgs) -> SmallVector<Value> {
182+
auto* invBody = rewriter.getInsertionBlock();
183+
rewriter.inlineBlockBefore(
184+
op.getBody(), invBody, invBody->begin(),
185+
invArgs);
186+
auto yieldedValues =
187+
to_vector(invBody->back().getOperands());
188+
rewriter.eraseOp(&invBody->back());
189+
return yieldedValues;
190+
})
190191
.getResults();
191192
});
192193

@@ -246,8 +247,8 @@ struct MoveCtrlOutside final : OpRewritePattern<PowOp> {
246247
rewriter.inlineBlockBefore(
247248
innerCtrlOp.getBody(), powBody,
248249
powBody->begin(), powArgs);
249-
auto yieldedValues = llvm::to_vector(
250-
powBody->back().getOperands());
250+
auto yieldedValues =
251+
to_vector(powBody->back().getOperands());
251252
rewriter.eraseOp(&powBody->back());
252253
return yieldedValues;
253254
})
@@ -549,7 +550,7 @@ struct FoldPowIntoGate final : OpRewritePattern<PowOp> {
549550
double PowOp::getExponentValue() {
550551
FloatAttr attr;
551552
if (!matchPattern(getExponent(), m_Constant(&attr))) {
552-
llvm::reportFatalUsageError("PowOp exponent must be a constant");
553+
reportFatalUsageError("PowOp exponent must be a constant");
553554
}
554555
return attr.getValueAsDouble();
555556
}
@@ -565,14 +566,14 @@ UnitaryOpInterface PowOp::getBodyUnitary() {
565566

566567
Value PowOp::getInputQubit(const size_t i) {
567568
if (i >= getNumTargets()) {
568-
llvm::reportFatalUsageError("Qubit index out of bounds");
569+
reportFatalUsageError("Qubit index out of bounds");
569570
}
570571
return getQubitsIn()[i];
571572
}
572573

573574
Value PowOp::getOutputQubit(const size_t i) {
574575
if (i >= getNumTargets()) {
575-
llvm::reportFatalUsageError("Qubit index out of bounds");
576+
reportFatalUsageError("Qubit index out of bounds");
576577
}
577578
return getQubitsOut()[i];
578579
}
@@ -583,7 +584,7 @@ Value PowOp::getInputForOutput(Value output) {
583584
return getQubitsIn()[i];
584585
}
585586
}
586-
llvm::reportFatalUsageError("Given qubit is not an output of the operation");
587+
reportFatalUsageError("Given qubit is not an output of the operation");
587588
}
588589

589590
Value PowOp::getOutputForInput(Value input) {
@@ -592,7 +593,7 @@ Value PowOp::getOutputForInput(Value input) {
592593
return getQubitsOut()[i];
593594
}
594595
}
595-
llvm::reportFatalUsageError("Given qubit is not an input of the operation");
596+
reportFatalUsageError("Given qubit is not an input of the operation");
596597
}
597598

598599
void PowOp::build(OpBuilder& odsBuilder, OperationState& odsState,

0 commit comments

Comments
 (0)