[Mlir-commits] [mlir] [mlir][emitc] Refactor getEmittedExpression (NFC) (PR #168361)

Gil Rapaport llvmlistbot at llvm.org
Mon Nov 17 04:31:55 PST 2025


https://github.com/aniragil created https://github.com/llvm/llvm-project/pull/168361

This method returns the current expression being emitted, but is only used testing whether an expression is being emitted or not. This patch therefore replaces it with a boolean isEmittingExpression() method.

>From 6f89af4ffa35df6129b08023fd39db5abc71a161 Mon Sep 17 00:00:00 2001
From: Gil Rapaport <gil.rapaport at mobileye.com>
Date: Mon, 17 Nov 2025 12:45:17 +0200
Subject: [PATCH] [mlir][emitc] Refactor getEmittedExpression (NFC)

This method returns the current expression being emitted, but is only
used testing whether an expression is being emitted or not. This patch
therefore replaces it with a boolean isEmittingExpression() method.
---
 mlir/lib/Target/Cpp/TranslateToCpp.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/mlir/lib/Target/Cpp/TranslateToCpp.cpp b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
index 6bd76bb1ffc4b..5bf6108756a2f 100644
--- a/mlir/lib/Target/Cpp/TranslateToCpp.cpp
+++ b/mlir/lib/Target/Cpp/TranslateToCpp.cpp
@@ -250,8 +250,8 @@ struct CppEmitter {
     return !fileId.empty() && file.getId() == fileId;
   }
 
-  /// Get expression currently being emitted.
-  ExpressionOp getEmittedExpression() { return emittedExpression; }
+  /// Is expression currently being emitted.
+  bool isEmittingExpression() { return emittedExpression; }
 
   /// Determine whether given value is part of the expression potentially being
   /// emitted.
@@ -1630,11 +1630,11 @@ LogicalResult CppEmitter::emitOperands(Operation &op) {
   return interleaveCommaWithError(op.getOperands(), os, [&](Value operand) {
     // If an expression is being emitted, push lowest precedence as these
     // operands are either wrapped by parenthesis.
-    if (getEmittedExpression())
+    if (isEmittingExpression())
       pushExpressionPrecedence(lowestPrecedence());
     if (failed(emitOperand(operand)))
       return failure();
-    if (getEmittedExpression())
+    if (isEmittingExpression())
       popExpressionPrecedence();
     return success();
   });
@@ -1718,7 +1718,7 @@ LogicalResult CppEmitter::emitGlobalVariable(GlobalOp op) {
 
 LogicalResult CppEmitter::emitAssignPrefix(Operation &op) {
   // If op is being emitted as part of an expression, bail out.
-  if (getEmittedExpression())
+  if (isEmittingExpression())
     return success();
 
   switch (op.getNumResults()) {
@@ -1800,7 +1800,7 @@ LogicalResult CppEmitter::emitOperation(Operation &op, bool trailingSemicolon) {
   if (hasDeferredEmission(&op))
     return success();
 
-  if (getEmittedExpression() ||
+  if (isEmittingExpression() ||
       (isa<emitc::ExpressionOp>(op) &&
        shouldBeInlined(cast<emitc::ExpressionOp>(op))))
     return success();



More information about the Mlir-commits mailing list