[clang] [CIR] Upstream minimal support for structure types (PR #135105)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 17:46:55 PDT 2025


================
@@ -0,0 +1,116 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 contains implementation details, such as storage structures, of
+// CIR dialect types.
+//
+//===----------------------------------------------------------------------===//
+#ifndef CIR_DIALECT_IR_CIRTYPESDETAILS_H
+#define CIR_DIALECT_IR_CIRTYPESDETAILS_H
+
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/Support/LogicalResult.h"
+#include "clang/CIR/Dialect/IR/CIRTypes.h"
+#include "llvm/ADT/Hashing.h"
+
+namespace cir {
+namespace detail {
+
+//===----------------------------------------------------------------------===//
+// CIR StructTypeStorage
+//===----------------------------------------------------------------------===//
+
+/// Type storage for CIR record types.
+struct StructTypeStorage : public mlir::TypeStorage {
+  struct KeyTy {
+    llvm::ArrayRef<mlir::Type> members;
+    mlir::StringAttr name;
+    bool incomplete;
+    bool packed;
+    bool padded;
+    StructType::RecordKind kind;
+
+    KeyTy(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
+          bool incomplete, bool packed, bool padded,
+          StructType::RecordKind kind)
+        : members(members), name(name), incomplete(incomplete), packed(packed),
+          padded(padded), kind(kind) {}
+  };
+
+  llvm::ArrayRef<mlir::Type> members;
+  mlir::StringAttr name;
+  bool incomplete;
+  bool packed;
+  bool padded;
+  StructType::RecordKind kind;
+
+  StructTypeStorage(llvm::ArrayRef<mlir::Type> members, mlir::StringAttr name,
+                    bool incomplete, bool packed, bool padded,
+                    StructType::RecordKind kind)
+      : members(members), name(name), incomplete(incomplete), packed(packed),
+        padded(padded), kind(kind) {}
+
+  KeyTy getAsKey() const {
+    return KeyTy(members, name, incomplete, packed, padded, kind);
+  }
+
+  bool operator==(const KeyTy &key) const {
+    if (name)
+      return (name == key.name) && (kind == key.kind);
+    return (members == key.members) && (name == key.name) &&
----------------
erichkeane wrote:

```suggestion
    return std::tie(members, name, incomplete, packed, padded, kind) == std::tie(key.members, key.name, key.incomplete, key.packed, key.padded, key.kind);
```

mostly because I've seen those and-equals patterns get wonky/messed up commonly in the past.


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


More information about the cfe-commits mailing list