1be04929f7fd76a921540e9901f24563e51dc1219Chandler Carruth//===- llvm/Analysis/TargetTransformInfo.cpp ------------------------------===// 2cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// 3cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// The LLVM Compiler Infrastructure 4cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// 5cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// This file is distributed under the University of Illinois Open Source 6cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// License. See LICENSE.TXT for details. 7cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem// 8cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem//===----------------------------------------------------------------------===// 9cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem 10aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth#define DEBUG_TYPE "tti" 11be04929f7fd76a921540e9901f24563e51dc1219Chandler Carruth#include "llvm/Analysis/TargetTransformInfo.h" 121e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth#include "llvm/IR/DataLayout.h" 131e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth#include "llvm/IR/Operator.h" 141e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth#include "llvm/IR/Instruction.h" 151e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth#include "llvm/IR/IntrinsicInst.h" 161e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth#include "llvm/IR/Instructions.h" 1713086a658ae06046ded902229f9918b8bad505bdChandler Carruth#include "llvm/Support/CallSite.h" 18cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem#include "llvm/Support/ErrorHandling.h" 19cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem 20cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotemusing namespace llvm; 21cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem 227bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth// Setup the analysis group to manage the TargetTransformInfo passes. 237bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler CarruthINITIALIZE_ANALYSIS_GROUP(TargetTransformInfo, "Target Information", NoTTI) 24cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotemchar TargetTransformInfo::ID = 0; 25cbd9a19b5d6ff93efa82c467508ede78b8af3bacNadav Rotem 267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler CarruthTargetTransformInfo::~TargetTransformInfo() { 277bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 29aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruthvoid TargetTransformInfo::pushTTIStack(Pass *P) { 30aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth TopTTI = this; 31aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth PrevTTI = &P->getAnalysis<TargetTransformInfo>(); 32aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth 33aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth // Walk up the chain and update the top TTI pointer. 34aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI) 35aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth PTTI->TopTTI = this; 36aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth} 37aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth 38aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruthvoid TargetTransformInfo::popTTIStack() { 39aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth TopTTI = 0; 40aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth 41aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth // Walk up the chain and update the top TTI pointer. 42aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth for (TargetTransformInfo *PTTI = PrevTTI; PTTI; PTTI = PTTI->PrevTTI) 43aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth PTTI->TopTTI = PrevTTI; 44aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth 45aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth PrevTTI = 0; 46aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth} 47aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth 487bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthvoid TargetTransformInfo::getAnalysisUsage(AnalysisUsage &AU) const { 497bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth AU.addRequired<TargetTransformInfo>(); 507bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 517bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 521e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruthunsigned TargetTransformInfo::getOperationCost(unsigned Opcode, Type *Ty, 531e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth Type *OpTy) const { 541e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return PrevTTI->getOperationCost(Opcode, Ty, OpTy); 551e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth} 561e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 571e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruthunsigned TargetTransformInfo::getGEPCost( 581e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth const Value *Ptr, ArrayRef<const Value *> Operands) const { 591e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return PrevTTI->getGEPCost(Ptr, Operands); 601e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth} 611e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 6213086a658ae06046ded902229f9918b8bad505bdChandler Carruthunsigned TargetTransformInfo::getCallCost(FunctionType *FTy, 6313086a658ae06046ded902229f9918b8bad505bdChandler Carruth int NumArgs) const { 6413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->getCallCost(FTy, NumArgs); 6513086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 6613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 6713086a658ae06046ded902229f9918b8bad505bdChandler Carruthunsigned TargetTransformInfo::getCallCost(const Function *F, 6813086a658ae06046ded902229f9918b8bad505bdChandler Carruth int NumArgs) const { 6913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->getCallCost(F, NumArgs); 7013086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 7113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 7213086a658ae06046ded902229f9918b8bad505bdChandler Carruthunsigned TargetTransformInfo::getCallCost( 7313086a658ae06046ded902229f9918b8bad505bdChandler Carruth const Function *F, ArrayRef<const Value *> Arguments) const { 7413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->getCallCost(F, Arguments); 7513086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 7613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 7713086a658ae06046ded902229f9918b8bad505bdChandler Carruthunsigned TargetTransformInfo::getIntrinsicCost( 7813086a658ae06046ded902229f9918b8bad505bdChandler Carruth Intrinsic::ID IID, Type *RetTy, ArrayRef<Type *> ParamTys) const { 7913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->getIntrinsicCost(IID, RetTy, ParamTys); 8013086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 8113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 8213086a658ae06046ded902229f9918b8bad505bdChandler Carruthunsigned TargetTransformInfo::getIntrinsicCost( 8313086a658ae06046ded902229f9918b8bad505bdChandler Carruth Intrinsic::ID IID, Type *RetTy, ArrayRef<const Value *> Arguments) const { 8413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->getIntrinsicCost(IID, RetTy, Arguments); 8513086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 8613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 871e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruthunsigned TargetTransformInfo::getUserCost(const User *U) const { 881e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return PrevTTI->getUserCost(U); 891e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth} 901e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 9157e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellardbool TargetTransformInfo::hasBranchDivergence() const { 9257e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard return PrevTTI->hasBranchDivergence(); 9357e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard} 9457e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard 9513086a658ae06046ded902229f9918b8bad505bdChandler Carruthbool TargetTransformInfo::isLoweredToCall(const Function *F) const { 9613086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->isLoweredToCall(F); 9713086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 9813086a658ae06046ded902229f9918b8bad505bdChandler Carruth 997bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const { 1007bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isLegalAddImmediate(Imm); 1017bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1027bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const { 1047bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isLegalICmpImmediate(Imm); 1057bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1067bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, 1087bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int64_t BaseOffset, 1097bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool HasBaseReg, 1107bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int64_t Scale) const { 1117bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, 1127bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Scale); 1137bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1147bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 11506f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombetint TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, 11606f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet int64_t BaseOffset, 11706f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet bool HasBaseReg, 11806f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet int64_t Scale) const { 11906f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet return PrevTTI->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg, 12006f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet Scale); 12106f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet} 12206f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet 1237bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const { 1247bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isTruncateFree(Ty1, Ty2); 1257bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1277bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isTypeLegal(Type *Ty) const { 1287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isTypeLegal(Ty); 1297bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1307bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1317bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getJumpBufAlignment() const { 1327bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getJumpBufAlignment(); 1337bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1357bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getJumpBufSize() const { 1367bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getJumpBufSize(); 1377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1387bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1397bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::shouldBuildLookupTables() const { 1407bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->shouldBuildLookupTables(); 1417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 143d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler CarruthTargetTransformInfo::PopcntSupportKind 144d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler CarruthTargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const { 145d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth return PrevTTI->getPopcntSupport(IntTyWidthInBit); 1467bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1477bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1487bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { 1497bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getIntImmCost(Imm, Ty); 1507bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1517bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1527bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const { 1537bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getNumberOfRegisters(Vector); 1547bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1557bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 15614925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotemunsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const { 15714925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem return PrevTTI->getRegisterBitWidth(Vector); 15814925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem} 15914925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem 16083be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotemunsigned TargetTransformInfo::getMaximumUnrollFactor() const { 16183be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem return PrevTTI->getMaximumUnrollFactor(); 16283be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem} 16383be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem 1647bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode, 1656bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer Type *Ty, 1666bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer OperandValueKind Op1Info, 1676bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer OperandValueKind Op2Info) const { 1686bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer return PrevTTI->getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info); 1697bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1707bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1717bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp, 1727bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int Index, Type *SubTp) const { 1737bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp); 1747bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1757bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1767bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, 1777bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *Src) const { 1787bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getCastInstrCost(Opcode, Dst, Src); 1797bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1807bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1817bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const { 1827bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getCFInstrCost(Opcode); 1837bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1847bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1857bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 1867bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *CondTy) const { 1877bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy); 1887bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1897bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1907bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, 1917bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Index) const { 1927bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getVectorInstrCost(Opcode, Val, Index); 1937bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1947bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1957bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, 1967bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Alignment, 1977bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned AddressSpace) const { 1987bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace); 1997bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth ; 2007bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 2017bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2027bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned 2037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler CarruthTargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, 2047bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *RetTy, 2057bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth ArrayRef<Type *> Tys) const { 2067bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys); 2077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 2087bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2097bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const { 2107bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getNumberOfParts(Tp); 2117bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 2127bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 213c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighoferunsigned TargetTransformInfo::getAddressComputationCost(Type *Tp, 214c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer bool IsComplex) const { 215c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer return PrevTTI->getAddressComputationCost(Tp, IsComplex); 216fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer} 2177bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2187bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthnamespace { 2197bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 220aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruthstruct NoTTI : ImmutablePass, TargetTransformInfo { 2211e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth const DataLayout *DL; 2221e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2231e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth NoTTI() : ImmutablePass(ID), DL(0) { 224aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth initializeNoTTIPass(*PassRegistry::getPassRegistry()); 2257bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 227aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth virtual void initializePass() { 228aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth // Note that this subclass is special, and must *not* call initializeTTI as 229aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth // it does not chain. 23013086a658ae06046ded902229f9918b8bad505bdChandler Carruth TopTTI = this; 231aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth PrevTTI = 0; 2321e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth DL = getAnalysisIfAvailable<DataLayout>(); 2337bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 235aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth virtual void getAnalysisUsage(AnalysisUsage &AU) const { 2367bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth // Note that this subclass is special, and must *not* call 2377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth // TTI::getAnalysisUsage as it breaks the recursion. 2387bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2397bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2407bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth /// Pass identification. 2417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth static char ID; 2427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2437bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth /// Provide necessary pointer adjustments for the two base classes. 2447bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth virtual void *getAdjustedAnalysisPointer(const void *ID) { 2457bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth if (ID == &TargetTransformInfo::ID) 2467bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return (TargetTransformInfo*)this; 2477bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return this; 2487bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2497bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2501e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) const { 2511e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth switch (Opcode) { 2521e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth default: 2531e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // By default, just classify everything as 'basic'. 2541e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2551e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2561e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::GetElementPtr: 2571e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth llvm_unreachable("Use getGEPCost for GEP operations!"); 2581e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2591e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::BitCast: 2601e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth assert(OpTy && "Cast instructions must provide the operand type"); 2611e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (Ty == OpTy || (Ty->isPointerTy() && OpTy->isPointerTy())) 2621e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Identity and pointer-to-pointer casts are free. 2631e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2641e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2651e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise, the default basic cost is used. 2661e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2671e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2681e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::IntToPtr: 2691e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // An inttoptr cast is free so long as the input is a legal integer type 2701e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // which doesn't contain values outside the range of a pointer. 2711e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (DL && DL->isLegalInteger(OpTy->getScalarSizeInBits()) && 2721e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth OpTy->getScalarSizeInBits() <= DL->getPointerSizeInBits()) 2731e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2741e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2751e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise it's not a no-op. 2761e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2771e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2781e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::PtrToInt: 2791e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // A ptrtoint cast is free so long as the result is large enough to store 2801e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // the pointer, and a legal integer type. 281ac5b3915aa64d287057752c2c90cfe04adacfa11Patrik Hagglund if (DL && DL->isLegalInteger(Ty->getScalarSizeInBits()) && 282ac5b3915aa64d287057752c2c90cfe04adacfa11Patrik Hagglund Ty->getScalarSizeInBits() >= DL->getPointerSizeInBits()) 2831e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2841e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2851e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise it's not a no-op. 2861e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2871e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2881e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::Trunc: 2891e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // trunc to a native type is free (assuming the target has compare and 2901e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // shift-right of the same width). 2911e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (DL && DL->isLegalInteger(DL->getTypeSizeInBits(Ty))) 2921e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2931e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2941e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2951e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 2961e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 2971e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2981e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth unsigned getGEPCost(const Value *Ptr, 2991e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth ArrayRef<const Value *> Operands) const { 3001e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // In the basic model, we just assume that all-constant GEPs will be folded 3011e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // into their uses via addressing modes. 3021e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx) 3031e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (!isa<Constant>(Operands[Idx])) 3041e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 3051e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 3061e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 3071e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 3081e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 30913086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const { 31013086a658ae06046ded902229f9918b8bad505bdChandler Carruth assert(FTy && "FunctionType must be provided to this routine."); 31113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 31213086a658ae06046ded902229f9918b8bad505bdChandler Carruth // The target-independent implementation just measures the size of the 31313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // function by approximating that each argument will take on average one 31413086a658ae06046ded902229f9918b8bad505bdChandler Carruth // instruction to prepare. 31513086a658ae06046ded902229f9918b8bad505bdChandler Carruth 31613086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (NumArgs < 0) 31713086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Set the argument number to the number of explicit arguments in the 31813086a658ae06046ded902229f9918b8bad505bdChandler Carruth // function. 31913086a658ae06046ded902229f9918b8bad505bdChandler Carruth NumArgs = FTy->getNumParams(); 32013086a658ae06046ded902229f9918b8bad505bdChandler Carruth 32113086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Basic * (NumArgs + 1); 32213086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 32313086a658ae06046ded902229f9918b8bad505bdChandler Carruth 32413086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getCallCost(const Function *F, int NumArgs = -1) const { 32513086a658ae06046ded902229f9918b8bad505bdChandler Carruth assert(F && "A concrete function must be provided to this routine."); 32613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 32713086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (NumArgs < 0) 32813086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Set the argument number to the number of explicit arguments in the 32913086a658ae06046ded902229f9918b8bad505bdChandler Carruth // function. 33013086a658ae06046ded902229f9918b8bad505bdChandler Carruth NumArgs = F->arg_size(); 33113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 33213086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (Intrinsic::ID IID = (Intrinsic::ID)F->getIntrinsicID()) { 33313086a658ae06046ded902229f9918b8bad505bdChandler Carruth FunctionType *FTy = F->getFunctionType(); 33413086a658ae06046ded902229f9918b8bad505bdChandler Carruth SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end()); 33513086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys); 33613086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 33713086a658ae06046ded902229f9918b8bad505bdChandler Carruth 33813086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (!TopTTI->isLoweredToCall(F)) 33913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Basic; // Give a basic cost if it will be lowered directly. 34013086a658ae06046ded902229f9918b8bad505bdChandler Carruth 34113086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(F->getFunctionType(), NumArgs); 34213086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 34313086a658ae06046ded902229f9918b8bad505bdChandler Carruth 34413086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getCallCost(const Function *F, 34513086a658ae06046ded902229f9918b8bad505bdChandler Carruth ArrayRef<const Value *> Arguments) const { 34613086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Simply delegate to generic handling of the call. 34713086a658ae06046ded902229f9918b8bad505bdChandler Carruth // FIXME: We should use instsimplify or something else to catch calls which 34813086a658ae06046ded902229f9918b8bad505bdChandler Carruth // will constant fold with these arguments. 34913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(F, Arguments.size()); 35013086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 35113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 35213086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, 35313086a658ae06046ded902229f9918b8bad505bdChandler Carruth ArrayRef<Type *> ParamTys) const { 35413086a658ae06046ded902229f9918b8bad505bdChandler Carruth switch (IID) { 35513086a658ae06046ded902229f9918b8bad505bdChandler Carruth default: 35613086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Intrinsics rarely (if ever) have normal argument setup constraints. 35713086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Model them as having a basic instruction cost. 35813086a658ae06046ded902229f9918b8bad505bdChandler Carruth // FIXME: This is wrong for libc intrinsics. 35913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Basic; 36013086a658ae06046ded902229f9918b8bad505bdChandler Carruth 36113086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::dbg_declare: 36213086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::dbg_value: 36313086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::invariant_start: 36413086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::invariant_end: 36513086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::lifetime_start: 36613086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::lifetime_end: 36713086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::objectsize: 36813086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::ptr_annotation: 36913086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::var_annotation: 37013086a658ae06046ded902229f9918b8bad505bdChandler Carruth // These intrinsics don't actually represent code after lowering. 37113086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Free; 37213086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 37313086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 37413086a658ae06046ded902229f9918b8bad505bdChandler Carruth 37513086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, 37613086a658ae06046ded902229f9918b8bad505bdChandler Carruth ArrayRef<const Value *> Arguments) const { 37713086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Delegate to the generic intrinsic handling code. This mostly provides an 37813086a658ae06046ded902229f9918b8bad505bdChandler Carruth // opportunity for targets to (for example) special case the cost of 37913086a658ae06046ded902229f9918b8bad505bdChandler Carruth // certain intrinsics based on constants used as arguments. 38013086a658ae06046ded902229f9918b8bad505bdChandler Carruth SmallVector<Type *, 8> ParamTys; 38113086a658ae06046ded902229f9918b8bad505bdChandler Carruth ParamTys.reserve(Arguments.size()); 38213086a658ae06046ded902229f9918b8bad505bdChandler Carruth for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx) 38313086a658ae06046ded902229f9918b8bad505bdChandler Carruth ParamTys.push_back(Arguments[Idx]->getType()); 38413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getIntrinsicCost(IID, RetTy, ParamTys); 38513086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 38613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 3871e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth unsigned getUserCost(const User *U) const { 388a5157e68d183e1bdf010e94a15dc0c44b65f889bChandler Carruth if (isa<PHINode>(U)) 389a5157e68d183e1bdf010e94a15dc0c44b65f889bChandler Carruth return TCC_Free; // Model all PHI nodes as free. 390a5157e68d183e1bdf010e94a15dc0c44b65f889bChandler Carruth 3911e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) 3921e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // In the basic model we just assume that all-constant GEPs will be 3931e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // folded into their uses via addressing modes. 3941e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return GEP->hasAllConstantIndices() ? TCC_Free : TCC_Basic; 3951e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 39613086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (ImmutableCallSite CS = U) { 39713086a658ae06046ded902229f9918b8bad505bdChandler Carruth const Function *F = CS.getCalledFunction(); 39813086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (!F) { 39913086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Just use the called value type. 40013086a658ae06046ded902229f9918b8bad505bdChandler Carruth Type *FTy = CS.getCalledValue()->getType()->getPointerElementType(); 40113086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(cast<FunctionType>(FTy), CS.arg_size()); 4021e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 40313086a658ae06046ded902229f9918b8bad505bdChandler Carruth 40413086a658ae06046ded902229f9918b8bad505bdChandler Carruth SmallVector<const Value *, 8> Arguments; 40513086a658ae06046ded902229f9918b8bad505bdChandler Carruth for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), 40613086a658ae06046ded902229f9918b8bad505bdChandler Carruth AE = CS.arg_end(); 40713086a658ae06046ded902229f9918b8bad505bdChandler Carruth AI != AE; ++AI) 40813086a658ae06046ded902229f9918b8bad505bdChandler Carruth Arguments.push_back(*AI); 40913086a658ae06046ded902229f9918b8bad505bdChandler Carruth 41013086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(F, Arguments); 4111e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 4121e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 4131e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (const CastInst *CI = dyn_cast<CastInst>(U)) { 4141e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Result of a cmp instruction is often extended (to be used by other 4151e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // cmp instructions, logical or return instructions). These are usually 4161e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // nop on most sane targets. 4171e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (isa<CmpInst>(CI->getOperand(0))) 4181e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 4191e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 4201e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 4211e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise delegate to the fully generic implementations. 4221e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return getOperationCost(Operator::getOpcode(U), U->getType(), 4231e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth U->getNumOperands() == 1 ? 4241e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth U->getOperand(0)->getType() : 0); 4251e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 4267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 42757e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard bool hasBranchDivergence() const { return false; } 42857e6b2d1f3de0bf459e96f7038e692d624f7e580Tom Stellard 42913086a658ae06046ded902229f9918b8bad505bdChandler Carruth bool isLoweredToCall(const Function *F) const { 43013086a658ae06046ded902229f9918b8bad505bdChandler Carruth // FIXME: These should almost certainly not be handled here, and instead 43113086a658ae06046ded902229f9918b8bad505bdChandler Carruth // handled with the help of TLI or the target itself. This was largely 43213086a658ae06046ded902229f9918b8bad505bdChandler Carruth // ported from existing analysis heuristics here so that such refactorings 43313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // can take place in the future. 43413086a658ae06046ded902229f9918b8bad505bdChandler Carruth 43513086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (F->isIntrinsic()) 43613086a658ae06046ded902229f9918b8bad505bdChandler Carruth return false; 43713086a658ae06046ded902229f9918b8bad505bdChandler Carruth 43813086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (F->hasLocalLinkage() || !F->hasName()) 43913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return true; 44013086a658ae06046ded902229f9918b8bad505bdChandler Carruth 44113086a658ae06046ded902229f9918b8bad505bdChandler Carruth StringRef Name = F->getName(); 44213086a658ae06046ded902229f9918b8bad505bdChandler Carruth 44313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // These will all likely lower to a single selection DAG node. 44413086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" || 44513086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "fabs" || Name == "fabsf" || Name == "fabsl" || Name == "sin" || 44613086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "sinf" || Name == "sinl" || Name == "cos" || Name == "cosf" || 44713086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "cosl" || Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl") 44813086a658ae06046ded902229f9918b8bad505bdChandler Carruth return false; 44913086a658ae06046ded902229f9918b8bad505bdChandler Carruth 45013086a658ae06046ded902229f9918b8bad505bdChandler Carruth // These are all likely to be optimized into something smaller. 45113086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" || 45213086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "exp2l" || Name == "exp2f" || Name == "floor" || Name == 45313086a658ae06046ded902229f9918b8bad505bdChandler Carruth "floorf" || Name == "ceil" || Name == "round" || Name == "ffs" || 45413086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "ffsl" || Name == "abs" || Name == "labs" || Name == "llabs") 45513086a658ae06046ded902229f9918b8bad505bdChandler Carruth return false; 45613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 45713086a658ae06046ded902229f9918b8bad505bdChandler Carruth return true; 45813086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 45913086a658ae06046ded902229f9918b8bad505bdChandler Carruth 4607bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isLegalAddImmediate(int64_t Imm) const { 461aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4627bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4637bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4647bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isLegalICmpImmediate(int64_t Imm) const { 465aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4667bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4677bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4687bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, 4697bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool HasBaseReg, int64_t Scale) const { 470e4ba75f43e2ab1480d119d2d4eb878256274e0fbChandler Carruth // Guess that reg+reg addressing is allowed. This heuristic is taken from 471e4ba75f43e2ab1480d119d2d4eb878256274e0fbChandler Carruth // the implementation of LSR. 472e4ba75f43e2ab1480d119d2d4eb878256274e0fbChandler Carruth return !BaseGV && BaseOffset == 0 && Scale <= 1; 4737bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4747bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 47506f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, 47606f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet bool HasBaseReg, int64_t Scale) const { 47706f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet // Guess that all legal addressing mode are free. 47806f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet if(isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, Scale)) 47906f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet return 0; 48006f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet return -1; 48106f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet } 48206f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet 48306f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet 4847bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isTruncateFree(Type *Ty1, Type *Ty2) const { 485aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4867bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4877bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4887bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isTypeLegal(Type *Ty) const { 489aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4907bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4917bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4927bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getJumpBufAlignment() const { 493aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 0; 4947bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4957bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4967bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getJumpBufSize() const { 497aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 0; 4987bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4997bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5007bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool shouldBuildLookupTables() const { 501aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return true; 5027bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 504d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const { 505d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth return PSK_Software; 5067bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5087bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getIntImmCost(const APInt &Imm, Type *Ty) const { 509aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5107bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5117bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5127bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getNumberOfRegisters(bool Vector) const { 513aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 8; 5147bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5157bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 51614925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem unsigned getRegisterBitWidth(bool Vector) const { 51714925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem return 32; 51814925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem } 51914925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem 52083be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem unsigned getMaximumUnrollFactor() const { 52183be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem return 1; 52283be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem } 52383be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem 5246bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind, 5256bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer OperandValueKind) const { 526aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5277bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5297bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, 5307bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int Index = 0, Type *SubTp = 0) const { 531aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5327bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5337bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getCastInstrCost(unsigned Opcode, Type *Dst, 5357bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *Src) const { 536aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5387bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5397bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getCFInstrCost(unsigned Opcode) const { 540aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5437bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 5447bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *CondTy = 0) const { 545aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5467bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5477bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5487bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getVectorInstrCost(unsigned Opcode, Type *Val, 5497bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Index = -1) const { 550aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5517bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5527bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5537bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getMemoryOpCost(unsigned Opcode, Type *Src, 5547bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Alignment, 5557bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned AddressSpace) const { 556aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5577bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5587bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5597bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getIntrinsicInstrCost(Intrinsic::ID ID, 5607bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *RetTy, 5617bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth ArrayRef<Type*> Tys) const { 562aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5637bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5647bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5657bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getNumberOfParts(Type *Tp) const { 566aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 0; 5677bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 568fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer 569c0a11edba6ea46c782672ab3fb4e4ab3dc267a22Arnold Schwaighofer unsigned getAddressComputationCost(Type *Tp, bool) const { 570fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer return 0; 571fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer } 5727bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth}; 5737bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5747bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} // end anonymous namespace 5757bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 576aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler CarruthINITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti", 5777bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth "No target information", true, true, true) 5787bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthchar NoTTI::ID = 0; 5797bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 580aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler CarruthImmutablePass *llvm::createNoTargetTransformInfoPass() { 581aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return new NoTTI(); 5827bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 583