From 8eb018ab9c00c504d8b6d991865a599adbd1da02 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 16 Feb 2009 22:43:43 +0000 Subject: Support IRgen of sqrt -> llvm.sqrt, pow -> llvm.pow. - Define pow[lf]?, sqrt[lf]? as builtins. - Add -fmath-errno option which binds to LangOptions.MathErrno - Add new builtin flag Builtin::Context::isConstWithoutErrno for functions which can be marked as const if errno isn't respected for math functions. Sema automatically marks these functions as const when they are defined, if MathErrno=0. - IRgen uses const attribute on sqrt and pow library functions to decide if it can use the llvm intrinsic. llvm-svn: 64689 --- clang/lib/Sema/SemaDecl.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'clang/lib/Sema/SemaDecl.cpp') diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 2692cd99db4..4f8b245ef36 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2956,6 +2956,15 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { if (!FD->getAttr()) FD->addAttr(new FormatAttr("printf", FormatIdx + 1, FormatIdx + 2)); } + + // Mark const if we don't care about errno and that is the only + // thing preventing the function from being const. This allows + // IRgen to use LLVM intrinsics for such functions. + if (!getLangOptions().MathErrno && + Context.BuiltinInfo.isConstWithoutErrno(BuiltinID)) { + if (!FD->getAttr()) + FD->addAttr(new ConstAttr()); + } } IdentifierInfo *Name = FD->getIdentifier(); -- cgit v1.2.3