-
-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathModifierUtils.cpp
More file actions
56 lines (48 loc) · 1.65 KB
/
Copy pathModifierUtils.cpp
File metadata and controls
56 lines (48 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
* Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
* All rights reserved.
*
* SPDX-License-Identifier: MIT
*
* Licensed under the MIT License
*/
#include "ModifierUtils.h"
#include "mlir/Dialect/QC/IR/QCDialect.h"
#include "mlir/Dialect/QC/IR/QCOps.h"
#include <llvm/ADT/STLExtras.h>
#include <mlir/Dialect/MemRef/IR/MemRef.h>
#include <mlir/IR/Block.h>
#include <mlir/IR/Operation.h>
#include <mlir/IR/Value.h>
#include <mlir/Support/LLVM.h>
#include <mlir/Support/LogicalResult.h>
#include <mlir/Support/WalkResult.h>
#include <mlir/Transforms/RegionUtils.h>
namespace mlir::qc::detail {
LogicalResult verifyModifierBody(Operation* modifierOp, Block& body) {
const auto hasNonUnitaryOperation =
body.walk([](Operation* operation) {
return isa<AllocOp, DeallocOp, StaticOp, MeasureOp, ResetOp,
memref::LoadOp, memref::StoreOp>(operation)
? WalkResult::interrupt()
: WalkResult::advance();
})
.wasInterrupted();
if (hasNonUnitaryOperation) {
return modifierOp->emitOpError(
"body must not contain non-unitary quantum operations or modify a "
"quantum register");
}
SetVector<Value> captures;
getUsedValuesDefinedAbove(modifierOp->getRegions(), captures);
if (llvm::any_of(captures, [](const Value value) {
return isa<QubitType>(value.getType());
})) {
return modifierOp->emitOpError(
"body must not capture qubits from above; use only its aliased block "
"arguments");
}
return success();
}
} // namespace mlir::qc::detail