Debian Codegraph @

clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp

raw
1 //===---------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===---------------------------------------------------------------------===//
8
9 #include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
10
11 #include "clang/CIR/Dialect/IR/CIRDialect.h"
12 #include "clang/CIR/Interfaces/CIRLoopOpInterface.cpp.inc"
13 #include "llvm/Support/ErrorHandling.h"
14
15 namespace cir {
16
17 void LoopOpInterface::getLoopOpSuccessorRegions(
18 LoopOpInterface op, mlir::RegionBranchPoint point,
19 llvm::SmallVectorImpl<mlir::RegionSuccessor> &regions) {
20 assert(point.isParent() || point.getTerminatorPredecessorOrNull());
21
22 // Branching to first region: go to condition or body (do-while).
23 if (point.isParent()) {
24 regions.emplace_back(&op.getEntry(), op.getEntry().getArguments());
25 return;
26 }
27
28 mlir::Region *parentRegion =
29 point.getTerminatorPredecessorOrNull()->getParentRegion();
30
31 // Branching from condition: go to body or exit.
32 if (&op.getCond() == parentRegion) {
33 regions.emplace_back(mlir::RegionSuccessor(op, op->getResults()));
34 regions.emplace_back(&op.getBody(), op.getBody().getArguments());
35 return;
36 }
37
38 // Branching from body: go to step (for) or condition.
39 if (&op.getBody() == parentRegion) {
40 // FIXME(cir): Should we consider break/continue statements here?
41 mlir::Region *afterBody =
42 (op.maybeGetStep() ? op.maybeGetStep() : &op.getCond());
43 regions.emplace_back(afterBody, afterBody->getArguments());
44 return;
45 }
46
47 // Branching from step: go to condition.
48 if (op.maybeGetStep() == parentRegion) {
49 regions.emplace_back(&op.getCond(), op.getCond().getArguments());
50 return;
51 }
52
53 llvm_unreachable("unexpected branch origin");
54 }
55
56 /// Verify invariants of the LoopOpInterface.
57 llvm::LogicalResult detail::verifyLoopOpInterface(mlir::Operation *op) {
58 // FIXME: fix this so the conditionop isn't requiring MLIRCIR
59 // auto loopOp = mlir::cast<LoopOpInterface>(op);
60 // if (!mlir::isa<ConditionOp>(loopOp.getCond().back().getTerminator()))
61 // return op->emitOpError(
62 // "expected condition region to terminate with 'cir.condition'");
63 return llvm::success();
64 }
65
66 } // namespace cir