to their corresponding library routines (e.g. isinf). This allows us to handle
all the stuff in macos math.h, and other stuff as it's added to *Builtins.def.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41634
91177308-0d34-0410-b5e6-
96231b3b80d8
#include "clang/AST/Builtins.h"
#include "clang/AST/Expr.h"
#include "llvm/Constants.h"
+#include "llvm/Function.h"
using namespace clang;
using namespace CodeGen;
RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
switch (BuiltinID) {
default:
+ if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
+ return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), E);
+
fprintf(stderr, "Unimplemented builtin!!\n");
E->dump();
return RValue::get(0);
}
-
-RValue CodeGenFunction::EmitBuiltinLibFuncExpr(unsigned BuiltinID,
- const CallExpr *E) {
- //llvm::Function *Callee = CGM.getBuiltinLibFunction(BuiltinID);
- return RValue();
-}
return EmitBuiltinExpr(builtinID, E);
llvm::Value *Callee = EmitScalarExpr(E->getCallee());
-
+ return EmitCallExpr(Callee, E);
+}
+
+RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, const CallExpr *E) {
// The callee type will always be a pointer to function type, get the function
// type.
QualType CalleeTy = E->getCallee()->getType();
//===--------------------------------------------------------------------===//
RValue EmitCallExpr(const CallExpr *E);
+ RValue EmitCallExpr(llvm::Value *Callee, const CallExpr *E);
RValue EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
- RValue EmitBuiltinLibFuncExpr(unsigned BuiltinID, const CallExpr *E);
llvm::Value *EmitObjCStringLiteral(const ObjCStringLiteral *E);
// and for the existing one to be turned into a constantexpr cast of the
// builtin. In the case where the existing one is a static function, it
// should just be renamed.
- assert(getModule().getFunction(Name) == 0 && "FIXME: Name collision");
+ if (llvm::Function *Existing = getModule().getFunction(Name)) {
+ if (Existing->getFunctionType() == Ty && Existing->hasExternalLinkage())
+ return FunctionSlot = Existing;
+ assert(Existing == 0 && "FIXME: Name collision");
+ }
// FIXME: param attributes for sext/zext etc.
return FunctionSlot = new llvm::Function(Ty, llvm::Function::ExternalLinkage,