blob: d578bfab3658b2afb2fb7e70302924a815fc6e29 [file] [log] [blame]
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +00001//===-- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass --------===//
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/// \file
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.
13///
14//===----------------------------------------------------------------------===//
15
16#include "HexagonTargetTransformInfo.h"
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +000017#include "llvm/IR/Instructions.h"
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000018#include "llvm/Support/Debug.h"
19
20using namespace llvm;
21
22#define DEBUG_TYPE "hexagontti"
23
24TargetTransformInfo::PopcntSupportKind
25HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {
26 // Return Fast Hardware support as every input < 64 bits will be promoted
27 // to 64 bits.
28 return TargetTransformInfo::PSK_FastHardware;
29}
30
31// The Hexagon target can unroll loops with run-time trip counts.
32void HexagonTTIImpl::getUnrollingPreferences(Loop *L,
33 TTI::UnrollingPreferences &UP) {
34 UP.Runtime = UP.Partial = true;
35}
36
37unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const {
Krzysztof Parzyszekeca6f042015-08-05 21:08:26 +000038 return vector ? 0 : 32;
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000039}
Krzysztof Parzyszekd3d0a4b2016-07-22 14:22:43 +000040
41unsigned HexagonTTIImpl::getPrefetchDistance() const {
42 return getST()->getL1PrefetchDistance();
43}
44
45unsigned HexagonTTIImpl::getCacheLineSize() const {
46 return getST()->getL1CacheLineSize();
47}
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +000048
49int HexagonTTIImpl::getUserCost(const User *U) {
50 auto isCastFoldedIntoLoad = [] (const CastInst *CI) -> bool {
51 if (!CI->isIntegerCast())
52 return false;
53 const LoadInst *LI = dyn_cast<const LoadInst>(CI->getOperand(0));
54 // Technically, this code could allow multiple uses of the load, and
55 // check if all the uses are the same extension operation, but this
56 // should be sufficient for most cases.
57 if (!LI || !LI->hasOneUse())
58 return false;
59
60 // Only extensions from an integer type shorter than 32-bit to i32
61 // can be folded into the load.
62 unsigned SBW = CI->getSrcTy()->getIntegerBitWidth();
63 unsigned DBW = CI->getDestTy()->getIntegerBitWidth();
64 return DBW == 32 && (SBW < DBW);
65 };
66
67 if (const CastInst *CI = dyn_cast<const CastInst>(U))
68 if (isCastFoldedIntoLoad(CI))
69 return TargetTransformInfo::TCC_Free;
70 return BaseT::getUserCost(U);
71}