diff options
| author | Ivan A. Kosarev <ikosarev@accesssoftek.com> | 2017-10-06 08:17:48 +0000 |
|---|---|---|
| committer | Ivan A. Kosarev <ikosarev@accesssoftek.com> | 2017-10-06 08:17:48 +0000 |
| commit | 383890bad473c1df16a4397aa669b801712b13d8 (patch) | |
| tree | 427d5183a2fa98149e930eff6d1e8c1eaf4a6a48 /clang/lib/CodeGen/CGExpr.cpp | |
| parent | 468e2f63f4742e403b77d3862d848a8479426c39 (diff) | |
| download | bcm5719-llvm-383890bad473c1df16a4397aa669b801712b13d8.tar.gz bcm5719-llvm-383890bad473c1df16a4397aa669b801712b13d8.zip | |
Refine generation of TBAA information in clang
This patch is an attempt to clarify and simplify generation and
propagation of TBAA information. The idea is to pack all values
that describe a memory access, namely, base type, access type and
offset, into a single structure. This is supposed to make further
changes, such as adding support for unions and array members,
easier to prepare and review.
DecorateInstructionWithTBAA() is no more responsible for
converting types to tags. These implicit conversions not only
complicate reading the code, but also suggest assigning scalar
access tags while we generally prefer full-size struct-path tags.
TBAAPathTag is replaced with TBAAAccessInfo; the latter is now
the type of the keys of the cache map that translates access
descriptors to metadata nodes.
Fixed a bug with writing to a wrong map in
getTBAABaseTypeMetadata() (former getTBAAStructTypeInfo()).
We now check for valid base access types every time we
dereference a field. The original code only checks the top-level
base type. See isValidBaseType() / isTBAAPathStruct() calls.
Some entities have been renamed to sound more adequate and less
confusing/misleading in presence of path-aware TBAA information.
Now we do not lookup twice for the same cache entry in
getAccessTagInfo().
Refined relevant comments and descriptions.
Differential Revision: https://reviews.llvm.org/D37826
llvm-svn: 315048
Diffstat (limited to 'clang/lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 076034ff51c..1bb57b6e2bb 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -1174,8 +1174,7 @@ LValue CodeGenFunction::EmitLValue(const Expr *E) { llvm::Value *V = LV.getPointer(); Scope.ForceCleanup({&V}); return LValue::MakeAddr(Address(V, LV.getAlignment()), LV.getType(), - getContext(), LV.getBaseInfo(), - LV.getTBAAAccessType()); + getContext(), LV.getBaseInfo(), LV.getTBAAInfo()); } // FIXME: Is it possible to create an ExprWithCleanups that produces a // bitfield lvalue or some other non-simple lvalue? @@ -1514,7 +1513,7 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(Address Addr, bool Volatile, // Atomic operations have to be done on integral types. LValue AtomicLValue = - LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo.AccessType); + LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo); if (Ty->isAtomicType() || LValueIsSuitableForInlineAtomic(AtomicLValue)) { return EmitAtomicLoad(AtomicLValue, Loc).getScalarVal(); } @@ -1525,11 +1524,10 @@ llvm::Value *CodeGenFunction::EmitLoadOfScalar(Address Addr, bool Volatile, Load->getContext(), llvm::ConstantAsMetadata::get(Builder.getInt32(1))); Load->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); } - if (TBAAInfo.AccessType) { - if (BaseInfo.getMayAlias()) - TBAAInfo = CGM.getTBAAMayAliasAccessInfo(); - CGM.DecorateInstructionWithTBAA(Load, TBAAInfo); - } + + if (BaseInfo.getMayAlias()) + TBAAInfo = CGM.getTBAAMayAliasAccessInfo(); + CGM.DecorateInstructionWithTBAA(Load, TBAAInfo); if (EmitScalarRangeCheck(Load, Ty, Loc)) { // In order to prevent the optimizer from throwing away the check, don't @@ -1596,7 +1594,7 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr, Value = EmitToMemory(Value, Ty); LValue AtomicLValue = - LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo.AccessType); + LValue::MakeAddr(Addr, Ty, getContext(), BaseInfo, TBAAInfo); if (Ty->isAtomicType() || (!isInit && LValueIsSuitableForInlineAtomic(AtomicLValue))) { EmitAtomicStore(RValue::get(Value), AtomicLValue, isInit); @@ -1610,11 +1608,10 @@ void CodeGenFunction::EmitStoreOfScalar(llvm::Value *Value, Address Addr, llvm::ConstantAsMetadata::get(Builder.getInt32(1))); Store->setMetadata(CGM.getModule().getMDKindID("nontemporal"), Node); } - if (TBAAInfo.AccessType) { - if (BaseInfo.getMayAlias()) - TBAAInfo = CGM.getTBAAMayAliasAccessInfo(); - CGM.DecorateInstructionWithTBAA(Store, TBAAInfo); - } + + if (BaseInfo.getMayAlias()) + TBAAInfo = CGM.getTBAAMayAliasAccessInfo(); + CGM.DecorateInstructionWithTBAA(Store, TBAAInfo); } void CodeGenFunction::EmitStoreOfScalar(llvm::Value *value, LValue lvalue, @@ -3753,17 +3750,33 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, LValue LV = MakeAddrLValue(addr, type, FieldBaseInfo); LV.getQuals().addCVRQualifiers(cvr); - if (TBAAPath) { + + // Fields of may_alias structs act like 'char' for TBAA purposes. + // FIXME: this should get propagated down through anonymous structs + // and unions. + if (mayAlias) { + LV.setTBAAInfo(CGM.getTBAAMayAliasAccessInfo()); + } else if (TBAAPath) { + // If no base type been assigned for the base access, then try to generate + // one for this base lvalue. + TBAAAccessInfo TBAAInfo = base.getTBAAInfo(); + if (!TBAAInfo.BaseType) { + TBAAInfo.BaseType = CGM.getTBAABaseTypeInfo(base.getType()); + assert(!TBAAInfo.Offset && + "Nonzero offset for an access with no base type!"); + } + + // Adjust offset to be relative to the base type. const ASTRecordLayout &Layout = getContext().getASTRecordLayout(field->getParent()); - // Set the base type to be the base type of the base LValue and - // update offset to be relative to the base type. unsigned CharWidth = getContext().getCharWidth(); - TBAAAccessInfo TBAAInfo = mayAlias ? - CGM.getTBAAMayAliasAccessInfo() : - TBAAAccessInfo(base.getTBAAInfo().BaseType, CGM.getTBAATypeInfo(type), - base.getTBAAInfo().Offset + Layout.getFieldOffset( - field->getFieldIndex()) / CharWidth); + if (TBAAInfo.BaseType) + TBAAInfo.Offset += + Layout.getFieldOffset(field->getFieldIndex()) / CharWidth; + + // Update the final access type. + TBAAInfo.AccessType = LV.getTBAAInfo().AccessType; + LV.setTBAAInfo(TBAAInfo); } @@ -3771,12 +3784,6 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, if (LV.getQuals().getObjCGCAttr() == Qualifiers::Weak) LV.getQuals().removeObjCGCAttr(); - // Fields of may_alias structs act like 'char' for TBAA purposes. - // FIXME: this should get propagated down through anonymous structs - // and unions. - if (mayAlias && LV.getTBAAAccessType()) - LV.setTBAAInfo(CGM.getTBAAMayAliasAccessInfo()); - return LV; } |

