Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 1 | //===- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass ---------===// |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 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" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 17 | #include "HexagonSubtarget.h" |
| 18 | #include "llvm/Analysis/TargetTransformInfo.h" |
| 19 | #include "llvm/IR/InstrTypes.h" |
Krzysztof Parzyszek | db019ae | 2016-08-19 14:22:07 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Instructions.h" |
Eugene Zelenko | 5288921 | 2017-08-01 21:20:10 +0000 | [diff] [blame] | 21 | #include "llvm/IR/User.h" |
| 22 | #include "llvm/Support/Casting.h" |
| 23 | #include "llvm/Support/CommandLine.h" |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 24 | |
| 25 | using namespace llvm; |
| 26 | |
| 27 | #define DEBUG_TYPE "hexagontti" |
| 28 | |
Sumanth Gundapaneni | d2dd79b | 2017-06-30 20:54:24 +0000 | [diff] [blame] | 29 | static 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 Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 33 | TargetTransformInfo::PopcntSupportKind |
| 34 | HexagonTTIImpl::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 Berry | 66d9bdb | 2017-06-28 15:53:17 +0000 | [diff] [blame] | 41 | void HexagonTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE, |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 42 | TTI::UnrollingPreferences &UP) { |
| 43 | UP.Runtime = UP.Partial = true; |
| 44 | } |
| 45 | |
| 46 | unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const { |
Krzysztof Parzyszek | eca6f04 | 2015-08-05 21:08:26 +0000 | [diff] [blame] | 47 | return vector ? 0 : 32; |
Krzysztof Parzyszek | 73e66f3 | 2015-08-05 18:35:37 +0000 | [diff] [blame] | 48 | } |
Krzysztof Parzyszek | d3d0a4b | 2016-07-22 14:22:43 +0000 | [diff] [blame] | 49 | |
| 50 | unsigned HexagonTTIImpl::getPrefetchDistance() const { |
| 51 | return getST()->getL1PrefetchDistance(); |
| 52 | } |
| 53 | |
| 54 | unsigned HexagonTTIImpl::getCacheLineSize() const { |
| 55 | return getST()->getL1CacheLineSize(); |
| 56 | } |
Krzysztof Parzyszek | db019ae | 2016-08-19 14:22:07 +0000 | [diff] [blame] | 57 | |
Evgeny Astigeevich | 70ed78e | 2017-06-29 13:42:12 +0000 | [diff] [blame] | 58 | int HexagonTTIImpl::getUserCost(const User *U, |
| 59 | ArrayRef<const Value *> Operands) { |
| 60 | auto isCastFoldedIntoLoad = [](const CastInst *CI) -> bool { |
Krzysztof Parzyszek | db019ae | 2016-08-19 14:22:07 +0000 | [diff] [blame] | 61 | 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 Astigeevich | 70ed78e | 2017-06-29 13:42:12 +0000 | [diff] [blame] | 80 | return BaseT::getUserCost(U, Operands); |
Krzysztof Parzyszek | db019ae | 2016-08-19 14:22:07 +0000 | [diff] [blame] | 81 | } |
Sumanth Gundapaneni | d2dd79b | 2017-06-30 20:54:24 +0000 | [diff] [blame] | 82 | |
| 83 | bool HexagonTTIImpl::shouldBuildLookupTables() const { |
| 84 | return EmitLookupTables; |
| 85 | } |