[cfe-commits] r53888 - in /cfe/trunk: include/clang/AST/Builtins.def lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtin-memfns.c
Daniel Dunbar
daniel at zuster.org
Mon Jul 21 17:26:46 PDT 2008
Author: ddunbar
Date: Mon Jul 21 19:26:45 2008
New Revision: 53888
URL: http://llvm.org/viewvc/llvm-project?rev=53888&view=rev
Log:
Implement bzero, memset, memmove builtins.
This subsumes Nico Weber's patch and implements bzero in terms
of llvm.memset to match llvm-gcc.
Added:
cfe/trunk/test/CodeGen/builtin-memfns.c
Modified:
cfe/trunk/include/clang/AST/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
Modified: cfe/trunk/include/clang/AST/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.def?rev=53888&r1=53887&r2=53888&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.def (original)
+++ cfe/trunk/include/clang/AST/Builtins.def Mon Jul 21 19:26:45 2008
@@ -117,7 +117,10 @@
BUILTIN(__builtin_va_end, "va&", "n")
BUILTIN(__builtin_va_copy, "va&a", "n")
BUILTIN(__builtin_stdarg_start, "va&a", "n")
+BUILTIN(__builtin_bzero, "vv*z", "n")
BUILTIN(__builtin_memcpy, "v*v*vC*z", "n")
+BUILTIN(__builtin_memmove, "v*v*vC*z", "n")
+BUILTIN(__builtin_memset, "v*v*cz", "n")
BUILTIN(__builtin_return_address, "v*Ui", "n")
BUILTIN(__builtin_frame_address, "v*Ui", "n")
// GCC Object size checking builtins
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=53888&r1=53887&r2=53888&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Jul 21 19:26:45 2008
@@ -291,18 +291,39 @@
// FIXME: LLVM IR Should allow alloca with an i64 size!
Value *Size = EmitScalarExpr(E->getArg(0));
Size = Builder.CreateIntCast(Size, llvm::Type::Int32Ty, false, "tmp");
- return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size,
- "tmp"));
+ return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size, "tmp"));
+ }
+ case Builtin::BI__builtin_bzero: {
+ Value *Address = EmitScalarExpr(E->getArg(0));
+ Builder.CreateCall4(CGM.getMemSetFn(), Address,
+ llvm::ConstantInt::get(llvm::Type::Int8Ty, 0),
+ EmitScalarExpr(E->getArg(1)),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
+ return RValue::get(Address);
}
case Builtin::BI__builtin_memcpy: {
- Value* MemCpyOps[4] = {
- EmitScalarExpr(E->getArg(0)),
- EmitScalarExpr(E->getArg(1)),
- EmitScalarExpr(E->getArg(2)),
- llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)
- };
- Builder.CreateCall(CGM.getMemCpyFn(), MemCpyOps, MemCpyOps+4);
- return RValue::get(MemCpyOps[0]);
+ Value *Address = EmitScalarExpr(E->getArg(0));
+ Builder.CreateCall4(CGM.getMemCpyFn(), Address,
+ EmitScalarExpr(E->getArg(1)),
+ EmitScalarExpr(E->getArg(2)),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
+ return RValue::get(Address);
+ }
+ case Builtin::BI__builtin_memmove: {
+ Value *Address = EmitScalarExpr(E->getArg(0));
+ Builder.CreateCall4(CGM.getMemMoveFn(), Address,
+ EmitScalarExpr(E->getArg(1)),
+ EmitScalarExpr(E->getArg(2)),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
+ return RValue::get(Address);
+ }
+ case Builtin::BI__builtin_memset: {
+ Value *Address = EmitScalarExpr(E->getArg(0));
+ Builder.CreateCall4(CGM.getMemSetFn(), Address,
+ EmitScalarExpr(E->getArg(1)),
+ EmitScalarExpr(E->getArg(2)),
+ llvm::ConstantInt::get(llvm::Type::Int32Ty, 1));
+ return RValue::get(Address);
}
case Builtin::BI__builtin_return_address: {
Value *F = CGM.getIntrinsic(Intrinsic::returnaddress, 0, 0);
Added: cfe/trunk/test/CodeGen/builtin-memfns.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-memfns.c?rev=53888&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-memfns.c (added)
+++ cfe/trunk/test/CodeGen/builtin-memfns.c Mon Jul 21 19:26:45 2008
@@ -0,0 +1,11 @@
+// RUN: clang -emit-llvm -o - %s | not grep __builtin
+
+int main(int argc, char **argv) {
+ unsigned char a = 0x11223344;
+ unsigned char b = 0x11223344;
+ __builtin_bzero(&a, sizeof(a));
+ __builtin_memset(&a, 0, sizeof(a));
+ __builtin_memcpy(&a, &b, sizeof(a));
+ __builtin_memmove(&a, &b, sizeof(a));
+ return 0;
+}
More information about the cfe-commits
mailing list