[clang] [CIR] Upstream minimal builtin function call support (PR #142981)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 9 09:21:26 PDT 2025
================
@@ -0,0 +1,55 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Builtin calls as CIR or a function call to be
+// later resolved.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CIRGenCall.h"
+#include "CIRGenFunction.h"
+#include "CIRGenModule.h"
+#include "CIRGenValue.h"
+#include "mlir/IR/BuiltinAttributes.h"
+#include "mlir/IR/Value.h"
+#include "mlir/Support/LLVM.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/GlobalDecl.h"
+#include "llvm/Support/ErrorHandling.h"
+
+using namespace clang;
+using namespace clang::CIRGen;
+
+RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
+ const CallExpr *e,
+ ReturnValueSlot returnValue) {
+ // See if we can constant fold this builtin. If so, don't emit it at all.
+ // TODO: Extend this handling to all builtin calls that we can constant-fold.
+ Expr::EvalResult result;
+ if (e->isPRValue() && e->EvaluateAsRValue(result, cgm.getASTContext()) &&
+ !result.hasSideEffects()) {
+ if (result.Val.isInt()) {
+ return RValue::get(builder.getConstInt(getLoc(e->getSourceRange()),
+ result.Val.getInt()));
+ }
+ if (result.Val.isFloat()) {
----------------
erichkeane wrote:
Do we have a test for one that has a floating point result?
https://github.com/llvm/llvm-project/pull/142981
More information about the cfe-commits
mailing list