================ @@ -5980,6 +5987,64 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, return Ret; } +static bool endsWithRoundingModeSuffix(StringRef FuncName) { + size_t Underscore = FuncName.find_last_of("_"); + if (Underscore == StringRef::npos || Underscore < 2) + return false; + StringRef Suffix = FuncName.substr(Underscore + 1); + static const StringRef RMSuffixes[] = {"rtz", "rte", "rtp", "rtn", "rhaz", + "rz", "rn", "ru", "rd"}; + for (auto RM : RMSuffixes) { + if (Suffix == RM) + return true; + } + return false; +} + +bool CodeGenFunction::requiresDynamicRounding(const CGCallee &Callee) { + if (Callee.isOrdinary()) { + const Decl *CalleeDecl = Callee.getAbstractInfo().getCalleeDecl().getDecl(); + if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CalleeDecl)) { + IdentifierInfo *FuncNameII = FD->getDeclName().getAsIdentifierInfo(); + if (FuncNameII) { + StringRef FuncName = FuncNameII->getName(); + // If a reserved identifier ends with rounding mode suffix preceded by + // underscore, this function does not need the previous dynamic rounding + // mode to be set. + if (isReservedInAllContexts( + FuncNameII->isReserved(getContext().getLangOpts()))) { + if (endsWithRoundingModeSuffix(FuncName)) + return false; + } + } + } + } + return true; +} + +/// Sets dynamic rounding mode for the function called in the region where +/// pragma FENV_ROUND is in effect. +void CodeGenFunction::setRoundingModeForCall(const CGCallee &Callee) { + if (Target.hasStaticRounding() || Callee.isBuiltin() || + !requiresDynamicRounding(Callee)) + return; + if (!CurrentRoundingIsStatic || !DynamicRoundingMode) + return; + Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::set_rounding), + DynamicRoundingMode); + CurrentRoundingIsStatic = false; ---------------- jcranmer-intel wrote:
I'm not seeing logic here to effect the proper handling of, e.g., `sqrt`. Is this planned in a future patch? If so, add in a TODO note. https://github.com/llvm/llvm-project/pull/89617 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits