[clang] [CIR] Upstream ClearCacheOp support for __builtin___clear_cache (PR #178260)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 27 10:35:43 PST 2026


================
@@ -5254,6 +5111,26 @@ def CIR_PrefetchOp : CIR_Op<"prefetch"> {
     }];
 }
 
+//===----------------------------------------------------------------------===//
+// ClearCacheOp
+//===----------------------------------------------------------------------===//
+
+def CIR_ClearCacheOp : CIR_Op<"clear_cache", [
+  AllTypesMatch<["begin", "end"]>
+]> {
+  let summary = "clear cache operation";
+  let description = [{
+    CIR representation for `__builtin___clear_cache`.
----------------
andykaylor wrote:

Let's make this more useful. The suggestion below is adapted from the LLVM Language Reference documentation for the corresponding intrinsic.

```suggestion
The ‘cir.clear_cache’ operation provides a representation for the `__builtin__clear_cache` builtin and corresponds to the `llvm.clear_cache` intrinsic in LLVM IR.

This operation ensures visibility of modifications in the specified range to the execution unit of the processor. On targets with non-unified instruction and data cache, the implementation flushes the instruction cache.

On platforms with coherent instruction and data caches (e.g., x86), this intrinsic is a nop. On platforms with non-coherent instruction and data cache (e.g., ARM, MIPS), the operation will be lowered either to appropriate instructions or a system call, if cache flushing requires special privileges.

The default behavior is to emit a call to __clear_cache from the runtime library.

This operation does not empty the instruction pipeline. Modifications of the current function are outside the scope of the operation.
```

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


More information about the cfe-commits mailing list