2121using namespace clang ;
2222using namespace clang ::CIRGen;
2323
24+ template <typename ... Operands>
25+ static mlir::Value emitIntrinsicCallOp (CIRGenFunction &cgf, const CallExpr *e,
26+ const std::string &str,
27+ const mlir::Type &resTy,
28+ Operands &&...op) {
29+ CIRGenBuilderTy &builder = cgf.getBuilder ();
30+ mlir::Location location = cgf.getLoc (e->getExprLoc ());
31+ return cir::LLVMIntrinsicCallOp::create (builder, location,
32+ builder.getStringAttr (str), resTy,
33+ std::forward<Operands>(op)...)
34+ .getResult ();
35+ }
36+
2437mlir::Value CIRGenFunction::emitX86BuiltinExpr (unsigned builtinID,
2538 const CallExpr *e) {
2639 if (builtinID == Builtin::BI__builtin_cpu_is) {
@@ -43,15 +56,37 @@ mlir::Value CIRGenFunction::emitX86BuiltinExpr(unsigned builtinID,
4356 // Find out if any arguments are required to be integer constant expressions.
4457 assert (!cir::MissingFeatures::handleBuiltinICEArguments ());
4558
59+ // The operands of the builtin call
60+ llvm::SmallVector<mlir::Value> ops;
61+
62+ // `ICEArguments` is a bitmap indicating whether the argument at the i-th bit
63+ // is required to be a constant integer expression.
64+ unsigned iceArguments = 0 ;
65+ ASTContext::GetBuiltinTypeError error;
66+ getContext ().GetBuiltinType (builtinID, error, &iceArguments);
67+ assert (error == ASTContext::GE_None && " Error while getting builtin type." );
68+
69+ for (auto [idx, arg] : llvm::enumerate (e->arguments ())) {
70+ ops.push_back (emitScalarOrConstFoldImmArg (iceArguments, idx, arg));
71+ }
72+
73+ CIRGenBuilderTy &builder = getBuilder ();
74+ mlir::Type voidTy = builder.getVoidTy ();
75+
4676 switch (builtinID) {
4777 default :
4878 return {};
49- case X86::BI_mm_prefetch:
5079 case X86::BI_mm_clflush:
80+ return emitIntrinsicCallOp (*this , e, " x86.sse2.clflush" , voidTy, ops[0 ]);
5181 case X86::BI_mm_lfence:
82+ return emitIntrinsicCallOp (*this , e, " x86.sse2.lfence" , voidTy);
5283 case X86::BI_mm_pause:
84+ return emitIntrinsicCallOp (*this , e, " x86.sse2.pause" , voidTy);
5385 case X86::BI_mm_mfence:
86+ return emitIntrinsicCallOp (*this , e, " x86.sse2.mfence" , voidTy);
5487 case X86::BI_mm_sfence:
88+ return emitIntrinsicCallOp (*this , e, " x86.sse.sfence" , voidTy);
89+ case X86::BI_mm_prefetch:
5590 case X86::BI__rdtsc:
5691 case X86::BI__builtin_ia32_rdtscp:
5792 case X86::BI__builtin_ia32_lzcnt_u16:
0 commit comments