diff options
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 48 | ||||
-rw-r--r-- | lib/CodeGen/CGDecl.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 5 | ||||
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 175 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 8 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 12 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenModule.h | 33 |
8 files changed, 168 insertions, 131 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 76a68b1526..fb90e025eb 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -481,8 +481,8 @@ static void computeBlockInfo(CodeGenModule &CGM, CGBlockInfo &info) { if (endAlign < maxFieldAlign) { CharUnits padding = maxFieldAlign - endAlign; - const llvm::Type *i8 = llvm::IntegerType::get(CGM.getLLVMContext(), 8); - elementTypes.push_back(llvm::ArrayType::get(i8, padding.getQuantity())); + elementTypes.push_back(llvm::ArrayType::get(CGM.Int8Ty, + padding.getQuantity())); blockSize += padding; endAlign = getLowBit(blockSize); @@ -517,7 +517,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) { llvm::Constant *blockFn = CodeGenFunction(CGM).GenerateBlockFunction(CurGD, blockInfo, CurFuncDecl, LocalDeclMap); - blockFn = llvm::ConstantExpr::getBitCast(blockFn, Int8PtrTy); + blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy); // If there is nothing to capture, we can emit this as a global block. if (blockInfo.CanBeGlobal) @@ -526,7 +526,7 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) { // Otherwise, we have to emit this as a local block. llvm::Constant *isa = CGM.getNSConcreteStackBlock(); - isa = llvm::ConstantExpr::getBitCast(isa, Int8PtrTy); + isa = llvm::ConstantExpr::getBitCast(isa, VoidPtrTy); // Build the block descriptor. llvm::Constant *descriptor = buildBlockDescriptor(CGM, blockInfo); @@ -604,13 +604,13 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const BlockExpr *blockExpr) { // pointer at this point, since we're building something that will // live a shorter life than the stack byref anyway. if (ci->isByRef()) { - // Get an i8* that points to the byref struct. + // Get a void* that points to the byref struct. if (ci->isNested()) src = Builder.CreateLoad(src, "byref.capture"); else - src = Builder.CreateBitCast(src, Int8PtrTy); + src = Builder.CreateBitCast(src, VoidPtrTy); - // Write that i8* into the capture field. + // Write that void* into the capture field. Builder.CreateStore(src, blockField); // If we have a copy constructor, evaluate that into the block field. @@ -710,9 +710,6 @@ const llvm::Type *CodeGenModule::getGenericBlockLiteralType() { const llvm::Type *BlockDescPtrTy = getBlockDescriptorType(); - const llvm::IntegerType *IntTy = cast<llvm::IntegerType>( - getTypes().ConvertType(getContext().IntTy)); - // struct __block_literal_generic { // void *__isa; // int __flags; @@ -720,11 +717,11 @@ const llvm::Type *CodeGenModule::getGenericBlockLiteralType() { // void (*__invoke)(void *); // struct __block_descriptor *__descriptor; // }; - GenericBlockLiteralType = llvm::StructType::get(IntTy->getContext(), - Int8PtrTy, + GenericBlockLiteralType = llvm::StructType::get(getLLVMContext(), + VoidPtrTy, IntTy, IntTy, - Int8PtrTy, + VoidPtrTy, BlockDescPtrTy, NULL); @@ -753,7 +750,7 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr* E, // Get the function pointer from the literal. llvm::Value *FuncPtr = Builder.CreateStructGEP(BlockLiteral, 3, "tmp"); - BlockLiteral = Builder.CreateBitCast(BlockLiteral, Int8PtrTy, "tmp"); + BlockLiteral = Builder.CreateBitCast(BlockLiteral, VoidPtrTy, "tmp"); // Add the block literal. QualType VoidPtrTy = getContext().getPointerType(getContext().VoidTy); @@ -827,7 +824,7 @@ llvm::Value *CodeGenFunction::GetAddrOfBlockDecl(const VarDecl *variable, llvm::Constant * CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *blockExpr, - const char *name) { + const char *name) { CGBlockInfo blockInfo(blockExpr, name); // Compute information about the layout, etc., of this block. @@ -841,7 +838,7 @@ CodeGenModule::GetAddrOfGlobalBlock(const BlockExpr *blockExpr, blockInfo, 0, LocalDeclMap); } - blockFn = llvm::ConstantExpr::getBitCast(blockFn, Int8PtrTy); + blockFn = llvm::ConstantExpr::getBitCast(blockFn, VoidPtrTy); return buildGlobalBlock(*this, blockInfo, blockFn); } @@ -860,11 +857,10 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule &CGM, // __flags BlockFlags flags = computeBlockFlag(CGM, blockInfo.getBlockExpr(), BLOCK_IS_GLOBAL | BLOCK_HAS_SIGNATURE); - const llvm::Type *intTy = CGM.getTypes().ConvertType(CGM.getContext().IntTy); - fields[1] = llvm::ConstantInt::get(intTy, flags.getBitMask()); + fields[1] = llvm::ConstantInt::get(CGM.IntTy, flags.getBitMask()); // Reserved - fields[2] = llvm::Constant::getNullValue(intTy); + fields[2] = llvm::Constant::getNullValue(CGM.IntTy); // Function fields[3] = blockFn; @@ -1155,8 +1151,8 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { EmitSynthesizedCXXCopyCtor(dstField, srcField, copyExpr); } else { llvm::Value *srcValue = Builder.CreateLoad(srcField, "blockcopy.src"); - srcValue = Builder.CreateBitCast(srcValue, Int8PtrTy); - llvm::Value *dstAddr = Builder.CreateBitCast(dstField, Int8PtrTy); + srcValue = Builder.CreateBitCast(srcValue, VoidPtrTy); + llvm::Value *dstAddr = Builder.CreateBitCast(dstField, VoidPtrTy); Builder.CreateCall3(CGM.getBlockObjectAssign(), dstAddr, srcValue, llvm::ConstantInt::get(Int32Ty, flags)); } @@ -1164,7 +1160,7 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) { FinishFunction(); - return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy); + return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy); } llvm::Constant * @@ -1246,7 +1242,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { // that things were done in reverse. } else { llvm::Value *value = Builder.CreateLoad(srcField); - value = Builder.CreateBitCast(value, Int8PtrTy); + value = Builder.CreateBitCast(value, VoidPtrTy); BuildBlockRelease(value, flags); } } @@ -1255,7 +1251,7 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) { FinishFunction(); - return llvm::ConstantExpr::getBitCast(Fn, Int8PtrTy); + return llvm::ConstantExpr::getBitCast(Fn, VoidPtrTy); } llvm::Constant *CodeGenFunction:: @@ -1318,8 +1314,8 @@ GeneratebyrefCopyHelperFunction(const llvm::Type *T, BlockFieldFlags flags, llvm::Value *SrcObj = V; EmitSynthesizedCXXCopyCtor(DstObj, SrcObj, copyExpr); } else { - DstObj = Builder.CreateBitCast(DstObj, Int8PtrTy); - V = Builder.CreateBitCast(V, llvm::PointerType::get(Int8PtrTy, 0)); + DstObj = Builder.CreateBitCast(DstObj, VoidPtrTy); + V = Builder.CreateBitCast(V, VoidPtrPtrTy); llvm::Value *SrcObj = Builder.CreateLoad(V); flags |= BLOCK_BYREF_CALLER; llvm::Value *N = llvm::ConstantInt::get(Int32Ty, flags.getBitMask()); diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index 44568bc2aa..4dd788b799 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -933,7 +933,6 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg, assert((isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D)) && "Invalid argument to EmitParmDecl"); QualType Ty = D.getType(); - CanQualType CTy = getContext().getCanonicalType(Ty); llvm::Value *DeclPtr; // If this is an aggregate or variable sized value, reuse the input pointer. @@ -945,8 +944,9 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, llvm::Value *Arg, DeclPtr = CreateMemTemp(Ty, D.getName() + ".addr"); // Store the initial value into the alloca. - unsigned Alignment = getContext().getDeclAlign(&D).getQuantity(); - EmitStoreOfScalar(Arg, DeclPtr, CTy.isVolatileQualified(), Alignment, Ty); + EmitStoreOfScalar(Arg, DeclPtr, Ty.isVolatileQualified(), + getContext().getDeclAlign(&D).getQuantity(), Ty, + CGM.getTBAAInfo(Ty)); } Arg->setName(D.getName()); diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 9e3ed62731..049aeeeebb 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -1387,9 +1387,8 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { } // Extend or truncate the index type to 32 or 64-bits. - if (!Idx->getType()->isIntegerTy(LLVMPointerWidth)) - Idx = Builder.CreateIntCast(Idx, IntPtrTy, - IdxSigned, "idxprom"); + if (Idx->getType() != IntPtrTy) + Idx = Builder.CreateIntCast(Idx, IntPtrTy, IdxSigned, "idxprom"); // FIXME: As llvm implements the object size checking, this can come out. if (CatchUndefined) { diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index bd54549940..e2e404f70f 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1250,104 +1250,123 @@ EmitAddConsiderOverflowBehavior(const UnaryOperator *E, return 0; } -llvm::Value *ScalarExprEmitter:: -EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, - bool isInc, bool isPre) { - - QualType ValTy = E->getSubExpr()->getType(); - llvm::Value *InVal = EmitLoadOfLValue(LV, ValTy); +llvm::Value * +ScalarExprEmitter::EmitScalarPrePostIncDec(const UnaryOperator *E, LValue LV, + bool isInc, bool isPre) { - int AmountVal = isInc ? 1 : -1; - - if (ValTy->isPointerType() && - ValTy->getAs<PointerType>()->isVariableArrayType()) { - // The amount of the addition/subtraction needs to account for the VLA size - CGF.ErrorUnsupported(E, "VLA pointer inc/dec"); - } + QualType type = E->getSubExpr()->getType(); + llvm::Value *value = EmitLoadOfLValue(LV, type); + llvm::Value *input = value; + + int amount = (isInc ? 1 : -1); + + // Special case of integer increment that we have to check first: bool++. + // Due to promotion rules, we get: + // bool++ -> bool = bool + 1 + // -> bool = (int)bool + 1 + // -> bool = ((int)bool + 1 != 0) + // An interesting aspect of this is that increment is always true. + // Decrement does not have this property. + if (isInc && type->isBooleanType()) { + value = Builder.getTrue(); + + // Most common case by far: integer increment. + } else if (type->isIntegerType()) { + + llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount); + + if (type->isSignedIntegerType()) + value = EmitAddConsiderOverflowBehavior(E, value, amt, isInc); + + // Unsigned integer inc is always two's complement. + else + value = Builder.CreateAdd(value, amt, isInc ? "inc" : "dec"); - llvm::Value *NextVal; - if (const llvm::PointerType *PT = - dyn_cast<llvm::PointerType>(InVal->getType())) { - llvm::Constant *Inc = llvm::ConstantInt::get(CGF.Int32Ty, AmountVal); - if (!isa<llvm::FunctionType>(PT->getElementType())) { - QualType PTEE = ValTy->getPointeeType(); - if (const ObjCObjectType *OIT = PTEE->getAs<ObjCObjectType>()) { - // Handle interface types, which are not represented with a concrete - // type. - CharUnits size = CGF.getContext().getTypeSizeInChars(OIT); - if (!isInc) - size = -size; - Inc = llvm::ConstantInt::get(Inc->getType(), size.getQuantity()); - const llvm::Type *i8Ty = llvm::Type::getInt8PtrTy(VMContext); - InVal = Builder.CreateBitCast(InVal, i8Ty); - NextVal = Builder.CreateGEP(InVal, Inc, "add.ptr"); - llvm::Value *lhs = LV.getAddress(); - lhs = Builder.CreateBitCast(lhs, llvm::PointerType::getUnqual(i8Ty)); - LV = CGF.MakeAddrLValue(lhs, ValTy); - } else - NextVal = Builder.CreateInBoundsGEP(InVal, Inc, "ptrincdec"); + // Next most common: pointer increment. + } else if (const PointerType *ptr = type->getAs<PointerType>()) { + QualType type = ptr->getPointeeType(); + + // VLA types don't have constant size. + if (type->isVariableArrayType()) { + llvm::Value *vlaSize = + CGF.GetVLASize(CGF.getContext().getAsVariableArrayType(type)); + value = CGF.EmitCastToVoidPtr(value); + if (!isInc) vlaSize = Builder.CreateNSWNeg(vlaSize, "vla.negsize"); + value = Builder.CreateInBoundsGEP(value, vlaSize, "vla.inc"); + value = Builder.CreateBitCast(value, input->getType()); + + // Arithmetic on function pointers (!) is just +-1. + } else if (type->isFunctionType()) { + llvm::Value *amt = llvm::ConstantInt::get(CGF.Int32Ty, amount); + + value = CGF.EmitCastToVoidPtr(value); + value = Builder.CreateInBoundsGEP(value, amt, "incdec.funcptr"); + value = Builder.CreateBitCast(value, input->getType()); + + // For everything else, we can just do a simple increment. } else { - const llvm::Type *i8Ty = llvm::Type::getInt8PtrTy(VMContext); - NextVal = Builder.CreateBitCast(InVal, i8Ty, "tmp"); - NextVal = Builder.CreateGEP(NextVal, Inc, "ptrincdec"); - NextVal = Builder.CreateBitCast(NextVal, InVal->getType()); + llvm::Value *amt = llvm::ConstantInt::get(CGF.Int32Ty, amount); + value = Builder.CreateInBoundsGEP(value, amt, "incdec.ptr"); } - } else if (InVal->getType()->isIntegerTy(1) && isInc) { - // Bool++ is an interesting case, due to promotion rules, we get: - // Bool++ -> Bool = Bool+1 -> Bool = (int)Bool+1 -> - // Bool = ((int)Bool+1) != 0 - // An interesting aspect of this is that increment is always true. - // Decrement does not have this property. - NextVal = llvm::ConstantInt::getTrue(VMContext); - } else if (ValTy->isVectorType()) { - if (ValTy->hasIntegerRepresentation()) { - NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal); - - NextVal = ValTy->hasSignedIntegerRepresentation() ? - EmitAddConsiderOverflowBehavior(E, InVal, NextVal, isInc) : - Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); + + // Vector increment/decrement. + } else if (type->isVectorType()) { + if (type->hasIntegerRepresentation()) { + llvm::Value *amt = llvm::ConstantInt::get(value->getType(), amount); + + if (type->hasSignedIntegerRepresentation()) + value = EmitAddConsiderOverflowBehavior(E, value, amt, isInc); + else + value = Builder.CreateAdd(value, amt, isInc ? "inc" : "dec"); } else { - NextVal = Builder.CreateFAdd( - InVal, - llvm::ConstantFP::get(InVal->getType(), AmountVal), + value = Builder.CreateFAdd( + value, + llvm::ConstantFP::get(value->getType(), amount), isInc ? "inc" : "dec"); } - } else if (isa<llvm::IntegerType>(InVal->getType())) { - NextVal = llvm::ConstantInt::get(InVal->getType(), AmountVal); - NextVal = ValTy->isSignedIntegerType() ? - EmitAddConsiderOverflowBehavior(E, InVal, NextVal, isInc) : - // Unsigned integer inc is always two's complement. - Builder.CreateAdd(InVal, NextVal, isInc ? "inc" : "dec"); - } else { + // Floating point. + } else if (type->isRealFloatingType()) { // Add the inc/dec to the real part. - if (InVal->getType()->isFloatTy()) - NextVal = - llvm::ConstantFP::get(VMContext, - llvm::APFloat(static_cast<float>(AmountVal))); - else if (InVal->getType()->isDoubleTy()) - NextVal = - llvm::ConstantFP::get(VMContext, - llvm::APFloat(static_cast<double>(AmountVal))); + llvm::Value *amt; + if (value->getType()->isFloatTy()) + amt = llvm::ConstantFP::get(VMContext, + llvm::APFloat(static_cast<float>(amount))); + else if (value->getType()->isDoubleTy()) + amt = llvm::ConstantFP::get(VMContext, + llvm::APFloat(static_cast<double>(amount))); else { - llvm::APFloat F(static_cast<float>(AmountVal)); + llvm::APFloat F(static_cast<float>(amount)); bool ignored; F.convert(CGF.Target.getLongDoubleFormat(), llvm::APFloat::rmTowardZero, &ignored); - NextVal = llvm::ConstantFP::get(VMContext, F); + amt = llvm::ConstantFP::get(VMContext, F); } - NextVal = Builder.CreateFAdd(InVal, NextVal, isInc ? "inc" : "dec"); + value = Builder.CreateFAdd(value, amt, isInc ? "inc" : "dec"); + + // Objective-C pointer types. + } else { + const ObjCObjectPointerType *OPT = type->castAs<ObjCObjectPointerType>(); + value = CGF.EmitCastToVoidPtr(value); + + CharUnits size = CGF.getContext().getTypeSizeInChars(OPT->getObjectType()); + if (!isInc) size = -size; + llvm::Value *sizeValue = + llvm::ConstantInt::get(CGF.SizeTy, size.getQuantity()); + + value = Builder.CreateInBoundsGEP(value, sizeValue, "incdec.objptr"); + value = Builder.CreateBitCast(value, input->getType()); } // Store the updated result through the lvalue. if (LV.isBitField()) - CGF.EmitStoreThroughBitfieldLValue(RValue::get(NextVal), LV, ValTy, &NextVal); + CGF.EmitStoreThroughBitfieldLValue(RValue::get(value), LV, type, &value); else - CGF.EmitStoreThroughLValue(RValue::get(NextVal), LV, ValTy); + CGF.EmitStoreThroughLValue(RValue::get(value), LV, type); // If this is a postinc, return the value read from memory, otherwise use the // updated value. - return isPre ? NextVal : InVal; + return isPre ? value : input; } @@ -1835,7 +1854,7 @@ Value *ScalarExprEmitter::EmitAdd(const BinOpInfo &Ops) { } unsigned Width = cast<llvm::IntegerType>(Idx->getType())->getBitWidth(); - if (Width < CGF.LLVMPointerWidth) { + if (Width < CGF.PointerWidthInBits) { // Zero or sign extend the pointer value based on whether the index is // signed or not. const llvm::Type *IdxType = CGF.IntPtrTy; @@ -1908,7 +1927,7 @@ Value *ScalarExprEmitter::EmitSub(const BinOpInfo &Ops) { // pointer - int Value *Idx = Ops.RHS; unsigned Width = cast<llvm::IntegerType>(Idx->getType())->getBitWidth(); - if (Width < CGF.LLVMPointerWidth) { + if (Width < CGF.PointerWidthInBits) { // Zero or sign extend the pointer value based on whether the index is // signed or not. const llvm::Type *IdxType = CGF.IntPtrTy; diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 39aff78c73..ee8b98cdd4 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -29,8 +29,8 @@ using namespace clang; using namespace CodeGen; CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) - : CGM(cgm), Target(CGM.getContext().Target), - Builder(cgm.getModule().getContext()), + : CodeGenTypeCache(cgm), CGM(cgm), + Target(CGM.getContext().Target), Builder(cgm.getModule().getContext()), BlockInfo(0), BlockPointer(0), NormalCleanupDest(0), EHCleanupDest(0), NextCleanupDestIndex(1), ExceptionSlot(0), DebugInfo(0), IndirectBranch(0), @@ -40,14 +40,6 @@ CodeGenFunction::CodeGenFunction(CodeGenModule &cgm) OutermostConditional(0), TerminateLandingPad(0), TerminateHandler(0), TrapBB(0) { - // Get some frequently used types. - LLVMPointerWidth = Target.getPointerWidth(0); - llvm::LLVMContext &LLVMContext = CGM.getLLVMContext(); - IntPtrTy = llvm::IntegerType::get(LLVMContext, LLVMPointerWidth); - Int32Ty = llvm::Type::getInt32Ty(LLVMContext); - Int64Ty = llvm::Type::getInt64Ty(LLVMContext); - Int8PtrTy = cgm.Int8PtrTy; - Exceptions = getContext().getLangOptions().Exceptions; CatchUndefined = getContext().getLangOptions().CatchUndefined; CGM.getCXXABI().getMangleContext().startNewFunction(); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 1fe1c3fda9..d52a481269 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -503,7 +503,7 @@ public: /// CodeGenFunction - This class organizes the per-function state that is used /// while generating LLVM code. -class CodeGenFunction { +class CodeGenFunction : public CodeGenTypeCache { CodeGenFunction(const CodeGenFunction&); // DO NOT IMPLEMENT void operator=(const CodeGenFunction&); // DO NOT IMPLEMENT @@ -581,12 +581,6 @@ public: /// we prefer to insert allocas. llvm::AssertingVH<llvm::Instruction> AllocaInsertPt; - // intptr_t, i32, i64 - const llvm::IntegerType *IntPtrTy, *Int32Ty, *Int64Ty; - uint32_t LLVMPointerWidth; - - const llvm::PointerType *Int8PtrTy; - bool Exceptions; bool CatchUndefined; diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 2a057a1866..5a45df24fe 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -90,7 +90,17 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO, DebugInfo = CodeGenOpts.DebugInfo ? new CGDebugInfo(*this) : 0; Block.GlobalUniqueCount = 0; - Int8PtrTy = llvm::Type::getInt8PtrTy(M.getContext()); + + // Initialize the type cache. + llvm::LLVMContext &LLVMContext = M.getContext(); + Int8Ty = llvm::Type::getInt8Ty(LLVMContext); + Int32Ty = llvm::Type::getInt32Ty(LLVMContext); + Int64Ty = llvm::Type::getInt64Ty(LLVMContext); + PointerWidthInBits = C.Target.getPointerWidth(0); + IntTy = llvm::IntegerType::get(LLVMContext, C.Target.getIntWidth()); + IntPtrTy = llvm::IntegerType::get(LLVMContext, PointerWidthInBits); + Int8PtrTy = Int8Ty->getPointerTo(0); + Int8PtrPtrTy = Int8PtrTy->getPointerTo(0); } CodeGenModule::~CodeGenModule() { diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 5d2e581ec3..b6bd37c1c0 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -94,10 +94,39 @@ namespace CodeGen { return priority == RHS.priority && lex_order < RHS.lex_order; } }; + + struct CodeGenTypeCache { + /// i8, i32, and i64 + const llvm::IntegerType *Int8Ty, *Int32Ty, *Int64Ty; + + /// int + const llvm::IntegerType *IntTy; + + /// intptr_t and size_t, which we assume are the same + union { + const llvm::IntegerType *IntPtrTy; + const llvm::IntegerType *SizeTy; + }; + + /// void* in address space 0 + union { + const llvm::PointerType *VoidPtrTy; + const llvm::PointerType *Int8PtrTy; + }; + + /// void** in address space 0 + union { + const llvm::PointerType *VoidPtrPtrTy; + const llvm::PointerType *Int8PtrPtrTy; + }; + + /// The width of an address-zero pointer. + unsigned char PointerWidthInBits; + }; /// CodeGenModule - This class organizes the cross-function state that is used /// while generating LLVM code. -class CodeGenModule { +class CodeGenModule : public CodeGenTypeCache { CodeGenModule(const CodeGenModule&); // DO NOT IMPLEMENT void operator=(const CodeGenModule&); // DO NOT IMPLEMENT @@ -227,8 +256,6 @@ public: /// Release - Finalize LLVM code generation. void Release(); - const llvm::PointerType *Int8PtrTy; - /// getObjCRuntime() - Return a reference to the configured /// Objective-C runtime. CGObjCRuntime &getObjCRuntime() { |