Skip to content

Commit cb9963f

Browse files
committed
🚨 fix clang-tidy warnings for MLIR-related clang-tidy problems
Signed-off-by: burgholzer <[email protected]>
1 parent 0a1b72e commit cb9963f

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

mlir/lib/Dialect/MQTOpt/IR/MQTOptOps.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
* Licensed under the MIT License
88
*/
99

10-
#include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h"
10+
#include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h" // IWYU pragma: associated
1111

12+
// The following headers are needed for some template instantiations.
13+
// IWYU pragma: begin_keep
1214
#include <llvm/ADT/TypeSwitch.h>
1315
#include <mlir/IR/Builders.h>
1416
#include <mlir/IR/DialectImplementation.h>
15-
#include <mlir/Support/LLVM.h>
17+
// IWYU pragma: end_keep
18+
19+
#include <mlir/Support/LogicalResult.h>
1620

1721
//===----------------------------------------------------------------------===//
1822
// Dialect
@@ -21,6 +25,7 @@
2125
#include "mlir/Dialect/MQTOpt/IR/MQTOptOpsDialect.cpp.inc"
2226

2327
void mqt::ir::opt::MQTOptDialect::initialize() {
28+
// NOLINTNEXTLINE(clang-analyzer-core.StackAddressEscape)
2429
addTypes<
2530
#define GET_TYPEDEF_LIST
2631
#include "mlir/Dialect/MQTOpt/IR/MQTOptOpsTypes.cpp.inc"

mlir/lib/Dialect/MQTOpt/Transforms/FromQuantumComputationPattern.cpp

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

1515
#include <cstddef>
1616
#include <cstdint>
17+
#include <llvm/Support/raw_ostream.h>
1718
#include <mlir/IR/BuiltinTypes.h>
1819
#include <mlir/IR/MLIRContext.h>
1920
#include <mlir/IR/PatternMatch.h>
@@ -34,6 +35,8 @@ struct FromQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
3435
qc::QuantumComputation& qc)
3536
: OpRewritePattern(context), circuit(qc) {}
3637

38+
// clang-tidy false positive
39+
// NOLINTNEXTLINE(*-convert-member-functions-to-static)
3740
[[nodiscard]] mlir::LogicalResult match(const AllocOp op) const override {
3841
return op->hasAttr("to_replace") ? mlir::success() : mlir::failure();
3942
}

mlir/lib/Dialect/MQTOpt/Transforms/MQTCoreRoundTrip.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct MQTCoreRoundTrip final : impl::MQTCoreRoundTripBase<MQTCoreRoundTrip> {
3838

3939
// Apply patterns in an iterative and greedy manner.
4040
if (mlir::failed(
41+
// This was deprecated in LLVM@20, but the alternative does not yet
42+
// exist in LLVM@19.
43+
// NOLINTNEXTLINE(clang-diagnostic-deprecated-declarations)
4144
mlir::applyPatternsAndFoldGreedily(op, std::move(patterns)))) {
4245
signalPassFailure();
4346
}

mlir/lib/Dialect/MQTOpt/Transforms/ToQuantumComputationPattern.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616

1717
#include <algorithm>
1818
#include <cstddef>
19+
#include <llvm/Support/Casting.h>
1920
#include <llvm/Support/raw_ostream.h>
2021
#include <mlir/Dialect/Arith/IR/Arith.h>
2122
#include <mlir/IR/BuiltinTypes.h>
2223
#include <mlir/IR/MLIRContext.h>
2324
#include <mlir/IR/PatternMatch.h>
2425
#include <mlir/IR/Value.h>
25-
#include <mlir/Support/LLVM.h>
2626
#include <mlir/Support/LogicalResult.h>
2727
#include <set>
2828
#include <sstream>
@@ -40,6 +40,8 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
4040
qc::QuantumComputation& qc)
4141
: OpRewritePattern(context), circuit(qc) {}
4242

43+
// clang-tidy false positive
44+
// NOLINTNEXTLINE(*-convert-member-functions-to-static)
4345
[[nodiscard]] mlir::LogicalResult match(const AllocOp op) const override {
4446
return (op->hasAttr("to_replace") || op->hasAttr("mqt_core"))
4547
? mlir::failure()
@@ -65,7 +67,7 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
6567
findQubitIndex(mlir::Value input,
6668
std::vector<mlir::Value>& currentQubitVariables) {
6769
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)) {
6971
arrayIndex = opResult.getResultNumber();
7072
} else {
7173
throw std::runtime_error(
@@ -74,7 +76,7 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
7476
for (size_t i = 0; i < currentQubitVariables.size(); i++) {
7577
size_t qubitArrayIndex = 0;
7678
if (auto opResult =
77-
mlir::dyn_cast<mlir::OpResult>(currentQubitVariables[i])) {
79+
llvm::dyn_cast<mlir::OpResult>(currentQubitVariables[i])) {
7880
qubitArrayIndex = opResult.getResultNumber();
7981
} else {
8082
throw std::runtime_error(
@@ -165,7 +167,7 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
165167
*/
166168
static void deleteRecursively(mlir::Operation* op,
167169
mlir::PatternRewriter& rewriter) {
168-
if (mlir::isa<AllocOp>(op)) {
170+
if (llvm::isa<AllocOp>(op)) {
169171
return; // Do not delete extract operations.
170172
}
171173
if (!op->getUsers().empty()) {
@@ -204,17 +206,17 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
204206
for (auto operand : op->getOperands()) {
205207
i++;
206208
const auto type = operand.getType();
207-
if (mlir::isa<QubitType>(type)) {
209+
if (llvm::isa<QubitType>(type)) {
208210
throw std::runtime_error(
209211
"Interleaving of qubits with non MQTOpt-operations not supported "
210212
"by round-trip pass!");
211213
}
212-
if (mlir::isa<QubitRegisterType>(type)) {
214+
if (llvm::isa<QubitRegisterType>(type)) {
213215
// Operations that used the old `qureg` will now use the new one
214216
// instead.
215217
cloned->setOperand(i - 1, qureg);
216218
}
217-
if (mlir::isa<mlir::IntegerType>(type)) {
219+
if (llvm::isa<mlir::IntegerType>(type)) {
218220
// Operations that used `i1` values (i.e. classical measurement results)
219221
// will now use a constant value of `false`.
220222
auto newInput = rewriter.create<mlir::arith::ConstantOp>(
@@ -274,25 +276,25 @@ struct ToQuantumComputationPattern final : mlir::OpRewritePattern<AllocOp> {
274276
}
275277
visited.insert(current);
276278

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);
279281
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);
282284
if (const auto indexAttr = extractOp.getIndexAttr();
283285
indexAttr.has_value()) {
284286
currentQubitVariables[*indexAttr] = extractOp.getOutQubit();
285287
} else {
286288
throw std::runtime_error(
287289
"Qubit extraction only supported with attr index!");
288290
}
289-
} else if (mlir::isa<AllocOp>(current)) {
291+
} else if (llvm::isa<AllocOp>(current)) {
290292
// Do nothing for now, may change later.
291-
} else if (mlir::isa<MeasureOp>(current)) {
293+
} else if (llvm::isa<MeasureOp>(current)) {
292294
// We count the number of measurements and add a measurement operation
293295
// to the QuantumComputation.
294296
measureCount++;
295-
auto measureOp = mlir::dyn_cast<MeasureOp>(current);
297+
auto measureOp = llvm::dyn_cast<MeasureOp>(current);
296298
handleMeasureOp(measureOp, currentQubitVariables);
297299
} else {
298300
continue;

mlir/tools/quantum-opt/quantum-opt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* Licensed under the MIT License
88
*/
99

10-
#include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h"
11-
#include "mlir/Dialect/MQTOpt/Transforms/Passes.h"
10+
#include "mlir/Dialect/MQTOpt/IR/MQTOptDialect.h" // IWYU pragma: keep
11+
#include "mlir/Dialect/MQTOpt/Transforms/Passes.h" // IWYU pragma: keep
1212

1313
#include <mlir/Dialect/Func/Extensions/AllExtensions.h>
1414
#include <mlir/IR/DialectRegistry.h>

0 commit comments

Comments
 (0)