aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/CostModel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/CostModel.cpp')
-rw-r--r--llvm/lib/Analysis/CostModel.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp
index 3c162f604cd5..1782b399e7fd 100644
--- a/llvm/lib/Analysis/CostModel.cpp
+++ b/llvm/lib/Analysis/CostModel.cpp
@@ -57,14 +57,6 @@ namespace {
*PassRegistry::getPassRegistry());
}
- /// Returns the expected cost of the instruction.
- /// Returns -1 if the cost is unknown.
- /// Note, this method does not cache the cost calculation and it
- /// can be expensive in some cases.
- InstructionCost getInstructionCost(const Instruction *I) const {
- return TTI->getInstructionCost(I, TargetTransformInfo::TCK_RecipThroughput);
- }
-
private:
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnFunction(Function &F) override;
@@ -108,8 +100,8 @@ void CostModelAnalysis::print(raw_ostream &OS, const Module*) const {
for (BasicBlock &B : *F) {
for (Instruction &Inst : B) {
InstructionCost Cost;
- if (TypeBasedIntrinsicCost && isa<IntrinsicInst>(&Inst)) {
- auto *II = dyn_cast<IntrinsicInst>(&Inst);
+ auto *II = dyn_cast<IntrinsicInst>(&Inst);
+ if (II && TypeBasedIntrinsicCost) {
IntrinsicCostAttributes ICA(II->getIntrinsicID(), *II,
InstructionCost::getInvalid(), true);
Cost = TTI->getIntrinsicInstrCost(ICA, CostKind);
@@ -117,6 +109,7 @@ void CostModelAnalysis::print(raw_ostream &OS, const Module*) const {
else {
Cost = TTI->getInstructionCost(&Inst, CostKind);
}
+
if (auto CostVal = Cost.getValue())
OS << "Cost Model: Found an estimated cost of " << *CostVal;
else
@@ -136,8 +129,8 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
// TODO: Use a pass parameter instead of cl::opt CostKind to determine
// which cost kind to print.
InstructionCost Cost;
- if (TypeBasedIntrinsicCost && isa<IntrinsicInst>(&Inst)) {
- auto *II = dyn_cast<IntrinsicInst>(&Inst);
+ auto *II = dyn_cast<IntrinsicInst>(&Inst);
+ if (II && TypeBasedIntrinsicCost) {
IntrinsicCostAttributes ICA(II->getIntrinsicID(), *II,
InstructionCost::getInvalid(), true);
Cost = TTI.getIntrinsicInstrCost(ICA, CostKind);
@@ -145,6 +138,7 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F,
else {
Cost = TTI.getInstructionCost(&Inst, CostKind);
}
+
if (auto CostVal = Cost.getValue())
OS << "Cost Model: Found an estimated cost of " << *CostVal;
else