16
16
17
17
#include < algorithm>
18
18
#include < cstddef>
19
+ #include < llvm/Support/Casting.h>
19
20
#include < llvm/Support/raw_ostream.h>
20
21
#include < mlir/Dialect/Arith/IR/Arith.h>
21
22
#include < mlir/IR/BuiltinTypes.h>
22
23
#include < mlir/IR/MLIRContext.h>
23
24
#include < mlir/IR/PatternMatch.h>
24
25
#include < mlir/IR/Value.h>
25
- #include < mlir/Support/LLVM.h>
26
26
#include < mlir/Support/LogicalResult.h>
27
27
#include < set>
28
28
#include < sstream>
@@ -40,6 +40,8 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
40
40
qc::QuantumComputation& qc)
41
41
: OpRewritePattern(context), circuit(qc) {}
42
42
43
+ // clang-tidy false positive
44
+ // NOLINTNEXTLINE(*-convert-member-functions-to-static)
43
45
[[nodiscard]] mlir::LogicalResult match (const AllocOp op) const override {
44
46
return (op->hasAttr (" to_replace" ) || op->hasAttr (" mqt_core" ))
45
47
? mlir::failure ()
@@ -65,7 +67,7 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
65
67
findQubitIndex (mlir::Value input,
66
68
std::vector<mlir::Value>& currentQubitVariables) {
67
69
size_t arrayIndex = 0 ;
68
- if (const auto opResult = mlir ::dyn_cast<mlir::OpResult>(input)) {
70
+ if (const auto opResult = llvm ::dyn_cast<mlir::OpResult>(input)) {
69
71
arrayIndex = opResult.getResultNumber ();
70
72
} else {
71
73
throw std::runtime_error (
@@ -74,7 +76,7 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
74
76
for (size_t i = 0 ; i < currentQubitVariables.size (); i++) {
75
77
size_t qubitArrayIndex = 0 ;
76
78
if (auto opResult =
77
- mlir ::dyn_cast<mlir::OpResult>(currentQubitVariables[i])) {
79
+ llvm ::dyn_cast<mlir::OpResult>(currentQubitVariables[i])) {
78
80
qubitArrayIndex = opResult.getResultNumber ();
79
81
} else {
80
82
throw std::runtime_error (
@@ -165,7 +167,7 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
165
167
*/
166
168
static void deleteRecursively (mlir::Operation* op,
167
169
mlir::PatternRewriter& rewriter) {
168
- if (mlir ::isa<AllocOp>(op)) {
170
+ if (llvm ::isa<AllocOp>(op)) {
169
171
return ; // Do not delete extract operations.
170
172
}
171
173
if (!op->getUsers ().empty ()) {
@@ -204,17 +206,17 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
204
206
for (auto operand : op->getOperands ()) {
205
207
i++;
206
208
const auto type = operand.getType ();
207
- if (mlir ::isa<QubitType>(type)) {
209
+ if (llvm ::isa<QubitType>(type)) {
208
210
throw std::runtime_error (
209
211
" Interleaving of qubits with non MQTOpt-operations not supported "
210
212
" by round-trip pass!" );
211
213
}
212
- if (mlir ::isa<QubitRegisterType>(type)) {
214
+ if (llvm ::isa<QubitRegisterType>(type)) {
213
215
// Operations that used the old `qureg` will now use the new one
214
216
// instead.
215
217
cloned->setOperand (i - 1 , qureg);
216
218
}
217
- if (mlir ::isa<mlir::IntegerType>(type)) {
219
+ if (llvm ::isa<mlir::IntegerType>(type)) {
218
220
// Operations that used `i1` values (i.e. classical measurement results)
219
221
// will now use a constant value of `false`.
220
222
auto newInput = rewriter.create <mlir::arith::ConstantOp>(
@@ -274,25 +276,25 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
274
276
}
275
277
visited.insert (current);
276
278
277
- if (mlir ::isa<XOp>(current)) {
278
- auto xOp = mlir ::dyn_cast<XOp>(current);
279
+ if (llvm ::isa<XOp>(current)) {
280
+ auto xOp = llvm ::dyn_cast<XOp>(current);
279
281
handleUnitaryOp (xOp, currentQubitVariables);
280
- } else if (mlir ::isa<ExtractOp>(current)) {
281
- auto extractOp = mlir ::dyn_cast<ExtractOp>(current);
282
+ } else if (llvm ::isa<ExtractOp>(current)) {
283
+ auto extractOp = llvm ::dyn_cast<ExtractOp>(current);
282
284
if (const auto indexAttr = extractOp.getIndexAttr ();
283
285
indexAttr.has_value ()) {
284
286
currentQubitVariables[*indexAttr] = extractOp.getOutQubit ();
285
287
} else {
286
288
throw std::runtime_error (
287
289
" Qubit extraction only supported with attr index!" );
288
290
}
289
- } else if (mlir ::isa<AllocOp>(current)) {
291
+ } else if (llvm ::isa<AllocOp>(current)) {
290
292
// Do nothing for now, may change later.
291
- } else if (mlir ::isa<MeasureOp>(current)) {
293
+ } else if (llvm ::isa<MeasureOp>(current)) {
292
294
// We count the number of measurements and add a measurement operation
293
295
// to the QuantumComputation.
294
296
measureCount++;
295
- auto measureOp = mlir ::dyn_cast<MeasureOp>(current);
297
+ auto measureOp = llvm ::dyn_cast<MeasureOp>(current);
296
298
handleMeasureOp (measureOp, currentQubitVariables);
297
299
} else {
298
300
continue ;
0 commit comments