forked from OSchip/llvm-project
Reapply patch for adding support for address spaces and added a isVolatile field to memcpy, memmove, and memset.
llvm-svn: 100305
This commit is contained in:
parent
c576ee9040
commit
cc2ab0cdc9
|
@ -338,38 +338,50 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
|
|||
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: {
|
||||
|
|
|
@ -564,11 +564,15 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
|
|||
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 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
|
|||
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);
|
||||
|
|
|
@ -771,12 +771,27 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
|
|||
// 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));
|
||||
}
|
||||
|
|
|
@ -495,12 +495,14 @@ void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) {
|
|||
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) {
|
||||
|
|
|
@ -47,8 +47,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
|
|||
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::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,
|
|||
(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::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() {
|
||||
if (MemMoveFn) return MemMoveFn;
|
||||
const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
|
||||
return MemMoveFn = getIntrinsic(llvm::Intrinsic::memmove, &IntPtr, 1);
|
||||
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() {
|
||||
if (MemSetFn) return MemSetFn;
|
||||
const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
|
||||
return MemSetFn = getIntrinsic(llvm::Intrinsic::memset, &IntPtr, 1);
|
||||
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*> &
|
||||
|
|
|
@ -97,10 +97,6 @@ class CodeGenModule : public BlockModule {
|
|||
|
||||
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
|
||||
|
@ -290,9 +286,17 @@ public:
|
|||
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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -15,7 +15,7 @@ void test1() {
|
|||
// 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
|
||||
|
||||
|
|
|
@ -93,6 +93,6 @@ A* t10() {
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ void test_value_init() {
|
|||
// 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
|
||||
|
|
Loading…
Reference in New Issue