[clang] [CIR] Add X86 prefetch builtins (PR #168051)

Hendrik Hübner via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 18 00:59:02 PST 2025


================
@@ -34,6 +39,28 @@ static mlir::Value emitIntrinsicCallOp(CIRGenFunction &cgf, const CallExpr *e,
       .getResult();
 }
 
+static mlir::Value emitPrefetch(CIRGenFunction &cgf, unsigned builtinID,
+                                const CallExpr *e,
+                                mlir::Value &addr, int64_t hint) {
+  CIRGenBuilderTy &builder = cgf.getBuilder();
+  mlir::Location location = cgf.getLoc(e->getExprLoc());
+  mlir::Type voidTy = builder.getVoidTy();
+  mlir::Value address = builder.createPtrBitcast(addr, voidTy);
+  bool isWrite{};
+  int locality{};
+
+  if (builtinID == X86::BI_mm_prefetch) {
+    isWrite = (hint >> 2) & 0x1;
+    locality = hint & 0x3;
+  } else {
+    isWrite = (builtinID == X86::BI_m_prefetchw);
+    locality = 0x3;
+  }
+
+  cir::PrefetchOp::create(builder, location, address, locality, isWrite);
+  return {};
----------------
HendrikHuebner wrote:

For this PR I replaced the return type with `std::optional<mlir::Value>` to handle this case. `return {}` just returns a nullopt, indicating the builtin was not created.

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


More information about the cfe-commits mailing list