[clang] [Clang][ExprConstant] Normalize aux target builtin IDs before dispatch (PR #201805)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 22 15:58:44 PDT 2026


================
@@ -78,6 +79,21 @@ void HandleComplexComplexDiv(llvm::APFloat A, llvm::APFloat B, llvm::APFloat C,
 CharUnits GetAlignOfExpr(const ASTContext &Ctx, const Expr *E,
                          UnaryExprOrTypeTrait ExprKind);
 
+/// Return the (normalized) builtin ID to dispatch on in the constant
+/// evaluators' target-specific cases, or 0 if the builtin is not one those
+/// cases should handle. Translates an auxiliary target builtin ID back to its
+/// canonical value and only returns IDs for architectures the constant
+/// evaluators can fold (currently x86/x86_64).
+///
+/// The ID-based overload performs no work beyond a single comparison for
+/// target-independent builtins, so it is suitable for hot paths (e.g. the
+/// bytecode interpreter's builtin dispatch) where re-deriving the ID from the
+/// call expression would be wasteful.
+unsigned getConstantEvaluatedBuiltinID(const ASTContext &Ctx,
+                                       unsigned BuiltinID);
----------------
efriedma-quic wrote:

This still has the problem that it assumes we only care about x86 builtins, in a non-obvious way.  It's not obvious how we adjust this to support other targets.

Maybe this signature is fine, though; we can rename the function to `ConvertBuiltinIDToX86BuiltinID`, or something like that, which more accurately describes what it's doing.

https://github.com/llvm/llvm-project/pull/201805


More information about the cfe-commits mailing list