@@ -26,13 +26,16 @@ static int64_t getIntValueFromConstOp(mlir::Value val) {
2626 return val.getDefiningOp <cir::ConstantOp>().getIntValue ().getSExtValue ();
2727}
2828
29- static mlir::Value emitClFlush (CIRGenFunction &cgf, const CallExpr *e,
30- mlir::Value &op) {
31- mlir::Type voidTy = cir::VoidType::get (&cgf.getMLIRContext ());
29+ template <typename ... Operands>
30+ static mlir::Value emitIntrinsicCallOp (CIRGenFunction &cgf, const CallExpr *e,
31+ const std::string &str,
32+ const mlir::Type &resTy,
33+ Operands &&...op) {
34+ CIRGenBuilderTy &builder = cgf.getBuilder ();
3235 mlir::Location location = cgf.getLoc (e->getExprLoc ());
33- return cir::LLVMIntrinsicCallOp::create (
34- cgf. getBuilder ( ), location ,
35- cgf. getBuilder (). getStringAttr ( " x86.sse2.clflush " ), voidTy, op )
36+ return cir::LLVMIntrinsicCallOp::create (builder, location,
37+ builder. getStringAttr (str ), resTy ,
38+ std::forward<Operands>(op)... )
3639 .getResult ();
3740}
3841
@@ -46,10 +49,8 @@ static mlir::Value emitPrefetch(CIRGenFunction &cgf, const CallExpr *e,
4649 mlir::Value locality = builder.getSignedInt (location, hint & 0x3 , 32 );
4750 mlir::Value data = builder.getSignedInt (location, 1 , 32 );
4851
49- return cir::LLVMIntrinsicCallOp::create (
50- builder, location, builder.getStringAttr (" prefetch" ), voidTy,
51- mlir::ValueRange{address, rw, locality, data})
52- .getResult ();
52+ return emitIntrinsicCallOp (cgf, e, " prefetch" , voidTy,
53+ mlir::ValueRange{address, rw, locality, data});
5354}
5455
5556mlir::Value CIRGenFunction::emitX86BuiltinExpr (unsigned builtinID,
@@ -89,17 +90,24 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
8990 ops.push_back (emitScalarOrConstFoldImmArg (iceArguments, i, e));
9091 }
9192
93+ CIRGenBuilderTy &builder = getBuilder ();
94+ mlir::Type voidTy = builder.getVoidTy ();
95+
9296 switch (builtinID) {
9397 default :
9498 return {};
9599 case X86::BI_mm_prefetch:
96100 return emitPrefetch (*this , e, ops[0 ], getIntValueFromConstOp (ops[1 ]));
97101 case X86::BI_mm_clflush:
98- return emitClFlush (*this , e, ops[0 ]);
102+ return emitIntrinsicCallOp (*this , e, " x86.sse2.clflush " , voidTy , ops[0 ]);
99103 case X86::BI_mm_lfence:
104+ return emitIntrinsicCallOp (*this , e, " x86.sse2.lfence" , voidTy);
100105 case X86::BI_mm_pause:
106+ return emitIntrinsicCallOp (*this , e, " x86.sse2.pause" , voidTy);
101107 case X86::BI_mm_mfence:
108+ return emitIntrinsicCallOp (*this , e, " x86.sse2.mfence" , voidTy);
102109 case X86::BI_mm_sfence:
110+ return emitIntrinsicCallOp (*this , e, " x86.sse.sfence" , voidTy);
103111 case X86::BI__rdtsc:
104112 case X86::BI__builtin_ia32_rdtscp:
105113 case X86::BI__builtin_ia32_lzcnt_u16:
0 commit comments