1 //===-- AMDGPUTargetTransformInfo.cpp - AMDGPU 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.
8 //===----------------------------------------------------------------------===//
11 // This file implements a TargetTransformInfo analysis pass specific to the
12 // AMDGPU target machine. It uses the target's detailed information to provide
13 // more precise answers to certain TTI queries, while letting the target
14 // independent and default TTI implementations handle the rest.
16 //===----------------------------------------------------------------------===//
18 #include "AMDGPUTargetTransformInfo.h"
19 #include "llvm/Analysis/LoopInfo.h"
20 #include "llvm/Analysis/TargetTransformInfo.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/CodeGen/BasicTTIImpl.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Target/CostTable.h"
26 #include "llvm/Target/TargetLowering.h"
29 #define DEBUG_TYPE "AMDGPUtti"
31 void AMDGPUTTIImpl::getUnrollingPreferences(Loop *L,
32 TTI::UnrollingPreferences &UP) {
33 UP.Threshold = 300; // Twice the default.
34 UP.MaxCount = UINT_MAX;
37 // TODO: Do we want runtime unrolling?
39 for (const BasicBlock *BB : L->getBlocks()) {
40 const DataLayout &DL = BB->getModule()->getDataLayout();
41 for (const Instruction &I : *BB) {
42 const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(&I);
43 if (!GEP || GEP->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS)
46 const Value *Ptr = GEP->getPointerOperand();
47 const AllocaInst *Alloca =
48 dyn_cast<AllocaInst>(GetUnderlyingObject(Ptr, DL));
50 // We want to do whatever we can to limit the number of alloca
51 // instructions that make it through to the code generator. allocas
52 // require us to use indirect addressing, which is slow and prone to
53 // compiler bugs. If this loop does an address calculation on an
54 // alloca ptr, then we want to use a higher than normal loop unroll
55 // threshold. This will give SROA a better chance to eliminate these
58 // Don't use the maximum allowed value here as it will make some
59 // programs way too big.
66 unsigned AMDGPUTTIImpl::getNumberOfRegisters(bool Vec) {
70 // Number of VGPRs on SI.
71 if (ST->getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS)
74 return 4 * 128; // XXX - 4 channels. Should these count as vector instead?
77 unsigned AMDGPUTTIImpl::getRegisterBitWidth(bool) { return 32; }
79 unsigned AMDGPUTTIImpl::getMaxInterleaveFactor(unsigned VF) {
80 // Semi-arbitrary large amount.