diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Analysis/CostModel.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Analysis/CostModel.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/contrib/llvm-project/llvm/lib/Analysis/CostModel.cpp b/contrib/llvm-project/llvm/lib/Analysis/CostModel.cpp index 83b7d5cbfc3e..f407ec0d017a 100644 --- a/contrib/llvm-project/llvm/lib/Analysis/CostModel.cpp +++ b/contrib/llvm-project/llvm/lib/Analysis/CostModel.cpp @@ -16,10 +16,12 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/CostModel.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/Passes.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/IR/Function.h" +#include "llvm/IR/PassManager.h" #include "llvm/InitializePasses.h" #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" @@ -113,3 +115,23 @@ void CostModelAnalysis::print(raw_ostream &OS, const Module*) const { } } } + +PreservedAnalyses CostModelPrinterPass::run(Function &F, + FunctionAnalysisManager &AM) { + auto &TTI = AM.getResult<TargetIRAnalysis>(F); + OS << "Cost Model for function '" << F.getName() << "'\n"; + for (BasicBlock &B : F) { + for (Instruction &Inst : B) { + // TODO: Use a pass parameter instead of cl::opt CostKind to determine + // which cost kind to print. + InstructionCost Cost = TTI.getInstructionCost(&Inst, CostKind); + if (auto CostVal = Cost.getValue()) + OS << "Cost Model: Found an estimated cost of " << *CostVal; + else + OS << "Cost Model: Invalid cost"; + + OS << " for instruction: " << Inst << "\n"; + } + } + return PreservedAnalyses::all(); +} |