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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Nov 17 04:33:28 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir-emitc

Author: Gil Rapaport (aniragil)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/168361.diff


1 Files Affected:

- (modified) mlir/lib/Target/Cpp/TranslateToCpp.cpp (+6-6) 


``````````diff
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();

``````````

</details>


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


More information about the Mlir-commits mailing list