Update for LLVM API change.

llvm-svn: 78946
This commit is contained in:
Owen Anderson 2009-08-13 21:57:51 +00:00
parent 3d693b22df
commit 41a750271b
20 changed files with 367 additions and 304 deletions

View File

@ -265,7 +265,7 @@ llvm::Value *CodeGenFunction::BuildBlockLiteralTmp(const BlockExpr *BE) {
llvm::Value *BlockLiteral = LoadBlockStruct(); llvm::Value *BlockLiteral = LoadBlockStruct();
Loc = Builder.CreateGEP(BlockLiteral, Loc = Builder.CreateGEP(BlockLiteral,
llvm::ConstantInt::get(llvm::Type::Int64Ty, llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
offset), offset),
"block.literal"); "block.literal");
Ty = llvm::PointerType::get(Ty, 0); Ty = llvm::PointerType::get(Ty, 0);
@ -406,7 +406,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E) {
BlockLiteral = BlockLiteral =
Builder.CreateBitCast(BlockLiteral, Builder.CreateBitCast(BlockLiteral,
llvm::PointerType::getUnqual(llvm::Type::Int8Ty), llvm::PointerType::getUnqual(
llvm::Type::getInt8Ty(VMContext)),
"tmp"); "tmp");
// Add the block literal. // Add the block literal.
@ -456,7 +457,7 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const BlockDeclRefExpr *E) {
llvm::Value *BlockLiteral = LoadBlockStruct(); llvm::Value *BlockLiteral = LoadBlockStruct();
llvm::Value *V = Builder.CreateGEP(BlockLiteral, llvm::Value *V = Builder.CreateGEP(BlockLiteral,
llvm::ConstantInt::get(llvm::Type::Int64Ty, llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
offset), offset),
"block.literal"); "block.literal");
if (E->isByRef()) { if (E->isByRef()) {
@ -688,7 +689,7 @@ uint64_t BlockFunction::getBlockOffset(const BlockDeclRefExpr *BDRE) {
uint64_t Pad = BlockOffset - OldOffset; uint64_t Pad = BlockOffset - OldOffset;
if (Pad) { if (Pad) {
llvm::ArrayType::get(llvm::Type::Int8Ty, Pad); llvm::ArrayType::get(llvm::Type::getInt8Ty(VMContext), Pad);
QualType PadTy = getContext().getConstantArrayType(getContext().CharTy, QualType PadTy = getContext().getConstantArrayType(getContext().CharTy,
llvm::APInt(32, Pad), llvm::APInt(32, Pad),
ArrayType::Normal, 0); ArrayType::Normal, 0);
@ -777,7 +778,8 @@ GenerateCopyHelperFunction(bool BlockHasCopyDispose, const llvm::StructType *T,
llvm::Value *Dstv = Builder.CreateStructGEP(DstObj, index); llvm::Value *Dstv = Builder.CreateStructGEP(DstObj, index);
Dstv = Builder.CreateBitCast(Dstv, PtrToInt8Ty); Dstv = Builder.CreateBitCast(Dstv, PtrToInt8Ty);
llvm::Value *N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag); llvm::Value *N = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(T->getContext()), flag);
llvm::Value *F = getBlockObjectAssign(); llvm::Value *F = getBlockObjectAssign();
Builder.CreateCall3(F, Dstv, Srcv, N); Builder.CreateCall3(F, Dstv, Srcv, N);
} }
@ -928,7 +930,8 @@ GeneratebyrefCopyHelperFunction(const llvm::Type *T, int flag) {
flag |= BLOCK_BYREF_CALLER; flag |= BLOCK_BYREF_CALLER;
llvm::Value *N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag); llvm::Value *N = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(T->getContext()), flag);
llvm::Value *F = getBlockObjectAssign(); llvm::Value *F = getBlockObjectAssign();
Builder.CreateCall3(F, DstObj, SrcObj, N); Builder.CreateCall3(F, DstObj, SrcObj, N);
@ -1025,9 +1028,9 @@ llvm::Value *BlockFunction::getBlockObjectDispose() {
if (CGM.BlockObjectDispose == 0) { if (CGM.BlockObjectDispose == 0) {
const llvm::FunctionType *FTy; const llvm::FunctionType *FTy;
std::vector<const llvm::Type*> ArgTys; std::vector<const llvm::Type*> ArgTys;
const llvm::Type *ResultType = llvm::Type::VoidTy; const llvm::Type *ResultType = llvm::Type::getVoidTy(VMContext);
ArgTys.push_back(PtrToInt8Ty); ArgTys.push_back(PtrToInt8Ty);
ArgTys.push_back(llvm::Type::Int32Ty); ArgTys.push_back(llvm::Type::getInt32Ty(VMContext));
FTy = llvm::FunctionType::get(ResultType, ArgTys, false); FTy = llvm::FunctionType::get(ResultType, ArgTys, false);
CGM.BlockObjectDispose CGM.BlockObjectDispose
= CGM.CreateRuntimeFunction(FTy, "_Block_object_dispose"); = CGM.CreateRuntimeFunction(FTy, "_Block_object_dispose");
@ -1039,10 +1042,10 @@ llvm::Value *BlockFunction::getBlockObjectAssign() {
if (CGM.BlockObjectAssign == 0) { if (CGM.BlockObjectAssign == 0) {
const llvm::FunctionType *FTy; const llvm::FunctionType *FTy;
std::vector<const llvm::Type*> ArgTys; std::vector<const llvm::Type*> ArgTys;
const llvm::Type *ResultType = llvm::Type::VoidTy; const llvm::Type *ResultType = llvm::Type::getVoidTy(VMContext);
ArgTys.push_back(PtrToInt8Ty); ArgTys.push_back(PtrToInt8Ty);
ArgTys.push_back(PtrToInt8Ty); ArgTys.push_back(PtrToInt8Ty);
ArgTys.push_back(llvm::Type::Int32Ty); ArgTys.push_back(llvm::Type::getInt32Ty(VMContext));
FTy = llvm::FunctionType::get(ResultType, ArgTys, false); FTy = llvm::FunctionType::get(ResultType, ArgTys, false);
CGM.BlockObjectAssign CGM.BlockObjectAssign
= CGM.CreateRuntimeFunction(FTy, "_Block_object_assign"); = CGM.CreateRuntimeFunction(FTy, "_Block_object_assign");
@ -1054,7 +1057,7 @@ void BlockFunction::BuildBlockRelease(llvm::Value *V, int flag) {
llvm::Value *F = getBlockObjectDispose(); llvm::Value *F = getBlockObjectDispose();
llvm::Value *N; llvm::Value *N;
V = Builder.CreateBitCast(V, PtrToInt8Ty); V = Builder.CreateBitCast(V, PtrToInt8Ty);
N = llvm::ConstantInt::get(llvm::Type::Int32Ty, flag); N = llvm::ConstantInt::get(llvm::Type::getInt32Ty(V->getContext()), flag);
Builder.CreateCall2(F, V, N); Builder.CreateCall2(F, V, N);
} }
@ -1063,7 +1066,8 @@ ASTContext &BlockFunction::getContext() const { return CGM.getContext(); }
BlockFunction::BlockFunction(CodeGenModule &cgm, CodeGenFunction &cgf, BlockFunction::BlockFunction(CodeGenModule &cgm, CodeGenFunction &cgf,
CGBuilderTy &B) CGBuilderTy &B)
: CGM(cgm), CGF(cgf), VMContext(cgm.getLLVMContext()), Builder(B) { : CGM(cgm), CGF(cgf), VMContext(cgm.getLLVMContext()), Builder(B) {
PtrToInt8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); PtrToInt8Ty = llvm::PointerType::getUnqual(
llvm::Type::getInt8Ty(VMContext));
BlockHasCopyDispose = false; BlockHasCopyDispose = false;
} }

View File

@ -112,7 +112,8 @@ public:
GenericBlockLiteralType(0), GenericExtendedBlockLiteralType(0), GenericBlockLiteralType(0), GenericExtendedBlockLiteralType(0),
BlockObjectAssign(0), BlockObjectDispose(0) { BlockObjectAssign(0), BlockObjectDispose(0) {
Block.GlobalUniqueCount = 0; Block.GlobalUniqueCount = 0;
PtrToInt8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); PtrToInt8Ty = llvm::PointerType::getUnqual(
llvm::Type::getInt8Ty(M.getContext()));
} }
}; };

View File

@ -78,7 +78,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BI__builtin_va_end: { case Builtin::BI__builtin_va_end: {
Value *ArgValue = EmitVAListRef(E->getArg(0)); Value *ArgValue = EmitVAListRef(E->getArg(0));
const llvm::Type *DestType = const llvm::Type *DestType =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
if (ArgValue->getType() != DestType) if (ArgValue->getType() != DestType)
ArgValue = Builder.CreateBitCast(ArgValue, DestType, ArgValue = Builder.CreateBitCast(ArgValue, DestType,
ArgValue->getName().data()); ArgValue->getName().data());
@ -92,7 +92,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *SrcPtr = EmitVAListRef(E->getArg(1)); Value *SrcPtr = EmitVAListRef(E->getArg(1));
const llvm::Type *Type = const llvm::Type *Type =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
DstPtr = Builder.CreateBitCast(DstPtr, Type); DstPtr = Builder.CreateBitCast(DstPtr, Type);
SrcPtr = Builder.CreateBitCast(SrcPtr, Type); SrcPtr = Builder.CreateBitCast(SrcPtr, Type);
@ -214,9 +214,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0)); Value *Locality, *RW, *Address = EmitScalarExpr(E->getArg(0));
// FIXME: Technically these constants should of type 'int', yes? // FIXME: Technically these constants should of type 'int', yes?
RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) : RW = (E->getNumArgs() > 1) ? EmitScalarExpr(E->getArg(1)) :
llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0);
Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) : Locality = (E->getNumArgs() > 2) ? EmitScalarExpr(E->getArg(2)) :
llvm::ConstantInt::get(llvm::Type::Int32Ty, 3); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 3);
Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0); Value *F = CGM.getIntrinsic(Intrinsic::prefetch, 0, 0);
return RValue::get(Builder.CreateCall3(F, Address, RW, Locality)); return RValue::get(Builder.CreateCall3(F, Address, RW, Locality));
} }
@ -275,15 +275,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BI__builtin_alloca: { case Builtin::BI__builtin_alloca: {
// FIXME: LLVM IR Should allow alloca with an i64 size! // FIXME: LLVM IR Should allow alloca with an i64 size!
Value *Size = EmitScalarExpr(E->getArg(0)); Value *Size = EmitScalarExpr(E->getArg(0));
Size = Builder.CreateIntCast(Size, llvm::Type::Int32Ty, false, "tmp"); Size = Builder.CreateIntCast(Size, llvm::Type::getInt32Ty(VMContext), false, "tmp");
return RValue::get(Builder.CreateAlloca(llvm::Type::Int8Ty, Size, "tmp")); return RValue::get(Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext), Size, "tmp"));
} }
case Builtin::BI__builtin_bzero: { case Builtin::BI__builtin_bzero: {
Value *Address = EmitScalarExpr(E->getArg(0)); Value *Address = EmitScalarExpr(E->getArg(0));
Builder.CreateCall4(CGM.getMemSetFn(), Address, Builder.CreateCall4(CGM.getMemSetFn(), Address,
llvm::ConstantInt::get(llvm::Type::Int8Ty, 0), llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 0),
EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(1)),
llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
return RValue::get(Address); return RValue::get(Address);
} }
case Builtin::BI__builtin_memcpy: { case Builtin::BI__builtin_memcpy: {
@ -291,7 +291,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Builder.CreateCall4(CGM.getMemCpyFn(), Address, Builder.CreateCall4(CGM.getMemCpyFn(), Address,
EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(1)),
EmitScalarExpr(E->getArg(2)), EmitScalarExpr(E->getArg(2)),
llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
return RValue::get(Address); return RValue::get(Address);
} }
case Builtin::BI__builtin_memmove: { case Builtin::BI__builtin_memmove: {
@ -299,16 +299,16 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Builder.CreateCall4(CGM.getMemMoveFn(), Address, Builder.CreateCall4(CGM.getMemMoveFn(), Address,
EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(1)),
EmitScalarExpr(E->getArg(2)), EmitScalarExpr(E->getArg(2)),
llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
return RValue::get(Address); return RValue::get(Address);
} }
case Builtin::BI__builtin_memset: { case Builtin::BI__builtin_memset: {
Value *Address = EmitScalarExpr(E->getArg(0)); Value *Address = EmitScalarExpr(E->getArg(0));
Builder.CreateCall4(CGM.getMemSetFn(), Address, Builder.CreateCall4(CGM.getMemSetFn(), Address,
Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)), Builder.CreateTrunc(EmitScalarExpr(E->getArg(1)),
llvm::Type::Int8Ty), llvm::Type::getInt8Ty(VMContext)),
EmitScalarExpr(E->getArg(2)), EmitScalarExpr(E->getArg(2)),
llvm::ConstantInt::get(llvm::Type::Int32Ty, 1)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1));
return RValue::get(Address); return RValue::get(Address);
} }
case Builtin::BI__builtin_return_address: { case Builtin::BI__builtin_return_address: {
@ -335,12 +335,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *FrameAddrF = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0); Value *FrameAddrF = CGM.getIntrinsic(Intrinsic::frameaddress, 0, 0);
Value *FrameAddr = Value *FrameAddr =
Builder.CreateCall(FrameAddrF, Builder.CreateCall(FrameAddrF,
Constant::getNullValue(llvm::Type::Int32Ty)); Constant::getNullValue(llvm::Type::getInt32Ty(VMContext)));
Builder.CreateStore(FrameAddr, Buf); Builder.CreateStore(FrameAddr, Buf);
// Call the setjmp intrinsic // Call the setjmp intrinsic
Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp, 0, 0); Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_setjmp, 0, 0);
const llvm::Type *DestType = const llvm::Type *DestType =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Buf = Builder.CreateBitCast(Buf, DestType); Buf = Builder.CreateBitCast(Buf, DestType);
return RValue::get(Builder.CreateCall(F, Buf)); return RValue::get(Builder.CreateCall(F, Buf));
} }
@ -348,7 +348,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp, 0, 0); Value *F = CGM.getIntrinsic(Intrinsic::eh_sjlj_longjmp, 0, 0);
Value *Buf = EmitScalarExpr(E->getArg(0)); Value *Buf = EmitScalarExpr(E->getArg(0));
const llvm::Type *DestType = const llvm::Type *DestType =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Buf = Builder.CreateBitCast(Buf, DestType); Buf = Builder.CreateBitCast(Buf, DestType);
return RValue::get(Builder.CreateCall(F, Buf)); return RValue::get(Builder.CreateCall(F, Buf));
} }
@ -514,8 +514,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
case Builtin::BI__sync_synchronize: { case Builtin::BI__sync_synchronize: {
Value *C[5]; Value *C[5];
C[0] = C[1] = C[2] = C[3] = llvm::ConstantInt::get(llvm::Type::Int1Ty, 1); C[0] = C[1] = C[2] = C[3] = llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 1);
C[4] = llvm::ConstantInt::get(llvm::Type::Int1Ty, 0); C[4] = llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), 0);
Builder.CreateCall(CGM.getIntrinsic(Intrinsic::memory_barrier), C, C + 5); Builder.CreateCall(CGM.getIntrinsic(Intrinsic::memory_barrier), C, C + 5);
return RValue::get(0); return RValue::get(0);
} }
@ -584,7 +584,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD,
Value *V = Builder.CreateCall(F, Args.data(), Args.data() + Args.size()); Value *V = Builder.CreateCall(F, Args.data(), Args.data() + Args.size());
QualType BuiltinRetType = E->getType(); QualType BuiltinRetType = E->getType();
const llvm::Type *RetTy = llvm::Type::VoidTy; const llvm::Type *RetTy = llvm::Type::getVoidTy(VMContext);
if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType); if (!BuiltinRetType->isVoidType()) RetTy = ConvertType(BuiltinRetType);
if (RetTy != V->getType()) { if (RetTy != V->getType()) {
@ -636,9 +636,9 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
case X86::BI__builtin_ia32_psrldi128: case X86::BI__builtin_ia32_psrldi128:
case X86::BI__builtin_ia32_psrlqi128: case X86::BI__builtin_ia32_psrlqi128:
case X86::BI__builtin_ia32_psrlwi128: { case X86::BI__builtin_ia32_psrlwi128: {
Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::getInt64Ty(VMContext), "zext");
const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 2); const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::getInt64Ty(VMContext), 2);
llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); llvm::Value *Zero = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0);
Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty), Ops[1] = Builder.CreateInsertElement(llvm::UndefValue::get(Ty),
Ops[1], Zero, "insert"); Ops[1], Zero, "insert");
Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast"); Ops[1] = Builder.CreateBitCast(Ops[1], Ops[0]->getType(), "bitcast");
@ -691,8 +691,8 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
case X86::BI__builtin_ia32_psrldi: case X86::BI__builtin_ia32_psrldi:
case X86::BI__builtin_ia32_psrlqi: case X86::BI__builtin_ia32_psrlqi:
case X86::BI__builtin_ia32_psrlwi: { case X86::BI__builtin_ia32_psrlwi: {
Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::Int64Ty, "zext"); Ops[1] = Builder.CreateZExt(Ops[1], llvm::Type::getInt64Ty(VMContext), "zext");
const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::Int64Ty, 1); const llvm::Type *Ty = llvm::VectorType::get(llvm::Type::getInt64Ty(VMContext), 1);
Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast"); Ops[1] = Builder.CreateBitCast(Ops[1], Ty, "bitcast");
const char *name = 0; const char *name = 0;
Intrinsic::ID ID = Intrinsic::not_intrinsic; Intrinsic::ID ID = Intrinsic::not_intrinsic;
@ -744,17 +744,17 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpss"); return Builder.CreateCall(F, &Ops[0], &Ops[0] + Ops.size(), "cmpss");
} }
case X86::BI__builtin_ia32_ldmxcsr: { case X86::BI__builtin_ia32_ldmxcsr: {
llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); Value *One = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1);
Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); Value *Tmp = Builder.CreateAlloca(llvm::Type::getInt32Ty(VMContext), One, "tmp");
Builder.CreateStore(Ops[0], Tmp); Builder.CreateStore(Ops[0], Tmp);
return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr), return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_ldmxcsr),
Builder.CreateBitCast(Tmp, PtrTy)); Builder.CreateBitCast(Tmp, PtrTy));
} }
case X86::BI__builtin_ia32_stmxcsr: { case X86::BI__builtin_ia32_stmxcsr: {
llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Value *One = llvm::ConstantInt::get(llvm::Type::Int32Ty, 1); Value *One = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 1);
Value *Tmp = Builder.CreateAlloca(llvm::Type::Int32Ty, One, "tmp"); Value *Tmp = Builder.CreateAlloca(llvm::Type::getInt32Ty(VMContext), One, "tmp");
One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr), One = Builder.CreateCall(CGM.getIntrinsic(Intrinsic::x86_sse_stmxcsr),
Builder.CreateBitCast(Tmp, PtrTy)); Builder.CreateBitCast(Tmp, PtrTy));
return Builder.CreateLoad(Tmp, "stmxcsr"); return Builder.CreateLoad(Tmp, "stmxcsr");
@ -769,7 +769,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
} }
case X86::BI__builtin_ia32_storehps: case X86::BI__builtin_ia32_storehps:
case X86::BI__builtin_ia32_storelps: { case X86::BI__builtin_ia32_storelps: {
const llvm::Type *EltTy = llvm::Type::Int64Ty; const llvm::Type *EltTy = llvm::Type::getInt64Ty(VMContext);
llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy); llvm::Type *PtrTy = llvm::PointerType::getUnqual(EltTy);
llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2); llvm::Type *VecTy = llvm::VectorType::get(EltTy, 2);
@ -778,7 +778,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned BuiltinID,
// extract (0, 1) // extract (0, 1)
unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1; unsigned Index = BuiltinID == X86::BI__builtin_ia32_storelps ? 0 : 1;
llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Index); llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), Index);
Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract"); Ops[1] = Builder.CreateExtractElement(Ops[1], Idx, "extract");
// cast pointer to i64 & store // cast pointer to i64 & store

View File

@ -31,14 +31,14 @@ CodeGenFunction::EmitCXXGlobalDtorRegistration(const CXXDestructorDecl *Dtor,
// FIXME: This is ABI dependent and we use the Itanium ABI. // FIXME: This is ABI dependent and we use the Itanium ABI.
const llvm::Type *Int8PtrTy = const llvm::Type *Int8PtrTy =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
std::vector<const llvm::Type *> Params; std::vector<const llvm::Type *> Params;
Params.push_back(Int8PtrTy); Params.push_back(Int8PtrTy);
// Get the destructor function type // Get the destructor function type
const llvm::Type *DtorFnTy = const llvm::Type *DtorFnTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Params, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Params, false);
DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy); DtorFnTy = llvm::PointerType::getUnqual(DtorFnTy);
Params.clear(); Params.clear();
@ -96,7 +96,7 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
if (CXXGlobalInits.empty()) if (CXXGlobalInits.empty())
return; return;
const llvm::FunctionType *FTy = llvm::FunctionType::get(llvm::Type::VoidTy, const llvm::FunctionType *FTy = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
false); false);
// Create our global initialization function. // Create our global initialization function.
@ -140,18 +140,18 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
// Create the guard variable. // Create the guard variable.
llvm::GlobalValue *GuardV = llvm::GlobalValue *GuardV =
new llvm::GlobalVariable(CGM.getModule(), llvm::Type::Int64Ty, false, new llvm::GlobalVariable(CGM.getModule(), llvm::Type::getInt64Ty(VMContext), false,
GV->getLinkage(), GV->getLinkage(),
llvm::Constant::getNullValue(llvm::Type::Int64Ty), llvm::Constant::getNullValue(llvm::Type::getInt64Ty(VMContext)),
GuardVName.c_str()); GuardVName.c_str());
// Load the first byte of the guard variable. // Load the first byte of the guard variable.
const llvm::Type *PtrTy = llvm::PointerType::get(llvm::Type::Int8Ty, 0); const llvm::Type *PtrTy = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
llvm::Value *V = Builder.CreateLoad(Builder.CreateBitCast(GuardV, PtrTy), llvm::Value *V = Builder.CreateLoad(Builder.CreateBitCast(GuardV, PtrTy),
"tmp"); "tmp");
// Compare it against 0. // Compare it against 0.
llvm::Value *nullValue = llvm::Constant::getNullValue(llvm::Type::Int8Ty); llvm::Value *nullValue = llvm::Constant::getNullValue(llvm::Type::getInt8Ty(VMContext));
llvm::Value *ICmp = Builder.CreateICmpEQ(V, nullValue , "tobool"); llvm::Value *ICmp = Builder.CreateICmpEQ(V, nullValue , "tobool");
llvm::BasicBlock *InitBlock = createBasicBlock("init"); llvm::BasicBlock *InitBlock = createBasicBlock("init");
@ -164,7 +164,7 @@ CodeGenFunction::EmitStaticCXXBlockVarDeclInit(const VarDecl &D,
EmitCXXGlobalVarDeclInit(D, GV); EmitCXXGlobalVarDeclInit(D, GV);
Builder.CreateStore(llvm::ConstantInt::get(llvm::Type::Int8Ty, 1), Builder.CreateStore(llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), 1),
Builder.CreateBitCast(GuardV, PtrTy)); Builder.CreateBitCast(GuardV, PtrTy));
EmitBlock(EndBlock); EmitBlock(EndBlock);
@ -301,7 +301,7 @@ llvm::Value *CodeGenFunction::AddressCXXOfBaseClass(llvm::Value *BaseValue,
if (ClassDecl == BaseClassDecl) if (ClassDecl == BaseClassDecl)
return BaseValue; return BaseValue;
llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
llvm::SmallVector<const CXXRecordDecl *, 16> NestedBasePaths; llvm::SmallVector<const CXXRecordDecl *, 16> NestedBasePaths;
GetNestedPaths(NestedBasePaths, ClassDecl, BaseClassDecl); GetNestedPaths(NestedBasePaths, ClassDecl, BaseClassDecl);
assert(NestedBasePaths.size() > 0 && assert(NestedBasePaths.size() > 0 &&
@ -602,7 +602,7 @@ const char *CodeGenModule::getMangledCXXDtorName(const CXXDestructorDecl *D,
llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) { llvm::Constant *CodeGenFunction::GenerateRtti(const CXXRecordDecl *RD) {
llvm::Type *Ptr8Ty; llvm::Type *Ptr8Ty;
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
llvm::Constant *Rtti = llvm::Constant::getNullValue(Ptr8Ty); llvm::Constant *Rtti = llvm::Constant::getNullValue(Ptr8Ty);
if (!getContext().getLangOptions().Rtti) if (!getContext().getLangOptions().Rtti)
@ -674,7 +674,7 @@ void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
bool ForVirtualBase, bool ForVirtualBase,
llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary) { llvm::SmallSet<const CXXRecordDecl *, 32> &IndirectPrimary) {
llvm::Type *Ptr8Ty; llvm::Type *Ptr8Ty;
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
llvm::Constant *m = llvm::Constant::getNullValue(Ptr8Ty); llvm::Constant *m = llvm::Constant::getNullValue(Ptr8Ty);
if (RD && !RD->isDynamicClass()) if (RD && !RD->isDynamicClass())
@ -693,7 +693,7 @@ void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl()); cast<CXXRecordDecl>(i->getType()->getAs<RecordType>()->getDecl());
int64_t BaseOffset = Layout.getBaseClassOffset(Base) / 8; int64_t BaseOffset = Layout.getBaseClassOffset(Base) / 8;
llvm::Constant *m; llvm::Constant *m;
m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset); m = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), BaseOffset);
m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty); m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
methods.push_back(m); methods.push_back(m);
} }
@ -723,7 +723,7 @@ void CodeGenFunction::GenerateVtableForBase(const CXXRecordDecl *RD,
if (TopPrimary) { if (TopPrimary) {
if (RD) { if (RD) {
int64_t BaseOffset = -(Layout.getBaseClassOffset(RD) / 8); int64_t BaseOffset = -(Layout.getBaseClassOffset(RD) / 8);
m = llvm::ConstantInt::get(llvm::Type::Int64Ty, BaseOffset); m = llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext), BaseOffset);
m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty); m = llvm::ConstantExpr::getIntToPtr(m, Ptr8Ty);
} }
methods.push_back(m); methods.push_back(m);
@ -750,7 +750,7 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
llvm::GlobalVariable::LinkageTypes linktype; llvm::GlobalVariable::LinkageTypes linktype;
linktype = llvm::GlobalValue::WeakAnyLinkage; linktype = llvm::GlobalValue::WeakAnyLinkage;
std::vector<llvm::Constant *> methods; std::vector<llvm::Constant *> methods;
llvm::Type *Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); llvm::Type *Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
int64_t Offset = 0; int64_t Offset = 0;
llvm::Constant *rtti = GenerateRtti(RD); llvm::Constant *rtti = GenerateRtti(RD);
@ -793,7 +793,7 @@ llvm::Value *CodeGenFunction::GenerateVtable(const CXXRecordDecl *RD) {
linktype, C, Name); linktype, C, Name);
vtable = Builder.CreateBitCast(vtable, Ptr8Ty); vtable = Builder.CreateBitCast(vtable, Ptr8Ty);
vtable = Builder.CreateGEP(vtable, vtable = Builder.CreateGEP(vtable,
llvm::ConstantInt::get(llvm::Type::Int64Ty, llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
Offset/8)); Offset/8));
return vtable; return vtable;
} }
@ -1100,7 +1100,7 @@ void CodeGenFunction::EmitCtorPrologue(const CXXConstructorDecl *CD) {
LoadOfThis = LoadCXXThis(); LoadOfThis = LoadCXXThis();
llvm::Value *VtableField; llvm::Value *VtableField;
llvm::Type *Ptr8Ty, *PtrPtr8Ty; llvm::Type *Ptr8Ty, *PtrPtr8Ty;
Ptr8Ty = llvm::PointerType::get(llvm::Type::Int8Ty, 0); Ptr8Ty = llvm::PointerType::get(llvm::Type::getInt8Ty(VMContext), 0);
PtrPtr8Ty = llvm::PointerType::get(Ptr8Ty, 0); PtrPtr8Ty = llvm::PointerType::get(Ptr8Ty, 0);
VtableField = Builder.CreateBitCast(LoadOfThis, PtrPtr8Ty); VtableField = Builder.CreateBitCast(LoadOfThis, PtrPtr8Ty);
llvm::Value *vtable = GenerateVtable(ClassDecl); llvm::Value *vtable = GenerateVtable(ClassDecl);

View File

@ -24,7 +24,7 @@ void CodeGenFunction::PushCXXTemporary(const CXXTemporary *Temporary,
// Check if temporaries need to be conditional. If so, we'll create a // Check if temporaries need to be conditional. If so, we'll create a
// condition boolean, initialize it to 0 and // condition boolean, initialize it to 0 and
if (!ConditionalTempDestructionStack.empty()) { if (!ConditionalTempDestructionStack.empty()) {
CondPtr = CreateTempAlloca(llvm::Type::Int1Ty, "cond"); CondPtr = CreateTempAlloca(llvm::Type::getInt1Ty(VMContext), "cond");
// Initialize it to false. This initialization takes place right after // Initialize it to false. This initialization takes place right after
// the alloca insert point. // the alloca insert point.

View File

@ -321,14 +321,14 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo &FI, bool IsVariadic) {
case ABIArgInfo::Indirect: { case ABIArgInfo::Indirect: {
assert(!RetAI.getIndirectAlign() && "Align unused on indirect return."); assert(!RetAI.getIndirectAlign() && "Align unused on indirect return.");
ResultType = llvm::Type::VoidTy; ResultType = llvm::Type::getVoidTy(getLLVMContext());
const llvm::Type *STy = ConvertType(RetTy); const llvm::Type *STy = ConvertType(RetTy);
ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace())); ArgTys.push_back(llvm::PointerType::get(STy, RetTy.getAddressSpace()));
break; break;
} }
case ABIArgInfo::Ignore: case ABIArgInfo::Ignore:
ResultType = llvm::Type::VoidTy; ResultType = llvm::Type::getVoidTy(getLLVMContext());
break; break;
case ABIArgInfo::Coerce: case ABIArgInfo::Coerce:
@ -839,7 +839,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
} }
llvm::Instruction *CI = CS.getInstruction(); llvm::Instruction *CI = CS.getInstruction();
if (Builder.isNamePreserving() && CI->getType() != llvm::Type::VoidTy) if (Builder.isNamePreserving() &&
CI->getType() != llvm::Type::getVoidTy(VMContext))
CI->setName("call"); CI->setName("call");
switch (RetAI.getKind()) { switch (RetAI.getKind()) {

View File

@ -224,11 +224,11 @@ const llvm::Type *CodeGenFunction::BuildByRefType(QualType Ty,
bool needsCopyDispose = BlockRequiresCopying(Ty); bool needsCopyDispose = BlockRequiresCopying(Ty);
std::vector<const llvm::Type *> Types(needsCopyDispose*2+5); std::vector<const llvm::Type *> Types(needsCopyDispose*2+5);
const llvm::PointerType *PtrToInt8Ty const llvm::PointerType *PtrToInt8Ty
= llvm::PointerType::getUnqual(llvm::Type::Int8Ty); = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Types[0] = PtrToInt8Ty; Types[0] = PtrToInt8Ty;
Types[1] = PtrToInt8Ty; Types[1] = PtrToInt8Ty;
Types[2] = llvm::Type::Int32Ty; Types[2] = llvm::Type::getInt32Ty(VMContext);
Types[3] = llvm::Type::Int32Ty; Types[3] = llvm::Type::getInt32Ty(VMContext);
if (needsCopyDispose) { if (needsCopyDispose) {
Types[4] = PtrToInt8Ty; Types[4] = PtrToInt8Ty;
Types[5] = PtrToInt8Ty; Types[5] = PtrToInt8Ty;
@ -282,7 +282,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
if (!DidCallStackSave) { if (!DidCallStackSave) {
// Save the stack. // Save the stack.
const llvm::Type *LTy = const llvm::Type *LTy =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
llvm::Value *Stack = CreateTempAlloca(LTy, "saved_stack"); llvm::Value *Stack = CreateTempAlloca(LTy, "saved_stack");
llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stacksave); llvm::Value *F = CGM.getIntrinsic(llvm::Intrinsic::stacksave);
@ -310,10 +310,12 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
llvm::Value *VLASize = EmitVLASize(Ty); llvm::Value *VLASize = EmitVLASize(Ty);
// Downcast the VLA size expression // Downcast the VLA size expression
VLASize = Builder.CreateIntCast(VLASize, llvm::Type::Int32Ty, false, "tmp"); VLASize = Builder.CreateIntCast(VLASize, llvm::Type::getInt32Ty(VMContext),
false, "tmp");
// Allocate memory for the array. // Allocate memory for the array.
llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::Int8Ty, VLASize, "vla"); llvm::Value *VLA = Builder.CreateAlloca(llvm::Type::getInt8Ty(VMContext),
VLASize, "vla");
DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp"); DeclPtr = Builder.CreateBitCast(VLA, LElemPtrTy, "tmp");
} }
@ -374,7 +376,7 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
if (isByRef) { if (isByRef) {
const llvm::PointerType *PtrToInt8Ty const llvm::PointerType *PtrToInt8Ty
= llvm::PointerType::getUnqual(llvm::Type::Int8Ty); = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
EnsureInsertPoint(); EnsureInsertPoint();
llvm::Value *isa_field = Builder.CreateStructGEP(DeclPtr, 0); llvm::Value *isa_field = Builder.CreateStructGEP(DeclPtr, 0);
@ -402,19 +404,19 @@ void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
int isa = 0; int isa = 0;
if (flag&BLOCK_FIELD_IS_WEAK) if (flag&BLOCK_FIELD_IS_WEAK)
isa = 1; isa = 1;
V = llvm::ConstantInt::get(llvm::Type::Int32Ty, isa); V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), isa);
V = Builder.CreateIntToPtr(V, PtrToInt8Ty, "isa"); V = Builder.CreateIntToPtr(V, PtrToInt8Ty, "isa");
Builder.CreateStore(V, isa_field); Builder.CreateStore(V, isa_field);
V = Builder.CreateBitCast(DeclPtr, PtrToInt8Ty, "forwarding"); V = Builder.CreateBitCast(DeclPtr, PtrToInt8Ty, "forwarding");
Builder.CreateStore(V, forwarding_field); Builder.CreateStore(V, forwarding_field);
V = llvm::ConstantInt::get(llvm::Type::Int32Ty, flags); V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), flags);
Builder.CreateStore(V, flags_field); Builder.CreateStore(V, flags_field);
const llvm::Type *V1; const llvm::Type *V1;
V1 = cast<llvm::PointerType>(DeclPtr->getType())->getElementType(); V1 = cast<llvm::PointerType>(DeclPtr->getType())->getElementType();
V = llvm::ConstantInt::get(llvm::Type::Int32Ty, V = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
(CGM.getTargetData().getTypeStoreSizeInBits(V1) (CGM.getTargetData().getTypeStoreSizeInBits(V1)
/ 8)); / 8));
Builder.CreateStore(V, size_field); Builder.CreateStore(V, size_field);

View File

@ -239,8 +239,8 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(llvm::Value *Addr, bool Volatile,
// Bool can have different representation in memory than in registers. // Bool can have different representation in memory than in registers.
if (Ty->isBooleanType()) if (Ty->isBooleanType())
if (V->getType() != llvm::Type::Int1Ty) if (V->getType() != llvm::Type::getInt1Ty(VMContext))
V = Builder.CreateTrunc(V, llvm::Type::Int1Ty, "tobool"); V = Builder.CreateTrunc(V, llvm::Type::getInt1Ty(VMContext), "tobool");
return V; return V;
} }
@ -340,9 +340,8 @@ RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV,
// Fetch the high bits if necessary. // Fetch the high bits if necessary.
if (LowBits < BitfieldSize) { if (LowBits < BitfieldSize) {
unsigned HighBits = BitfieldSize - LowBits; unsigned HighBits = BitfieldSize - LowBits;
llvm::Value *HighPtr = llvm::Value *HighPtr = Builder.CreateGEP(Ptr, llvm::ConstantInt::get(
Builder.CreateGEP(Ptr, llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), llvm::Type::getInt32Ty(VMContext), 1), "bf.ptr.hi");
"bf.ptr.hi");
llvm::Value *HighVal = Builder.CreateLoad(HighPtr, llvm::Value *HighVal = Builder.CreateLoad(HighPtr,
LV.isVolatileQualified(), LV.isVolatileQualified(),
"tmp"); "tmp");
@ -397,7 +396,8 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV,
const VectorType *ExprVT = ExprType->getAsVectorType(); const VectorType *ExprVT = ExprType->getAsVectorType();
if (!ExprVT) { if (!ExprVT) {
unsigned InIdx = getAccessedFieldNo(0, Elts); unsigned InIdx = getAccessedFieldNo(0, Elts);
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx); llvm::Value *Elt = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), InIdx);
return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp")); return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp"));
} }
@ -407,7 +407,8 @@ RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV,
llvm::SmallVector<llvm::Constant*, 4> Mask; llvm::SmallVector<llvm::Constant*, 4> Mask;
for (unsigned i = 0; i != NumResultElts; ++i) { for (unsigned i = 0; i != NumResultElts; ++i) {
unsigned InIdx = getAccessedFieldNo(i, Elts); unsigned InIdx = getAccessedFieldNo(i, Elts);
Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx)); Mask.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), InIdx));
} }
llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size()); llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size());
@ -551,9 +552,8 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst,
// If the low part doesn't cover the bitfield emit a high part. // If the low part doesn't cover the bitfield emit a high part.
if (LowBits < BitfieldSize) { if (LowBits < BitfieldSize) {
unsigned HighBits = BitfieldSize - LowBits; unsigned HighBits = BitfieldSize - LowBits;
llvm::Value *HighPtr = llvm::Value *HighPtr = Builder.CreateGEP(Ptr, llvm::ConstantInt::get(
Builder.CreateGEP(Ptr, llvm::ConstantInt::get(llvm::Type::Int32Ty, 1), llvm::Type::getInt32Ty(VMContext), 1), "bf.ptr.hi");
"bf.ptr.hi");
llvm::Value *HighVal = Builder.CreateLoad(HighPtr, llvm::Value *HighVal = Builder.CreateLoad(HighPtr,
Dst.isVolatileQualified(), Dst.isVolatileQualified(),
"bf.prev.hi"); "bf.prev.hi");
@ -612,7 +612,8 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
llvm::SmallVector<llvm::Constant*, 4> Mask(NumDstElts); llvm::SmallVector<llvm::Constant*, 4> Mask(NumDstElts);
for (unsigned i = 0; i != NumSrcElts; ++i) { for (unsigned i = 0; i != NumSrcElts; ++i) {
unsigned InIdx = getAccessedFieldNo(i, Elts); unsigned InIdx = getAccessedFieldNo(i, Elts);
Mask[InIdx] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); Mask[InIdx] = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), i);
} }
llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size()); llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size());
@ -627,9 +628,11 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
llvm::SmallVector<llvm::Constant*, 4> ExtMask; llvm::SmallVector<llvm::Constant*, 4> ExtMask;
unsigned i; unsigned i;
for (i = 0; i != NumSrcElts; ++i) for (i = 0; i != NumSrcElts; ++i)
ExtMask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, i)); ExtMask.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), i));
for (; i != NumDstElts; ++i) for (; i != NumDstElts; ++i)
ExtMask.push_back(llvm::UndefValue::get(llvm::Type::Int32Ty)); ExtMask.push_back(llvm::UndefValue::get(
llvm::Type::getInt32Ty(VMContext)));
llvm::Value *ExtMaskV = llvm::ConstantVector::get(&ExtMask[0], llvm::Value *ExtMaskV = llvm::ConstantVector::get(&ExtMask[0],
ExtMask.size()); ExtMask.size());
llvm::Value *ExtSrcVal = llvm::Value *ExtSrcVal =
@ -639,12 +642,14 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
// build identity // build identity
llvm::SmallVector<llvm::Constant*, 4> Mask; llvm::SmallVector<llvm::Constant*, 4> Mask;
for (unsigned i = 0; i != NumDstElts; ++i) { for (unsigned i = 0; i != NumDstElts; ++i) {
Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, i)); Mask.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), i));
} }
// modify when what gets shuffled in // modify when what gets shuffled in
for (unsigned i = 0; i != NumSrcElts; ++i) { for (unsigned i = 0; i != NumSrcElts; ++i) {
unsigned Idx = getAccessedFieldNo(i, Elts); unsigned Idx = getAccessedFieldNo(i, Elts);
Mask[Idx] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i+NumDstElts); Mask[Idx] = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), i+NumDstElts);
} }
llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size()); llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size());
Vec = Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV, "tmp"); Vec = Builder.CreateShuffleVector(Vec, ExtSrcVal, MaskV, "tmp");
@ -655,7 +660,8 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
} else { } else {
// If the Src is a scalar (not a vector) it must be updating one element. // If the Src is a scalar (not a vector) it must be updating one element.
unsigned InIdx = getAccessedFieldNo(0, Elts); unsigned InIdx = getAccessedFieldNo(0, Elts);
llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx); llvm::Value *Elt = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), InIdx);
Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt, "tmp"); Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt, "tmp");
} }
@ -860,7 +866,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
// Emit the vector as an lvalue to get its address. // Emit the vector as an lvalue to get its address.
LValue LHS = EmitLValue(E->getBase()); LValue LHS = EmitLValue(E->getBase());
assert(LHS.isSimple() && "Can only subscript lvalue vectors here!"); assert(LHS.isSimple() && "Can only subscript lvalue vectors here!");
Idx = Builder.CreateIntCast(Idx, llvm::Type::Int32Ty, IdxSigned, "vidx"); Idx = Builder.CreateIntCast(Idx,
llvm::Type::getInt32Ty(VMContext), IdxSigned, "vidx");
return LValue::MakeVectorElt(LHS.getAddress(), Idx, return LValue::MakeVectorElt(LHS.getAddress(), Idx,
E->getBase()->getType().getCVRQualifiers()); E->getBase()->getType().getCVRQualifiers());
} }
@ -871,7 +878,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
// Extend or truncate the index type to 32 or 64-bits. // Extend or truncate the index type to 32 or 64-bits.
unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth(); unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth();
if (IdxBitwidth != LLVMPointerWidth) if (IdxBitwidth != LLVMPointerWidth)
Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth), Idx = Builder.CreateIntCast(Idx,
llvm::IntegerType::get(VMContext, LLVMPointerWidth),
IdxSigned, "idxprom"); IdxSigned, "idxprom");
// We know that the pointer points to a type of the correct size, // We know that the pointer points to a type of the correct size,
@ -898,7 +906,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) {
Idx = Builder.CreateMul(Idx, InterfaceSize); Idx = Builder.CreateMul(Idx, InterfaceSize);
llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *i8PTy =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy), Address = Builder.CreateGEP(Builder.CreateBitCast(Base, i8PTy),
Idx, "arrayidx"); Idx, "arrayidx");
Address = Builder.CreateBitCast(Address, Base->getType()); Address = Builder.CreateBitCast(Address, Base->getType());
@ -926,7 +935,8 @@ llvm::Constant *GenerateConstantVector(llvm::LLVMContext &VMContext,
llvm::SmallVector<llvm::Constant *, 4> CElts; llvm::SmallVector<llvm::Constant *, 4> CElts;
for (unsigned i = 0, e = Elts.size(); i != e; ++i) for (unsigned i = 0, e = Elts.size(); i != e; ++i)
CElts.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Elts[i])); CElts.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), Elts[i]));
return llvm::ConstantVector::get(&CElts[0], CElts.size()); return llvm::ConstantVector::get(&CElts[0], CElts.size());
} }
@ -964,7 +974,8 @@ EmitExtVectorElementExpr(const ExtVectorElementExpr *E) {
for (unsigned i = 0, e = Indices.size(); i != e; ++i) { for (unsigned i = 0, e = Indices.size(); i != e; ++i) {
if (isa<llvm::ConstantAggregateZero>(BaseElts)) if (isa<llvm::ConstantAggregateZero>(BaseElts))
CElts.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); CElts.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), 0));
else else
CElts.push_back(BaseElts->getOperand(Indices[i])); CElts.push_back(BaseElts->getOperand(Indices[i]));
} }
@ -1037,7 +1048,7 @@ LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue,
"tmp"); "tmp");
llvm::Value *Idx = llvm::Value *Idx =
llvm::ConstantInt::get(llvm::Type::Int32Ty, Info.FieldNo); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), Info.FieldNo);
llvm::Value *V = Builder.CreateGEP(BaseValue, Idx, "tmp"); llvm::Value *V = Builder.CreateGEP(BaseValue, Idx, "tmp");
return LValue::MakeBitfield(V, Info.Start, Info.Size, return LValue::MakeBitfield(V, Info.Start, Info.Size,

View File

@ -541,7 +541,8 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
// equal, but other compilers do this optimization, and almost every memcpy // equal, but other compilers do this optimization, and almost every memcpy
// implementation handles this case safely. If there is a libc that does not // implementation handles this case safely. If there is a libc that does not
// safely handle this, we can add a target hook. // safely handle this, we can add a target hook.
const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *BP =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
if (DestPtr->getType() != BP) if (DestPtr->getType() != BP)
DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");
if (SrcPtr->getType() != BP) if (SrcPtr->getType() != BP)
@ -551,7 +552,8 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
std::pair<uint64_t, unsigned> TypeInfo = getContext().getTypeInfo(Ty); std::pair<uint64_t, unsigned> TypeInfo = getContext().getTypeInfo(Ty);
// FIXME: Handle variable sized types. // FIXME: Handle variable sized types.
const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth); const llvm::Type *IntPtr =
llvm::IntegerType::get(VMContext, LLVMPointerWidth);
// FIXME: If we have a volatile struct, the optimizer can remove what might // FIXME: If we have a volatile struct, the optimizer can remove what might
// appear to be `extra' memory ops: // appear to be `extra' memory ops:
@ -569,6 +571,6 @@ void CodeGenFunction::EmitAggregateCopy(llvm::Value *DestPtr,
DestPtr, SrcPtr, DestPtr, SrcPtr,
// TypeInfo.first describes size in bits. // TypeInfo.first describes size in bits.
llvm::ConstantInt::get(IntPtr, TypeInfo.first/8), llvm::ConstantInt::get(IntPtr, TypeInfo.first/8),
llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
TypeInfo.second/8)); TypeInfo.second/8));
} }

View File

@ -81,7 +81,7 @@ class VISIBILITY_HIDDEN ConstStructBuilder {
uint64_t NumBytes = uint64_t NumBytes =
AlignedElementOffsetInBytes - ElementOffsetInBytes; AlignedElementOffsetInBytes - ElementOffsetInBytes;
const llvm::Type *Ty = llvm::Type::Int8Ty; const llvm::Type *Ty = llvm::Type::getInt8Ty(CGF->getLLVMContext());
if (NumBytes > 1) if (NumBytes > 1)
Ty = llvm::ArrayType::get(Ty, NumBytes); Ty = llvm::ArrayType::get(Ty, NumBytes);
@ -249,7 +249,7 @@ class VISIBILITY_HIDDEN ConstStructBuilder {
if (!NumBytes) if (!NumBytes)
return; return;
const llvm::Type *Ty = llvm::Type::Int8Ty; const llvm::Type *Ty = llvm::Type::getInt8Ty(CGM.getLLVMContext());
if (NumBytes > 1) if (NumBytes > 1)
Ty = llvm::ArrayType::get(Ty, NumBytes); Ty = llvm::ArrayType::get(Ty, NumBytes);
@ -399,7 +399,7 @@ public:
assert(CurSize <= TotalSize && "Union size mismatch!"); assert(CurSize <= TotalSize && "Union size mismatch!");
if (unsigned NumPadBytes = TotalSize - CurSize) { if (unsigned NumPadBytes = TotalSize - CurSize) {
const llvm::Type *Ty = llvm::Type::Int8Ty; const llvm::Type *Ty = llvm::Type::getInt8Ty(VMContext);
if (NumPadBytes > 1) if (NumPadBytes > 1)
Ty = llvm::ArrayType::get(Ty, NumPadBytes); Ty = llvm::ArrayType::get(Ty, NumPadBytes);
@ -545,7 +545,8 @@ public:
// This must be a string initializing an array in a static initializer. // This must be a string initializing an array in a static initializer.
// Don't emit it as the address of the string, emit the string data itself // Don't emit it as the address of the string, emit the string data itself
// as an inline array. // as an inline array.
return llvm::ConstantArray::get(CGM.GetStringForStringLiteral(E), false); return llvm::ConstantArray::get(VMContext,
CGM.GetStringForStringLiteral(E), false);
} }
llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) { llvm::Constant *VisitObjCEncodeExpr(ObjCEncodeExpr *E) {
@ -559,7 +560,7 @@ public:
// Resize the string to the right size, adding zeros at the end, or // Resize the string to the right size, adding zeros at the end, or
// truncating as needed. // truncating as needed.
Str.resize(CAT->getSize().getZExtValue(), '\0'); Str.resize(CAT->getSize().getZExtValue(), '\0');
return llvm::ConstantArray::get(Str, false); return llvm::ConstantArray::get(VMContext, Str, false);
} }
llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) { llvm::Constant *VisitUnaryExtension(const UnaryOperator *E) {
@ -626,8 +627,10 @@ public:
} }
case Expr::AddrLabelExprClass: { case Expr::AddrLabelExprClass: {
assert(CGF && "Invalid address of label expression outside function."); assert(CGF && "Invalid address of label expression outside function.");
unsigned id = CGF->GetIDForAddrOfLabel(cast<AddrLabelExpr>(E)->getLabel()); unsigned id =
llvm::Constant *C = llvm::ConstantInt::get(llvm::Type::Int32Ty, id); CGF->GetIDForAddrOfLabel(cast<AddrLabelExpr>(E)->getLabel());
llvm::Constant *C =
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), id);
return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType())); return llvm::ConstantExpr::getIntToPtr(C, ConvertType(E->getType()));
} }
case Expr::CallExprClass: { case Expr::CallExprClass: {
@ -679,7 +682,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
case APValue::LValue: { case APValue::LValue: {
const llvm::Type *DestTy = getTypes().ConvertTypeForMem(DestType); const llvm::Type *DestTy = getTypes().ConvertTypeForMem(DestType);
llvm::Constant *Offset = llvm::Constant *Offset =
llvm::ConstantInt::get(llvm::Type::Int64Ty, llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
Result.Val.getLValueOffset()); Result.Val.getLValueOffset());
llvm::Constant *C; llvm::Constant *C;
@ -689,7 +692,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
// Apply offset if necessary. // Apply offset if necessary.
if (!Offset->isNullValue()) { if (!Offset->isNullValue()) {
const llvm::Type *Type = const llvm::Type *Type =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Type); llvm::Constant *Casted = llvm::ConstantExpr::getBitCast(C, Type);
Casted = llvm::ConstantExpr::getGetElementPtr(Casted, &Offset, 1); Casted = llvm::ConstantExpr::getGetElementPtr(Casted, &Offset, 1);
C = llvm::ConstantExpr::getBitCast(Casted, C->getType()); C = llvm::ConstantExpr::getBitCast(Casted, C->getType());
@ -720,7 +723,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
llvm::Constant *C = llvm::ConstantInt::get(VMContext, llvm::Constant *C = llvm::ConstantInt::get(VMContext,
Result.Val.getInt()); Result.Val.getInt());
if (C->getType() == llvm::Type::Int1Ty) { if (C->getType() == llvm::Type::getInt1Ty(VMContext)) {
const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType()); const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
C = llvm::ConstantExpr::getZExt(C, BoolTy); C = llvm::ConstantExpr::getZExt(C, BoolTy);
} }
@ -765,7 +768,7 @@ llvm::Constant *CodeGenModule::EmitConstantExpr(const Expr *E,
} }
llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E)); llvm::Constant* C = ConstExprEmitter(*this, CGF).Visit(const_cast<Expr*>(E));
if (C && C->getType() == llvm::Type::Int1Ty) { if (C && C->getType() == llvm::Type::getInt1Ty(VMContext)) {
const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType()); const llvm::Type *BoolTy = getTypes().ConvertTypeForMem(E->getType());
C = llvm::ConstantExpr::getZExt(C, BoolTy); C = llvm::ConstantExpr::getZExt(C, BoolTy);
} }

View File

@ -134,7 +134,7 @@ public:
Value *VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E); Value *VisitSizeOfAlignOfExpr(const SizeOfAlignOfExpr *E);
Value *VisitAddrLabelExpr(const AddrLabelExpr *E) { Value *VisitAddrLabelExpr(const AddrLabelExpr *E) {
llvm::Value *V = llvm::Value *V =
llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()),
CGF.GetIDForAddrOfLabel(E->getLabel())); CGF.GetIDForAddrOfLabel(E->getLabel()));
return Builder.CreateIntToPtr(V, ConvertType(E->getType())); return Builder.CreateIntToPtr(V, ConvertType(E->getType()));
@ -206,13 +206,15 @@ public:
unsigned i; unsigned i;
for (i = 0; i < NumInitElements; ++i) { for (i = 0; i < NumInitElements; ++i) {
Value *NewV = Visit(E->getInit(i)); Value *NewV = Visit(E->getInit(i));
Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); Value *Idx =
llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()), i);
V = Builder.CreateInsertElement(V, NewV, Idx); V = Builder.CreateInsertElement(V, NewV, Idx);
} }
// Emit remaining default initializers // Emit remaining default initializers
for (/* Do not initialize i*/; i < NumVectorElements; ++i) { for (/* Do not initialize i*/; i < NumVectorElements; ++i) {
Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); Value *Idx =
llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()), i);
llvm::Value *NewV = llvm::Constant::getNullValue(ElementType); llvm::Value *NewV = llvm::Constant::getNullValue(ElementType);
V = Builder.CreateInsertElement(V, NewV, Idx); V = Builder.CreateInsertElement(V, NewV, Idx);
} }
@ -406,7 +408,8 @@ Value *ScalarExprEmitter::EmitConversionToBool(Value *Src, QualType SrcType) {
// then zero extending it to int, then wanting it as a logical value again. // then zero extending it to int, then wanting it as a logical value again.
// Optimize this common case. // Optimize this common case.
if (llvm::ZExtInst *ZI = dyn_cast<llvm::ZExtInst>(Src)) { if (llvm::ZExtInst *ZI = dyn_cast<llvm::ZExtInst>(Src)) {
if (ZI->getOperand(0)->getType() == llvm::Type::Int1Ty) { if (ZI->getOperand(0)->getType() ==
llvm::Type::getInt1Ty(CGF.getLLVMContext())) {
Value *Result = ZI->getOperand(0); Value *Result = ZI->getOperand(0);
// If there aren't any more uses, zap the instruction to save space. // If there aren't any more uses, zap the instruction to save space.
// Note that there can be more uses, for example if this // Note that there can be more uses, for example if this
@ -432,6 +435,8 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
if (DstType->isVoidType()) return 0; if (DstType->isVoidType()) return 0;
llvm::LLVMContext &VMContext = CGF.getLLVMContext();
// Handle conversions to bool first, they are special: comparisons against 0. // Handle conversions to bool first, they are special: comparisons against 0.
if (DstType->isBooleanType()) if (DstType->isBooleanType())
return EmitConversionToBool(Src, SrcType); return EmitConversionToBool(Src, SrcType);
@ -460,7 +465,8 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?"); assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
// First, convert to the correct width so that we control the kind of // First, convert to the correct width so that we control the kind of
// extension. // extension.
const llvm::Type *MiddleTy = llvm::IntegerType::get(CGF.LLVMPointerWidth); const llvm::Type *MiddleTy =
llvm::IntegerType::get(VMContext, CGF.LLVMPointerWidth);
bool InputSigned = SrcType->isSignedIntegerType(); bool InputSigned = SrcType->isSignedIntegerType();
llvm::Value* IntResult = llvm::Value* IntResult =
Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv"); Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
@ -482,14 +488,16 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType,
// Insert the element in element zero of an undef vector // Insert the element in element zero of an undef vector
llvm::Value *UnV = llvm::UndefValue::get(DstTy); llvm::Value *UnV = llvm::UndefValue::get(DstTy);
llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); llvm::Value *Idx =
llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0);
UnV = Builder.CreateInsertElement(UnV, Elt, Idx, "tmp"); UnV = Builder.CreateInsertElement(UnV, Elt, Idx, "tmp");
// Splat the element across to all elements // Splat the element across to all elements
llvm::SmallVector<llvm::Constant*, 16> Args; llvm::SmallVector<llvm::Constant*, 16> Args;
unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements(); unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements();
for (unsigned i = 0; i < NumElements; i++) for (unsigned i = 0; i < NumElements; i++)
Args.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); Args.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), 0));
llvm::Constant *Mask = llvm::ConstantVector::get(&Args[0], NumElements); llvm::Constant *Mask = llvm::ConstantVector::get(&Args[0], NumElements);
llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat"); llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat");
@ -589,7 +597,9 @@ Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
Value *Base = Visit(E->getBase()); Value *Base = Visit(E->getBase());
Value *Idx = Visit(E->getIdx()); Value *Idx = Visit(E->getIdx());
bool IdxSigned = E->getIdx()->getType()->isSignedIntegerType(); bool IdxSigned = E->getIdx()->getType()->isSignedIntegerType();
Idx = Builder.CreateIntCast(Idx, llvm::Type::Int32Ty, IdxSigned, Idx = Builder.CreateIntCast(Idx,
llvm::Type::getInt32Ty(CGF.getLLVMContext()),
IdxSigned,
"vecidxcast"); "vecidxcast");
return Builder.CreateExtractElement(Base, Idx, "vecext"); return Builder.CreateExtractElement(Base, Idx, "vecext");
} }
@ -693,6 +703,8 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
QualType ValTy = E->getSubExpr()->getType(); QualType ValTy = E->getSubExpr()->getType();
Value *InVal = CGF.EmitLoadOfLValue(LV, ValTy).getScalarVal(); Value *InVal = CGF.EmitLoadOfLValue(LV, ValTy).getScalarVal();
llvm::LLVMContext &VMContext = CGF.getLLVMContext();
int AmountVal = isInc ? 1 : -1; int AmountVal = isInc ? 1 : -1;
if (ValTy->isPointerType() && if (ValTy->isPointerType() &&
@ -705,7 +717,7 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
if (const llvm::PointerType *PT = if (const llvm::PointerType *PT =
dyn_cast<llvm::PointerType>(InVal->getType())) { dyn_cast<llvm::PointerType>(InVal->getType())) {
llvm::Constant *Inc = llvm::Constant *Inc =
llvm::ConstantInt::get(llvm::Type::Int32Ty, AmountVal); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), AmountVal);
if (!isa<llvm::FunctionType>(PT->getElementType())) { if (!isa<llvm::FunctionType>(PT->getElementType())) {
QualType PTEE = ValTy->getPointeeType(); QualType PTEE = ValTy->getPointeeType();
if (const ObjCInterfaceType *OIT = if (const ObjCInterfaceType *OIT =
@ -716,7 +728,7 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
size = -size; size = -size;
Inc = llvm::ConstantInt::get(Inc->getType(), size); Inc = llvm::ConstantInt::get(Inc->getType(), size);
const llvm::Type *i8Ty = const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
InVal = Builder.CreateBitCast(InVal, i8Ty); InVal = Builder.CreateBitCast(InVal, i8Ty);
NextVal = Builder.CreateGEP(InVal, Inc, "add.ptr"); NextVal = Builder.CreateGEP(InVal, Inc, "add.ptr");
llvm::Value *lhs = LV.getAddress(); llvm::Value *lhs = LV.getAddress();
@ -727,12 +739,12 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
NextVal = Builder.CreateInBoundsGEP(InVal, Inc, "ptrincdec"); NextVal = Builder.CreateInBoundsGEP(InVal, Inc, "ptrincdec");
} else { } else {
const llvm::Type *i8Ty = const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
NextVal = Builder.CreateBitCast(InVal, i8Ty, "tmp"); NextVal = Builder.CreateBitCast(InVal, i8Ty, "tmp");
NextVal = Builder.CreateGEP(NextVal, Inc, "ptrincdec"); NextVal = Builder.CreateGEP(NextVal, Inc, "ptrincdec");
NextVal = Builder.CreateBitCast(NextVal, InVal->getType()); NextVal = Builder.CreateBitCast(NextVal, InVal->getType());
} }
} else if (InVal->getType() == llvm::Type::Int1Ty && isInc) { } else if (InVal->getType() == llvm::Type::getInt1Ty(VMContext) && isInc) {
// Bool++ is an interesting case, due to promotion rules, we get: // Bool++ is an interesting case, due to promotion rules, we get:
// Bool++ -> Bool = Bool+1 -> Bool = (int)Bool+1 -> // Bool++ -> Bool = Bool+1 -> Bool = (int)Bool+1 ->
// Bool = ((int)Bool+1) != 0 // Bool = ((int)Bool+1) != 0
@ -749,11 +761,11 @@ Value *ScalarExprEmitter::VisitPrePostIncDec(const UnaryOperator *E,
NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); NextVal = Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec");
} else { } else {
// Add the inc/dec to the real part. // Add the inc/dec to the real part.
if (InVal->getType() == llvm::Type::FloatTy) if (InVal->getType() == llvm::Type::getFloatTy(VMContext))
NextVal = NextVal =
llvm::ConstantFP::get(VMContext, llvm::ConstantFP::get(VMContext,
llvm::APFloat(static_cast<float>(AmountVal))); llvm::APFloat(static_cast<float>(AmountVal)));
else if (InVal->getType() == llvm::Type::DoubleTy) else if (InVal->getType() == llvm::Type::getDoubleTy(VMContext))
NextVal = NextVal =
llvm::ConstantFP::get(VMContext, llvm::ConstantFP::get(VMContext,
llvm::APFloat(static_cast<double>(AmountVal))); llvm::APFloat(static_cast<double>(AmountVal)));
@ -997,22 +1009,22 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
// long long *__overflow_handler)(long long a, long long b, char op, // long long *__overflow_handler)(long long a, long long b, char op,
// char width) // char width)
std::vector<const llvm::Type*> handerArgTypes; std::vector<const llvm::Type*> handerArgTypes;
handerArgTypes.push_back(llvm::Type::Int64Ty); handerArgTypes.push_back(llvm::Type::getInt64Ty(VMContext));
handerArgTypes.push_back(llvm::Type::Int64Ty); handerArgTypes.push_back(llvm::Type::getInt64Ty(VMContext));
handerArgTypes.push_back(llvm::Type::Int8Ty); handerArgTypes.push_back(llvm::Type::getInt8Ty(VMContext));
handerArgTypes.push_back(llvm::Type::Int8Ty); handerArgTypes.push_back(llvm::Type::getInt8Ty(VMContext));
llvm::FunctionType *handlerTy = llvm::FunctionType::get(llvm::Type::Int64Ty, llvm::FunctionType *handlerTy = llvm::FunctionType::get(
handerArgTypes, false); llvm::Type::getInt64Ty(VMContext), handerArgTypes, false);
llvm::Value *handlerFunction = llvm::Value *handlerFunction =
CGF.CGM.getModule().getOrInsertGlobal("__overflow_handler", CGF.CGM.getModule().getOrInsertGlobal("__overflow_handler",
llvm::PointerType::getUnqual(handlerTy)); llvm::PointerType::getUnqual(handlerTy));
handlerFunction = Builder.CreateLoad(handlerFunction); handlerFunction = Builder.CreateLoad(handlerFunction);
llvm::Value *handlerResult = Builder.CreateCall4(handlerFunction, llvm::Value *handlerResult = Builder.CreateCall4(handlerFunction,
Builder.CreateSExt(Ops.LHS, llvm::Type::Int64Ty), Builder.CreateSExt(Ops.LHS, llvm::Type::getInt64Ty(VMContext)),
Builder.CreateSExt(Ops.RHS, llvm::Type::Int64Ty), Builder.CreateSExt(Ops.RHS, llvm::Type::getInt64Ty(VMContext)),
llvm::ConstantInt::get(llvm::Type::Int8Ty, OpID), llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext), OpID),
llvm::ConstantInt::get(llvm::Type::Int8Ty, llvm::ConstantInt::get(llvm::Type::getInt8Ty(VMContext),
cast<llvm::IntegerType>(opTy)->getBitWidth())); cast<llvm::IntegerType>(opTy)->getBitWidth()));
handlerResult = Builder.CreateTrunc(handlerResult, opTy); handlerResult = Builder.CreateTrunc(handlerResult, opTy);
@ -1073,7 +1085,8 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
if (Width < CGF.LLVMPointerWidth) { if (Width < CGF.LLVMPointerWidth) {
// Zero or sign extend the pointer value based on whether the index is // Zero or sign extend the pointer value based on whether the index is
// signed or not. // signed or not.
const llvm::Type *IdxType = llvm::IntegerType::get(CGF.LLVMPointerWidth); const llvm::Type *IdxType =
llvm::IntegerType::get(VMContext, CGF.LLVMPointerWidth);
if (IdxExp->getType()->isSignedIntegerType()) if (IdxExp->getType()->isSignedIntegerType())
Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext"); Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext");
else else
@ -1087,7 +1100,8 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
llvm::ConstantInt::get(Idx->getType(), llvm::ConstantInt::get(Idx->getType(),
CGF.getContext().getTypeSize(OIT) / 8); CGF.getContext().getTypeSize(OIT) / 8);
Idx = Builder.CreateMul(Idx, InterfaceSize); Idx = Builder.CreateMul(Idx, InterfaceSize);
const llvm::Type *i8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Value *Casted = Builder.CreateBitCast(Ptr, i8Ty); Value *Casted = Builder.CreateBitCast(Ptr, i8Ty);
Value *Res = Builder.CreateGEP(Casted, Idx, "add.ptr"); Value *Res = Builder.CreateGEP(Casted, Idx, "add.ptr");
return Builder.CreateBitCast(Res, Ptr->getType()); return Builder.CreateBitCast(Res, Ptr->getType());
@ -1097,7 +1111,8 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) {
// extensions. The GNU void* casts amount to no-ops since our void* // extensions. The GNU void* casts amount to no-ops since our void*
// type is i8*, but this is future proof. // type is i8*, but this is future proof.
if (ElementType->isVoidType() || ElementType->isFunctionType()) { if (ElementType->isVoidType() || ElementType->isFunctionType()) {
const llvm::Type *i8Ty = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Value *Casted = Builder.CreateBitCast(Ptr, i8Ty); Value *Casted = Builder.CreateBitCast(Ptr, i8Ty);
Value *Res = Builder.CreateGEP(Casted, Idx, "add.ptr"); Value *Res = Builder.CreateGEP(Casted, Idx, "add.ptr");
return Builder.CreateBitCast(Res, Ptr->getType()); return Builder.CreateBitCast(Res, Ptr->getType());
@ -1135,7 +1150,8 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
if (Width < CGF.LLVMPointerWidth) { if (Width < CGF.LLVMPointerWidth) {
// Zero or sign extend the pointer value based on whether the index is // Zero or sign extend the pointer value based on whether the index is
// signed or not. // signed or not.
const llvm::Type *IdxType = llvm::IntegerType::get(CGF.LLVMPointerWidth); const llvm::Type *IdxType =
llvm::IntegerType::get(VMContext, CGF.LLVMPointerWidth);
if (Ops.E->getRHS()->getType()->isSignedIntegerType()) if (Ops.E->getRHS()->getType()->isSignedIntegerType())
Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext"); Idx = Builder.CreateSExt(Idx, IdxType, "idx.ext");
else else
@ -1152,7 +1168,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
CGF.getContext().getTypeSize(OIT) / 8); CGF.getContext().getTypeSize(OIT) / 8);
Idx = Builder.CreateMul(Idx, InterfaceSize); Idx = Builder.CreateMul(Idx, InterfaceSize);
const llvm::Type *i8Ty = const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Value *LHSCasted = Builder.CreateBitCast(Ops.LHS, i8Ty); Value *LHSCasted = Builder.CreateBitCast(Ops.LHS, i8Ty);
Value *Res = Builder.CreateGEP(LHSCasted, Idx, "add.ptr"); Value *Res = Builder.CreateGEP(LHSCasted, Idx, "add.ptr");
return Builder.CreateBitCast(Res, Ops.LHS->getType()); return Builder.CreateBitCast(Res, Ops.LHS->getType());
@ -1163,7 +1179,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) {
// void* type is i8*, but this is future proof. // void* type is i8*, but this is future proof.
if (LHSElementType->isVoidType() || LHSElementType->isFunctionType()) { if (LHSElementType->isVoidType() || LHSElementType->isFunctionType()) {
const llvm::Type *i8Ty = const llvm::Type *i8Ty =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
Value *LHSCasted = Builder.CreateBitCast(Ops.LHS, i8Ty); Value *LHSCasted = Builder.CreateBitCast(Ops.LHS, i8Ty);
Value *Res = Builder.CreateGEP(LHSCasted, Idx, "sub.ptr"); Value *Res = Builder.CreateGEP(LHSCasted, Idx, "sub.ptr");
return Builder.CreateBitCast(Res, Ops.LHS->getType()); return Builder.CreateBitCast(Res, Ops.LHS->getType());
@ -1334,7 +1350,8 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
// Any edges into the ContBlock are now from an (indeterminate number of) // Any edges into the ContBlock are now from an (indeterminate number of)
// edges from this first condition. All of these values will be false. Start // edges from this first condition. All of these values will be false. Start
// setting up the PHI node in the Cont Block for this. // setting up the PHI node in the Cont Block for this.
llvm::PHINode *PN = llvm::PHINode::Create(llvm::Type::Int1Ty, "", ContBlock); llvm::PHINode *PN = llvm::PHINode::Create(llvm::Type::getInt1Ty(VMContext),
"", ContBlock);
PN->reserveOperandSpace(2); // Normal case, two inputs. PN->reserveOperandSpace(2); // Normal case, two inputs.
for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock); for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock);
PI != PE; ++PI) PI != PE; ++PI)
@ -1381,7 +1398,8 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
// Any edges into the ContBlock are now from an (indeterminate number of) // Any edges into the ContBlock are now from an (indeterminate number of)
// edges from this first condition. All of these values will be true. Start // edges from this first condition. All of these values will be true. Start
// setting up the PHI node in the Cont Block for this. // setting up the PHI node in the Cont Block for this.
llvm::PHINode *PN = llvm::PHINode::Create(llvm::Type::Int1Ty, "", ContBlock); llvm::PHINode *PN = llvm::PHINode::Create(llvm::Type::getInt1Ty(VMContext),
"", ContBlock);
PN->reserveOperandSpace(2); // Normal case, two inputs. PN->reserveOperandSpace(2); // Normal case, two inputs.
for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock); for (llvm::pred_iterator PI = pred_begin(ContBlock), PE = pred_end(ContBlock);
PI != PE; ++PI) PI != PE; ++PI)
@ -1609,7 +1627,8 @@ Value *CodeGenFunction::EmitShuffleVector(Value* V1, Value *V2, ...) {
int n = va_arg(va, int); int n = va_arg(va, int);
assert(n >= 0 && n < (int)NumElements * 2 && assert(n >= 0 && n < (int)NumElements * 2 &&
"Vector shuffle index out of bounds!"); "Vector shuffle index out of bounds!");
Args.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, n)); Args.push_back(llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), n));
} }
const char *Name = va_arg(va, const char *); const char *Name = va_arg(va, const char *);
@ -1627,7 +1646,8 @@ llvm::Value *CodeGenFunction::EmitVector(llvm::Value * const *Vals,
for (unsigned i = 0, e = NumVals; i != e; ++i) { for (unsigned i = 0, e = NumVals; i != e; ++i) {
llvm::Value *Val = isSplat ? Vals[0] : Vals[i]; llvm::Value *Val = isSplat ? Vals[0] : Vals[i];
llvm::Value *Idx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); llvm::Value *Idx = llvm::ConstantInt::get(
llvm::Type::getInt32Ty(VMContext), i);
Vec = Builder.CreateInsertElement(Vec, Val, Idx, "tmp"); Vec = Builder.CreateInsertElement(Vec, Val, Idx, "tmp");
} }

View File

@ -214,10 +214,10 @@ CGObjCGNU::CGObjCGNU(CodeGen::CodeGenModule &cgm)
Zeros[0] = llvm::ConstantInt::get(LongTy, 0); Zeros[0] = llvm::ConstantInt::get(LongTy, 0);
Zeros[1] = Zeros[0]; Zeros[1] = Zeros[0];
NULLPtr = llvm::ConstantPointerNull::get( NULLPtr = llvm::ConstantPointerNull::get(
llvm::PointerType::getUnqual(llvm::Type::Int8Ty)); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext)));
// C string type. Used in lots of places. // C string type. Used in lots of places.
PtrToInt8Ty = PtrToInt8Ty =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
// Get the selector Type. // Get the selector Type.
SelectorTy = cast<llvm::PointerType>( SelectorTy = cast<llvm::PointerType>(
CGM.getTypes().ConvertType(CGM.getContext().getObjCSelType())); CGM.getTypes().ConvertType(CGM.getContext().getObjCSelType()));
@ -291,7 +291,7 @@ llvm::Value *CGObjCGNU::GetSelector(CGBuilderTy &Builder, const ObjCMethodDecl
llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str, llvm::Constant *CGObjCGNU::MakeConstantString(const std::string &Str,
const std::string &Name) { const std::string &Name) {
llvm::Constant * ConstStr = llvm::ConstantArray::get(Str); llvm::Constant * ConstStr = llvm::ConstantArray::get(VMContext, Str);
ConstStr = new llvm::GlobalVariable(TheModule, ConstStr->getType(), true, ConstStr = new llvm::GlobalVariable(TheModule, ConstStr->getType(), true,
llvm::GlobalValue::InternalLinkage, llvm::GlobalValue::InternalLinkage,
ConstStr, Name); ConstStr, Name);
@ -544,7 +544,7 @@ llvm::Constant *CGObjCGNU::GenerateMethodList(const std::string &ClassName,
Methods.clear(); Methods.clear();
Methods.push_back(llvm::ConstantPointerNull::get( Methods.push_back(llvm::ConstantPointerNull::get(
llvm::PointerType::getUnqual(ObjCMethodListTy))); llvm::PointerType::getUnqual(ObjCMethodListTy)));
Methods.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Methods.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
MethodTypes.size())); MethodTypes.size()));
Methods.push_back(MethodArray); Methods.push_back(MethodArray);
@ -733,7 +733,7 @@ llvm::Constant *CGObjCGNU::GenerateEmptyProtocol(
// The isa pointer must be set to a magic number so the runtime knows it's // The isa pointer must be set to a magic number so the runtime knows it's
// the correct layout. // the correct layout.
Elements.push_back(llvm::ConstantExpr::getIntToPtr( Elements.push_back(llvm::ConstantExpr::getIntToPtr(
llvm::ConstantInt::get(llvm::Type::Int32Ty, ProtocolVersion), IdTy)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ProtocolVersion), IdTy));
Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name")); Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name"));
Elements.push_back(ProtocolList); Elements.push_back(ProtocolList);
Elements.push_back(InstanceMethodList); Elements.push_back(InstanceMethodList);
@ -788,7 +788,7 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) {
// The isa pointer must be set to a magic number so the runtime knows it's // The isa pointer must be set to a magic number so the runtime knows it's
// the correct layout. // the correct layout.
Elements.push_back(llvm::ConstantExpr::getIntToPtr( Elements.push_back(llvm::ConstantExpr::getIntToPtr(
llvm::ConstantInt::get(llvm::Type::Int32Ty, ProtocolVersion), IdTy)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), ProtocolVersion), IdTy));
Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name")); Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name"));
Elements.push_back(ProtocolList); Elements.push_back(ProtocolList);
Elements.push_back(InstanceMethodList); Elements.push_back(InstanceMethodList);
@ -914,7 +914,7 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
Offset = ComputeIvarBaseOffset(CGM, ClassDecl, *iter); Offset = ComputeIvarBaseOffset(CGM, ClassDecl, *iter);
} }
IvarOffsets.push_back( IvarOffsets.push_back(
llvm::ConstantInt::get(llvm::Type::Int32Ty, Offset)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), Offset));
} }
// Collect information about instance methods // Collect information about instance methods
@ -1064,8 +1064,8 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
Classes.size() + Categories.size() + 2); Classes.size() + Categories.size() + 2);
llvm::StructType *SymTabTy = llvm::StructType::get(VMContext, llvm::StructType *SymTabTy = llvm::StructType::get(VMContext,
LongTy, SelStructPtrTy, LongTy, SelStructPtrTy,
llvm::Type::Int16Ty, llvm::Type::getInt16Ty(VMContext),
llvm::Type::Int16Ty, llvm::Type::getInt16Ty(VMContext),
ClassListTy, NULL); ClassListTy, NULL);
Elements.clear(); Elements.clear();
@ -1107,7 +1107,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
iter=TypedSelectors.begin(), iterEnd =TypedSelectors.end(); iter=TypedSelectors.begin(), iterEnd =TypedSelectors.end();
iter != iterEnd; ++iter) { iter != iterEnd; ++iter) {
llvm::Constant *Idxs[] = {Zeros[0], llvm::Constant *Idxs[] = {Zeros[0],
llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]}; llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]};
llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy, llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy,
true, llvm::GlobalValue::InternalLinkage, true, llvm::GlobalValue::InternalLinkage,
llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2), llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
@ -1124,7 +1124,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
iter=UntypedSelectors.begin(), iterEnd = UntypedSelectors.end(); iter=UntypedSelectors.begin(), iterEnd = UntypedSelectors.end();
iter != iterEnd; iter++) { iter != iterEnd; iter++) {
llvm::Constant *Idxs[] = {Zeros[0], llvm::Constant *Idxs[] = {Zeros[0],
llvm::ConstantInt::get(llvm::Type::Int32Ty, index++), Zeros[0]}; llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]};
llvm::Constant *SelPtr = new llvm::GlobalVariable llvm::Constant *SelPtr = new llvm::GlobalVariable
(TheModule, SelStructPtrTy, (TheModule, SelStructPtrTy,
true, llvm::GlobalValue::InternalLinkage, true, llvm::GlobalValue::InternalLinkage,
@ -1139,10 +1139,10 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
(*iter).second->setAliasee(SelPtr); (*iter).second->setAliasee(SelPtr);
} }
// Number of classes defined. // Number of classes defined.
Elements.push_back(llvm::ConstantInt::get(llvm::Type::Int16Ty, Elements.push_back(llvm::ConstantInt::get(llvm::Type::getInt16Ty(VMContext),
Classes.size())); Classes.size()));
// Number of categories defined // Number of categories defined
Elements.push_back(llvm::ConstantInt::get(llvm::Type::Int16Ty, Elements.push_back(llvm::ConstantInt::get(llvm::Type::getInt16Ty(VMContext),
Categories.size())); Categories.size()));
// Create an array of classes, then categories, then static object instances // Create an array of classes, then categories, then static object instances
Classes.insert(Classes.end(), Categories.begin(), Categories.end()); Classes.insert(Classes.end(), Categories.begin(), Categories.end());
@ -1178,17 +1178,18 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
// Create the load function calling the runtime entry point with the module // Create the load function calling the runtime entry point with the module
// structure // structure
llvm::Function * LoadFunction = llvm::Function::Create( llvm::Function * LoadFunction = llvm::Function::Create(
llvm::FunctionType::get(llvm::Type::VoidTy, false), llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), false),
llvm::GlobalValue::InternalLinkage, ".objc_load_function", llvm::GlobalValue::InternalLinkage, ".objc_load_function",
&TheModule); &TheModule);
llvm::BasicBlock *EntryBB = llvm::BasicBlock::Create("entry", LoadFunction); llvm::BasicBlock *EntryBB =
llvm::BasicBlock::Create(VMContext, "entry", LoadFunction);
CGBuilderTy Builder(VMContext); CGBuilderTy Builder(VMContext);
Builder.SetInsertPoint(EntryBB); Builder.SetInsertPoint(EntryBB);
std::vector<const llvm::Type*> Params(1, std::vector<const llvm::Type*> Params(1,
llvm::PointerType::getUnqual(ModuleTy)); llvm::PointerType::getUnqual(ModuleTy));
llvm::Value *Register = CGM.CreateRuntimeFunction(llvm::FunctionType::get( llvm::Value *Register = CGM.CreateRuntimeFunction(llvm::FunctionType::get(
llvm::Type::VoidTy, Params, true), "__objc_exec_class"); llvm::Type::getVoidTy(VMContext), Params, true), "__objc_exec_class");
Builder.CreateCall(Register, Module); Builder.CreateCall(Register, Module);
Builder.CreateRetVoid(); Builder.CreateRetVoid();
@ -1246,7 +1247,7 @@ llvm::Function *CGObjCGNU::GetPropertySetFunction() {
Params.push_back(BoolTy); Params.push_back(BoolTy);
// void objc_setProperty (id, SEL, ptrdiff_t, id, bool, bool) // void objc_setProperty (id, SEL, ptrdiff_t, id, bool, bool)
const llvm::FunctionType *FTy = const llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Params, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Params, false);
return cast<llvm::Function>(CGM.CreateRuntimeFunction(FTy, return cast<llvm::Function>(CGM.CreateRuntimeFunction(FTy,
"objc_setProperty")); "objc_setProperty"));
} }
@ -1266,14 +1267,14 @@ void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
const Stmt &S) { const Stmt &S) {
// Pointer to the personality function // Pointer to the personality function
llvm::Constant *Personality = llvm::Constant *Personality =
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::Int32Ty, CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty(VMContext),
true), true),
"__gnu_objc_personality_v0"); "__gnu_objc_personality_v0");
Personality = llvm::ConstantExpr::getBitCast(Personality, PtrTy); Personality = llvm::ConstantExpr::getBitCast(Personality, PtrTy);
std::vector<const llvm::Type*> Params; std::vector<const llvm::Type*> Params;
Params.push_back(PtrTy); Params.push_back(PtrTy);
llvm::Value *RethrowFn = llvm::Value *RethrowFn =
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, false), "_Unwind_Resume_or_Rethrow"); Params, false), "_Unwind_Resume_or_Rethrow");
bool isTry = isa<ObjCAtTryStmt>(S); bool isTry = isa<ObjCAtTryStmt>(S);
@ -1289,7 +1290,7 @@ void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
if (!isTry) { if (!isTry) {
std::vector<const llvm::Type*> Args(1, IdTy); std::vector<const llvm::Type*> Args(1, IdTy);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Args, false);
llvm::Value *SyncEnter = CGM.CreateRuntimeFunction(FTy, "objc_sync_enter"); llvm::Value *SyncEnter = CGM.CreateRuntimeFunction(FTy, "objc_sync_enter");
llvm::Value *SyncArg = llvm::Value *SyncArg =
CGF.EmitScalarExpr(cast<ObjCAtSynchronizedStmt>(S).getSynchExpr()); CGF.EmitScalarExpr(cast<ObjCAtSynchronizedStmt>(S).getSynchExpr());
@ -1377,7 +1378,7 @@ void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
// We use a cleanup unless there was already a catch all. // We use a cleanup unless there was already a catch all.
if (!HasCatchAll) { if (!HasCatchAll) {
ESelArgs.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); ESelArgs.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0));
Handlers.push_back(std::make_pair((const ParmVarDecl*) 0, (const Stmt*) 0)); Handlers.push_back(std::make_pair((const ParmVarDecl*) 0, (const Stmt*) 0));
} }
@ -1442,7 +1443,7 @@ void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
ESelArgs.clear(); ESelArgs.clear();
ESelArgs.push_back(Exc); ESelArgs.push_back(Exc);
ESelArgs.push_back(Personality); ESelArgs.push_back(Personality);
ESelArgs.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); ESelArgs.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0));
CGF.Builder.CreateCall(llvm_eh_selector, ESelArgs.begin(), ESelArgs.end(), CGF.Builder.CreateCall(llvm_eh_selector, ESelArgs.begin(), ESelArgs.end(),
"selector"); "selector");
CGF.Builder.CreateCall(llvm_eh_typeid_for, CGF.Builder.CreateCall(llvm_eh_typeid_for,
@ -1466,7 +1467,7 @@ void CGObjCGNU::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
// @synchronized. // @synchronized.
std::vector<const llvm::Type*> Args(1, IdTy); std::vector<const llvm::Type*> Args(1, IdTy);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Args, false);
llvm::Value *SyncExit = CGM.CreateRuntimeFunction(FTy, "objc_sync_exit"); llvm::Value *SyncExit = CGM.CreateRuntimeFunction(FTy, "objc_sync_exit");
llvm::Value *SyncArg = llvm::Value *SyncArg =
CGF.EmitScalarExpr(cast<ObjCAtSynchronizedStmt>(S).getSynchExpr()); CGF.EmitScalarExpr(cast<ObjCAtSynchronizedStmt>(S).getSynchExpr());
@ -1496,7 +1497,7 @@ void CGObjCGNU::EmitThrowStmt(CodeGen::CodeGenFunction &CGF,
std::vector<const llvm::Type*> Args(1, IdTy); std::vector<const llvm::Type*> Args(1, IdTy);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Args, false);
llvm::Value *ThrowFn = llvm::Value *ThrowFn =
CGM.CreateRuntimeFunction(FTy, "objc_exception_throw"); CGM.CreateRuntimeFunction(FTy, "objc_exception_throw");

View File

@ -101,7 +101,8 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
unsigned CVRQualifiers, unsigned CVRQualifiers,
llvm::Value *Offset) { llvm::Value *Offset) {
// Compute (type*) ( (char *) BaseValue + Offset) // Compute (type*) ( (char *) BaseValue + Offset)
llvm::Type *I8Ptr = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *I8Ptr =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(CGF.getLLVMContext()));
QualType IvarTy = Ivar->getType(); QualType IvarTy = Ivar->getType();
const llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy); const llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, I8Ptr); llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, I8Ptr);
@ -160,7 +161,7 @@ private:
Params.push_back(ObjectPtrTy); Params.push_back(ObjectPtrTy);
Params.push_back(SelectorPtrTy); Params.push_back(SelectorPtrTy);
return return
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, true), Params, true),
"objc_msgSend_stret"); "objc_msgSend_stret");
@ -173,7 +174,8 @@ private:
Params.push_back(ObjectPtrTy); Params.push_back(ObjectPtrTy);
Params.push_back(SelectorPtrTy); Params.push_back(SelectorPtrTy);
return return
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::DoubleTy, CGM.CreateRuntimeFunction(llvm::FunctionType::get(
llvm::Type::getDoubleTy(VMContext),
Params, Params,
true), true),
"objc_msgSend_fpret"); "objc_msgSend_fpret");
@ -210,7 +212,7 @@ private:
Params.push_back(SuperPtrTy); Params.push_back(SuperPtrTy);
Params.push_back(SelectorPtrTy); Params.push_back(SelectorPtrTy);
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::VoidTy, llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, true), Params, true),
"objc_msgSendSuper_stret"); "objc_msgSendSuper_stret");
} }
@ -223,7 +225,7 @@ private:
Params.push_back(SuperPtrTy); Params.push_back(SuperPtrTy);
Params.push_back(SelectorPtrTy); Params.push_back(SelectorPtrTy);
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::VoidTy, llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, true), Params, true),
"objc_msgSendSuper2_stret"); "objc_msgSendSuper2_stret");
} }
@ -395,7 +397,7 @@ public:
// void objc_exception_throw(id) // void objc_exception_throw(id)
std::vector<const llvm::Type*> Args(1, ObjectPtrTy); std::vector<const llvm::Type*> Args(1, ObjectPtrTy);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Args, false);
return CGM.CreateRuntimeFunction(FTy, "objc_exception_throw"); return CGM.CreateRuntimeFunction(FTy, "objc_exception_throw");
} }
@ -404,7 +406,7 @@ public:
// void objc_sync_enter (id) // void objc_sync_enter (id)
std::vector<const llvm::Type*> Args(1, ObjectPtrTy); std::vector<const llvm::Type*> Args(1, ObjectPtrTy);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Args, false);
return CGM.CreateRuntimeFunction(FTy, "objc_sync_enter"); return CGM.CreateRuntimeFunction(FTy, "objc_sync_enter");
} }
@ -413,7 +415,7 @@ public:
// void objc_sync_exit (id) // void objc_sync_exit (id)
std::vector<const llvm::Type*> Args(1, ObjectPtrTy); std::vector<const llvm::Type*> Args(1, ObjectPtrTy);
llvm::FunctionType *FTy = llvm::FunctionType *FTy =
llvm::FunctionType::get(llvm::Type::VoidTy, Args, false); llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext), Args, false);
return CGM.CreateRuntimeFunction(FTy, "objc_sync_exit"); return CGM.CreateRuntimeFunction(FTy, "objc_sync_exit");
} }
@ -508,7 +510,7 @@ public:
std::vector<const llvm::Type*> Params; std::vector<const llvm::Type*> Params;
Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy)); Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy));
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::VoidTy, llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, false), Params, false),
"objc_exception_try_enter"); "objc_exception_try_enter");
} }
@ -518,7 +520,7 @@ public:
std::vector<const llvm::Type*> Params; std::vector<const llvm::Type*> Params;
Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy)); Params.push_back(llvm::PointerType::getUnqual(ExceptionDataTy));
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::VoidTy, llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, false), Params, false),
"objc_exception_try_exit"); "objc_exception_try_exit");
} }
@ -539,7 +541,7 @@ public:
Params.push_back(ClassPtrTy); Params.push_back(ClassPtrTy);
Params.push_back(ObjectPtrTy); Params.push_back(ObjectPtrTy);
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::Int32Ty, llvm::FunctionType::get(llvm::Type::getInt32Ty(VMContext),
Params, false), Params, false),
"objc_exception_match"); "objc_exception_match");
@ -548,9 +550,9 @@ public:
/// SetJmpFn - LLVM _setjmp function. /// SetJmpFn - LLVM _setjmp function.
llvm::Constant *getSetJmpFn() { llvm::Constant *getSetJmpFn() {
std::vector<const llvm::Type*> Params; std::vector<const llvm::Type*> Params;
Params.push_back(llvm::PointerType::getUnqual(llvm::Type::Int32Ty)); Params.push_back(llvm::PointerType::getUnqual(llvm::Type::getInt32Ty(VMContext)));
return return
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::Int32Ty, CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty(VMContext),
Params, false), Params, false),
"_setjmp"); "_setjmp");
@ -714,7 +716,7 @@ public:
/// exception personality function. /// exception personality function.
llvm::Value *getEHPersonalityPtr() { llvm::Value *getEHPersonalityPtr() {
llvm::Constant *Personality = llvm::Constant *Personality =
CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::Int32Ty, CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getInt32Ty(VMContext),
true), true),
"__objc_personality_v0"); "__objc_personality_v0");
return llvm::ConstantExpr::getBitCast(Personality, Int8PtrTy); return llvm::ConstantExpr::getBitCast(Personality, Int8PtrTy);
@ -724,13 +726,13 @@ public:
std::vector<const llvm::Type*> Params; std::vector<const llvm::Type*> Params;
Params.push_back(Int8PtrTy); Params.push_back(Int8PtrTy);
return CGM.CreateRuntimeFunction( return CGM.CreateRuntimeFunction(
llvm::FunctionType::get(llvm::Type::VoidTy, llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
Params, false), Params, false),
"_Unwind_Resume_or_Rethrow"); "_Unwind_Resume_or_Rethrow");
} }
llvm::Constant *getObjCEndCatchFn() { llvm::Constant *getObjCEndCatchFn() {
return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::VoidTy, return CGM.CreateRuntimeFunction(llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
false), false),
"objc_end_catch"); "objc_end_catch");
@ -1377,8 +1379,8 @@ static llvm::Constant *getConstantGEP(llvm::LLVMContext &VMContext,
unsigned idx0, unsigned idx0,
unsigned idx1) { unsigned idx1) {
llvm::Value *Idxs[] = { llvm::Value *Idxs[] = {
llvm::ConstantInt::get(llvm::Type::Int32Ty, idx0), llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx0),
llvm::ConstantInt::get(llvm::Type::Int32Ty, idx1) llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), idx1)
}; };
return llvm::ConstantExpr::getGetElementPtr(C, Idxs, 2); return llvm::ConstantExpr::getGetElementPtr(C, Idxs, 2);
} }
@ -2471,7 +2473,8 @@ void CGObjCMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
"exceptiondata.ptr"); "exceptiondata.ptr");
llvm::Value *RethrowPtr = CGF.CreateTempAlloca(ObjCTypes.ObjectPtrTy, llvm::Value *RethrowPtr = CGF.CreateTempAlloca(ObjCTypes.ObjectPtrTy,
"_rethrow"); "_rethrow");
llvm::Value *CallTryExitPtr = CGF.CreateTempAlloca(llvm::Type::Int1Ty, llvm::Value *CallTryExitPtr = CGF.CreateTempAlloca(
llvm::Type::getInt1Ty(VMContext),
"_call_try_exit"); "_call_try_exit");
CGF.Builder.CreateStore(llvm::ConstantInt::getTrue(VMContext), CGF.Builder.CreateStore(llvm::ConstantInt::getTrue(VMContext),
CallTryExitPtr); CallTryExitPtr);
@ -2849,10 +2852,10 @@ void CGObjCMac::EmitImageInfo() {
// Emitted as int[2]; // Emitted as int[2];
llvm::Constant *values[2] = { llvm::Constant *values[2] = {
llvm::ConstantInt::get(llvm::Type::Int32Ty, version), llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), version),
llvm::ConstantInt::get(llvm::Type::Int32Ty, flags) llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), flags)
}; };
llvm::ArrayType *AT = llvm::ArrayType::get(llvm::Type::Int32Ty, 2); llvm::ArrayType *AT = llvm::ArrayType::get(llvm::Type::getInt32Ty(VMContext), 2);
const char *Section; const char *Section;
if (ObjCABI == 1) if (ObjCABI == 1)
@ -2973,7 +2976,7 @@ llvm::Constant *CGObjCCommonMac::GetClassName(IdentifierInfo *Ident) {
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_CLASS_NAME_", Entry = CreateMetadataVar("\01L_OBJC_CLASS_NAME_",
llvm::ConstantArray::get(Ident->getName()), llvm::ConstantArray::get(VMContext, Ident->getName()),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3191,7 +3194,7 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
bool hasUnion = false; bool hasUnion = false;
unsigned int WordsToScan, WordsToSkip; unsigned int WordsToScan, WordsToSkip;
const llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *PtrTy = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
if (CGM.getLangOptions().getGCMode() == LangOptions::NonGC) if (CGM.getLangOptions().getGCMode() == LangOptions::NonGC)
return llvm::Constant::getNullValue(PtrTy); return llvm::Constant::getNullValue(PtrTy);
@ -3357,7 +3360,7 @@ llvm::Constant *CGObjCCommonMac::BuildIvarLayout(
return llvm::Constant::getNullValue(PtrTy); return llvm::Constant::getNullValue(PtrTy);
llvm::GlobalVariable * Entry = llvm::GlobalVariable * Entry =
CreateMetadataVar("\01L_OBJC_CLASS_NAME_", CreateMetadataVar("\01L_OBJC_CLASS_NAME_",
llvm::ConstantArray::get(BitMap.c_str()), llvm::ConstantArray::get(VMContext, BitMap.c_str()),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
return getConstantGEP(VMContext, Entry, 0, 0); return getConstantGEP(VMContext, Entry, 0, 0);
@ -3369,7 +3372,7 @@ llvm::Constant *CGObjCCommonMac::GetMethodVarName(Selector Sel) {
// FIXME: Avoid std::string copying. // FIXME: Avoid std::string copying.
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_NAME_", Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_NAME_",
llvm::ConstantArray::get(Sel.getAsString()), llvm::ConstantArray::get(VMContext, Sel.getAsString()),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3394,7 +3397,7 @@ llvm::Constant *CGObjCCommonMac::GetMethodVarType(const FieldDecl *Field) {
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_TYPE_", Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_TYPE_",
llvm::ConstantArray::get(TypeStr), llvm::ConstantArray::get(VMContext, TypeStr),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3410,7 +3413,7 @@ llvm::Constant *CGObjCCommonMac::GetMethodVarType(const ObjCMethodDecl *D) {
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_TYPE_", Entry = CreateMetadataVar("\01L_OBJC_METH_VAR_TYPE_",
llvm::ConstantArray::get(TypeStr), llvm::ConstantArray::get(VMContext, TypeStr),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3423,7 +3426,7 @@ llvm::Constant *CGObjCCommonMac::GetPropertyName(IdentifierInfo *Ident) {
if (!Entry) if (!Entry)
Entry = CreateMetadataVar("\01L_OBJC_PROP_NAME_ATTR_", Entry = CreateMetadataVar("\01L_OBJC_PROP_NAME_ATTR_",
llvm::ConstantArray::get(Ident->getName()), llvm::ConstantArray::get(VMContext, Ident->getName()),
"__TEXT,__cstring,cstring_literals", "__TEXT,__cstring,cstring_literals",
1, true); 1, true);
@ -3525,7 +3528,7 @@ ObjCCommonTypesHelper::ObjCCommonTypesHelper(CodeGen::CodeGenModule &cgm)
IntTy = Types.ConvertType(Ctx.IntTy); IntTy = Types.ConvertType(Ctx.IntTy);
LongTy = Types.ConvertType(Ctx.LongTy); LongTy = Types.ConvertType(Ctx.LongTy);
LongLongTy = Types.ConvertType(Ctx.LongLongTy); LongLongTy = Types.ConvertType(Ctx.LongLongTy);
Int8PtrTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); Int8PtrTy = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
ObjectPtrTy = Types.ConvertType(Ctx.getObjCIdType()); ObjectPtrTy = Types.ConvertType(Ctx.getObjCIdType());
PtrObjectPtrTy = llvm::PointerType::getUnqual(ObjectPtrTy); PtrObjectPtrTy = llvm::PointerType::getUnqual(ObjectPtrTy);
@ -3814,10 +3817,10 @@ ObjCTypesHelper::ObjCTypesHelper(CodeGen::CodeGenModule &cgm)
// Exceptions // Exceptions
const llvm::Type *StackPtrTy = llvm::ArrayType::get( const llvm::Type *StackPtrTy = llvm::ArrayType::get(
llvm::PointerType::getUnqual(llvm::Type::Int8Ty), 4); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext)), 4);
ExceptionDataTy = ExceptionDataTy =
llvm::StructType::get(VMContext, llvm::ArrayType::get(llvm::Type::Int32Ty, llvm::StructType::get(VMContext, llvm::ArrayType::get(llvm::Type::getInt32Ty(VMContext),
SetJmpBufferSize), SetJmpBufferSize),
StackPtrTy, NULL); StackPtrTy, NULL);
CGM.getModule().addTypeName("struct._objc_exception_data", CGM.getModule().addTypeName("struct._objc_exception_data",
@ -5548,7 +5551,7 @@ CGObjCNonFragileABIMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
llvm::SmallVector<llvm::Value*, 8> Args; llvm::SmallVector<llvm::Value*, 8> Args;
Args.push_back(Exc); Args.push_back(Exc);
Args.push_back(ObjCTypes.getEHPersonalityPtr()); Args.push_back(ObjCTypes.getEHPersonalityPtr());
Args.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
0)); 0));
CGF.Builder.CreateCall(llvm_eh_selector_i64, Args.begin(), Args.end()); CGF.Builder.CreateCall(llvm_eh_selector_i64, Args.begin(), Args.end());
CGF.Builder.CreateStore(Exc, RethrowPtr); CGF.Builder.CreateStore(Exc, RethrowPtr);
@ -5580,7 +5583,7 @@ CGObjCNonFragileABIMac::EmitTryOrSynchronizedStmt(CodeGen::CodeGenFunction &CGF,
Args.clear(); Args.clear();
Args.push_back(Exc); Args.push_back(Exc);
Args.push_back(ObjCTypes.getEHPersonalityPtr()); Args.push_back(ObjCTypes.getEHPersonalityPtr());
Args.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Args.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
0)); 0));
CGF.Builder.CreateCall(llvm_eh_selector_i64, Args.begin(), Args.end()); CGF.Builder.CreateCall(llvm_eh_selector_i64, Args.begin(), Args.end());
CGF.Builder.CreateStore(Exc, RethrowPtr); CGF.Builder.CreateStore(Exc, RethrowPtr);
@ -5693,7 +5696,7 @@ CGObjCNonFragileABIMac::GetInterfaceEHType(const ObjCInterfaceDecl *ID,
llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::ExternalLinkage,
0, VTableName); 0, VTableName);
llvm::Value *VTableIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, 2); llvm::Value *VTableIdx = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 2);
std::vector<llvm::Constant*> Values(3); std::vector<llvm::Constant*> Values(3);
Values[0] = llvm::ConstantExpr::getGetElementPtr(VTableGV, &VTableIdx, 1); Values[0] = llvm::ConstantExpr::getGetElementPtr(VTableGV, &VTableIdx, 1);

View File

@ -282,7 +282,7 @@ void CGRecordLayoutBuilder::AppendBytes(uint64_t NumBytes) {
if (NumBytes == 0) if (NumBytes == 0)
return; return;
const llvm::Type *Ty = llvm::Type::Int8Ty; const llvm::Type *Ty = llvm::Type::getInt8Ty(Types.getLLVMContext());
if (NumBytes > 1) if (NumBytes > 1)
Ty = llvm::ArrayType::get(Ty, NumBytes); Ty = llvm::ArrayType::get(Ty, NumBytes);

View File

@ -282,7 +282,7 @@ void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
// EmitIndirectSwitches(). We need a default dest, so we use the // EmitIndirectSwitches(). We need a default dest, so we use the
// current BB, but this is overwritten. // current BB, but this is overwritten.
llvm::Value *V = Builder.CreatePtrToInt(EmitScalarExpr(S.getTarget()), llvm::Value *V = Builder.CreatePtrToInt(EmitScalarExpr(S.getTarget()),
llvm::Type::Int32Ty, llvm::Type::getInt32Ty(VMContext),
"addr"); "addr");
llvm::SwitchInst *I = Builder.CreateSwitch(V, Builder.GetInsertBlock()); llvm::SwitchInst *I = Builder.CreateSwitch(V, Builder.GetInsertBlock());
IndirectSwitches.push_back(I); IndirectSwitches.push_back(I);
@ -780,7 +780,7 @@ llvm::Value* CodeGenFunction::EmitAsmInput(const AsmStmt &S,
uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty); uint64_t Size = CGM.getTargetData().getTypeSizeInBits(Ty);
if (Size <= 64 && llvm::isPowerOf2_64(Size)) { if (Size <= 64 && llvm::isPowerOf2_64(Size)) {
Ty = llvm::IntegerType::get(Size); Ty = llvm::IntegerType::get(VMContext, Size);
Ty = llvm::PointerType::getUnqual(Ty); Ty = llvm::PointerType::getUnqual(Ty);
Arg = Builder.CreateLoad(Builder.CreateBitCast(Dest.getAddress(), Ty)); Arg = Builder.CreateLoad(Builder.CreateBitCast(Dest.getAddress(), Ty));
@ -896,7 +896,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
uint64_t InputSize = getContext().getTypeSize(InputTy); uint64_t InputSize = getContext().getTypeSize(InputTy);
if (getContext().getTypeSize(OutputTy) < InputSize) { if (getContext().getTypeSize(OutputTy) < InputSize) {
// Form the asm to return the value as a larger integer type. // Form the asm to return the value as a larger integer type.
ResultRegTypes.back() = llvm::IntegerType::get((unsigned)InputSize); ResultRegTypes.back() = llvm::IntegerType::get(VMContext, (unsigned)InputSize);
} }
} }
} else { } else {
@ -954,9 +954,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
// Use ptrtoint as appropriate so that we can do our extension. // Use ptrtoint as appropriate so that we can do our extension.
if (isa<llvm::PointerType>(Arg->getType())) if (isa<llvm::PointerType>(Arg->getType()))
Arg = Builder.CreatePtrToInt(Arg, Arg = Builder.CreatePtrToInt(Arg,
llvm::IntegerType::get(LLVMPointerWidth)); llvm::IntegerType::get(VMContext, LLVMPointerWidth));
unsigned OutputSize = (unsigned)getContext().getTypeSize(OutputTy); unsigned OutputSize = (unsigned)getContext().getTypeSize(OutputTy);
Arg = Builder.CreateZExt(Arg, llvm::IntegerType::get(OutputSize)); Arg = Builder.CreateZExt(Arg, llvm::IntegerType::get(VMContext, OutputSize));
} }
} }
@ -998,7 +998,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
const llvm::Type *ResultType; const llvm::Type *ResultType;
if (ResultRegTypes.empty()) if (ResultRegTypes.empty())
ResultType = llvm::Type::VoidTy; ResultType = llvm::Type::getVoidTy(VMContext);
else if (ResultRegTypes.size() == 1) else if (ResultRegTypes.size() == 1)
ResultType = ResultRegTypes[0]; ResultType = ResultRegTypes[0];
else else
@ -1035,7 +1035,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
// Truncate the integer result to the right size, note that // Truncate the integer result to the right size, note that
// ResultTruncRegTypes can be a pointer. // ResultTruncRegTypes can be a pointer.
uint64_t ResSize = CGM.getTargetData().getTypeSizeInBits(TruncTy); uint64_t ResSize = CGM.getTargetData().getTypeSizeInBits(TruncTy);
Tmp = Builder.CreateTrunc(Tmp, llvm::IntegerType::get((unsigned)ResSize)); Tmp = Builder.CreateTrunc(Tmp, llvm::IntegerType::get(VMContext, (unsigned)ResSize));
if (Tmp->getType() != TruncTy) { if (Tmp->getType() != TruncTy) {
assert(isa<llvm::PointerType>(TruncTy)); assert(isa<llvm::PointerType>(TruncTy));

View File

@ -156,8 +156,8 @@ void CodeGenFunction::StartFunction(const Decl *D, QualType RetTy,
// Create a marker to make it easy to insert allocas into the entryblock // Create a marker to make it easy to insert allocas into the entryblock
// later. Don't create this with the builder, because we don't want it // later. Don't create this with the builder, because we don't want it
// folded. // folded.
llvm::Value *Undef = llvm::UndefValue::get(llvm::Type::Int32Ty); llvm::Value *Undef = llvm::UndefValue::get(llvm::Type::getInt32Ty(VMContext));
AllocaInsertPt = new llvm::BitCastInst(Undef, llvm::Type::Int32Ty, "", AllocaInsertPt = new llvm::BitCastInst(Undef, llvm::Type::getInt32Ty(VMContext), "",
EntryBB); EntryBB);
if (Builder.isNamePreserving()) if (Builder.isNamePreserving())
AllocaInsertPt->setName("allocapt"); AllocaInsertPt->setName("allocapt");
@ -424,7 +424,7 @@ unsigned CodeGenFunction::GetIDForAddrOfLabel(const LabelStmt *L) {
} }
void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) { void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) {
const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
if (DestPtr->getType() != BP) if (DestPtr->getType() != BP)
DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp"); DestPtr = Builder.CreateBitCast(DestPtr, BP, "tmp");
@ -436,13 +436,14 @@ void CodeGenFunction::EmitMemSetToZero(llvm::Value *DestPtr, QualType Ty) {
return; return;
// FIXME: Handle variable sized types. // FIXME: Handle variable sized types.
const llvm::Type *IntPtr = llvm::IntegerType::get(LLVMPointerWidth); const llvm::Type *IntPtr = llvm::IntegerType::get(VMContext,
LLVMPointerWidth);
Builder.CreateCall4(CGM.getMemSetFn(), DestPtr, Builder.CreateCall4(CGM.getMemSetFn(), DestPtr,
llvm::Constant::getNullValue(llvm::Type::Int8Ty), llvm::Constant::getNullValue(llvm::Type::getInt8Ty(VMContext)),
// TypeInfo.first describes size in bits. // TypeInfo.first describes size in bits.
llvm::ConstantInt::get(IntPtr, TypeInfo.first/8), llvm::ConstantInt::get(IntPtr, TypeInfo.first/8),
llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
TypeInfo.second/8)); TypeInfo.second/8));
} }
@ -468,7 +469,7 @@ void CodeGenFunction::EmitIndirectSwitches() {
I->setSuccessor(0, Default); I->setSuccessor(0, Default);
for (std::map<const LabelStmt*,unsigned>::iterator LI = LabelIDs.begin(), for (std::map<const LabelStmt*,unsigned>::iterator LI = LabelIDs.begin(),
LE = LabelIDs.end(); LI != LE; ++LI) { LE = LabelIDs.end(); LI != LE; ++LI) {
I->addCase(llvm::ConstantInt::get(llvm::Type::Int32Ty, I->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
LI->second), LI->second),
getBasicBlockForLabel(LI->first)); getBasicBlockForLabel(LI->first));
} }
@ -590,7 +591,7 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
Builder.SetInsertPoint(SwitchBlock); Builder.SetInsertPoint(SwitchBlock);
llvm::Value *DestCodePtr = CreateTempAlloca(llvm::Type::Int32Ty, llvm::Value *DestCodePtr = CreateTempAlloca(llvm::Type::getInt32Ty(VMContext),
"cleanup.dst"); "cleanup.dst");
llvm::Value *DestCode = Builder.CreateLoad(DestCodePtr, "tmp"); llvm::Value *DestCode = Builder.CreateLoad(DestCodePtr, "tmp");
@ -604,7 +605,7 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
// If we had a current basic block, we also need to emit an instruction // If we had a current basic block, we also need to emit an instruction
// to initialize the cleanup destination. // to initialize the cleanup destination.
Builder.CreateStore(llvm::Constant::getNullValue(llvm::Type::Int32Ty), Builder.CreateStore(llvm::Constant::getNullValue(llvm::Type::getInt32Ty(VMContext)),
DestCodePtr); DestCodePtr);
} else } else
Builder.ClearInsertionPoint(); Builder.ClearInsertionPoint();
@ -621,13 +622,13 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
// Check if we already have a destination for this block. // Check if we already have a destination for this block.
if (Dest == SI->getDefaultDest()) if (Dest == SI->getDefaultDest())
ID = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0); ID = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 0);
else { else {
ID = SI->findCaseDest(Dest); ID = SI->findCaseDest(Dest);
if (!ID) { if (!ID) {
// No code found, get a new unique one by using the number of // No code found, get a new unique one by using the number of
// switch successors. // switch successors.
ID = llvm::ConstantInt::get(llvm::Type::Int32Ty, ID = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
SI->getNumSuccessors()); SI->getNumSuccessors());
SI->addCase(ID, Dest); SI->addCase(ID, Dest);
} }
@ -644,7 +645,7 @@ CodeGenFunction::CleanupBlockInfo CodeGenFunction::PopCleanupBlock()
llvm::BasicBlock *CleanupPad = createBasicBlock("cleanup.pad", CurFn); llvm::BasicBlock *CleanupPad = createBasicBlock("cleanup.pad", CurFn);
// Create a unique case ID. // Create a unique case ID.
llvm::ConstantInt *ID = llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::ConstantInt *ID = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
SI->getNumSuccessors()); SI->getNumSuccessors());
// Store the jump destination before the branch instruction. // Store the jump destination before the branch instruction.

View File

@ -424,9 +424,9 @@ public:
llvm::Function *Parent=0, llvm::Function *Parent=0,
llvm::BasicBlock *InsertBefore=0) { llvm::BasicBlock *InsertBefore=0) {
#ifdef NDEBUG #ifdef NDEBUG
return llvm::BasicBlock::Create("", Parent, InsertBefore); return llvm::BasicBlock::Create(VMContext, "", Parent, InsertBefore);
#else #else
return llvm::BasicBlock::Create(Name, Parent, InsertBefore); return llvm::BasicBlock::Create(VMContext, Name, Parent, InsertBefore);
#endif #endif
} }

View File

@ -199,22 +199,22 @@ void CodeGenModule::AddGlobalDtor(llvm::Function * Dtor, int Priority) {
void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) { void CodeGenModule::EmitCtorList(const CtorList &Fns, const char *GlobalName) {
// Ctor function type is void()*. // Ctor function type is void()*.
llvm::FunctionType* CtorFTy = llvm::FunctionType* CtorFTy =
llvm::FunctionType::get(llvm::Type::VoidTy, llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
std::vector<const llvm::Type*>(), std::vector<const llvm::Type*>(),
false); false);
llvm::Type *CtorPFTy = llvm::PointerType::getUnqual(CtorFTy); llvm::Type *CtorPFTy = llvm::PointerType::getUnqual(CtorFTy);
// Get the type of a ctor entry, { i32, void ()* }. // Get the type of a ctor entry, { i32, void ()* }.
llvm::StructType* CtorStructTy = llvm::StructType* CtorStructTy =
llvm::StructType::get(VMContext, llvm::Type::Int32Ty, llvm::StructType::get(VMContext, llvm::Type::getInt32Ty(VMContext),
llvm::PointerType::getUnqual(CtorFTy), NULL); llvm::PointerType::getUnqual(CtorFTy), NULL);
// Construct the constructor and destructor arrays. // Construct the constructor and destructor arrays.
std::vector<llvm::Constant*> Ctors; std::vector<llvm::Constant*> Ctors;
for (CtorList::const_iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) { for (CtorList::const_iterator I = Fns.begin(), E = Fns.end(); I != E; ++I) {
std::vector<llvm::Constant*> S; std::vector<llvm::Constant*> S;
S.push_back( S.push_back(llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
llvm::ConstantInt::get(llvm::Type::Int32Ty, I->second, false)); I->second, false));
S.push_back(llvm::ConstantExpr::getBitCast(I->first, CtorPFTy)); S.push_back(llvm::ConstantExpr::getBitCast(I->first, CtorPFTy));
Ctors.push_back(llvm::ConstantStruct::get(CtorStructTy, S)); Ctors.push_back(llvm::ConstantStruct::get(CtorStructTy, S));
} }
@ -421,7 +421,8 @@ void CodeGenModule::EmitLLVMUsed() {
if (LLVMUsed.empty()) if (LLVMUsed.empty())
return; return;
llvm::Type *i8PTy = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::Type *i8PTy =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
// Convert LLVMUsed to what ConstantArray needs. // Convert LLVMUsed to what ConstantArray needs.
std::vector<llvm::Constant*> UsedArray; std::vector<llvm::Constant*> UsedArray;
@ -486,9 +487,12 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
// get [N x i8] constants for the annotation string, and the filename string // get [N x i8] constants for the annotation string, and the filename string
// which are the 2nd and 3rd elements of the global annotation structure. // which are the 2nd and 3rd elements of the global annotation structure.
const llvm::Type *SBP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *SBP =
llvm::Constant *anno = llvm::ConstantArray::get(AA->getAnnotation(), true); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
llvm::Constant *unit = llvm::ConstantArray::get(M->getModuleIdentifier(), llvm::Constant *anno = llvm::ConstantArray::get(VMContext,
AA->getAnnotation(), true);
llvm::Constant *unit = llvm::ConstantArray::get(VMContext,
M->getModuleIdentifier(),
true); true);
// Get the two global values corresponding to the ConstantArrays we just // Get the two global values corresponding to the ConstantArrays we just
@ -508,7 +512,7 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV,
llvm::ConstantExpr::getBitCast(GV, SBP), llvm::ConstantExpr::getBitCast(GV, SBP),
llvm::ConstantExpr::getBitCast(annoGV, SBP), llvm::ConstantExpr::getBitCast(annoGV, SBP),
llvm::ConstantExpr::getBitCast(unitGV, SBP), llvm::ConstantExpr::getBitCast(unitGV, SBP),
llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo) llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), LineNo)
}; };
return llvm::ConstantStruct::get(VMContext, Fields, 4, false); return llvm::ConstantStruct::get(VMContext, Fields, 4, false);
} }
@ -663,7 +667,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(const char *MangledName,
// sure not to try to set attributes. // sure not to try to set attributes.
bool IsIncompleteFunction = false; bool IsIncompleteFunction = false;
if (!isa<llvm::FunctionType>(Ty)) { if (!isa<llvm::FunctionType>(Ty)) {
Ty = llvm::FunctionType::get(llvm::Type::VoidTy, Ty = llvm::FunctionType::get(llvm::Type::getVoidTy(VMContext),
std::vector<const llvm::Type*>(), false); std::vector<const llvm::Type*>(), false);
IsIncompleteFunction = true; IsIncompleteFunction = true;
} }
@ -1057,7 +1061,7 @@ static void ReplaceUsesOfNonProtoTypeWithRealFunction(llvm::GlobalValue *Old,
llvm::CallInst *NewCall = llvm::CallInst::Create(NewFn, ArgList.begin(), llvm::CallInst *NewCall = llvm::CallInst::Create(NewFn, ArgList.begin(),
ArgList.end(), "", CI); ArgList.end(), "", CI);
ArgList.clear(); ArgList.clear();
if (NewCall->getType() != llvm::Type::VoidTy) if (NewCall->getType() != llvm::Type::getVoidTy(Old->getContext()))
NewCall->takeName(CI); NewCall->takeName(CI);
NewCall->setCallingConv(CI->getCallingConv()); NewCall->setCallingConv(CI->getCallingConv());
NewCall->setAttributes(CI->getAttributes()); NewCall->setAttributes(CI->getAttributes());
@ -1264,19 +1268,19 @@ llvm::Function *CodeGenModule::getIntrinsic(unsigned IID,const llvm::Type **Tys,
llvm::Function *CodeGenModule::getMemCpyFn() { llvm::Function *CodeGenModule::getMemCpyFn() {
if (MemCpyFn) return MemCpyFn; if (MemCpyFn) return MemCpyFn;
const llvm::Type *IntPtr = TheTargetData.getIntPtrType(); const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
return MemCpyFn = getIntrinsic(llvm::Intrinsic::memcpy, &IntPtr, 1); return MemCpyFn = getIntrinsic(llvm::Intrinsic::memcpy, &IntPtr, 1);
} }
llvm::Function *CodeGenModule::getMemMoveFn() { llvm::Function *CodeGenModule::getMemMoveFn() {
if (MemMoveFn) return MemMoveFn; if (MemMoveFn) return MemMoveFn;
const llvm::Type *IntPtr = TheTargetData.getIntPtrType(); const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
return MemMoveFn = getIntrinsic(llvm::Intrinsic::memmove, &IntPtr, 1); return MemMoveFn = getIntrinsic(llvm::Intrinsic::memmove, &IntPtr, 1);
} }
llvm::Function *CodeGenModule::getMemSetFn() { llvm::Function *CodeGenModule::getMemSetFn() {
if (MemSetFn) return MemSetFn; if (MemSetFn) return MemSetFn;
const llvm::Type *IntPtr = TheTargetData.getIntPtrType(); const llvm::Type *IntPtr = TheTargetData.getIntPtrType(VMContext);
return MemSetFn = getIntrinsic(llvm::Intrinsic::memset, &IntPtr, 1); return MemSetFn = getIntrinsic(llvm::Intrinsic::memset, &IntPtr, 1);
} }
@ -1379,7 +1383,8 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
if (llvm::Constant *C = Entry.getValue()) if (llvm::Constant *C = Entry.getValue())
return C; return C;
llvm::Constant *Zero = llvm::Constant::getNullValue(llvm::Type::Int32Ty); llvm::Constant *Zero =
llvm::Constant::getNullValue(llvm::Type::getInt32Ty(VMContext));
llvm::Constant *Zeros[] = { Zero, Zero }; llvm::Constant *Zeros[] = { Zero, Zero };
// If we don't already have it, get __CFConstantStringClassReference. // If we don't already have it, get __CFConstantStringClassReference.
@ -1420,7 +1425,7 @@ CodeGenModule::GetAddrOfConstantCFString(const StringLiteral *Literal) {
// String pointer. // String pointer.
CurField = NextField; CurField = NextField;
NextField = *Field++; NextField = *Field++;
llvm::Constant *C = llvm::ConstantArray::get(Entry.getKey().str()); llvm::Constant *C = llvm::ConstantArray::get(VMContext, Entry.getKey().str());
const char *Sect, *Prefix; const char *Sect, *Prefix;
bool isConstant; bool isConstant;
@ -1519,7 +1524,8 @@ static llvm::Constant *GenerateStringLiteral(const std::string &str,
CodeGenModule &CGM, CodeGenModule &CGM,
const char *GlobalName) { const char *GlobalName) {
// Create Constant for this string literal. Don't add a '\0'. // Create Constant for this string literal. Don't add a '\0'.
llvm::Constant *C = llvm::ConstantArray::get(str, false); llvm::Constant *C =
llvm::ConstantArray::get(CGM.getLLVMContext(), str, false);
// Create a global variable for this string // Create a global variable for this string
return new llvm::GlobalVariable(CGM.getModule(), C->getType(), constant, return new llvm::GlobalVariable(CGM.getModule(), C->getType(), constant,

View File

@ -82,8 +82,9 @@ const llvm::Type *CodeGenTypes::ConvertTypeRecursive(QualType T) {
const llvm::Type *CodeGenTypes::ConvertTypeForMemRecursive(QualType T) { const llvm::Type *CodeGenTypes::ConvertTypeForMemRecursive(QualType T) {
const llvm::Type *ResultType = ConvertTypeRecursive(T); const llvm::Type *ResultType = ConvertTypeRecursive(T);
if (ResultType == llvm::Type::Int1Ty) if (ResultType == llvm::Type::getInt1Ty(getLLVMContext()))
return llvm::IntegerType::get((unsigned)Context.getTypeSize(T)); return llvm::IntegerType::get(getLLVMContext(),
(unsigned)Context.getTypeSize(T));
return ResultType; return ResultType;
} }
@ -95,11 +96,12 @@ const llvm::Type *CodeGenTypes::ConvertTypeForMem(QualType T) {
const llvm::Type *R = ConvertType(T); const llvm::Type *R = ConvertType(T);
// If this is a non-bool type, don't map it. // If this is a non-bool type, don't map it.
if (R != llvm::Type::Int1Ty) if (R != llvm::Type::getInt1Ty(getLLVMContext()))
return R; return R;
// Otherwise, return an integer of the target-specified size. // Otherwise, return an integer of the target-specified size.
return llvm::IntegerType::get((unsigned)Context.getTypeSize(T)); return llvm::IntegerType::get(getLLVMContext(),
(unsigned)Context.getTypeSize(T));
} }
@ -161,17 +163,18 @@ void CodeGenTypes::UpdateCompletedType(const TagDecl *TD) {
} }
} }
static const llvm::Type* getTypeForFormat(const llvm::fltSemantics &format) { static const llvm::Type* getTypeForFormat(llvm::LLVMContext &VMContext,
const llvm::fltSemantics &format) {
if (&format == &llvm::APFloat::IEEEsingle) if (&format == &llvm::APFloat::IEEEsingle)
return llvm::Type::FloatTy; return llvm::Type::getFloatTy(VMContext);
if (&format == &llvm::APFloat::IEEEdouble) if (&format == &llvm::APFloat::IEEEdouble)
return llvm::Type::DoubleTy; return llvm::Type::getDoubleTy(VMContext);
if (&format == &llvm::APFloat::IEEEquad) if (&format == &llvm::APFloat::IEEEquad)
return llvm::Type::FP128Ty; return llvm::Type::getFP128Ty(VMContext);
if (&format == &llvm::APFloat::PPCDoubleDouble) if (&format == &llvm::APFloat::PPCDoubleDouble)
return llvm::Type::PPC_FP128Ty; return llvm::Type::getPPC_FP128Ty(VMContext);
if (&format == &llvm::APFloat::x87DoubleExtended) if (&format == &llvm::APFloat::x87DoubleExtended)
return llvm::Type::X86_FP80Ty; return llvm::Type::getX86_FP80Ty(VMContext);
assert(0 && "Unknown float format!"); assert(0 && "Unknown float format!");
return 0; return 0;
} }
@ -196,11 +199,11 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
case BuiltinType::ObjCClass: case BuiltinType::ObjCClass:
// LLVM void type can only be used as the result of a function call. Just // LLVM void type can only be used as the result of a function call. Just
// map to the same as char. // map to the same as char.
return llvm::IntegerType::get(8); return llvm::IntegerType::get(getLLVMContext(), 8);
case BuiltinType::Bool: case BuiltinType::Bool:
// Note that we always return bool as i1 for use as a scalar type. // Note that we always return bool as i1 for use as a scalar type.
return llvm::Type::Int1Ty; return llvm::Type::getInt1Ty(getLLVMContext());
case BuiltinType::Char_S: case BuiltinType::Char_S:
case BuiltinType::Char_U: case BuiltinType::Char_U:
@ -217,22 +220,24 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) {
case BuiltinType::WChar: case BuiltinType::WChar:
case BuiltinType::Char16: case BuiltinType::Char16:
case BuiltinType::Char32: case BuiltinType::Char32:
return llvm::IntegerType::get( return llvm::IntegerType::get(getLLVMContext(),
static_cast<unsigned>(Context.getTypeSize(T))); static_cast<unsigned>(Context.getTypeSize(T)));
case BuiltinType::Float: case BuiltinType::Float:
case BuiltinType::Double: case BuiltinType::Double:
case BuiltinType::LongDouble: case BuiltinType::LongDouble:
return getTypeForFormat(Context.getFloatTypeSemantics(T)); return getTypeForFormat(getLLVMContext(),
Context.getFloatTypeSemantics(T));
case BuiltinType::UInt128: case BuiltinType::UInt128:
case BuiltinType::Int128: case BuiltinType::Int128:
return llvm::IntegerType::get(128); return llvm::IntegerType::get(getLLVMContext(), 128);
} }
break; break;
} }
case Type::FixedWidthInt: case Type::FixedWidthInt:
return llvm::IntegerType::get(cast<FixedWidthIntType>(T)->getWidth()); return llvm::IntegerType::get(getLLVMContext(),
cast<FixedWidthIntType>(T)->getWidth());
case Type::Complex: { case Type::Complex: {
const llvm::Type *EltTy = const llvm::Type *EltTy =
ConvertTypeRecursive(cast<ComplexType>(Ty).getElementType()); ConvertTypeRecursive(cast<ComplexType>(Ty).getElementType());

View File

@ -307,15 +307,14 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
// registers and we need to make sure to pick a type the LLVM // registers and we need to make sure to pick a type the LLVM
// backend will like. // backend will like.
if (Size == 128) if (Size == 128)
return return ABIArgInfo::getCoerce(llvm::VectorType::get(
ABIArgInfo::getCoerce(llvm::VectorType::get(llvm::Type::Int64Ty, llvm::Type::getInt64Ty(VMContext), 2));
2));
// Always return in register if it fits in a general purpose // Always return in register if it fits in a general purpose
// register, or if it is 64 bits and has a single element. // register, or if it is 64 bits and has a single element.
if ((Size == 8 || Size == 16 || Size == 32) || if ((Size == 8 || Size == 16 || Size == 32) ||
(Size == 64 && VT->getNumElements() == 1)) (Size == 64 && VT->getNumElements() == 1))
return ABIArgInfo::getCoerce(llvm::IntegerType::get(Size)); return ABIArgInfo::getCoerce(llvm::IntegerType::get(VMContext, Size));
return ABIArgInfo::getIndirect(0); return ABIArgInfo::getIndirect(0);
} }
@ -340,21 +339,21 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
// element type. // element type.
uint64_t Size = Context.getTypeSize(RetTy); uint64_t Size = Context.getTypeSize(RetTy);
return ABIArgInfo::getCoerce( return ABIArgInfo::getCoerce(
llvm::IntegerType::get((unsigned) Size)); llvm::IntegerType::get(VMContext, (unsigned) Size));
} else if (BT->getKind() == BuiltinType::Float) { } else if (BT->getKind() == BuiltinType::Float) {
assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) && assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
"Unexpect single element structure size!"); "Unexpect single element structure size!");
return ABIArgInfo::getCoerce(llvm::Type::FloatTy); return ABIArgInfo::getCoerce(llvm::Type::getFloatTy(VMContext));
} else if (BT->getKind() == BuiltinType::Double) { } else if (BT->getKind() == BuiltinType::Double) {
assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) && assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
"Unexpect single element structure size!"); "Unexpect single element structure size!");
return ABIArgInfo::getCoerce(llvm::Type::DoubleTy); return ABIArgInfo::getCoerce(llvm::Type::getDoubleTy(VMContext));
} }
} else if (SeltTy->isPointerType()) { } else if (SeltTy->isPointerType()) {
// FIXME: It would be really nice if this could come out as the proper // FIXME: It would be really nice if this could come out as the proper
// pointer type. // pointer type.
llvm::Type *PtrTy = llvm::Type *PtrTy =
llvm::PointerType::getUnqual(llvm::Type::Int8Ty); llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(VMContext));
return ABIArgInfo::getCoerce(PtrTy); return ABIArgInfo::getCoerce(PtrTy);
} else if (SeltTy->isVectorType()) { } else if (SeltTy->isVectorType()) {
// 64- and 128-bit vectors are never returned in a // 64- and 128-bit vectors are never returned in a
@ -371,7 +370,7 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
// in a register. // in a register.
if (X86_32ABIInfo::shouldReturnTypeInRegister(RetTy, Context)) { if (X86_32ABIInfo::shouldReturnTypeInRegister(RetTy, Context)) {
uint64_t Size = Context.getTypeSize(RetTy); uint64_t Size = Context.getTypeSize(RetTy);
return ABIArgInfo::getCoerce(llvm::IntegerType::get(Size)); return ABIArgInfo::getCoerce(llvm::IntegerType::get(VMContext, Size));
} }
return ABIArgInfo::getIndirect(0); return ABIArgInfo::getIndirect(0);
@ -424,7 +423,7 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty,
llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
CodeGenFunction &CGF) const { CodeGenFunction &CGF) const {
const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(CGF.getLLVMContext()));
const llvm::Type *BPP = llvm::PointerType::getUnqual(BP); const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
CGBuilderTy &Builder = CGF.Builder; CGBuilderTy &Builder = CGF.Builder;
@ -438,8 +437,8 @@ llvm::Value *X86_32ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
uint64_t Offset = uint64_t Offset =
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4); llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
llvm::Value *NextAddr = llvm::Value *NextAddr =
Builder.CreateGEP(Addr, Builder.CreateGEP(Addr, llvm::ConstantInt::get(
llvm::ConstantInt::get(llvm::Type::Int32Ty, Offset), llvm::Type::getInt32Ty(CGF.getLLVMContext()), Offset),
"ap.next"); "ap.next");
Builder.CreateStore(NextAddr, VAListAddrAsBPP); Builder.CreateStore(NextAddr, VAListAddrAsBPP);
@ -796,13 +795,13 @@ void X86_64ABIInfo::classify(QualType Ty,
ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty, ABIArgInfo X86_64ABIInfo::getCoerceResult(QualType Ty,
const llvm::Type *CoerceTo, const llvm::Type *CoerceTo,
ASTContext &Context) const { ASTContext &Context) const {
if (CoerceTo == llvm::Type::Int64Ty) { if (CoerceTo == llvm::Type::getInt64Ty(CoerceTo->getContext())) {
// Integer and pointer types will end up in a general purpose // Integer and pointer types will end up in a general purpose
// register. // register.
if (Ty->isIntegralType() || Ty->isPointerType()) if (Ty->isIntegralType() || Ty->isPointerType())
return (Ty->isPromotableIntegerType() ? return (Ty->isPromotableIntegerType() ?
ABIArgInfo::getExtend() : ABIArgInfo::getDirect()); ABIArgInfo::getExtend() : ABIArgInfo::getDirect());
} else if (CoerceTo == llvm::Type::DoubleTy) { } else if (CoerceTo == llvm::Type::getDoubleTy(CoerceTo->getContext())) {
// FIXME: It would probably be better to make CGFunctionInfo only map using // FIXME: It would probably be better to make CGFunctionInfo only map using
// canonical types than to canonize here. // canonical types than to canonize here.
QualType CTy = Context.getCanonicalType(Ty); QualType CTy = Context.getCanonicalType(Ty);
@ -858,25 +857,25 @@ ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy,
// AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next // AMD64-ABI 3.2.3p4: Rule 3. If the class is INTEGER, the next
// available register of the sequence %rax, %rdx is used. // available register of the sequence %rax, %rdx is used.
case Integer: case Integer:
ResType = llvm::Type::Int64Ty; break; ResType = llvm::Type::getInt64Ty(VMContext); break;
// AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next // AMD64-ABI 3.2.3p4: Rule 4. If the class is SSE, the next
// available SSE register of the sequence %xmm0, %xmm1 is used. // available SSE register of the sequence %xmm0, %xmm1 is used.
case SSE: case SSE:
ResType = llvm::Type::DoubleTy; break; ResType = llvm::Type::getDoubleTy(VMContext); break;
// AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is // AMD64-ABI 3.2.3p4: Rule 6. If the class is X87, the value is
// returned on the X87 stack in %st0 as 80-bit x87 number. // returned on the X87 stack in %st0 as 80-bit x87 number.
case X87: case X87:
ResType = llvm::Type::X86_FP80Ty; break; ResType = llvm::Type::getX86_FP80Ty(VMContext); break;
// AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real // AMD64-ABI 3.2.3p4: Rule 8. If the class is COMPLEX_X87, the real
// part of the value is returned in %st0 and the imaginary part in // part of the value is returned in %st0 and the imaginary part in
// %st1. // %st1.
case ComplexX87: case ComplexX87:
assert(Hi == ComplexX87 && "Unexpected ComplexX87 classification."); assert(Hi == ComplexX87 && "Unexpected ComplexX87 classification.");
ResType = llvm::StructType::get(VMContext, llvm::Type::X86_FP80Ty, ResType = llvm::StructType::get(VMContext, llvm::Type::getX86_FP80Ty(VMContext),
llvm::Type::X86_FP80Ty, llvm::Type::getX86_FP80Ty(VMContext),
NULL); NULL);
break; break;
} }
@ -893,11 +892,11 @@ ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy,
case Integer: case Integer:
ResType = llvm::StructType::get(VMContext, ResType, ResType = llvm::StructType::get(VMContext, ResType,
llvm::Type::Int64Ty, NULL); llvm::Type::getInt64Ty(VMContext), NULL);
break; break;
case SSE: case SSE:
ResType = llvm::StructType::get(VMContext, ResType, ResType = llvm::StructType::get(VMContext, ResType,
llvm::Type::DoubleTy, NULL); llvm::Type::getDoubleTy(VMContext), NULL);
break; break;
// AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte // AMD64-ABI 3.2.3p4: Rule 5. If the class is SSEUP, the eightbyte
@ -906,7 +905,7 @@ ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy,
// SSEUP should always be preceeded by SSE, just widen. // SSEUP should always be preceeded by SSE, just widen.
case SSEUp: case SSEUp:
assert(Lo == SSE && "Unexpected SSEUp classification."); assert(Lo == SSE && "Unexpected SSEUp classification.");
ResType = llvm::VectorType::get(llvm::Type::DoubleTy, 2); ResType = llvm::VectorType::get(llvm::Type::getDoubleTy(VMContext), 2);
break; break;
// AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is // AMD64-ABI 3.2.3p4: Rule 7. If the class is X87UP, the value is
@ -918,7 +917,7 @@ ABIArgInfo X86_64ABIInfo::classifyReturnType(QualType RetTy,
// extra bits in an SSE reg. // extra bits in an SSE reg.
if (Lo != X87) if (Lo != X87)
ResType = llvm::StructType::get(VMContext, ResType, ResType = llvm::StructType::get(VMContext, ResType,
llvm::Type::DoubleTy, NULL); llvm::Type::getDoubleTy(VMContext), NULL);
break; break;
} }
@ -964,7 +963,7 @@ ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, ASTContext &Context,
// and %r9 is used. // and %r9 is used.
case Integer: case Integer:
++neededInt; ++neededInt;
ResType = llvm::Type::Int64Ty; ResType = llvm::Type::getInt64Ty(VMContext);
break; break;
// AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next // AMD64-ABI 3.2.3p3: Rule 3. If the class is SSE, the next
@ -972,7 +971,7 @@ ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, ASTContext &Context,
// order from %xmm0 to %xmm7. // order from %xmm0 to %xmm7.
case SSE: case SSE:
++neededSSE; ++neededSSE;
ResType = llvm::Type::DoubleTy; ResType = llvm::Type::getDoubleTy(VMContext);
break; break;
} }
@ -989,7 +988,7 @@ ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, ASTContext &Context,
case NoClass: break; case NoClass: break;
case Integer: case Integer:
ResType = llvm::StructType::get(VMContext, ResType, ResType = llvm::StructType::get(VMContext, ResType,
llvm::Type::Int64Ty, NULL); llvm::Type::getInt64Ty(VMContext), NULL);
++neededInt; ++neededInt;
break; break;
@ -998,7 +997,7 @@ ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, ASTContext &Context,
case X87Up: case X87Up:
case SSE: case SSE:
ResType = llvm::StructType::get(VMContext, ResType, ResType = llvm::StructType::get(VMContext, ResType,
llvm::Type::DoubleTy, NULL); llvm::Type::getDoubleTy(VMContext), NULL);
++neededSSE; ++neededSSE;
break; break;
@ -1007,7 +1006,7 @@ ABIArgInfo X86_64ABIInfo::classifyArgumentType(QualType Ty, ASTContext &Context,
// register. // register.
case SSEUp: case SSEUp:
assert(Lo == SSE && "Unexpected SSEUp classification."); assert(Lo == SSE && "Unexpected SSEUp classification.");
ResType = llvm::VectorType::get(llvm::Type::DoubleTy, 2); ResType = llvm::VectorType::get(llvm::Type::getDoubleTy(VMContext), 2);
break; break;
} }
@ -1065,11 +1064,13 @@ static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr,
// shouldn't ever matter in practice. // shouldn't ever matter in practice.
// overflow_arg_area = (overflow_arg_area + 15) & ~15; // overflow_arg_area = (overflow_arg_area + 15) & ~15;
llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, 15); llvm::Value *Offset =
llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()), 15);
overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset); overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset);
llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area, llvm::Value *AsInt = CGF.Builder.CreatePtrToInt(overflow_arg_area,
llvm::Type::Int64Ty); llvm::Type::getInt64Ty(CGF.getLLVMContext()));
llvm::Value *Mask = llvm::ConstantInt::get(llvm::Type::Int64Ty, ~15LL); llvm::Value *Mask = llvm::ConstantInt::get(
llvm::Type::getInt64Ty(CGF.getLLVMContext()), ~15LL);
overflow_arg_area = overflow_arg_area =
CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask), CGF.Builder.CreateIntToPtr(CGF.Builder.CreateAnd(AsInt, Mask),
overflow_arg_area->getType(), overflow_arg_area->getType(),
@ -1088,7 +1089,8 @@ static llvm::Value *EmitVAArgFromMemory(llvm::Value *VAListAddr,
// an 8 byte boundary. // an 8 byte boundary.
uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8; uint64_t SizeInBytes = (CGF.getContext().getTypeSize(Ty) + 7) / 8;
llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::Value *Offset =
llvm::ConstantInt::get(llvm::Type::getInt32Ty(CGF.getLLVMContext()),
(SizeInBytes + 7) & ~7); (SizeInBytes + 7) & ~7);
overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset, overflow_arg_area = CGF.Builder.CreateGEP(overflow_arg_area, Offset,
"overflow_arg_area.next"); "overflow_arg_area.next");
@ -1137,7 +1139,7 @@ llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
gp_offset = CGF.Builder.CreateLoad(gp_offset_p, "gp_offset"); gp_offset = CGF.Builder.CreateLoad(gp_offset_p, "gp_offset");
InRegs = InRegs =
CGF.Builder.CreateICmpULE(gp_offset, CGF.Builder.CreateICmpULE(gp_offset,
llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
48 - neededInt * 8), 48 - neededInt * 8),
"fits_in_gp"); "fits_in_gp");
} }
@ -1147,7 +1149,7 @@ llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
fp_offset = CGF.Builder.CreateLoad(fp_offset_p, "fp_offset"); fp_offset = CGF.Builder.CreateLoad(fp_offset_p, "fp_offset");
llvm::Value *FitsInFP = llvm::Value *FitsInFP =
CGF.Builder.CreateICmpULE(fp_offset, CGF.Builder.CreateICmpULE(fp_offset,
llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
176 - neededSSE * 16), 176 - neededSSE * 16),
"fits_in_fp"); "fits_in_fp");
InRegs = InRegs ? CGF.Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP; InRegs = InRegs ? CGF.Builder.CreateAnd(InRegs, FitsInFP) : FitsInFP;
@ -1216,12 +1218,12 @@ llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
llvm::Value *RegAddrLo = CGF.Builder.CreateGEP(RegAddr, fp_offset); llvm::Value *RegAddrLo = CGF.Builder.CreateGEP(RegAddr, fp_offset);
llvm::Value *RegAddrHi = llvm::Value *RegAddrHi =
CGF.Builder.CreateGEP(RegAddrLo, CGF.Builder.CreateGEP(RegAddrLo,
llvm::ConstantInt::get(llvm::Type::Int32Ty, 16)); llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), 16));
const llvm::Type *DblPtrTy = const llvm::Type *DblPtrTy =
llvm::PointerType::getUnqual(llvm::Type::DoubleTy); llvm::PointerType::getUnqual(llvm::Type::getDoubleTy(VMContext));
const llvm::StructType *ST = llvm::StructType::get(VMContext, const llvm::StructType *ST = llvm::StructType::get(VMContext,
llvm::Type::DoubleTy, llvm::Type::getDoubleTy(VMContext),
llvm::Type::DoubleTy, llvm::Type::getDoubleTy(VMContext),
NULL); NULL);
llvm::Value *V, *Tmp = CGF.CreateTempAlloca(ST); llvm::Value *V, *Tmp = CGF.CreateTempAlloca(ST);
V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrLo, V = CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegAddrLo,
@ -1239,13 +1241,13 @@ llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
// l->gp_offset = l->gp_offset + num_gp * 8 // l->gp_offset = l->gp_offset + num_gp * 8
// l->fp_offset = l->fp_offset + num_fp * 16. // l->fp_offset = l->fp_offset + num_fp * 16.
if (neededInt) { if (neededInt) {
llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
neededInt * 8); neededInt * 8);
CGF.Builder.CreateStore(CGF.Builder.CreateAdd(gp_offset, Offset), CGF.Builder.CreateStore(CGF.Builder.CreateAdd(gp_offset, Offset),
gp_offset_p); gp_offset_p);
} }
if (neededSSE) { if (neededSSE) {
llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::Int32Ty, llvm::Value *Offset = llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext),
neededSSE * 16); neededSSE * 16);
CGF.Builder.CreateStore(CGF.Builder.CreateAdd(fp_offset, Offset), CGF.Builder.CreateStore(CGF.Builder.CreateAdd(fp_offset, Offset),
fp_offset_p); fp_offset_p);
@ -1353,10 +1355,10 @@ ABIArgInfo ARMABIInfo::classifyArgumentType(QualType Ty,
const llvm::Type* ElemTy; const llvm::Type* ElemTy;
unsigned SizeRegs; unsigned SizeRegs;
if (Context.getTypeAlign(Ty) > 32) { if (Context.getTypeAlign(Ty) > 32) {
ElemTy = llvm::Type::Int64Ty; ElemTy = llvm::Type::getInt64Ty(VMContext);
SizeRegs = (Context.getTypeSize(Ty) + 63) / 64; SizeRegs = (Context.getTypeSize(Ty) + 63) / 64;
} else { } else {
ElemTy = llvm::Type::Int32Ty; ElemTy = llvm::Type::getInt32Ty(VMContext);
SizeRegs = (Context.getTypeSize(Ty) + 31) / 32; SizeRegs = (Context.getTypeSize(Ty) + 31) / 32;
} }
std::vector<const llvm::Type*> LLVMFields; std::vector<const llvm::Type*> LLVMFields;
@ -1375,7 +1377,7 @@ ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy,
// are returned indirectly. // are returned indirectly.
uint64_t Size = Context.getTypeSize(RetTy); uint64_t Size = Context.getTypeSize(RetTy);
if (Size <= 32) if (Size <= 32)
return ABIArgInfo::getCoerce(llvm::Type::Int32Ty); return ABIArgInfo::getCoerce(llvm::Type::getInt32Ty(VMContext));
return ABIArgInfo::getIndirect(0); return ABIArgInfo::getIndirect(0);
} else { } else {
return (RetTy->isPromotableIntegerType() ? return (RetTy->isPromotableIntegerType() ?
@ -1386,7 +1388,8 @@ ABIArgInfo ARMABIInfo::classifyReturnType(QualType RetTy,
llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty, llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
CodeGenFunction &CGF) const { CodeGenFunction &CGF) const {
// FIXME: Need to handle alignment // FIXME: Need to handle alignment
const llvm::Type *BP = llvm::PointerType::getUnqual(llvm::Type::Int8Ty); const llvm::Type *BP =
llvm::PointerType::getUnqual(llvm::Type::getInt8Ty(CGF.getLLVMContext()));
const llvm::Type *BPP = llvm::PointerType::getUnqual(BP); const llvm::Type *BPP = llvm::PointerType::getUnqual(BP);
CGBuilderTy &Builder = CGF.Builder; CGBuilderTy &Builder = CGF.Builder;
@ -1400,8 +1403,8 @@ llvm::Value *ARMABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
uint64_t Offset = uint64_t Offset =
llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4); llvm::RoundUpToAlignment(CGF.getContext().getTypeSize(Ty) / 8, 4);
llvm::Value *NextAddr = llvm::Value *NextAddr =
Builder.CreateGEP(Addr, Builder.CreateGEP(Addr, llvm::ConstantInt::get(
llvm::ConstantInt::get(llvm::Type::Int32Ty, Offset), llvm::Type::getInt32Ty(CGF.getLLVMContext()), Offset),
"ap.next"); "ap.next");
Builder.CreateStore(NextAddr, VAListAddrAsBPP); Builder.CreateStore(NextAddr, VAListAddrAsBPP);