[Mlir-commits] [mlir] [mlir][NFC] Move LLVM::ModuleTranslation::SaveStack to a shared header (PR #144897)
Tom Eccles
llvmlistbot at llvm.org
Fri Jun 20 04:10:38 PDT 2025
================
@@ -0,0 +1,116 @@
+//===- StateStack.h - Utility for storing a stack of state ------*- 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 utilities for storing a stack of generic context.
+// The context can be arbitrary data, possibly including file-scoped types.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_SUPPORT_STACKFRAME_H
+#define MLIR_SUPPORT_STACKFRAME_H
+
+#include "mlir/IR/Visitors.h"
+#include "mlir/Support/TypeID.h"
+#include <memory>
+
+namespace mlir {
+
+/// Common CRTP base class for StateStack frames.
+class StateStackFrame {
+public:
+ virtual ~StateStackFrame() = default;
+ TypeID getTypeID() const { return typeID; }
+
+protected:
+ explicit StateStackFrame(TypeID typeID) : typeID(typeID) {}
+
+private:
+ const TypeID typeID;
+ virtual void anchor() {};
----------------
tblah wrote:
Thanks for the explanation. I hadn't seen this pattern before.
https://github.com/llvm/llvm-project/pull/144897
More information about the Mlir-commits
mailing list