diff --git a/llvm/include/llvm/Support/InstructionCost.h b/llvm/include/llvm/Support/InstructionCost.h --- a/llvm/include/llvm/Support/InstructionCost.h +++ b/llvm/include/llvm/Support/InstructionCost.h @@ -204,7 +204,7 @@ template auto map(const Function &F) const -> InstructionCost { if (isValid()) - return F(*getValue()); + return F(Value); return getInvalid(); } }; diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp --- a/llvm/lib/Transforms/IPO/PartialInlining.cpp +++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp @@ -1354,16 +1354,13 @@ if (Cloner.OutlinedFunctions.empty()) return false; - int SizeCost = 0; - BlockFrequency WeightedRcost; - int NonWeightedRcost; - auto OutliningCosts = computeOutliningCosts(Cloner); - assert(std::get<0>(OutliningCosts).isValid() && - std::get<1>(OutliningCosts).isValid() && "Expected valid costs"); - SizeCost = *std::get<0>(OutliningCosts).getValue(); - NonWeightedRcost = *std::get<1>(OutliningCosts).getValue(); + InstructionCost SizeCost = std::get<0>(OutliningCosts); + InstructionCost NonWeightedRcost = std::get<1>(OutliningCosts); + + assert(SizeCost.isValid() && NonWeightedRcost.isValid() && + "Expected valid costs"); // Only calculate RelativeToEntryFreq when we are doing single region // outlining. @@ -1378,7 +1375,8 @@ // execute the calls to outlined functions. RelativeToEntryFreq = BranchProbability(0, 1); - WeightedRcost = BlockFrequency(NonWeightedRcost) * RelativeToEntryFreq; + BlockFrequency WeightedRcost = + BlockFrequency(*NonWeightedRcost.getValue()) * RelativeToEntryFreq; // The call sequence(s) to the outlined function(s) are larger than the sum of // the original outlined region size(s), it does not increase the chances of diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -1268,7 +1268,7 @@ /// If interleave count has been specified by metadata it will be returned. /// Otherwise, the interleave count is computed and returned. VF and LoopCost /// are the selected vectorization factor and the cost of the selected VF. - unsigned selectInterleaveCount(ElementCount VF, unsigned LoopCost); + unsigned selectInterleaveCount(ElementCount VF, InstructionCost LoopCost); /// Memory access instruction may be vectorized in more than one way. /// Form of instruction after vectorization depends on cost. @@ -1782,8 +1782,9 @@ /// scalarize and their scalar costs are collected in \p ScalarCosts. A /// non-negative return value implies the expression will be scalarized. /// Currently, only single-use chains are considered for scalarization. - int computePredInstDiscount(Instruction *PredInst, ScalarCostsTy &ScalarCosts, - ElementCount VF); + InstructionCost computePredInstDiscount(Instruction *PredInst, + ScalarCostsTy &ScalarCosts, + ElementCount VF); /// Collect the instructions that are uniform after vectorization. An /// instruction is uniform if we represent it with a single scalar value in @@ -6072,10 +6073,9 @@ assert(C.first.isValid() && "Unexpected invalid cost for vector loop"); VectorizationFactor Candidate(i, C.first); - LLVM_DEBUG( - dbgs() << "LV: Vector loop of width " << i << " costs: " - << (*Candidate.Cost.getValue() / Candidate.Width.getFixedValue()) - << ".\n"); + LLVM_DEBUG(dbgs() << "LV: Vector loop of width " << i << " costs: " + << (Candidate.Cost / Candidate.Width.getFixedValue()) + << ".\n"); if (!C.second && !ForceVectorization) { LLVM_DEBUG( @@ -6100,8 +6100,7 @@ } LLVM_DEBUG(if (ForceVectorization && !ChosenFactor.Width.isScalar() && - *ChosenFactor.Cost.getValue() >= *ScalarCost.Cost.getValue()) - dbgs() + ChosenFactor.Cost >= ScalarCost.Cost) dbgs() << "LV: Vectorization seems to be not beneficial, " << "but was forced by a user.\n"); LLVM_DEBUG(dbgs() << "LV: Selecting VF: " << ChosenFactor.Width << ".\n"); @@ -6290,8 +6289,9 @@ return {MinWidth, MaxWidth}; } -unsigned LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF, - unsigned LoopCost) { +unsigned +LoopVectorizationCostModel::selectInterleaveCount(ElementCount VF, + InstructionCost LoopCost) { // -- The interleave heuristics -- // We interleave the loop in order to expose ILP and reduce the loop overhead. // There are many micro-architectural considerations that we can't predict @@ -6418,11 +6418,11 @@ // If we did not calculate the cost for VF (because the user selected the VF) // then we calculate the cost of VF here. if (LoopCost == 0) { - assert(expectedCost(VF).first.isValid() && "Expected a valid cost"); - LoopCost = *expectedCost(VF).first.getValue(); + LoopCost = expectedCost(VF).first; + assert(LoopCost.isValid() && "Expected a valid cost"); } - assert(LoopCost && "Non-zero loop cost expected"); + assert(LoopCost != 0 && "Non-zero loop cost expected"); // Interleave if we vectorized this loop and there is a reduction that could // benefit from interleaving. @@ -6447,8 +6447,8 @@ // We assume that the cost overhead is 1 and we use the cost model // to estimate the cost of the loop and interleave until the cost of the // loop overhead is about 5% of the cost of the loop. - unsigned SmallIC = - std::min(IC, (unsigned)PowerOf2Floor(SmallLoopCost / LoopCost)); + unsigned SmallIC = std::min( + IC, (unsigned)PowerOf2Floor(SmallLoopCost / *LoopCost.getValue())); // Interleave until store/load ports (estimated by max interleave count) are // saturated. @@ -6742,7 +6742,7 @@ } } -int LoopVectorizationCostModel::computePredInstDiscount( +InstructionCost LoopVectorizationCostModel::computePredInstDiscount( Instruction *PredInst, ScalarCostsTy &ScalarCosts, ElementCount VF) { assert(!isUniformAfterVectorization(PredInst, VF) && "Instruction marked uniform-after-vectorization will be predicated"); @@ -6854,7 +6854,7 @@ ScalarCosts[I] = ScalarCost; } - return *Discount.getValue(); + return Discount; } LoopVectorizationCostModel::VectorizationCostTy @@ -7179,7 +7179,7 @@ TTI.getCastInstrCost(RedOp->getOpcode(), VectorTy, ExtType, TTI::CastContextHint::None, CostKind, RedOp); if (RedCost.isValid() && RedCost < BaseCost + ExtCost) - return I == RetI ? *RedCost.getValue() : 0; + return I == RetI ? RedCost : 0; } else if (RedOp && RedOp->getOpcode() == Instruction::Mul) { Instruction *Mul = RedOp; Instruction *Op0 = dyn_cast(Mul->getOperand(0)); @@ -7202,7 +7202,7 @@ CostKind); if (RedCost.isValid() && RedCost < ExtCost * 2 + MulCost + BaseCost) - return I == RetI ? *RedCost.getValue() : 0; + return I == RetI ? RedCost : 0; } else { InstructionCost MulCost = TTI.getArithmeticInstrCost(Mul->getOpcode(), VectorTy, CostKind); @@ -7212,7 +7212,7 @@ CostKind); if (RedCost.isValid() && RedCost < MulCost + BaseCost) - return I == RetI ? *RedCost.getValue() : 0; + return I == RetI ? RedCost : 0; } } @@ -10007,7 +10007,7 @@ if (MaybeVF) { VF = *MaybeVF; // Select the interleave count. - IC = CM.selectInterleaveCount(VF.Width, *VF.Cost.getValue()); + IC = CM.selectInterleaveCount(VF.Width, VF.Cost); } // Identify the diagnostic messages that should be produced.