================
@@ -1798,6 +1901,103 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl
&gd, unsigned builtinID,
return emitLibraryCall(*this, fd, e,
cgm.getBuiltinLibFunction(fd, builtinID));
+ // See if we have a target specific intrinsic.
+ std::string name = getContext().BuiltinInfo.getName(builtinID);
+ Intrinsic::ID intrinsicID = Intrinsic::not_intrinsic;
+ StringRef prefix =
+ llvm::Triple::getArchTypePrefix(getTarget().getTriple().getArch());
+ if (!prefix.empty()) {
+ intrinsicID = Intrinsic::getIntrinsicForClangBuiltin(prefix.data(), name);
+ // NOTE we don't need to perform a compatibility flag check here since the
+ // intrinsics are declared in Builtins*.def via LANGBUILTIN which filter
the
+ // MS builtins via ALL_MS_LANGUAGES and are filtered earlier.
+ if (intrinsicID == Intrinsic::not_intrinsic)
+ intrinsicID = Intrinsic::getIntrinsicForMSBuiltin(prefix.data(), name);
+ }
+
+ if (intrinsicID != Intrinsic::not_intrinsic) {
+ unsigned iceArguments = 0;
+ ASTContext::GetBuiltinTypeError error;
+ getContext().GetBuiltinType(builtinID, error, &iceArguments);
+ assert(error == ASTContext::GE_None && "Should not codegen an error");
+
+ llvm::StringRef name = llvm::Intrinsic::getName(intrinsicID);
+ // cir::LLVMIntrinsicCallOp expects intrinsic name to not have prefix
+ // "llvm." For example, `llvm.nvvm.barrier0` should be passed as
+ // `nvvm.barrier0`.
+ if (!name.consume_front("llvm."))
+ assert(false && "bad intrinsic name!");
+
+ cir::FuncType intrinsicType =
+ getIntrinsicType(&getMLIRContext(), intrinsicID);
+
+ SmallVector<mlir::Value> args;
+ for (unsigned i = 0; i < e->getNumArgs(); i++) {
+ mlir::Value argValue =
+ emitScalarOrConstFoldImmArg(iceArguments, i, e->getArg(i));
+ // If the intrinsic arg type is different from the builtin arg type
+ // we need to do a bit cast.
+ mlir::Type argType = argValue.getType();
+ mlir::Type expectedTy = intrinsicType.getInput(i);
+
+ // Use helper to get the correct integer type based on AST signedness
+ mlir::Type correctedExpectedTy =
+ getIntrinsicArgumentTypeFromAST(expectedTy, e, i, &getMLIRContext());
+
+ if (argType != correctedExpectedTy)
+ argValue = getCorrectedPtr(argValue, expectedTy, builder);
+
----------------
Priyanshu3820 wrote:
I am yet to see a builtin having such a type mismatch(signed mismatches are
already handled)
https://github.com/llvm/llvm-project/pull/179098
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits