[llvm] [CostModel] Add -cost-kind=all costmodel output (PR #130490)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 10 03:45:14 PDT 2025
================
@@ -63,34 +71,53 @@ static cl::opt<IntrinsicCostStrategy> IntrinsicCost(
#define CM_NAME "cost-model"
#define DEBUG_TYPE CM_NAME
+static InstructionCost getCost(Instruction &Inst, TTI::TargetCostKind CostKind,
+ TargetTransformInfo &TTI,
+ TargetLibraryInfo &TLI) {
+ auto *II = dyn_cast<IntrinsicInst>(&Inst);
+ if (II && IntrinsicCost != IntrinsicCostStrategy::InstructionCost) {
+ IntrinsicCostAttributes ICA(
+ II->getIntrinsicID(), *II, InstructionCost::getInvalid(),
+ /*TypeBasedOnly=*/IntrinsicCost ==
+ IntrinsicCostStrategy::TypeBasedIntrinsicCost,
+ &TLI);
+ return TTI.getIntrinsicInstrCost(ICA, CostKind);
+ }
+
+ return TTI.getInstructionCost(&Inst, CostKind);
+}
+
PreservedAnalyses CostModelPrinterPass::run(Function &F,
FunctionAnalysisManager &AM) {
auto &TTI = AM.getResult<TargetIRAnalysis>(F);
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
OS << "Printing analysis 'Cost Model Analysis' 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;
- auto *II = dyn_cast<IntrinsicInst>(&Inst);
- if (II && IntrinsicCost != IntrinsicCostStrategy::InstructionCost) {
- IntrinsicCostAttributes ICA(
- II->getIntrinsicID(), *II, InstructionCost::getInvalid(),
- /*TypeBasedOnly=*/IntrinsicCost ==
- IntrinsicCostStrategy::TypeBasedIntrinsicCost,
- &TLI);
- Cost = TTI.getIntrinsicInstrCost(ICA, CostKind);
+ OS << "Cost Model: ";
+ if (CostKind == OutputCostKind::All) {
+ OS << "Found costs of ";
----------------
RKSimon wrote:
"Found estimated costs of " ?
https://github.com/llvm/llvm-project/pull/130490
More information about the llvm-commits
mailing list