[clang] [CIR] Memoize FuncType purity checks in the CIR dialect (PR #232863)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 10:59:03 PDT 2026


================
@@ -253,6 +253,33 @@ static LogicalResult verifyOffloadContainer(mlir::Operation *op) {
   return success();
 }
 
+bool cir::CIRDialect::isPureCIRType(mlir::Type ty) const {
+  assert(ty && "isPureCIRType requires a non-null type");
+  {
+    std::lock_guard<std::mutex> lock(pureCIRTypeCacheMutex);
+    auto it = pureCIRTypeCache.find(ty);
+    if (it != pureCIRTypeCache.end())
+      return it->second;
+  }
+  // Records gain members when completed, so a "pure" answer is only stable
+  // when the walk saw no incomplete record. "Impure" answers stay stable.
+  bool sawIncompleteRecord = false;
+  bool result = !ty.walk([&](mlir::Type t) {
+                     if (!t)
+                       return mlir::WalkResult::advance();
+                     if (auto rec = mlir::dyn_cast<cir::RecordType>(t))
+                       sawIncompleteRecord |= rec.isIncomplete();
+                     return mlir::isa<cir::CIRDialect>(t.getDialect())
+                                ? mlir::WalkResult::advance()
+                                : mlir::WalkResult::interrupt();
+                   }).wasInterrupted();
+  if (!result || !sawIncompleteRecord) {
----------------
erichkeane wrote:

We are only saving the 'true' cases?  I guess I don't get why?  

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


More information about the cfe-commits mailing list