diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-16 22:43:43 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-16 22:43:43 +0000 |
commit | 8eb018ab9c00c504d8b6d991865a599adbd1da02 (patch) | |
tree | 0c2978666b992a473ab97522b85289681716c7f4 /clang/lib/CodeGen/CGBuiltin.cpp | |
parent | 45a2a20384f6c74d66f2b5c0b42f083d31deaefc (diff) | |
download | bcm5719-llvm-8eb018ab9c00c504d8b6d991865a599adbd1da02.tar.gz bcm5719-llvm-8eb018ab9c00c504d8b6d991865a599adbd1da02.zip |
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
Diffstat (limited to 'clang/lib/CodeGen/CGBuiltin.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGBuiltin.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index b990c199953..6e59226a6e8 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -36,7 +36,8 @@ static RValue EmitBinaryAtomic(CodeGenFunction& CFG, CFG.EmitScalarExpr(E->getArg(1)))); } -RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { +RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, + unsigned BuiltinID, const CallExpr *E) { // See if we can constant fold this builtin. If so, don't emit it at all. Expr::EvalResult Result; if (E->Evaluate(Result, CGM.getContext())) { @@ -324,6 +325,34 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) { } case Builtin::BI__sync_lock_test_and_set: return EmitBinaryAtomic(*this, Intrinsic::atomic_swap, E); + + + // Library functions with special handling. + + case Builtin::BIsqrt: + case Builtin::BIsqrtf: + case Builtin::BIsqrtl: { + // Rewrite sqrt to intrinsic if allowed. + if (!FD->getAttr<ConstAttr>()) + break; + Value *Arg0 = EmitScalarExpr(E->getArg(0)); + const llvm::Type *ArgType = Arg0->getType(); + Value *F = CGM.getIntrinsic(Intrinsic::sqrt, &ArgType, 1); + return RValue::get(Builder.CreateCall(F, Arg0, "tmp")); + } + + case Builtin::BIpow: + case Builtin::BIpowf: + case Builtin::BIpowl: { + // Rewrite sqrt to intrinsic if allowed. + if (!FD->getAttr<ConstAttr>()) + break; + Value *Base = EmitScalarExpr(E->getArg(0)); + Value *Exponent = EmitScalarExpr(E->getArg(1)); + const llvm::Type *ArgType = Base->getType(); + Value *F = CGM.getIntrinsic(Intrinsic::pow, &ArgType, 1); + return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp")); + } } // If this is an alias for a libm function (e.g. __builtin_sin) turn it into |