[Mlir-commits] [mlir] [mlir][EmitC] Refactor MLIR Translate To Cpp (PR #84973)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Mar 12 12:01:21 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Weizhe (Jack) Chen (weizchen)

<details>
<summary>Changes</summary>

This refactors the MLIR TranslateToCpp part by introducing CppTranslationInterface
that breaks down the overall translation into different dialects. This majorly helps
the readability of the code and extensibility for future c++ translation addition.


---

Patch is 104.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/84973.diff


23 Files Affected:

- (modified) mlir/include/mlir/Target/Cpp/CppEmitter.h (-6) 
- (added) mlir/include/mlir/Target/Cpp/CppTranslationInterface.h (+55) 
- (added) mlir/include/mlir/Target/Cpp/CppTranslationUtils.h (+86) 
- (added) mlir/include/mlir/Target/Cpp/Dialect/All.h (+35) 
- (added) mlir/include/mlir/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.h (+31) 
- (added) mlir/include/mlir/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.h (+31) 
- (added) mlir/include/mlir/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.h (+31) 
- (added) mlir/include/mlir/Target/Cpp/Dialect/Func/FuncToCppTranslation.h (+31) 
- (added) mlir/include/mlir/Target/Cpp/TranslateToCpp.h (+194) 
- (modified) mlir/lib/Target/Cpp/CMakeLists.txt (+22-6) 
- (added) mlir/lib/Target/Cpp/CppTranslationUtils.cpp (+225) 
- (added) mlir/lib/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.cpp (+74) 
- (added) mlir/lib/Target/Cpp/Dialect/Builtin/CMakeLists.txt (+11) 
- (added) mlir/lib/Target/Cpp/Dialect/CMakeLists.txt (+4) 
- (added) mlir/lib/Target/Cpp/Dialect/ControlFlow/CMakeLists.txt (+12) 
- (added) mlir/lib/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.cpp (+128) 
- (added) mlir/lib/Target/Cpp/Dialect/EmitC/CMakeLists.txt (+12) 
- (added) mlir/lib/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.cpp (+538) 
- (added) mlir/lib/Target/Cpp/Dialect/Func/CMakeLists.txt (+12) 
- (added) mlir/lib/Target/Cpp/Dialect/Func/FuncToCppTranslation.cpp (+126) 
- (modified) mlir/lib/Target/Cpp/TranslateRegistration.cpp (+4-8) 
- (modified) mlir/lib/Target/Cpp/TranslateToCpp.cpp (+16-1035) 
- (modified) mlir/test/Target/Cpp/invalid.mlir (+1-1) 


``````````diff
diff --git a/mlir/include/mlir/Target/Cpp/CppEmitter.h b/mlir/include/mlir/Target/Cpp/CppEmitter.h
index 30d3fff9fca88b..4aa551fa205123 100644
--- a/mlir/include/mlir/Target/Cpp/CppEmitter.h
+++ b/mlir/include/mlir/Target/Cpp/CppEmitter.h
@@ -14,13 +14,8 @@
 #define MLIR_TARGET_CPP_CPPEMITTER_H
 
 #include "mlir/IR/BuiltinTypes.h"
-#include "mlir/IR/Value.h"
-#include "llvm/ADT/ScopedHashTable.h"
-#include "llvm/Support/raw_ostream.h"
-#include <stack>
 
 namespace mlir {
-namespace emitc {
 
 /// Translates the given operation to C++ code. The operation or operations in
 /// the region of 'op' need almost all be in EmitC dialect. The parameter
@@ -28,7 +23,6 @@ namespace emitc {
 /// arguments are declared at the beginning of the function.
 LogicalResult translateToCpp(Operation *op, raw_ostream &os,
                              bool declareVariablesAtTop = false);
-} // namespace emitc
 } // namespace mlir
 
 #endif // MLIR_TARGET_CPP_CPPEMITTER_H
diff --git a/mlir/include/mlir/Target/Cpp/CppTranslationInterface.h b/mlir/include/mlir/Target/Cpp/CppTranslationInterface.h
new file mode 100644
index 00000000000000..d0a964a82ec2ec
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/CppTranslationInterface.h
@@ -0,0 +1,55 @@
+//===--- CppTranslationInterface.h - Translation to Cpp iface ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This header file defines dialect interfaces for translation to Cpp.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_CPPTRANSLATIONINTERFACE_H
+#define MLIR_TARGET_CPP_CPPTRANSLATIONINTERFACE_H
+
+#include "mlir/IR/DialectInterface.h"
+#include "mlir/Support/LogicalResult.h"
+
+namespace mlir {
+struct CppEmitter;
+
+/// Base class for dialect interfaces providing translation to Cpp. Dialects
+/// should implement this interface with supported operation translations to
+/// be registered and used with translate-to-cpp.
+class CppTranslationDialectInterface
+    : public DialectInterface::Base<CppTranslationDialectInterface> {
+public:
+  CppTranslationDialectInterface(Dialect *dialect) : Base(dialect) {}
+
+  /// Hook for derived dialect interface to provide op translation to Cpp.
+  virtual LogicalResult emitOperation(Operation *op, CppEmitter &cppEmitter,
+                                      bool trailingSemicolon) const {
+    return failure();
+  }
+};
+
+/// Interface collection for translation to Cpp, dispatches to a concrete
+/// interface implementation based on the dialect to which the given op belongs.
+class CppTranslationInterface
+    : public DialectInterfaceCollection<CppTranslationDialectInterface> {
+public:
+  using Base::Base;
+
+  /// Translates the given operation to Cpp using the derived dialect interface.
+  virtual LogicalResult emitOperation(Operation *op, CppEmitter &cppEmitter,
+                                      bool trailingSemicolon) const {
+    if (const CppTranslationDialectInterface *iface = getInterfaceFor(op))
+      return iface->emitOperation(op, cppEmitter, trailingSemicolon);
+    return failure();
+  }
+};
+
+} // namespace mlir
+
+#endif // MLIR_TARGET_CPP_CPPTRANSLATIONINTERFACE_H
diff --git a/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h b/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h
new file mode 100644
index 00000000000000..4ca777fa901618
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/CppTranslationUtils.h
@@ -0,0 +1,86 @@
+//===- CppTranslationUtils.h - Helpers to used in C++ emitter ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines common helper functions used across different dialects
+// during the Cpp translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_CPPTRANSLATIONUTILS_H
+#define MLIR_TARGET_CPP_CPPTRANSLATIONUTILS_H
+
+#include "mlir/Dialect/EmitC/IR/EmitC.h"
+#include "mlir/Target/Cpp/TranslateToCpp.h"
+
+using namespace mlir;
+
+/// Convenience functions to produce interleaved output with functions returning
+/// a LogicalResult. This is different than those in STLExtras as functions used
+/// on each element doesn't return a string.
+template <typename ForwardIterator, typename UnaryFunctor,
+          typename NullaryFunctor>
+inline LogicalResult
+interleaveWithError(ForwardIterator begin, ForwardIterator end,
+                    UnaryFunctor eachFn, NullaryFunctor betweenFn) {
+  if (begin == end)
+    return success();
+  if (failed(eachFn(*begin)))
+    return failure();
+  ++begin;
+  for (; begin != end; ++begin) {
+    betweenFn();
+    if (failed(eachFn(*begin)))
+      return failure();
+  }
+  return success();
+}
+
+template <typename Container, typename UnaryFunctor, typename NullaryFunctor>
+inline LogicalResult interleaveWithError(const Container &c,
+                                         UnaryFunctor eachFn,
+                                         NullaryFunctor betweenFn) {
+  return interleaveWithError(c.begin(), c.end(), eachFn, betweenFn);
+}
+
+template <typename Container, typename UnaryFunctor>
+inline LogicalResult interleaveCommaWithError(const Container &c,
+                                              raw_ostream &os,
+                                              UnaryFunctor eachFn) {
+  return interleaveWithError(c.begin(), c.end(), eachFn, [&]() { os << ", "; });
+}
+
+
+/// Determine whether expression \p expressionOp should be emitted inline, i.e.
+/// as part of its user. This function recommends inlining of any expressions
+/// that can be inlined unless it is used by another expression, under the
+/// assumption that  any expression fusion/re-materialization was taken care of
+/// by transformations run by the backend.
+bool shouldBeInlined(emitc::ExpressionOp expressionOp);
+
+LogicalResult printConstantOp(CppEmitter &emitter, Operation *operation,
+                              Attribute value);
+
+LogicalResult printBinaryOperation(CppEmitter &emitter, Operation *operation,
+                                   StringRef binaryOperator);
+
+LogicalResult printUnaryOperation(CppEmitter &emitter, Operation *operation,
+                                  StringRef unaryOperator);
+
+LogicalResult printCallOperation(CppEmitter &emitter, Operation *callOp,
+                                 StringRef callee);
+
+LogicalResult printFunctionArgs(CppEmitter &emitter, Operation *functionOp,
+                                ArrayRef<Type> arguments);
+
+LogicalResult printFunctionArgs(CppEmitter &emitter, Operation *functionOp,
+                                Region::BlockArgListType arguments);
+
+LogicalResult printFunctionBody(CppEmitter &emitter, Operation *functionOp,
+                                Region::BlockListType &blocks);
+
+#endif // MLIR_TARGET_CPP_CPPTRANSLATIONUTILS_H
diff --git a/mlir/include/mlir/Target/Cpp/Dialect/All.h b/mlir/include/mlir/Target/Cpp/Dialect/All.h
new file mode 100644
index 00000000000000..556588efb0118c
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/Dialect/All.h
@@ -0,0 +1,35 @@
+//===----- All.h - MLIR To Cpp Translation Registration ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines a helper to register the all dialect translations to Cpp.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_DIALECT_ALL_H
+#define MLIR_TARGET_CPP_DIALECT_ALL_H
+
+#include "mlir/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.h"
+#include "mlir/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.h"
+#include "mlir/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.h"
+#include "mlir/Target/Cpp/Dialect/Func/FuncToCppTranslation.h"
+
+namespace mlir {
+class DialectRegistry;
+
+/// Registers all dialects that can be translated to Cpp and the
+/// corresponding translation interfaces.
+static inline void registerAllToCppTranslations(DialectRegistry &registry) {
+  registerBuiltinDialectCppTranslation(registry);
+  registerControlFlowDialectCppTranslation(registry);
+  registerEmitCDialectCppTranslation(registry);
+  registerFuncDialectCppTranslation(registry);
+}
+
+} // namespace mlir
+
+#endif // MLIR_TARGET_CPP_DIALECT_ALL_H
diff --git a/mlir/include/mlir/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.h b/mlir/include/mlir/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.h
new file mode 100644
index 00000000000000..25f19022f49043
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/Dialect/Builtin/BuiltinToCppTranslation.h
@@ -0,0 +1,31 @@
+//===---- BuiltinToCppTranslation.h - Builtin Dialect to Cpp ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides registration calls for Builtin dialect to Cpp translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_DIALECT_BUILTIN_BUILTINTOCPPTRANSLATION_H
+#define MLIR_TARGET_CPP_DIALECT_BUILTIN_BUILTINTOCPPTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the Builtin dialect and the translation from it to the Cpp in the
+/// given registry;
+void registerBuiltinDialectCppTranslation(DialectRegistry &registry);
+
+/// Register the Builtin dialect and the translation from it in the registry
+/// associated with the given context.
+void registerBuiltinDialectCppTranslation(MLIRContext &context);
+
+} // namespace mlir
+
+#endif // MLIR_TARGET_CPP_DIALECT_BUILTIN_BUILTINTOCPPTRANSLATION_H
diff --git a/mlir/include/mlir/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.h b/mlir/include/mlir/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.h
new file mode 100644
index 00000000000000..fea57fd1c02e28
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/Dialect/ControlFlow/ControlFlowToCppTranslation.h
@@ -0,0 +1,31 @@
+//===- ControlFlowToCppTranslation.h - ControlFlow Dialect to Cpp -*-C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides registration calls for ControlFlow dialect to Cpp translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_DIALECT_CONTROLFLOW_CONTROLFLOWTOCPPTRANSLATION_H
+#define MLIR_TARGET_CPP_DIALECT_CONTROLFLOW_CONTROLFLOWTOCPPTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the ControlFlow dialect and the translation from it to the Cpp in
+/// the given registry;
+void registerControlFlowDialectCppTranslation(DialectRegistry &registry);
+
+/// Register the ControlFlow dialect and the translation from it in the registry
+/// associated with the given context.
+void registerControlFlowDialectCppTranslation(MLIRContext &context);
+
+} // namespace mlir
+
+#endif // MLIR_TARGET_CPP_DIALECT_CONTROLFLOW_CONTROLFLOWTOCPPTRANSLATION_H
diff --git a/mlir/include/mlir/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.h b/mlir/include/mlir/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.h
new file mode 100644
index 00000000000000..af47ffad1ab62e
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/Dialect/EmitC/EmitCToCppTranslation.h
@@ -0,0 +1,31 @@
+//===------ EmitCToCppTranslation.h - EmitC Dialect to Cpp-------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides registration calls for EmitC dialect to Cpp translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_DIALECT_EMITC_EMITCTOCPPTRANSLATION_H
+#define MLIR_TARGET_CPP_DIALECT_EMITC_EMITCTOCPPTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the EmitC dialect and the translation from it to the Cpp in the
+/// given registry;
+void registerEmitCDialectCppTranslation(DialectRegistry &registry);
+
+/// Register the EmitC dialect and the translation from it in the registry
+/// associated with the given context.
+void registerEmitCDialectCppTranslation(MLIRContext &context);
+
+} // namespace mlir
+
+#endif // MLIR_TARGET_CPP_DIALECT_EMITC_EMITCTOCPPTRANSLATION_H
diff --git a/mlir/include/mlir/Target/Cpp/Dialect/Func/FuncToCppTranslation.h b/mlir/include/mlir/Target/Cpp/Dialect/Func/FuncToCppTranslation.h
new file mode 100644
index 00000000000000..b167093dc334bb
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/Dialect/Func/FuncToCppTranslation.h
@@ -0,0 +1,31 @@
+//===------- FuncToCppTranslation.h - Func Dialect to Cpp -------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This provides registration calls for Func dialect to Cpp translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_DIALECT_FUNC_FUNCTOCPPTRANSLATION_H
+#define MLIR_TARGET_CPP_DIALECT_FUNC_FUNCTOCPPTRANSLATION_H
+
+namespace mlir {
+
+class DialectRegistry;
+class MLIRContext;
+
+/// Register the Func dialect and the translation from it to the Cpp in the
+/// given registry;
+void registerFuncDialectCppTranslation(DialectRegistry &registry);
+
+/// Register the Func dialect and the translation from it in the registry
+/// associated with the given context.
+void registerFuncDialectCppTranslation(MLIRContext &context);
+
+} // namespace mlir
+
+#endif // MLIR_TARGET_CPP_DIALECT_FUNC_FUNCTOCPPTRANSLATION_H
diff --git a/mlir/include/mlir/Target/Cpp/TranslateToCpp.h b/mlir/include/mlir/Target/Cpp/TranslateToCpp.h
new file mode 100644
index 00000000000000..9deb44a9fe0066
--- /dev/null
+++ b/mlir/include/mlir/Target/Cpp/TranslateToCpp.h
@@ -0,0 +1,194 @@
+//===-- TranslateToCpp.h - Define CppEmitter struct -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the CppEmitter meta struct used for Cpp translation.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_TARGET_CPP_TRANSLATETOCPP_H
+#define MLIR_TARGET_CPP_TRANSLATETOCPP_H
+
+#include "mlir/Dialect/EmitC/IR/EmitC.h"
+#include "mlir/IR/BuiltinTypes.h"
+#include "mlir/Support/IndentedOstream.h"
+#include "mlir/Target/Cpp/CppEmitter.h"
+#include "mlir/Target/Cpp/CppTranslationInterface.h"
+#include "llvm/ADT/ScopedHashTable.h"
+#include "llvm/Support/raw_ostream.h"
+#include <stack>
+
+namespace mlir {
+
+/// Emitter that uses dialect specific emitters to emit C++ code.
+struct CppEmitter {
+  friend LogicalResult translateToCpp(Operation *op, raw_ostream &os,
+                                      bool declareVariablesAtTop);
+
+  explicit CppEmitter(raw_ostream &os, Operation *module,
+                      bool declareVariablesAtTop);
+
+  /// Emits attribute or returns failure.
+  LogicalResult emitAttribute(Location loc, Attribute attr);
+
+  /// Emits operation 'op' with/without training semicolon or returns failure.
+  LogicalResult emitOperation(Operation &op, bool trailingSemicolon);
+
+  /// Emits type 'type' or returns failure.
+  LogicalResult emitType(Location loc, Type type);
+
+  /// Emits array of types as a std::tuple of the emitted types.
+  /// - emits void for an empty array;
+  /// - emits the type of the only element for arrays of size one;
+  /// - emits a std::tuple otherwise;
+  LogicalResult emitTypes(Location loc, ArrayRef<Type> types);
+
+  /// Emits array of types as a std::tuple of the emitted types independently of
+  /// the array size.
+  LogicalResult emitTupleType(Location loc, ArrayRef<Type> types);
+
+  /// Emits an assignment for a variable which has been declared previously.
+  LogicalResult emitVariableAssignment(OpResult result);
+
+  /// Emits a variable declaration for a result of an operation.
+  LogicalResult emitVariableDeclaration(OpResult result,
+                                        bool trailingSemicolon);
+
+  /// Emits a declaration of a variable with the given type and name.
+  LogicalResult emitVariableDeclaration(Location loc, Type type,
+                                        StringRef name);
+
+  /// Emits the variable declaration and assignment prefix for 'op'.
+  /// - emits separate variable followed by std::tie for multi-valued operation;
+  /// - emits single type followed by variable for single result;
+  /// - emits nothing if no value produced by op;
+  /// Emits final '=' operator where a type is produced. Returns failure if
+  /// any result type could not be converted.
+  LogicalResult emitAssignPrefix(Operation &op);
+
+  /// Emits a label for the block.
+  LogicalResult emitLabel(Block &block);
+
+  /// Emits the operands and atttributes of the operation. All operands are
+  /// emitted first and then all attributes in alphabetical order.
+  LogicalResult emitOperandsAndAttributes(Operation &op,
+                                          ArrayRef<StringRef> exclude = {});
+
+  /// Emits the operands of the operation. All operands are emitted in order.
+  LogicalResult emitOperands(Operation &op);
+
+  /// Emits value as an operands of an operation
+  LogicalResult emitOperand(Value value);
+
+  /// Emit an expression as a C expression.
+  LogicalResult emitExpression(emitc::ExpressionOp expressionOp);
+
+  /// Return the existing or a new name for a Value.
+  StringRef getOrCreateName(Value val);
+
+  /// Return the existing or a new label of a Block.
+  StringRef getOrCreateName(Block &block);
+
+  /// Whether to map an mlir integer to a unsigned integer in C++.
+  bool shouldMapToUnsigned(IntegerType::SignednessSemantics val);
+
+  /// RAII helper function to manage entering/exiting C++ scopes.
+  struct Scope {
+    Scope(CppEmitter &emitter)
+        : valueMapperScope(emitter.valueMapper),
+          blockMapperScope(emitter.blockMapper), emitter(emitter) {
+      emitter.valueInScopeCount.push(emitter.valueInScopeCount.top());
+      emitter.labelInScopeCount.push(emitter.labelInScopeCount.top());
+    }
+    ~Scope() {
+      emitter.valueInScopeCount.pop();
+      emitter.labelInScopeCount.pop();
+    }
+
+  private:
+    llvm::ScopedHashTableScope<Value, std::string> valueMapperScope;
+    llvm::ScopedHashTableScope<Block *, std::string> blockMapperScope;
+    CppEmitter &emitter;
+  };
+
+  /// Returns wether the Value is assigned to a C++ variable in the scope.
+  bool hasValueInScope(Value val);
+
+  // Returns whether a label is assigned to the block.
+  bool hasBlockLabel(Block &block);
+
+  /// Returns the output stream.
+  raw_indented_ostream &ostream() { return os; };
+
+  /// Returns if all variables for op results and basic block argu...
[truncated]

``````````

</details>


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


More information about the Mlir-commits mailing list