diff options
author | David Green <david.green@arm.com> | 2025-04-23 07:46:27 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-23 07:46:27 +0100 |
commit | 98b6f8dc699d789d834e5b6d810ed217f560aad0 (patch) | |
tree | 2e6a97dca2bcd2f2376e2d127a819105200ee9e7 /llvm/lib | |
parent | 665914fea1433409015a87fef2837218bcd21460 (diff) | |
download | llvm-98b6f8dc699d789d834e5b6d810ed217f560aad0.zip llvm-98b6f8dc699d789d834e5b6d810ed217f560aad0.tar.gz llvm-98b6f8dc699d789d834e5b6d810ed217f560aad0.tar.bz2 |
[CostModel] Remove optional from InstructionCost::getValue() (#135596)
InstructionCost is already an optional value, containing an Invalid
state that can be checked with isValid(). There is little point in
returning another optional from getValue(). Most uses do not make use of
it being a std::optional, dereferencing the value directly (either
isValid has been checked previously or the Cost is assumed to be valid).
The one case that does in AMDGPU used value_or which has been replaced
by a isValid() check.
Diffstat (limited to 'llvm/lib')
18 files changed, 34 insertions, 34 deletions
diff --git a/llvm/lib/Analysis/CostModel.cpp b/llvm/lib/Analysis/CostModel.cpp index cec0fb6..6d8bd7d 100644 --- a/llvm/lib/Analysis/CostModel.cpp +++ b/llvm/lib/Analysis/CostModel.cpp @@ -128,8 +128,8 @@ PreservedAnalyses CostModelPrinterPass::run(Function &F, } else { InstructionCost Cost = getCost(Inst, OutputCostKindToTargetCostKind(CostKind), TTI, TLI); - if (auto CostVal = Cost.getValue()) - OS << "Found an estimated cost of " << *CostVal; + if (Cost.isValid()) + OS << "Found an estimated cost of " << Cost.getValue(); else OS << "Invalid cost"; OS << " for instruction: " << Inst << "\n"; diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp index 00148b0..13ed8f2 100644 --- a/llvm/lib/CodeGen/SelectOptimize.cpp +++ b/llvm/lib/CodeGen/SelectOptimize.cpp @@ -206,7 +206,7 @@ public: getI()->getOpcode(), I->getType(), TargetTransformInfo::TCK_Latency, {TargetTransformInfo::OK_AnyValue, TargetTransformInfo::OP_None}, {TTI::OK_UniformConstantValue, TTI::OP_PowerOf2}); - auto TotalCost = Scaled64::get(*Cost.getValue()); + auto TotalCost = Scaled64::get(Cost.getValue()); if (auto *OpI = dyn_cast<Instruction>(I->getOperand(1 - CondIdx))) { auto It = InstCostMap.find(OpI); if (It != InstCostMap.end()) @@ -1380,8 +1380,8 @@ std::optional<uint64_t> SelectOptimizeImpl::computeInstCost(const Instruction *I) { InstructionCost ICost = TTI->getInstructionCost(I, TargetTransformInfo::TCK_Latency); - if (auto OC = ICost.getValue()) - return std::optional<uint64_t>(*OC); + if (ICost.isValid()) + return std::optional<uint64_t>(ICost.getValue()); return std::nullopt; } diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 771eee1..0ff681c 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -28530,7 +28530,7 @@ bool AArch64TargetLowering::shouldLocalize( Imm, CI->getType(), TargetTransformInfo::TCK_CodeSize); assert(Cost.isValid() && "Expected a valid imm cost"); - unsigned RematCost = *Cost.getValue(); + unsigned RematCost = Cost.getValue(); RematCost += AdditionalCost; Register Reg = MI.getOperand(0).getReg(); unsigned MaxUses = maxUses(RematCost); diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp index a20f1c1..324e234 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -4618,7 +4618,7 @@ static bool isLoopSizeWithinBudget(Loop *L, const AArch64TTIImpl &TTI, } if (FinalSize) - *FinalSize = *LoopCost.getValue(); + *FinalSize = LoopCost.getValue(); return true; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp index dd3bec7..1506f02 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUSplitModule.cpp @@ -205,8 +205,8 @@ static CostType calculateFunctionCosts(GetTTIFn GetTTI, Module &M, TTI.getInstructionCost(&I, TargetTransformInfo::TCK_CodeSize); assert(Cost != InstructionCost::getMax()); // Assume expensive if we can't tell the cost of an instruction. - CostType CostVal = - Cost.getValue().value_or(TargetTransformInfo::TCC_Expensive); + CostType CostVal = Cost.isValid() ? Cost.getValue() + : TargetTransformInfo::TCC_Expensive; assert((FnCost + CostVal) >= FnCost && "Overflow!"); FnCost += CostVal; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp index cc2ca77..9512bcd 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp @@ -1277,9 +1277,9 @@ static unsigned adjustInliningThresholdUsingCallee(const CallBase *CB, // The penalty cost is computed relative to the cost of instructions and does // not model any storage costs. adjustThreshold += std::max(0, SGPRsInUse - NrOfSGPRUntilSpill) * - *ArgStackCost.getValue() * InlineConstants::getInstrCost(); + ArgStackCost.getValue() * InlineConstants::getInstrCost(); adjustThreshold += std::max(0, VGPRsInUse - NrOfVGPRUntilSpill) * - *ArgStackCost.getValue() * InlineConstants::getInstrCost(); + ArgStackCost.getValue() * InlineConstants::getInstrCost(); return adjustThreshold; } diff --git a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp index eb487bd..bf2a95b 100644 --- a/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp @@ -1096,7 +1096,7 @@ InstructionCost PPCTTIImpl::getVPMemoryOpCost(unsigned Opcode, Type *Src, float AlignmentProb = ((float)Alignment.value()) / DesiredAlignment.value(); float MisalignmentProb = 1.0 - AlignmentProb; return (MisalignmentProb * P9PipelineFlushEstimate) + - (AlignmentProb * *Cost.getValue()); + (AlignmentProb * Cost.getValue()); } // Usually we should not get to this point, but the following is an attempt to diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 11f2095..dadae2e 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -2909,7 +2909,7 @@ InstructionCost RISCVTargetLowering::getVRGatherVVCost(MVT VT) const { bool Log2CostModel = Subtarget.getVRGatherCostModel() == llvm::RISCVSubtarget::NLog2N; if (Log2CostModel && LMULCost.isValid()) { - unsigned Log = Log2_64(*LMULCost.getValue()); + unsigned Log = Log2_64(LMULCost.getValue()); if (Log > 0) return LMULCost * Log; } diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index 2cea601..73ebd87 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -483,7 +483,7 @@ costShuffleViaVRegSplitting(const RISCVTTIImpl &TTI, MVT LegalVT, auto *SingleOpTy = FixedVectorType::get(Tp->getElementType(), LegalVT.getVectorNumElements()); - unsigned E = *NumOfDests.getValue(); + unsigned E = NumOfDests.getValue(); unsigned NormalizedVF = LegalVT.getVectorNumElements() * std::max(NumOfSrcs, E); unsigned NumOfSrcRegs = NormalizedVF / LegalVT.getVectorNumElements(); diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp index 53270ac..ee142cc 100644 --- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp +++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp @@ -380,7 +380,7 @@ void SystemZTTIImpl::getUnrollingPreferences( // The z13 processor will run out of store tags if too many stores // are fed into it too quickly. Therefore make sure there are not // too many stores in the resulting unrolled loop. - unsigned const NumStoresVal = *NumStores.getValue(); + unsigned const NumStoresVal = NumStores.getValue(); unsigned const Max = (NumStoresVal ? (12 / NumStoresVal) : UINT_MAX); if (HasCall) { diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp index 2375a8f..74bb257 100644 --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -1748,7 +1748,7 @@ InstructionCost X86TTIImpl::getShuffleCost( getTypeLegalizationCost( FixedVectorType::get(BaseTp->getElementType(), Mask.size())) .first; - unsigned E = *NumOfDests.getValue(); + unsigned E = NumOfDests.getValue(); unsigned NormalizedVF = LegalVT.getVectorNumElements() * std::max(NumOfSrcs, E); unsigned NumOfSrcRegs = NormalizedVF / LegalVT.getVectorNumElements(); @@ -4931,7 +4931,7 @@ InstructionCost X86TTIImpl::getScalarizationOverhead( (LegalVectorBitWidth % LaneBitWidth) == 0) && "Illegal vector"); - const int NumLegalVectors = *LT.first.getValue(); + const int NumLegalVectors = LT.first.getValue(); assert(NumLegalVectors >= 0 && "Negative cost!"); // For insertions, a ISD::BUILD_VECTOR style vector initialization can be much @@ -6164,7 +6164,7 @@ InstructionCost X86TTIImpl::getGSVectorCost(unsigned Opcode, std::pair<InstructionCost, MVT> IdxsLT = getTypeLegalizationCost(IndexVTy); std::pair<InstructionCost, MVT> SrcLT = getTypeLegalizationCost(SrcVTy); InstructionCost::CostType SplitFactor = - *std::max(IdxsLT.first, SrcLT.first).getValue(); + std::max(IdxsLT.first, SrcLT.first).getValue(); if (SplitFactor > 1) { // Handle splitting of vector of pointers auto *SplitSrcTy = diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp index c13305c..1034ce9 100644 --- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -662,7 +662,7 @@ FunctionSpecializer::~FunctionSpecializer() { /// non-negative, which is true for both TCK_CodeSize and TCK_Latency, and /// always Valid. static unsigned getCostValue(const Cost &C) { - int64_t Value = *C.getValue(); + int64_t Value = C.getValue(); assert(Value >= 0 && "CodeSize and Latency cannot be negative"); // It is safe to down cast since we know the arguments cannot be negative and @@ -713,7 +713,7 @@ bool FunctionSpecializer::run() { if (!SpecializeLiteralConstant && !Inserted && !Metrics.isRecursive) continue; - int64_t Sz = *Metrics.NumInsts.getValue(); + int64_t Sz = Metrics.NumInsts.getValue(); assert(Sz > 0 && "CodeSize should be positive"); // It is safe to down cast from int64_t, NumInsts is always positive. unsigned FuncSize = static_cast<unsigned>(Sz); diff --git a/llvm/lib/Transforms/IPO/PartialInlining.cpp b/llvm/lib/Transforms/IPO/PartialInlining.cpp index e2df95e..b79fe83 100644 --- a/llvm/lib/Transforms/IPO/PartialInlining.cpp +++ b/llvm/lib/Transforms/IPO/PartialInlining.cpp @@ -1320,7 +1320,7 @@ bool PartialInlinerImpl::tryPartialInline(FunctionCloner &Cloner) { RelativeToEntryFreq = BranchProbability(0, 1); BlockFrequency WeightedRcost = - BlockFrequency(*NonWeightedRcost.getValue()) * RelativeToEntryFreq; + 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/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp index 40c4c15..dd4d4ef 100644 --- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp +++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp @@ -386,7 +386,7 @@ void ConstantHoistingPass::collectConstantCandidates( ConstIntCandVec.push_back(ConstantCandidate(ConstInt)); Itr->second = ConstIntCandVec.size() - 1; } - ConstIntCandVec[Itr->second].addUser(Inst, Idx, *Cost.getValue()); + ConstIntCandVec[Itr->second].addUser(Inst, Idx, Cost.getValue()); LLVM_DEBUG(if (isa<ConstantInt>(Inst->getOperand(Idx))) dbgs() << "Collect constant " << *ConstInt << " from " << *Inst << " with cost " << Cost << '\n'; @@ -446,7 +446,7 @@ void ConstantHoistingPass::collectConstantCandidates( ConstExpr)); Itr->second = ExprCandVec.size() - 1; } - ExprCandVec[Itr->second].addUser(Inst, Idx, *Cost.getValue()); + ExprCandVec[Itr->second].addUser(Inst, Idx, Cost.getValue()); } /// Check the operand for instruction Inst at index Idx. diff --git a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp index 838c7a1..61863bcf 100644 --- a/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDataPrefetch.cpp @@ -304,7 +304,7 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) { if (!Metrics.NumInsts.isValid()) return MadeChange; - unsigned LoopSize = *Metrics.NumInsts.getValue(); + unsigned LoopSize = Metrics.NumInsts.getValue(); if (!LoopSize) LoopSize = 1; diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index fd16593..04719fb 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1535,7 +1535,7 @@ void Cost::RateFormula(const Formula &F, C.NumBaseAdds += (F.UnfoldedOffset.isNonZero()); // Accumulate non-free scaling amounts. - C.ScaleCost += *getScalingFactorCost(*TTI, LU, F, *L).getValue(); + C.ScaleCost += getScalingFactorCost(*TTI, LU, F, *L).getValue(); // Tally up the non-zero immediates. for (const LSRFixup &Fixup : LU.Fixups) { diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index be9b0e3..d7080d6 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -677,8 +677,8 @@ static std::optional<EstimatedUnrollCost> analyzeLoopUnrollCost( LLVM_DEBUG(dbgs() << "Analysis finished:\n" << "UnrolledCost: " << UnrolledCost << ", " << "RolledDynamicCost: " << RolledDynamicCost << "\n"); - return {{unsigned(*UnrolledCost.getValue()), - unsigned(*RolledDynamicCost.getValue())}}; + return {{unsigned(UnrolledCost.getValue()), + unsigned(RolledDynamicCost.getValue())}}; } UnrollCostEstimator::UnrollCostEstimator( @@ -729,7 +729,7 @@ bool UnrollCostEstimator::canUnroll() const { uint64_t UnrollCostEstimator::getUnrolledLoopSize( const TargetTransformInfo::UnrollingPreferences &UP, unsigned CountOverwrite) const { - unsigned LS = *LoopSize.getValue(); + unsigned LS = LoopSize.getValue(); assert(LS >= UP.BEInsns && "LoopSize should not be less than BEInsns!"); if (CountOverwrite) return static_cast<uint64_t>(LS - UP.BEInsns) * CountOverwrite + UP.BEInsns; diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 32c3435..f985e88 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -2002,7 +2002,7 @@ public: InstructionCost NewMemCheckCost = MemCheckCost / BestTripCount; // Let's ensure the cost is always at least 1. - NewMemCheckCost = std::max(*NewMemCheckCost.getValue(), + NewMemCheckCost = std::max(NewMemCheckCost.getValue(), (InstructionCost::CostType)1); if (BestTripCount > 1) @@ -5314,7 +5314,7 @@ LoopVectorizationCostModel::selectInterleaveCount(VPlan &Plan, ElementCount VF, // 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)llvm::bit_floor<uint64_t>( - SmallLoopCost / *LoopCost.getValue())); + SmallLoopCost / LoopCost.getValue())); // Interleave until store/load ports (estimated by max interleave count) are // saturated. @@ -7659,7 +7659,7 @@ InstructionCost LoopVectorizationPlanner::cost(VPlan &Plan, LLVM_DEBUG(dbgs() << "Cost for VF " << VF << ": " << Cost << " (Estimated cost per lane: "); if (Cost.isValid()) { - double CostPerLane = double(*Cost.getValue()) / EstimatedWidth; + double CostPerLane = double(Cost.getValue()) / EstimatedWidth; LLVM_DEBUG(dbgs() << format("%.1f", CostPerLane)); } else /* No point dividing an invalid cost - it will still be invalid */ LLVM_DEBUG(dbgs() << "Invalid"); @@ -10478,7 +10478,7 @@ static bool isOutsideLoopWorkProfitable(GeneratedRTChecks &Checks, // The scalar cost should only be 0 when vectorizing with a user specified // VF/IC. In those cases, runtime checks should always be generated. - uint64_t ScalarC = *VF.ScalarCost.getValue(); + uint64_t ScalarC = VF.ScalarCost.getValue(); if (ScalarC == 0) return true; @@ -10513,8 +10513,8 @@ static bool isOutsideLoopWorkProfitable(GeneratedRTChecks &Checks, // the computations are performed on doubles, not integers and the result // is rounded up, hence we get an upper estimate of the TC. unsigned IntVF = getEstimatedRuntimeVF(VF.Width, VScale); - uint64_t RtC = *TotalCost.getValue(); - uint64_t Div = ScalarC * IntVF - *VF.Cost.getValue(); + uint64_t RtC = TotalCost.getValue(); + uint64_t Div = ScalarC * IntVF - VF.Cost.getValue(); uint64_t MinTC1 = Div == 0 ? 0 : divideCeil(RtC * IntVF, Div); // Second, compute a minimum iteration count so that the cost of the |