/// value is not an induction variable, then return nullptr.
ParallelOp getParallelForInductionVarOwner(Value val);
+/// Return true if ops a and b (or their ancestors) are in mutually exclusive
+/// regions/blocks of an IfOp.
+// TODO: Consider moving this functionality to RegionBranchOpInterface.
+bool insideMutuallyExclusiveBranches(Operation *a, Operation *b);
+
/// An owning vector of values, handy to return from functions.
using ValueVector = std::vector<Value>;
using LoopVector = std::vector<scf::ForOp>;
// IfOp
//===----------------------------------------------------------------------===//
+bool mlir::scf::insideMutuallyExclusiveBranches(Operation *a, Operation *b) {
+ assert(a && "expected non-empty operation");
+ assert(b && "expected non-empty operation");
+
+ IfOp ifOp = a->getParentOfType<IfOp>();
+ while (ifOp) {
+ // Check if b is inside ifOp. (We already know that a is.)
+ if (ifOp->isProperAncestor(b))
+ // b is contained in ifOp. a and b are in mutually exclusive branches if
+ // they are in different blocks of ifOp.
+ return static_cast<bool>(ifOp.thenBlock()->findAncestorOpInBlock(*a)) !=
+ static_cast<bool>(ifOp.thenBlock()->findAncestorOpInBlock(*b));
+ // Check next enclosing IfOp.
+ ifOp = ifOp->getParentOfType<IfOp>();
+ }
+
+ // Could not find a common IfOp among a's and b's ancestors.
+ return false;
+}
+
void IfOp::build(OpBuilder &builder, OperationState &result, Value cond,
bool withElseRegion) {
build(builder, result, /*resultTypes=*/llvm::None, cond, withElseRegion);