@@ -376,7 +376,7 @@ bool TypeBasedAliasAnalysis::pointsToConstantMemory(const Location &Loc,
376
376
377
377
// If this is an "immutable" type, we can assume the pointer is pointing
378
378
// to constant memory.
379
- if (TBAANode (M).TypeIsImmutable ())
379
+ if (!EnableStructPathTBAA && TBAANode (M).TypeIsImmutable ())
380
380
return true ;
381
381
382
382
return AliasAnalysis::pointsToConstantMemory (Loc, OrLocal);
@@ -392,7 +392,7 @@ TypeBasedAliasAnalysis::getModRefBehavior(ImmutableCallSite CS) {
392
392
// If this is an "immutable" type, we can assume the call doesn't write
393
393
// to memory.
394
394
if (const MDNode *M = CS.getInstruction ()->getMetadata (LLVMContext::MD_tbaa))
395
- if (TBAANode (M).TypeIsImmutable ())
395
+ if (!EnableStructPathTBAA && TBAANode (M).TypeIsImmutable ())
396
396
Min = OnlyReadsMemory;
397
397
398
398
return ModRefBehavior (AliasAnalysis::getModRefBehavior (CS) & Min);
@@ -434,3 +434,61 @@ TypeBasedAliasAnalysis::getModRefInfo(ImmutableCallSite CS1,
434
434
435
435
return AliasAnalysis::getModRefInfo (CS1, CS2);
436
436
}
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
+ }
0 commit comments