[Mlir-commits] [mlir] Adding to execute_region_op some missing support (PR #164159)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sun Oct 19 06:27:10 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- mlir/lib/Dialect/SCF/IR/SCF.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp
index 727c2e3ff..753fe96cd 100644
--- a/mlir/lib/Dialect/SCF/IR/SCF.cpp
+++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp
@@ -291,9 +291,11 @@ struct MultiBlockExecuteInliner : public OpRewritePattern<ExecuteRegionOp> {
}
};
-// Pattern to eliminate ExecuteRegionOp results when it only forwards external values.
-// It operates only on execute regions with single terminator yield operation.
-struct ExecuteRegionForwardingEliminator : public OpRewritePattern<ExecuteRegionOp> {
+// Pattern to eliminate ExecuteRegionOp results when it only forwards external
+// values. It operates only on execute regions with single terminator yield
+// operation.
+struct ExecuteRegionForwardingEliminator
+ : public OpRewritePattern<ExecuteRegionOp> {
using OpRewritePattern<ExecuteRegionOp>::OpRewritePattern;
LogicalResult matchAndRewrite(ExecuteRegionOp op,
@@ -301,7 +303,7 @@ struct ExecuteRegionForwardingEliminator : public OpRewritePattern<ExecuteRegion
if (op.getNumResults() == 0)
return failure();
- SmallVector<Operation*> yieldOps;
+ SmallVector<Operation *> yieldOps;
for (Block &block : op.getRegion()) {
if (auto yield = dyn_cast<scf::YieldOp>(block.getTerminator())) {
if (yield.getResults().empty())
@@ -310,70 +312,73 @@ struct ExecuteRegionForwardingEliminator : public OpRewritePattern<ExecuteRegion
}
}
- if(yieldOps.size() != 1)
+ if (yieldOps.size() != 1)
return failure();
auto yieldOp = dyn_cast<scf::YieldOp>(yieldOps.front());
auto yieldedValues = yieldOp.getOperands();
// Check if all yielded values are from outside the region
- bool allExternal = true;
+ bool allExternal = true;
for (Value yieldedValue : yieldedValues) {
if (isValueFromInsideRegion(yieldedValue, op)) {
allExternal = false;
break;
}
- }
+ }
if (!allExternal)
return failure();
- // All yielded values are external - create a new execute_region with no results.
+ // All yielded values are external - create a new execute_region with no
+ // results.
auto newOp = rewriter.create<ExecuteRegionOp>(op.getLoc(), TypeRange{});
newOp->setAttrs(op->getAttrs());
-
+
// Move the region content to the new operation
newOp.getRegion().takeBody(op.getRegion());
-
+
// Replace the yield operation with a new yield operation with no results.
rewriter.setInsertionPoint(yieldOp);
rewriter.eraseOp(yieldOp);
rewriter.create<scf::YieldOp>(yieldOp.getLoc());
-
+
// Replace the old operation with the external values directly.
rewriter.replaceOp(op, yieldedValues);
return success();
}
private:
- bool isValueFromInsideRegion(Value value, ExecuteRegionOp executeRegionOp) const {
+ bool isValueFromInsideRegion(Value value,
+ ExecuteRegionOp executeRegionOp) const {
// Check if the value is defined within the execute_region
if (Operation *defOp = value.getDefiningOp()) {
return executeRegionOp.getRegion().isAncestor(defOp->getParentRegion());
}
-
+
// If it's a block argument, check if it's from within the region
if (BlockArgument blockArg = dyn_cast<BlockArgument>(value)) {
return executeRegionOp.getRegion().isAncestor(blockArg.getParentRegion());
}
-
+
return false; // Value is from outside the region
}
};
void ExecuteRegionOp::getCanonicalizationPatterns(RewritePatternSet &results,
- MLIRContext *context) {
+ MLIRContext *context) {
results.add<SingleBlockExecuteInliner, MultiBlockExecuteInliner,
- ExecuteRegionForwardingEliminator>(context);
+ ExecuteRegionForwardingEliminator>(context);
}
void ExecuteRegionOp::getEffects(
- SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
- &effects) {
-if (!getNoInline())
- return;
-// In case there is attribute no_inline we want the region not to be inlined into the parent operation.
-effects.emplace_back(MemoryEffects::Write::get(),
- SideEffects::DefaultResource::get());
+ SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
+ &effects) {
+ if (!getNoInline())
+ return;
+ // In case there is attribute no_inline we want the region not to be inlined
+ // into the parent operation.
+ effects.emplace_back(MemoryEffects::Write::get(),
+ SideEffects::DefaultResource::get());
}
void ExecuteRegionOp::getSuccessorRegions(
``````````
</details>
https://github.com/llvm/llvm-project/pull/164159
More information about the Mlir-commits
mailing list