aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-16 22:43:43 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-16 22:43:43 +0000
commitef2abfee3ea16ec74942dc09e9e425f46aeb2582 (patch)
treea1fd544522e1d5e2708b9b2a6df1704a0734d0bd /lib/Sema/SemaDecl.cpp
parentf592c929bd1f083abcc8199b24bb825fdd28df1c (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64689 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 2692cd99db..4f8b245ef3 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2956,6 +2956,15 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
if (!FD->getAttr<FormatAttr>())
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<ConstAttr>())
+ FD->addAttr(new ConstAttr());
+ }
}
IdentifierInfo *Name = FD->getIdentifier();