TargetTransformInfo.cpp revision 06f5ebc5a1604b01689cf2d482dd05f956538af6
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 9113086a658ae06046ded902229f9918b8bad505bdChandler Carruthbool TargetTransformInfo::isLoweredToCall(const Function *F) const { 9213086a658ae06046ded902229f9918b8bad505bdChandler Carruth return PrevTTI->isLoweredToCall(F); 9313086a658ae06046ded902229f9918b8bad505bdChandler Carruth} 9413086a658ae06046ded902229f9918b8bad505bdChandler Carruth 957bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isLegalAddImmediate(int64_t Imm) const { 967bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isLegalAddImmediate(Imm); 977bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 987bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 997bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isLegalICmpImmediate(int64_t Imm) const { 1007bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isLegalICmpImmediate(Imm); 1017bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1027bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, 1047bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int64_t BaseOffset, 1057bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool HasBaseReg, 1067bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int64_t Scale) const { 1077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, 1087bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Scale); 1097bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1107bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 11106f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombetint TargetTransformInfo::getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, 11206f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet int64_t BaseOffset, 11306f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet bool HasBaseReg, 11406f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet int64_t Scale) const { 11506f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet return PrevTTI->getScalingFactorCost(Ty, BaseGV, BaseOffset, HasBaseReg, 11606f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet Scale); 11706f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet} 11806f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet 1197bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isTruncateFree(Type *Ty1, Type *Ty2) const { 1207bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isTruncateFree(Ty1, Ty2); 1217bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1227bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1237bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::isTypeLegal(Type *Ty) const { 1247bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->isTypeLegal(Ty); 1257bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1277bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getJumpBufAlignment() const { 1287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getJumpBufAlignment(); 1297bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1307bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1317bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getJumpBufSize() const { 1327bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getJumpBufSize(); 1337bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1357bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthbool TargetTransformInfo::shouldBuildLookupTables() const { 1367bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->shouldBuildLookupTables(); 1377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1387bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 139d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler CarruthTargetTransformInfo::PopcntSupportKind 140d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler CarruthTargetTransformInfo::getPopcntSupport(unsigned IntTyWidthInBit) const { 141d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth return PrevTTI->getPopcntSupport(IntTyWidthInBit); 1427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1437bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1447bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getIntImmCost(const APInt &Imm, Type *Ty) const { 1457bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getIntImmCost(Imm, Ty); 1467bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1477bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1487bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getNumberOfRegisters(bool Vector) const { 1497bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getNumberOfRegisters(Vector); 1507bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1517bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 15214925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotemunsigned TargetTransformInfo::getRegisterBitWidth(bool Vector) const { 15314925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem return PrevTTI->getRegisterBitWidth(Vector); 15414925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem} 15514925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem 15683be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotemunsigned TargetTransformInfo::getMaximumUnrollFactor() const { 15783be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem return PrevTTI->getMaximumUnrollFactor(); 15883be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem} 15983be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem 1607bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getArithmeticInstrCost(unsigned Opcode, 1616bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer Type *Ty, 1626bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer OperandValueKind Op1Info, 1636bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer OperandValueKind Op2Info) const { 1646bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer return PrevTTI->getArithmeticInstrCost(Opcode, Ty, Op1Info, Op2Info); 1657bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1667bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1677bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getShuffleCost(ShuffleKind Kind, Type *Tp, 1687bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int Index, Type *SubTp) const { 1697bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getShuffleCost(Kind, Tp, Index, SubTp); 1707bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1717bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1727bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getCastInstrCost(unsigned Opcode, Type *Dst, 1737bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *Src) const { 1747bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getCastInstrCost(Opcode, Dst, Src); 1757bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1767bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1777bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getCFInstrCost(unsigned Opcode) const { 1787bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getCFInstrCost(Opcode); 1797bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1807bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1817bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 1827bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *CondTy) const { 1837bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getCmpSelInstrCost(Opcode, ValTy, CondTy); 1847bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1857bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1867bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getVectorInstrCost(unsigned Opcode, Type *Val, 1877bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Index) const { 1887bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getVectorInstrCost(Opcode, Val, Index); 1897bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1907bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1917bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getMemoryOpCost(unsigned Opcode, Type *Src, 1927bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Alignment, 1937bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned AddressSpace) const { 1947bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getMemoryOpCost(Opcode, Src, Alignment, AddressSpace); 1957bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth ; 1967bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 1977bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 1987bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned 1997bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler CarruthTargetTransformInfo::getIntrinsicInstrCost(Intrinsic::ID ID, 2007bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *RetTy, 2017bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth ArrayRef<Type *> Tys) const { 2027bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getIntrinsicInstrCost(ID, RetTy, Tys); 2037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 2047bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2057bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthunsigned TargetTransformInfo::getNumberOfParts(Type *Tp) const { 2067bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return PrevTTI->getNumberOfParts(Tp); 2077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 2087bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 209fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighoferunsigned TargetTransformInfo::getAddressComputationCost(Type *Tp) const { 210fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer return PrevTTI->getAddressComputationCost(Tp); 211fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer} 2127bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2137bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthnamespace { 2147bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 215aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruthstruct NoTTI : ImmutablePass, TargetTransformInfo { 2161e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth const DataLayout *DL; 2171e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2181e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth NoTTI() : ImmutablePass(ID), DL(0) { 219aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth initializeNoTTIPass(*PassRegistry::getPassRegistry()); 2207bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2217bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 222aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth virtual void initializePass() { 223aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth // Note that this subclass is special, and must *not* call initializeTTI as 224aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth // it does not chain. 22513086a658ae06046ded902229f9918b8bad505bdChandler Carruth TopTTI = this; 226aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth PrevTTI = 0; 2271e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth DL = getAnalysisIfAvailable<DataLayout>(); 2287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2297bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 230aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth virtual void getAnalysisUsage(AnalysisUsage &AU) const { 2317bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth // Note that this subclass is special, and must *not* call 2327bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth // TTI::getAnalysisUsage as it breaks the recursion. 2337bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2357bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth /// Pass identification. 2367bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth static char ID; 2377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2387bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth /// Provide necessary pointer adjustments for the two base classes. 2397bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth virtual void *getAdjustedAnalysisPointer(const void *ID) { 2407bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth if (ID == &TargetTransformInfo::ID) 2417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return (TargetTransformInfo*)this; 2427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth return this; 2437bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 2447bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 2451e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth unsigned getOperationCost(unsigned Opcode, Type *Ty, Type *OpTy) const { 2461e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth switch (Opcode) { 2471e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth default: 2481e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // By default, just classify everything as 'basic'. 2491e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2501e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2511e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::GetElementPtr: 2521e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth llvm_unreachable("Use getGEPCost for GEP operations!"); 2531e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2541e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::BitCast: 2551e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth assert(OpTy && "Cast instructions must provide the operand type"); 2561e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (Ty == OpTy || (Ty->isPointerTy() && OpTy->isPointerTy())) 2571e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Identity and pointer-to-pointer casts are free. 2581e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2591e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2601e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise, the default basic cost is used. 2611e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2621e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2631e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::IntToPtr: 2641e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // An inttoptr cast is free so long as the input is a legal integer type 2651e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // which doesn't contain values outside the range of a pointer. 2661e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (DL && DL->isLegalInteger(OpTy->getScalarSizeInBits()) && 2671e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth OpTy->getScalarSizeInBits() <= DL->getPointerSizeInBits()) 2681e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2691e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2701e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise it's not a no-op. 2711e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2721e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2731e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::PtrToInt: 2741e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // A ptrtoint cast is free so long as the result is large enough to store 2751e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // the pointer, and a legal integer type. 276ac5b3915aa64d287057752c2c90cfe04adacfa11Patrik Hagglund if (DL && DL->isLegalInteger(Ty->getScalarSizeInBits()) && 277ac5b3915aa64d287057752c2c90cfe04adacfa11Patrik Hagglund Ty->getScalarSizeInBits() >= DL->getPointerSizeInBits()) 2781e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2791e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2801e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise it's not a no-op. 2811e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2821e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2831e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth case Instruction::Trunc: 2841e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // trunc to a native type is free (assuming the target has compare and 2851e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // shift-right of the same width). 2861e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (DL && DL->isLegalInteger(DL->getTypeSizeInBits(Ty))) 2871e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 2881e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2891e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 2901e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 2911e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 2921e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 2931e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth unsigned getGEPCost(const Value *Ptr, 2941e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth ArrayRef<const Value *> Operands) const { 2951e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // In the basic model, we just assume that all-constant GEPs will be folded 2961e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // into their uses via addressing modes. 2971e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth for (unsigned Idx = 0, Size = Operands.size(); Idx != Size; ++Idx) 2981e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (!isa<Constant>(Operands[Idx])) 2991e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Basic; 3001e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 3011e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 3021e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 3031e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 30413086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getCallCost(FunctionType *FTy, int NumArgs = -1) const { 30513086a658ae06046ded902229f9918b8bad505bdChandler Carruth assert(FTy && "FunctionType must be provided to this routine."); 30613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 30713086a658ae06046ded902229f9918b8bad505bdChandler Carruth // The target-independent implementation just measures the size of the 30813086a658ae06046ded902229f9918b8bad505bdChandler Carruth // function by approximating that each argument will take on average one 30913086a658ae06046ded902229f9918b8bad505bdChandler Carruth // instruction to prepare. 31013086a658ae06046ded902229f9918b8bad505bdChandler Carruth 31113086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (NumArgs < 0) 31213086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Set the argument number to the number of explicit arguments in the 31313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // function. 31413086a658ae06046ded902229f9918b8bad505bdChandler Carruth NumArgs = FTy->getNumParams(); 31513086a658ae06046ded902229f9918b8bad505bdChandler Carruth 31613086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Basic * (NumArgs + 1); 31713086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 31813086a658ae06046ded902229f9918b8bad505bdChandler Carruth 31913086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getCallCost(const Function *F, int NumArgs = -1) const { 32013086a658ae06046ded902229f9918b8bad505bdChandler Carruth assert(F && "A concrete function must be provided to this routine."); 32113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 32213086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (NumArgs < 0) 32313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Set the argument number to the number of explicit arguments in the 32413086a658ae06046ded902229f9918b8bad505bdChandler Carruth // function. 32513086a658ae06046ded902229f9918b8bad505bdChandler Carruth NumArgs = F->arg_size(); 32613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 32713086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (Intrinsic::ID IID = (Intrinsic::ID)F->getIntrinsicID()) { 32813086a658ae06046ded902229f9918b8bad505bdChandler Carruth FunctionType *FTy = F->getFunctionType(); 32913086a658ae06046ded902229f9918b8bad505bdChandler Carruth SmallVector<Type *, 8> ParamTys(FTy->param_begin(), FTy->param_end()); 33013086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getIntrinsicCost(IID, FTy->getReturnType(), ParamTys); 33113086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 33213086a658ae06046ded902229f9918b8bad505bdChandler Carruth 33313086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (!TopTTI->isLoweredToCall(F)) 33413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Basic; // Give a basic cost if it will be lowered directly. 33513086a658ae06046ded902229f9918b8bad505bdChandler Carruth 33613086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(F->getFunctionType(), NumArgs); 33713086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 33813086a658ae06046ded902229f9918b8bad505bdChandler Carruth 33913086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getCallCost(const Function *F, 34013086a658ae06046ded902229f9918b8bad505bdChandler Carruth ArrayRef<const Value *> Arguments) const { 34113086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Simply delegate to generic handling of the call. 34213086a658ae06046ded902229f9918b8bad505bdChandler Carruth // FIXME: We should use instsimplify or something else to catch calls which 34313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // will constant fold with these arguments. 34413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(F, Arguments.size()); 34513086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 34613086a658ae06046ded902229f9918b8bad505bdChandler Carruth 34713086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, 34813086a658ae06046ded902229f9918b8bad505bdChandler Carruth ArrayRef<Type *> ParamTys) const { 34913086a658ae06046ded902229f9918b8bad505bdChandler Carruth switch (IID) { 35013086a658ae06046ded902229f9918b8bad505bdChandler Carruth default: 35113086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Intrinsics rarely (if ever) have normal argument setup constraints. 35213086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Model them as having a basic instruction cost. 35313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // FIXME: This is wrong for libc intrinsics. 35413086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Basic; 35513086a658ae06046ded902229f9918b8bad505bdChandler Carruth 35613086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::dbg_declare: 35713086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::dbg_value: 35813086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::invariant_start: 35913086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::invariant_end: 36013086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::lifetime_start: 36113086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::lifetime_end: 36213086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::objectsize: 36313086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::ptr_annotation: 36413086a658ae06046ded902229f9918b8bad505bdChandler Carruth case Intrinsic::var_annotation: 36513086a658ae06046ded902229f9918b8bad505bdChandler Carruth // These intrinsics don't actually represent code after lowering. 36613086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TCC_Free; 36713086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 36813086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 36913086a658ae06046ded902229f9918b8bad505bdChandler Carruth 37013086a658ae06046ded902229f9918b8bad505bdChandler Carruth unsigned getIntrinsicCost(Intrinsic::ID IID, Type *RetTy, 37113086a658ae06046ded902229f9918b8bad505bdChandler Carruth ArrayRef<const Value *> Arguments) const { 37213086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Delegate to the generic intrinsic handling code. This mostly provides an 37313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // opportunity for targets to (for example) special case the cost of 37413086a658ae06046ded902229f9918b8bad505bdChandler Carruth // certain intrinsics based on constants used as arguments. 37513086a658ae06046ded902229f9918b8bad505bdChandler Carruth SmallVector<Type *, 8> ParamTys; 37613086a658ae06046ded902229f9918b8bad505bdChandler Carruth ParamTys.reserve(Arguments.size()); 37713086a658ae06046ded902229f9918b8bad505bdChandler Carruth for (unsigned Idx = 0, Size = Arguments.size(); Idx != Size; ++Idx) 37813086a658ae06046ded902229f9918b8bad505bdChandler Carruth ParamTys.push_back(Arguments[Idx]->getType()); 37913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getIntrinsicCost(IID, RetTy, ParamTys); 38013086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 38113086a658ae06046ded902229f9918b8bad505bdChandler Carruth 3821e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth unsigned getUserCost(const User *U) const { 383a5157e68d183e1bdf010e94a15dc0c44b65f889bChandler Carruth if (isa<PHINode>(U)) 384a5157e68d183e1bdf010e94a15dc0c44b65f889bChandler Carruth return TCC_Free; // Model all PHI nodes as free. 385a5157e68d183e1bdf010e94a15dc0c44b65f889bChandler Carruth 3861e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (const GEPOperator *GEP = dyn_cast<GEPOperator>(U)) 3871e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // In the basic model we just assume that all-constant GEPs will be 3881e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // folded into their uses via addressing modes. 3891e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return GEP->hasAllConstantIndices() ? TCC_Free : TCC_Basic; 3901e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 39113086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (ImmutableCallSite CS = U) { 39213086a658ae06046ded902229f9918b8bad505bdChandler Carruth const Function *F = CS.getCalledFunction(); 39313086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (!F) { 39413086a658ae06046ded902229f9918b8bad505bdChandler Carruth // Just use the called value type. 39513086a658ae06046ded902229f9918b8bad505bdChandler Carruth Type *FTy = CS.getCalledValue()->getType()->getPointerElementType(); 39613086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(cast<FunctionType>(FTy), CS.arg_size()); 3971e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 39813086a658ae06046ded902229f9918b8bad505bdChandler Carruth 39913086a658ae06046ded902229f9918b8bad505bdChandler Carruth SmallVector<const Value *, 8> Arguments; 40013086a658ae06046ded902229f9918b8bad505bdChandler Carruth for (ImmutableCallSite::arg_iterator AI = CS.arg_begin(), 40113086a658ae06046ded902229f9918b8bad505bdChandler Carruth AE = CS.arg_end(); 40213086a658ae06046ded902229f9918b8bad505bdChandler Carruth AI != AE; ++AI) 40313086a658ae06046ded902229f9918b8bad505bdChandler Carruth Arguments.push_back(*AI); 40413086a658ae06046ded902229f9918b8bad505bdChandler Carruth 40513086a658ae06046ded902229f9918b8bad505bdChandler Carruth return TopTTI->getCallCost(F, Arguments); 4061e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 4071e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 4081e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (const CastInst *CI = dyn_cast<CastInst>(U)) { 4091e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Result of a cmp instruction is often extended (to be used by other 4101e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // cmp instructions, logical or return instructions). These are usually 4111e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // nop on most sane targets. 4121e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth if (isa<CmpInst>(CI->getOperand(0))) 4131e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return TCC_Free; 4141e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 4151e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth 4161e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth // Otherwise delegate to the fully generic implementations. 4171e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth return getOperationCost(Operator::getOpcode(U), U->getType(), 4181e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth U->getNumOperands() == 1 ? 4191e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth U->getOperand(0)->getType() : 0); 4201e05bd9e714934a71ff933ad15f0b884808b405fChandler Carruth } 4217bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 42213086a658ae06046ded902229f9918b8bad505bdChandler Carruth bool isLoweredToCall(const Function *F) const { 42313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // FIXME: These should almost certainly not be handled here, and instead 42413086a658ae06046ded902229f9918b8bad505bdChandler Carruth // handled with the help of TLI or the target itself. This was largely 42513086a658ae06046ded902229f9918b8bad505bdChandler Carruth // ported from existing analysis heuristics here so that such refactorings 42613086a658ae06046ded902229f9918b8bad505bdChandler Carruth // can take place in the future. 42713086a658ae06046ded902229f9918b8bad505bdChandler Carruth 42813086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (F->isIntrinsic()) 42913086a658ae06046ded902229f9918b8bad505bdChandler Carruth return false; 43013086a658ae06046ded902229f9918b8bad505bdChandler Carruth 43113086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (F->hasLocalLinkage() || !F->hasName()) 43213086a658ae06046ded902229f9918b8bad505bdChandler Carruth return true; 43313086a658ae06046ded902229f9918b8bad505bdChandler Carruth 43413086a658ae06046ded902229f9918b8bad505bdChandler Carruth StringRef Name = F->getName(); 43513086a658ae06046ded902229f9918b8bad505bdChandler Carruth 43613086a658ae06046ded902229f9918b8bad505bdChandler Carruth // These will all likely lower to a single selection DAG node. 43713086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (Name == "copysign" || Name == "copysignf" || Name == "copysignl" || 43813086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "fabs" || Name == "fabsf" || Name == "fabsl" || Name == "sin" || 43913086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "sinf" || Name == "sinl" || Name == "cos" || Name == "cosf" || 44013086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "cosl" || Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl") 44113086a658ae06046ded902229f9918b8bad505bdChandler Carruth return false; 44213086a658ae06046ded902229f9918b8bad505bdChandler Carruth 44313086a658ae06046ded902229f9918b8bad505bdChandler Carruth // These are all likely to be optimized into something smaller. 44413086a658ae06046ded902229f9918b8bad505bdChandler Carruth if (Name == "pow" || Name == "powf" || Name == "powl" || Name == "exp2" || 44513086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "exp2l" || Name == "exp2f" || Name == "floor" || Name == 44613086a658ae06046ded902229f9918b8bad505bdChandler Carruth "floorf" || Name == "ceil" || Name == "round" || Name == "ffs" || 44713086a658ae06046ded902229f9918b8bad505bdChandler Carruth Name == "ffsl" || Name == "abs" || Name == "labs" || Name == "llabs") 44813086a658ae06046ded902229f9918b8bad505bdChandler Carruth return false; 44913086a658ae06046ded902229f9918b8bad505bdChandler Carruth 45013086a658ae06046ded902229f9918b8bad505bdChandler Carruth return true; 45113086a658ae06046ded902229f9918b8bad505bdChandler Carruth } 45213086a658ae06046ded902229f9918b8bad505bdChandler Carruth 4537bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isLegalAddImmediate(int64_t Imm) const { 454aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4557bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4567bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4577bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isLegalICmpImmediate(int64_t Imm) const { 458aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4597bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4607bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4617bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isLegalAddressingMode(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, 4627bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool HasBaseReg, int64_t Scale) const { 463e4ba75f43e2ab1480d119d2d4eb878256274e0fbChandler Carruth // Guess that reg+reg addressing is allowed. This heuristic is taken from 464e4ba75f43e2ab1480d119d2d4eb878256274e0fbChandler Carruth // the implementation of LSR. 465e4ba75f43e2ab1480d119d2d4eb878256274e0fbChandler Carruth return !BaseGV && BaseOffset == 0 && Scale <= 1; 4667bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4677bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 46806f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet int getScalingFactorCost(Type *Ty, GlobalValue *BaseGV, int64_t BaseOffset, 46906f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet bool HasBaseReg, int64_t Scale) const { 47006f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet // Guess that all legal addressing mode are free. 47106f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet if(isLegalAddressingMode(Ty, BaseGV, BaseOffset, HasBaseReg, Scale)) 47206f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet return 0; 47306f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet return -1; 47406f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet } 47506f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet 47606f5ebc5a1604b01689cf2d482dd05f956538af6Quentin Colombet 4777bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isTruncateFree(Type *Ty1, Type *Ty2) const { 478aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4797bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4807bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4817bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool isTypeLegal(Type *Ty) const { 482aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return false; 4837bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4847bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4857bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getJumpBufAlignment() const { 486aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 0; 4877bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4887bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4897bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getJumpBufSize() const { 490aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 0; 4917bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4927bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 4937bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth bool shouldBuildLookupTables() const { 494aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return true; 4957bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 4967bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 497d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth PopcntSupportKind getPopcntSupport(unsigned IntTyWidthInBit) const { 498d1b8ef97c47d347f2a2261a0d6de4872f248321fChandler Carruth return PSK_Software; 4997bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5007bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5017bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getIntImmCost(const APInt &Imm, Type *Ty) const { 502aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5037bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5047bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5057bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getNumberOfRegisters(bool Vector) const { 506aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 8; 5077bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5087bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 50914925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem unsigned getRegisterBitWidth(bool Vector) const { 51014925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem return 32; 51114925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem } 51214925e6b885f8bd8cf448627386d412831f4bf1bNadav Rotem 51383be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem unsigned getMaximumUnrollFactor() const { 51483be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem return 1; 51583be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem } 51683be7b0dd3ae9a3cb22d36ae4c1775972553b94bNadav Rotem 5176bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer unsigned getArithmeticInstrCost(unsigned Opcode, Type *Ty, OperandValueKind, 5186bf4f676413b8f7d97aaff289997aab344180957Arnold Schwaighofer OperandValueKind) const { 519aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5207bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5217bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5227bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getShuffleCost(ShuffleKind Kind, Type *Tp, 5237bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth int Index = 0, Type *SubTp = 0) const { 524aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5257bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5267bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5277bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getCastInstrCost(unsigned Opcode, Type *Dst, 5287bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *Src) const { 529aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5307bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5317bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5327bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getCFInstrCost(unsigned Opcode) const { 533aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5347bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5357bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5367bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getCmpSelInstrCost(unsigned Opcode, Type *ValTy, 5377bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *CondTy = 0) const { 538aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5397bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5407bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5417bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getVectorInstrCost(unsigned Opcode, Type *Val, 5427bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Index = -1) const { 543aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5447bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5457bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5467bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getMemoryOpCost(unsigned Opcode, Type *Src, 5477bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned Alignment, 5487bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned AddressSpace) const { 549aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5507bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5517bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5527bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getIntrinsicInstrCost(Intrinsic::ID ID, 5537bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth Type *RetTy, 5547bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth ArrayRef<Type*> Tys) const { 555aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 1; 5567bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 5577bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5587bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth unsigned getNumberOfParts(Type *Tp) const { 559aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return 0; 5607bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth } 561fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer 562fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer unsigned getAddressComputationCost(Type *Tp) const { 563fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer return 0; 564fb55a8fd7c38aa09d9c243d48a8a72d890f36a3dArnold Schwaighofer } 5657bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth}; 5667bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 5677bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} // end anonymous namespace 5687bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 569aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler CarruthINITIALIZE_AG_PASS(NoTTI, TargetTransformInfo, "notti", 5707bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth "No target information", true, true, true) 5717bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruthchar NoTTI::ID = 0; 5727bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth 573aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler CarruthImmutablePass *llvm::createNoTargetTransformInfoPass() { 574aeef83c6afa1e18d1cf9d359cc678ca0ad556175Chandler Carruth return new NoTTI(); 5757bdf6b00e04c177f22133b5d4be10cb246cb1e76Chandler Carruth} 576