Path: blob/main/contrib/llvm-project/clang/lib/CIR/Interfaces/CIRLoopOpInterface.cpp
213799 views
//===---------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===---------------------------------------------------------------------===//78#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"910#include "clang/CIR/Dialect/IR/CIRDialect.h"11#include "clang/CIR/Interfaces/CIRLoopOpInterface.cpp.inc"12#include "llvm/Support/ErrorHandling.h"1314namespace cir {1516void LoopOpInterface::getLoopOpSuccessorRegions(17LoopOpInterface op, mlir::RegionBranchPoint point,18llvm::SmallVectorImpl<mlir::RegionSuccessor> ®ions) {19assert(point.isParent() || point.getRegionOrNull());2021// Branching to first region: go to condition or body (do-while).22if (point.isParent()) {23regions.emplace_back(&op.getEntry(), op.getEntry().getArguments());24return;25}2627// Branching from condition: go to body or exit.28if (&op.getCond() == point.getRegionOrNull()) {29regions.emplace_back(mlir::RegionSuccessor(op->getResults()));30regions.emplace_back(&op.getBody(), op.getBody().getArguments());31return;32}3334// Branching from body: go to step (for) or condition.35if (&op.getBody() == point.getRegionOrNull()) {36// FIXME(cir): Should we consider break/continue statements here?37mlir::Region *afterBody =38(op.maybeGetStep() ? op.maybeGetStep() : &op.getCond());39regions.emplace_back(afterBody, afterBody->getArguments());40return;41}4243// Branching from step: go to condition.44if (op.maybeGetStep() == point.getRegionOrNull()) {45regions.emplace_back(&op.getCond(), op.getCond().getArguments());46return;47}4849llvm_unreachable("unexpected branch origin");50}5152/// Verify invariants of the LoopOpInterface.53llvm::LogicalResult detail::verifyLoopOpInterface(mlir::Operation *op) {54// FIXME: fix this so the conditionop isn't requiring MLIRCIR55// auto loopOp = mlir::cast<LoopOpInterface>(op);56// if (!mlir::isa<ConditionOp>(loopOp.getCond().back().getTerminator()))57// return op->emitOpError(58// "expected condition region to terminate with 'cir.condition'");59return llvm::success();60}6162} // namespace cir636465