From: Daniel Dunbar Date: Tue, 6 Apr 2010 01:07:44 +0000 (+0000) Subject: IRgen: Move BitFieldIsSigned bit into CGBitFieldInfo. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=efbf487da83883c2da81181cac6f040928aa4289;p=clang IRgen: Move BitFieldIsSigned bit into CGBitFieldInfo. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100513 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index eb848331ec..0aa4438f4f 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -605,8 +605,9 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) { RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV, QualType ExprType) { - unsigned StartBit = LV.getBitFieldInfo().Start; - unsigned BitfieldSize = LV.getBitFieldInfo().Size; + const CGBitFieldInfo &Info = LV.getBitFieldInfo(); + unsigned StartBit = Info.Start; + unsigned BitfieldSize = Info.Size; llvm::Value *Ptr = LV.getBitFieldAddr(); const llvm::Type *EltTy = @@ -650,7 +651,7 @@ RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV, } // Sign extend if necessary. - if (LV.isBitFieldSigned()) { + if (Info.IsSigned) { llvm::Value *ExtraBits = llvm::ConstantInt::get(EltTy, EltTySize - BitfieldSize); Val = Builder.CreateAShr(Builder.CreateShl(Val, ExtraBits), @@ -781,8 +782,9 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst, void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, QualType Ty, llvm::Value **Result) { - unsigned StartBit = Dst.getBitFieldInfo().Start; - unsigned BitfieldSize = Dst.getBitFieldInfo().Size; + const CGBitFieldInfo &Info = Dst.getBitFieldInfo(); + unsigned StartBit = Info.Start; + unsigned BitfieldSize = Info.Size; llvm::Value *Ptr = Dst.getBitFieldAddr(); const llvm::Type *EltTy = @@ -805,7 +807,7 @@ void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, "bf.reload.val"); // Sign extend if necessary. - if (Dst.isBitFieldSigned()) { + if (Info.IsSigned) { unsigned SrcTySize = CGM.getTargetData().getTypeSizeInBits(SrcTy); llvm::Value *ExtraBits = llvm::ConstantInt::get(SrcTy, SrcTySize - BitfieldSize); @@ -1484,7 +1486,7 @@ LValue CodeGenFunction::EmitLValueForBitfield(llvm::Value* BaseValue, llvm::PointerType::get(FieldTy, AS)); llvm::Value *V = Builder.CreateConstGEP1_32(BaseValue, Info.FieldNo); - return LValue::MakeBitfield(V, Info, Field->getType()->isSignedIntegerType(), + return LValue::MakeBitfield(V, Info, Field->getType().getCVRQualifiers()|CVRQualifiers); } diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 467ad43bb2..ac8fa057a0 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -126,12 +126,12 @@ LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF, // objects. unsigned FieldNo = 0; // This value is unused. CGBitFieldInfo *Info = - new (CGF.CGM.getContext()) CGBitFieldInfo(FieldNo, BitOffset, BitFieldSize); + new (CGF.CGM.getContext()) CGBitFieldInfo(FieldNo, BitOffset, BitFieldSize, + IvarTy->isSignedIntegerType()); // FIXME: We need to set a very conservative alignment on this, or make sure // that the runtime is doing the right thing. - return LValue::MakeBitfield(V, *Info, IvarTy->isSignedIntegerType(), - Quals.getCVRQualifiers()); + return LValue::MakeBitfield(V, *Info, Quals.getCVRQualifiers()); } /// diff --git a/lib/CodeGen/CGRecordLayout.h b/lib/CodeGen/CGRecordLayout.h index 5e2abb1bb3..fd1775ea5e 100644 --- a/lib/CodeGen/CGRecordLayout.h +++ b/lib/CodeGen/CGRecordLayout.h @@ -21,12 +21,14 @@ namespace CodeGen { class CGBitFieldInfo { public: - CGBitFieldInfo(unsigned FieldNo, unsigned Start, unsigned Size) - : FieldNo(FieldNo), Start(Start), Size(Size) {} + CGBitFieldInfo(unsigned FieldNo, unsigned Start, unsigned Size, + bool IsSigned) + : FieldNo(FieldNo), Start(Start), Size(Size), IsSigned(IsSigned) {} unsigned FieldNo; unsigned Start; unsigned Size; + bool IsSigned : 1; }; /// CGRecordLayout - This class handles struct and union layout info while diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index e6aa320d81..4b9ec66e17 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -178,10 +178,11 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D, const llvm::Type *Ty = Types.ConvertTypeForMemRecursive(D->getType()); uint64_t TypeSizeInBits = getTypeSizeInBytes(Ty) * 8; + bool IsSigned = D->getType()->isSignedIntegerType(); LLVMBitFields.push_back(LLVMBitFieldInfo( D, CGBitFieldInfo(FieldOffset / TypeSizeInBits, FieldOffset % TypeSizeInBits, - FieldSize))); + FieldSize, IsSigned))); AppendBytes(NumBytesToAppend); @@ -279,8 +280,10 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) { continue; // Add the bit field info. + bool IsSigned = Field->getType()->isSignedIntegerType(); LLVMBitFields.push_back(LLVMBitFieldInfo( - *Field, CGBitFieldInfo(0, 0, FieldSize))); + *Field, CGBitFieldInfo(0, 0, FieldSize, + IsSigned))); } else { LLVMFields.push_back(LLVMFieldInfo(*Field, 0)); } diff --git a/lib/CodeGen/CGValue.h b/lib/CodeGen/CGValue.h index 465ea76913..91fb714315 100644 --- a/lib/CodeGen/CGValue.h +++ b/lib/CodeGen/CGValue.h @@ -154,9 +154,6 @@ class LValue { // Lvalue is a global reference of an objective-c object bool GlobalObjCRef : 1; - /// Is the bit-field value signed. - bool BitFieldIsSigned : 1; - Expr *BaseIvarExp; private: void SetQualifiers(Qualifiers Quals) { @@ -231,10 +228,6 @@ public: assert(isBitField()); return *BitFieldInfo; } - bool isBitFieldSigned() const { - assert(isBitField()); - return BitFieldIsSigned; - } // property ref lvalue const ObjCPropertyRefExpr *getPropertyRefExpr() const { @@ -277,12 +270,11 @@ public: } static LValue MakeBitfield(llvm::Value *V, const CGBitFieldInfo &Info, - bool IsSigned, unsigned CVR) { + unsigned CVR) { LValue R; R.LVType = BitField; R.V = V; R.BitFieldInfo = &Info; - R.BitFieldIsSigned = IsSigned; R.SetQualifiers(Qualifiers::fromCVRMask(CVR)); return R; }