From dfb865732c65f45b5ee513bb58c7adfaffbdb1e9 Mon Sep 17 00:00:00 2001 From: swote Date: Thu, 25 Sep 2025 02:12:41 +0900 Subject: [PATCH 1/3] [MLIR] Clarify createOrFold as opportunistic eager folding Add documentation note explaining that createOrFold performs opportunistic eager folding during IR construction, attempting optimization only once without iterative refinement. This addresses user confusion about createOrFold behavior compared to canonicalization passes. Addresses #159844 --- mlir/include/mlir/IR/Builders.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index ad59ea63a6901..7a137125eb440 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -513,6 +513,9 @@ class OpBuilder : public Builder { /// Create an operation of specific op type at the current insertion point, /// and immediately try to fold it. This functions populates 'results' with /// the results of the operation. + /// + /// Note: This performs opportunistic eager folding during IR construction, + /// attempting optimization only once without iterative refinement. template void createOrFold(SmallVectorImpl &results, Location location, Args &&...args) { From 4849263ae26af8de3f5285d98377c4d762534fbc Mon Sep 17 00:00:00 2001 From: NohHyeon Kwon <96061253+swote-git@users.noreply.github.com> Date: Thu, 25 Sep 2025 06:30:57 +0900 Subject: [PATCH 2/3] Update mlir/include/mlir/IR/Builders.h much clearer comment for createOrFold. Co-authored-by: Mehdi Amini --- mlir/include/mlir/IR/Builders.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 7a137125eb440..9e453f941b479 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -514,8 +514,11 @@ class OpBuilder : public Builder { /// and immediately try to fold it. This functions populates 'results' with /// the results of the operation. /// - /// Note: This performs opportunistic eager folding during IR construction, - /// attempting optimization only once without iterative refinement. + /// Note: This performs opportunistic eager folding during IR construction. + /// The folders are designed to operate efficiently on canonical IR, which this + /// API does not enforce. Complete folding isn't only expected in the context + /// of canonicalization which intertwine folders with pattern rewrites until + /// fixed-point. template void createOrFold(SmallVectorImpl &results, Location location, Args &&...args) { From 9e9cc9b92cf4039ca70c53d0b3dc027ab41466da Mon Sep 17 00:00:00 2001 From: swote Date: Thu, 25 Sep 2025 06:52:36 +0900 Subject: [PATCH 3/3] fix: to observe clang format --- mlir/include/mlir/IR/Builders.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mlir/include/mlir/IR/Builders.h b/mlir/include/mlir/IR/Builders.h index 9e453f941b479..50fa6d0302a69 100644 --- a/mlir/include/mlir/IR/Builders.h +++ b/mlir/include/mlir/IR/Builders.h @@ -515,10 +515,10 @@ class OpBuilder : public Builder { /// the results of the operation. /// /// Note: This performs opportunistic eager folding during IR construction. - /// The folders are designed to operate efficiently on canonical IR, which this - /// API does not enforce. Complete folding isn't only expected in the context - /// of canonicalization which intertwine folders with pattern rewrites until - /// fixed-point. + /// The folders are designed to operate efficiently on canonical IR, which + /// this API does not enforce. Complete folding isn't only expected in the + /// context of canonicalization which intertwine folders with pattern + /// rewrites until fixed-point. template void createOrFold(SmallVectorImpl &results, Location location, Args &&...args) {