Index: llvm/include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfo.h +++ llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -221,28 +221,6 @@ TCK_SizeAndLatency ///< The weighted sum of size and latency. }; - /// Query the cost of a specified instruction. - /// - /// Clients should use this interface to query the cost of an existing - /// instruction. The instruction must have a valid parent (basic block). - /// - /// Note, this method does not cache the cost calculation and it - /// can be expensive in some cases. - int getInstructionCost(const Instruction *I, enum TargetCostKind kind) const { - switch (kind) { - case TCK_RecipThroughput: - return getInstructionThroughput(I); - - case TCK_Latency: - return getInstructionLatency(I); - - case TCK_CodeSize: - case TCK_SizeAndLatency: - return getUserCost(I, kind); - } - llvm_unreachable("Unknown instruction cost kind"); - } - /// Underlying constants for 'cost' values in this interface. /// /// Many APIs in this interface return a cost. This enum defines the @@ -1235,14 +1213,6 @@ /// @} private: - /// Estimate the latency of specified instruction. - /// Returns 1 as the default value. - int getInstructionLatency(const Instruction *I) const; - - /// Returns the expected throughput cost of the instruction. - /// Returns -1 if the cost is unknown. - int getInstructionThroughput(const Instruction *I) const; - /// The abstract base class used to type erase specific TTI /// implementations. class Concept; @@ -1497,7 +1467,6 @@ virtual bool shouldExpandReduction(const IntrinsicInst *II) const = 0; virtual unsigned getGISelRematGlobalCost() const = 0; virtual bool hasActiveVectorLength() const = 0; - virtual int getInstructionLatency(const Instruction *I) = 0; }; template @@ -1983,10 +1952,6 @@ bool hasActiveVectorLength() const override { return Impl.hasActiveVectorLength(); } - - int getInstructionLatency(const Instruction *I) override { - return Impl.getInstructionLatency(I); - } }; template Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -906,6 +906,9 @@ CostKind, I); } case Instruction::Load: { + // FIXME: Arbitary cost which could come from the backend. + if (CostKind == TTI::TCK_Latency) + return 4; auto *LI = cast(U); return TargetTTI->getMemoryOpCost(Opcode, U->getType(), LI->getAlign(), LI->getPointerAddressSpace(), @@ -1006,40 +1009,9 @@ Idx); } } - // By default, just classify everything as 'basic'. - return TTI::TCC_Basic; - } - - int getInstructionLatency(const Instruction *I) { - SmallVector Operands(I->value_op_begin(), - I->value_op_end()); - if (getUserCost(I, Operands, TTI::TCK_Latency) == TTI::TCC_Free) - return 0; - - if (isa(I)) - return 4; - - Type *DstTy = I->getType(); - - // Usually an intrinsic is a simple instruction. - // A real function call is much slower. - if (auto *CI = dyn_cast(I)) { - const Function *F = CI->getCalledFunction(); - if (!F || static_cast(this)->isLoweredToCall(F)) - return 40; - // Some intrinsics return a value and a flag, we use the value type - // to decide its latency. - if (StructType *StructTy = dyn_cast(DstTy)) - DstTy = StructTy->getElementType(0); - // Fall through to simple instructions. - } - - if (VectorType *VectorTy = dyn_cast(DstTy)) - DstTy = VectorTy->getElementType(); - if (DstTy->isFloatingPointTy()) - return 3; - - return 1; + // By default, just classify everything as 'basic' or -1 to represent that + // don't know the throughput cost. + return CostKind == TTI::TCK_RecipThroughput ? - 1: TTI::TCC_Basic; } }; } // namespace llvm Index: llvm/lib/Analysis/CostModel.cpp =================================================================== --- llvm/lib/Analysis/CostModel.cpp +++ llvm/lib/Analysis/CostModel.cpp @@ -50,14 +50,6 @@ *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. - unsigned getInstructionCost(const Instruction *I) const { - return TTI->getInstructionCost(I, TargetTransformInfo::TCK_RecipThroughput); - } - private: void getAnalysisUsage(AnalysisUsage &AU) const override; bool runOnFunction(Function &F) override; @@ -100,7 +92,7 @@ for (BasicBlock &B : *F) { for (Instruction &Inst : B) { - unsigned Cost = TTI->getInstructionCost(&Inst, CostKind); + unsigned Cost = TTI->getUserCost(&Inst, CostKind); if (Cost != (unsigned)-1) OS << "Cost Model: Found an estimated cost of " << Cost; else Index: llvm/lib/Analysis/TargetTransformInfo.cpp =================================================================== --- llvm/lib/Analysis/TargetTransformInfo.cpp +++ llvm/lib/Analysis/TargetTransformInfo.cpp @@ -950,10 +950,6 @@ return TTIImpl->getGISelRematGlobalCost(); } -int TargetTransformInfo::getInstructionLatency(const Instruction *I) const { - return TTIImpl->getInstructionLatency(I); -} - static bool matchPairwiseShuffleMask(ShuffleVectorInst *SI, bool IsLeft, unsigned Level) { // We don't need a shuffle if we just want to have element 0 in position 0 of @@ -1224,63 +1220,6 @@ return RD->Kind; } -int TargetTransformInfo::getInstructionThroughput(const Instruction *I) const { - TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; - - switch (I->getOpcode()) { - case Instruction::GetElementPtr: - case Instruction::Ret: - case Instruction::PHI: - case Instruction::Br: - case Instruction::Add: - case Instruction::FAdd: - case Instruction::Sub: - case Instruction::FSub: - case Instruction::Mul: - case Instruction::FMul: - case Instruction::UDiv: - case Instruction::SDiv: - case Instruction::FDiv: - case Instruction::URem: - case Instruction::SRem: - case Instruction::FRem: - case Instruction::Shl: - case Instruction::LShr: - case Instruction::AShr: - case Instruction::And: - case Instruction::Or: - case Instruction::Xor: - case Instruction::FNeg: - case Instruction::Select: - case Instruction::ICmp: - case Instruction::FCmp: - case Instruction::Store: - case Instruction::Load: - case Instruction::ZExt: - case Instruction::SExt: - case Instruction::FPToUI: - case Instruction::FPToSI: - case Instruction::FPExt: - case Instruction::PtrToInt: - case Instruction::IntToPtr: - case Instruction::SIToFP: - case Instruction::UIToFP: - case Instruction::Trunc: - case Instruction::FPTrunc: - case Instruction::BitCast: - case Instruction::AddrSpaceCast: - case Instruction::ExtractElement: - case Instruction::InsertElement: - case Instruction::ExtractValue: - case Instruction::ShuffleVector: - case Instruction::Call: - return getUserCost(I, CostKind); - default: - // We don't have any information on this instruction. - return -1; - } -} - TargetTransformInfo::Concept::~Concept() {} TargetIRAnalysis::TargetIRAnalysis() : TTICallback(&getDefaultTTI) {} Index: llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp =================================================================== --- llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp +++ llvm/lib/CodeGen/InterleavedLoadCombinePass.cpp @@ -1160,7 +1160,7 @@ for (auto &I : Is) { // Compute the old cost InstructionCost += - TTI.getInstructionCost(I, TargetTransformInfo::TCK_Latency); + TTI.getUserCost(I, TargetTransformInfo::TCK_Latency); // The final SVIs are allowed not to be dead, all uses will be replaced if (SVIs.find(I) != SVIs.end()) Index: llvm/lib/Transforms/IPO/HotColdSplitting.cpp =================================================================== --- llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -230,7 +230,7 @@ for (Instruction &I : BB->instructionsWithoutDebug()) if (&I != BB->getTerminator()) Benefit += - TTI.getInstructionCost(&I, TargetTransformInfo::TCK_CodeSize); + TTI.getUserCost(&I, TargetTransformInfo::TCK_CodeSize); return Benefit; } Index: llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp =================================================================== --- llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp +++ llvm/lib/Transforms/Scalar/CallSiteSplitting.cpp @@ -211,8 +211,8 @@ unsigned Cost = 0; for (auto &InstBeforeCall : llvm::make_range(CallSiteBB->begin(), CB.getIterator())) { - Cost += TTI.getInstructionCost(&InstBeforeCall, - TargetTransformInfo::TCK_CodeSize); + Cost += TTI.getUserCost(&InstBeforeCall, + TargetTransformInfo::TCK_CodeSize); if (Cost >= DuplicationThreshold) return false; } Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -3612,17 +3612,17 @@ if (NeedToShuffleReuses) { for (unsigned Idx : E->ReuseShuffleIndices) { Instruction *I = cast(VL[Idx]); - ReuseShuffleCost -= TTI->getInstructionCost(I, CostKind); + ReuseShuffleCost -= TTI->getUserCost(I, CostKind); } for (Value *V : VL) { Instruction *I = cast(V); - ReuseShuffleCost += TTI->getInstructionCost(I, CostKind); + ReuseShuffleCost += TTI->getUserCost(I, CostKind); } } for (Value *V : VL) { Instruction *I = cast(V); assert(E->isOpcodeOrAlt(I) && "Unexpected main/alternate opcode"); - ScalarCost += TTI->getInstructionCost(I, CostKind); + ScalarCost += TTI->getUserCost(I, CostKind); } // VecCost is equal to sum of the cost of creating 2 vectors // and the cost of creating shuffle. Index: llvm/test/Analysis/CostModel/X86/costmodel.ll =================================================================== --- llvm/test/Analysis/CostModel/X86/costmodel.ll +++ llvm/test/Analysis/CostModel/X86/costmodel.ll @@ -19,7 +19,7 @@ ; LATENCY-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %P2I = ptrtoint i8* undef to i64 ; LATENCY-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %TC = trunc i64 undef to i32 ; LATENCY-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %uadd = call { i32, i1 } @llvm.uadd.with.overflow.i32(i32 undef, i32 undef) -; LATENCY-NEXT: Cost Model: Found an estimated cost of 40 for instruction: call void undef() +; LATENCY-NEXT: Cost Model: Found an estimated cost of 1 for instruction: call void undef() ; LATENCY-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 undef ; ; CODESIZE-LABEL: 'foo'