diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h --- a/llvm/include/llvm/InitializePasses.h +++ b/llvm/include/llvm/InitializePasses.h @@ -259,6 +259,7 @@ void initializeLowerSwitchPass(PassRegistry&); void initializeLowerTypeTestsPass(PassRegistry&); void initializeLowerMatrixIntrinsicsLegacyPassPass(PassRegistry &); +void initializeLowerMatrixIntrinsicsMinimalLegacyPassPass(PassRegistry &); void initializeMIRCanonicalizerPass(PassRegistry &); void initializeMIRNamerPass(PassRegistry &); void initializeMIRPrintingPassPass(PassRegistry&); diff --git a/llvm/include/llvm/Transforms/Scalar.h b/llvm/include/llvm/Transforms/Scalar.h --- a/llvm/include/llvm/Transforms/Scalar.h +++ b/llvm/include/llvm/Transforms/Scalar.h @@ -372,6 +372,12 @@ // Pass *createLowerMatrixIntrinsicsPass(); +//===----------------------------------------------------------------------===// +// +// LowerMatrixIntrinsicsMinimal - Lower matrix intrinsics to vector operations (minimal) +// +Pass *createLowerMatrixIntrinsicsMinimalPass(); + //===----------------------------------------------------------------------===// // // LowerWidenableCondition - Lower widenable condition to i1 true. diff --git a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp --- a/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp @@ -146,7 +146,7 @@ Function &Func; const DataLayout &DL; const TargetTransformInfo &TTI; - OptimizationRemarkEmitter &ORE; + OptimizationRemarkEmitter *ORE; /// Contains estimates of the number of operations (loads, stores, compute) required to lower a matrix operation. struct OpInfoTy { @@ -299,7 +299,7 @@ public: LowerMatrixIntrinsics(Function &F, TargetTransformInfo &TTI, - OptimizationRemarkEmitter &ORE) + OptimizationRemarkEmitter *ORE) : Func(F), DL(F.getParent()->getDataLayout()), TTI(TTI), ORE(ORE) {} unsigned getNumOps(Type *VT) { @@ -606,8 +606,10 @@ } } - RemarkGenerator RemarkGen(Inst2ColumnMatrix, ORE, Func); - RemarkGen.emitRemarks(); + if (ORE) { + RemarkGenerator RemarkGen(Inst2ColumnMatrix, *ORE, Func); + RemarkGen.emitRemarks(); + } for (Instruction *Inst : reverse(ToRemove)) Inst->eraseFromParent(); @@ -1481,7 +1483,7 @@ FunctionAnalysisManager &AM) { auto &TTI = AM.getResult(F); auto &ORE = AM.getResult(F); - LowerMatrixIntrinsics LMT(F, TTI, ORE); + LowerMatrixIntrinsics LMT(F, TTI, &ORE); if (LMT.Visit()) { PreservedAnalyses PA; PA.preserveSet(); @@ -1504,7 +1506,7 @@ bool runOnFunction(Function &F) override { auto &TTI = getAnalysis().getTTI(F); auto &ORE = getAnalysis().getORE(); - LowerMatrixIntrinsics LMT(F, TTI, ORE); + LowerMatrixIntrinsics LMT(F, TTI, &ORE); bool C = LMT.Visit(); return C; } @@ -1528,3 +1530,41 @@ Pass *llvm::createLowerMatrixIntrinsicsPass() { return new LowerMatrixIntrinsicsLegacyPass(); } + +namespace { + +class LowerMatrixIntrinsicsMinimalLegacyPass : public FunctionPass { +public: + static char ID; + + LowerMatrixIntrinsicsMinimalLegacyPass() : FunctionPass(ID) { + initializeLowerMatrixIntrinsicsMinimalLegacyPassPass( + *PassRegistry::getPassRegistry()); + } + + bool runOnFunction(Function &F) override { + if (!shouldRunMatrixLowering(F)) + return false; + auto &TTI = getAnalysis().getTTI(F); + LowerMatrixIntrinsics LMT(F, TTI, nullptr); + bool C = LMT.Visit(); + return C; + } + + void getAnalysisUsage(AnalysisUsage &AU) const override { + AU.addRequired(); + AU.setPreservesCFG(); + } +}; +} // namespace + +static const char pass_name_minimal[] = "Lower the matrix intrinsics (minimal)"; +char LowerMatrixIntrinsicsMinimalLegacyPass::ID = 0; +INITIALIZE_PASS_BEGIN(LowerMatrixIntrinsicsMinimalLegacyPass, "lower-matrix-intrinsics-minimal", pass_name_minimal, + false, false) +INITIALIZE_PASS_END(LowerMatrixIntrinsicsMinimalLegacyPass, "lower-matrix-intrinsics-minimal", pass_name_minimal, + false, false) + +Pass *llvm::createLowerMatrixIntrinsicsMinimalPass() { + return new LowerMatrixIntrinsicsMinimalLegacyPass(); +}