blob: d638503990adcfb8d072c339ce7c09c058f2e2ee [file] [log] [blame]
Eugene Zelenko52889212017-08-01 21:20:10 +00001//===- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass ---------===//
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +00002//
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"
Eugene Zelenko52889212017-08-01 21:20:10 +000017#include "HexagonSubtarget.h"
18#include "llvm/Analysis/TargetTransformInfo.h"
19#include "llvm/IR/InstrTypes.h"
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +000020#include "llvm/IR/Instructions.h"
Eugene Zelenko52889212017-08-01 21:20:10 +000021#include "llvm/IR/User.h"
22#include "llvm/Support/Casting.h"
23#include "llvm/Support/CommandLine.h"
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000024
25using namespace llvm;
26
27#define DEBUG_TYPE "hexagontti"
28
Sumanth Gundapanenid2dd79b2017-06-30 20:54:24 +000029static cl::opt<bool> EmitLookupTables("hexagon-emit-lookup-tables",
30 cl::init(true), cl::Hidden,
31 cl::desc("Control lookup table emission on Hexagon target"));
32
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000033TargetTransformInfo::PopcntSupportKind
34HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {
35 // Return Fast Hardware support as every input < 64 bits will be promoted
36 // to 64 bits.
37 return TargetTransformInfo::PSK_FastHardware;
38}
39
40// The Hexagon target can unroll loops with run-time trip counts.
Geoff Berry66d9bdb2017-06-28 15:53:17 +000041void HexagonTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000042 TTI::UnrollingPreferences &UP) {
43 UP.Runtime = UP.Partial = true;
44}
45
46unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const {
Krzysztof Parzyszekeca6f042015-08-05 21:08:26 +000047 return vector ? 0 : 32;
Krzysztof Parzyszek73e66f32015-08-05 18:35:37 +000048}
Krzysztof Parzyszekd3d0a4b2016-07-22 14:22:43 +000049
50unsigned HexagonTTIImpl::getPrefetchDistance() const {
51 return getST()->getL1PrefetchDistance();
52}
53
54unsigned HexagonTTIImpl::getCacheLineSize() const {
55 return getST()->getL1CacheLineSize();
56}
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +000057
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +000058int HexagonTTIImpl::getUserCost(const User *U,
59 ArrayRef<const Value *> Operands) {
60 auto isCastFoldedIntoLoad = [](const CastInst *CI) -> bool {
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +000061 if (!CI->isIntegerCast())
62 return false;
63 const LoadInst *LI = dyn_cast<const LoadInst>(CI->getOperand(0));
64 // Technically, this code could allow multiple uses of the load, and
65 // check if all the uses are the same extension operation, but this
66 // should be sufficient for most cases.
67 if (!LI || !LI->hasOneUse())
68 return false;
69
70 // Only extensions from an integer type shorter than 32-bit to i32
71 // can be folded into the load.
72 unsigned SBW = CI->getSrcTy()->getIntegerBitWidth();
73 unsigned DBW = CI->getDestTy()->getIntegerBitWidth();
74 return DBW == 32 && (SBW < DBW);
75 };
76
77 if (const CastInst *CI = dyn_cast<const CastInst>(U))
78 if (isCastFoldedIntoLoad(CI))
79 return TargetTransformInfo::TCC_Free;
Evgeny Astigeevich70ed78e2017-06-29 13:42:12 +000080 return BaseT::getUserCost(U, Operands);
Krzysztof Parzyszekdb019ae2016-08-19 14:22:07 +000081}
Sumanth Gundapanenid2dd79b2017-06-30 20:54:24 +000082
83bool HexagonTTIImpl::shouldBuildLookupTables() const {
84 return EmitLookupTables;
85}