X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FTypeBasedAliasAnalysis.cpp;h=27b469a43b01f4998a19c15d7e4ffe434671bdf2;hb=594e4a1dd36fb69e1420c643b0f548c2bb79c76c;hp=6738720db954da697a727400817934c573c173cc;hpb=07f099b867d60520d5fb391afd3d962638276cf4;p=oota-llvm.git diff --git a/lib/Analysis/TypeBasedAliasAnalysis.cpp b/lib/Analysis/TypeBasedAliasAnalysis.cpp index 6738720db95..27b469a43b0 100644 --- a/lib/Analysis/TypeBasedAliasAnalysis.cpp +++ b/lib/Analysis/TypeBasedAliasAnalysis.cpp @@ -339,7 +339,8 @@ static bool isStructPathTBAA(const MDNode *MD) { bool TypeBasedAliasAnalysis::Aliases(const MDNode *A, const MDNode *B) const { - if (isStructPathTBAA(A)) + // Make sure that both MDNodes are struct-path aware. + if (isStructPathTBAA(A) && isStructPathTBAA(B)) return PathAliases(A, B); // Keep track of the root node for A and B. @@ -385,6 +386,10 @@ TypeBasedAliasAnalysis::Aliases(const MDNode *A, bool TypeBasedAliasAnalysis::PathAliases(const MDNode *A, const MDNode *B) const { + // Verify that both input nodes are struct-path aware. + assert(isStructPathTBAA(A) && "MDNode A is not struct-path aware."); + assert(isStructPathTBAA(B) && "MDNode B is not struct-path aware."); + // Keep track of the root node for A and B. TBAAStructTypeNode RootA, RootB; TBAAStructTagNode TagA(A), TagB(B); @@ -449,9 +454,9 @@ TypeBasedAliasAnalysis::alias(const Location &LocA, // Get the attached MDNodes. If either value lacks a tbaa MDNode, we must // be conservative. - const MDNode *AM = LocA.TBAATag; + const MDNode *AM = LocA.AATags.TBAA; if (!AM) return AliasAnalysis::alias(LocA, LocB); - const MDNode *BM = LocB.TBAATag; + const MDNode *BM = LocB.AATags.TBAA; if (!BM) return AliasAnalysis::alias(LocA, LocB); // If they may alias, chain to the next AliasAnalysis. @@ -467,7 +472,7 @@ bool TypeBasedAliasAnalysis::pointsToConstantMemory(const Location &Loc, if (!EnableTBAA) return AliasAnalysis::pointsToConstantMemory(Loc, OrLocal); - const MDNode *M = Loc.TBAATag; + const MDNode *M = Loc.AATags.TBAA; if (!M) return AliasAnalysis::pointsToConstantMemory(Loc, OrLocal); // If this is an "immutable" type, we can assume the pointer is pointing @@ -508,7 +513,7 @@ TypeBasedAliasAnalysis::getModRefInfo(ImmutableCallSite CS, if (!EnableTBAA) return AliasAnalysis::getModRefInfo(CS, Loc); - if (const MDNode *L = Loc.TBAATag) + if (const MDNode *L = Loc.AATags.TBAA) if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa)) if (!Aliases(L, M)) @@ -560,7 +565,7 @@ MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) { return A; // For struct-path aware TBAA, we use the access type of the tag. - bool StructPath = isStructPathTBAA(A); + bool StructPath = isStructPathTBAA(A) && isStructPathTBAA(B); if (StructPath) { A = cast_or_null(A->getOperand(1)); if (!A) return nullptr; @@ -606,3 +611,24 @@ MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) { Value *Ops[3] = { Ret, Ret, ConstantInt::get(Int64, 0) }; return MDNode::get(A->getContext(), Ops); } + +void Instruction::getAAMetadata(AAMDNodes &N, bool Merge) const { + if (Merge) + N.TBAA = MDNode::getMostGenericTBAA(N.TBAA, + getMetadata(LLVMContext::MD_tbaa)); + else + N.TBAA = getMetadata(LLVMContext::MD_tbaa); + + if (Merge) + N.Scope = MDNode::intersect(N.Scope, + getMetadata(LLVMContext::MD_alias_scope)); + else + N.Scope = getMetadata(LLVMContext::MD_alias_scope); + + if (Merge) + N.NoAlias = MDNode::intersect(N.NoAlias, + getMetadata(LLVMContext::MD_noalias)); + else + N.NoAlias = getMetadata(LLVMContext::MD_noalias); +} +