2017-08-02 05:20:10 +08:00
|
|
|
//===- HexagonTargetTransformInfo.cpp - Hexagon specific TTI pass ---------===//
|
2015-08-06 02:35:37 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
/// This file implements a TargetTransformInfo analysis pass specific to the
|
|
|
|
/// Hexagon target machine. It uses the target's detailed information to provide
|
|
|
|
/// more precise answers to certain TTI queries, while letting the target
|
|
|
|
/// independent and default TTI implementations handle the rest.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "HexagonTargetTransformInfo.h"
|
2017-08-02 05:20:10 +08:00
|
|
|
#include "HexagonSubtarget.h"
|
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
|
|
|
#include "llvm/IR/InstrTypes.h"
|
2016-08-19 22:22:07 +08:00
|
|
|
#include "llvm/IR/Instructions.h"
|
2017-08-02 05:20:10 +08:00
|
|
|
#include "llvm/IR/User.h"
|
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2015-08-06 02:35:37 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "hexagontti"
|
|
|
|
|
2017-07-01 04:54:24 +08:00
|
|
|
static cl::opt<bool> EmitLookupTables("hexagon-emit-lookup-tables",
|
|
|
|
cl::init(true), cl::Hidden,
|
|
|
|
cl::desc("Control lookup table emission on Hexagon target"));
|
|
|
|
|
2015-08-06 02:35:37 +08:00
|
|
|
TargetTransformInfo::PopcntSupportKind
|
|
|
|
HexagonTTIImpl::getPopcntSupport(unsigned IntTyWidthInBit) const {
|
|
|
|
// Return Fast Hardware support as every input < 64 bits will be promoted
|
|
|
|
// to 64 bits.
|
|
|
|
return TargetTransformInfo::PSK_FastHardware;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The Hexagon target can unroll loops with run-time trip counts.
|
[LoopUnroll] Pass SCEV to getUnrollingPreferences hook. NFCI.
Reviewers: sanjoy, anna, reames, apilipenko, igor-laevsky, mkuper
Subscribers: jholewinski, arsenm, mzolotukhin, nemanjai, nhaehnle, javed.absar, mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D34531
llvm-svn: 306554
2017-06-28 23:53:17 +08:00
|
|
|
void HexagonTTIImpl::getUnrollingPreferences(Loop *L, ScalarEvolution &SE,
|
2015-08-06 02:35:37 +08:00
|
|
|
TTI::UnrollingPreferences &UP) {
|
|
|
|
UP.Runtime = UP.Partial = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned HexagonTTIImpl::getNumberOfRegisters(bool vector) const {
|
2015-08-06 05:08:26 +08:00
|
|
|
return vector ? 0 : 32;
|
2015-08-06 02:35:37 +08:00
|
|
|
}
|
2016-07-22 22:22:43 +08:00
|
|
|
|
|
|
|
unsigned HexagonTTIImpl::getPrefetchDistance() const {
|
|
|
|
return getST()->getL1PrefetchDistance();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned HexagonTTIImpl::getCacheLineSize() const {
|
|
|
|
return getST()->getL1CacheLineSize();
|
|
|
|
}
|
2016-08-19 22:22:07 +08:00
|
|
|
|
2017-06-29 21:42:12 +08:00
|
|
|
int HexagonTTIImpl::getUserCost(const User *U,
|
|
|
|
ArrayRef<const Value *> Operands) {
|
|
|
|
auto isCastFoldedIntoLoad = [](const CastInst *CI) -> bool {
|
2016-08-19 22:22:07 +08:00
|
|
|
if (!CI->isIntegerCast())
|
|
|
|
return false;
|
|
|
|
const LoadInst *LI = dyn_cast<const LoadInst>(CI->getOperand(0));
|
|
|
|
// Technically, this code could allow multiple uses of the load, and
|
|
|
|
// check if all the uses are the same extension operation, but this
|
|
|
|
// should be sufficient for most cases.
|
|
|
|
if (!LI || !LI->hasOneUse())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Only extensions from an integer type shorter than 32-bit to i32
|
|
|
|
// can be folded into the load.
|
|
|
|
unsigned SBW = CI->getSrcTy()->getIntegerBitWidth();
|
|
|
|
unsigned DBW = CI->getDestTy()->getIntegerBitWidth();
|
|
|
|
return DBW == 32 && (SBW < DBW);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (const CastInst *CI = dyn_cast<const CastInst>(U))
|
|
|
|
if (isCastFoldedIntoLoad(CI))
|
|
|
|
return TargetTransformInfo::TCC_Free;
|
2017-06-29 21:42:12 +08:00
|
|
|
return BaseT::getUserCost(U, Operands);
|
2016-08-19 22:22:07 +08:00
|
|
|
}
|
2017-07-01 04:54:24 +08:00
|
|
|
|
|
|
|
bool HexagonTTIImpl::shouldBuildLookupTables() const {
|
|
|
|
return EmitLookupTables;
|
|
|
|
}
|