[cfe-commits] r41634 - in /cfe/trunk/CodeGen: CGBuiltin.cpp CGExpr.cpp CodeGenFunction.h CodeGenModule.cpp
Chris Lattner
sabre at nondot.org
Thu Aug 30 21:44:07 PDT 2007
Author: lattner
Date: Thu Aug 30 23:44:06 2007
New Revision: 41634
URL: http://llvm.org/viewvc/llvm-project?rev=41634&view=rev
Log:
Implement codegen support for lowering "library builtins" like __builtin_isinf
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.
Modified:
cfe/trunk/CodeGen/CGBuiltin.cpp
cfe/trunk/CodeGen/CGExpr.cpp
cfe/trunk/CodeGen/CodeGenFunction.h
cfe/trunk/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGBuiltin.cpp?rev=41634&r1=41633&r2=41634&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/CodeGen/CGBuiltin.cpp Thu Aug 30 23:44:06 2007
@@ -17,12 +17,16 @@
#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();
@@ -46,9 +50,3 @@
return RValue::get(0);
}
-
-RValue CodeGenFunction::EmitBuiltinLibFuncExpr(unsigned BuiltinID,
- const CallExpr *E) {
- //llvm::Function *Callee = CGM.getBuiltinLibFunction(BuiltinID);
- return RValue();
-}
Modified: cfe/trunk/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGExpr.cpp?rev=41634&r1=41633&r2=41634&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/CodeGen/CGExpr.cpp Thu Aug 30 23:44:06 2007
@@ -376,7 +376,10 @@
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();
Modified: cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenFunction.h?rev=41634&r1=41633&r2=41634&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/CodeGen/CodeGenFunction.h Thu Aug 30 23:44:06 2007
@@ -324,8 +324,8 @@
//===--------------------------------------------------------------------===//
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);
Modified: cfe/trunk/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CodeGenModule.cpp?rev=41634&r1=41633&r2=41634&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/CodeGen/CodeGenModule.cpp Thu Aug 30 23:44:06 2007
@@ -127,7 +127,11 @@
// 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,
More information about the cfe-commits
mailing list