@@ -299,26 +299,30 @@ void getConstantAnalysis(Constant *Val, TypeAnalyzer &TA,
299
299
int Off = (int )ai.getLimitedValue ();
300
300
301
301
getConstantAnalysis (Op, TA, analysis);
302
- auto mid = analysis[Op].ShiftIndices (DL, /* init offset*/ 0 ,
303
- /* maxSize*/ ObjSize,
304
- /* addOffset*/ Off);
305
-
302
+ auto mid = analysis[Op];
306
303
if (TA.fntypeinfo .Function ->getParent ()
307
304
->getDataLayout ()
308
305
.getTypeSizeInBits (CA->getType ()) >= 16 ) {
309
306
mid.ReplaceIntWithAnything ();
310
307
}
311
308
312
- Result |= mid;
309
+ Result |= mid.ShiftIndices (DL, /* init offset*/ 0 ,
310
+ /* maxSize*/ ObjSize,
311
+ /* addOffset*/ Off);
313
312
}
313
+ Result = Result.CanonicalizeValue (
314
+ (TA.fntypeinfo .Function ->getParent ()->getDataLayout ().getTypeSizeInBits (
315
+ CA->getType ()) +
316
+ 7 ) /
317
+ 8 ,
318
+ DL);
314
319
return ;
315
320
}
316
321
317
322
// Type of an sequence is the aggregation of
318
323
// the subtypes
319
324
if (auto CD = dyn_cast<ConstantDataSequential>(Val)) {
320
325
TypeTree &Result = analysis[Val];
321
-
322
326
for (unsigned i = 0 , size = CD->getNumElements (); i < size; ++i) {
323
327
assert (TA.fntypeinfo .Function );
324
328
auto Op = CD->getElementAsConstant (i);
@@ -349,18 +353,24 @@ void getConstantAnalysis(Constant *Val, TypeAnalyzer &TA,
349
353
int Off = (int )ai.getLimitedValue ();
350
354
351
355
getConstantAnalysis (Op, TA, analysis);
352
- auto mid = analysis[Op].ShiftIndices (DL, /* init offset*/ 0 ,
353
- /* maxSize*/ ObjSize,
354
- /* addOffset*/ Off);
355
-
356
+ auto mid = analysis[Op];
356
357
if (TA.fntypeinfo .Function ->getParent ()
357
358
->getDataLayout ()
358
359
.getTypeSizeInBits (CD->getType ()) >= 16 ) {
359
360
mid.ReplaceIntWithAnything ();
360
361
}
362
+ Result |= mid.ShiftIndices (DL, /* init offset*/ 0 ,
363
+ /* maxSize*/ ObjSize,
364
+ /* addOffset*/ Off);
361
365
362
366
Result |= mid;
363
367
}
368
+ Result = Result.CanonicalizeValue (
369
+ (TA.fntypeinfo .Function ->getParent ()->getDataLayout ().getTypeSizeInBits (
370
+ CD->getType ()) +
371
+ 7 ) /
372
+ 8 ,
373
+ DL);
364
374
return ;
365
375
}
366
376
@@ -849,12 +859,12 @@ void TypeAnalyzer::considerTBAA() {
849
859
(DL.getTypeSizeInBits (SI->getValueOperand ()->getType ()) + 7 ) / 8 ;
850
860
updateAnalysis (SI->getPointerOperand (),
851
861
vdptr
862
+ // Don't propagate "Anything" into ptr
863
+ .PurgeAnything ()
852
864
// Cut off any values outside of store
853
865
.ShiftIndices (DL, /* init offset*/ 0 ,
854
866
/* max size*/ StoreSize,
855
867
/* new offset*/ 0 )
856
- // Don't propagate "Anything" into ptr
857
- .PurgeAnything ()
858
868
.Only (-1 ),
859
869
SI);
860
870
TypeTree req = vdptr.Only (-1 );
@@ -863,12 +873,12 @@ void TypeAnalyzer::considerTBAA() {
863
873
auto LoadSize = (DL.getTypeSizeInBits (LI->getType ()) + 7 ) / 8 ;
864
874
updateAnalysis (LI->getPointerOperand (),
865
875
vdptr
876
+ // Don't propagate "Anything" into ptr
877
+ .PurgeAnything ()
866
878
// Cut off any values outside of load
867
879
.ShiftIndices (DL, /* init offset*/ 0 ,
868
880
/* max size*/ LoadSize,
869
881
/* new offset*/ 0 )
870
- // Don't propagate "Anything" into ptr
871
- .PurgeAnything ()
872
882
.Only (-1 ),
873
883
LI);
874
884
TypeTree req = vdptr.Only (-1 );
@@ -1125,12 +1135,12 @@ void TypeAnalyzer::visitCmpInst(CmpInst &cmp) {
1125
1135
if (direction & UP) {
1126
1136
updateAnalysis (
1127
1137
cmp.getOperand (0 ),
1128
- TypeTree (getAnalysis (cmp.getOperand (1 )).Data0 ().PurgeAnything ()[{}] )
1138
+ TypeTree (getAnalysis (cmp.getOperand (1 )).Inner0 ().PurgeAnything ())
1129
1139
.Only (-1 ),
1130
1140
&cmp);
1131
1141
updateAnalysis (
1132
1142
cmp.getOperand (1 ),
1133
- TypeTree (getAnalysis (cmp.getOperand (0 )).Data0 ().PurgeAnything ()[{}] )
1143
+ TypeTree (getAnalysis (cmp.getOperand (0 )).Inner0 ().PurgeAnything ())
1134
1144
.Only (-1 ),
1135
1145
&cmp);
1136
1146
}
@@ -1194,8 +1204,9 @@ void TypeAnalyzer::visitStoreInst(StoreInst &I) {
1194
1204
// Only propagate mappings in range that aren't "Anything" into the pointer
1195
1205
auto ptr = TypeTree (BaseType::Pointer);
1196
1206
auto purged = getAnalysis (I.getValueOperand ())
1207
+ .PurgeAnything ()
1197
1208
.ShiftIndices (DL, /* start*/ 0 , StoreSize, /* addOffset*/ 0 )
1198
- .PurgeAnything ();
1209
+ .ReplaceMinus ();
1199
1210
ptr |= purged;
1200
1211
1201
1212
if (direction & UP) {
@@ -2460,13 +2471,13 @@ void TypeAnalyzer::visitMemTransferCommon(llvm::CallInst &MTI) {
2460
2471
2461
2472
auto &dl = MTI.getParent ()->getParent ()->getParent ()->getDataLayout ();
2462
2473
TypeTree res = getAnalysis (MTI.getArgOperand (0 ))
2474
+ .PurgeAnything ()
2463
2475
.Data0 ()
2464
- .ShiftIndices (dl, 0 , sz, 0 )
2465
- .PurgeAnything ();
2476
+ .ShiftIndices (dl, 0 , sz, 0 );
2466
2477
TypeTree res2 = getAnalysis (MTI.getArgOperand (1 ))
2478
+ .PurgeAnything ()
2467
2479
.Data0 ()
2468
- .ShiftIndices (dl, 0 , sz, 0 )
2469
- .PurgeAnything ();
2480
+ .ShiftIndices (dl, 0 , sz, 0 );
2470
2481
2471
2482
bool Legal = true ;
2472
2483
res.checkedOrIn (res2, /* PointerIntSame*/ false , Legal);
@@ -3772,11 +3783,11 @@ void TypeAnalyzer::visitCallInst(CallInst &call) {
3772
3783
3773
3784
auto &dl = call.getParent ()->getParent ()->getParent ()->getDataLayout ();
3774
3785
TypeTree res = getAnalysis (call.getArgOperand (0 ))
3786
+ .PurgeAnything ()
3775
3787
.Data0 ()
3776
- .ShiftIndices (dl, 0 , sz, 0 )
3777
- .PurgeAnything ();
3788
+ .ShiftIndices (dl, 0 , sz, 0 );
3778
3789
TypeTree res2 =
3779
- getAnalysis (&call).Data0 ().ShiftIndices (dl, 0 , sz, 0 ). PurgeAnything ( );
3790
+ getAnalysis (&call).PurgeAnything (). Data0 ().ShiftIndices (dl, 0 , sz, 0 );
3780
3791
3781
3792
res.orIn (res2, /* PointerIntSame*/ false );
3782
3793
res.insert ({}, BaseType::Pointer);
@@ -4524,6 +4535,9 @@ void TypeAnalyzer::visitIPOCall(CallInst &call, Function &fn) {
4524
4535
4525
4536
TypeResults STR = interprocedural.analyzeFunction (typeInfo);
4526
4537
4538
+ if (EnzymePrintType)
4539
+ llvm::errs () << " ending IPO of " << call << " \n " ;
4540
+
4527
4541
if (hasUp) {
4528
4542
auto a = fn.arg_begin ();
4529
4543
#if LLVM_VERSION_MAJOR >= 14
@@ -4533,6 +4547,9 @@ void TypeAnalyzer::visitIPOCall(CallInst &call, Function &fn) {
4533
4547
#endif
4534
4548
{
4535
4549
auto dt = STR.query (a);
4550
+ if (EnzymePrintType)
4551
+ llvm::errs () << " updating " << *arg << " = " << dt.str ()
4552
+ << " via IPO of " << call << " arg " << *a << " \n " ;
4536
4553
updateAnalysis (arg, dt, &call);
4537
4554
++a;
4538
4555
}
0 commit comments