@@ -66,6 +66,14 @@ translateX86ToMsvcIntrin(unsigned BuiltinID) {
66
66
llvm_unreachable (" must return from switch" );
67
67
}
68
68
69
+ // / Get integer from a mlir::Value that is an int constant or a constant op.
70
+ static int64_t getIntValueFromConstOp (mlir::Value val) {
71
+ auto constOp = mlir::cast<cir::ConstantOp>(val.getDefiningOp ());
72
+ return (mlir::cast<cir::IntAttr>(constOp.getValue ()))
73
+ .getValue ()
74
+ .getSExtValue ();
75
+ }
76
+
69
77
mlir::Value CIRGenFunction::emitX86BuiltinExpr (unsigned BuiltinID,
70
78
const CallExpr *E) {
71
79
if (BuiltinID == Builtin::BI__builtin_cpu_is)
@@ -96,7 +104,23 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned BuiltinID,
96
104
default :
97
105
return nullptr ;
98
106
case X86::BI_mm_prefetch: {
99
- llvm_unreachable (" _mm_prefetch NYI" );
107
+ mlir::Value Address = builder.createPtrBitcast (Ops[0 ], VoidTy);
108
+
109
+ int64_t Hint = getIntValueFromConstOp (Ops[1 ]);
110
+ mlir::Value RW = builder.create <cir::ConstantOp>(
111
+ getLoc (E->getExprLoc ()),
112
+ cir::IntAttr::get (SInt32Ty, (Hint >> 2 ) & 0x1 ));
113
+ mlir::Value Locality = builder.create <cir::ConstantOp>(
114
+ getLoc (E->getExprLoc ()), cir::IntAttr::get (SInt32Ty, Hint & 0x3 ));
115
+ mlir::Value Data = builder.create <cir::ConstantOp>(
116
+ getLoc (E->getExprLoc ()), cir::IntAttr::get (SInt32Ty, 1 ));
117
+ mlir::Type voidTy = cir::VoidType::get (&getMLIRContext ());
118
+
119
+ return builder
120
+ .create <cir::LLVMIntrinsicCallOp>(
121
+ getLoc (E->getExprLoc ()), builder.getStringAttr (" prefetch" ), voidTy,
122
+ mlir::ValueRange{Address, RW, Locality, Data})
123
+ .getResult ();
100
124
}
101
125
case X86::BI_mm_clflush: {
102
126
mlir::Type voidTy = cir::VoidType::get (&getMLIRContext ());
0 commit comments