1 //===-- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass --------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
9 /// This file implements a TargetTransformInfo analysis pass specific to the
10 /// Hexagon target machine. It uses the target's detailed information to provide
11 /// more precise answers to certain TTI queries, while letting the target
12 /// independent and default TTI implementations handle the rest.
14 //===----------------------------------------------------------------------===//
16 #include "HexagonTargetTransformInfo.h"
17 #include "llvm/IR/Instructions.h"
18 #include "llvm/Support/Debug.h"
22 #define DEBUG_TYPE "hexagontti"
24 static cl::opt<bool> EmitLookupTables("hexagon-emit-lookup-tables",
25 cl::init(true), cl::Hidden,
26 cl::desc("Control lookup table emission on Hexagon target"));
28 TargetTransformInfo::PopcntSupportKind
29 HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {
30 // Return Fast Hardware support as every input < 64 bits will be promoted
32 return TargetTransformInfo::PSK_FastHardware;
35 // The Hexagon target can unroll loops with run-time trip counts.
36 void HexagonTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
37 TTI::UnrollingPreferences &UP) {
38 UP.Runtime = UP.Partial = true;
41 unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const {
42 return vector ? 0 : 32;
45 unsigned HexagonTTIImpl::getPrefetchDistance() const {
46 return getST()->getL1PrefetchDistance();
49 unsigned HexagonTTIImpl::getCacheLineSize() const {
50 return getST()->getL1CacheLineSize();
53 int HexagonTTIImpl::getUserCost(const User *U,
54 ArrayRef<const Value *> Operands) {
55 auto isCastFoldedIntoLoad = [](const CastInst *CI) -> bool {
56 if (!CI->isIntegerCast())
58 const LoadInst *LI = dyn_cast<const LoadInst>(CI->getOperand(0));
59 // Technically, this code could allow multiple uses of the load, and
60 // check if all the uses are the same extension operation, but this
61 // should be sufficient for most cases.
62 if (!LI || !LI->hasOneUse())
65 // Only extensions from an integer type shorter than 32-bit to i32
66 // can be folded into the load.
67 unsigned SBW = CI->getSrcTy()->getIntegerBitWidth();
68 unsigned DBW = CI->getDestTy()->getIntegerBitWidth();
69 return DBW == 32 && (SBW < DBW);
72 if (const CastInst *CI = dyn_cast<const CastInst>(U))
73 if (isCastFoldedIntoLoad(CI))
74 return TargetTransformInfo::TCC_Free;
75 return BaseT::getUserCost(U, Operands);
78 bool HexagonTTIImpl::shouldBuildLookupTables() const {
79 return EmitLookupTables;