Skip to content

Commit 47dd2e2

Browse files
committed
inline the lambda shim, to simplify
1 parent a62ef50 commit 47dd2e2

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,24 +2265,21 @@ class LowerMatrixIntrinsics {
22652265
}
22662266

22672267
MatrixTy VisitPHI(PHINode *Inst, const ShapeInfo &SI, IRBuilder<> &Builder) {
2268-
// Shim this->getMatrix to adjust where it creates new instructions, which
2269-
// it may need to insert for re-shaping.
2270-
auto GetMatrix = [this, &Builder, SI, Inst](Value *MatrixVal) -> MatrixTy {
2271-
IRBuilder<>::InsertPointGuard IPG(Builder);
2272-
if (auto *MatrixInst = dyn_cast<Instruction>(MatrixVal)) {
2273-
if (auto MaybeIP = MatrixInst->getInsertionPointAfterDef())
2274-
Builder.SetInsertPoint(*MaybeIP);
2275-
} else if (auto MaybeIP = Inst->getInsertionPointAfterDef())
2276-
Builder.SetInsertPoint(*MaybeIP);
2277-
2278-
return this->getMatrix(MatrixVal, SI, Builder);
2279-
};
2280-
2281-
MatrixTy PhiM = GetMatrix(Inst);
2268+
auto BlockIP = Inst->getParent()->getFirstInsertionPt();
2269+
Builder.SetInsertPoint(BlockIP);
2270+
MatrixTy PhiM = getMatrix(Inst, SI, Builder);
22822271

22832272
for (auto [IncomingV, IncomingB] :
22842273
llvm::zip_equal(Inst->incoming_values(), Inst->blocks())) {
2285-
MatrixTy OpM = GetMatrix(IncomingV);
2274+
// getMatrix() may insert some instructions to help with reshaping. The
2275+
// safest place for those is at the top of the block after the rest of the
2276+
// PHI's. Even better, if we can put it in the incoming block.
2277+
Builder.SetInsertPoint(BlockIP);
2278+
if (auto *IncomingInst = dyn_cast<Instruction>(IncomingV))
2279+
if (auto MaybeIP = IncomingInst->getInsertionPointAfterDef())
2280+
Builder.SetInsertPoint(*MaybeIP);
2281+
2282+
MatrixTy OpM = getMatrix(IncomingV, SI, Builder);
22862283

22872284
for (unsigned VI = 0, VE = PhiM.getNumVectors(); VI != VE; ++VI) {
22882285
PHINode *NewPHI = cast<PHINode>(PhiM.getVector(VI));
@@ -2292,7 +2289,7 @@ class LowerMatrixIntrinsics {
22922289

22932290
// finalizeLowering() may also insert instructions in some cases. The safe
22942291
// place for those is at the end of the initial block of PHIs.
2295-
Builder.SetInsertPoint(Inst->getParent()->getFirstInsertionPt());
2292+
Builder.SetInsertPoint(BlockIP);
22962293
return PhiM;
22972294
}
22982295

0 commit comments

Comments
 (0)