Skip to content

Commit 8ed43c4

Browse files
authored
[Matrix] Hoist IRBuilder<> out of Visit* functions. NFC (#144369)
1 parent 0058272 commit 8ed43c4

File tree

1 file changed

+21
-27
lines changed

1 file changed

+21
-27
lines changed

llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,24 +1146,24 @@ class LowerMatrixIntrinsics {
11461146
Value *Op1;
11471147
Value *Op2;
11481148
MatrixTy Result;
1149+
IRBuilder<> Builder(Inst);
11491150
if (auto *BinOp = dyn_cast<BinaryOperator>(Inst))
1150-
Result = VisitBinaryOperator(BinOp, SI);
1151+
Result = VisitBinaryOperator(BinOp, SI, Builder);
11511152
else if (auto *Cast = dyn_cast<CastInst>(Inst))
1152-
Result = VisitCastInstruction(Cast, SI);
1153+
Result = VisitCastInstruction(Cast, SI, Builder);
11531154
else if (auto *UnOp = dyn_cast<UnaryOperator>(Inst))
1154-
Result = VisitUnaryOperator(UnOp, SI);
1155+
Result = VisitUnaryOperator(UnOp, SI, Builder);
11551156
else if (auto *Intr = dyn_cast<IntrinsicInst>(Inst))
1156-
Result = VisitIntrinsicInst(Intr, SI);
1157+
Result = VisitIntrinsicInst(Intr, SI, Builder);
11571158
else if (auto *Select = dyn_cast<SelectInst>(Inst))
1158-
Result = VisitSelectInst(Select, SI);
1159+
Result = VisitSelectInst(Select, SI, Builder);
11591160
else if (match(Inst, m_Load(m_Value(Op1))))
1160-
Result = VisitLoad(cast<LoadInst>(Inst), SI, Op1);
1161+
Result = VisitLoad(cast<LoadInst>(Inst), SI, Op1, Builder);
11611162
else if (match(Inst, m_Store(m_Value(Op1), m_Value(Op2))))
1162-
Result = VisitStore(cast<StoreInst>(Inst), SI, Op1, Op2);
1163+
Result = VisitStore(cast<StoreInst>(Inst), SI, Op1, Op2, Builder);
11631164
else
11641165
continue;
11651166

1166-
IRBuilder<> Builder(Inst);
11671167
finalizeLowering(Inst, Result, Builder);
11681168
Changed = true;
11691169
}
@@ -1204,7 +1204,8 @@ class LowerMatrixIntrinsics {
12041204
}
12051205

12061206
/// Replace intrinsic calls.
1207-
MatrixTy VisitIntrinsicInst(IntrinsicInst *Inst, const ShapeInfo &SI) {
1207+
MatrixTy VisitIntrinsicInst(IntrinsicInst *Inst, const ShapeInfo &SI,
1208+
IRBuilder<> &Builder) {
12081209
assert(Inst->getCalledFunction() &&
12091210
Inst->getCalledFunction()->isIntrinsic());
12101211

@@ -1219,7 +1220,6 @@ class LowerMatrixIntrinsics {
12191220
return LowerColumnMajorStore(Inst);
12201221
case Intrinsic::abs:
12211222
case Intrinsic::fabs: {
1222-
IRBuilder<> Builder(Inst);
12231223
MatrixTy Result;
12241224
MatrixTy M = getMatrix(Inst->getOperand(0), SI, Builder);
12251225
Builder.setFastMathFlags(getFastMathFlags(Inst));
@@ -1298,7 +1298,6 @@ class LowerMatrixIntrinsics {
12981298
ShapeInfo MatrixShape, Value *I, Value *J,
12991299
ShapeInfo ResultShape, Type *EltTy,
13001300
IRBuilder<> &Builder) {
1301-
13021301
Value *Offset = Builder.CreateAdd(
13031302
Builder.CreateMul(J, Builder.getInt64(MatrixShape.getStride())), I);
13041303

@@ -2228,26 +2227,24 @@ class LowerMatrixIntrinsics {
22282227
}
22292228

22302229
/// Lower load instructions.
2231-
MatrixTy VisitLoad(LoadInst *Inst, const ShapeInfo &SI, Value *Ptr) {
2232-
IRBuilder<> Builder(Inst);
2230+
MatrixTy VisitLoad(LoadInst *Inst, const ShapeInfo &SI, Value *Ptr,
2231+
IRBuilder<> &Builder) {
22332232
return LowerLoad(Inst, Ptr, Inst->getAlign(),
22342233
Builder.getInt64(SI.getStride()), Inst->isVolatile(), SI);
22352234
}
22362235

22372236
MatrixTy VisitStore(StoreInst *Inst, const ShapeInfo &SI, Value *StoredVal,
2238-
Value *Ptr) {
2239-
IRBuilder<> Builder(Inst);
2237+
Value *Ptr, IRBuilder<> &Builder) {
22402238
return LowerStore(Inst, StoredVal, Ptr, Inst->getAlign(),
22412239
Builder.getInt64(SI.getStride()), Inst->isVolatile(), SI);
22422240
}
22432241

22442242
/// Lower binary operators.
2245-
MatrixTy VisitBinaryOperator(BinaryOperator *Inst, const ShapeInfo &SI) {
2243+
MatrixTy VisitBinaryOperator(BinaryOperator *Inst, const ShapeInfo &SI,
2244+
IRBuilder<> &Builder) {
22462245
Value *Lhs = Inst->getOperand(0);
22472246
Value *Rhs = Inst->getOperand(1);
22482247

2249-
IRBuilder<> Builder(Inst);
2250-
22512248
MatrixTy Result;
22522249
MatrixTy A = getMatrix(Lhs, SI, Builder);
22532250
MatrixTy B = getMatrix(Rhs, SI, Builder);
@@ -2265,11 +2262,10 @@ class LowerMatrixIntrinsics {
22652262
}
22662263

22672264
/// Lower unary operators.
2268-
MatrixTy VisitUnaryOperator(UnaryOperator *Inst, const ShapeInfo &SI) {
2265+
MatrixTy VisitUnaryOperator(UnaryOperator *Inst, const ShapeInfo &SI,
2266+
IRBuilder<> &Builder) {
22692267
Value *Op = Inst->getOperand(0);
22702268

2271-
IRBuilder<> Builder(Inst);
2272-
22732269
MatrixTy Result;
22742270
MatrixTy M = getMatrix(Op, SI, Builder);
22752271

@@ -2293,11 +2289,10 @@ class LowerMatrixIntrinsics {
22932289
}
22942290

22952291
/// Lower cast instructions.
2296-
MatrixTy VisitCastInstruction(CastInst *Inst, const ShapeInfo &Shape) {
2292+
MatrixTy VisitCastInstruction(CastInst *Inst, const ShapeInfo &Shape,
2293+
IRBuilder<> &Builder) {
22972294
Value *Op = Inst->getOperand(0);
22982295

2299-
IRBuilder<> Builder(Inst);
2300-
23012296
MatrixTy Result;
23022297
MatrixTy M = getMatrix(Op, Shape, Builder);
23032298

@@ -2315,13 +2310,12 @@ class LowerMatrixIntrinsics {
23152310
}
23162311

23172312
/// Lower selects.
2318-
MatrixTy VisitSelectInst(SelectInst *Inst, const ShapeInfo &Shape) {
2313+
MatrixTy VisitSelectInst(SelectInst *Inst, const ShapeInfo &Shape,
2314+
IRBuilder<> &Builder) {
23192315
Value *Cond = Inst->getOperand(0);
23202316
Value *OpA = Inst->getOperand(1);
23212317
Value *OpB = Inst->getOperand(2);
23222318

2323-
IRBuilder<> Builder(Inst);
2324-
23252319
MatrixTy Result;
23262320
MatrixTy A = getMatrix(OpA, Shape, Builder);
23272321
MatrixTy B = getMatrix(OpB, Shape, Builder);

0 commit comments

Comments
 (0)