Skip to content

Conversation

@aniragil
Copy link
Contributor

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.

@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-emitc

Author: Gil Rapaport (aniragil)

Changes

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

@aniragil
Copy link
Contributor Author

ping

@aniragil
Copy link
Contributor Author

thanks @simon-camp !

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.
@aniragil aniragil force-pushed the emitc-refactor-get-emitted-expression branch from 6f89af4 to cb8fef4 Compare November 24, 2025 08:49
@aniragil
Copy link
Contributor Author

(rebased, one of the uses of getEmittedExpression was eliminated by #168267)

@aniragil aniragil merged commit ce70d4b into llvm:main Nov 24, 2025
10 checks passed
aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
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.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Nov 26, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants