From 7f2896406c8f14bf123578610043a919ba1a1c8a Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Thu, 8 Apr 2010 02:59:45 +0000 Subject: IRgen: Move the bit-field access type into CGBitFieldInfo, and change bit-field LValues to just store the base address of object containing the bit-field. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100745 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGExpr.cpp | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'lib/CodeGen/CGExpr.cpp') diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 0aa4438f4f..6fd18f395c 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -603,12 +603,27 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) { return EmitLoadOfKVCRefLValue(LV, ExprType); } +static llvm::Value *getBitFieldAddr(LValue LV, CGBuilderTy &Builder) { + const CGBitFieldInfo &Info = LV.getBitFieldInfo(); + + llvm::Value *BaseValue = LV.getBitFieldBaseAddr(); + const llvm::PointerType *BaseTy = + cast(BaseValue->getType()); + + // Cast to the type of the access we will perform. + llvm::Value *V = Builder.CreateBitCast( + BaseValue, llvm::PointerType::get(Info.FieldTy, BaseTy->getAddressSpace())); + + // Offset by the access index. + return Builder.CreateConstGEP1_32(V, Info.FieldNo); +} + RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType) { const CGBitFieldInfo &Info = LV.getBitFieldInfo(); unsigned StartBit = Info.Start; unsigned BitfieldSize = Info.Size; - llvm::Value *Ptr = LV.getBitFieldAddr(); + llvm::Value *Ptr = getBitFieldAddr(LV, Builder); const llvm::Type *EltTy = cast(Ptr->getType())->getElementType(); @@ -785,7 +800,7 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, const CGBitFieldInfo &Info = Dst.getBitFieldInfo(); unsigned StartBit = Info.Start; unsigned BitfieldSize = Info.Size; - llvm::Value *Ptr = Dst.getBitFieldAddr(); + llvm::Value *Ptr = getBitFieldAddr(Dst, Builder); const llvm::Type *EltTy = cast(Ptr->getType())->getElementType(); @@ -1474,19 +1489,7 @@ LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue, const CGRecordLayout &RL = CGM.getTypes().getCGRecordLayout(Field->getParent()); const CGBitFieldInfo &Info = RL.getBitFieldInfo(Field); - - // FIXME: CodeGenTypes should expose a method to get the appropriate type for - // FieldTy (the appropriate type is ABI-dependent). - const llvm::Type *FieldTy = - CGM.getTypes().ConvertTypeForMem(Field->getType()); - const llvm::PointerType *BaseTy = - cast(BaseValue->getType()); - unsigned AS = BaseTy->getAddressSpace(); - BaseValue = Builder.CreateBitCast(BaseValue, - llvm::PointerType::get(FieldTy, AS)); - llvm::Value *V = Builder.CreateConstGEP1_32(BaseValue, Info.FieldNo); - - return LValue::MakeBitfield(V, Info, + return LValue::MakeBitfield(BaseValue, Info, Field->getType().getCVRQualifiers()|CVRQualifiers); } -- cgit v1.2.3-70-g09d2