[clang] [CIR] Introduce more cleanup infrastructure (PR #152589)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 11 07:43:12 PDT 2025
================
@@ -14,10 +14,117 @@
#ifndef CLANG_LIB_CIR_CODEGEN_CIRGENCLEANUP_H
#define CLANG_LIB_CIR_CODEGEN_CIRGENCLEANUP_H
+#include "Address.h"
#include "EHScopeStack.h"
+#include "mlir/IR/Value.h"
namespace clang::CIRGen {
+/// A protected scope for zero-cost EH handling.
+class EHScope {
+ class CommonBitFields {
+ friend class EHScope;
+ unsigned kind : 3;
+ };
+ enum { NumCommonBits = 3 };
+
+protected:
+ class CleanupBitFields {
+ friend class EHCleanupScope;
+ unsigned : NumCommonBits;
+
+ /// Whether this cleanup needs to be run along normal edges.
+ unsigned isNormalCleanup : 1;
+
+ /// Whether this cleanup needs to be run along exception edges.
+ unsigned isEHCleanup : 1;
+
+ /// Whether this cleanup is currently active.
+ unsigned isActive : 1;
+
+ /// Whether this cleanup is a lifetime marker
+ unsigned isLifetimeMarker : 1;
+
+ /// Whether the normal cleanup should test the activation flag.
+ unsigned testFlagInNormalCleanup : 1;
+
+ /// Whether the EH cleanup should test the activation flag.
+ unsigned testFlagInEHCleanup : 1;
+
+ /// The amount of extra storage needed by the Cleanup.
+ /// Always a multiple of the scope-stack alignment.
+ unsigned cleanupSize : 12;
+ };
+
+ union {
+ CommonBitFields commonBits;
+ CleanupBitFields cleanupBits;
+ };
+
+public:
+ enum Kind { Cleanup, Catch, Terminate, Filter };
+
+ EHScope(Kind kind) { commonBits.kind = kind; }
+
+ Kind getKind() const { return static_cast<Kind>(commonBits.kind); }
+};
+
+/// A cleanup scope which generates the cleanup blocks lazily.
+class alignas(8) EHCleanupScope : public EHScope {
----------------
mmha wrote:
Should this be `alignas(EHScopeStack::ScopeStackAlignment)`? We can get rid of that static_assert below the class declaration this way.
https://github.com/llvm/llvm-project/pull/152589
More information about the cfe-commits
mailing list