[cfe-commits] r44254 - in /cfe/trunk: CodeGen/CGBuiltin.cpp include/clang/AST/Builtins.def
Anders Carlsson
andersca at mac.com
Tue Nov 20 11:05:26 PST 2007
Author: andersca
Date: Tue Nov 20 13:05:17 2007
New Revision: 44254
URL: http://llvm.org/viewvc/llvm-project?rev=44254&view=rev
Log:
Add __builtin_abs
Modified:
cfe/trunk/CodeGen/CGBuiltin.cpp
cfe/trunk/include/clang/AST/Builtins.def
Modified: cfe/trunk/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/CGBuiltin.cpp?rev=44254&r1=44253&r2=44254&view=diff
==============================================================================
--- cfe/trunk/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/CodeGen/CGBuiltin.cpp Tue Nov 20 13:05:17 2007
@@ -85,6 +85,18 @@
return RValue::get(llvm::ConstantInt::get(Result));
}
+ case Builtin::BI__builtin_abs: {
+ llvm::Value *ArgValue = EmitScalarExpr(E->getArg(0));
+
+ llvm::BinaryOperator *NegOp =
+ Builder.CreateNeg(ArgValue, (ArgValue->getName() + "neg").c_str());
+ llvm::Value *CmpResult =
+ Builder.CreateICmpSGE(ArgValue, NegOp->getOperand(0), "abscond");
+ llvm::Value *Result =
+ Builder.CreateSelect(CmpResult, ArgValue, NegOp, "abs");
+
+ return RValue::get(Result);
+ }
}
return RValue::get(0);
Modified: cfe/trunk/include/clang/AST/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.def?rev=44254&r1=44253&r2=44254&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.def (original)
+++ cfe/trunk/include/clang/AST/Builtins.def Tue Nov 20 13:05:17 2007
@@ -55,6 +55,7 @@
BUILTIN(__builtin_inf , "d" , "ncF")
BUILTIN(__builtin_inff , "f" , "ncF")
BUILTIN(__builtin_infl , "Ld" , "ncF")
+BUILTIN(__builtin_abs , "ii" , "ncF")
BUILTIN(__builtin_fabs , "dd" , "ncF")
BUILTIN(__builtin_fabsf, "ff" , "ncF")
BUILTIN(__builtin_fabsl, "LdLd", "ncF")
More information about the cfe-commits
mailing list