aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEli Bendersky <eliben@chromium.org>2013-07-10 08:54:29 -0700
committerEli Bendersky <eliben@chromium.org>2013-07-10 08:54:29 -0700
commitf69ebb4201da8bb5045f9335150ed6ef6bcfc2cc (patch)
tree6d0ef75997255e633806335ddf7e8647dbcd5459 /lib
parent3ae70608405cf8180c89f8d3393049b4acd58104 (diff)
Cherry-picking the pow-for-le32 fix from upstream clang.
SVN log from upstream clang: r185568 | eliben | 2013-07-03 12:19:12 -0700 (Wed, 03 Jul 2013) Add target hook CodeGen queries when generating builtin pow*. Without fmath-errno, Clang currently generates calls to @llvm.pow.* intrinsics when it sees pow*(). This may not be suitable for all targets (for example le32/PNaCl), so the attached patch adds a target hook that CodeGen queries. The target can state its preference for having or not having the intrinsic generated. Non-PNaCl behavior remains unchanged; PNaCl-specific test added. BUG= https://code.google.com/p/nativeclient/issues/detail?id=3513 R=dschuff@chromium.org Review URL: https://codereview.chromium.org/18953003
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/CGBuiltin.cpp15
-rw-r--r--lib/CodeGen/TargetInfo.cpp4
-rw-r--r--lib/CodeGen/TargetInfo.h4
3 files changed, 19 insertions, 4 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp
index 7f1709e10f..0d5be26a5e 100644
--- a/lib/CodeGen/CGBuiltin.cpp
+++ b/lib/CodeGen/CGBuiltin.cpp
@@ -1293,10 +1293,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BIpow:
case Builtin::BIpowf:
case Builtin::BIpowl: {
- // LOCALMOD: For PNACl we don't want pow* calls to ever turn into
- // intrinsics. We want them to be resolved vs. the newlib implementation
- // within the pexe during bitcode linking.
- // TODO(eliben): upstream this
+ // Transform a call to pow* into a @llvm.pow.* intrinsic call, but only
+ // if the target agrees.
+ if (getTargetHooks().emitIntrinsicForPow()) {
+ if (!FD->hasAttr<ConstAttr>())
+ break;
+ Value *Base = EmitScalarExpr(E->getArg(0));
+ Value *Exponent = EmitScalarExpr(E->getArg(1));
+ llvm::Type *ArgType = Base->getType();
+ Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType);
+ return RValue::get(Builder.CreateCall2(F, Base, Exponent));
+ }
break;
}
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp
index b870ae9eb1..6ca2910d79 100644
--- a/lib/CodeGen/TargetInfo.cpp
+++ b/lib/CodeGen/TargetInfo.cpp
@@ -416,6 +416,10 @@ class PNaClTargetCodeGenInfo : public TargetCodeGenInfo {
public:
PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
: TargetCodeGenInfo(new PNaClABIInfo(CGT)) {}
+
+ /// For PNaCl we don't want llvm.pow.* intrinsics to be emitted instead
+ /// of library function calls.
+ bool emitIntrinsicForPow() const { return false; }
};
void PNaClABIInfo::computeInfo(CGFunctionInfo &FI) const {
diff --git a/lib/CodeGen/TargetInfo.h b/lib/CodeGen/TargetInfo.h
index bb50ce69e3..a682c183f0 100644
--- a/lib/CodeGen/TargetInfo.h
+++ b/lib/CodeGen/TargetInfo.h
@@ -73,6 +73,10 @@ namespace clang {
/// through such registers.
virtual bool extendPointerWithSExt() const { return false; }
+ /// Controls whether BIpow* emit an intrinsic call instead of a library
+ /// function call.
+ virtual bool emitIntrinsicForPow() const { return true; }
+
/// Determines the DWARF register number for the stack pointer, for
/// exception-handling purposes. Implements __builtin_dwarf_sp_column.
///