diff options
author | Ivan A. Kosarev <ikosarev@accesssoftek.com> | 2017-10-30 11:49:31 +0000 |
---|---|---|
committer | Ivan A. Kosarev <ikosarev@accesssoftek.com> | 2017-10-30 11:49:31 +0000 |
commit | a855bcfaf28c168e378e403990848acf17cefb69 (patch) | |
tree | d9920b07e0e2705b284ba17dd2fb04f8d747d683 /lib | |
parent | 7fc4b5017f6fa01d6078ef7d5fb156f044a69125 (diff) | |
download | clang-a855bcfaf28c168e378e403990848acf17cefb69.tar.gz |
[CodeGen] Generate TBAA info for reference loads
Differential Revision: https://reviews.llvm.org/D39177
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316896 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGBlocks.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/CGExpr.cpp | 94 | ||||
-rw-r--r-- | lib/CodeGen/CGOpenMPRuntime.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/CGStmtOpenMP.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 15 |
5 files changed, 62 insertions, 58 deletions
diff --git a/lib/CodeGen/CGBlocks.cpp b/lib/CodeGen/CGBlocks.cpp index 8b79893405..850681471d 100644 --- a/lib/CodeGen/CGBlocks.cpp +++ b/lib/CodeGen/CGBlocks.cpp @@ -1189,8 +1189,8 @@ Address CodeGenFunction::GetAddrOfBlockDecl(const VarDecl *variable, variable->getName()); } - if (auto refType = capture.fieldType()->getAs<ReferenceType>()) - addr = EmitLoadOfReference(addr, refType); + if (capture.fieldType()->isReferenceType()) + addr = EmitLoadOfReference(MakeAddrLValue(addr, capture.fieldType())); return addr; } diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 6837377de8..431ffa55d1 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2160,22 +2160,30 @@ static LValue EmitThreadPrivateVarDeclLValue( return CGF.MakeAddrLValue(Addr, T, AlignmentSource::Decl); } -Address CodeGenFunction::EmitLoadOfReference(Address Addr, - const ReferenceType *RefTy, - LValueBaseInfo *BaseInfo, - TBAAAccessInfo *TBAAInfo) { - llvm::Value *Ptr = Builder.CreateLoad(Addr); - return Address(Ptr, getNaturalTypeAlignment(RefTy->getPointeeType(), - BaseInfo, TBAAInfo, - /* forPointeeType= */ true)); -} - -LValue CodeGenFunction::EmitLoadOfReferenceLValue(Address RefAddr, - const ReferenceType *RefTy) { - LValueBaseInfo BaseInfo; - TBAAAccessInfo TBAAInfo; - Address Addr = EmitLoadOfReference(RefAddr, RefTy, &BaseInfo, &TBAAInfo); - return MakeAddrLValue(Addr, RefTy->getPointeeType(), BaseInfo, TBAAInfo); +Address +CodeGenFunction::EmitLoadOfReference(LValue RefLVal, + LValueBaseInfo *PointeeBaseInfo, + TBAAAccessInfo *PointeeTBAAInfo) { + llvm::LoadInst *Load = Builder.CreateLoad(RefLVal.getAddress(), + RefLVal.isVolatile()); + TBAAAccessInfo RefTBAAInfo = RefLVal.getTBAAInfo(); + if (RefLVal.getBaseInfo().getMayAlias()) + RefTBAAInfo = CGM.getTBAAMayAliasAccessInfo(); + CGM.DecorateInstructionWithTBAA(Load, RefTBAAInfo); + + CharUnits Align = getNaturalTypeAlignment(RefLVal.getType()->getPointeeType(), + PointeeBaseInfo, PointeeTBAAInfo, + /* forPointeeType= */ true); + return Address(Load, Align); +} + +LValue CodeGenFunction::EmitLoadOfReferenceLValue(LValue RefLVal) { + LValueBaseInfo PointeeBaseInfo; + TBAAAccessInfo PointeeTBAAInfo; + Address PointeeAddr = EmitLoadOfReference(RefLVal, &PointeeBaseInfo, + &PointeeTBAAInfo); + return MakeAddrLValue(PointeeAddr, RefLVal.getType()->getPointeeType(), + PointeeBaseInfo, PointeeTBAAInfo); } Address CodeGenFunction::EmitLoadOfPointer(Address Ptr, @@ -2210,17 +2218,15 @@ static LValue EmitGlobalVarDeclLValue(CodeGenFunction &CGF, V = EmitBitCastOfLValueToProperType(CGF, V, RealVarTy); CharUnits Alignment = CGF.getContext().getDeclAlign(VD); Address Addr(V, Alignment); - LValue LV; // Emit reference to the private copy of the variable if it is an OpenMP // threadprivate variable. if (CGF.getLangOpts().OpenMP && VD->hasAttr<OMPThreadPrivateDeclAttr>()) return EmitThreadPrivateVarDeclLValue(CGF, VD, T, Addr, RealVarTy, E->getExprLoc()); - if (auto RefTy = VD->getType()->getAs<ReferenceType>()) { - LV = CGF.EmitLoadOfReferenceLValue(Addr, RefTy); - } else { - LV = CGF.MakeAddrLValue(Addr, T, AlignmentSource::Decl); - } + LValue LV = VD->getType()->isReferenceType() ? + CGF.EmitLoadOfReferenceLValue(Addr, VD->getType(), + AlignmentSource::Decl) : + CGF.MakeAddrLValue(Addr, T, AlignmentSource::Decl); setObjCGCLValueClass(CGF.getContext(), E, LV); return LV; } @@ -2338,8 +2344,9 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { else if (CapturedStmtInfo) { auto I = LocalDeclMap.find(VD); if (I != LocalDeclMap.end()) { - if (auto RefTy = VD->getType()->getAs<ReferenceType>()) - return EmitLoadOfReferenceLValue(I->second, RefTy); + if (VD->getType()->isReferenceType()) + return EmitLoadOfReferenceLValue(I->second, VD->getType(), + AlignmentSource::Decl); return MakeAddrLValue(I->second, T); } LValue CapLVal = @@ -2410,12 +2417,9 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { } // Drill into reference types. - LValue LV; - if (auto RefTy = VD->getType()->getAs<ReferenceType>()) { - LV = EmitLoadOfReferenceLValue(addr, RefTy); - } else { - LV = MakeAddrLValue(addr, T, AlignmentSource::Decl); - } + LValue LV = VD->getType()->isReferenceType() ? + EmitLoadOfReferenceLValue(addr, VD->getType(), AlignmentSource::Decl) : + MakeAddrLValue(addr, T, AlignmentSource::Decl); bool isLocalStorage = VD->hasLocalStorage(); @@ -3748,7 +3752,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, } Address addr = base.getAddress(); - unsigned cvr = base.getVRQualifiers(); + unsigned RecordCVR = base.getVRQualifiers(); if (rec->isUnion()) { // For unions, there is no pointer adjustment. assert(!FieldType->isReferenceType() && "union has reference member"); @@ -3763,22 +3767,16 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, addr = emitAddrOfFieldStorage(*this, addr, field); // If this is a reference field, load the reference right now. - if (const ReferenceType *refType = FieldType->getAs<ReferenceType>()) { - llvm::LoadInst *load = Builder.CreateLoad(addr, "ref"); - if (cvr & Qualifiers::Volatile) load->setVolatile(true); - - CGM.DecorateInstructionWithTBAA(load, FieldTBAAInfo); - - FieldType = refType->getPointeeType(); - CharUnits Align = getNaturalTypeAlignment(FieldType, &FieldBaseInfo, - &FieldTBAAInfo, - /* forPointeeType= */ true); - addr = Address(load, Align); - - // Qualifiers on the struct don't apply to the referencee, and - // we'll pick up CVR from the actual type later, so reset these - // additional qualifiers now. - cvr = 0; + if (FieldType->isReferenceType()) { + LValue RefLVal = MakeAddrLValue(addr, FieldType, FieldBaseInfo, + FieldTBAAInfo); + if (RecordCVR & Qualifiers::Volatile) + RefLVal.getQuals().setVolatile(true); + addr = EmitLoadOfReference(RefLVal, &FieldBaseInfo, &FieldTBAAInfo); + + // Qualifiers on the struct don't apply to the referencee. + RecordCVR = 0; + FieldType = FieldType->getPointeeType(); } } @@ -3793,7 +3791,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, addr = EmitFieldAnnotations(field, addr); LValue LV = MakeAddrLValue(addr, FieldType, FieldBaseInfo, FieldTBAAInfo); - LV.getQuals().addCVRQualifiers(cvr); + LV.getQuals().addCVRQualifiers(RecordCVR); // __weak attribute on a field is ignored. if (LV.getQuals().getObjCGCAttr() == Qualifiers::Weak) diff --git a/lib/CodeGen/CGOpenMPRuntime.cpp b/lib/CodeGen/CGOpenMPRuntime.cpp index b23d601eb8..0a798b8903 100644 --- a/lib/CodeGen/CGOpenMPRuntime.cpp +++ b/lib/CodeGen/CGOpenMPRuntime.cpp @@ -1037,8 +1037,8 @@ static LValue loadToBegin(CodeGenFunction &CGF, QualType BaseTy, QualType ElTy, if (auto *PtrTy = BaseTy->getAs<PointerType>()) BaseLV = CGF.EmitLoadOfPointerLValue(BaseLV.getAddress(), PtrTy); else { - BaseLV = CGF.EmitLoadOfReferenceLValue(BaseLV.getAddress(), - BaseTy->castAs<ReferenceType>()); + LValue RefLVal = CGF.MakeAddrLValue(BaseLV.getAddress(), BaseTy); + BaseLV = CGF.EmitLoadOfReferenceLValue(RefLVal); } BaseTy = BaseTy->getPointeeType(); } diff --git a/lib/CodeGen/CGStmtOpenMP.cpp b/lib/CodeGen/CGStmtOpenMP.cpp index f46ca23c55..df7f7802d3 100644 --- a/lib/CodeGen/CGStmtOpenMP.cpp +++ b/lib/CodeGen/CGStmtOpenMP.cpp @@ -417,8 +417,7 @@ static llvm::Function *emitOutlinedFunctionPrologue( Address ArgAddr = ArgLVal.getAddress(); if (!VarTy->isReferenceType()) { if (ArgLVal.getType()->isLValueReferenceType()) { - ArgAddr = CGF.EmitLoadOfReference( - ArgAddr, ArgLVal.getType()->castAs<ReferenceType>()); + ArgAddr = CGF.EmitLoadOfReference(ArgLVal); } else if (!VarTy->isVariablyModifiedType() || !VarTy->isPointerType()) { assert(ArgLVal.getType()->isPointerType()); ArgAddr = CGF.EmitLoadOfPointer( diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index 210dbaa993..2d919876e2 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -1952,10 +1952,17 @@ public: LValueBaseInfo *BaseInfo = nullptr, TBAAAccessInfo *TBAAInfo = nullptr); - Address EmitLoadOfReference(Address Ref, const ReferenceType *RefTy, - LValueBaseInfo *BaseInfo = nullptr, - TBAAAccessInfo *TBAAInfo = nullptr); - LValue EmitLoadOfReferenceLValue(Address Ref, const ReferenceType *RefTy); + Address EmitLoadOfReference(LValue RefLVal, + LValueBaseInfo *PointeeBaseInfo = nullptr, + TBAAAccessInfo *PointeeTBAAInfo = nullptr); + LValue EmitLoadOfReferenceLValue(LValue RefLVal); + LValue EmitLoadOfReferenceLValue(Address RefAddr, QualType RefTy, + AlignmentSource Source = + AlignmentSource::Type) { + LValue RefLVal = MakeAddrLValue(RefAddr, RefTy, LValueBaseInfo(Source), + CGM.getTBAAAccessInfo(RefTy)); + return EmitLoadOfReferenceLValue(RefLVal); + } Address EmitLoadOfPointer(Address Ptr, const PointerType *PtrTy, LValueBaseInfo *BaseInfo = nullptr, |