20 #define DEBUG_TYPE "ppctti" 29 cl::desc(
"The loop prefetch cache line size"));
33 cl::desc(
"Enable using coldcc calling conv for cold " 34 "internal functions"));
40 cl::desc(
"Loops with a constant trip count smaller than " 41 "this value will not use the count register."));
101 case Intrinsic::sadd_with_overflow:
102 case Intrinsic::uadd_with_overflow:
103 case Intrinsic::ssub_with_overflow:
104 case Intrinsic::usub_with_overflow:
108 case Intrinsic::experimental_stackmap:
112 case Intrinsic::experimental_patchpoint_void:
113 case Intrinsic::experimental_patchpoint_i64:
132 unsigned ImmIdx = ~0U;
133 bool ShiftedFree =
false, RunFree =
false, UnsignedFree =
false,
138 case Instruction::GetElementPtr:
145 case Instruction::And:
149 case Instruction::Or:
150 case Instruction::Xor:
153 case Instruction::Sub:
154 case Instruction::Mul:
155 case Instruction::Shl:
156 case Instruction::LShr:
157 case Instruction::AShr:
160 case Instruction::ICmp:
168 case Instruction::PHI:
176 if (ZeroFree && Imm == 0)
222 auto asmClobbersCTR = [](
InlineAsm *IA) {
224 for (
unsigned i = 0, ie = CIV.size(); i < ie; ++i) {
227 for (
unsigned j = 0, je = C.
Codes.size(); j < je; ++j)
236 std::function<bool(const Value*)> memAddrUsesCTR =
237 [&memAddrUsesCTR, &
TM](
const Value *MemAddr) ->
bool {
241 if (
const auto *CV = dyn_cast<Constant>(MemAddr))
242 for (
const auto &CO : CV->operands())
243 if (memAddrUsesCTR(CO))
249 if (!GV->isThreadLocal())
256 auto isLargeIntegerTy = [](
bool Is32Bit,
Type *Ty) {
258 return ITy->getBitWidth() > (Is32Bit ? 32U : 64U);
265 if (
CallInst *CI = dyn_cast<CallInst>(J)) {
267 if (
InlineAsm *IA = dyn_cast<InlineAsm>(CI->getCalledValue())) {
268 if (asmClobbersCTR(IA))
273 if (
Function *
F = CI->getCalledFunction()) {
278 switch (
F->getIntrinsicID()) {
282 case Intrinsic::set_loop_iterations:
283 case Intrinsic::loop_decrement:
290 case Intrinsic::eh_sjlj_setjmp:
292 case Intrinsic::memcpy:
293 case Intrinsic::memmove:
294 case Intrinsic::memset:
295 case Intrinsic::powi:
298 case Intrinsic::log10:
300 case Intrinsic::exp2:
305 case Intrinsic::copysign:
306 if (CI->getArgOperand(0)->getType()->getScalarType()->
311 case Intrinsic::sqrt: Opcode =
ISD::FSQRT;
break;
312 case Intrinsic::floor: Opcode =
ISD::FFLOOR;
break;
313 case Intrinsic::ceil: Opcode =
ISD::FCEIL;
break;
314 case Intrinsic::trunc: Opcode =
ISD::FTRUNC;
break;
315 case Intrinsic::rint: Opcode =
ISD::FRINT;
break;
316 case Intrinsic::lrint: Opcode =
ISD::LRINT;
break;
317 case Intrinsic::llrint: Opcode =
ISD::LLRINT;
break;
320 case Intrinsic::lround: Opcode =
ISD::LROUND;
break;
324 case Intrinsic::umul_with_overflow: Opcode =
ISD::UMULO;
break;
325 case Intrinsic::smul_with_overflow: Opcode =
ISD::SMULO;
break;
335 if (!
F->hasLocalLinkage() &&
F->hasName() && LibInfo &&
339 if (!CI->onlyReadsMemory())
343 if (!CI->getArgOperand(0)->getType()->isFloatingPointTy())
347 default:
return true;
348 case LibFunc_copysign:
349 case LibFunc_copysignf:
351 case LibFunc_copysignl:
365 case LibFunc_nearbyint:
366 case LibFunc_nearbyintf:
367 case LibFunc_nearbyintl:
414 }
else if (isa<BinaryOperator>(J) &&
415 J->getType()->getScalarType()->isPPC_FP128Ty()) {
418 }
else if (isa<UIToFPInst>(J) || isa<SIToFPInst>(J) ||
419 isa<FPToUIInst>(J) || isa<FPToSIInst>(J)) {
426 }
else if (isLargeIntegerTy(!TM.
isPPC64(),
427 J->getType()->getScalarType()) &&
428 (J->getOpcode() == Instruction::UDiv ||
429 J->getOpcode() == Instruction::SDiv ||
430 J->getOpcode() == Instruction::URem ||
431 J->getOpcode() == Instruction::SRem)) {
434 isLargeIntegerTy(
false, J->getType()->getScalarType()) &&
435 (J->getOpcode() == Instruction::Shl ||
436 J->getOpcode() == Instruction::AShr ||
437 J->getOpcode() == Instruction::LShr)) {
441 }
else if (isa<IndirectBrInst>(J) || isa<InvokeInst>(J)) {
450 if (J->getOpcode() == Instruction::FRem)
454 switch(J->getOpcode()) {
455 case Instruction::FAdd:
456 case Instruction::FSub:
457 case Instruction::FMul:
458 case Instruction::FDiv:
459 case Instruction::FPTrunc:
460 case Instruction::FPExt:
461 case Instruction::FPToUI:
462 case Instruction::FPToSI:
463 case Instruction::UIToFP:
464 case Instruction::SIToFP:
465 case Instruction::FCmp:
470 for (
Value *Operand : J->operands())
471 if (memAddrUsesCTR(Operand))
503 if (mightUseCTR(*
I, LibInfo))
511 for (
auto &BB : ExitingBlocks) {
515 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
516 uint64_t TrueWeight = 0, FalseWeight = 0;
517 if (!BI->isConditional() ||
518 !BI->extractProfMetadata(TrueWeight, FalseWeight))
523 bool TrueIsExit = !L->
contains(BI->getSuccessor(0));
524 if (( TrueIsExit && FalseWeight < TrueWeight) ||
525 (!TrueIsExit && FalseWeight > TrueWeight))
568 return LoopHasReductions;
588 return ClassID ==
VSXRC ? 64 : 32;
614 return "PPC::unknown register class";
615 case GPRRC:
return "PPC::GPRRC";
616 case FPRRC:
return "PPC::FPRRC";
617 case VRRC:
return "PPC::VRRC";
618 case VSXRC:
return "PPC::VSXRC";
624 if (ST->
hasQPX())
return 256;
697 if (LT1.first != 1 || !LT1.second.isVector())
706 if (LT2.first != 1 || !LT2.second.isVector())
724 Opd1PropInfo, Opd2PropInfo);
760 assert(ISD &&
"Invalid opcode");
791 if (Index == MfvsrdIndex)
793 }
else if (EltSize == 32) {
795 if (Index == MfvsrwzIndex)
814 unsigned LHSPenalty = 2;
824 return LHSPenalty + Cost;
843 bool IsVSXType = ST->
hasVSX() &&
845 bool IsQPXType = ST->
hasQPX() &&
854 (MemBytes == 64 || (ST->
hasP8Vector() && MemBytes == 32)))
858 unsigned SrcBytes = LT.second.getStoreSize();
859 if (!SrcBytes || !Alignment || Alignment >= SrcBytes)
870 ((!ST->
hasP8Vector() && IsAltivecType) || IsQPXType) &&
871 Alignment >= LT.second.getScalarType().getStoreSize())
872 return Cost + LT.first;
878 if (IsVSXType || (ST->
hasVSX() && IsAltivecType))
890 Cost += LT.first * ((SrcBytes / Alignment->value()) - 1);
908 bool UseMaskForGaps) {
909 if (UseMaskForCond || UseMaskForGaps)
911 Alignment, AddressSpace,
912 UseMaskForCond, UseMaskForGaps);
914 assert(isa<VectorType>(VecTy) &&
915 "Expect a vector type for interleaved memory op");
929 Cost += Factor*(LT.first-1);
941 unsigned ScalarizationCostPassed) {
945 ScalarizationCostPassed);
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value *> &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop)...
unsigned getSmallConstantTripCount(const Loop *L)
Returns the maximum trip count of the loop if it is a single-exit loop and we can compute a small max...
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Type * getSrcTy() const
Return the source type, as a convenience.
uint64_t getZExtValue() const
Get zero extended value.
bool useColdCCForColdCall(Function &F)
This class represents lattice values for constants.
Cost tables and simple lookup functions.
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
LLVM_NODISCARD bool equals_lower(StringRef RHS) const
equals_lower - Check for string equality, ignoring case.
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
unsigned getCacheLineSize() const override
The main scalar evolution driver.
bool isFP128Ty() const
Return true if this is 'fp128'.
This class represents a function call, abstracting a target machine's calling convention.
static uint64_t round(uint64_t Acc, uint64_t Input)
bool enableInterleavedAccessVectorization()
A cache of @llvm.assume calls within a function.
constexpr bool isInt< 16 >(int64_t x)
static IntegerType * getInt64Ty(LLVMContext &C)
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
TTI::MemCmpExpansionOptions enableMemCmpExpansion(bool OptSize, bool IsZeroCmp) const
bool isVectorTy() const
True if this is an instance of VectorType.
bool isOperationLegalOrCustom(unsigned Op, EVT VT) const
Return true if the specified operation is legal on this target or can be made legal with custom lower...
bool isPPC_FP128Ty() const
Return true if this is powerpc long double.
LLVMContext & getContext() const
Get the context in which this basic block lives.
unsigned getBitWidth() const
Return the number of bits in the APInt.
int getShuffleCost(TTI::ShuffleKind Kind, Type *Tp, int Index, Type *SubTp)
ConstraintCodeVector Codes
Code - The constraint code, either the register name (in braces) or the constraint letter/number...
unsigned getUserCost(const User *U, ArrayRef< const Value *> Operands)
iterator begin()
Instruction iterator methods.
unsigned getIntrinsicInstrCost(Intrinsic::ID IID, Type *RetTy, ArrayRef< Value * > Args, FastMathFlags FMF, unsigned VF=1)
Get intrinsic cost based on arguments.
int getIntImmCost(const APInt &Imm, Type *Ty)
Provide an instruction scheduling machine model to CodeGen passes.
This is the base class for all instructions that perform data casts.
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
bool hasDirectMove() const
int getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
bool isIntegerTy() const
True if this is an instance of IntegerType.
mir Rename Register Operands
unsigned getMaxInterleaveFactor(unsigned VF)
int getIntImmCostInst(unsigned Opcode, unsigned Idx, const APInt &Imm, Type *Ty)
bool useSoftFloat() const
BlockT * getHeader() const
std::vector< Loop *>::const_iterator iterator
unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I)
int64_t getSExtValue() const
Get sign extended value.
unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
Type * getType() const
All values are typed, get the type of this value.
Directive
IDs for all OpenMP directives.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
const PPCTargetMachine & getTargetMachine() const
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
ConstraintPrefix Type
Type - The basic type of the constraint: input/output/clobber.
bool isHardwareLoopProfitable(Loop *L, ScalarEvolution &SE, AssumptionCache &AC, TargetLibraryInfo *LibInfo, HardwareLoopInfo &HWLoopInfo)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
int getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value *> Args=ArrayRef< const Value *>(), const Instruction *CxtI=nullptr)
bool vectorsUseTwoUnits() const
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
initializer< Ty > init(const Ty &Val)
unsigned getRegisterBitWidth(bool Vector) const
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM Basic Block Representation.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
unsigned getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
Conditional or Unconditional Branch instruction.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
void analyzeBasicBlock(const BasicBlock *BB, const TargetTransformInfo &TTI, const SmallPtrSetImpl< const Value *> &EphValues)
Add information about a block to the current state.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
unsigned getCPUDirective() const
getCPUDirective - Returns the -m directive specified for the cpu.
unsigned getNumberOfRegisters(unsigned ClassID) const
int getIntImmCostIntrin(Intrinsic::ID IID, unsigned Idx, const APInt &Imm, Type *Ty)
Class to represent integer types.
This file provides a helper that implements much of the TTI interface in terms of the target-independ...
Attributes of a target dependent hardware loop.
Common code between 32-bit and 64-bit PowerPC targets.
static double log2(double V)
void init(const TargetSubtargetInfo *TSInfo)
Initialize the machine model for instruction scheduling.
void getExitingBlocks(SmallVectorImpl< BlockT *> &ExitingBlocks) const
Return all blocks inside the loop that have successors outside of the loop.
bool isLittleEndian() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_READONLY APFloat maxnum(const APFloat &A, const APFloat &B)
Implements IEEE maxNum semantics.
EVT getValueType(const DataLayout &DL, Type *Ty, bool AllowUnknown=false) const
Return the EVT corresponding to this LLVM type.
std::vector< ConstraintInfo > ConstraintInfoVector
bool contains(const LoopT *L) const
Return true if the specified loop is contained within in this loop.
Iterator for intrusive lists based on ilist_node.
const char * getRegisterClassName(unsigned ClassID) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
constexpr bool isInt< 32 >(int64_t x)
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
Utility to calculate the size and a few similar metrics for a set of basic blocks.
unsigned getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info=TTI::OK_AnyValue, TTI::OperandValueKind Opd2Info=TTI::OK_AnyValue, TTI::OperandValueProperties Opd1PropInfo=TTI::OP_None, TTI::OperandValueProperties Opd2PropInfo=TTI::OP_None, ArrayRef< const Value * > Args=ArrayRef< const Value * >(), const Instruction *CxtI=nullptr)
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Type * getDestTy() const
Return the destination type, as a convenience.
bool enableAggressiveInterleaving(bool LoopHasReductions)
bool canAnalyze(LoopInfo &LI)
unsigned getVectorNumElements() const
void getUnrollingPreferences(Loop *L, ScalarEvolution &SE, TTI::UnrollingPreferences &UP)
bool hasP9Altivec() const
Class for arbitrary precision integers.
unsigned getMaxExpandSizeMemcmp(bool OptSize) const
Get maximum # of load operations permitted for memcmp.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
int InstructionOpcodeToISD(unsigned Opcode) const
Get the ISD node that corresponds to the Instruction class opcode.
int vectorCostAdjustment(int Cost, unsigned Opcode, Type *Ty1, Type *Ty2)
int getCmpSelInstrCost(unsigned Opcode, Type *ValTy, Type *CondTy, const Instruction *I=nullptr)
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
bool isVector() const
Return true if this is a vector value type.
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth)
static IntegerType * getInt32Ty(LLVMContext &C)
Represents a single loop in the control flow graph.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getVectorInstrCost(unsigned Opcode, Type *Val, unsigned Index)
block_iterator block_end() const
constexpr bool isUInt< 16 >(uint64_t x)
virtual unsigned getMinimumJumpTableEntries() const
Return lower limit for number of blocks in a jump table.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
POPCNTDKind hasPOPCNTD() const
int getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src, const Instruction *I=nullptr)
LLVM Value Representation.
unsigned getPrefetchDistance() const override
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Convenience struct for specifying and reasoning about fast-math flags.
constexpr bool isShiftedMask_32(uint32_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (32 bit ver...
StringRef - Represent a constant reference to a string, i.e.
int getInterleavedMemoryOpCost(unsigned Opcode, Type *VecTy, unsigned Factor, ArrayRef< unsigned > Indices, unsigned Alignment, unsigned AddressSpace, bool UseMaskForCond=false, bool UseMaskForGaps=false)
unsigned getIssueWidth() const
Maximum number of micro-ops that may be scheduled per cycle.
bool isHardwareLoopCandidate(ScalarEvolution &SE, LoopInfo &LI, DominatorTree &DT, bool ForceNestedLoop=false, bool ForceHardwareLoopPHI=false)
unsigned NumInsts
Number of instructions in the analyzed blocks.
iterator_range< block_iterator > blocks() const
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
block_iterator block_begin() const
bool canSaveCmp(Loop *L, BranchInst **BI, ScalarEvolution *SE, LoopInfo *LI, DominatorTree *DT, AssumptionCache *AC, TargetLibraryInfo *LibInfo)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool isOperationExpand(unsigned Op, EVT VT) const
Return true if the specified operation is illegal on this target or unlikely to be made legal with cu...
std::pair< int, MVT > getTypeLegalizationCost(const DataLayout &DL, Type *Ty) const
Estimate the cost of type-legalization and the legalized type.
LLVM_READONLY APFloat minnum(const APFloat &A, const APFloat &B)
Implements IEEE minNum semantics.
unsigned getIntrinsicInstrCost(Intrinsic::ID ID, Type *RetTy, ArrayRef< Value *> Args, FastMathFlags FMF, unsigned VF)
This file describes how to lower LLVM code to machine code.
int getMemoryOpCost(unsigned Opcode, Type *Src, MaybeAlign Alignment, unsigned AddressSpace, const Instruction *I=nullptr)
bool allowsMisalignedMemoryAccesses(EVT VT, unsigned AddrSpace, unsigned Align=1, MachineMemOperand::Flags Flags=MachineMemOperand::MONone, bool *Fast=nullptr) const override
Is unaligned memory access allowed for the given type, and is it fast relative to software emulation...