@@ -97,19 +97,6 @@ static DISubprogram *getSubprogram(DIScope *Scope) {
97
97
return cast<DILocalScope>(Scope)->getSubprogram ();
98
98
}
99
99
100
- // / Erase \p V from \p BB and move \II forward to avoid invalidating
101
- // / iterators.
102
- static void eraseFromParentAndMove (Value *V, BasicBlock::reverse_iterator &II,
103
- BasicBlock &BB) {
104
- auto *Inst = cast<Instruction>(V);
105
- // Still used, don't erase.
106
- if (!Inst->use_empty ())
107
- return ;
108
- if (II != BB.rend () && Inst == &*II)
109
- ++II;
110
- Inst->eraseFromParent ();
111
- }
112
-
113
100
// / Return true if V is a splat of a value (which is used when multiplying a
114
101
// / matrix with a scalar).
115
102
static bool isSplat (Value *V) {
@@ -756,6 +743,26 @@ class LowerMatrixIntrinsics {
756
743
return Operation (T0, Shape0.t (), T1, Shape1.t ());
757
744
}
758
745
746
+ void eraseFromParentAndRemoveFromShapeMap (Instruction *Inst) {
747
+ auto Iter = ShapeMap.find (Inst);
748
+ if (Iter != ShapeMap.end ())
749
+ ShapeMap.erase (Iter);
750
+ Inst->eraseFromParent ();
751
+ }
752
+
753
+ // / Erase \p V from \p BB and move \II forward to avoid invalidating
754
+ // / iterators.
755
+ void eraseFromParentAndMove (Value *V, BasicBlock::reverse_iterator &II,
756
+ BasicBlock &BB) {
757
+ auto *Inst = cast<Instruction>(V);
758
+ // Still used, don't erase.
759
+ if (!Inst->use_empty ())
760
+ return ;
761
+ if (II != BB.rend () && Inst == &*II)
762
+ ++II;
763
+ eraseFromParentAndRemoveFromShapeMap (Inst);
764
+ }
765
+
759
766
void updateShapeAndReplaceAllUsesWith (Instruction &Old, Value *New) {
760
767
// We need to remove Old from the ShapeMap otherwise RAUW will replace it
761
768
// with New. We should only add New it it supportsShapeInfo so we insert
@@ -869,13 +876,13 @@ class LowerMatrixIntrinsics {
869
876
870
877
void liftTranspose (Instruction &I) {
871
878
// Erase dead Instructions after lifting transposes from binops.
872
- auto CleanupBinOp = [](Instruction &T, Value *A, Value *B) {
879
+ auto CleanupBinOp = [this ](Instruction &T, Value *A, Value *B) {
873
880
if (T.use_empty ())
874
- T. eraseFromParent ( );
881
+ eraseFromParentAndRemoveFromShapeMap (&T );
875
882
if (A->use_empty ())
876
- cast<Instruction>(A)-> eraseFromParent ( );
883
+ eraseFromParentAndRemoveFromShapeMap ( cast<Instruction>(A));
877
884
if (A != B && B->use_empty ())
878
- cast<Instruction>(B)-> eraseFromParent ( );
885
+ eraseFromParentAndRemoveFromShapeMap ( cast<Instruction>(B));
879
886
};
880
887
881
888
Value *A, *B, *AT, *BT;
@@ -1482,7 +1489,7 @@ class LowerMatrixIntrinsics {
1482
1489
m_Value (Arg)))) {
1483
1490
auto *NewLoad = Builder.CreateLoad (Op->getType (), Arg);
1484
1491
Op->replaceAllUsesWith (NewLoad);
1485
- cast<Instruction>(Op)-> eraseFromParent ( );
1492
+ eraseFromParentAndRemoveFromShapeMap ( cast<Instruction>(Op));
1486
1493
return ;
1487
1494
} else if (match (Op, m_Intrinsic<Intrinsic::matrix_transpose>(
1488
1495
m_Value (Arg)))) {
@@ -1851,15 +1858,15 @@ class LowerMatrixIntrinsics {
1851
1858
// Mark eliminated instructions as fused and remove them.
1852
1859
FusedInsts.insert (Store);
1853
1860
FusedInsts.insert (MatMul);
1854
- Store-> eraseFromParent ( );
1855
- MatMul-> eraseFromParent ( );
1861
+ eraseFromParentAndRemoveFromShapeMap (Store );
1862
+ eraseFromParentAndRemoveFromShapeMap (MatMul );
1856
1863
if (LoadOp0->hasNUses (0 )) {
1857
1864
FusedInsts.insert (LoadOp0);
1858
- LoadOp0-> eraseFromParent ();
1865
+ eraseFromParentAndRemoveFromShapeMap ( eraseFromParent () );
1859
1866
}
1860
1867
if (LoadOp1 != LoadOp0 && LoadOp1->hasNUses (0 )) {
1861
1868
FusedInsts.insert (LoadOp1);
1862
- LoadOp1-> eraseFromParent ();
1869
+ eraseFromParentAndRemoveFromShapeMap ( eraseFromParent () );
1863
1870
}
1864
1871
}
1865
1872
0 commit comments