[cfe-commits] r99930 - in /cfe/trunk: lib/CodeGen/CGBuiltin.cpp lib/CodeGen/CGDecl.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h test/CodeGen/builtin-memfns.c test/CodeGenCXX/eh.cpp test/CodeGenCXX/new.cpp test/CodeGenCXX/value-init.cpp
Mon P Wang
wangmp at apple.com
Tue Mar 30 14:02:45 PDT 2010
Author: wangmp
Date: Tue Mar 30 16:02:45 2010
New Revision: 99930
URL: http://llvm.org/viewvc/llvm-project?rev=99930&view=rev
Log:
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset
Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGen/builtin-memfns.c
cfe/trunk/test/CodeGenCXX/eh.cpp
cfe/trunk/test/CodeGenCXX/new.cpp
cfe/trunk/test/CodeGenCXX/value-init.cpp
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Mar 30 16:02:45 2010
@@ -338,38 +338,50 @@
case Builtin::BIbzero:
case Builtin::BI__builtin_bzero: {
Value *Address = EmitScalarExpr(E->getArg(0));
- Builder.CreateCall4(CGM.getMemSetFn(), Address,
- llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0),
- EmitScalarExpr(E->getArg(1)),
- llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
+ Value *SizeVal = EmitScalarExpr(E->getArg(1));
+ Builder.CreateCall5(CGM.getMemSetFn(Address->getType(), SizeVal->getType()),
+ Address,
+ llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0),
+ SizeVal,
+ llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1),
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0));
return RValue::get(Address);
}
case Builtin::BImemcpy:
case Builtin::BI__builtin_memcpy: {
Value *Address = EmitScalarExpr(E->getArg(0));
- Builder.CreateCall4(CGM.getMemCpyFn(), Address,
- EmitScalarExpr(E->getArg(1)),
- EmitScalarExpr(E->getArg(2)),
- llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
+ Value *SrcAddr = EmitScalarExpr(E->getArg(1));
+ Value *SizeVal = EmitScalarExpr(E->getArg(2));
+ Builder.CreateCall5(CGM.getMemCpyFn(Address->getType(), SrcAddr->getType(),
+ SizeVal->getType()),
+ Address, SrcAddr, SizeVal,
+ llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1),
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0));
return RValue::get(Address);
}
case Builtin::BImemmove:
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::getInt32Ty(VMContext), 1));
+ Value *SrcAddr = EmitScalarExpr(E->getArg(1));
+ Value *SizeVal = EmitScalarExpr(E->getArg(2));
+ Builder.CreateCall5(CGM.getMemMoveFn(Address->getType(), SrcAddr->getType(),
+ SizeVal->getType()),
+ Address, SrcAddr, SizeVal,
+ llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1),
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0));
return RValue::get(Address);
}
case Builtin::BImemset:
case Builtin::BI__builtin_memset: {
Value *Address = EmitScalarExpr(E->getArg(0));
- Builder.CreateCall4(CGM.getMemSetFn(), Address,
- Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
- llvm::Type::getInt8Ty(VMContext)),
- EmitScalarExpr(E->getArg(2)),
- llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
+ Value *SizeVal = EmitScalarExpr(E->getArg(2));
+ Builder.CreateCall5(CGM.getMemSetFn(Address->getType(), SizeVal->getType()),
+ Address,
+ Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
+ llvm::Type::getInt8Ty(VMContext)),
+ SizeVal,
+ llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1),
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0));
return RValue::get(Address);
}
case Builtin::BI__builtin_dwarf_cfa: {
Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Mar 30 16:02:45 2010
@@ -564,11 +564,15 @@
if (Loc->getType() != BP)
Loc = Builder.CreateBitCast(Loc, BP, "tmp");
+ llvm::Value *NotVolatile =
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0);
+
// If the initializer is all zeros, codegen with memset.
if (isa<llvm::ConstantAggregateZero>(Init)) {
llvm::Value *Zero =
- llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0);
- Builder.CreateCall4(CGM.getMemSetFn(), Loc, Zero, SizeVal, AlignVal);
+ llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0);
+ Builder.CreateCall5(CGM.getMemSetFn(Loc->getType(), SizeVal->getType()),
+ Loc, Zero, SizeVal, AlignVal, NotVolatile);
} else {
// Otherwise, create a temporary global with the initializer then
// memcpy from the global to the alloca.
@@ -582,8 +586,10 @@
llvm::Value *SrcPtr = GV;
if (SrcPtr->getType() != BP)
SrcPtr = Builder.CreateBitCast(SrcPtr, BP, "tmp");
-
- Builder.CreateCall4(CGM.getMemCpyFn(), Loc, SrcPtr, SizeVal, AlignVal);
+
+ Builder.CreateCall5(CGM.getMemCpyFn(Loc->getType(), SrcPtr->getType(),
+ SizeVal->getType()),
+ Loc, SrcPtr, SizeVal, AlignVal, NotVolatile);
}
} else if (Ty->isReferenceType()) {
RValue RV = EmitReferenceBindingToExpr(Init, /*IsInitializer=*/true);
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Tue Mar 30 16:02:45 2010
@@ -771,12 +771,27 @@
// a = b;
// }
//
- // we need to use a differnt call here. We use isVolatile to indicate when
+ // we need to use a different call here. We use isVolatile to indicate when
// either the source or the destination is volatile.
- Builder.CreateCall4(CGM.getMemCpyFn(),
+ const llvm::Type *I1Ty = llvm::Type::getInt1Ty(VMContext);
+ const llvm::Type *I8Ty = llvm::Type::getInt8Ty(VMContext);
+ const llvm::Type *I32Ty = llvm::Type::getInt32Ty(VMContext);
+
+ const llvm::PointerType *DPT = cast<llvm::PointerType>(DestPtr->getType());
+ const llvm::Type *DBP = llvm::PointerType::get(I8Ty, DPT->getAddressSpace());
+ if (DestPtr->getType() != DBP)
+ DestPtr = Builder.CreateBitCast(DestPtr, DBP, "tmp");
+
+ const llvm::PointerType *SPT = cast<llvm::PointerType>(SrcPtr->getType());
+ const llvm::Type *SBP = llvm::PointerType::get(I8Ty, SPT->getAddressSpace());
+ if (SrcPtr->getType() != SBP)
+ SrcPtr = Builder.CreateBitCast(SrcPtr, SBP, "tmp");
+
+ Builder.CreateCall5(CGM.getMemCpyFn(DestPtr->getType(), SrcPtr->getType(),
+ IntPtr),
DestPtr, SrcPtr,
// TypeInfo.first describes size in bits.
llvm::ConstantInt::get(IntPtr, TypeInfo.first/8),
- llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
- TypeInfo.second/8));
+ llvm::ConstantInt::get(I32Ty, TypeInfo.second/8),
+ llvm::ConstantInt::get(I1Ty, isVolatile));
}
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.cpp Tue Mar 30 16:02:45 2010
@@ -495,12 +495,14 @@
const llvm::Type *IntPtr = llvm::IntegerType::get(VMContext,
LLVMPointerWidth);
- Builder.CreateCall4(CGM.getMemSetFn(), DestPtr,
+ Builder.CreateCall5(CGM.getMemSetFn(BP, IntPtr), DestPtr,
llvm::Constant::getNullValue(llvm::Type::getInt8Ty(VMContext)),
// TypeInfo.first describes size in bits.
llvm::ConstantInt::get(IntPtr, TypeInfo.first/8),
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
- TypeInfo.second/8));
+ TypeInfo.second/8),
+ llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext),
+ 0));
}
llvm::BlockAddress *CodeGenFunction::GetAddrOfLabel(const LabelStmt *L) {
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Mar 30 16:02:45 2010
@@ -47,8 +47,7 @@
Features(C.getLangOptions()), CodeGenOpts(CGO), TheModule(M),
TheTargetData(TD), TheTargetCodeGenInfo(0), Diags(diags),
Types(C, M, TD, getTargetCodeGenInfo().getABIInfo()),
- MangleCtx(C), VTables(*this), Runtime(0),
- MemCpyFn(0), MemMoveFn(0), MemSetFn(0), CFConstantStringClassRef(0),
+ MangleCtx(C), VTables(*this), Runtime(0), CFConstantStringClassRef(0),
VMContext(M.getContext()) {
if (!Features.ObjC1)
@@ -1414,22 +1413,25 @@
(llvm::Intrinsic::ID)IID, Tys, NumTys);
}
-llvm::Function *CodeGenModule::getMemCpyFn() {
- if (MemCpyFn) return MemCpyFn;
- const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
- return MemCpyFn = getIntrinsic(llvm::Intrinsic::memcpy, &IntPtr, 1);
-}
-
-llvm::Function *CodeGenModule::getMemMoveFn() {
- if (MemMoveFn) return MemMoveFn;
- const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
- return MemMoveFn = getIntrinsic(llvm::Intrinsic::memmove, &IntPtr, 1);
-}
-
-llvm::Function *CodeGenModule::getMemSetFn() {
- if (MemSetFn) return MemSetFn;
- const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
- return MemSetFn = getIntrinsic(llvm::Intrinsic::memset, &IntPtr, 1);
+
+llvm::Function *CodeGenModule::getMemCpyFn(const llvm::Type *DestType,
+ const llvm::Type *SrcType,
+ const llvm::Type *SizeType) {
+ const llvm::Type *ArgTypes[3] = {DestType, SrcType, SizeType };
+ return getIntrinsic(llvm::Intrinsic::memcpy, ArgTypes, 3);
+}
+
+llvm::Function *CodeGenModule::getMemMoveFn(const llvm::Type *DestType,
+ const llvm::Type *SrcType,
+ const llvm::Type *SizeType) {
+ const llvm::Type *ArgTypes[3] = {DestType, SrcType, SizeType };
+ return getIntrinsic(llvm::Intrinsic::memmove, ArgTypes, 3);
+}
+
+llvm::Function *CodeGenModule::getMemSetFn(const llvm::Type *DestType,
+ const llvm::Type *SizeType) {
+ const llvm::Type *ArgTypes[2] = { DestType, SizeType };
+ return getIntrinsic(llvm::Intrinsic::memset, ArgTypes, 2);
}
static llvm::StringMapEntry<llvm::Constant*> &
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Tue Mar 30 16:02:45 2010
@@ -98,10 +98,6 @@
CGObjCRuntime* Runtime;
CGDebugInfo* DebugInfo;
-
- llvm::Function *MemCpyFn;
- llvm::Function *MemMoveFn;
- llvm::Function *MemSetFn;
// WeakRefReferences - A set of references that have only been seen via
// a weakref so far. This is used to remove the weak of the reference if we ever
@@ -291,9 +287,17 @@
llvm::Value *getBuiltinLibFunction(const FunctionDecl *FD,
unsigned BuiltinID);
- llvm::Function *getMemCpyFn();
- llvm::Function *getMemMoveFn();
- llvm::Function *getMemSetFn();
+ llvm::Function *getMemCpyFn(const llvm::Type *DestType,
+ const llvm::Type *SrcType,
+ const llvm::Type *SizeType);
+
+ llvm::Function *getMemMoveFn(const llvm::Type *DestType,
+ const llvm::Type *SrcType,
+ const llvm::Type *SizeType);
+
+ llvm::Function *getMemSetFn(const llvm::Type *DestType,
+ const llvm::Type *SizeType);
+
llvm::Function *getIntrinsic(unsigned IID, const llvm::Type **Tys = 0,
unsigned NumTys = 0);
Modified: cfe/trunk/test/CodeGen/builtin-memfns.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-memfns.c?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-memfns.c (original)
+++ cfe/trunk/test/CodeGen/builtin-memfns.c Tue Mar 30 16:02:45 2010
@@ -1,9 +1,11 @@
-// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o %t %s
-// RUN: grep '@llvm.memset.i32' %t
-// RUN: grep '@llvm.memcpy.i32' %t
-// RUN: grep '@llvm.memmove.i32' %t
-// RUN: grep __builtin %t | count 0
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm < %s| FileCheck %s
+// CHECK: call void @llvm.memset.p0i8.i32
+// CHECK: call void @llvm.memset.p0i8.i32
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i32
+// CHECK: call void @llvm.memmove.p0i8.p0i8.i32
+// CHECK-NOT: __builtin
+// CHECK: ret
int main(int argc, char **argv) {
unsigned char a = 0x11223344;
unsigned char b = 0x11223344;
Modified: cfe/trunk/test/CodeGenCXX/eh.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/eh.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/eh.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/eh.cpp Tue Mar 30 16:02:45 2010
@@ -15,7 +15,7 @@
// CHECK-NEXT: store i8* %{{exception|2}}, i8** %{{exception.ptr|1}}
// CHECK-NEXT: %{{0|3}} = bitcast i8* %{{exception|2}} to %struct.test1_D*
// CHECK-NEXT: %{{tmp|4}} = bitcast %struct.test1_D* %{{0|3}} to i8*
-// CHECK-NEXT: call void @llvm.memcpy.i64(i8* %{{tmp|4}}, i8* bitcast (%struct.test1_D* @d1 to i8*), i64 8, i32 8)
+// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{tmp|4}}, i8* bitcast (%struct.test1_D* @d1 to i8*), i64 8, i32 8, i1 false)
// CHECK-NEXT: call void @__cxa_throw(i8* %{{exception|2}}, i8* bitcast (%0* @_ZTI7test1_D to i8*), i8* null) noreturn
// CHECK-NEXT: unreachable
Modified: cfe/trunk/test/CodeGenCXX/new.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/new.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/new.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/new.cpp Tue Mar 30 16:02:45 2010
@@ -93,6 +93,6 @@
struct B { };
void t11() {
// CHECK: call noalias i8* @_Znwm
- // CHECK: call void @llvm.memset.i64(
+ // CHECK: call void @llvm.memset.p0i8.i64(
B* b = new B();
}
Modified: cfe/trunk/test/CodeGenCXX/value-init.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/value-init.cpp?rev=99930&r1=99929&r2=99930&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/value-init.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/value-init.cpp Tue Mar 30 16:02:45 2010
@@ -18,7 +18,7 @@
// PR5800
// CHECK: store i32 17
- // CHECK: call void @llvm.memset.i64
+ // CHECK: call void @llvm.memset.p0i8.i64
// CHECK: call void @_ZN1BC1Ev
C c = { 17 } ;
// CHECK: call void @_ZN1CD1Ev
More information about the cfe-commits
mailing list