[llvm-commits] [llvm-gcc-4.2] r56903 - in /llvm-gcc-4.2/trunk/gcc: llvm-backend.cpp llvm-convert.cpp
Bill Wendling
isanbard at gmail.com
Tue Sep 30 18:07:42 PDT 2008
Author: void
Date: Tue Sep 30 20:07:42 2008
New Revision: 56903
URL: http://llvm.org/viewvc/llvm-project?rev=56903&view=rev
Log:
Don't generate calls to intrinsics if the user specified that all built-ins (or a
particular built-in) are to be disabled.
Modified:
llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
Modified: llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp?rev=56903&r1=56902&r2=56903&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-backend.cpp Tue Sep 30 20:07:42 2008
@@ -70,7 +70,6 @@
#include "tree-inline.h"
#include "langhooks.h"
#include "cgraph.h"
-#include "c-common.h"
}
// Non-zero if bytecode from PCH is successfully read.
@@ -166,16 +165,15 @@
ArgStrings.push_back(Arg);
}
- if (flag_no_builtin)
- ArgStrings.push_back(std::string("--no-builtin"));
-
if (llvm_optns) {
std::string Opts = llvm_optns;
for (std::string Opt = getToken(Opts); !Opt.empty(); Opt = getToken(Opts))
ArgStrings.push_back(Opt);
}
+
for (unsigned i = 0, e = ArgStrings.size(); i != e; ++i)
Args.push_back(ArgStrings[i].c_str());
+
Args.push_back(0); // Null terminator.
int pseudo_argc = Args.size()-1;
Modified: llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp?rev=56903&r1=56902&r2=56903&view=diff
==============================================================================
--- llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp (original)
+++ llvm-gcc-4.2/trunk/gcc/llvm-convert.cpp Tue Sep 30 20:07:42 2008
@@ -67,6 +67,7 @@
#include "libfuncs.h"
#include "tree-flow.h"
#include "tree-gimple.h"
+#include "c-common.h"
extern int get_pointer_alignment (tree exp, unsigned int max_align);
extern enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
}
@@ -1470,9 +1471,15 @@
ConstantInt::get(Type::Int32Ty, Align)
};
- Intrinsic::ID IID =
- (IntPtr == Type::Int32Ty) ? Intrinsic::memcpy_i32 : Intrinsic::memcpy_i64;
- Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops, Ops+4);
+ if (!flag_no_builtin && !builtin_function_disabled_p("memcpy")) {
+ Intrinsic::ID IID =
+ (IntPtr == Type::Int32Ty) ? Intrinsic::memcpy_i32 : Intrinsic::memcpy_i64;
+ Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops, Ops + 4);
+ } else {
+ Builder.CreateCall(TheModule->getOrInsertFunction("memcpy", SBP, SBP, SBP,
+ IntPtr, (Type*)0),
+ Ops, Ops + 3);
+ }
}
void TreeToLLVM::EmitMemMove(Value *DestPtr, Value *SrcPtr, Value *Size,
@@ -1486,9 +1493,16 @@
ConstantInt::get(Type::Int32Ty, Align)
};
- Intrinsic::ID IID =
- (IntPtr == Type::Int32Ty) ? Intrinsic::memmove_i32 : Intrinsic::memmove_i64;
- Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops, Ops+4);
+ if (!flag_no_builtin && !builtin_function_disabled_p("memmove")) {
+ Intrinsic::ID IID =
+ (IntPtr == Type::Int32Ty) ?
+ Intrinsic::memmove_i32 : Intrinsic::memmove_i64;
+ Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops, Ops + 4);
+ } else {
+ Builder.CreateCall(TheModule->getOrInsertFunction("memmove", SBP, SBP, SBP,
+ IntPtr, (Type*)0),
+ Ops, Ops + 3);
+ }
}
void TreeToLLVM::EmitMemSet(Value *DestPtr, Value *SrcVal, Value *Size,
@@ -1502,13 +1516,18 @@
ConstantInt::get(Type::Int32Ty, Align)
};
- Intrinsic::ID IID =
- (IntPtr == Type::Int32Ty) ? Intrinsic::memset_i32 : Intrinsic::memset_i64;
-
- Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops, Ops+4);
+ if (!flag_no_builtin && !builtin_function_disabled_p("memset")) {
+ Intrinsic::ID IID =
+ (IntPtr == Type::Int32Ty) ? Intrinsic::memset_i32 : Intrinsic::memset_i64;
+ Builder.CreateCall(Intrinsic::getDeclaration(TheModule, IID), Ops, Ops + 4);
+ } else {
+ Builder.CreateCall(TheModule->getOrInsertFunction("memset", SBP, SBP,
+ Type::Int8Ty, IntPtr,
+ (Type*)0),
+ Ops, Ops + 3);
+ }
}
-
// Emits code to do something for a type attribute
void TreeToLLVM::EmitTypeGcroot(Value *V, tree decl) {
// GC intrinsics can only be used in functions which specify a collector.
@@ -5039,24 +5058,88 @@
}
bool TreeToLLVM::EmitBuiltinUnaryOp(Value *InVal, Value *&Result,
- Intrinsic::ID Id) {
+ Intrinsic::ID Id) {
// The intrinsic might be overloaded in which case the argument is of
// varying type. Make sure that we specify the actual type for "iAny"
// by passing it as the 3rd and 4th parameters. This isn't needed for
// most intrinsics, but is needed for ctpop, cttz, ctlz.
const Type *Ty = InVal->getType();
- Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule, Id, &Ty, 1),
- InVal);
+ const char *Name = 0;
+
+#define CASE(ID, NAME) \
+ case Intrinsic::ID: \
+ if (flag_no_builtin || builtin_function_disabled_p(NAME)) \
+ Name = NAME; \
+ break
+
+ if (Ty == Type::DoubleTy) {
+ switch (Id) {
+ default: break;
+ CASE(log, "log");
+ CASE(log2, "log2");
+ CASE(log10, "log10");
+ CASE(exp, "exp");
+ CASE(exp2, "exp2");
+ }
+ } else if (Ty == Type::FloatTy) {
+ switch (Id) {
+ default: break;
+ CASE(log, "logf");
+ CASE(log2, "log2f");
+ CASE(log10, "log10f");
+ CASE(exp, "expf");
+ CASE(exp2, "exp2f");
+ }
+ } else {
+ switch (Id) {
+ default: break;
+ CASE(log, "logl");
+ CASE(log2, "log2l");
+ CASE(log10, "log10l");
+ CASE(exp, "expl");
+ CASE(exp2, "exp2l");
+ }
+ }
+
+#undef CASE
+
+ if (!Name)
+ Result = Builder.CreateCall(Intrinsic::getDeclaration(TheModule, Id,
+ &Ty, 1),
+ InVal);
+ else
+ Result = Builder.CreateCall(TheModule->getOrInsertFunction(Name, Ty, Ty,
+ NULL),
+ InVal);
+
return true;
}
Value *TreeToLLVM::EmitBuiltinSQRT(tree exp) {
Value *Amt = Emit(TREE_VALUE(TREE_OPERAND(exp, 1)), 0);
const Type* Ty = Amt->getType();
-
- return Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
- Intrinsic::sqrt, &Ty, 1),
- Amt);
+ const char *Name = 0;
+
+ if (Ty == Type::DoubleTy) {
+ if (flag_no_builtin || builtin_function_disabled_p("sqrt"))
+ Name = "sqrt";
+ } else if (Ty == Type::FloatTy) {
+ if (flag_no_builtin || builtin_function_disabled_p("sqrtf"))
+ Name = "sqrtf";
+ } else {
+ if (flag_no_builtin || builtin_function_disabled_p("sqrtl"))
+ Name = "sqrtl";
+ }
+
+ if (!Name)
+ return Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+ Intrinsic::sqrt,
+ &Ty, 1),
+ Amt);
+ else
+ return Builder.CreateCall(TheModule->getOrInsertFunction(Name, Ty, Ty,
+ NULL),
+ Amt);
}
Value *TreeToLLVM::EmitBuiltinPOWI(tree exp) {
@@ -5072,9 +5155,30 @@
SmallVector<Value *,2> Args;
Args.push_back(Val);
Args.push_back(Pow);
- return Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
- Intrinsic::powi, &Ty, 1),
- Args.begin(), Args.end());
+
+ const char *Name = 0;
+
+ if (Ty == Type::DoubleTy) {
+ if (flag_no_builtin || builtin_function_disabled_p("powi"))
+ Name = "powi";
+ } else if (Ty == Type::FloatTy) {
+ if (flag_no_builtin || builtin_function_disabled_p("powif"))
+ Name = "powif";
+ } else {
+ if (flag_no_builtin || builtin_function_disabled_p("powil"))
+ Name = "powil";
+ }
+
+ if (!Name)
+ return Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+ Intrinsic::powi,
+ &Ty, 1),
+ Args.begin(), Args.end());
+ else
+ return Builder.CreateCall(TheModule->getOrInsertFunction(Name, Ty, Ty,
+ Type::Int32Ty,
+ NULL),
+ Args.begin(), Args.end());
}
Value *TreeToLLVM::EmitBuiltinPOW(tree exp) {
@@ -5089,9 +5193,29 @@
SmallVector<Value *,2> Args;
Args.push_back(Val);
Args.push_back(Pow);
- return Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
- Intrinsic::pow, &Ty, 1),
- Args.begin(), Args.end());
+
+ const char *Name = 0;
+
+ if (Ty == Type::DoubleTy) {
+ if (flag_no_builtin || builtin_function_disabled_p("pow"))
+ Name = "pow";
+ } else if (Ty == Type::FloatTy) {
+ if (flag_no_builtin || builtin_function_disabled_p("powf"))
+ Name = "powf";
+ } else {
+ if (flag_no_builtin || builtin_function_disabled_p("powl"))
+ Name = "powl";
+ }
+
+ if (!Name)
+ return Builder.CreateCall(Intrinsic::getDeclaration(TheModule,
+ Intrinsic::pow, &Ty, 1),
+ Args.begin(), Args.end());
+ else
+ return Builder.CreateCall(TheModule->getOrInsertFunction(Name, Ty, Ty,
+ Type::Int32Ty,
+ NULL),
+ Args.begin(), Args.end());
}
bool TreeToLLVM::EmitBuiltinConstantP(tree exp, Value *&Result) {
More information about the llvm-commits
mailing list