1 //===-- NVPTXTargetTransformInfo.cpp - NVPTX specific TTI -----------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "NVPTXTargetTransformInfo.h" 11 #include "llvm/Analysis/LoopInfo.h" 12 #include "llvm/Analysis/TargetTransformInfo.h" 13 #include "llvm/Analysis/ValueTracking.h" 14 #include "llvm/CodeGen/BasicTTIImpl.h" 15 #include "llvm/Support/Debug.h" 16 #include "llvm/Target/CostTable.h" 17 #include "llvm/Target/TargetLowering.h" 18 using namespace llvm; 19 20 #define DEBUG_TYPE "NVPTXtti" 21 22 unsigned NVPTXTTIImpl::getArithmeticInstrCost( 23 unsigned Opcode, Type *Ty, TTI::OperandValueKind Opd1Info, 24 TTI::OperandValueKind Opd2Info, TTI::OperandValueProperties Opd1PropInfo, 25 TTI::OperandValueProperties Opd2PropInfo) { 26 // Legalize the type. 27 std::pair<unsigned, MVT> LT = TLI->getTypeLegalizationCost(Ty); 28 29 int ISD = TLI->InstructionOpcodeToISD(Opcode); 30 31 switch (ISD) { 32 default: 33 return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 34 Opd1PropInfo, Opd2PropInfo); 35 case ISD::ADD: 36 case ISD::MUL: 37 case ISD::XOR: 38 case ISD::OR: 39 case ISD::AND: 40 // The machine code (SASS) simulates an i64 with two i32. Therefore, we 41 // estimate that arithmetic operations on i64 are twice as expensive as 42 // those on types that can fit into one machine register. 43 if (LT.second.SimpleTy == MVT::i64) 44 return 2 * LT.first; 45 // Delegate other cases to the basic TTI. 46 return BaseT::getArithmeticInstrCost(Opcode, Ty, Opd1Info, Opd2Info, 47 Opd1PropInfo, Opd2PropInfo); 48 } 49 } 50