Skip to content

Commit 4a4970e

Browse files
author
Manman Ren
committed
Struct-path aware TBAA: update getMostGenericTBAA
The tag is of type TBAANode when flag EnableStructPathTBAA is off. Move implementation of MDNode::getMostGenericTBAA to TypeBasedAliasAnalysis.cpp since it depends on how to interprete the MDNodes for scalar TBAA and struct-path aware TBAA. llvm-svn: 180068
1 parent 19f0e8c commit 4a4970e

File tree

2 files changed

+60
-38
lines changed

2 files changed

+60
-38
lines changed

llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ bool TypeBasedAliasAnalysis::pointsToConstantMemory(const Location &Loc,
376376

377377
// If this is an "immutable" type, we can assume the pointer is pointing
378378
// to constant memory.
379-
if (TBAANode(M).TypeIsImmutable())
379+
if (!EnableStructPathTBAA && TBAANode(M).TypeIsImmutable())
380380
return true;
381381

382382
return AliasAnalysis::pointsToConstantMemory(Loc, OrLocal);
@@ -392,7 +392,7 @@ TypeBasedAliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
392392
// If this is an "immutable" type, we can assume the call doesn't write
393393
// to memory.
394394
if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
395-
if (TBAANode(M).TypeIsImmutable())
395+
if (!EnableStructPathTBAA && TBAANode(M).TypeIsImmutable())
396396
Min = OnlyReadsMemory;
397397

398398
return ModRefBehavior(AliasAnalysis::getModRefBehavior(CS) & Min);
@@ -434,3 +434,61 @@ TypeBasedAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
434434

435435
return AliasAnalysis::getModRefInfo(CS1, CS2);
436436
}
437+
438+
MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) {
439+
if (!A || !B)
440+
return NULL;
441+
442+
if (A == B)
443+
return A;
444+
445+
// For struct-path aware TBAA, we use the access type of the tag.
446+
if (EnableStructPathTBAA) {
447+
A = cast_or_null<MDNode>(A->getOperand(1));
448+
if (!A) return 0;
449+
B = cast_or_null<MDNode>(B->getOperand(1));
450+
if (!B) return 0;
451+
}
452+
453+
SmallVector<MDNode *, 4> PathA;
454+
MDNode *T = A;
455+
while (T) {
456+
PathA.push_back(T);
457+
if (EnableStructPathTBAA)
458+
T = T->getNumOperands() >= 3 ? cast_or_null<MDNode>(T->getOperand(2)) : 0;
459+
else
460+
T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1)) : 0;
461+
}
462+
463+
SmallVector<MDNode *, 4> PathB;
464+
T = B;
465+
while (T) {
466+
PathB.push_back(T);
467+
if (EnableStructPathTBAA)
468+
T = T->getNumOperands() >= 3 ? cast_or_null<MDNode>(T->getOperand(2)) : 0;
469+
else
470+
T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1)) : 0;
471+
}
472+
473+
int IA = PathA.size() - 1;
474+
int IB = PathB.size() - 1;
475+
476+
MDNode *Ret = 0;
477+
while (IA >= 0 && IB >=0) {
478+
if (PathA[IA] == PathB[IB])
479+
Ret = PathA[IA];
480+
else
481+
break;
482+
--IA;
483+
--IB;
484+
}
485+
if (!EnableStructPathTBAA)
486+
return Ret;
487+
488+
if (!Ret)
489+
return 0;
490+
// We need to convert from a type node to a tag node.
491+
Type *Int64 = IntegerType::get(A->getContext(), 64);
492+
Value *Ops[3] = { Ret, Ret, ConstantInt::get(Int64, 0) };
493+
return MDNode::get(A->getContext(), Ops);
494+
}

llvm/lib/IR/Metadata.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -403,42 +403,6 @@ void MDNode::replaceOperand(MDNodeOperand *Op, Value *To) {
403403
}
404404
}
405405

406-
MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) {
407-
if (!A || !B)
408-
return NULL;
409-
410-
if (A == B)
411-
return A;
412-
413-
SmallVector<MDNode *, 4> PathA;
414-
MDNode *T = A;
415-
while (T) {
416-
PathA.push_back(T);
417-
T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1)) : 0;
418-
}
419-
420-
SmallVector<MDNode *, 4> PathB;
421-
T = B;
422-
while (T) {
423-
PathB.push_back(T);
424-
T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1)) : 0;
425-
}
426-
427-
int IA = PathA.size() - 1;
428-
int IB = PathB.size() - 1;
429-
430-
MDNode *Ret = 0;
431-
while (IA >= 0 && IB >=0) {
432-
if (PathA[IA] == PathB[IB])
433-
Ret = PathA[IA];
434-
else
435-
break;
436-
--IA;
437-
--IB;
438-
}
439-
return Ret;
440-
}
441-
442406
MDNode *MDNode::getMostGenericFPMath(MDNode *A, MDNode *B) {
443407
if (!A || !B)
444408
return NULL;

0 commit comments

Comments
 (0)